@spfx-fast/sharepoint-ui 0.0.0-stage → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +211 -0
- package/LICENSE +21 -0
- package/README.md +897 -2
- package/components.json +5811 -0
- package/dist/appearance.d.ts +6 -0
- package/dist/appearance.js +217 -0
- package/dist/elements/accordion.d.ts +9 -0
- package/dist/elements/accordion.js +338 -0
- package/dist/elements/alert.d.ts +2 -0
- package/dist/elements/alert.js +62 -0
- package/dist/elements/avatar-group-primitives.d.ts +3 -0
- package/dist/elements/avatar-group-primitives.js +189 -0
- package/dist/elements/avatar-group.d.ts +2 -0
- package/dist/elements/avatar-group.js +110 -0
- package/dist/elements/avatar.d.ts +4 -0
- package/dist/elements/avatar.js +251 -0
- package/dist/elements/badge.d.ts +8 -0
- package/dist/elements/badge.js +182 -0
- package/dist/elements/breadcrumb.d.ts +4 -0
- package/dist/elements/breadcrumb.js +233 -0
- package/dist/elements/button-group.d.ts +1 -0
- package/dist/elements/button-group.js +20 -0
- package/dist/elements/button-variants.d.ts +6 -0
- package/dist/elements/button-variants.js +339 -0
- package/dist/elements/button.d.ts +5 -0
- package/dist/elements/button.js +233 -0
- package/dist/elements/card-primitives.d.ts +3 -0
- package/dist/elements/card-primitives.js +83 -0
- package/dist/elements/card.d.ts +5 -0
- package/dist/elements/card.js +213 -0
- package/dist/elements/carousel.d.ts +92 -0
- package/dist/elements/carousel.js +1112 -0
- package/dist/elements/color-picker.d.ts +24 -0
- package/dist/elements/color-picker.js +1004 -0
- package/dist/elements/combobox.d.ts +1 -0
- package/dist/elements/combobox.js +1012 -0
- package/dist/elements/data-grid-model.d.ts +117 -0
- package/dist/elements/data-grid-model.js +294 -0
- package/dist/elements/data-grid.d.ts +29 -0
- package/dist/elements/data-grid.js +1567 -0
- package/dist/elements/date-picker.d.ts +1 -0
- package/dist/elements/date-picker.js +486 -0
- package/dist/elements/dialog.d.ts +23 -0
- package/dist/elements/dialog.js +409 -0
- package/dist/elements/divider.d.ts +2 -0
- package/dist/elements/divider.js +66 -0
- package/dist/elements/drawer.d.ts +3 -0
- package/dist/elements/drawer.js +308 -0
- package/dist/elements/field-composition.d.ts +26 -0
- package/dist/elements/field-composition.js +133 -0
- package/dist/elements/field.d.ts +1 -0
- package/dist/elements/field.js +67 -0
- package/dist/elements/file-upload.d.ts +6 -0
- package/dist/elements/file-upload.js +211 -0
- package/dist/elements/floating-position.d.ts +26 -0
- package/dist/elements/floating-position.js +39 -0
- package/dist/elements/image.d.ts +28 -0
- package/dist/elements/image.js +38 -0
- package/dist/elements/info.d.ts +9 -0
- package/dist/elements/info.js +102 -0
- package/dist/elements/input.d.ts +5 -0
- package/dist/elements/input.js +255 -0
- package/dist/elements/label.d.ts +15 -0
- package/dist/elements/label.js +56 -0
- package/dist/elements/link.d.ts +1 -0
- package/dist/elements/link.js +92 -0
- package/dist/elements/list.d.ts +19 -0
- package/dist/elements/list.js +297 -0
- package/dist/elements/menu.d.ts +33 -0
- package/dist/elements/menu.js +1103 -0
- package/dist/elements/message-bar.d.ts +10 -0
- package/dist/elements/message-bar.js +299 -0
- package/dist/elements/nav.d.ts +32 -0
- package/dist/elements/nav.js +791 -0
- package/dist/elements/overflow.d.ts +9 -0
- package/dist/elements/overflow.js +218 -0
- package/dist/elements/persona.d.ts +3 -0
- package/dist/elements/persona.js +125 -0
- package/dist/elements/popover.d.ts +77 -0
- package/dist/elements/popover.js +840 -0
- package/dist/elements/progress-bar.d.ts +4 -0
- package/dist/elements/progress-bar.js +82 -0
- package/dist/elements/radio-group.d.ts +1 -0
- package/dist/elements/radio-group.js +303 -0
- package/dist/elements/rating-display.d.ts +2 -0
- package/dist/elements/rating-display.js +125 -0
- package/dist/elements/rating.d.ts +2 -0
- package/dist/elements/rating.js +206 -0
- package/dist/elements/rich-text-editor.d.ts +18 -0
- package/dist/elements/rich-text-editor.js +508 -0
- package/dist/elements/search.d.ts +3 -0
- package/dist/elements/search.js +207 -0
- package/dist/elements/select.d.ts +6 -0
- package/dist/elements/select.js +291 -0
- package/dist/elements/shared.d.ts +19 -0
- package/dist/elements/shared.js +396 -0
- package/dist/elements/skeleton.d.ts +6 -0
- package/dist/elements/skeleton.js +91 -0
- package/dist/elements/slider.d.ts +1 -0
- package/dist/elements/slider.js +248 -0
- package/dist/elements/spin-button.d.ts +7 -0
- package/dist/elements/spin-button.js +499 -0
- package/dist/elements/spinner.d.ts +4 -0
- package/dist/elements/spinner.js +124 -0
- package/dist/elements/swatch-picker.d.ts +5 -0
- package/dist/elements/swatch-picker.js +363 -0
- package/dist/elements/table.d.ts +21 -0
- package/dist/elements/table.js +261 -0
- package/dist/elements/tabs.d.ts +1 -0
- package/dist/elements/tabs.js +276 -0
- package/dist/elements/tag-picker.d.ts +29 -0
- package/dist/elements/tag-picker.js +697 -0
- package/dist/elements/tags.d.ts +21 -0
- package/dist/elements/tags.js +421 -0
- package/dist/elements/teaching-popover.d.ts +32 -0
- package/dist/elements/teaching-popover.js +412 -0
- package/dist/elements/text.d.ts +9 -0
- package/dist/elements/text.js +75 -0
- package/dist/elements/textarea.d.ts +1 -0
- package/dist/elements/textarea.js +182 -0
- package/dist/elements/toast.d.ts +25 -0
- package/dist/elements/toast.js +337 -0
- package/dist/elements/toaster.d.ts +6 -0
- package/dist/elements/toaster.js +356 -0
- package/dist/elements/toggle.d.ts +2 -0
- package/dist/elements/toggle.js +246 -0
- package/dist/elements/toolbar.d.ts +12 -0
- package/dist/elements/toolbar.js +381 -0
- package/dist/elements/tooltip.d.ts +76 -0
- package/dist/elements/tooltip.js +510 -0
- package/dist/elements/tree-model.d.ts +19 -0
- package/dist/elements/tree-model.js +34 -0
- package/dist/elements/tree.d.ts +5 -0
- package/dist/elements/tree.js +273 -0
- package/dist/elements/view-card.d.ts +2 -0
- package/dist/elements/view-card.js +78 -0
- package/dist/elements/virtual-list.d.ts +41 -0
- package/dist/elements/virtual-list.js +369 -0
- package/dist/elements.d.ts +72 -0
- package/dist/elements.js +207 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +66 -0
- package/dist/react.d.ts +4546 -0
- package/dist/react.js +6837 -0
- package/dist/theme.d.ts +169 -0
- package/dist/theme.js +167 -0
- package/dist/virtualizer-hooks.d.ts +80 -0
- package/dist/virtualizer-hooks.js +253 -0
- package/package.json +87 -4
- package/scripts/generate-token-index.mjs +43 -0
- package/scripts/sync-component-catalog-signatures.mjs +55 -0
- package/scripts/validate-component-catalog.mjs +44 -0
- package/skills/sharepoint-ui/SKILL.md +12 -0
- package/skills/sharepoint-ui/references/choosing-components.md +20 -0
- package/skills/sharepoint-ui/references/sharepoint-patterns.md +17 -0
- package/tokens.json +3777 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { base } from "./shared.js";
|
|
2
|
+
export function defineDrawer() {
|
|
3
|
+
if (customElements.get("spui-drawer"))
|
|
4
|
+
return;
|
|
5
|
+
class SpuiDrawer extends HTMLElement {
|
|
6
|
+
static observedAttributes = ["open", "motion", "motion-visible", "motion-exit-complete", "data-has-custom-backdrop", "title", "position", "size", "type", "modal", "modal-type", "inert-trap-focus", "dismissible", "close-label", "aria-label", "expandable", "expanded", "expand-label", "restore-label"];
|
|
7
|
+
outsidePointer;
|
|
8
|
+
get open() { return this.hasAttribute("open"); }
|
|
9
|
+
set open(value) { this.toggleAttribute("open", Boolean(value)); }
|
|
10
|
+
connectedCallback() {
|
|
11
|
+
if (!this.shadowRoot)
|
|
12
|
+
this.render();
|
|
13
|
+
this.syncOpen();
|
|
14
|
+
}
|
|
15
|
+
disconnectedCallback() { this.removeOutsidePointer(); }
|
|
16
|
+
attributeChangedCallback() { if (this.isConnected)
|
|
17
|
+
this.syncOpen(); }
|
|
18
|
+
syncOpen() {
|
|
19
|
+
const dialog = this.shadowRoot?.querySelector("dialog");
|
|
20
|
+
if (!dialog)
|
|
21
|
+
return;
|
|
22
|
+
const motionExiting = this.hasAttribute("motion") && this.getAttribute("motion-visible") === "false" && !this.hasAttribute("motion-exit-complete");
|
|
23
|
+
const shouldOpen = this.open || motionExiting;
|
|
24
|
+
if (shouldOpen && !dialog.open) {
|
|
25
|
+
if (this.getAttribute("modal") === "false" && this.getAttribute("modal-type") !== "alert")
|
|
26
|
+
dialog.show();
|
|
27
|
+
else
|
|
28
|
+
dialog.showModal();
|
|
29
|
+
}
|
|
30
|
+
else if (!shouldOpen && dialog.open)
|
|
31
|
+
dialog.close();
|
|
32
|
+
dialog.inert = motionExiting;
|
|
33
|
+
if (motionExiting)
|
|
34
|
+
dialog.setAttribute("aria-hidden", "true");
|
|
35
|
+
else
|
|
36
|
+
dialog.removeAttribute("aria-hidden");
|
|
37
|
+
if (this.open && this.getAttribute("modal") === "false" && this.getAttribute("dismissible") !== "false") {
|
|
38
|
+
if (!this.outsidePointer) {
|
|
39
|
+
this.outsidePointer = event => {
|
|
40
|
+
if (!this.open || this.getAttribute("motion-visible") === "false" || this.getAttribute("modal") !== "false" || this.getAttribute("dismissible") === "false" || event.composedPath().includes(dialog))
|
|
41
|
+
return;
|
|
42
|
+
this.dismiss(event, "backdropClick");
|
|
43
|
+
};
|
|
44
|
+
document.addEventListener("pointerdown", this.outsidePointer, true);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else
|
|
48
|
+
this.removeOutsidePointer();
|
|
49
|
+
const fallbackTitle = this.shadowRoot?.querySelector(".fallback-title");
|
|
50
|
+
if (fallbackTitle)
|
|
51
|
+
fallbackTitle.textContent = this.getAttribute("title") ?? "Details";
|
|
52
|
+
const titleSlot = this.shadowRoot?.querySelector("slot[name=title]");
|
|
53
|
+
if (fallbackTitle && titleSlot)
|
|
54
|
+
fallbackTitle.hidden = titleSlot.assignedNodes().length > 0;
|
|
55
|
+
const navigationSlot = this.shadowRoot?.querySelector("slot[name=header-navigation]");
|
|
56
|
+
const navigation = this.shadowRoot?.querySelector(".header-navigation");
|
|
57
|
+
if (navigation && navigationSlot)
|
|
58
|
+
navigation.hidden = navigationSlot.assignedNodes().length === 0;
|
|
59
|
+
const close = this.shadowRoot?.querySelector(".close");
|
|
60
|
+
if (close) {
|
|
61
|
+
close.setAttribute("aria-label", this.getAttribute("close-label") ?? "Close");
|
|
62
|
+
close.hidden = this.getAttribute("dismissible") === "false" || this.getAttribute("modal-type") === "alert";
|
|
63
|
+
}
|
|
64
|
+
const expand = this.shadowRoot?.querySelector(".expand");
|
|
65
|
+
if (expand) {
|
|
66
|
+
const expanded = this.hasAttribute("expanded");
|
|
67
|
+
expand.hidden = !this.hasAttribute("expandable") || this.getAttribute("expandable") === "false";
|
|
68
|
+
expand.setAttribute("aria-label", expanded ? this.getAttribute("restore-label") ?? "Restore drawer size" : this.getAttribute("expand-label") ?? "Expand drawer to full screen");
|
|
69
|
+
expand.setAttribute("aria-pressed", String(expanded));
|
|
70
|
+
}
|
|
71
|
+
const label = this.getAttribute("aria-label");
|
|
72
|
+
if (label)
|
|
73
|
+
dialog.setAttribute("aria-label", label);
|
|
74
|
+
else
|
|
75
|
+
dialog.removeAttribute("aria-label");
|
|
76
|
+
if (this.getAttribute("modal-type") === "alert")
|
|
77
|
+
dialog.setAttribute("role", "alertdialog");
|
|
78
|
+
else
|
|
79
|
+
dialog.removeAttribute("role");
|
|
80
|
+
}
|
|
81
|
+
removeOutsidePointer() {
|
|
82
|
+
if (!this.outsidePointer)
|
|
83
|
+
return;
|
|
84
|
+
document.removeEventListener("pointerdown", this.outsidePointer, true);
|
|
85
|
+
this.outsidePointer = undefined;
|
|
86
|
+
}
|
|
87
|
+
dismiss(sourceEvent, type) {
|
|
88
|
+
if (!this.open || this.getAttribute("dismissible") === "false" || this.getAttribute("modal-type") === "alert")
|
|
89
|
+
return;
|
|
90
|
+
if (this.hasAttribute("motion")) {
|
|
91
|
+
if (this.getAttribute("motion-visible") === "false")
|
|
92
|
+
return;
|
|
93
|
+
this.dispatchEvent(new CustomEvent("spui-open-change", { bubbles: true, composed: true, detail: { open: false, type, event: sourceEvent } }));
|
|
94
|
+
this.dispatchEvent(new CustomEvent("spui-dismiss", { bubbles: true, composed: true }));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.removeAttribute("open");
|
|
98
|
+
const dialog = this.shadowRoot?.querySelector("dialog");
|
|
99
|
+
if (dialog?.open)
|
|
100
|
+
dialog.close();
|
|
101
|
+
this.dispatchEvent(new CustomEvent("spui-open-change", { bubbles: true, composed: true, detail: { open: false, type, event: sourceEvent } }));
|
|
102
|
+
this.dispatchEvent(new CustomEvent("spui-dismiss", { bubbles: true, composed: true }));
|
|
103
|
+
}
|
|
104
|
+
render() {
|
|
105
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
106
|
+
const dialog = document.createElement("dialog");
|
|
107
|
+
dialog.part.add("surface");
|
|
108
|
+
dialog.setAttribute("aria-labelledby", "title");
|
|
109
|
+
const header = document.createElement("header");
|
|
110
|
+
const headerMain = document.createElement("div");
|
|
111
|
+
headerMain.className = "header-main";
|
|
112
|
+
const navigation = document.createElement("div");
|
|
113
|
+
navigation.className = "header-navigation";
|
|
114
|
+
const navigationSlot = document.createElement("slot");
|
|
115
|
+
navigationSlot.name = "header-navigation";
|
|
116
|
+
navigationSlot.addEventListener("slotchange", () => this.syncOpen());
|
|
117
|
+
navigation.append(navigationSlot);
|
|
118
|
+
const heading = document.createElement("h2");
|
|
119
|
+
heading.id = "title";
|
|
120
|
+
const fallbackTitle = document.createElement("span");
|
|
121
|
+
fallbackTitle.className = "fallback-title";
|
|
122
|
+
fallbackTitle.textContent = this.getAttribute("title") ?? "Details";
|
|
123
|
+
const titleSlot = document.createElement("slot");
|
|
124
|
+
titleSlot.name = "title";
|
|
125
|
+
titleSlot.addEventListener("slotchange", () => { fallbackTitle.hidden = titleSlot.assignedNodes().length > 0; });
|
|
126
|
+
heading.append(fallbackTitle, titleSlot);
|
|
127
|
+
headerMain.append(navigation, heading);
|
|
128
|
+
const controls = document.createElement("div");
|
|
129
|
+
controls.className = "controls";
|
|
130
|
+
const headerAction = document.createElement("slot");
|
|
131
|
+
headerAction.name = "header-action";
|
|
132
|
+
const expand = document.createElement("button");
|
|
133
|
+
expand.type = "button";
|
|
134
|
+
expand.className = "expand";
|
|
135
|
+
expand.part.add("expand-button");
|
|
136
|
+
expand.setAttribute("aria-label", this.getAttribute("expand-label") ?? "Expand drawer to full screen");
|
|
137
|
+
expand.setAttribute("aria-pressed", "false");
|
|
138
|
+
const expandIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
139
|
+
expandIcon.setAttribute("viewBox", "0 0 20 20");
|
|
140
|
+
expandIcon.setAttribute("width", "20");
|
|
141
|
+
expandIcon.setAttribute("height", "20");
|
|
142
|
+
expandIcon.setAttribute("aria-hidden", "true");
|
|
143
|
+
const expandPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
144
|
+
expandPath.setAttribute("d", "M7 3H3v4m10-4h4v4M3 13v4h4m10-4v4h-4M3 7l5-4m9 4-5-4M3 13l5 4m9-4-5 4");
|
|
145
|
+
expandPath.setAttribute("fill", "none");
|
|
146
|
+
expandPath.setAttribute("stroke", "currentColor");
|
|
147
|
+
expandPath.setAttribute("stroke-width", "1.4");
|
|
148
|
+
expandPath.setAttribute("stroke-linecap", "round");
|
|
149
|
+
expandPath.setAttribute("stroke-linejoin", "round");
|
|
150
|
+
expandIcon.append(expandPath);
|
|
151
|
+
expand.append(expandIcon);
|
|
152
|
+
expand.addEventListener("click", () => {
|
|
153
|
+
const expanded = !this.hasAttribute("expanded");
|
|
154
|
+
this.toggleAttribute("expanded", expanded);
|
|
155
|
+
this.dispatchEvent(new CustomEvent("spui-expanded-change", { bubbles: true, composed: true, detail: { expanded } }));
|
|
156
|
+
});
|
|
157
|
+
const close = document.createElement("button");
|
|
158
|
+
close.type = "button";
|
|
159
|
+
close.className = "close";
|
|
160
|
+
close.part.add("close-button");
|
|
161
|
+
close.setAttribute("aria-label", this.getAttribute("close-label") ?? "Close");
|
|
162
|
+
const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
163
|
+
icon.setAttribute("viewBox", "0 0 20 20");
|
|
164
|
+
icon.setAttribute("width", "20");
|
|
165
|
+
icon.setAttribute("height", "20");
|
|
166
|
+
icon.setAttribute("aria-hidden", "true");
|
|
167
|
+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
168
|
+
path.setAttribute("d", "m5 5 10 10M15 5 5 15");
|
|
169
|
+
path.setAttribute("fill", "none");
|
|
170
|
+
path.setAttribute("stroke", "currentColor");
|
|
171
|
+
path.setAttribute("stroke-width", "1.7");
|
|
172
|
+
path.setAttribute("stroke-linecap", "round");
|
|
173
|
+
icon.append(path);
|
|
174
|
+
close.append(icon);
|
|
175
|
+
close.addEventListener("click", event => this.dismiss(event, "triggerClick"));
|
|
176
|
+
controls.append(headerAction, expand, close);
|
|
177
|
+
header.append(headerMain, controls);
|
|
178
|
+
const body = document.createElement("div");
|
|
179
|
+
body.className = "body";
|
|
180
|
+
body.part.add("body");
|
|
181
|
+
body.append(document.createElement("slot"));
|
|
182
|
+
const footer = document.createElement("footer");
|
|
183
|
+
footer.part.add("actions");
|
|
184
|
+
footer.hidden = true;
|
|
185
|
+
const actions = document.createElement("slot");
|
|
186
|
+
actions.name = "actions";
|
|
187
|
+
actions.addEventListener("slotchange", () => { footer.hidden = actions.assignedElements().length === 0; });
|
|
188
|
+
footer.append(actions);
|
|
189
|
+
const backdropSlot = document.createElement("slot");
|
|
190
|
+
backdropSlot.name = "backdrop";
|
|
191
|
+
backdropSlot.addEventListener("click", event => { if (this.getAttribute("modal-type") !== "alert")
|
|
192
|
+
this.dismiss(event, "backdropClick"); });
|
|
193
|
+
dialog.append(backdropSlot, header, body, footer);
|
|
194
|
+
dialog.addEventListener("cancel", event => { event.preventDefault(); });
|
|
195
|
+
dialog.addEventListener("keydown", event => { if (event.key === "Escape") {
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
if (this.getAttribute("modal-type") !== "alert")
|
|
198
|
+
this.dismiss(event, "escapeKeyDown");
|
|
199
|
+
} });
|
|
200
|
+
dialog.addEventListener("click", event => {
|
|
201
|
+
if (event.target !== dialog || this.getAttribute("dismissible") === "false" || this.getAttribute("modal-type") === "alert")
|
|
202
|
+
return;
|
|
203
|
+
const rect = dialog.getBoundingClientRect();
|
|
204
|
+
if (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom)
|
|
205
|
+
this.dismiss(event, "backdropClick");
|
|
206
|
+
});
|
|
207
|
+
const style = document.createElement("style");
|
|
208
|
+
style.textContent = `${base}:host{display:contents}dialog{isolation:isolate;position:fixed;inset-block:0;inset-inline-start:auto;inset-inline-end:0;box-sizing:border-box;display:flex;flex-direction:column;width:min(var(--spui-drawer-width,480px),calc(100vw - 24px));height:100dvh;max-height:100dvh;margin:0;padding:0;overflow:auto;border:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1));border-start-start-radius:var(--spui-card-radius,12px);border-end-start-radius:var(--spui-card-radius,12px);background:var(--spui-card-background,var(--spui-ui-surface,#fff));color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424));box-shadow:var(--spui-card-shadow,0 16px 48px #0004)}dialog:not([open]){display:none}:host([position=start]) dialog{inset-inline-start:0;inset-inline-end:auto;border-start-start-radius:0;border-end-start-radius:0;border-start-end-radius:var(--spui-card-radius,12px);border-end-end-radius:var(--spui-card-radius,12px)}:host([position=top]) dialog{inset-block-start:0;inset-block-end:auto;width:100vw;height:min(var(--spui-drawer-height,360px),calc(100dvh - 24px));max-height:calc(100dvh - 24px);border-start-start-radius:0;border-start-end-radius:0;border-end-start-radius:var(--spui-card-radius,12px);border-end-end-radius:var(--spui-card-radius,12px)}:host([position=bottom]) dialog{inset-block-start:auto;inset-block-end:0;width:100vw;height:min(var(--spui-drawer-height,360px),calc(100dvh - 24px));max-height:calc(100dvh - 24px);border-start-start-radius:var(--spui-card-radius,12px);border-start-end-radius:var(--spui-card-radius,12px);border-end-start-radius:0;border-end-end-radius:0}:host([size=small]) dialog{--spui-drawer-width:320px;--spui-drawer-height:256px}:host([size=medium]) dialog{--spui-drawer-width:480px;--spui-drawer-height:360px}:host([size=large]) dialog{--spui-drawer-width:640px;--spui-drawer-height:480px}:host([size=full]) dialog{width:100vw;max-width:100vw;--spui-drawer-width:100vw;--spui-drawer-height:100dvh;border-radius:0}:host([position=top][size=full]) dialog,:host([position=bottom][size=full]) dialog{height:100dvh;max-height:100dvh}dialog::backdrop{background:color-mix(in srgb,var(--spui-ui-text,#242424) 42%,transparent);backdrop-filter:blur(2px)}:host([data-has-custom-backdrop]) dialog::backdrop{background:transparent;backdrop-filter:none}:host([data-has-custom-backdrop]) dialog{background:transparent}::slotted([slot=backdrop]){position:fixed;inset:0;z-index:-1;display:block;background:color-mix(in srgb,var(--spui-ui-text,#242424) 42%,transparent)}:host([data-has-custom-backdrop]) header,:host([data-has-custom-backdrop]) .body,:host([data-has-custom-backdrop]) footer{position:relative;z-index:0;background:var(--spui-card-background,var(--spui-ui-surface,#fff))}header{display:flex;align-items:start;justify-content:space-between;gap:16px;flex:none;padding:20px 20px 0}.header-main{display:flex;align-items:center;gap:12px;flex:1;min-width:0}:host([size=small]) header{flex-wrap:wrap}:host([size=small]) .header-main{flex-basis:100%}.header-navigation{display:flex;align-items:center;flex:none}.header-navigation[hidden]{display:none}.header-navigation slot[name=header-navigation]{display:contents}h2{min-width:0;overflow-wrap:anywhere;margin:0;font-size:20px;line-height:1.3;font-weight:650}.controls{display:flex;align-items:center;gap:4px;flex:none;margin-inline-start:auto}.controls slot[name=header-action]{display:contents}.close{display:inline-grid;place-items:center;flex:none;width:var(--spui-control-height,36px);height:var(--spui-control-height,36px);margin:-5px -6px 0 0;border:0;border-radius:var(--spui-control-radius,6px);background:transparent;color:inherit;cursor:pointer}.close:hover{background:var(--spui-ui-surface-hover,#f5f5f5)}.close:focus-visible{outline:2px solid var(--spui-focus-ring,#005a9e);outline-offset:2px}.body{flex:1;min-height:0;overflow:auto;padding:16px 20px 20px;line-height:1.5}footer{display:flex;justify-content:flex-end;flex-wrap:wrap;gap:8px;flex:none;padding:12px 20px 20px;border-top:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1))}footer[hidden],.close[hidden]{display:none}@media(forced-colors:active){dialog{border-color:CanvasText;box-shadow:none}dialog::backdrop{background:Canvas}.close:focus-visible{outline-color:Highlight}}`;
|
|
209
|
+
const expansionStyle = document.createElement("style");
|
|
210
|
+
expansionStyle.textContent = `${base}dialog{transition:border-radius var(--spui-motion-duration-normal,150ms) var(--spui-motion-easing-standard,cubic-bezier(.2,0,0,1))}:host([expanded]) dialog{width:100vw;max-width:100vw;height:100dvh;max-height:100dvh;--spui-drawer-width:100vw;--spui-drawer-height:100dvh;border-radius:0}:host([expanded]) dialog::backdrop{backdrop-filter:none}header{align-items:center}.controls{display:flex;align-items:center;gap:4px}.expand,.close{display:inline-grid;place-items:center;flex:none;width:var(--spui-control-height,36px);height:var(--spui-control-height,36px);margin:0;border:0;border-radius:var(--spui-control-radius,6px);background:transparent;color:inherit;cursor:pointer}.expand:hover,.close:hover{background:var(--spui-ui-surface-hover,#f5f5f5)}.expand:focus-visible,.close:focus-visible{outline:2px solid var(--spui-focus-ring,#005a9e);outline-offset:2px}.expand[hidden],.close[hidden]{display:none}@media(prefers-reduced-motion:reduce){dialog{transition:none}}@media(forced-colors:active){.expand:focus-visible,.close:focus-visible{outline-color:Highlight}}`;
|
|
211
|
+
shadow.append(style, expansionStyle, dialog);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
customElements.define("spui-drawer", SpuiDrawer);
|
|
215
|
+
}
|
|
216
|
+
/** Non-modal, in-flow companion surface for navigation and supporting work. */
|
|
217
|
+
export function defineInlineDrawer() {
|
|
218
|
+
if (customElements.get("spui-inline-drawer"))
|
|
219
|
+
return;
|
|
220
|
+
class SpuiInlineDrawer extends HTMLElement {
|
|
221
|
+
static observedAttributes = ["open", "motion", "position", "size", "separator", "title", "aria-label"];
|
|
222
|
+
connectedCallback() { if (!this.shadowRoot)
|
|
223
|
+
this.render();
|
|
224
|
+
else
|
|
225
|
+
this.sync(); }
|
|
226
|
+
attributeChangedCallback() { if (this.isConnected)
|
|
227
|
+
this.sync(); }
|
|
228
|
+
render() {
|
|
229
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
230
|
+
const aside = document.createElement("aside");
|
|
231
|
+
aside.part.add("surface");
|
|
232
|
+
const header = document.createElement("header");
|
|
233
|
+
header.hidden = true;
|
|
234
|
+
const navigation = document.createElement("nav");
|
|
235
|
+
navigation.className = "header-navigation";
|
|
236
|
+
const navigationSlot = document.createElement("slot");
|
|
237
|
+
navigationSlot.name = "header-navigation";
|
|
238
|
+
navigationSlot.addEventListener("slotchange", () => this.sync());
|
|
239
|
+
navigation.append(navigationSlot);
|
|
240
|
+
const heading = document.createElement("h2");
|
|
241
|
+
const title = document.createElement("span");
|
|
242
|
+
title.className = "fallback-title";
|
|
243
|
+
const titleSlot = document.createElement("slot");
|
|
244
|
+
titleSlot.name = "title";
|
|
245
|
+
titleSlot.addEventListener("slotchange", () => this.sync());
|
|
246
|
+
heading.append(title, titleSlot);
|
|
247
|
+
const controls = document.createElement("div");
|
|
248
|
+
controls.className = "controls";
|
|
249
|
+
const headerAction = document.createElement("slot");
|
|
250
|
+
headerAction.name = "header-action";
|
|
251
|
+
headerAction.addEventListener("slotchange", () => this.sync());
|
|
252
|
+
controls.append(headerAction);
|
|
253
|
+
header.append(navigation, heading, controls);
|
|
254
|
+
const body = document.createElement("div");
|
|
255
|
+
body.className = "body";
|
|
256
|
+
body.append(document.createElement("slot"));
|
|
257
|
+
const footer = document.createElement("footer");
|
|
258
|
+
footer.hidden = true;
|
|
259
|
+
const actions = document.createElement("slot");
|
|
260
|
+
actions.name = "actions";
|
|
261
|
+
actions.addEventListener("slotchange", () => this.sync());
|
|
262
|
+
footer.append(actions);
|
|
263
|
+
aside.append(header, body, footer);
|
|
264
|
+
const style = document.createElement("style");
|
|
265
|
+
style.textContent = `${base}:host{display:block;min-width:0;max-width:100%}:host(:not([open]):not([motion])){display:none}aside{box-sizing:border-box;display:flex;flex-direction:column;flex:none;inline-size:min(var(--spui-inline-drawer-width,320px),100%);min-inline-size:0;block-size:100%;min-block-size:0;overflow:auto;background:var(--spui-card-background,var(--spui-ui-surface,#fff));color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424))}:host([position=end]) aside{margin-inline-start:auto}:host([position=bottom]) aside,:host([position=top]) aside{inline-size:100%;block-size:auto}:host([size=small]) aside{--spui-inline-drawer-width:240px}:host([size=medium]) aside{--spui-inline-drawer-width:320px}:host([size=large]) aside{--spui-inline-drawer-width:420px}:host([size=full]) aside{--spui-inline-drawer-width:100%}:host([separator]) aside{border-inline-end:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1))}:host([position=end][separator]) aside{border-inline-end:0;border-inline-start:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1))}:host([position=bottom][separator]) aside{border-inline:0;border-block-start:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1))}:host([position=top][separator]) aside{border-inline:0;border-block-end:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1))}header{display:flex;align-items:center;gap:12px;flex:none;padding:16px 16px 8px}header[hidden],footer[hidden]{display:none}.header-navigation{display:flex;align-items:center;flex:none}.header-navigation[hidden]{display:none}.controls{display:flex;align-items:center;gap:8px;margin-inline-start:auto}.controls slot{display:contents}h2{margin:0;font-size:18px;line-height:1.35;font-weight:600}.body{flex:1;min-height:0;overflow:auto;padding:12px 16px 16px;line-height:1.5}footer{display:flex;justify-content:flex-end;flex-wrap:wrap;gap:8px;flex:none;padding:12px 16px;border-block-start:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1))}@media(forced-colors:active){aside{border-color:CanvasText}}`;
|
|
266
|
+
shadow.append(style, aside);
|
|
267
|
+
this.sync();
|
|
268
|
+
}
|
|
269
|
+
sync() {
|
|
270
|
+
const aside = this.shadowRoot?.querySelector("aside");
|
|
271
|
+
const heading = this.shadowRoot?.querySelector(".fallback-title");
|
|
272
|
+
const titleSlot = this.shadowRoot?.querySelector('slot[name="title"]');
|
|
273
|
+
const titleNodes = titleSlot?.assignedNodes({ flatten: true }) ?? [];
|
|
274
|
+
const actionsSlot = this.shadowRoot?.querySelector('slot[name="actions"]');
|
|
275
|
+
const actions = this.shadowRoot?.querySelector("footer");
|
|
276
|
+
if (aside) {
|
|
277
|
+
const open = this.hasAttribute("open");
|
|
278
|
+
aside.inert = !open;
|
|
279
|
+
aside.setAttribute("aria-hidden", String(!open));
|
|
280
|
+
const titleText = titleNodes.map(node => node.textContent ?? "").join(" ").trim();
|
|
281
|
+
const label = this.getAttribute("aria-label") ?? this.getAttribute("title") ?? titleText;
|
|
282
|
+
if (label)
|
|
283
|
+
aside.setAttribute("aria-label", label);
|
|
284
|
+
else
|
|
285
|
+
aside.removeAttribute("aria-label");
|
|
286
|
+
}
|
|
287
|
+
if (heading) {
|
|
288
|
+
heading.textContent = this.getAttribute("title") ?? "";
|
|
289
|
+
heading.hidden = titleNodes.length > 0;
|
|
290
|
+
}
|
|
291
|
+
const header = this.shadowRoot?.querySelector("header");
|
|
292
|
+
const navSlot = this.shadowRoot?.querySelector('slot[name="header-navigation"]');
|
|
293
|
+
const nav = this.shadowRoot?.querySelector(".header-navigation");
|
|
294
|
+
const hasNavigation = Boolean(navSlot?.assignedElements().length);
|
|
295
|
+
if (nav)
|
|
296
|
+
nav.hidden = !hasNavigation;
|
|
297
|
+
const headerActionSlot = this.shadowRoot?.querySelector('slot[name="header-action"]');
|
|
298
|
+
const hasHeaderAction = Boolean(headerActionSlot?.assignedElements().length);
|
|
299
|
+
if (header)
|
|
300
|
+
header.hidden = !this.getAttribute("title") && !titleNodes.length && !hasNavigation && !hasHeaderAction;
|
|
301
|
+
if (titleSlot)
|
|
302
|
+
titleSlot.hidden = titleNodes.length === 0;
|
|
303
|
+
if (actions && actionsSlot)
|
|
304
|
+
actions.hidden = actionsSlot.assignedElements().length === 0;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
customElements.define("spui-inline-drawer", SpuiInlineDrawer);
|
|
308
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getLabelStyle, type LabelSize } from "./label.js";
|
|
2
|
+
export type FieldValidationState = "error" | "warning" | "success" | "none";
|
|
3
|
+
export type FieldOrientation = "vertical" | "horizontal";
|
|
4
|
+
export type FormFieldOptions = {
|
|
5
|
+
id?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
label?: string | Node;
|
|
8
|
+
hint?: string | Node;
|
|
9
|
+
validationMessage?: string | Node;
|
|
10
|
+
validationState?: FieldValidationState;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
orientation?: FieldOrientation;
|
|
14
|
+
size?: LabelSize;
|
|
15
|
+
};
|
|
16
|
+
export declare function mergeFieldIdRefs(existing: string | null, id?: string): string | undefined;
|
|
17
|
+
export declare function getFieldValidationTokens(state: FieldValidationState): {
|
|
18
|
+
foreground: string;
|
|
19
|
+
border: string;
|
|
20
|
+
} | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Compose a visible label, hint, and validation message around any native or
|
|
23
|
+
* custom form control. The returned wrapper owns its control's generated ID.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createFormField(control: HTMLElement, options?: FormFieldOptions): HTMLDivElement;
|
|
26
|
+
export { getLabelStyle };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createLabel, getLabelStyle } from "./label.js";
|
|
2
|
+
let generatedFieldId = 0;
|
|
3
|
+
const validationTokens = {
|
|
4
|
+
error: {
|
|
5
|
+
foreground: "var(--spui-danger-text,var(--spui-semantic-error-text,var(--colorPaletteRedForeground1,#a4262c)))",
|
|
6
|
+
border: "var(--spui-semantic-error-text,var(--colorPaletteRedForeground1,#a4262c))",
|
|
7
|
+
},
|
|
8
|
+
warning: {
|
|
9
|
+
foreground: "var(--spui-warning-text,var(--spui-semantic-warning-text,var(--colorPaletteMarigoldForeground1,#835b00)))",
|
|
10
|
+
border: "var(--spui-semantic-warning-text,var(--colorPaletteMarigoldForeground1,#835b00))",
|
|
11
|
+
},
|
|
12
|
+
success: {
|
|
13
|
+
foreground: "var(--spui-success-text,var(--spui-semantic-success-text,var(--colorPaletteGreenForeground1,#107c10)))",
|
|
14
|
+
border: "var(--spui-semantic-success-text,var(--colorPaletteGreenForeground1,#107c10))",
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export function mergeFieldIdRefs(existing, id) {
|
|
18
|
+
const values = new Set((existing ?? "").split(/\s+/).filter(Boolean));
|
|
19
|
+
if (id)
|
|
20
|
+
values.add(id);
|
|
21
|
+
return values.size ? [...values].join(" ") : undefined;
|
|
22
|
+
}
|
|
23
|
+
export function getFieldValidationTokens(state) {
|
|
24
|
+
return state === "none" ? undefined : validationTokens[state];
|
|
25
|
+
}
|
|
26
|
+
function appendContent(target, value) {
|
|
27
|
+
if (typeof value === "string")
|
|
28
|
+
target.textContent = value;
|
|
29
|
+
else if (value)
|
|
30
|
+
target.append(value);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Compose a visible label, hint, and validation message around any native or
|
|
34
|
+
* custom form control. The returned wrapper owns its control's generated ID.
|
|
35
|
+
*/
|
|
36
|
+
export function createFormField(control, options = {}) {
|
|
37
|
+
const id = options.id ?? `spui-form-field-${++generatedFieldId}`;
|
|
38
|
+
const controlId = control.id || `${id}-control`;
|
|
39
|
+
control.id = controlId;
|
|
40
|
+
const labelId = options.label == null ? undefined : `${id}-label`;
|
|
41
|
+
const hintId = options.hint == null ? undefined : `${id}-hint`;
|
|
42
|
+
const messageId = options.validationMessage == null ? undefined : `${id}-validation`;
|
|
43
|
+
const state = options.validationState ?? (options.validationMessage == null ? "none" : "error");
|
|
44
|
+
const shadowControl = Boolean(control.shadowRoot) || control.localName.includes("-");
|
|
45
|
+
const details = mergeFieldIdRefs(messageId ?? null, hintId);
|
|
46
|
+
const describedBy = shadowControl ? control.getAttribute("aria-describedby") ?? undefined : mergeFieldIdRefs(details ?? null, control.getAttribute("aria-describedby") ?? undefined);
|
|
47
|
+
const contentText = (value) => typeof value === "string" ? value : value?.textContent?.trim() ?? "";
|
|
48
|
+
const accessibleDescription = [control.getAttribute("aria-description"), shadowControl ? contentText(options.validationMessage) : "", shadowControl ? contentText(options.hint) : ""].filter(Boolean).join(" ");
|
|
49
|
+
if (labelId && !shadowControl)
|
|
50
|
+
control.setAttribute("aria-labelledby", mergeFieldIdRefs(control.getAttribute("aria-labelledby"), labelId));
|
|
51
|
+
if (describedBy)
|
|
52
|
+
control.setAttribute("aria-describedby", describedBy);
|
|
53
|
+
else if (shadowControl)
|
|
54
|
+
control.removeAttribute("aria-describedby");
|
|
55
|
+
if (shadowControl && accessibleDescription)
|
|
56
|
+
control.setAttribute("aria-description", accessibleDescription);
|
|
57
|
+
if (options.required) {
|
|
58
|
+
control.setAttribute("required", "");
|
|
59
|
+
control.setAttribute("aria-required", "true");
|
|
60
|
+
}
|
|
61
|
+
if (options.disabled)
|
|
62
|
+
control.setAttribute("disabled", "");
|
|
63
|
+
if (options.validationState !== undefined || options.validationMessage !== undefined) {
|
|
64
|
+
if (state === "error")
|
|
65
|
+
control.setAttribute("aria-invalid", "true");
|
|
66
|
+
else
|
|
67
|
+
control.removeAttribute("aria-invalid");
|
|
68
|
+
}
|
|
69
|
+
const tokens = getFieldValidationTokens(state);
|
|
70
|
+
if (tokens) {
|
|
71
|
+
control.style.setProperty("--spui-control-border", tokens.border);
|
|
72
|
+
control.style.setProperty("--spui-input-border", tokens.border);
|
|
73
|
+
control.style.setProperty("--spui-focus-ring", tokens.border);
|
|
74
|
+
}
|
|
75
|
+
const wrapper = document.createElement("div");
|
|
76
|
+
wrapper.id = id;
|
|
77
|
+
wrapper.className = ["spui-form-field", options.className].filter(Boolean).join(" ");
|
|
78
|
+
wrapper.dataset.orientation = options.orientation ?? "vertical";
|
|
79
|
+
wrapper.dataset.validationState = state;
|
|
80
|
+
wrapper.dataset.size = options.size ?? "medium";
|
|
81
|
+
wrapper.style.display = "grid";
|
|
82
|
+
wrapper.style.gridTemplateColumns = options.orientation === "horizontal" ? "minmax(8rem, 1fr) minmax(0, 2fr)" : "minmax(0, 1fr)";
|
|
83
|
+
wrapper.style.columnGap = "var(--spui-field-column-gap,16px)";
|
|
84
|
+
wrapper.style.rowGap = "var(--spui-field-gap,4px)";
|
|
85
|
+
wrapper.style.alignItems = "start";
|
|
86
|
+
wrapper.style.color = "var(--spui-ui-text,var(--spui-semantic-body-text,#323130))";
|
|
87
|
+
wrapper.style.fontFamily = "var(--spui-font-family,inherit)";
|
|
88
|
+
if (options.label != null) {
|
|
89
|
+
const label = createLabel(options.label, { htmlFor: controlId, id: labelId, size: options.size, required: options.required, disabled: Boolean(options.disabled || control.matches(":disabled") || control.hasAttribute("disabled")) });
|
|
90
|
+
label.style.gridArea = options.orientation === "horizontal" ? "1 / 1 / span 3 / 2" : "auto";
|
|
91
|
+
const accessibleLabel = label.textContent?.replace("*", "").trim();
|
|
92
|
+
if (accessibleLabel)
|
|
93
|
+
control.setAttribute("aria-label", accessibleLabel);
|
|
94
|
+
wrapper.append(label);
|
|
95
|
+
}
|
|
96
|
+
control.style.gridArea = options.orientation === "horizontal" ? "1 / 2 / span 3 / 3" : "auto";
|
|
97
|
+
wrapper.append(control);
|
|
98
|
+
if (options.hint != null) {
|
|
99
|
+
const hint = document.createElement("div");
|
|
100
|
+
hint.id = hintId;
|
|
101
|
+
hint.dataset.fieldHint = "";
|
|
102
|
+
hint.style.gridArea = options.orientation === "horizontal" ? "2 / 2" : "auto";
|
|
103
|
+
hint.style.color = "var(--spui-ui-muted,var(--spui-semantic-body-subtext,#616161))";
|
|
104
|
+
hint.style.fontSize = "var(--spui-field-hint-size,12px)";
|
|
105
|
+
appendContent(hint, options.hint);
|
|
106
|
+
wrapper.append(hint);
|
|
107
|
+
}
|
|
108
|
+
if (options.validationMessage != null) {
|
|
109
|
+
const message = document.createElement("div");
|
|
110
|
+
message.id = messageId;
|
|
111
|
+
message.dataset.fieldValidation = state;
|
|
112
|
+
if (state === "error" || state === "warning")
|
|
113
|
+
message.setAttribute("role", "alert");
|
|
114
|
+
message.style.gridArea = options.orientation === "horizontal" ? "3 / 2" : "auto";
|
|
115
|
+
message.style.display = "flex";
|
|
116
|
+
message.style.alignItems = "baseline";
|
|
117
|
+
message.style.gap = "6px";
|
|
118
|
+
message.style.fontSize = "var(--spui-field-message-size,12px)";
|
|
119
|
+
if (state !== "none")
|
|
120
|
+
message.style.color = getFieldValidationTokens(state).foreground;
|
|
121
|
+
const icon = document.createElement("span");
|
|
122
|
+
icon.setAttribute("aria-hidden", "true");
|
|
123
|
+
icon.textContent = state === "success" ? "✓" : state === "warning" ? "!" : state === "error" ? "!" : "";
|
|
124
|
+
if (icon.textContent)
|
|
125
|
+
message.append(icon);
|
|
126
|
+
const content = document.createElement("span");
|
|
127
|
+
appendContent(content, options.validationMessage);
|
|
128
|
+
message.append(content);
|
|
129
|
+
wrapper.append(message);
|
|
130
|
+
}
|
|
131
|
+
return wrapper;
|
|
132
|
+
}
|
|
133
|
+
export { getLabelStyle };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function defineField(): void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { base } from "./shared.js";
|
|
2
|
+
export function defineField() {
|
|
3
|
+
if (customElements.get("spui-field"))
|
|
4
|
+
return;
|
|
5
|
+
class SpuiField extends HTMLElement {
|
|
6
|
+
static observedAttributes = ["label", "value", "type", "disabled", "required", "read-only", "placeholder", "aria-label", "aria-labelledby", "aria-description", "aria-describedby", "aria-invalid"];
|
|
7
|
+
connectedCallback() { this.render(); }
|
|
8
|
+
attributeChangedCallback(name) {
|
|
9
|
+
if (!this.isConnected)
|
|
10
|
+
return;
|
|
11
|
+
const input = this.shadowRoot?.querySelector("input");
|
|
12
|
+
if (!input)
|
|
13
|
+
return;
|
|
14
|
+
if (name === "value") {
|
|
15
|
+
const value = this.getAttribute(name) ?? "";
|
|
16
|
+
if (input.value !== value)
|
|
17
|
+
input.value = value;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (name === "label") {
|
|
21
|
+
const label = this.shadowRoot?.querySelector("label");
|
|
22
|
+
if (label)
|
|
23
|
+
label.textContent = this.getAttribute(name) ?? "";
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (name === "disabled")
|
|
27
|
+
input.disabled = this.hasAttribute(name);
|
|
28
|
+
if (name === "required")
|
|
29
|
+
input.required = this.hasAttribute(name);
|
|
30
|
+
if (name === "read-only")
|
|
31
|
+
input.readOnly = this.hasAttribute(name);
|
|
32
|
+
if (name === "placeholder")
|
|
33
|
+
input.placeholder = this.getAttribute(name) ?? "";
|
|
34
|
+
if (name === "aria-label" || name === "aria-labelledby" || name === "aria-description" || name === "aria-describedby" || name === "aria-invalid") {
|
|
35
|
+
const value = this.getAttribute(name);
|
|
36
|
+
value === null ? input.removeAttribute(name) : input.setAttribute(name, value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
render() {
|
|
40
|
+
const shadow = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
41
|
+
const id = `field-${Math.random().toString(36).slice(2)}`;
|
|
42
|
+
const label = document.createElement("label");
|
|
43
|
+
label.htmlFor = id;
|
|
44
|
+
label.textContent = this.getAttribute("label") ?? "";
|
|
45
|
+
label.part.add("label");
|
|
46
|
+
const input = document.createElement("input");
|
|
47
|
+
input.id = id;
|
|
48
|
+
input.type = this.getAttribute("type") ?? "text";
|
|
49
|
+
input.value = this.getAttribute("value") ?? "";
|
|
50
|
+
input.disabled = this.hasAttribute("disabled");
|
|
51
|
+
input.required = this.hasAttribute("required");
|
|
52
|
+
input.readOnly = this.hasAttribute("read-only");
|
|
53
|
+
input.placeholder = this.getAttribute("placeholder") ?? "";
|
|
54
|
+
input.part.add("control");
|
|
55
|
+
for (const name of ["aria-label", "aria-labelledby", "aria-description", "aria-describedby", "aria-invalid"]) {
|
|
56
|
+
const value = this.getAttribute(name);
|
|
57
|
+
if (value !== null)
|
|
58
|
+
input.setAttribute(name, value);
|
|
59
|
+
}
|
|
60
|
+
input.addEventListener("input", () => this.dispatchEvent(new CustomEvent("spui-input", { bubbles: true, composed: true, detail: { value: input.value } })));
|
|
61
|
+
const style = document.createElement("style");
|
|
62
|
+
style.textContent = `${base}:host{display:grid;gap:var(--spui-control-gap,6px)}label:empty{display:none}label{font-size:14px;font-weight:600;color:var(--spui-ui-muted,var(--spui-semantic-body-text,inherit))}input{min-height:var(--spui-control-height,36px);padding-inline:var(--spui-control-padding-inline,12px);border:1px solid var(--spui-control-border,var(--spui-ui-stroke,var(--spui-semantic-input-border,var(--colorNeutralStroke1,#8a8886))));border-radius:var(--spui-control-radius,4px);background:var(--spui-control-background,var(--spui-ui-surface,var(--spui-semantic-input-background,var(--colorNeutralBackground1,#fff))));box-shadow:var(--spui-control-shadow,none);color:var(--spui-ui-text,var(--spui-semantic-body-text,inherit))}input:disabled{opacity:.55}@media(forced-colors:active){input{border-color:FieldText}}`;
|
|
63
|
+
shadow.replaceChildren(style, label, input);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
customElements.define("spui-field", SpuiField);
|
|
67
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type FileUploadError = {
|
|
2
|
+
code: "too-many-files" | "file-too-large" | "file-type-not-accepted";
|
|
3
|
+
file?: File;
|
|
4
|
+
};
|
|
5
|
+
/** File selection surface. Uploading and SharePoint persistence remain the consumer's responsibility. */
|
|
6
|
+
export declare function defineFileUpload(): void;
|