@spfx-fast/sharepoint-ui 0.4.2 → 0.5.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/QUICKSTART.md +18 -0
- package/README.md +19 -24
- package/components.json +240 -5694
- package/dist/accordion.d.ts +11 -0
- package/dist/accordion.js +4 -0
- package/dist/alert.d.ts +3 -0
- package/dist/alert.js +4 -0
- package/dist/attachment-list.d.ts +15 -0
- package/dist/attachment-list.js +14 -0
- package/dist/avatar-group.d.ts +12 -0
- package/dist/avatar-group.js +7 -0
- package/dist/avatar.d.ts +6 -0
- package/dist/avatar.js +5 -0
- package/dist/badge.d.ts +3 -0
- package/dist/badge.js +4 -0
- package/dist/breadcrumb.d.ts +10 -0
- package/dist/breadcrumb.js +9 -0
- package/dist/button-group.d.ts +6 -0
- package/dist/button-group.js +4 -0
- package/dist/button.d.ts +3 -0
- package/dist/button.js +4 -0
- package/dist/card.d.ts +3 -0
- package/dist/card.js +4 -0
- package/dist/carousel.d.ts +11 -0
- package/dist/carousel.js +6 -0
- package/dist/checkbox.d.ts +3 -0
- package/dist/checkbox.js +4 -0
- package/dist/combobox.d.ts +9 -0
- package/dist/combobox.js +6 -0
- package/dist/command-bar.d.ts +6 -0
- package/dist/command-bar.js +4 -0
- package/dist/copy-button.d.ts +7 -0
- package/dist/copy-button.js +19 -0
- package/dist/data-grid.d.ts +25 -0
- package/dist/data-grid.js +39 -0
- package/dist/date-range-picker.d.ts +12 -0
- package/dist/date-range-picker.js +4 -0
- package/dist/dialog.d.ts +9 -0
- package/dist/dialog.js +21 -0
- package/dist/divider.d.ts +3 -0
- package/dist/divider.js +4 -0
- package/dist/drawer.d.ts +6 -0
- package/dist/drawer.js +5 -0
- package/dist/empty-state.d.ts +7 -0
- package/dist/empty-state.js +5 -0
- package/dist/field.d.ts +15 -0
- package/dist/field.js +11 -0
- package/dist/file-dropzone.d.ts +15 -0
- package/dist/file-dropzone.js +21 -0
- package/dist/filter-bar.d.ts +9 -0
- package/dist/filter-bar.js +9 -0
- package/dist/image.d.ts +5 -0
- package/dist/image.js +4 -0
- package/dist/index.d.ts +68 -76
- package/dist/index.js +60 -66
- package/dist/input.d.ts +3 -0
- package/dist/input.js +4 -0
- package/dist/label.d.ts +3 -0
- package/dist/label.js +4 -0
- package/dist/link.d.ts +3 -0
- package/dist/link.js +9 -0
- package/dist/list-view.d.ts +29 -0
- package/dist/list-view.js +14 -0
- package/dist/list.d.ts +6 -0
- package/dist/list.js +5 -0
- package/dist/lookup-picker.d.ts +12 -0
- package/dist/lookup-picker.js +4 -0
- package/dist/menu.d.ts +6 -0
- package/dist/menu.js +4 -0
- package/dist/nav.d.ts +12 -0
- package/dist/nav.js +4 -0
- package/dist/pagination.d.ts +11 -0
- package/dist/pagination.js +5 -0
- package/dist/person-picker.d.ts +13 -0
- package/dist/person-picker.js +4 -0
- package/dist/persona.d.ts +7 -0
- package/dist/persona.js +5 -0
- package/dist/popover.d.ts +6 -0
- package/dist/popover.js +4 -0
- package/dist/progress-bar.d.ts +5 -0
- package/dist/progress-bar.js +5 -0
- package/dist/radio-group.d.ts +6 -0
- package/dist/radio-group.js +4 -0
- package/dist/radio.d.ts +3 -0
- package/dist/radio.js +4 -0
- package/dist/rating.d.ts +8 -0
- package/dist/rating.js +5 -0
- package/dist/react.d.ts +1 -4583
- package/dist/react.js +1 -6837
- package/dist/select.d.ts +3 -0
- package/dist/select.js +4 -0
- package/dist/sharepoint-field.d.ts +18 -0
- package/dist/sharepoint-field.js +54 -0
- package/dist/skeleton.d.ts +6 -0
- package/dist/skeleton.js +9 -0
- package/dist/spinner.d.ts +5 -0
- package/dist/spinner.js +4 -0
- package/dist/swatch-picker.d.ts +17 -0
- package/dist/swatch-picker.js +11 -0
- package/dist/switch.d.ts +3 -0
- package/dist/switch.js +4 -0
- package/dist/table.d.ts +6 -0
- package/dist/table.js +4 -0
- package/dist/tabs.d.ts +14 -0
- package/dist/tabs.js +30 -0
- package/dist/tag-group.d.ts +6 -0
- package/dist/tag-group.js +4 -0
- package/dist/tag-picker.d.ts +12 -0
- package/dist/tag-picker.js +4 -0
- package/dist/tag.d.ts +7 -0
- package/dist/tag.js +5 -0
- package/dist/text.d.ts +5 -0
- package/dist/text.js +4 -0
- package/dist/textarea.d.ts +3 -0
- package/dist/textarea.js +4 -0
- package/dist/theme.d.ts +15 -167
- package/dist/theme.js +36 -162
- package/dist/toast.d.ts +9 -0
- package/dist/toast.js +12 -0
- package/dist/tree.d.ts +13 -0
- package/dist/tree.js +9 -0
- package/dist/view-card.d.ts +8 -0
- package/dist/view-card.js +4 -0
- package/dist/view-switcher.d.ts +13 -0
- package/dist/view-switcher.js +7 -0
- package/dist/virtual-list.d.ts +11 -0
- package/dist/virtual-list.js +25 -0
- package/measurements.json +365 -0
- package/package.json +19 -42
- package/src/theme.css +125 -0
- package/AGENTS.md +0 -211
- package/dist/appearance.d.ts +0 -6
- package/dist/appearance.js +0 -217
- package/dist/elements/accordion.d.ts +0 -9
- package/dist/elements/accordion.js +0 -338
- package/dist/elements/alert.d.ts +0 -2
- package/dist/elements/alert.js +0 -62
- package/dist/elements/avatar-group-primitives.d.ts +0 -3
- package/dist/elements/avatar-group-primitives.js +0 -189
- package/dist/elements/avatar-group.d.ts +0 -2
- package/dist/elements/avatar-group.js +0 -110
- package/dist/elements/avatar.d.ts +0 -4
- package/dist/elements/avatar.js +0 -251
- package/dist/elements/badge.d.ts +0 -8
- package/dist/elements/badge.js +0 -182
- package/dist/elements/breadcrumb.d.ts +0 -4
- package/dist/elements/breadcrumb.js +0 -233
- package/dist/elements/button-group.d.ts +0 -1
- package/dist/elements/button-group.js +0 -20
- package/dist/elements/button-variants.d.ts +0 -6
- package/dist/elements/button-variants.js +0 -339
- package/dist/elements/button.d.ts +0 -5
- package/dist/elements/button.js +0 -233
- package/dist/elements/card-primitives.d.ts +0 -3
- package/dist/elements/card-primitives.js +0 -83
- package/dist/elements/card.d.ts +0 -5
- package/dist/elements/card.js +0 -213
- package/dist/elements/carousel.d.ts +0 -92
- package/dist/elements/carousel.js +0 -1112
- package/dist/elements/color-picker.d.ts +0 -24
- package/dist/elements/color-picker.js +0 -1004
- package/dist/elements/combobox.d.ts +0 -1
- package/dist/elements/combobox.js +0 -1012
- package/dist/elements/data-grid-model.d.ts +0 -117
- package/dist/elements/data-grid-model.js +0 -294
- package/dist/elements/data-grid.d.ts +0 -29
- package/dist/elements/data-grid.js +0 -1567
- package/dist/elements/date-picker.d.ts +0 -1
- package/dist/elements/date-picker.js +0 -486
- package/dist/elements/dialog.d.ts +0 -23
- package/dist/elements/dialog.js +0 -409
- package/dist/elements/divider.d.ts +0 -2
- package/dist/elements/divider.js +0 -66
- package/dist/elements/drawer.d.ts +0 -3
- package/dist/elements/drawer.js +0 -308
- package/dist/elements/field-composition.d.ts +0 -26
- package/dist/elements/field-composition.js +0 -133
- package/dist/elements/field.d.ts +0 -1
- package/dist/elements/field.js +0 -67
- package/dist/elements/file-upload.d.ts +0 -6
- package/dist/elements/file-upload.js +0 -211
- package/dist/elements/floating-position.d.ts +0 -26
- package/dist/elements/floating-position.js +0 -39
- package/dist/elements/image.d.ts +0 -28
- package/dist/elements/image.js +0 -38
- package/dist/elements/info.d.ts +0 -9
- package/dist/elements/info.js +0 -102
- package/dist/elements/input.d.ts +0 -5
- package/dist/elements/input.js +0 -255
- package/dist/elements/label.d.ts +0 -15
- package/dist/elements/label.js +0 -56
- package/dist/elements/link.d.ts +0 -1
- package/dist/elements/link.js +0 -92
- package/dist/elements/list.d.ts +0 -19
- package/dist/elements/list.js +0 -297
- package/dist/elements/menu.d.ts +0 -33
- package/dist/elements/menu.js +0 -1103
- package/dist/elements/message-bar.d.ts +0 -10
- package/dist/elements/message-bar.js +0 -299
- package/dist/elements/nav.d.ts +0 -32
- package/dist/elements/nav.js +0 -791
- package/dist/elements/overflow.d.ts +0 -9
- package/dist/elements/overflow.js +0 -218
- package/dist/elements/persona.d.ts +0 -3
- package/dist/elements/persona.js +0 -125
- package/dist/elements/popover.d.ts +0 -77
- package/dist/elements/popover.js +0 -840
- package/dist/elements/progress-bar.d.ts +0 -4
- package/dist/elements/progress-bar.js +0 -82
- package/dist/elements/radio-group.d.ts +0 -1
- package/dist/elements/radio-group.js +0 -303
- package/dist/elements/rating-display.d.ts +0 -2
- package/dist/elements/rating-display.js +0 -125
- package/dist/elements/rating.d.ts +0 -2
- package/dist/elements/rating.js +0 -206
- package/dist/elements/rich-text-editor.d.ts +0 -18
- package/dist/elements/rich-text-editor.js +0 -508
- package/dist/elements/search.d.ts +0 -3
- package/dist/elements/search.js +0 -207
- package/dist/elements/select.d.ts +0 -6
- package/dist/elements/select.js +0 -291
- package/dist/elements/shared.d.ts +0 -19
- package/dist/elements/shared.js +0 -396
- package/dist/elements/skeleton.d.ts +0 -6
- package/dist/elements/skeleton.js +0 -91
- package/dist/elements/slider.d.ts +0 -1
- package/dist/elements/slider.js +0 -248
- package/dist/elements/spin-button.d.ts +0 -7
- package/dist/elements/spin-button.js +0 -499
- package/dist/elements/spinner.d.ts +0 -4
- package/dist/elements/spinner.js +0 -124
- package/dist/elements/swatch-picker.d.ts +0 -5
- package/dist/elements/swatch-picker.js +0 -363
- package/dist/elements/table.d.ts +0 -21
- package/dist/elements/table.js +0 -261
- package/dist/elements/tabs.d.ts +0 -1
- package/dist/elements/tabs.js +0 -276
- package/dist/elements/tag-picker.d.ts +0 -29
- package/dist/elements/tag-picker.js +0 -697
- package/dist/elements/tags.d.ts +0 -21
- package/dist/elements/tags.js +0 -421
- package/dist/elements/teaching-popover.d.ts +0 -32
- package/dist/elements/teaching-popover.js +0 -412
- package/dist/elements/text.d.ts +0 -9
- package/dist/elements/text.js +0 -75
- package/dist/elements/textarea.d.ts +0 -1
- package/dist/elements/textarea.js +0 -182
- package/dist/elements/toast.d.ts +0 -25
- package/dist/elements/toast.js +0 -337
- package/dist/elements/toaster.d.ts +0 -6
- package/dist/elements/toaster.js +0 -356
- package/dist/elements/toggle.d.ts +0 -2
- package/dist/elements/toggle.js +0 -246
- package/dist/elements/toolbar.d.ts +0 -12
- package/dist/elements/toolbar.js +0 -381
- package/dist/elements/tooltip.d.ts +0 -76
- package/dist/elements/tooltip.js +0 -510
- package/dist/elements/tree-model.d.ts +0 -19
- package/dist/elements/tree-model.js +0 -34
- package/dist/elements/tree.d.ts +0 -5
- package/dist/elements/tree.js +0 -273
- package/dist/elements/view-card.d.ts +0 -2
- package/dist/elements/view-card.js +0 -78
- package/dist/elements/virtual-list.d.ts +0 -41
- package/dist/elements/virtual-list.js +0 -369
- package/dist/elements.d.ts +0 -72
- package/dist/elements.js +0 -207
- package/dist/virtualizer-hooks.d.ts +0 -80
- package/dist/virtualizer-hooks.js +0 -253
- package/scripts/generate-token-index.mjs +0 -43
- package/scripts/sync-component-catalog-signatures.mjs +0 -55
- package/scripts/validate-component-catalog.mjs +0 -44
- package/skills/sharepoint-ui/SKILL.md +0 -12
- package/skills/sharepoint-ui/references/choosing-components.md +0 -20
- package/skills/sharepoint-ui/references/sharepoint-patterns.md +0 -17
- package/tokens.json +0 -3777
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { base } from "./shared.js";
|
|
2
|
-
import { buttonControlCss } from "./button.js";
|
|
3
|
-
export function defineBreadcrumb() {
|
|
4
|
-
if (customElements.get("spui-breadcrumb"))
|
|
5
|
-
return;
|
|
6
|
-
class SpuiBreadcrumb extends HTMLElement {
|
|
7
|
-
static observedAttributes = ["label", "focus-mode", "size", "separator", "aria-label"];
|
|
8
|
-
observer;
|
|
9
|
-
events;
|
|
10
|
-
connectedCallback() {
|
|
11
|
-
if (!this.shadowRoot)
|
|
12
|
-
this.render();
|
|
13
|
-
this.observer = new MutationObserver(() => this.syncItems());
|
|
14
|
-
this.observer.observe(this, { childList: true, subtree: true });
|
|
15
|
-
this.events?.abort();
|
|
16
|
-
this.events = new AbortController();
|
|
17
|
-
this.addEventListener("keydown", event => this.onKeyDown(event), { signal: this.events.signal });
|
|
18
|
-
this.addEventListener("focusin", event => this.onFocusIn(event), { signal: this.events.signal });
|
|
19
|
-
queueMicrotask(() => this.syncItems());
|
|
20
|
-
}
|
|
21
|
-
disconnectedCallback() { this.observer?.disconnect(); this.events?.abort(); }
|
|
22
|
-
attributeChangedCallback(name) {
|
|
23
|
-
if (!this.isConnected)
|
|
24
|
-
return;
|
|
25
|
-
if (name === "label" || name === "aria-label") {
|
|
26
|
-
const nav = this.shadowRoot?.querySelector("nav");
|
|
27
|
-
const label = this.getAttribute("aria-label") ?? this.getAttribute("label") ?? "Breadcrumb";
|
|
28
|
-
nav?.setAttribute("aria-label", label);
|
|
29
|
-
}
|
|
30
|
-
if (name === "separator")
|
|
31
|
-
this.style.setProperty("--spui-breadcrumb-separator", JSON.stringify(this.getAttribute("separator") ?? "›"));
|
|
32
|
-
if (name === "focus-mode")
|
|
33
|
-
this.syncItems();
|
|
34
|
-
}
|
|
35
|
-
listRoot() { return this.querySelector(":scope > [slot=list]") ?? this; }
|
|
36
|
-
items() { return [...this.listRoot().children].filter((child) => child.localName === "spui-breadcrumb-item"); }
|
|
37
|
-
linkFor(item) {
|
|
38
|
-
const child = [...item.children].find(element => element.localName === "spui-link" || element.localName === "spui-breadcrumb-button" || element.matches("a,button,[tabindex]"));
|
|
39
|
-
if (!child)
|
|
40
|
-
return null;
|
|
41
|
-
return child.localName === "spui-link" || child.localName === "spui-breadcrumb-button" ? child.shadowRoot?.querySelector("a,button") ?? null : child;
|
|
42
|
-
}
|
|
43
|
-
syncItems() {
|
|
44
|
-
const items = this.items();
|
|
45
|
-
const explicitDivider = [...this.listRoot().children].some(child => child.localName === "spui-breadcrumb-divider");
|
|
46
|
-
items.forEach(item => explicitDivider ? item.setAttribute("data-explicit-divider", "") : item.removeAttribute("data-explicit-divider"));
|
|
47
|
-
const links = items.map(item => this.linkFor(item));
|
|
48
|
-
const active = links.findIndex(link => link?.matches(":focus"));
|
|
49
|
-
if (active >= 0)
|
|
50
|
-
this.dataset.rovingIndex = String(active);
|
|
51
|
-
const selected = Math.max(0, Math.min(Number(this.dataset.rovingIndex ?? 0), Math.max(0, links.length - 1)));
|
|
52
|
-
links.forEach((link, index) => {
|
|
53
|
-
if (!link)
|
|
54
|
-
return;
|
|
55
|
-
if (!link.hasAttribute("data-spui-breadcrumb-tabindex"))
|
|
56
|
-
link.setAttribute("data-spui-breadcrumb-tabindex", link.getAttribute("tabindex") ?? "__unset");
|
|
57
|
-
if (this.getAttribute("focus-mode") === "arrow")
|
|
58
|
-
link.tabIndex = index === selected ? 0 : -1;
|
|
59
|
-
else {
|
|
60
|
-
const original = link.getAttribute("data-spui-breadcrumb-tabindex");
|
|
61
|
-
if (original === "__unset")
|
|
62
|
-
link.removeAttribute("tabindex");
|
|
63
|
-
else if (original !== null)
|
|
64
|
-
link.setAttribute("tabindex", original);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
onFocusIn(event) {
|
|
69
|
-
const path = event.composedPath();
|
|
70
|
-
const index = this.items().findIndex(item => path.includes(item));
|
|
71
|
-
if (index >= 0 && this.getAttribute("focus-mode") === "arrow") {
|
|
72
|
-
this.dataset.rovingIndex = String(index);
|
|
73
|
-
this.syncItems();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
onKeyDown(event) {
|
|
77
|
-
if (this.getAttribute("focus-mode") !== "arrow")
|
|
78
|
-
return;
|
|
79
|
-
const items = this.items();
|
|
80
|
-
const links = items.map(item => this.linkFor(item));
|
|
81
|
-
const actionable = links.flatMap((link, index) => link ? [index] : []);
|
|
82
|
-
if (!actionable.length)
|
|
83
|
-
return;
|
|
84
|
-
const path = event.composedPath();
|
|
85
|
-
const current = items.findIndex(item => path.includes(item));
|
|
86
|
-
if (current < 0)
|
|
87
|
-
return;
|
|
88
|
-
const currentAction = actionable.indexOf(current);
|
|
89
|
-
if (currentAction < 0)
|
|
90
|
-
return;
|
|
91
|
-
const rtl = getComputedStyle(this).direction === "rtl";
|
|
92
|
-
let nextAction = -1;
|
|
93
|
-
if (event.key === (rtl ? "ArrowLeft" : "ArrowRight"))
|
|
94
|
-
nextAction = (currentAction + 1) % actionable.length;
|
|
95
|
-
else if (event.key === (rtl ? "ArrowRight" : "ArrowLeft"))
|
|
96
|
-
nextAction = (currentAction - 1 + actionable.length) % actionable.length;
|
|
97
|
-
else if (event.key === "Home")
|
|
98
|
-
nextAction = 0;
|
|
99
|
-
else if (event.key === "End")
|
|
100
|
-
nextAction = actionable.length - 1;
|
|
101
|
-
if (nextAction < 0)
|
|
102
|
-
return;
|
|
103
|
-
const next = actionable[nextAction];
|
|
104
|
-
const link = links[next];
|
|
105
|
-
if (!link)
|
|
106
|
-
return;
|
|
107
|
-
event.preventDefault();
|
|
108
|
-
this.dataset.rovingIndex = String(next);
|
|
109
|
-
this.syncItems();
|
|
110
|
-
link.focus();
|
|
111
|
-
}
|
|
112
|
-
render() {
|
|
113
|
-
const shadow = this.attachShadow({ mode: "open" });
|
|
114
|
-
const nav = document.createElement("nav");
|
|
115
|
-
nav.setAttribute("aria-label", this.getAttribute("aria-label") ?? this.getAttribute("label") ?? "Breadcrumb");
|
|
116
|
-
nav.part.add("navigation");
|
|
117
|
-
const list = document.createElement("ol");
|
|
118
|
-
list.part.add("list");
|
|
119
|
-
list.setAttribute("role", "list");
|
|
120
|
-
list.append(document.createElement("slot"));
|
|
121
|
-
const listSlot = document.createElement("slot");
|
|
122
|
-
listSlot.name = "list";
|
|
123
|
-
listSlot.addEventListener("slotchange", () => {
|
|
124
|
-
const assignedList = listSlot.assignedElements()[0];
|
|
125
|
-
if (assignedList instanceof HTMLElement && !assignedList.hasAttribute("role"))
|
|
126
|
-
assignedList.setAttribute("role", "list");
|
|
127
|
-
this.syncItems();
|
|
128
|
-
});
|
|
129
|
-
listSlot.append(list);
|
|
130
|
-
const style = document.createElement("style");
|
|
131
|
-
style.textContent = `${base}:host{display:block;min-width:0;--spui-breadcrumb-separator:${JSON.stringify(this.getAttribute("separator") ?? "›")}}nav{min-width:0;color:var(--spui-ui-muted,var(--spui-semantic-body-text,#616161));font-family:var(--spui-font-family,inherit);font-size:var(--spui-breadcrumb-font-size,14px)}ol,::slotted([slot=list]){display:flex;flex-wrap:wrap;align-items:center;gap:0;min-width:0;margin:0;padding:0;list-style:none}:host([size=small]) nav{--spui-breadcrumb-font-size:12px}:host([size=large]) nav{--spui-breadcrumb-font-size:16px}:host([size=medium]),:host(:not([size])){--spui-breadcrumb-item-gap:10px}::slotted(spui-breadcrumb-item){--spui-breadcrumb-separator-gap:var(--spui-breadcrumb-item-gap,10px)}@media(forced-colors:active){nav{color:CanvasText}}`;
|
|
132
|
-
nav.append(listSlot);
|
|
133
|
-
shadow.append(style, nav);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
customElements.define("spui-breadcrumb", SpuiBreadcrumb);
|
|
137
|
-
}
|
|
138
|
-
export function defineBreadcrumbItem() {
|
|
139
|
-
if (customElements.get("spui-breadcrumb-item"))
|
|
140
|
-
return;
|
|
141
|
-
class SpuiBreadcrumbItem extends HTMLElement {
|
|
142
|
-
static observedAttributes = ["current", "size"];
|
|
143
|
-
connectedCallback() { if (!this.shadowRoot)
|
|
144
|
-
this.render(); this.sync(); }
|
|
145
|
-
attributeChangedCallback() { if (this.isConnected)
|
|
146
|
-
this.sync(); }
|
|
147
|
-
sync() {
|
|
148
|
-
this.setAttribute("role", "listitem");
|
|
149
|
-
if (this.hasAttribute("current"))
|
|
150
|
-
this.setAttribute("aria-current", "page");
|
|
151
|
-
else if (this.getAttribute("aria-current") === "page")
|
|
152
|
-
this.removeAttribute("aria-current");
|
|
153
|
-
}
|
|
154
|
-
render() {
|
|
155
|
-
const shadow = this.attachShadow({ mode: "open" });
|
|
156
|
-
const slot = document.createElement("slot");
|
|
157
|
-
const style = document.createElement("style");
|
|
158
|
-
style.textContent = `${base}:host{display:inline-flex;flex:none;align-items:center;min-width:0;color:var(--spui-ui-muted,var(--spui-semantic-body-text,#616161));font:inherit}:host([current]){color:var(--spui-ui-text,var(--spui-semantic-body-text,#323130));font-weight:600}:host([size=small]){font-size:12px}:host([size=large]){font-size:16px}:host(:not(:last-child):not([data-explicit-divider]))::after{content:var(--spui-breadcrumb-separator,"›");display:inline-block;margin-inline-start:var(--spui-breadcrumb-separator-gap,10px);color:var(--spui-ui-stroke,var(--spui-semantic-body-divider,#a19f9d))}:host-context([dir=rtl]):not(:last-child):not([data-explicit-divider])::after{transform:scaleX(-1)}@media(forced-colors:active){:host{color:CanvasText}:host(:not(:last-child):not([data-explicit-divider]))::after{color:CanvasText}}`;
|
|
159
|
-
shadow.append(style, slot);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
customElements.define("spui-breadcrumb-item", SpuiBreadcrumbItem);
|
|
163
|
-
}
|
|
164
|
-
export function defineBreadcrumbDivider() {
|
|
165
|
-
if (customElements.get("spui-breadcrumb-divider"))
|
|
166
|
-
return;
|
|
167
|
-
class SpuiBreadcrumbDivider extends HTMLElement {
|
|
168
|
-
connectedCallback() {
|
|
169
|
-
if (this.shadowRoot)
|
|
170
|
-
return;
|
|
171
|
-
this.setAttribute("role", "presentation");
|
|
172
|
-
this.setAttribute("aria-hidden", "true");
|
|
173
|
-
const shadow = this.attachShadow({ mode: "open" });
|
|
174
|
-
const style = document.createElement("style");
|
|
175
|
-
style.textContent = `${base}:host{display:inline-flex;flex:none;align-items:center;justify-content:center;padding-inline:var(--spui-breadcrumb-item-gap,10px);color:var(--spui-ui-stroke,var(--spui-semantic-body-divider,#a19f9d));font:inherit}:host-context([dir=rtl]){transform:scaleX(-1)}@media(forced-colors:active){:host{color:CanvasText}}`;
|
|
176
|
-
const slot = document.createElement("slot");
|
|
177
|
-
if (!this.childNodes.length)
|
|
178
|
-
this.textContent = "›";
|
|
179
|
-
shadow.append(style, slot);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
customElements.define("spui-breadcrumb-divider", SpuiBreadcrumbDivider);
|
|
183
|
-
}
|
|
184
|
-
export function defineBreadcrumbButton() {
|
|
185
|
-
if (customElements.get("spui-breadcrumb-button"))
|
|
186
|
-
return;
|
|
187
|
-
class SpuiBreadcrumbButton extends HTMLElement {
|
|
188
|
-
static observedAttributes = ["href", "target", "rel", "type", "disabled", "disabled-focusable", "current", "size", "aria-label", "aria-current", "tabindex", "title"];
|
|
189
|
-
connectedCallback() { this.render(); }
|
|
190
|
-
attributeChangedCallback() { if (this.isConnected)
|
|
191
|
-
this.render(); }
|
|
192
|
-
render() {
|
|
193
|
-
const shadow = this.shadowRoot ?? this.attachShadow({ mode: "open", delegatesFocus: true });
|
|
194
|
-
const href = this.getAttribute("href");
|
|
195
|
-
const control = document.createElement(href !== null ? "a" : "button");
|
|
196
|
-
if (href !== null) {
|
|
197
|
-
control.setAttribute("href", href);
|
|
198
|
-
for (const name of ["target", "rel"]) {
|
|
199
|
-
const value = this.getAttribute(name);
|
|
200
|
-
if (value !== null)
|
|
201
|
-
control.setAttribute(name, value);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
else
|
|
205
|
-
control.type = this.getAttribute("type") === "submit" ? "submit" : "button";
|
|
206
|
-
const disabled = this.hasAttribute("disabled");
|
|
207
|
-
const disabledFocusable = this.hasAttribute("disabled-focusable");
|
|
208
|
-
if (disabled && href === null && !disabledFocusable)
|
|
209
|
-
control.disabled = true;
|
|
210
|
-
if (disabled && disabledFocusable || this.hasAttribute("current"))
|
|
211
|
-
control.setAttribute("aria-disabled", "true");
|
|
212
|
-
const current = this.getAttribute("aria-current") ?? (this.hasAttribute("current") ? "page" : null);
|
|
213
|
-
if (current)
|
|
214
|
-
control.setAttribute("aria-current", current);
|
|
215
|
-
for (const name of ["aria-label", "tabindex", "title"]) {
|
|
216
|
-
const value = this.getAttribute(name);
|
|
217
|
-
if (value !== null)
|
|
218
|
-
control.setAttribute(name, value);
|
|
219
|
-
}
|
|
220
|
-
if (disabled && (href !== null || disabledFocusable))
|
|
221
|
-
control.addEventListener("click", event => { event.preventDefault(); event.stopImmediatePropagation(); });
|
|
222
|
-
control.className = "subtle";
|
|
223
|
-
control.part.add("control");
|
|
224
|
-
const style = document.createElement("style");
|
|
225
|
-
style.textContent = `${buttonControlCss}:host{display:inline-flex;font:inherit}:host([size=small]) button,:host([size=small]) a{min-height:24px;padding-inline:8px;font-size:12px}:host([size=large]) button,:host([size=large]) a{min-height:40px;padding-inline:16px;font-size:16px}a{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;min-height:var(--spui-control-height,32px);padding-inline:14px;border:1px solid transparent;border-radius:var(--spui-control-radius,4px);color:inherit;text-decoration:none;cursor:pointer;font:inherit}a:hover{background:var(--spui-button-secondary-hover,color-mix(in srgb,var(--spui-ui-surface,#fff) 90%,var(--spui-ui-text,#242424) 10%))}:is(button,a):focus-visible{outline:2px solid var(--spui-ui-focus,var(--spui-semantic-focus-border,#005a9e));outline-offset:2px}:is(button,a)[aria-disabled=true]{opacity:.55;cursor:not-allowed}`;
|
|
226
|
-
const icon = document.createElement("slot");
|
|
227
|
-
icon.name = "icon";
|
|
228
|
-
control.append(icon, document.createElement("slot"));
|
|
229
|
-
shadow.replaceChildren(style, control);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
customElements.define("spui-breadcrumb-button", SpuiBreadcrumbButton);
|
|
233
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function defineButtonGroup(): void;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { base } from "./shared.js";
|
|
2
|
-
export function defineButtonGroup() {
|
|
3
|
-
if (customElements.get("spui-button-group"))
|
|
4
|
-
return;
|
|
5
|
-
class SpuiButtonGroup extends HTMLElement {
|
|
6
|
-
static observedAttributes = ["orientation"];
|
|
7
|
-
connectedCallback() {
|
|
8
|
-
if (!this.shadowRoot) {
|
|
9
|
-
const shadow = this.attachShadow({ mode: "open" });
|
|
10
|
-
const style = document.createElement("style");
|
|
11
|
-
style.textContent = `${base}:host{display:inline-flex;align-items:center;gap:var(--spui-button-group-gap,8px);min-width:0;vertical-align:middle}:host([orientation=vertical]){flex-direction:column;align-items:stretch}:host([hidden]){display:none}`;
|
|
12
|
-
shadow.append(style, document.createElement("slot"));
|
|
13
|
-
}
|
|
14
|
-
this.setAttribute("role", "group");
|
|
15
|
-
}
|
|
16
|
-
attributeChangedCallback() { if (this.isConnected)
|
|
17
|
-
this.setAttribute("role", "group"); }
|
|
18
|
-
}
|
|
19
|
-
customElements.define("spui-button-group", SpuiButtonGroup);
|
|
20
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type { ButtonAppearance, ButtonShape, ButtonSize } from "./button.js";
|
|
2
|
-
export declare function defineCompoundButton(): void;
|
|
3
|
-
/** A button trigger for Menu. The containing spui-menu owns popup state and focus management. */
|
|
4
|
-
export declare function defineMenuButton(): void;
|
|
5
|
-
export declare function defineToggleButton(): void;
|
|
6
|
-
export declare function defineSplitButton(): void;
|
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
import { buttonControlCss } from "./button.js";
|
|
2
|
-
import { base, stopHostAccessibleNameSync, syncHostAccessibleName } from "./shared.js";
|
|
3
|
-
const forward = ["aria-label", "aria-labelledby", "aria-describedby", "aria-description", "title"];
|
|
4
|
-
export function defineCompoundButton() {
|
|
5
|
-
if (customElements.get("spui-compound-button"))
|
|
6
|
-
return;
|
|
7
|
-
class SpuiCompoundButton extends HTMLElement {
|
|
8
|
-
static observedAttributes = ["appearance", "size", "shape", "disabled", "disabled-focusable", "icon-position", ...forward];
|
|
9
|
-
observer;
|
|
10
|
-
connectedCallback() {
|
|
11
|
-
if (!this.shadowRoot)
|
|
12
|
-
this.render();
|
|
13
|
-
else
|
|
14
|
-
this.sync();
|
|
15
|
-
this.observer?.disconnect();
|
|
16
|
-
this.observer = new MutationObserver(() => this.sync());
|
|
17
|
-
this.observer.observe(this, { childList: true, subtree: true, characterData: true });
|
|
18
|
-
}
|
|
19
|
-
disconnectedCallback() { this.observer?.disconnect(); }
|
|
20
|
-
attributeChangedCallback() { if (this.isConnected)
|
|
21
|
-
this.sync(); }
|
|
22
|
-
render() {
|
|
23
|
-
const shadow = this.attachShadow({ mode: "open" });
|
|
24
|
-
const button = document.createElement("button");
|
|
25
|
-
button.type = "button";
|
|
26
|
-
button.part.add("control");
|
|
27
|
-
const icon = document.createElement("span");
|
|
28
|
-
icon.className = "icon";
|
|
29
|
-
icon.hidden = true;
|
|
30
|
-
icon.setAttribute("aria-hidden", "true");
|
|
31
|
-
const iconSlot = document.createElement("slot");
|
|
32
|
-
iconSlot.name = "icon";
|
|
33
|
-
icon.append(iconSlot);
|
|
34
|
-
const content = document.createElement("span");
|
|
35
|
-
content.className = "content";
|
|
36
|
-
const title = document.createElement("span");
|
|
37
|
-
title.className = "title";
|
|
38
|
-
const titleSlot = document.createElement("slot");
|
|
39
|
-
titleSlot.addEventListener("slotchange", () => this.sync());
|
|
40
|
-
title.append(titleSlot);
|
|
41
|
-
const description = document.createElement("span");
|
|
42
|
-
description.className = "description";
|
|
43
|
-
description.id = "description";
|
|
44
|
-
description.hidden = true;
|
|
45
|
-
const descriptionSlot = document.createElement("slot");
|
|
46
|
-
descriptionSlot.name = "secondary-content";
|
|
47
|
-
descriptionSlot.addEventListener("slotchange", () => this.sync());
|
|
48
|
-
description.append(descriptionSlot);
|
|
49
|
-
const contentSlot = document.createElement("slot");
|
|
50
|
-
contentSlot.name = "content-container";
|
|
51
|
-
contentSlot.addEventListener("slotchange", () => this.sync());
|
|
52
|
-
contentSlot.append(content);
|
|
53
|
-
iconSlot.addEventListener("slotchange", () => this.sync());
|
|
54
|
-
content.append(title, description);
|
|
55
|
-
button.append(icon, contentSlot);
|
|
56
|
-
const style = document.createElement("style");
|
|
57
|
-
style.textContent = `${buttonControlCss}:host{display:inline-block;max-width:100%;vertical-align:middle}button{justify-content:flex-start;min-height:64px;padding:10px 14px;text-align:start}.icon:empty{display:none}.content,::slotted([slot=content-container]){display:grid;flex:1;min-width:0;gap:3px}.title{font-weight:600}.description{color:var(--spui-ui-muted,var(--spui-semantic-body-subtext,#605e5c));font-size:12px;line-height:1.35}:host([size=small]) button{min-height:52px}:host([size=large]) button{min-height:76px}:host([disabled-focusable]) button:disabled{opacity:1}.description:empty{display:none}@media(forced-colors:active){.description{color:CanvasText}}`;
|
|
58
|
-
button.addEventListener("click", event => { if (this.hasAttribute("disabled") && this.hasAttribute("disabled-focusable")) {
|
|
59
|
-
event.preventDefault();
|
|
60
|
-
event.stopImmediatePropagation();
|
|
61
|
-
event.stopPropagation();
|
|
62
|
-
} });
|
|
63
|
-
shadow.append(style, button);
|
|
64
|
-
this.sync();
|
|
65
|
-
}
|
|
66
|
-
sync() {
|
|
67
|
-
const button = this.shadowRoot?.querySelector("button");
|
|
68
|
-
if (!button)
|
|
69
|
-
return;
|
|
70
|
-
const appearance = this.getAttribute("appearance") ?? "secondary";
|
|
71
|
-
button.className = appearance === "primary" ? "primary" : appearance === "outline" || appearance === "subtle" || appearance === "transparent" ? appearance : "secondary";
|
|
72
|
-
const disabled = this.hasAttribute("disabled");
|
|
73
|
-
const disabledFocusable = disabled && this.hasAttribute("disabled-focusable");
|
|
74
|
-
button.disabled = disabled && !disabledFocusable;
|
|
75
|
-
disabledFocusable ? button.setAttribute("aria-disabled", "true") : button.removeAttribute("aria-disabled");
|
|
76
|
-
for (const name of forward) {
|
|
77
|
-
const value = this.getAttribute(name);
|
|
78
|
-
value === null ? button.removeAttribute(name) : button.setAttribute(name, value);
|
|
79
|
-
}
|
|
80
|
-
const titleSlot = this.shadowRoot?.querySelector(".title slot");
|
|
81
|
-
const customContent = this.querySelector(":scope > [slot=content-container]");
|
|
82
|
-
const markedTitle = customContent?.querySelector("[data-content-title]");
|
|
83
|
-
const titleText = titleSlot?.assignedNodes({ flatten: true }).map(node => node.textContent ?? "").join("").trim() || markedTitle?.textContent?.trim() || customContent?.textContent?.trim() || "";
|
|
84
|
-
if (!this.hasAttribute("aria-label") && !this.hasAttribute("aria-labelledby") && titleText)
|
|
85
|
-
button.setAttribute("aria-label", titleText);
|
|
86
|
-
const descriptionSlot = this.shadowRoot?.querySelector(".description slot");
|
|
87
|
-
const customDescription = customContent?.querySelector("[data-content-description], #description");
|
|
88
|
-
const hasDescription = customDescription ? Boolean(customDescription.textContent?.trim()) : Boolean(descriptionSlot?.assignedNodes({ flatten: true }).some(node => (node.textContent ?? "").trim() || node instanceof Element));
|
|
89
|
-
const description = this.shadowRoot?.querySelector(".description");
|
|
90
|
-
if (description)
|
|
91
|
-
description.hidden = !hasDescription || Boolean(customContent);
|
|
92
|
-
const ariaDescription = [this.getAttribute("aria-description"), customContent ? customDescription?.textContent?.trim() : ""].filter(Boolean).join(" ");
|
|
93
|
-
if (ariaDescription)
|
|
94
|
-
button.setAttribute("aria-description", ariaDescription);
|
|
95
|
-
else
|
|
96
|
-
button.removeAttribute("aria-description");
|
|
97
|
-
const describedBy = [this.getAttribute("aria-describedby"), hasDescription && !customContent ? "description" : ""].filter(Boolean).join(" ");
|
|
98
|
-
if (describedBy)
|
|
99
|
-
button.setAttribute("aria-describedby", describedBy);
|
|
100
|
-
else
|
|
101
|
-
button.removeAttribute("aria-describedby");
|
|
102
|
-
const iconSlot = this.shadowRoot?.querySelector(".icon slot");
|
|
103
|
-
const icon = this.shadowRoot?.querySelector(".icon");
|
|
104
|
-
if (icon)
|
|
105
|
-
icon.hidden = !iconSlot?.assignedNodes({ flatten: true }).length;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
customElements.define("spui-compound-button", SpuiCompoundButton);
|
|
109
|
-
}
|
|
110
|
-
/** A button trigger for Menu. The containing spui-menu owns popup state and focus management. */
|
|
111
|
-
export function defineMenuButton() {
|
|
112
|
-
if (customElements.get("spui-menu-button"))
|
|
113
|
-
return;
|
|
114
|
-
class SpuiMenuButton extends HTMLElement {
|
|
115
|
-
static observedAttributes = ["appearance", "size", "shape", "disabled", "disabled-focusable", "type", "tabindex", "aria-label", "aria-labelledby", "aria-describedby", "aria-haspopup", "aria-controls", "aria-expanded", "title"];
|
|
116
|
-
connectedCallback() { if (!this.shadowRoot)
|
|
117
|
-
this.render();
|
|
118
|
-
else
|
|
119
|
-
this.sync(); }
|
|
120
|
-
disconnectedCallback() { stopHostAccessibleNameSync(this); }
|
|
121
|
-
attributeChangedCallback() { if (this.isConnected)
|
|
122
|
-
this.sync(); }
|
|
123
|
-
render() {
|
|
124
|
-
const shadow = this.attachShadow({ mode: "open", delegatesFocus: true });
|
|
125
|
-
const button = document.createElement("button");
|
|
126
|
-
button.part.add("control");
|
|
127
|
-
const icon = document.createElement("span");
|
|
128
|
-
icon.className = "icon";
|
|
129
|
-
icon.setAttribute("aria-hidden", "true");
|
|
130
|
-
const iconSlot = document.createElement("slot");
|
|
131
|
-
iconSlot.name = "icon";
|
|
132
|
-
icon.append(iconSlot);
|
|
133
|
-
const content = document.createElement("span");
|
|
134
|
-
content.className = "content";
|
|
135
|
-
content.append(document.createElement("slot"));
|
|
136
|
-
const menuIcon = document.createElement("span");
|
|
137
|
-
menuIcon.className = "menu-icon";
|
|
138
|
-
menuIcon.setAttribute("aria-hidden", "true");
|
|
139
|
-
const menuIconSlot = document.createElement("slot");
|
|
140
|
-
menuIconSlot.name = "menu-icon";
|
|
141
|
-
menuIcon.append(menuIconSlot);
|
|
142
|
-
if (!this.querySelector('[slot="menu-icon"]')) {
|
|
143
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
144
|
-
svg.setAttribute("viewBox", "0 0 16 16");
|
|
145
|
-
svg.setAttribute("width", "16");
|
|
146
|
-
svg.setAttribute("height", "16");
|
|
147
|
-
svg.setAttribute("focusable", "false");
|
|
148
|
-
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
149
|
-
path.setAttribute("d", "m4 6 4 4 4-4");
|
|
150
|
-
path.setAttribute("fill", "none");
|
|
151
|
-
path.setAttribute("stroke", "currentColor");
|
|
152
|
-
path.setAttribute("stroke-width", "1.5");
|
|
153
|
-
path.setAttribute("stroke-linecap", "round");
|
|
154
|
-
path.setAttribute("stroke-linejoin", "round");
|
|
155
|
-
svg.append(path);
|
|
156
|
-
menuIconSlot.append(svg);
|
|
157
|
-
}
|
|
158
|
-
iconSlot.addEventListener("slotchange", this.syncSlots);
|
|
159
|
-
menuIconSlot.addEventListener("slotchange", this.syncSlots);
|
|
160
|
-
button.append(icon, content, menuIcon);
|
|
161
|
-
const style = document.createElement("style");
|
|
162
|
-
style.textContent = `${buttonControlCss}:host{display:inline-block;vertical-align:middle;max-width:100%}.menu-icon{display:inline-flex;align-items:center;justify-content:center;flex:none;line-height:0}.menu-icon:empty{display:none}:host([disabled-focusable]) button:disabled{opacity:1}@media(forced-colors:active){.menu-icon{color:ButtonText}}`;
|
|
163
|
-
button.addEventListener("click", event => { if (this.hasAttribute("disabled") && this.hasAttribute("disabled-focusable")) {
|
|
164
|
-
event.preventDefault();
|
|
165
|
-
event.stopImmediatePropagation();
|
|
166
|
-
event.stopPropagation();
|
|
167
|
-
} });
|
|
168
|
-
shadow.append(style, button);
|
|
169
|
-
this.sync();
|
|
170
|
-
this.syncSlots();
|
|
171
|
-
}
|
|
172
|
-
syncSlots = () => {
|
|
173
|
-
for (const [slotName, className] of [["icon", ".icon"], ["menu-icon", ".menu-icon"]]) {
|
|
174
|
-
const slot = this.shadowRoot?.querySelector(`slot[name="${slotName}"]`);
|
|
175
|
-
const host = this.shadowRoot?.querySelector(className);
|
|
176
|
-
if (host && slot)
|
|
177
|
-
host.hidden = slotName === "icon" ? !slot.assignedNodes({ flatten: true }).length : !slot.assignedNodes({ flatten: true }).length && !slot.childNodes.length;
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
sync() {
|
|
181
|
-
const button = this.shadowRoot?.querySelector("button");
|
|
182
|
-
if (!button)
|
|
183
|
-
return;
|
|
184
|
-
const appearance = this.getAttribute("appearance") ?? "secondary";
|
|
185
|
-
button.className = appearance === "primary" ? "primary" : appearance === "outline" || appearance === "subtle" || appearance === "transparent" ? appearance : "secondary";
|
|
186
|
-
button.type = this.getAttribute("type") === "submit" || this.getAttribute("type") === "reset" ? this.getAttribute("type") : "button";
|
|
187
|
-
const disabled = this.hasAttribute("disabled");
|
|
188
|
-
const disabledFocusable = disabled && this.hasAttribute("disabled-focusable");
|
|
189
|
-
button.disabled = disabled && !disabledFocusable;
|
|
190
|
-
disabledFocusable ? button.setAttribute("aria-disabled", "true") : button.removeAttribute("aria-disabled");
|
|
191
|
-
if (this.hasAttribute("tabindex"))
|
|
192
|
-
button.setAttribute("tabindex", this.getAttribute("tabindex"));
|
|
193
|
-
else
|
|
194
|
-
button.removeAttribute("tabindex");
|
|
195
|
-
for (const name of ["aria-label", "aria-describedby", "aria-haspopup", "aria-controls", "aria-expanded", "title"]) {
|
|
196
|
-
const value = this.getAttribute(name);
|
|
197
|
-
value === null ? button.removeAttribute(name) : button.setAttribute(name, value);
|
|
198
|
-
}
|
|
199
|
-
syncHostAccessibleName(this, button);
|
|
200
|
-
if (!this.hasAttribute("aria-label") && !this.hasAttribute("aria-labelledby")) {
|
|
201
|
-
const text = this.textContent?.trim();
|
|
202
|
-
if (text)
|
|
203
|
-
button.setAttribute("aria-label", text);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
customElements.define("spui-menu-button", SpuiMenuButton);
|
|
208
|
-
}
|
|
209
|
-
export function defineToggleButton() {
|
|
210
|
-
if (customElements.get("spui-toggle-button"))
|
|
211
|
-
return;
|
|
212
|
-
class SpuiToggleButton extends HTMLElement {
|
|
213
|
-
static observedAttributes = ["pressed", "checked", "default-pressed", "default-checked", "controlled", "is-accessible", "appearance", "size", "shape", "disabled", "disabled-focusable", "icon-position", "tabindex", "aria-label", "aria-describedby", "title"];
|
|
214
|
-
get pressed() { return this.hasAttribute("checked") || this.hasAttribute("pressed"); }
|
|
215
|
-
set pressed(value) { this.checked = value; }
|
|
216
|
-
get checked() { return this.pressed; }
|
|
217
|
-
set checked(value) { this.toggleAttribute("checked", Boolean(value)); this.toggleAttribute("pressed", Boolean(value)); }
|
|
218
|
-
connectedCallback() {
|
|
219
|
-
if (!this.shadowRoot)
|
|
220
|
-
this.render();
|
|
221
|
-
if (!this.hasAttribute("pressed") && !this.hasAttribute("checked"))
|
|
222
|
-
this.checked = this.hasAttribute("default-checked") || this.hasAttribute("default-pressed");
|
|
223
|
-
this.sync();
|
|
224
|
-
}
|
|
225
|
-
attributeChangedCallback(name, _oldValue, newValue) {
|
|
226
|
-
if (name === "checked" && this.hasAttribute("pressed") !== (newValue !== null))
|
|
227
|
-
this.toggleAttribute("pressed", newValue !== null);
|
|
228
|
-
if (name === "pressed" && this.hasAttribute("checked") !== (newValue !== null))
|
|
229
|
-
this.toggleAttribute("checked", newValue !== null);
|
|
230
|
-
if (this.isConnected)
|
|
231
|
-
this.sync();
|
|
232
|
-
}
|
|
233
|
-
render() {
|
|
234
|
-
const shadow = this.attachShadow({ mode: "open" });
|
|
235
|
-
const button = document.createElement("button");
|
|
236
|
-
button.type = "button";
|
|
237
|
-
button.part.add("control");
|
|
238
|
-
const icon = document.createElement("span");
|
|
239
|
-
icon.className = "icon";
|
|
240
|
-
icon.hidden = true;
|
|
241
|
-
icon.setAttribute("aria-hidden", "true");
|
|
242
|
-
const iconSlot = document.createElement("slot");
|
|
243
|
-
iconSlot.name = "icon";
|
|
244
|
-
iconSlot.addEventListener("slotchange", () => { icon.hidden = !iconSlot.assignedNodes({ flatten: true }).length; });
|
|
245
|
-
icon.append(iconSlot);
|
|
246
|
-
const content = document.createElement("span");
|
|
247
|
-
content.className = "content";
|
|
248
|
-
content.append(document.createElement("slot"));
|
|
249
|
-
button.append(icon, content);
|
|
250
|
-
button.addEventListener("click", event => {
|
|
251
|
-
if (this.hasAttribute("disabled")) {
|
|
252
|
-
event.preventDefault();
|
|
253
|
-
event.stopImmediatePropagation();
|
|
254
|
-
event.stopPropagation();
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
const checked = !this.checked;
|
|
258
|
-
if (!this.hasAttribute("controlled"))
|
|
259
|
-
this.checked = checked;
|
|
260
|
-
this.dispatchEvent(new CustomEvent("spui-checked-change", { bubbles: true, composed: true, detail: { checked, sourceEvent: event, currentTarget: event.currentTarget } }));
|
|
261
|
-
this.dispatchEvent(new CustomEvent("spui-pressed-change", { bubbles: true, composed: true, detail: { pressed: checked } }));
|
|
262
|
-
});
|
|
263
|
-
const style = document.createElement("style");
|
|
264
|
-
style.textContent = `${buttonControlCss}:host{display:inline-block;vertical-align:middle}:host([pressed]) button,:host([checked]) button{border-color:var(--spui-toggle-pressed-border,var(--spui-ui-accent,var(--colorBrandBackground,#0078d4)));background:var(--spui-toggle-pressed-background,color-mix(in srgb,var(--spui-ui-accent,var(--colorBrandBackground,#0078d4)) 12%,var(--spui-ui-surface,var(--colorNeutralBackground1,#fff))))}:host([pressed]) button:hover:not(:disabled),:host([checked]) button:hover:not(:disabled){background:var(--spui-toggle-pressed-hover,color-mix(in srgb,var(--spui-ui-accent,var(--colorBrandBackground,#0078d4)) 18%,var(--spui-ui-surface,var(--colorNeutralBackground1,#fff))))}:host([is-accessible][checked]) button,:host([is-accessible][pressed]) button{border-color:var(--spui-ui-accent,var(--colorBrandBackground,#0078d4));background:var(--spui-ui-accent,var(--colorBrandBackground,#0078d4));color:var(--spui-ui-accent-text,#fff)}:host([is-accessible][checked]) button:hover:not(:disabled),:host([is-accessible][pressed]) button:hover:not(:disabled){background:var(--spui-ui-accent-hover,var(--colorBrandBackgroundHover,#106ebe))}:host([disabled-focusable]) button:disabled{opacity:1}@media(forced-colors:active){:host([pressed]) button,:host([checked]) button{outline:1px solid Highlight}}`;
|
|
265
|
-
shadow.append(style, button);
|
|
266
|
-
this.sync();
|
|
267
|
-
}
|
|
268
|
-
sync() {
|
|
269
|
-
const button = this.shadowRoot?.querySelector("button");
|
|
270
|
-
if (!button)
|
|
271
|
-
return;
|
|
272
|
-
const appearance = this.getAttribute("appearance") ?? "secondary";
|
|
273
|
-
button.className = appearance === "primary" ? "primary" : appearance === "outline" || appearance === "subtle" || appearance === "transparent" ? appearance : "secondary";
|
|
274
|
-
const disabled = this.hasAttribute("disabled");
|
|
275
|
-
const disabledFocusable = disabled && this.hasAttribute("disabled-focusable");
|
|
276
|
-
button.disabled = disabled && !disabledFocusable;
|
|
277
|
-
if (disabledFocusable)
|
|
278
|
-
button.setAttribute("aria-disabled", "true");
|
|
279
|
-
else
|
|
280
|
-
button.removeAttribute("aria-disabled");
|
|
281
|
-
if (this.hasAttribute("tabindex"))
|
|
282
|
-
button.setAttribute("tabindex", this.getAttribute("tabindex"));
|
|
283
|
-
else
|
|
284
|
-
button.removeAttribute("tabindex");
|
|
285
|
-
button.setAttribute("aria-pressed", String(this.checked));
|
|
286
|
-
for (const name of ["aria-label", "aria-describedby", "title"]) {
|
|
287
|
-
const value = this.getAttribute(name);
|
|
288
|
-
value === null ? button.removeAttribute(name) : button.setAttribute(name, value);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
customElements.define("spui-toggle-button", SpuiToggleButton);
|
|
293
|
-
}
|
|
294
|
-
export function defineSplitButton() {
|
|
295
|
-
if (customElements.get("spui-split-button"))
|
|
296
|
-
return;
|
|
297
|
-
class SpuiSplitButton extends HTMLElement {
|
|
298
|
-
static observedAttributes = ["aria-label"];
|
|
299
|
-
primarySegment;
|
|
300
|
-
triggerSegment;
|
|
301
|
-
connectedCallback() {
|
|
302
|
-
if (!this.shadowRoot) {
|
|
303
|
-
const shadow = this.attachShadow({ mode: "open" });
|
|
304
|
-
const style = document.createElement("style");
|
|
305
|
-
style.textContent = `${base}:host{display:inline-flex;align-items:center;gap:0;max-width:100%;vertical-align:middle}::slotted([slot=primary]){position:relative;z-index:1;margin-inline-end:-1px}::slotted([slot=menu]){display:contents}@media(forced-colors:active){:host{outline-color:Highlight}}`;
|
|
306
|
-
const primary = document.createElement("slot");
|
|
307
|
-
primary.name = "primary";
|
|
308
|
-
const menu = document.createElement("slot");
|
|
309
|
-
menu.name = "menu";
|
|
310
|
-
shadow.append(style, primary, menu);
|
|
311
|
-
primary.addEventListener("slotchange", this.syncSegments);
|
|
312
|
-
menu.addEventListener("slotchange", this.syncSegments);
|
|
313
|
-
}
|
|
314
|
-
this.syncSegments();
|
|
315
|
-
if (!this.hasAttribute("role"))
|
|
316
|
-
this.setAttribute("role", "group");
|
|
317
|
-
if (!this.hasAttribute("aria-label"))
|
|
318
|
-
this.setAttribute("aria-label", "Actions");
|
|
319
|
-
}
|
|
320
|
-
disconnectedCallback() { this.primarySegment?.removeAttribute("data-spui-split-primary"); this.triggerSegment?.removeAttribute("data-spui-split-trigger"); }
|
|
321
|
-
syncSegments = () => {
|
|
322
|
-
const slots = this.shadowRoot?.querySelectorAll("slot");
|
|
323
|
-
if (!slots)
|
|
324
|
-
return;
|
|
325
|
-
const primary = slots[0]?.assignedElements().find(element => element instanceof HTMLElement);
|
|
326
|
-
const menu = slots[1]?.assignedElements().find(element => element instanceof HTMLElement);
|
|
327
|
-
const trigger = menu?.querySelector("[slot=trigger]") ?? undefined;
|
|
328
|
-
if (this.primarySegment !== primary)
|
|
329
|
-
this.primarySegment?.removeAttribute("data-spui-split-primary");
|
|
330
|
-
if (this.triggerSegment !== trigger)
|
|
331
|
-
this.triggerSegment?.removeAttribute("data-spui-split-trigger");
|
|
332
|
-
this.primarySegment = primary;
|
|
333
|
-
this.triggerSegment = trigger;
|
|
334
|
-
this.primarySegment?.setAttribute("data-spui-split-primary", "");
|
|
335
|
-
this.triggerSegment?.setAttribute("data-spui-split-trigger", "");
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
customElements.define("spui-split-button", SpuiSplitButton);
|
|
339
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type ButtonAppearance = "primary" | "secondary" | "outline" | "subtle" | "transparent";
|
|
2
|
-
export type ButtonSize = "small" | "medium" | "large";
|
|
3
|
-
export type ButtonShape = "rounded" | "circular" | "square";
|
|
4
|
-
export declare const buttonControlCss: string;
|
|
5
|
-
export declare function defineButton(): void;
|