@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.
Files changed (156) hide show
  1. package/AGENTS.md +211 -0
  2. package/LICENSE +21 -0
  3. package/README.md +897 -2
  4. package/components.json +5811 -0
  5. package/dist/appearance.d.ts +6 -0
  6. package/dist/appearance.js +217 -0
  7. package/dist/elements/accordion.d.ts +9 -0
  8. package/dist/elements/accordion.js +338 -0
  9. package/dist/elements/alert.d.ts +2 -0
  10. package/dist/elements/alert.js +62 -0
  11. package/dist/elements/avatar-group-primitives.d.ts +3 -0
  12. package/dist/elements/avatar-group-primitives.js +189 -0
  13. package/dist/elements/avatar-group.d.ts +2 -0
  14. package/dist/elements/avatar-group.js +110 -0
  15. package/dist/elements/avatar.d.ts +4 -0
  16. package/dist/elements/avatar.js +251 -0
  17. package/dist/elements/badge.d.ts +8 -0
  18. package/dist/elements/badge.js +182 -0
  19. package/dist/elements/breadcrumb.d.ts +4 -0
  20. package/dist/elements/breadcrumb.js +233 -0
  21. package/dist/elements/button-group.d.ts +1 -0
  22. package/dist/elements/button-group.js +20 -0
  23. package/dist/elements/button-variants.d.ts +6 -0
  24. package/dist/elements/button-variants.js +339 -0
  25. package/dist/elements/button.d.ts +5 -0
  26. package/dist/elements/button.js +233 -0
  27. package/dist/elements/card-primitives.d.ts +3 -0
  28. package/dist/elements/card-primitives.js +83 -0
  29. package/dist/elements/card.d.ts +5 -0
  30. package/dist/elements/card.js +213 -0
  31. package/dist/elements/carousel.d.ts +92 -0
  32. package/dist/elements/carousel.js +1112 -0
  33. package/dist/elements/color-picker.d.ts +24 -0
  34. package/dist/elements/color-picker.js +1004 -0
  35. package/dist/elements/combobox.d.ts +1 -0
  36. package/dist/elements/combobox.js +1012 -0
  37. package/dist/elements/data-grid-model.d.ts +117 -0
  38. package/dist/elements/data-grid-model.js +294 -0
  39. package/dist/elements/data-grid.d.ts +29 -0
  40. package/dist/elements/data-grid.js +1567 -0
  41. package/dist/elements/date-picker.d.ts +1 -0
  42. package/dist/elements/date-picker.js +486 -0
  43. package/dist/elements/dialog.d.ts +23 -0
  44. package/dist/elements/dialog.js +409 -0
  45. package/dist/elements/divider.d.ts +2 -0
  46. package/dist/elements/divider.js +66 -0
  47. package/dist/elements/drawer.d.ts +3 -0
  48. package/dist/elements/drawer.js +308 -0
  49. package/dist/elements/field-composition.d.ts +26 -0
  50. package/dist/elements/field-composition.js +133 -0
  51. package/dist/elements/field.d.ts +1 -0
  52. package/dist/elements/field.js +67 -0
  53. package/dist/elements/file-upload.d.ts +6 -0
  54. package/dist/elements/file-upload.js +211 -0
  55. package/dist/elements/floating-position.d.ts +26 -0
  56. package/dist/elements/floating-position.js +39 -0
  57. package/dist/elements/image.d.ts +28 -0
  58. package/dist/elements/image.js +38 -0
  59. package/dist/elements/info.d.ts +9 -0
  60. package/dist/elements/info.js +102 -0
  61. package/dist/elements/input.d.ts +5 -0
  62. package/dist/elements/input.js +255 -0
  63. package/dist/elements/label.d.ts +15 -0
  64. package/dist/elements/label.js +56 -0
  65. package/dist/elements/link.d.ts +1 -0
  66. package/dist/elements/link.js +92 -0
  67. package/dist/elements/list.d.ts +19 -0
  68. package/dist/elements/list.js +297 -0
  69. package/dist/elements/menu.d.ts +33 -0
  70. package/dist/elements/menu.js +1103 -0
  71. package/dist/elements/message-bar.d.ts +10 -0
  72. package/dist/elements/message-bar.js +299 -0
  73. package/dist/elements/nav.d.ts +32 -0
  74. package/dist/elements/nav.js +791 -0
  75. package/dist/elements/overflow.d.ts +9 -0
  76. package/dist/elements/overflow.js +218 -0
  77. package/dist/elements/persona.d.ts +3 -0
  78. package/dist/elements/persona.js +125 -0
  79. package/dist/elements/popover.d.ts +77 -0
  80. package/dist/elements/popover.js +840 -0
  81. package/dist/elements/progress-bar.d.ts +4 -0
  82. package/dist/elements/progress-bar.js +82 -0
  83. package/dist/elements/radio-group.d.ts +1 -0
  84. package/dist/elements/radio-group.js +303 -0
  85. package/dist/elements/rating-display.d.ts +2 -0
  86. package/dist/elements/rating-display.js +125 -0
  87. package/dist/elements/rating.d.ts +2 -0
  88. package/dist/elements/rating.js +206 -0
  89. package/dist/elements/rich-text-editor.d.ts +18 -0
  90. package/dist/elements/rich-text-editor.js +508 -0
  91. package/dist/elements/search.d.ts +3 -0
  92. package/dist/elements/search.js +207 -0
  93. package/dist/elements/select.d.ts +6 -0
  94. package/dist/elements/select.js +291 -0
  95. package/dist/elements/shared.d.ts +19 -0
  96. package/dist/elements/shared.js +396 -0
  97. package/dist/elements/skeleton.d.ts +6 -0
  98. package/dist/elements/skeleton.js +91 -0
  99. package/dist/elements/slider.d.ts +1 -0
  100. package/dist/elements/slider.js +248 -0
  101. package/dist/elements/spin-button.d.ts +7 -0
  102. package/dist/elements/spin-button.js +499 -0
  103. package/dist/elements/spinner.d.ts +4 -0
  104. package/dist/elements/spinner.js +124 -0
  105. package/dist/elements/swatch-picker.d.ts +5 -0
  106. package/dist/elements/swatch-picker.js +363 -0
  107. package/dist/elements/table.d.ts +21 -0
  108. package/dist/elements/table.js +261 -0
  109. package/dist/elements/tabs.d.ts +1 -0
  110. package/dist/elements/tabs.js +276 -0
  111. package/dist/elements/tag-picker.d.ts +29 -0
  112. package/dist/elements/tag-picker.js +697 -0
  113. package/dist/elements/tags.d.ts +21 -0
  114. package/dist/elements/tags.js +421 -0
  115. package/dist/elements/teaching-popover.d.ts +32 -0
  116. package/dist/elements/teaching-popover.js +412 -0
  117. package/dist/elements/text.d.ts +9 -0
  118. package/dist/elements/text.js +75 -0
  119. package/dist/elements/textarea.d.ts +1 -0
  120. package/dist/elements/textarea.js +182 -0
  121. package/dist/elements/toast.d.ts +25 -0
  122. package/dist/elements/toast.js +337 -0
  123. package/dist/elements/toaster.d.ts +6 -0
  124. package/dist/elements/toaster.js +356 -0
  125. package/dist/elements/toggle.d.ts +2 -0
  126. package/dist/elements/toggle.js +246 -0
  127. package/dist/elements/toolbar.d.ts +12 -0
  128. package/dist/elements/toolbar.js +381 -0
  129. package/dist/elements/tooltip.d.ts +76 -0
  130. package/dist/elements/tooltip.js +510 -0
  131. package/dist/elements/tree-model.d.ts +19 -0
  132. package/dist/elements/tree-model.js +34 -0
  133. package/dist/elements/tree.d.ts +5 -0
  134. package/dist/elements/tree.js +273 -0
  135. package/dist/elements/view-card.d.ts +2 -0
  136. package/dist/elements/view-card.js +78 -0
  137. package/dist/elements/virtual-list.d.ts +41 -0
  138. package/dist/elements/virtual-list.js +369 -0
  139. package/dist/elements.d.ts +72 -0
  140. package/dist/elements.js +207 -0
  141. package/dist/index.d.ts +76 -0
  142. package/dist/index.js +66 -0
  143. package/dist/react.d.ts +4546 -0
  144. package/dist/react.js +6837 -0
  145. package/dist/theme.d.ts +169 -0
  146. package/dist/theme.js +167 -0
  147. package/dist/virtualizer-hooks.d.ts +80 -0
  148. package/dist/virtualizer-hooks.js +253 -0
  149. package/package.json +87 -4
  150. package/scripts/generate-token-index.mjs +43 -0
  151. package/scripts/sync-component-catalog-signatures.mjs +55 -0
  152. package/scripts/validate-component-catalog.mjs +44 -0
  153. package/skills/sharepoint-ui/SKILL.md +12 -0
  154. package/skills/sharepoint-ui/references/choosing-components.md +20 -0
  155. package/skills/sharepoint-ui/references/sharepoint-patterns.md +17 -0
  156. package/tokens.json +3777 -0
