-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontent.ts
More file actions
103 lines (93 loc) · 3.8 KB
/
Copy pathcontent.ts
File metadata and controls
103 lines (93 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { asWebGenComponent, Component, HTMLComponent } from "../components.ts";
import { alwaysRef, Reference } from "../state.ts";
@asWebGenComponent("full-width-section")
class FullWidthSectionComponent extends HTMLComponent {
constructor(
components: Component[]
) {
super();
this.style.display = "grid";
this.style.gridTemplateColumns = "inherit";
this.style.gridColumn = "full-width";
for (const iterator of components) {
const item = iterator.draw();
item.style.gridColumn = "full-width";
this.append(item);
}
}
}
export const FullWidthSection = (...elements: Component[]) => new FullWidthSectionComponent(elements).make();
@asWebGenComponent("content")
export class ContentComponent extends HTMLComponent {
constructor(component: Reference<Component[] | Component> | Component, components: Component[]) {
super();
this.style.display = "grid";
this.style.setProperty("--content-padding", "16px");
this.style.gridTemplateColumns = [
"[full-width-start]",
"minmax(var(--content-padding), 1fr)",
"[content-start]",
"min(100% - (var(--content-padding) * 2), var(--content-max-width, 900px))",
"[content-end]",
"minmax(var(--content-padding), 1fr)",
"[full-width-end]",
].join(" ");
this.style.alignContent = "start";
const dynamicElement = document.createElement("slot");
dynamicElement.name = "dynamic";
const staticElements = document.createElement("slot");
staticElements.name = "static";
this.shadowRoot!.append(dynamicElement, staticElements);
this.addListen(() => {
const current = alwaysRef(component).value;
const alwaysList = Array.isArray(current) ? current : [ current ];
this.replaceChildren(
...alwaysList
.map(component => component.draw())
.map(element => {
if (element instanceof FullWidthSectionComponent) {
return Array.from(element.children)
} else {
element.style.gridColumn = "content";
return [element];
}
}).flat().map(element => {
element.slot = "dynamic";
return element;
}),
...components
.map(component => component.draw())
.map(element => {
if (element instanceof FullWidthSectionComponent) {
return Array.from(element.children)
} else {
element.style.gridColumn = "content";
return [element];
}
}).flat().map(element => {
element.slot = "static";
return element;
})
);
});
}
override make() {
const obj = {
...super.make(),
setContentMaxWidth: (size: string) => {
this.style.setProperty("--content-max-width", size);
return obj;
},
setContentPadding: (size: string) => {
this.style.setProperty("--content-padding", size);
return obj;
},
fillHeight: () => {
this.style.marginBlockEnd = "auto";
return obj;
}
};
return obj;
}
}
export const Content = (component: Reference<Component[] | Component> | Component, ...components: Component[]) => new ContentComponent(component, components).make();