@spfx-fast/sharepoint-ui 0.0.0-stage → 0.4.0
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 +5810 -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 +124 -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 +5 -0
- package/dist/elements/text.js +69 -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-theme-styles.d.ts +2 -0
- package/dist/react-theme-styles.js +75 -0
- package/dist/react.d.ts +4540 -0
- package/dist/react.js +6799 -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,791 @@
|
|
|
1
|
+
import { base } from "./shared.js";
|
|
2
|
+
import { buttonControlCss } from "./button.js";
|
|
3
|
+
let nextNavId = 0;
|
|
4
|
+
export function defineNav() {
|
|
5
|
+
defineNavItem();
|
|
6
|
+
defineAppItem();
|
|
7
|
+
defineAppItemStatic();
|
|
8
|
+
defineSplitNavItem();
|
|
9
|
+
defineHamburger();
|
|
10
|
+
defineNavDrawer();
|
|
11
|
+
defineNavDrawerHeader();
|
|
12
|
+
defineNavDrawerBody();
|
|
13
|
+
defineNavDrawerFooter();
|
|
14
|
+
defineNavCategory();
|
|
15
|
+
defineNavCategoryItem();
|
|
16
|
+
defineNavSubItemGroup();
|
|
17
|
+
defineNavSubItem();
|
|
18
|
+
defineNavDivider();
|
|
19
|
+
defineNavSectionHeader();
|
|
20
|
+
if (customElements.get("spui-nav"))
|
|
21
|
+
return;
|
|
22
|
+
class SpuiNav extends HTMLElement {
|
|
23
|
+
static observedAttributes = ["label", "aria-label", "density", "multiple", "tabbable", "open", "open-label", "close-label", "collapsible", "collapsed", "expand-label", "collapse-label"];
|
|
24
|
+
observer;
|
|
25
|
+
events;
|
|
26
|
+
breakpoint;
|
|
27
|
+
current = null;
|
|
28
|
+
currentCategory = null;
|
|
29
|
+
currentControlled = false;
|
|
30
|
+
currentCategoryControlled = false;
|
|
31
|
+
categoriesOpen = new Set();
|
|
32
|
+
categoriesOpenControlled = false;
|
|
33
|
+
drawerOpenControlled = false;
|
|
34
|
+
drawerOpen = false;
|
|
35
|
+
reflectingOpen = false;
|
|
36
|
+
collapsedControlled = false;
|
|
37
|
+
reflectingCollapsed = false;
|
|
38
|
+
nextGroupId = 0;
|
|
39
|
+
get open() { return this.drawerOpen; }
|
|
40
|
+
set open(value) { this.drawerOpenControlled = true; this.setDrawerOpen(Boolean(value)); }
|
|
41
|
+
get defaultOpen() { return this.drawerOpen; }
|
|
42
|
+
set defaultOpen(value) { if (!this.drawerOpenControlled)
|
|
43
|
+
this.setDrawerOpen(Boolean(value)); }
|
|
44
|
+
get collapsed() { return this.hasAttribute("collapsed"); }
|
|
45
|
+
set collapsed(value) { this.collapsedControlled = true; this.setCollapsed(Boolean(value)); }
|
|
46
|
+
get defaultCollapsed() { return this.collapsed; }
|
|
47
|
+
set defaultCollapsed(value) { if (!this.collapsedControlled)
|
|
48
|
+
this.setCollapsed(Boolean(value)); }
|
|
49
|
+
connectedCallback() {
|
|
50
|
+
if (!this.shadowRoot)
|
|
51
|
+
this.render();
|
|
52
|
+
this.observer = new MutationObserver(() => this.sync());
|
|
53
|
+
this.observer.observe(this, { childList: true, subtree: true });
|
|
54
|
+
this.events?.abort();
|
|
55
|
+
this.events = new AbortController();
|
|
56
|
+
this.breakpoint?.removeEventListener("change", this.onBreakpointChange);
|
|
57
|
+
this.breakpoint = window.matchMedia("(max-width: 640px)");
|
|
58
|
+
this.breakpoint.addEventListener("change", this.onBreakpointChange);
|
|
59
|
+
window.addEventListener("resize", this.onBreakpointChange);
|
|
60
|
+
this.addEventListener("click", event => this.onClick(event), { signal: this.events.signal });
|
|
61
|
+
this.addEventListener("keydown", event => {
|
|
62
|
+
if (this.handleRovingKeydown(event))
|
|
63
|
+
return;
|
|
64
|
+
if (event.key !== "Escape" || !this.drawerOpen)
|
|
65
|
+
return;
|
|
66
|
+
if (this.getAttribute("data-drawer-type") === "inline")
|
|
67
|
+
this.requestOpen(false);
|
|
68
|
+
requestAnimationFrame(() => this.shadowRoot?.querySelector(".mobile-toggle")?.focus());
|
|
69
|
+
}, { signal: this.events.signal });
|
|
70
|
+
this.addEventListener("focusin", event => this.syncTabStops(event.composedPath().find(node => node instanceof HTMLElement && this.navControl(node))), { signal: this.events.signal });
|
|
71
|
+
const nav = this.shadowRoot?.querySelector("nav");
|
|
72
|
+
nav?.addEventListener("toggle", () => this.onPopoverToggle(), { signal: this.events.signal });
|
|
73
|
+
this.sync();
|
|
74
|
+
this.syncResponsive();
|
|
75
|
+
}
|
|
76
|
+
disconnectedCallback() { this.observer?.disconnect(); this.events?.abort(); this.breakpoint?.removeEventListener("change", this.onBreakpointChange); window.removeEventListener("resize", this.onBreakpointChange); }
|
|
77
|
+
attributeChangedCallback(name) {
|
|
78
|
+
if (name === "open" && !this.reflectingOpen) {
|
|
79
|
+
this.drawerOpenControlled = true;
|
|
80
|
+
this.drawerOpen = this.hasAttribute("open");
|
|
81
|
+
}
|
|
82
|
+
if (name === "collapsed" && !this.reflectingCollapsed)
|
|
83
|
+
this.syncResponsive();
|
|
84
|
+
if (!this.isConnected)
|
|
85
|
+
return;
|
|
86
|
+
if (name === "label" || name === "aria-label")
|
|
87
|
+
this.shadowRoot?.querySelector("nav")?.setAttribute("aria-label", this.getAttribute("aria-label") ?? this.getAttribute("label") ?? "Navigation");
|
|
88
|
+
this.sync();
|
|
89
|
+
}
|
|
90
|
+
get selectedValue() { return this.current; }
|
|
91
|
+
set selectedValue(value) { this.currentControlled = true; this.current = value; this.sync(); }
|
|
92
|
+
get defaultSelectedValue() { return this.current; }
|
|
93
|
+
set defaultSelectedValue(value) { if (!this.currentControlled) {
|
|
94
|
+
this.current = value;
|
|
95
|
+
this.sync();
|
|
96
|
+
} }
|
|
97
|
+
get selectedCategoryValue() { return this.currentCategory; }
|
|
98
|
+
set selectedCategoryValue(value) { this.currentCategoryControlled = true; this.currentCategory = value; this.sync(); }
|
|
99
|
+
get defaultSelectedCategoryValue() { return this.currentCategory; }
|
|
100
|
+
set defaultSelectedCategoryValue(value) { if (!this.currentCategoryControlled) {
|
|
101
|
+
this.currentCategory = value;
|
|
102
|
+
this.sync();
|
|
103
|
+
} }
|
|
104
|
+
get openCategories() { return [...this.categoriesOpen]; }
|
|
105
|
+
set openCategories(values) { this.categoriesOpenControlled = true; this.categoriesOpen = new Set(values); this.sync(); }
|
|
106
|
+
get defaultOpenCategories() { return [...this.categoriesOpen]; }
|
|
107
|
+
set defaultOpenCategories(values) { if (!this.categoriesOpenControlled) {
|
|
108
|
+
this.categoriesOpen = new Set(this.allowsMultipleCategories() ? values : values.slice(0, 1));
|
|
109
|
+
this.sync();
|
|
110
|
+
} }
|
|
111
|
+
allowsMultipleCategories() { return this.getAttribute("multiple") !== "false"; }
|
|
112
|
+
onBreakpointChange = () => {
|
|
113
|
+
if (!this.breakpoint?.matches && this.drawerOpen)
|
|
114
|
+
this.requestOpen(false);
|
|
115
|
+
this.syncResponsive();
|
|
116
|
+
};
|
|
117
|
+
navControls() {
|
|
118
|
+
return [...this.querySelectorAll("spui-nav-item, spui-app-item, spui-nav-sub-item, spui-nav-category-item")].filter(host => {
|
|
119
|
+
if (host.hasAttribute("disabled") || host.closest("spui-nav-sub-item-group")?.hidden)
|
|
120
|
+
return false;
|
|
121
|
+
return Boolean(this.navControl(host));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
navControl(host) { return host.shadowRoot?.querySelector("a,button") ?? null; }
|
|
125
|
+
syncTabStops(preferred) {
|
|
126
|
+
const items = this.navControls();
|
|
127
|
+
const roving = this.getAttribute("tabbable") === "false";
|
|
128
|
+
const active = preferred ?? items.find(item => item.shadowRoot?.activeElement) ?? items.find(item => item.hasAttribute("selected")) ?? items[0];
|
|
129
|
+
for (const item of items)
|
|
130
|
+
this.navControl(item)?.setAttribute("tabindex", String(!roving || item === active ? 0 : -1));
|
|
131
|
+
}
|
|
132
|
+
handleRovingKeydown(event) {
|
|
133
|
+
if (this.getAttribute("tabbable") !== "false")
|
|
134
|
+
return false;
|
|
135
|
+
const host = event.composedPath().find(node => node instanceof HTMLElement && this.navControl(node));
|
|
136
|
+
if (!host)
|
|
137
|
+
return false;
|
|
138
|
+
const items = this.navControls();
|
|
139
|
+
const current = items.indexOf(host);
|
|
140
|
+
if (current < 0)
|
|
141
|
+
return false;
|
|
142
|
+
let next = current;
|
|
143
|
+
if (event.key === "ArrowDown")
|
|
144
|
+
next = Math.min(items.length - 1, current + 1);
|
|
145
|
+
else if (event.key === "ArrowUp")
|
|
146
|
+
next = Math.max(0, current - 1);
|
|
147
|
+
else if (event.key === "Home")
|
|
148
|
+
next = 0;
|
|
149
|
+
else if (event.key === "End")
|
|
150
|
+
next = items.length - 1;
|
|
151
|
+
else
|
|
152
|
+
return false;
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
this.syncTabStops(items[next]);
|
|
155
|
+
this.navControl(items[next])?.focus();
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
setDrawerOpen(value, notify = false) {
|
|
159
|
+
if (value === this.drawerOpen) {
|
|
160
|
+
this.syncResponsive();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
this.drawerOpen = value;
|
|
164
|
+
this.reflectingOpen = true;
|
|
165
|
+
this.toggleAttribute("open", value);
|
|
166
|
+
this.reflectingOpen = false;
|
|
167
|
+
this.syncResponsive();
|
|
168
|
+
if (notify)
|
|
169
|
+
this.dispatchEvent(new CustomEvent("spui-nav-open-change", { bubbles: true, composed: true, detail: { open: value } }));
|
|
170
|
+
}
|
|
171
|
+
requestOpen(value) {
|
|
172
|
+
if (this.drawerOpenControlled) {
|
|
173
|
+
if (value !== this.drawerOpen)
|
|
174
|
+
this.dispatchEvent(new CustomEvent("spui-nav-open-change", { bubbles: true, composed: true, detail: { open: value } }));
|
|
175
|
+
}
|
|
176
|
+
else
|
|
177
|
+
this.setDrawerOpen(value, true);
|
|
178
|
+
}
|
|
179
|
+
onPopoverToggle() {
|
|
180
|
+
const nav = this.shadowRoot?.querySelector("nav");
|
|
181
|
+
const value = nav?.matches(":popover-open") ?? false;
|
|
182
|
+
if (value === this.drawerOpen)
|
|
183
|
+
return;
|
|
184
|
+
if (this.drawerOpenControlled)
|
|
185
|
+
this.dispatchEvent(new CustomEvent("spui-nav-open-change", { bubbles: true, composed: true, detail: { open: value } }));
|
|
186
|
+
else
|
|
187
|
+
this.setDrawerOpen(value, true);
|
|
188
|
+
}
|
|
189
|
+
syncResponsive() {
|
|
190
|
+
const nav = this.shadowRoot?.querySelector("nav");
|
|
191
|
+
const toggle = this.shadowRoot?.querySelector(".mobile-toggle");
|
|
192
|
+
const close = this.shadowRoot?.querySelector(".mobile-close");
|
|
193
|
+
const railToggle = this.shadowRoot?.querySelector(".rail-toggle");
|
|
194
|
+
if (!nav || !toggle || !close || !railToggle)
|
|
195
|
+
return;
|
|
196
|
+
const mobile = this.breakpoint?.matches ?? window.matchMedia("(max-width: 640px)").matches;
|
|
197
|
+
const inlineDrawer = this.getAttribute("data-drawer-type") === "inline";
|
|
198
|
+
this.toggleAttribute("data-mobile", mobile);
|
|
199
|
+
this.toggleAttribute("data-collapsed", !mobile && this.collapsed);
|
|
200
|
+
this.dataset.direction = getComputedStyle(this).direction;
|
|
201
|
+
toggle.hidden = !mobile;
|
|
202
|
+
toggle.setAttribute("aria-expanded", String(mobile && this.drawerOpen));
|
|
203
|
+
toggle.setAttribute("aria-label", this.drawerOpen ? this.getAttribute("close-label") ?? "Close navigation" : this.getAttribute("open-label") ?? "Open navigation");
|
|
204
|
+
close.setAttribute("aria-label", this.getAttribute("close-label") ?? "Close navigation");
|
|
205
|
+
close.hidden = !mobile;
|
|
206
|
+
railToggle.hidden = mobile || !this.hasAttribute("collapsible");
|
|
207
|
+
railToggle.setAttribute("aria-expanded", String(!this.collapsed));
|
|
208
|
+
railToggle.setAttribute("aria-label", this.getAttribute(this.collapsed ? "expand-label" : "collapse-label") ?? (this.collapsed ? "Expand navigation" : "Collapse navigation"));
|
|
209
|
+
railToggle.title = this.getAttribute(this.collapsed ? "expand-label" : "collapse-label") ?? (this.collapsed ? "Expand navigation" : "Collapse navigation");
|
|
210
|
+
for (const item of this.querySelectorAll("spui-nav-item, spui-app-item, spui-nav-sub-item, spui-nav-category-item, spui-nav-sub-item-group, spui-nav-divider, spui-nav-section-header"))
|
|
211
|
+
item.toggleAttribute("compact", !mobile && this.collapsed);
|
|
212
|
+
if (!mobile) {
|
|
213
|
+
if (nav.matches(":popover-open"))
|
|
214
|
+
nav.hidePopover();
|
|
215
|
+
nav.removeAttribute("popover");
|
|
216
|
+
nav.hidden = false;
|
|
217
|
+
}
|
|
218
|
+
else if (inlineDrawer) {
|
|
219
|
+
if (nav.matches(":popover-open"))
|
|
220
|
+
nav.hidePopover();
|
|
221
|
+
nav.removeAttribute("popover");
|
|
222
|
+
nav.hidden = !this.drawerOpen;
|
|
223
|
+
}
|
|
224
|
+
else if (typeof nav.showPopover === "function") {
|
|
225
|
+
nav.hidden = false;
|
|
226
|
+
if (!nav.hasAttribute("popover"))
|
|
227
|
+
nav.setAttribute("popover", "auto");
|
|
228
|
+
if (this.drawerOpen && !nav.matches(":popover-open"))
|
|
229
|
+
nav.showPopover();
|
|
230
|
+
else if (!this.drawerOpen && nav.matches(":popover-open"))
|
|
231
|
+
nav.hidePopover();
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this.toggleAttribute("data-popover-fallback", true);
|
|
235
|
+
nav.hidden = !this.drawerOpen;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
onClick(event) {
|
|
239
|
+
const path = event.composedPath();
|
|
240
|
+
const mobile = this.breakpoint?.matches ?? false;
|
|
241
|
+
if (mobile && this.getAttribute("data-drawer-type") === "inline" && path.some(node => node instanceof HTMLElement && node.classList.contains("mobile-toggle"))) {
|
|
242
|
+
event.preventDefault();
|
|
243
|
+
this.requestOpen(!this.drawerOpen);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (mobile && this.getAttribute("data-drawer-type") === "inline" && path.some(node => node instanceof HTMLElement && node.classList.contains("mobile-close"))) {
|
|
247
|
+
event.preventDefault();
|
|
248
|
+
this.requestOpen(false);
|
|
249
|
+
this.shadowRoot?.querySelector(".mobile-toggle")?.focus();
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (path.some(node => node instanceof HTMLElement && node.classList.contains("rail-toggle"))) {
|
|
253
|
+
const collapsed = !this.collapsed;
|
|
254
|
+
if (this.collapsedControlled)
|
|
255
|
+
this.dispatchEvent(new CustomEvent("spui-nav-collapsed-change", { bubbles: true, composed: true, detail: { collapsed } }));
|
|
256
|
+
else
|
|
257
|
+
this.setCollapsed(collapsed, true);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const categoryItem = path.find(node => node instanceof HTMLElement && node.localName === "spui-nav-category-item");
|
|
261
|
+
if (categoryItem) {
|
|
262
|
+
const category = categoryItem.parentElement?.closest("spui-nav-category");
|
|
263
|
+
const value = category?.getAttribute("value") ?? "";
|
|
264
|
+
if (!value || category?.hasAttribute("disabled"))
|
|
265
|
+
return;
|
|
266
|
+
if (!this.currentCategoryControlled)
|
|
267
|
+
this.currentCategory = value;
|
|
268
|
+
const next = new Set(this.categoriesOpen);
|
|
269
|
+
if (next.has(value))
|
|
270
|
+
next.delete(value);
|
|
271
|
+
else {
|
|
272
|
+
if (!this.allowsMultipleCategories())
|
|
273
|
+
next.clear();
|
|
274
|
+
next.add(value);
|
|
275
|
+
}
|
|
276
|
+
if (!this.categoriesOpenControlled)
|
|
277
|
+
this.categoriesOpen = next;
|
|
278
|
+
this.sync();
|
|
279
|
+
const categoryIndex = path.indexOf(category);
|
|
280
|
+
const parentCategory = categoryIndex >= 0 ? path.slice(categoryIndex + 1).find((node) => node instanceof HTMLElement && node.localName === "spui-nav-category") ?? null : null;
|
|
281
|
+
this.dispatchEvent(new CustomEvent("spui-nav-category-toggle", { bubbles: true, composed: true, detail: { value, categoryValue: parentCategory?.getAttribute("value") ?? undefined, open: next.has(value), openCategories: [...next], event, type: "click" } }));
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const item = path.find(node => node instanceof HTMLElement && (node.localName === "spui-nav-item" || node.localName === "spui-app-item" || node.localName === "spui-nav-sub-item"));
|
|
285
|
+
if (!item)
|
|
286
|
+
return;
|
|
287
|
+
if (item.hasAttribute("disabled")) {
|
|
288
|
+
event.preventDefault();
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const value = item.getAttribute("value") ?? "";
|
|
292
|
+
if (!value)
|
|
293
|
+
return;
|
|
294
|
+
if (!this.currentControlled)
|
|
295
|
+
this.current = value;
|
|
296
|
+
this.sync();
|
|
297
|
+
const category = path.find((node) => node instanceof HTMLElement && node.localName === "spui-nav-category") ?? null;
|
|
298
|
+
this.dispatchEvent(new CustomEvent("spui-nav-item-select", { bubbles: true, composed: true, detail: { value, href: item.getAttribute("href"), label: item.textContent?.trim() ?? "", categoryValue: category?.getAttribute("value") ?? undefined, event, type: "click" } }));
|
|
299
|
+
if (this.breakpoint?.matches && this.drawerOpen)
|
|
300
|
+
this.requestOpen(false);
|
|
301
|
+
}
|
|
302
|
+
setCollapsed(value, notify = false) {
|
|
303
|
+
if (value === this.collapsed)
|
|
304
|
+
return;
|
|
305
|
+
this.reflectingCollapsed = true;
|
|
306
|
+
this.toggleAttribute("collapsed", value);
|
|
307
|
+
this.reflectingCollapsed = false;
|
|
308
|
+
this.sync();
|
|
309
|
+
if (notify)
|
|
310
|
+
this.dispatchEvent(new CustomEvent("spui-nav-collapsed-change", { bubbles: true, composed: true, detail: { collapsed: value } }));
|
|
311
|
+
}
|
|
312
|
+
sync() {
|
|
313
|
+
const nav = this.shadowRoot?.querySelector("nav");
|
|
314
|
+
if (!nav)
|
|
315
|
+
return;
|
|
316
|
+
nav.setAttribute("aria-label", this.getAttribute("aria-label") ?? this.getAttribute("label") ?? "Navigation");
|
|
317
|
+
let categories = 0;
|
|
318
|
+
for (const category of this.querySelectorAll("spui-nav-category")) {
|
|
319
|
+
const value = category.getAttribute("value") ?? "";
|
|
320
|
+
const categoryItem = category.querySelector("spui-nav-category-item");
|
|
321
|
+
const group = category.querySelector("spui-nav-sub-item-group");
|
|
322
|
+
if (!category.dataset.spuiGroupId)
|
|
323
|
+
category.dataset.spuiGroupId = `spui-nav-group-${++this.nextGroupId}`;
|
|
324
|
+
const isOpen = this.categoriesOpen.has(value);
|
|
325
|
+
if (categoryItem) {
|
|
326
|
+
categoryItem.toggleAttribute("expanded", isOpen);
|
|
327
|
+
categoryItem.toggleAttribute("disabled", category.hasAttribute("disabled"));
|
|
328
|
+
categoryItem.setAttribute("controls", category.dataset.spuiGroupId);
|
|
329
|
+
}
|
|
330
|
+
if (group) {
|
|
331
|
+
group.id = category.dataset.spuiGroupId;
|
|
332
|
+
const navGroup = group;
|
|
333
|
+
if (navGroup.setExpanded)
|
|
334
|
+
navGroup.setExpanded(isOpen);
|
|
335
|
+
else
|
|
336
|
+
group.hidden = !isOpen;
|
|
337
|
+
}
|
|
338
|
+
categories++;
|
|
339
|
+
}
|
|
340
|
+
for (const item of this.querySelectorAll("spui-nav-item, spui-app-item, spui-nav-sub-item")) {
|
|
341
|
+
const selected = item.getAttribute("value") === this.current;
|
|
342
|
+
item.toggleAttribute("selected", selected);
|
|
343
|
+
}
|
|
344
|
+
for (const category of this.querySelectorAll("spui-nav-category")) {
|
|
345
|
+
const selected = category.getAttribute("value") === this.currentCategory;
|
|
346
|
+
category.toggleAttribute("selected", selected);
|
|
347
|
+
category.querySelector("spui-nav-category-item")?.toggleAttribute("selected", selected);
|
|
348
|
+
}
|
|
349
|
+
this.dataset.density = this.getAttribute("density") ?? "medium";
|
|
350
|
+
this.toggleAttribute("data-has-categories", categories > 0);
|
|
351
|
+
this.syncTabStops();
|
|
352
|
+
this.syncResponsive();
|
|
353
|
+
}
|
|
354
|
+
render() {
|
|
355
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
356
|
+
const nav = document.createElement("nav");
|
|
357
|
+
nav.setAttribute("aria-label", this.getAttribute("aria-label") ?? this.getAttribute("label") ?? "Navigation");
|
|
358
|
+
nav.part.add("navigation");
|
|
359
|
+
nav.id = this.id ? `${this.id}-panel` : `spui-nav-panel-${++nextNavId}`;
|
|
360
|
+
const mobileHeader = document.createElement("div");
|
|
361
|
+
mobileHeader.className = "mobile-header";
|
|
362
|
+
mobileHeader.part.add("mobile-header");
|
|
363
|
+
const mobileTitle = document.createElement("span");
|
|
364
|
+
mobileTitle.textContent = this.getAttribute("label") ?? "Navigation";
|
|
365
|
+
const closeButton = document.createElement("button");
|
|
366
|
+
closeButton.type = "button";
|
|
367
|
+
closeButton.className = "mobile-close";
|
|
368
|
+
closeButton.part.add("mobile-close");
|
|
369
|
+
closeButton.setAttribute("popovertarget", nav.id);
|
|
370
|
+
closeButton.setAttribute("popovertargetaction", "hide");
|
|
371
|
+
closeButton.setAttribute("aria-label", this.getAttribute("close-label") ?? "Close navigation");
|
|
372
|
+
const closeIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
373
|
+
closeIcon.setAttribute("viewBox", "0 0 24 24");
|
|
374
|
+
closeIcon.setAttribute("width", "20");
|
|
375
|
+
closeIcon.setAttribute("height", "20");
|
|
376
|
+
closeIcon.setAttribute("aria-hidden", "true");
|
|
377
|
+
const closePath = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
378
|
+
closePath.setAttribute("d", "M5 5l14 14M19 5 5 19");
|
|
379
|
+
closePath.setAttribute("fill", "none");
|
|
380
|
+
closePath.setAttribute("stroke", "currentColor");
|
|
381
|
+
closePath.setAttribute("stroke-width", "1.8");
|
|
382
|
+
closePath.setAttribute("stroke-linecap", "round");
|
|
383
|
+
closeIcon.append(closePath);
|
|
384
|
+
closeButton.append(closeIcon);
|
|
385
|
+
mobileHeader.append(mobileTitle, closeButton);
|
|
386
|
+
const slot = document.createElement("slot");
|
|
387
|
+
nav.append(slot);
|
|
388
|
+
nav.prepend(mobileHeader);
|
|
389
|
+
const railToggle = document.createElement("button");
|
|
390
|
+
railToggle.type = "button";
|
|
391
|
+
railToggle.className = "rail-toggle";
|
|
392
|
+
railToggle.part.add("rail-toggle");
|
|
393
|
+
railToggle.setAttribute("aria-controls", nav.id);
|
|
394
|
+
railToggle.setAttribute("aria-expanded", String(!this.collapsed));
|
|
395
|
+
railToggle.setAttribute("aria-label", this.getAttribute("collapse-label") ?? "Collapse navigation");
|
|
396
|
+
const railIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
397
|
+
railIcon.setAttribute("viewBox", "0 0 24 24");
|
|
398
|
+
railIcon.setAttribute("width", "18");
|
|
399
|
+
railIcon.setAttribute("height", "18");
|
|
400
|
+
railIcon.setAttribute("aria-hidden", "true");
|
|
401
|
+
const railPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
402
|
+
railPath.setAttribute("d", "M14 5 7 12l7 7");
|
|
403
|
+
railPath.setAttribute("fill", "none");
|
|
404
|
+
railPath.setAttribute("stroke", "currentColor");
|
|
405
|
+
railPath.setAttribute("stroke-width", "2");
|
|
406
|
+
railPath.setAttribute("stroke-linecap", "round");
|
|
407
|
+
railPath.setAttribute("stroke-linejoin", "round");
|
|
408
|
+
railIcon.append(railPath);
|
|
409
|
+
railToggle.append(railIcon);
|
|
410
|
+
const toggle = document.createElement("button");
|
|
411
|
+
toggle.type = "button";
|
|
412
|
+
toggle.className = "mobile-toggle";
|
|
413
|
+
toggle.part.add("mobile-toggle");
|
|
414
|
+
toggle.setAttribute("popovertarget", nav.id);
|
|
415
|
+
toggle.setAttribute("popovertargetaction", "toggle");
|
|
416
|
+
toggle.setAttribute("aria-controls", nav.id);
|
|
417
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
418
|
+
toggle.setAttribute("aria-label", this.getAttribute("open-label") ?? "Open navigation");
|
|
419
|
+
const menuIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
420
|
+
menuIcon.setAttribute("viewBox", "0 0 24 24");
|
|
421
|
+
menuIcon.setAttribute("width", "22");
|
|
422
|
+
menuIcon.setAttribute("height", "22");
|
|
423
|
+
menuIcon.setAttribute("aria-hidden", "true");
|
|
424
|
+
const menuPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
425
|
+
menuPath.setAttribute("d", "M4 6h16M4 12h16M4 18h16");
|
|
426
|
+
menuPath.setAttribute("fill", "none");
|
|
427
|
+
menuPath.setAttribute("stroke", "currentColor");
|
|
428
|
+
menuPath.setAttribute("stroke-width", "1.8");
|
|
429
|
+
menuPath.setAttribute("stroke-linecap", "round");
|
|
430
|
+
menuIcon.append(menuPath);
|
|
431
|
+
toggle.append(menuIcon);
|
|
432
|
+
const style = document.createElement("style");
|
|
433
|
+
style.textContent = `${base}
|
|
434
|
+
:host{display:block;width:var(--spui-nav-width,260px);max-width:100%;min-width:0;color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424));font:inherit}:host([data-collapsed]){width:var(--spui-nav-collapsed-width,64px)}
|
|
435
|
+
nav{display:grid;grid-template-columns:minmax(0,1fr);gap:2px;width:100%;min-width:0;font-family:var(--spui-font-family,inherit);font-size:var(--spui-nav-font-size,14px);color:inherit}nav[hidden]{display:none}nav slot{min-width:0}
|
|
436
|
+
:host([density=small]) nav{--spui-nav-item-block:5px;--spui-nav-font-size:13px}
|
|
437
|
+
:host([density=large]) nav{--spui-nav-item-block:10px;--spui-nav-font-size:15px}
|
|
438
|
+
.mobile-toggle,.mobile-header{display:none}.rail-toggle{box-sizing:border-box;display:flex;align-items:center;justify-content:flex-start;width:100%;min-height:36px;padding:6px 12px;border:0;border-radius:var(--spui-control-radius,6px);background:transparent;color:inherit;cursor:pointer}.rail-toggle:hover{background:var(--spui-ui-surface-hover,var(--spui-semantic-subtle-background,#f5f5f5))}.rail-toggle:focus-visible{outline:2px solid var(--spui-focus-ring,var(--spui-semantic-focus-border,#005a9e));outline-offset:2px}.rail-toggle[hidden]{display:none}.rail-toggle svg{transition:transform var(--spui-motion-duration-fast,120ms) var(--spui-motion-easing-standard,cubic-bezier(.2,0,0,1))}:host([data-collapsed]) .rail-toggle{justify-content:center;padding-inline:4px}:host([data-collapsed][data-direction=ltr]) .rail-toggle svg,:host([data-direction=rtl]) .rail-toggle svg{transform:rotate(180deg)}:host([data-collapsed][data-direction=rtl]) .rail-toggle svg{transform:none}
|
|
439
|
+
.mobile-toggle[hidden],.mobile-close[hidden]{display:none}
|
|
440
|
+
.mobile-toggle,.mobile-close{box-sizing:border-box;place-items:center;width:44px;height:44px;border:0;border-radius:var(--spui-control-radius,6px);background:transparent;color:inherit;cursor:pointer}
|
|
441
|
+
.mobile-toggle:hover,.mobile-close:hover{background:var(--spui-ui-surface-hover,var(--spui-semantic-subtle-background,#f5f5f5))}
|
|
442
|
+
.mobile-toggle:focus-visible,.mobile-close:focus-visible{outline:2px solid var(--spui-focus-ring,var(--spui-semantic-focus-border,#005a9e));outline-offset:2px}
|
|
443
|
+
.mobile-header{align-items:center;justify-content:space-between;gap:12px;min-height:44px;margin:0 0 8px;padding-block-end:8px;border-block-end:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1));font-weight:600}
|
|
444
|
+
.mobile-header[part]{min-width:0}
|
|
445
|
+
.mobile-header span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
446
|
+
::slotted(spui-nav-item),::slotted(spui-nav-category),::slotted(spui-nav-divider),::slotted(spui-nav-section-header){min-width:0}
|
|
447
|
+
@media(max-width:640px){
|
|
448
|
+
:host{width:auto;max-width:none}
|
|
449
|
+
.mobile-toggle{display:grid}
|
|
450
|
+
:host([data-drawer-type=inline]) nav{box-sizing:border-box;width:100%;padding:8px 12px;border:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1));border-radius:var(--spui-surface-radius,var(--spui-card-radius,8px));background:var(--spui-ui-surface,var(--spui-semantic-card-background,#fff))}
|
|
451
|
+
:host([data-drawer-type=inline]) .mobile-header{display:flex}
|
|
452
|
+
nav[popover]:popover-open{position:fixed;inset-block:0;inset-inline:0 auto;box-sizing:border-box;display:grid;align-content:start;gap:2px;width:min(var(--spui-nav-width,260px),calc(100vw - 32px));height:100dvh;max-height:none;margin:0;padding:8px 12px;overflow:auto;border:0;border-inline-end:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1));background:var(--spui-card-background,var(--spui-ui-surface,#fff));color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424));box-shadow:0 12px 36px color-mix(in srgb,var(--spui-ui-text,#242424) 20%,transparent)}
|
|
453
|
+
nav[popover]:popover-open .mobile-header{display:flex}
|
|
454
|
+
nav[popover]::backdrop{background:color-mix(in srgb,var(--spui-ui-text,#242424) 36%,transparent);backdrop-filter:blur(1px)}
|
|
455
|
+
:host([data-direction=rtl]) nav[popover]:popover-open{border-inline-end:0;border-inline-start:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1))}
|
|
456
|
+
}
|
|
457
|
+
@media(prefers-reduced-motion:reduce){.rail-toggle svg{transition:none}}
|
|
458
|
+
@media(forced-colors:active){nav{color:CanvasText}nav[popover]:popover-open{border:1px solid CanvasText;background:Canvas;color:CanvasText;box-shadow:none}nav[popover]::backdrop{background:Canvas}}
|
|
459
|
+
`;
|
|
460
|
+
shadow.append(style, toggle, railToggle, nav);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
customElements.define("spui-nav", SpuiNav);
|
|
464
|
+
}
|
|
465
|
+
function defineNavItemElement(tag) {
|
|
466
|
+
if (customElements.get(tag))
|
|
467
|
+
return;
|
|
468
|
+
class SpuiNavItem extends HTMLElement {
|
|
469
|
+
static observedAttributes = ["href", "disabled", "selected", "value", "compact", "aria-label"];
|
|
470
|
+
connectedCallback() { if (!this.shadowRoot)
|
|
471
|
+
this.render(); this.sync(); }
|
|
472
|
+
attributeChangedCallback() { if (this.isConnected)
|
|
473
|
+
this.sync(); }
|
|
474
|
+
sync() {
|
|
475
|
+
const action = this.shadowRoot?.querySelector("a,button");
|
|
476
|
+
if (!action)
|
|
477
|
+
return;
|
|
478
|
+
const href = this.getAttribute("href");
|
|
479
|
+
if (href && action.localName === "a")
|
|
480
|
+
action.setAttribute("href", href);
|
|
481
|
+
else if (href && action.localName === "button") {
|
|
482
|
+
const anchor = document.createElement("a");
|
|
483
|
+
anchor.setAttribute("href", href);
|
|
484
|
+
anchor.part.add("action");
|
|
485
|
+
anchor.innerHTML = "<slot name=avatar></slot><slot name=icon></slot><span part=label><slot></slot></span><span part=compact-fallback aria-hidden=true></span>";
|
|
486
|
+
action.replaceWith(anchor);
|
|
487
|
+
}
|
|
488
|
+
else if (!href && action.localName === "a") {
|
|
489
|
+
const button = document.createElement("button");
|
|
490
|
+
button.type = "button";
|
|
491
|
+
button.part.add("action");
|
|
492
|
+
button.innerHTML = "<slot name=avatar></slot><slot name=icon></slot><span part=label><slot></slot></span><span part=compact-fallback aria-hidden=true></span>";
|
|
493
|
+
action.replaceWith(button);
|
|
494
|
+
}
|
|
495
|
+
const control = this.shadowRoot?.querySelector("a,button");
|
|
496
|
+
if (!control)
|
|
497
|
+
return;
|
|
498
|
+
if (control.localName === "button")
|
|
499
|
+
control.disabled = this.hasAttribute("disabled");
|
|
500
|
+
else {
|
|
501
|
+
if (this.hasAttribute("disabled")) {
|
|
502
|
+
control.setAttribute("aria-disabled", "true");
|
|
503
|
+
control.setAttribute("tabindex", "-1");
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
control.removeAttribute("aria-disabled");
|
|
507
|
+
control.removeAttribute("tabindex");
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (this.hasAttribute("selected"))
|
|
511
|
+
control.setAttribute("aria-current", "page");
|
|
512
|
+
else
|
|
513
|
+
control.removeAttribute("aria-current");
|
|
514
|
+
const label = this.getAttribute("aria-label") ?? this.textContent?.trim() ?? "";
|
|
515
|
+
control.setAttribute("aria-label", label);
|
|
516
|
+
control.title = this.hasAttribute("compact") ? label : "";
|
|
517
|
+
const fallback = control.querySelector("[part=compact-fallback]");
|
|
518
|
+
if (fallback) {
|
|
519
|
+
fallback.textContent = Array.from(label)[0] ?? "";
|
|
520
|
+
fallback.hidden = Boolean(this.querySelector('[slot="icon"],[slot="avatar"]'));
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
render() {
|
|
524
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
525
|
+
const control = this.hasAttribute("href") ? document.createElement("a") : document.createElement("button");
|
|
526
|
+
if (control.localName === "button")
|
|
527
|
+
control.type = "button";
|
|
528
|
+
control.part.add("action");
|
|
529
|
+
control.innerHTML = "<slot name=avatar></slot><slot name=icon></slot><span part=label><slot></slot></span><span part=compact-fallback aria-hidden=true></span>";
|
|
530
|
+
const style = document.createElement("style");
|
|
531
|
+
style.textContent = `${base}:host{display:block;min-width:0}a,button{box-sizing:border-box;display:flex;align-items:center;gap:12px;width:100%;min-height:36px;padding:var(--spui-nav-item-block,7px) 12px;border:0;border-radius:var(--spui-nav-item-radius,5px);background:transparent;color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424));font:inherit;text-align:start;text-decoration:none;cursor:pointer}a:hover,button:hover{background:var(--spui-ui-surface-hover,var(--spui-semantic-subtle-background,#f5f5f5))}:host([selected]) a,:host([selected]) button{background:color-mix(in srgb,var(--spui-ui-accent,#78716c) 12%,var(--spui-ui-surface,#fff));font-weight:600}:host([disabled]) a,:host([disabled]) button{opacity:.55;cursor:not-allowed}a:focus-visible,button:focus-visible{outline:2px solid var(--spui-focus-ring,var(--spui-semantic-focus-border,#005a9e));outline-offset:2px}::slotted([slot=icon]){inline-size:20px;block-size:20px;flex:none}::slotted([slot=avatar]){inline-size:28px;block-size:28px;flex:none}[part=compact-fallback]{display:none}:host([compact]) a,:host([compact]) button{justify-content:center;gap:0;padding-inline:4px}:host([compact]) [part=label]{position:absolute;inline-size:1px;block-size:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}:host([compact]) [part=compact-fallback]:not([hidden]){display:grid;place-items:center;inline-size:28px;block-size:28px;border-radius:50%;background:var(--spui-ui-surface-hover,var(--spui-semantic-subtle-background,#f5f5f5));font-size:12px;font-weight:600}:host(spui-nav-sub-item){padding-inline-start:14px}:host(spui-app-item) a,:host(spui-app-item) button{font-weight:600}:host(spui-app-item) [part=label]{font-size:var(--spui-nav-app-item-font-size,15px)}@media(forced-colors:active){a,button{color:LinkText}:host([selected]) a,:host([selected]) button{outline:1px solid Highlight}}`;
|
|
532
|
+
shadow.append(style, control);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
customElements.define(tag, SpuiNavItem);
|
|
536
|
+
}
|
|
537
|
+
export function defineNavItem() { defineNavItemElement("spui-nav-item"); }
|
|
538
|
+
export function defineNavSubItem() { defineNavItemElement("spui-nav-sub-item"); }
|
|
539
|
+
export function defineAppItem() { defineNavItemElement("spui-app-item"); }
|
|
540
|
+
function defineNavPart(tag, styleText, role) {
|
|
541
|
+
if (customElements.get(tag))
|
|
542
|
+
return;
|
|
543
|
+
class SpuiNavPart extends HTMLElement {
|
|
544
|
+
connectedCallback() {
|
|
545
|
+
if (role)
|
|
546
|
+
this.setAttribute("role", role);
|
|
547
|
+
if (this.shadowRoot)
|
|
548
|
+
return;
|
|
549
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
550
|
+
const style = document.createElement("style");
|
|
551
|
+
style.textContent = `${base}${styleText}`;
|
|
552
|
+
shadow.append(style, document.createElement("slot"));
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
customElements.define(tag, SpuiNavPart);
|
|
556
|
+
}
|
|
557
|
+
export function defineAppItemStatic() {
|
|
558
|
+
defineNavPart("spui-app-item-static", ":host{box-sizing:border-box;display:flex;align-items:center;gap:12px;min-height:40px;padding:8px 12px;color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424));font:600 15px/1.3 var(--spui-font-family,inherit)}::slotted([slot=icon]){inline-size:20px;block-size:20px;flex:none}");
|
|
559
|
+
}
|
|
560
|
+
export function defineSplitNavItem() {
|
|
561
|
+
if (customElements.get("spui-split-nav-item"))
|
|
562
|
+
return;
|
|
563
|
+
class SpuiSplitNavItem extends HTMLElement {
|
|
564
|
+
connectedCallback() { if (this.shadowRoot)
|
|
565
|
+
return; const shadow = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = `${base}:host{display:grid;grid-template-columns:minmax(0,1fr) auto auto auto;align-items:center;min-width:0}slot[name=action],slot[name=menu-button],slot[name=toggle-button]{display:grid;place-items:center}::slotted(spui-nav-item),::slotted(spui-nav-sub-item){min-width:0}::slotted([slot=action]),::slotted([slot=menu-button]),::slotted([slot=toggle-button]){min-width:36px;min-height:36px}`; shadow.append(style, document.createElement("slot"), Object.assign(document.createElement("slot"), { name: "action" }), Object.assign(document.createElement("slot"), { name: "menu-button" }), Object.assign(document.createElement("slot"), { name: "toggle-button" })); }
|
|
566
|
+
}
|
|
567
|
+
customElements.define("spui-split-nav-item", SpuiSplitNavItem);
|
|
568
|
+
}
|
|
569
|
+
export function defineHamburger() {
|
|
570
|
+
if (customElements.get("spui-hamburger"))
|
|
571
|
+
return;
|
|
572
|
+
class SpuiHamburger extends HTMLElement {
|
|
573
|
+
static observedAttributes = ["disabled", "disabled-focusable", "aria-label", "aria-expanded", "appearance", "size", "shape", "icon-position", "type", "title"];
|
|
574
|
+
connectedCallback() { if (!this.hasAttribute("aria-label"))
|
|
575
|
+
this.setAttribute("aria-label", "Toggle navigation"); this.render(); }
|
|
576
|
+
attributeChangedCallback() { if (this.isConnected)
|
|
577
|
+
this.render(); }
|
|
578
|
+
render() {
|
|
579
|
+
const shadow = this.shadowRoot ?? this.attachShadow({ mode: "open", delegatesFocus: true });
|
|
580
|
+
const previous = shadow.querySelector("button");
|
|
581
|
+
const restoreFocus = previous !== null && shadow.activeElement === previous;
|
|
582
|
+
const button = document.createElement("button");
|
|
583
|
+
button.className = this.getAttribute("appearance") || "secondary";
|
|
584
|
+
button.type = this.getAttribute("type") === "submit" || this.getAttribute("type") === "reset" ? this.getAttribute("type") : "button";
|
|
585
|
+
const disabled = this.hasAttribute("disabled");
|
|
586
|
+
const disabledFocusable = this.hasAttribute("disabled-focusable");
|
|
587
|
+
button.disabled = disabled && !disabledFocusable;
|
|
588
|
+
if (disabledFocusable) {
|
|
589
|
+
button.tabIndex = 0;
|
|
590
|
+
button.setAttribute("aria-disabled", "true");
|
|
591
|
+
}
|
|
592
|
+
for (const attribute of this.attributes) {
|
|
593
|
+
if (attribute.name.startsWith("aria-") || attribute.name === "title")
|
|
594
|
+
button.setAttribute(attribute.name, attribute.value);
|
|
595
|
+
}
|
|
596
|
+
button.setAttribute("aria-label", this.getAttribute("aria-label") || "Toggle navigation");
|
|
597
|
+
if (disabledFocusable)
|
|
598
|
+
button.addEventListener("click", event => { event.preventDefault(); event.stopImmediatePropagation(); });
|
|
599
|
+
const iconSlot = document.createElement("slot");
|
|
600
|
+
iconSlot.name = "icon";
|
|
601
|
+
const icon = document.createElement("span");
|
|
602
|
+
icon.className = "icon";
|
|
603
|
+
icon.append(iconSlot);
|
|
604
|
+
const content = document.createElement("span");
|
|
605
|
+
content.className = "content";
|
|
606
|
+
content.append(document.createElement("slot"));
|
|
607
|
+
const style = document.createElement("style");
|
|
608
|
+
style.textContent = `${base}${buttonControlCss}:host{display:inline-flex;vertical-align:middle}button{min-width:44px;min-height:44px;padding:8px}::slotted([slot=icon]){display:inline-flex;align-items:center;justify-content:center;line-height:0}::slotted([slot=icon]) svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round}@media(forced-colors:active){button:focus-visible{outline-color:Highlight}}`;
|
|
609
|
+
button.append(icon, content);
|
|
610
|
+
shadow.replaceChildren(style, button);
|
|
611
|
+
if (restoreFocus)
|
|
612
|
+
button.focus();
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
customElements.define("spui-hamburger", SpuiHamburger);
|
|
616
|
+
}
|
|
617
|
+
export function defineNavDrawer() { defineNavPart("spui-nav-drawer", ":host{display:block;min-width:0}"); }
|
|
618
|
+
export function defineNavDrawerHeader() { defineNavPart("spui-nav-drawer-header", ":host{display:flex;align-items:center;gap:12px;min-height:44px;padding:8px 12px;border-block-end:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1));font-weight:600}"); }
|
|
619
|
+
export function defineNavDrawerBody() { defineNavPart("spui-nav-drawer-body", ":host{display:grid;align-content:start;gap:2px;min-width:0}"); }
|
|
620
|
+
export function defineNavDrawerFooter() { defineNavPart("spui-nav-drawer-footer", ":host{display:grid;gap:4px;margin-block-start:auto;padding:8px 0;border-block-start:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1))}"); }
|
|
621
|
+
export function defineNavCategory() {
|
|
622
|
+
if (customElements.get("spui-nav-category"))
|
|
623
|
+
return;
|
|
624
|
+
class SpuiNavCategory extends HTMLElement {
|
|
625
|
+
connectedCallback() { if (!this.shadowRoot) {
|
|
626
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
627
|
+
const style = document.createElement("style");
|
|
628
|
+
style.textContent = `${base}:host{display:block;min-width:0}`;
|
|
629
|
+
shadow.append(style, document.createElement("slot"));
|
|
630
|
+
} }
|
|
631
|
+
}
|
|
632
|
+
customElements.define("spui-nav-category", SpuiNavCategory);
|
|
633
|
+
}
|
|
634
|
+
export function defineNavCategoryItem() {
|
|
635
|
+
if (customElements.get("spui-nav-category-item"))
|
|
636
|
+
return;
|
|
637
|
+
class SpuiNavCategoryItem extends HTMLElement {
|
|
638
|
+
static observedAttributes = ["expanded", "controls", "disabled", "compact", "selected", "aria-label"];
|
|
639
|
+
connectedCallback() { if (!this.shadowRoot)
|
|
640
|
+
this.render(); this.sync(); }
|
|
641
|
+
attributeChangedCallback() { if (this.isConnected)
|
|
642
|
+
this.sync(); }
|
|
643
|
+
sync() { const button = this.shadowRoot?.querySelector("button"); if (!button)
|
|
644
|
+
return; button.setAttribute("aria-expanded", String(this.hasAttribute("expanded"))); if (this.hasAttribute("selected"))
|
|
645
|
+
button.setAttribute("aria-current", "page");
|
|
646
|
+
else
|
|
647
|
+
button.removeAttribute("aria-current"); const controls = this.getAttribute("controls"); if (controls)
|
|
648
|
+
button.setAttribute("aria-controls", controls); button.disabled = this.hasAttribute("disabled"); const defaultSlot = button.querySelector("slot:not([name])"); const label = this.getAttribute("aria-label") ?? defaultSlot?.assignedNodes({ flatten: true }).map(node => node.textContent ?? "").join("").trim() ?? ""; button.setAttribute("aria-label", label); button.title = this.hasAttribute("compact") ? label : ""; const fallback = button.querySelector("[part=compact-fallback]"); if (fallback) {
|
|
649
|
+
fallback.textContent = Array.from(label)[0] ?? "";
|
|
650
|
+
fallback.hidden = Boolean(this.querySelector('[slot="icon"],[slot="avatar"]'));
|
|
651
|
+
} }
|
|
652
|
+
render() { const shadow = this.attachShadow({ mode: "open" }); const button = document.createElement("button"); button.type = "button"; button.part.add("action"); button.innerHTML = "<slot name=avatar></slot><slot name=icon></slot><span part=label><slot></slot></span><span part=compact-fallback aria-hidden=true></span><span aria-hidden=true part=chevron><slot name=expand-icon></slot></span>"; const chevron = button.querySelector("[part=chevron]"); const expandIconSlot = button.querySelector('slot[name="expand-icon"]'); expandIconSlot.addEventListener("slotchange", () => chevron.classList.toggle("custom", expandIconSlot.assignedNodes({ flatten: true }).length > 0)); button.querySelector("slot:not([name])")?.addEventListener("slotchange", () => this.sync()); const style = document.createElement("style"); style.textContent = `${base}:host{display:block}button{box-sizing:border-box;display:flex;align-items:center;gap:12px;width:100%;min-height:36px;padding:var(--spui-nav-item-block,7px) 12px;border:0;border-radius:var(--spui-nav-item-radius,5px);background:transparent;color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424));font:inherit;text-align:start;cursor:pointer}button:hover{background:var(--spui-ui-hover,var(--spui-semantic-subtle-background,#f5f5f5))}button[aria-current=page]{background:color-mix(in srgb,var(--spui-ui-accent,#78716c) 12%,var(--spui-ui-surface,#fff));font-weight:600}button:focus-visible{outline:2px solid var(--spui-focus-ring,var(--spui-semantic-focus-border,#005a9e));outline-offset:2px}::slotted([slot=avatar]){inline-size:28px;block-size:28px;flex:none}[part=compact-fallback]{display:none}:host([compact]) button{justify-content:center;gap:0;padding-inline:4px}:host([compact]) [part=label]{position:absolute;inline-size:1px;block-size:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}:host([compact]) [part=compact-fallback]:not([hidden]){display:grid;place-items:center;inline-size:28px;block-size:28px;border-radius:50%;background:var(--spui-ui-surface-hover,var(--spui-semantic-subtle-background,#f5f5f5));font-size:12px;font-weight:600}:host([compact]) [part=chevron]{display:none}span[part=chevron]:not(.custom){box-sizing:border-box;width:7px;height:7px;margin-inline-start:auto;border:solid currentColor;border-width:0 1.5px 1.5px 0;transform:translateY(-2px) rotate(45deg);transition:transform var(--spui-motion-duration-fast,.12s) var(--spui-motion-easing-standard,cubic-bezier(.2,0,0,1))}:host([expanded]) span[part=chevron]:not(.custom){transform:translateY(2px) rotate(225deg)}span[part=chevron].custom{display:inline-flex;align-items:center;justify-content:center;flex:none;margin-inline-start:auto}:host([disabled]) button{opacity:.55;cursor:not-allowed}@media(prefers-reduced-motion:reduce){span[part=chevron]:not(.custom){transition:none}}@media(forced-colors:active){button{color:ButtonText}}`; shadow.append(style, button); }
|
|
653
|
+
}
|
|
654
|
+
customElements.define("spui-nav-category-item", SpuiNavCategoryItem);
|
|
655
|
+
}
|
|
656
|
+
export function defineNavSubItemGroup() {
|
|
657
|
+
if (customElements.get("spui-nav-sub-item-group"))
|
|
658
|
+
return;
|
|
659
|
+
class SpuiNavSubItemGroup extends HTMLElement {
|
|
660
|
+
expanded = false;
|
|
661
|
+
exitPending = false;
|
|
662
|
+
exitGeneration = 0;
|
|
663
|
+
hasSynced = false;
|
|
664
|
+
connectedCallback() {
|
|
665
|
+
if (!this.shadowRoot) {
|
|
666
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
667
|
+
const style = document.createElement("style");
|
|
668
|
+
style.textContent = `${base}:host{display:grid;gap:2px;padding-inline-start:16px}:host([compact]){padding-inline-start:0}:host([hidden]){display:none}`;
|
|
669
|
+
shadow.append(style, document.createElement("slot"));
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
setExpanded(open) {
|
|
673
|
+
if (!this.hasSynced) {
|
|
674
|
+
this.hasSynced = true;
|
|
675
|
+
this.expanded = open;
|
|
676
|
+
this.hidden = !open;
|
|
677
|
+
this.inert = !open;
|
|
678
|
+
if (open)
|
|
679
|
+
this.removeAttribute("aria-hidden");
|
|
680
|
+
else
|
|
681
|
+
this.setAttribute("aria-hidden", "true");
|
|
682
|
+
this.toggleAttribute("motion-visible", open);
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
this.expanded = open;
|
|
686
|
+
this.toggleAttribute("motion-visible", open);
|
|
687
|
+
if (open) {
|
|
688
|
+
this.exitGeneration++;
|
|
689
|
+
this.exitPending = false;
|
|
690
|
+
this.hidden = false;
|
|
691
|
+
this.inert = false;
|
|
692
|
+
this.removeAttribute("aria-hidden");
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
if (!this.hasAttribute("motion") || this.hidden) {
|
|
696
|
+
this.exitPending = false;
|
|
697
|
+
this.hidden = true;
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
this.exitPending = true;
|
|
701
|
+
this.hidden = false;
|
|
702
|
+
this.inert = true;
|
|
703
|
+
this.setAttribute("aria-hidden", "true");
|
|
704
|
+
const generation = ++this.exitGeneration;
|
|
705
|
+
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
706
|
+
const animations = new Set();
|
|
707
|
+
const visit = (element) => {
|
|
708
|
+
for (const animation of element.getAnimations())
|
|
709
|
+
if (animation.playState === "running")
|
|
710
|
+
animations.add(animation);
|
|
711
|
+
if (element.shadowRoot)
|
|
712
|
+
for (const child of element.shadowRoot.children)
|
|
713
|
+
visit(child);
|
|
714
|
+
if (element instanceof HTMLSlotElement)
|
|
715
|
+
for (const child of element.assignedElements({ flatten: true }))
|
|
716
|
+
visit(child);
|
|
717
|
+
for (const child of element.children)
|
|
718
|
+
visit(child);
|
|
719
|
+
};
|
|
720
|
+
visit(this);
|
|
721
|
+
const finish = () => {
|
|
722
|
+
if (generation !== this.exitGeneration || this.expanded || !this.exitPending)
|
|
723
|
+
return;
|
|
724
|
+
this.exitPending = false;
|
|
725
|
+
this.hidden = true;
|
|
726
|
+
};
|
|
727
|
+
if (animations.size)
|
|
728
|
+
void Promise.allSettled([...animations].map(animation => animation.finished)).then(finish);
|
|
729
|
+
else
|
|
730
|
+
finish();
|
|
731
|
+
}));
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
customElements.define("spui-nav-sub-item-group", SpuiNavSubItemGroup);
|
|
735
|
+
}
|
|
736
|
+
export function defineNavDivider() {
|
|
737
|
+
if (customElements.get("spui-nav-divider"))
|
|
738
|
+
return;
|
|
739
|
+
class SpuiNavDivider extends HTMLElement {
|
|
740
|
+
static observedAttributes = ["align-content", "appearance", "inset", "vertical", "aria-label", "aria-labelledby"];
|
|
741
|
+
connectedCallback() { if (!this.shadowRoot)
|
|
742
|
+
this.render(); this.sync(); }
|
|
743
|
+
attributeChangedCallback() { if (this.isConnected)
|
|
744
|
+
this.sync(); }
|
|
745
|
+
sync() {
|
|
746
|
+
const vertical = this.hasAttribute("vertical");
|
|
747
|
+
this.dataset.orientation = vertical ? "vertical" : "horizontal";
|
|
748
|
+
this.dataset.alignContent = this.getAttribute("align-content") ?? "center";
|
|
749
|
+
this.dataset.dividerAppearance = this.getAttribute("appearance") ?? "default";
|
|
750
|
+
this.setAttribute("role", "separator");
|
|
751
|
+
this.setAttribute("aria-orientation", vertical ? "vertical" : "horizontal");
|
|
752
|
+
const wrapper = this.shadowRoot?.querySelector('slot[name="wrapper"]');
|
|
753
|
+
const hasWrapper = Boolean(wrapper?.assignedNodes().some(node => node.nodeType === Node.ELEMENT_NODE || Boolean(node.textContent?.trim())));
|
|
754
|
+
this.dataset.hasLabel = String(hasWrapper);
|
|
755
|
+
}
|
|
756
|
+
render() {
|
|
757
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
758
|
+
const before = document.createElement("span");
|
|
759
|
+
before.className = "line";
|
|
760
|
+
before.part.add("line");
|
|
761
|
+
before.setAttribute("aria-hidden", "true");
|
|
762
|
+
const wrapper = document.createElement("slot");
|
|
763
|
+
wrapper.name = "wrapper";
|
|
764
|
+
wrapper.addEventListener("slotchange", () => this.sync());
|
|
765
|
+
const after = document.createElement("span");
|
|
766
|
+
after.className = "line";
|
|
767
|
+
after.part.add("line");
|
|
768
|
+
after.setAttribute("aria-hidden", "true");
|
|
769
|
+
const style = document.createElement("style");
|
|
770
|
+
style.textContent = `${base}:host{box-sizing:border-box;display:flex;align-items:center;gap:var(--spui-divider-gap,12px);min-width:0;margin-block:var(--spui-divider-margin-block,12px);color:var(--spui-ui-muted,var(--spui-semantic-body-subtext,#616161));font:inherit}:host([data-orientation=vertical]){display:inline-flex;flex-direction:column;align-self:stretch;min-height:1em;width:1px;margin-inline:var(--spui-divider-margin-inline,12px);margin-block:0}:host([data-has-label=false]) slot{display:none}:host([data-has-label=false]) .line:last-child{display:none}:host([data-has-label=true]) slot{min-width:0;font-size:.875em;line-height:1.25;text-align:center}.line{flex:1;min-height:1px;background:var(--spui-divider-color,var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1)))}:host([data-orientation=vertical]) .line{min-width:1px;min-height:0;width:1px;height:auto;background:var(--spui-divider-color,var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1)))}:host([data-divider-appearance=brand]) .line{background:var(--spui-divider-color,var(--spui-base-accent,var(--spui-ui-accent,#0078d4)))}:host([data-divider-appearance=strong]) .line{background:var(--spui-divider-color,color-mix(in srgb,var(--spui-ui-text,#242424) 44%,var(--spui-ui-stroke,#d1d1d1)))}:host([data-divider-appearance=subtle]) .line{background:var(--spui-divider-color,color-mix(in srgb,var(--spui-ui-stroke,#d1d1d1) 56%,transparent))}:host([data-align-content=start]) .line:first-child{flex:0}:host([data-align-content=end]) .line:last-child{flex:0}:host([data-align-content=center]) .line{flex:1}:host([inset]){margin-inline:var(--spui-divider-inset,16px)}@media(forced-colors:active){.line{background:CanvasText}}`;
|
|
771
|
+
shadow.append(style, before, wrapper, after);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
customElements.define("spui-nav-divider", SpuiNavDivider);
|
|
775
|
+
}
|
|
776
|
+
export function defineNavSectionHeader() {
|
|
777
|
+
if (customElements.get("spui-nav-section-header"))
|
|
778
|
+
return;
|
|
779
|
+
class SpuiNavSectionHeader extends HTMLElement {
|
|
780
|
+
connectedCallback() { if (!this.hasAttribute("role"))
|
|
781
|
+
this.setAttribute("role", "heading"); if (!this.hasAttribute("aria-level"))
|
|
782
|
+
this.setAttribute("aria-level", "3"); if (!this.shadowRoot) {
|
|
783
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
784
|
+
const label = document.createElement("slot");
|
|
785
|
+
const style = document.createElement("style");
|
|
786
|
+
style.textContent = `${base}:host{display:block;padding:12px 12px 4px;color:var(--spui-ui-muted,var(--spui-semantic-body-subtext,#616161));font:600 12px/1.3 var(--spui-font-family,inherit);letter-spacing:.02em;text-transform:uppercase}:host([compact]){display:none}`;
|
|
787
|
+
shadow.append(style, label);
|
|
788
|
+
} }
|
|
789
|
+
}
|
|
790
|
+
customElements.define("spui-nav-section-header", SpuiNavSectionHeader);
|
|
791
|
+
}
|