@@ -0,0 +1,207 @@
1
+ import { base, stopHostAccessibleNameSync, syncHostAccessibleName } from "./shared.js";
2
+ export function defineSearchBox() {
3
+ if (customElements.get("spui-search-box"))
4
+ return;
5
+ class SpuiSearchBox extends HTMLElement {
6
+ static formAssociated = true;
7
+ static observedAttributes = ["label", "value", "placeholder", "type", "disabled", "required", "read-only", "name", "autocomplete", "maxlength", "minlength", "pattern", "inputmode", "size", "appearance", "clear-label", "aria-label", "aria-labelledby", "aria-description", "aria-describedby", "aria-invalid", "aria-required"];
8
+ #internals = this.attachInternals();
9
+ #value = "";
10
+ #dirty = false;
11
+ #formDisabled = false;
12
+ get form() { return this.#internals.form; }
13
+ get value() { return this.#value; }
14
+ set value(value) { this.setValue(String(value ?? ""), true); }
15
+ get defaultValue() { return this.getAttribute("value") ?? ""; }
16
+ set defaultValue(value) { this.setAttribute("value", value); }
17
+ get name() { return this.getAttribute("name") ?? ""; }
18
+ set name(value) { this.setAttribute("name", value); }
19
+ connectedCallback() {
20
+ if (!this.#dirty)
21
+ this.#value = this.getAttribute("value") ?? "";
22
+ this.render();
23
+ }
24
+ disconnectedCallback() { stopHostAccessibleNameSync(this); }
25
+ attributeChangedCallback(name, _oldValue, value) {
26
+ if (!this.isConnected || !this.shadowRoot?.querySelector("input"))
27
+ return;
28
+ if (name === "value") {
29
+ if (!this.#dirty)
30
+ this.setValue(value ?? "", false);
31
+ return;
32
+ }
33
+ if (name === "label") {
34
+ const label = this.shadowRoot?.querySelector("label");
35
+ if (label)
36
+ label.textContent = value ?? "";
37
+ }
38
+ if (name === "placeholder")
39
+ this.input().placeholder = value ?? "";
40
+ if (name === "type")
41
+ this.input().type = value || "search";
42
+ if (name === "disabled")
43
+ this.input().disabled = value !== null || this.#formDisabled;
44
+ if (name === "required") {
45
+ this.input().required = value !== null;
46
+ this.syncFormValue();
47
+ }
48
+ if (name === "read-only")
49
+ this.input().readOnly = value !== null;
50
+ if (["autocomplete", "maxlength", "minlength", "pattern", "inputmode"].includes(name)) {
51
+ if (value === null)
52
+ this.input().removeAttribute(name);
53
+ else
54
+ this.input().setAttribute(name, value);
55
+ }
56
+ if (name === "aria-label" || name === "aria-labelledby" || name === "aria-description" || name === "aria-describedby" || name === "aria-invalid" || name === "aria-required") {
57
+ if (value === null)
58
+ this.input().removeAttribute(name);
59
+ else
60
+ this.input().setAttribute(name, value);
61
+ }
62
+ if (name === "size")
63
+ this.shadowRoot.querySelector(".control").dataset.size = value || "medium";
64
+ if (name === "appearance")
65
+ this.shadowRoot.querySelector(".control").dataset.appearance = value || "outline";
66
+ if (name === "clear-label")
67
+ this.shadowRoot.querySelector("[part=clear-button]").setAttribute("aria-label", value || "Clear search");
68
+ if (name === "disabled" || name === "read-only")
69
+ this.setValue(this.#value, false);
70
+ this.syncFormValue();
71
+ }
72
+ formResetCallback() { this.#dirty = false; this.setValue(this.defaultValue, false); }
73
+ formStateRestoreCallback(state) { if (typeof state === "string")
74
+ this.setValue(state, false); }
75
+ formDisabledCallback(disabled) {
76
+ this.#formDisabled = disabled;
77
+ const input = this.shadowRoot?.querySelector("input");
78
+ if (input)
79
+ input.disabled = disabled || this.hasAttribute("disabled");
80
+ const clear = this.shadowRoot?.querySelector("[part=clear-button]");
81
+ if (clear)
82
+ clear.hidden = !this.#value || Boolean(input?.disabled) || Boolean(input?.readOnly);
83
+ }
84
+ input() { return this.shadowRoot.querySelector("input"); }
85
+ setValue(value, dirty) {
86
+ this.#value = value;
87
+ if (dirty)
88
+ this.#dirty = true;
89
+ const input = this.shadowRoot?.querySelector("input");
90
+ if (input && input.value !== value)
91
+ input.value = value;
92
+ const clear = this.shadowRoot?.querySelector("[part=clear-button]");
93
+ if (clear)
94
+ clear.hidden = !value || Boolean(input?.disabled) || Boolean(input?.readOnly);
95
+ this.syncFormValue();
96
+ }
97
+ syncFormValue() {
98
+ if (!this.#internals)
99
+ return;
100
+ const input = this.shadowRoot?.querySelector("input");
101
+ if (input)
102
+ syncHostAccessibleName(this, input);
103
+ this.#internals.setFormValue(this.#value, this.#value);
104
+ if (input && !input.validity.valid) {
105
+ const invalidFlags = ["badInput", "customError", "patternMismatch", "rangeOverflow", "rangeUnderflow", "stepMismatch", "tooLong", "tooShort", "typeMismatch", "valueMissing"];
106
+ const flags = {};
107
+ for (const flag of invalidFlags)
108
+ if (input.validity[flag])
109
+ flags[flag] = true;
110
+ this.#internals.setValidity(flags, input.validationMessage, input);
111
+ }
112
+ else
113
+ this.#internals.setValidity({});
114
+ }
115
+ render() {
116
+ const shadow = this.shadowRoot ?? this.attachShadow({ mode: "open" });
117
+ const label = document.createElement("label");
118
+ label.part.add("label");
119
+ label.htmlFor = "search-input";
120
+ label.textContent = this.getAttribute("label") ?? "";
121
+ const control = document.createElement("div");
122
+ control.className = "control";
123
+ control.dataset.size = this.getAttribute("size") || "medium";
124
+ control.dataset.appearance = this.getAttribute("appearance") || "outline";
125
+ const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
126
+ icon.setAttribute("viewBox", "0 0 20 20");
127
+ icon.setAttribute("aria-hidden", "true");
128
+ icon.setAttribute("focusable", "false");
129
+ icon.setAttribute("part", "search-icon");
130
+ icon.innerHTML = '<circle cx="8.5" cy="8.5" r="5.75"/><path d="m13 13 4.25 4.25"/>';
131
+ const contentBefore = document.createElement("slot");
132
+ contentBefore.name = "content-before";
133
+ contentBefore.append(icon);
134
+ const input = document.createElement("input");
135
+ input.type = this.getAttribute("type") || "search";
136
+ input.value = this.#value;
137
+ input.placeholder = this.getAttribute("placeholder") ?? "";
138
+ input.disabled = this.#formDisabled || this.hasAttribute("disabled");
139
+ input.required = this.hasAttribute("required");
140
+ input.readOnly = this.hasAttribute("read-only");
141
+ input.id = "search-input";
142
+ input.part.add("control");
143
+ for (const name of ["autocomplete", "maxlength", "minlength", "pattern", "inputmode"]) {
144
+ const value = this.getAttribute(name);
145
+ if (value !== null)
146
+ input.setAttribute(name, value);
147
+ }
148
+ for (const name of ["aria-label", "aria-labelledby", "aria-description", "aria-describedby", "aria-invalid", "aria-required"]) {
149
+ const value = this.getAttribute(name);
150
+ if (value !== null)
151
+ input.setAttribute(name, value);
152
+ }
153
+ const clear = document.createElement("span");
154
+ clear.className = "dismiss";
155
+ clear.setAttribute("role", "button");
156
+ clear.tabIndex = -1;
157
+ clear.part.add("clear-button");
158
+ clear.setAttribute("aria-label", this.getAttribute("clear-label") || "Clear search");
159
+ clear.hidden = !this.#value || input.disabled || input.readOnly;
160
+ const dismiss = document.createElement("slot");
161
+ dismiss.name = "dismiss";
162
+ const dismissIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
163
+ dismissIcon.setAttribute("viewBox", "0 0 16 16");
164
+ dismissIcon.setAttribute("aria-hidden", "true");
165
+ dismissIcon.setAttribute("focusable", "false");
166
+ dismissIcon.innerHTML = '<path d="m4 4 8 8m0-8-8 8"/>';
167
+ dismiss.append(dismissIcon);
168
+ clear.append(dismiss);
169
+ clear.addEventListener("click", event => {
170
+ this.setValue("", true);
171
+ input.focus();
172
+ this.dispatchEvent(new CustomEvent("spui-input", { bubbles: true, composed: true, detail: { value: "", reason: "clear", sourceEvent: event } }));
173
+ this.dispatchEvent(new CustomEvent("spui-clear", { bubbles: true, composed: true }));
174
+ });
175
+ clear.addEventListener("keydown", event => {
176
+ if (event.key !== "Enter" && event.key !== " ")
177
+ return;
178
+ event.preventDefault();
179
+ clear.click();
180
+ });
181
+ input.addEventListener("input", event => {
182
+ this.setValue(input.value, true);
183
+ this.dispatchEvent(new CustomEvent("spui-input", { bubbles: true, composed: true, detail: { value: input.value, reason: "input", sourceEvent: event } }));
184
+ });
185
+ input.addEventListener("keydown", event => {
186
+ if (event.key !== "Enter" || event.isComposing)
187
+ return;
188
+ this.dispatchEvent(new CustomEvent("spui-search", { bubbles: true, composed: true, detail: { value: input.value } }));
189
+ if (this.#internals.form) {
190
+ event.preventDefault();
191
+ this.#internals.form.requestSubmit();
192
+ }
193
+ });
194
+ const afterSlot = document.createElement("slot");
195
+ afterSlot.name = "content-after";
196
+ const after = document.createElement("span");
197
+ after.className = "content-after";
198
+ after.append(afterSlot, clear);
199
+ control.append(contentBefore, input, after);
200
+ const style = document.createElement("style");
201
+ style.textContent = `${base}:host{display:grid;gap:var(--spui-control-gap,6px);min-width:0}label:empty{display:none}label{font-size:14px;font-weight:600;color:var(--spui-ui-muted,var(--spui-semantic-body-text,inherit))}.control{box-sizing:border-box;display:flex;align-items:center;gap:8px;min-width:0;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))}.control[data-size=small]{min-height:28px;font-size:13px}.control[data-size=large]{min-height:44px;font-size:16px}.control[data-appearance=underline]{border:0;border-bottom:1px solid var(--spui-control-border,var(--spui-ui-stroke,#8a8886));border-radius:0}.control[data-appearance=filled-darker],.control[data-appearance=filled-darker-shadow]{border-color:transparent;background:var(--spui-input-filled-darker,var(--spui-ui-surface-hover,var(--spui-semantic-input-background,#f3f2f1)))}.control[data-appearance=filled-lighter],.control[data-appearance=filled-lighter-shadow]{border-color:transparent;background:var(--spui-input-filled-lighter,var(--spui-base-surface,var(--spui-ui-canvas,#faf9f8)))}.control[data-appearance=filled-darker-shadow],.control[data-appearance=filled-lighter-shadow]{box-shadow:var(--spui-input-filled-shadow,var(--spui-control-shadow,var(--shadow2,0 1px 2px rgb(0 0 0 / 20%))))}.control:focus-within{border-color:var(--spui-focus-ring,var(--spui-semantic-focus-border,var(--colorStrokeFocus2,#005a9e)))}.control:focus-within[data-appearance=underline]{border-bottom-width:2px}slot[name=content-before],.content-after{display:inline-flex;align-items:center;flex:none;gap:4px}slot[name=content-after]{display:inline-flex;align-items:center;gap:4px}input{box-sizing:border-box;flex:1;min-width:0;width:100%;padding:0;border:0;outline:0;background:transparent;color:inherit;font:inherit}input::placeholder{color:var(--spui-ui-muted,var(--spui-semantic-body-subtext,#616161));opacity:1}input::-webkit-search-cancel-.dismiss{display:none}svg[part=search-icon]{width:18px;height:18px;flex:none;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}.dismiss{display:grid;place-items:center;flex:none;width:28px;height:28px;padding:5px;border:0;border-radius:var(--spui-control-radius,4px);background:transparent;color:inherit;cursor:pointer}.dismiss[hidden]{display:none}.dismiss:hover{background:var(--spui-ui-surface-hover,var(--spui-ui-canvas,#f5f5f5))}.dismiss:focus-visible{outline:2px solid var(--spui-focus-ring,var(--spui-ui-accent,#0078d4));outline-offset:1px}.dismiss svg{width:14px;height:14px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round}@media(forced-colors:active){.control{border-color:FieldText}.control:focus-within,.dismiss:focus-visible{outline-color:Highlight}}`;
202
+ shadow.replaceChildren(style, label, control);
203
+ this.syncFormValue();
204
+ }
205
+ }
206
+ customElements.define("spui-search-box", SpuiSearchBox);
207
+ }
@@ -0,0 +1,6 @@
1
+ export type SelectAppearance = "outline" | "underline" | "filled-darker" | "filled-lighter";
2
+ export type SelectSize = "small" | "medium" | "large";
3
+ export type SelectChangeData = {
4
+ value: string;
5
+ };
6
+ export declare function defineSelect(): void;
@@ -0,0 +1,291 @@
1
+ import { base, rememberNativeFormControlDefaults, stopHostAccessibleNameSync, syncHostAccessibleName } from "./shared.js";
2
+ export function defineSelect() {
3
+ if (customElements.get("spui-select"))
4
+ return;
5
+ class SpuiSelect extends HTMLElement {
6
+ static formAssociated = true;
7
+ static observedAttributes = ["label", "value", "default-value", "auto-complete", "autofocus", "tabindex", "appearance", "size", "disabled", "required", "name", "multiple", "form", "aria-label", "aria-labelledby", "aria-description", "aria-describedby", "aria-invalid"];
8
+ internals;
9
+ observer;
10
+ currentValue;
11
+ boundSelect;
12
+ formDisabled = false;
13
+ slotSelectDefaults;
14
+ initialSelectedValues;
15
+ requestedTabIndex;
16
+ slotSelectTabIndex;
17
+ slotSelectTabIndexCaptured = false;
18
+ normalizingTabIndex = false;
19
+ get form() { return this.internals?.form ?? null; }
20
+ cloneOptionContent() {
21
+ return [...this.children]
22
+ .filter(child => child.localName === "option" || child.localName === "optgroup")
23
+ .map(child => child.cloneNode(true));
24
+ }
25
+ handleSelectChange = (event) => {
26
+ const select = event.currentTarget;
27
+ this.currentValue = select.value;
28
+ this.syncFormValue(select);
29
+ this.dispatchEvent(new CustomEvent("spui-change", { detail: { value: select.value, sourceEvent: event }, bubbles: true, composed: true }));
30
+ };
31
+ getSelect() {
32
+ const slot = this.shadowRoot?.querySelector('slot[name="select"]');
33
+ const assigned = slot?.assignedElements().find((element) => element instanceof HTMLSelectElement);
34
+ return assigned ?? this.shadowRoot?.querySelector(".select-fallback") ?? null;
35
+ }
36
+ constructor() {
37
+ super();
38
+ try {
39
+ this.internals = this.attachInternals();
40
+ }
41
+ catch { /* Form association is an enhancement where ElementInternals is unavailable. */ }
42
+ }
43
+ connectedCallback() {
44
+ this.render();
45
+ if (this.hasAttribute("autofocus"))
46
+ this.getSelect()?.focus();
47
+ this.observer = new MutationObserver(records => {
48
+ if (records.some(record => !this.boundSelect?.contains(record.target)))
49
+ this.syncOptions();
50
+ });
51
+ this.observer.observe(this, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ["value", "label", "disabled", "selected"] });
52
+ }
53
+ disconnectedCallback() { this.observer?.disconnect(); stopHostAccessibleNameSync(this); }
54
+ attributeChangedCallback(name, _oldValue, value) {
55
+ if (name === "tabindex" && !this.normalizingTabIndex)
56
+ this.requestedTabIndex = value === null ? undefined : Number(value);
57
+ if (this.normalizingTabIndex || !this.isConnected)
58
+ return;
59
+ const select = this.getSelect();
60
+ if (!select)
61
+ return;
62
+ if (name === "tabindex") {
63
+ this.syncTabIndex(select);
64
+ return;
65
+ }
66
+ if (name === "autofocus") {
67
+ if (value !== null)
68
+ select.focus();
69
+ return;
70
+ }
71
+ if (name === "value")
72
+ this.currentValue = value ?? "";
73
+ if (name === "default-value" && this.currentValue === undefined && this.getAttribute("value") === null)
74
+ this.currentValue = value ?? "";
75
+ if (name === "label") {
76
+ const label = this.shadowRoot?.querySelector("label");
77
+ if (label)
78
+ label.textContent = value ?? "";
79
+ }
80
+ if (name === "disabled")
81
+ select.disabled = this.formDisabled || this.hasAttribute("disabled") || Boolean(this.slotSelectDefaults?.disabled);
82
+ if (name === "required")
83
+ select.required = this.hasAttribute("required") || Boolean(this.slotSelectDefaults?.required);
84
+ if (name === "multiple")
85
+ select.multiple = this.hasAttribute("multiple") || Boolean(this.slotSelectDefaults?.multiple);
86
+ if (name === "form")
87
+ value === null ? select.removeAttribute("form") : select.setAttribute("form", value);
88
+ if (name === "auto-complete")
89
+ value === null ? select.removeAttribute("autocomplete") : select.setAttribute("autocomplete", value);
90
+ if (name === "aria-label" || name === "aria-labelledby" || name === "aria-description" || name === "aria-describedby" || name === "aria-invalid")
91
+ value === null ? select.removeAttribute(name) : select.setAttribute(name, value);
92
+ if (name === "value")
93
+ select.value = this.currentValue ?? "";
94
+ if (name === "default-value" && this.currentValue !== undefined)
95
+ select.value = this.currentValue;
96
+ if (name === "appearance" || name === "size") {
97
+ this.render();
98
+ return;
99
+ }
100
+ this.syncFormValue(select);
101
+ }
102
+ focus(options) { this.getSelect()?.focus(options); }
103
+ blur() { this.getSelect()?.blur(); }
104
+ get value() { return this.currentValue ?? this.getAttribute("value") ?? this.getSelect()?.value ?? ""; }
105
+ set value(value) {
106
+ this.currentValue = value;
107
+ const select = this.getSelect();
108
+ if (select) {
109
+ select.value = value;
110
+ this.syncFormValue(select);
111
+ }
112
+ }
113
+ get defaultValue() { return this.getAttribute("default-value") ?? ""; }
114
+ set defaultValue(value) { this.setAttribute("default-value", value); }
115
+ formDisabledCallback(disabled) {
116
+ this.formDisabled = disabled;
117
+ this.syncOptions();
118
+ }
119
+ formResetCallback() {
120
+ const select = this.getSelect();
121
+ if (select?.multiple) {
122
+ this.currentValue = undefined;
123
+ for (const option of [...select.options])
124
+ option.selected = this.initialSelectedValues?.has(option.value) ?? option.defaultSelected;
125
+ this.syncFormValue(select);
126
+ return;
127
+ }
128
+ const options = [...this.querySelectorAll("option")];
129
+ this.value = this.getAttribute("value") ?? this.getAttribute("default-value") ?? this.initialSelectedValues?.values().next().value ?? options.find(option => option.hasAttribute("selected"))?.value ?? options[0]?.value ?? "";
130
+ }
131
+ formStateRestoreCallback(state) { if (typeof state === "string")
132
+ this.value = state; }
133
+ syncFormValue(select) {
134
+ syncHostAccessibleName(this, select);
135
+ const value = select.multiple
136
+ ? [...select.selectedOptions].reduce((data, option) => { const name = this.getAttribute("name"); if (name)
137
+ data.append(name, option.value); return data; }, new FormData())
138
+ : select.value;
139
+ this.internals?.setFormValue(value);
140
+ try {
141
+ this.internals?.setValidity(select.validity.valid ? {} : { valueMissing: select.validity.valueMissing }, select.validationMessage, select);
142
+ }
143
+ catch { /* Older engines can omit custom-element validity anchors. */ }
144
+ }
145
+ syncTabIndex(select) {
146
+ const fallback = select.classList.contains("select-fallback");
147
+ if (!fallback && !this.slotSelectTabIndexCaptured) {
148
+ this.slotSelectTabIndex = select.tabIndex;
149
+ this.slotSelectTabIndexCaptured = true;
150
+ }
151
+ select.tabIndex = this.requestedTabIndex ?? (fallback ? 0 : this.slotSelectTabIndex ?? select.tabIndex);
152
+ if (this.requestedTabIndex !== undefined && this.requestedTabIndex !== -1 && this.getAttribute("tabindex") !== "-1") {
153
+ this.normalizingTabIndex = true;
154
+ this.setAttribute("tabindex", "-1");
155
+ this.normalizingTabIndex = false;
156
+ }
157
+ }
158
+ syncOptions() {
159
+ const select = this.getSelect();
160
+ if (!select)
161
+ return;
162
+ if (!select.classList.contains("select-fallback"))
163
+ this.slotSelectDefaults = rememberNativeFormControlDefaults(this.slotSelectDefaults, select);
164
+ const defaults = select.classList.contains("select-fallback") ? undefined : this.slotSelectDefaults;
165
+ if (select.classList.contains("select-fallback")) {
166
+ const priorValue = this.currentValue ?? select.value;
167
+ const sourceOptions = [...this.querySelectorAll("option")];
168
+ const sourceSelectedValues = new Set(sourceOptions.filter(option => option.selected).map(option => option.value));
169
+ if (!this.initialSelectedValues && sourceOptions.length > 0)
170
+ this.initialSelectedValues = sourceSelectedValues;
171
+ const priorValues = select.multiple ? new Set([...select.selectedOptions].map(option => option.value)) : undefined;
172
+ select.replaceChildren(...this.cloneOptionContent());
173
+ select.disabled = this.formDisabled || this.hasAttribute("disabled");
174
+ select.required = this.hasAttribute("required");
175
+ select.multiple = this.hasAttribute("multiple");
176
+ if (this.hasAttribute("form"))
177
+ select.setAttribute("form", this.getAttribute("form"));
178
+ else
179
+ select.removeAttribute("form");
180
+ if (this.hasAttribute("auto-complete"))
181
+ select.setAttribute("autocomplete", this.getAttribute("auto-complete"));
182
+ else
183
+ select.removeAttribute("autocomplete");
184
+ for (const name of ["aria-label", "aria-labelledby", "aria-description", "aria-describedby", "aria-invalid"]) {
185
+ const value = this.getAttribute(name);
186
+ if (value === null)
187
+ select.removeAttribute(name);
188
+ else
189
+ select.setAttribute(name, value);
190
+ }
191
+ if (this.getAttribute("label") && !select.hasAttribute("aria-label") && !select.hasAttribute("aria-labelledby"))
192
+ select.setAttribute("aria-label", this.getAttribute("label"));
193
+ if (priorValues) {
194
+ const selectedValues = priorValues.size > 0 ? priorValues : this.initialSelectedValues ?? sourceSelectedValues;
195
+ for (const option of [...select.options])
196
+ option.selected = selectedValues.has(option.value);
197
+ }
198
+ else if (this.initialSelectedValues?.size) {
199
+ select.value = this.initialSelectedValues.values().next().value ?? priorValue;
200
+ }
201
+ else {
202
+ select.value = priorValue;
203
+ }
204
+ }
205
+ else {
206
+ select.disabled = this.formDisabled || this.hasAttribute("disabled") || Boolean(defaults?.disabled);
207
+ select.required = this.hasAttribute("required") || Boolean(defaults?.required);
208
+ select.multiple = this.hasAttribute("multiple") || Boolean(defaults?.multiple);
209
+ if (this.hasAttribute("auto-complete") && !select.hasAttribute("autocomplete"))
210
+ select.setAttribute("autocomplete", this.getAttribute("auto-complete"));
211
+ if (this.hasAttribute("name"))
212
+ select.removeAttribute("name");
213
+ for (const name of ["aria-label", "aria-labelledby", "aria-description", "aria-describedby", "aria-invalid"]) {
214
+ if (select.hasAttribute(name))
215
+ continue;
216
+ const value = this.getAttribute(name);
217
+ if (value !== null)
218
+ select.setAttribute(name, value);
219
+ }
220
+ if (this.getAttribute("label") && !select.hasAttribute("aria-label") && !select.hasAttribute("aria-labelledby"))
221
+ select.setAttribute("aria-label", this.getAttribute("label"));
222
+ if (this.currentValue !== undefined || this.hasAttribute("value") || this.hasAttribute("default-value"))
223
+ select.value = this.currentValue ?? this.getAttribute("value") ?? this.getAttribute("default-value") ?? "";
224
+ }
225
+ this.syncTabIndex(select);
226
+ if (this.boundSelect !== select) {
227
+ this.boundSelect?.removeEventListener("change", this.handleSelectChange);
228
+ select.addEventListener("change", this.handleSelectChange);
229
+ this.boundSelect = select;
230
+ }
231
+ this.syncFormValue(select);
232
+ }
233
+ render() {
234
+ const shadow = this.shadowRoot ?? this.attachShadow({ mode: "open" });
235
+ const id = `select-${crypto.randomUUID()}`;
236
+ const label = document.createElement("label");
237
+ label.htmlFor = id;
238
+ label.textContent = this.getAttribute("label") ?? "";
239
+ label.part.add("label");
240
+ const select = document.createElement("select");
241
+ select.className = "select-fallback";
242
+ select.id = id;
243
+ select.part.add("control");
244
+ select.disabled = this.hasAttribute("disabled");
245
+ select.required = this.hasAttribute("required");
246
+ select.multiple = this.hasAttribute("multiple");
247
+ if (this.hasAttribute("form"))
248
+ select.setAttribute("form", this.getAttribute("form"));
249
+ if (this.hasAttribute("auto-complete"))
250
+ select.setAttribute("autocomplete", this.getAttribute("auto-complete"));
251
+ for (const name of ["aria-label", "aria-labelledby", "aria-description", "aria-describedby", "aria-invalid"]) {
252
+ const value = this.getAttribute(name);
253
+ if (value !== null)
254
+ select.setAttribute(name, value);
255
+ }
256
+ select.append(...this.cloneOptionContent());
257
+ if (this.currentValue !== undefined || this.hasAttribute("value") || this.hasAttribute("default-value"))
258
+ select.value = this.currentValue ?? this.getAttribute("value") ?? this.getAttribute("default-value") ?? "";
259
+ const control = document.createElement("span");
260
+ control.className = "control";
261
+ const selectSlot = document.createElement("slot");
262
+ selectSlot.name = "select";
263
+ selectSlot.part.add("select");
264
+ selectSlot.append(select);
265
+ selectSlot.addEventListener("slotchange", () => this.syncOptions());
266
+ const icon = document.createElement("slot");
267
+ icon.name = "icon";
268
+ icon.part.add("icon");
269
+ icon.setAttribute("aria-hidden", "true");
270
+ const fallbackIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
271
+ fallbackIcon.setAttribute("viewBox", "0 0 20 20");
272
+ fallbackIcon.setAttribute("width", "20");
273
+ fallbackIcon.setAttribute("height", "20");
274
+ fallbackIcon.setAttribute("fill", "none");
275
+ fallbackIcon.setAttribute("aria-hidden", "true");
276
+ const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
277
+ path.setAttribute("d", "m5 7.5 5 5 5-5");
278
+ path.setAttribute("stroke", "currentColor");
279
+ path.setAttribute("stroke-width", "1.5");
280
+ fallbackIcon.append(path);
281
+ icon.append(fallbackIcon);
282
+ control.append(selectSlot, icon);
283
+ const style = document.createElement("style");
284
+ style.textContent = `${base}:host{display:grid;gap:var(--spui-control-gap,6px)}label{font-size:14px;font-weight:600;color:var(--spui-ui-muted,var(--spui-semantic-body-text,inherit))}.control{position:relative;min-width:0}select{box-sizing:border-box;width:100%;min-height:var(--spui-control-height,36px);padding-inline:var(--spui-control-padding-inline,12px);padding-inline-end:36px;appearance:none;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));font:inherit}:host([size=small]) select{min-height:24px;font-size:var(--spui-text-font-size-small,12px)}:host([size=large]) select{min-height:40px;font-size:var(--spui-text-font-size-large,18px)}:host([appearance=underline]) select{border-width:0 0 1px;border-radius:0}:host([appearance=filled-darker]) select{background:var(--colorNeutralBackground3,var(--spui-ui-surface-sunken,#f0f0f0));border-color:transparent}:host([appearance=filled-lighter]) select{background:var(--colorNeutralBackground2,var(--spui-ui-surface-hover,#f5f5f5));border-color:transparent}slot[name=icon]{position:absolute;inset-inline-end:8px;top:50%;display:grid;place-items:center;width:20px;height:20px;transform:translateY(-50%);color:var(--spui-ui-muted,var(--spui-ui-text,#424242));pointer-events:none}slot[name=icon]::slotted(*){width:20px;height:20px}select:focus-visible{outline:2px solid var(--spui-focus-ring,var(--colorStrokeFocus2,#005a9e));outline-offset:2px}select:disabled{opacity:.55}@media(forced-colors:active){select{border-color:FieldText}slot[name=icon]{color:ButtonText}select:focus-visible{outline-color:Highlight}}`;
285
+ style.textContent += `slot[name=select]{display:block}slot[name=select]::slotted(select){box-sizing:border-box;width:100%;min-height:var(--spui-control-height,36px);padding-inline:var(--spui-control-padding-inline,12px);padding-inline-end:36px;appearance:none;border:1px solid var(--spui-control-border,var(--spui-ui-stroke,var(--colorNeutralStroke1,#8a8886)));border-radius:var(--spui-control-radius,4px);background:var(--spui-control-background,var(--spui-ui-surface,#fff));color:var(--spui-ui-text,inherit);font:inherit}:host([size=small]) slot[name=select]::slotted(select){min-height:24px;font-size:var(--spui-text-font-size-small,12px)}:host([size=large]) slot[name=select]::slotted(select){min-height:40px;font-size:var(--spui-text-font-size-large,18px)}:host([appearance=underline]) slot[name=select]::slotted(select){border-width:0 0 1px;border-radius:0}:host([appearance=filled-darker]) slot[name=select]::slotted(select){background:var(--colorNeutralBackground3,var(--spui-ui-surface-sunken,#f0f0f0));border-color:transparent}:host([appearance=filled-lighter]) slot[name=select]::slotted(select){background:var(--colorNeutralBackground2,var(--spui-ui-surface-hover,#f5f5f5));border-color:transparent}slot[name=select]::slotted(select:focus-visible){outline:2px solid var(--spui-focus-ring,var(--colorStrokeFocus2,#005a9e));outline-offset:2px}slot[name=select]::slotted(select:disabled){opacity:.55}@media(forced-colors:active){slot[name=select]::slotted(select){border-color:FieldText}slot[name=select]::slotted(select:focus-visible){outline-color:Highlight}}`;
286
+ shadow.replaceChildren(style, label, control);
287
+ this.syncOptions();
288
+ }
289
+ }
290
+ customElements.define("spui-select", SpuiSelect);
291
+ }
@@ -0,0 +1,19 @@
1
+ export declare const base = ":host{font:inherit;font-family:var(--spui-font-family,inherit);color:var(--spui-ui-text,var(--spui-semantic-body-text,var(--colorNeutralForeground1,#323130)));color-scheme:var(--spui-color-scheme,light dark)}button,input,textarea{font:inherit;font-family:var(--spui-font-family,inherit)}button:focus-visible,input:focus-visible,textarea:focus-visible{outline:2px solid var(--spui-focus-ring,var(--spui-semantic-focus-border,var(--colorStrokeFocus2,#005a9e)));outline-offset:2px}";
2
+ export type NativeFormControl = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
3
+ export type NativeFormControlDefaults = {
4
+ control: NativeFormControl;
5
+ disabled: boolean;
6
+ required: boolean;
7
+ readOnly: boolean;
8
+ multiple: boolean;
9
+ value: string;
10
+ defaultValue: string;
11
+ checked: boolean;
12
+ defaultChecked: boolean;
13
+ };
14
+ export declare function stopHostAccessibleNameSync(host: HTMLElement): void;
15
+ export declare function observeAccessibleTextFromIdRefs(context: HTMLElement, labelledBy: string, onText: (text: string) => void): Pick<MutationObserver, "disconnect">;
16
+ export declare function resolveAccessibleTextFromIdRefs(context: HTMLElement | Document, labelledBy: string): string;
17
+ export declare function syncHostAccessibleName(host: HTMLElement, control: HTMLElement): void;
18
+ export declare function rememberNativeFormControlDefaults(current: NativeFormControlDefaults | undefined, control: NativeFormControl): NativeFormControlDefaults;
19
+ export declare function findFocusable(root: ParentNode): HTMLElement | undefined;