@stainless-api/ui-primitives 0.1.0-beta.22 → 0.1.0-beta.24
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/dist/{Accordion-DLQE3Td6.js → Accordion-CL3Oarbz.js} +3 -3
- package/dist/{Accordion-CJL9SWwS.d.ts → Accordion-Cj5GURin.d.ts} +4 -4
- package/dist/{Button-DwndlytB.d.ts → Button-CxQtPObH.d.ts} +4 -4
- package/dist/{Button-DBhd6kU7.js → Button-DFAg4M-E.js} +3 -3
- package/dist/{Callout-UZQRuCQ5.js → Callout-BGkXD7D2.js} +1 -1
- package/dist/{Callout-CMz3Yl_5.d.ts → Callout-DlwbfFHm.d.ts} +2 -2
- package/dist/components/Accordion.d.ts +1 -1
- package/dist/components/Accordion.js +1 -1
- package/dist/components/Button.d.ts +1 -1
- package/dist/components/Button.js +1 -1
- package/dist/components/Callout.d.ts +1 -1
- package/dist/components/Callout.js +1 -1
- package/dist/index.d.ts +170 -5
- package/dist/index.js +175 -5
- package/dist/scripts/index.d.ts +12 -1
- package/dist/scripts/index.js +150 -22
- package/dist/styles.css +221 -99
- package/dist/styles.js +0 -1
- package/package.json +21 -12
- package/.turbo/turbo-build.log +0 -35
- package/CHANGELOG.md +0 -139
- package/dist/DropdownButton-DoYDi8tB.js +0 -82
- package/dist/DropdownButton-zcvep_xH.d.ts +0 -50
- package/dist/components/DropdownButton.d.ts +0 -2
- package/dist/components/DropdownButton.js +0 -3
- package/eslint.config.js +0 -2
- package/src/components/Accordion.tsx +0 -41
- package/src/components/Button.tsx +0 -95
- package/src/components/Callout.tsx +0 -31
- package/src/components/accordion.css +0 -145
- package/src/components/button.css +0 -187
- package/src/components/callout.css +0 -93
- package/src/components/dropdown/Dropdown.tsx +0 -51
- package/src/components/dropdown/DropdownButton.tsx +0 -54
- package/src/components/dropdown/DropdownMenu.tsx +0 -113
- package/src/components/dropdown/dropdown.css +0 -232
- package/src/index.ts +0 -5
- package/src/scripts/dropdown-button.ts +0 -39
- package/src/scripts/dropdown.ts +0 -193
- package/src/scripts/index.ts +0 -2
- package/src/styles/layout.css +0 -13
- package/src/styles/scales.css +0 -129
- package/src/styles/starlight-compat.css +0 -162
- package/src/styles/swatches.css +0 -87
- package/src/styles/theme.css +0 -49
- package/src/styles/typography.css +0 -169
- package/src/styles.css +0 -11
- package/tsconfig.json +0 -11
package/dist/scripts/index.js
CHANGED
|
@@ -1,33 +1,161 @@
|
|
|
1
|
+
//#region src/scripts/dropdown.ts
|
|
2
|
+
function initDropdown({ root, onSelect, initialValue }) {
|
|
3
|
+
if (!root) {
|
|
4
|
+
console.error("Dropdown root element not found");
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const trigger = root.querySelector("[data-part=\"trigger\"]");
|
|
8
|
+
const menu = root.querySelector("[data-part=\"menu\"]");
|
|
9
|
+
if (!trigger) {
|
|
10
|
+
console.error("Dropdown trigger not found");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!menu) {
|
|
14
|
+
console.error("Dropdown menu not found");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const selectedSlot = trigger.querySelector("[data-part=\"trigger-selected\"]");
|
|
18
|
+
const items = Array.from(menu.querySelectorAll("[data-part=\"item\"]"));
|
|
19
|
+
function open() {
|
|
20
|
+
if (!trigger || !menu || !root) return;
|
|
21
|
+
root.setAttribute("aria-expanded", "true");
|
|
22
|
+
menu.dataset.state = "open";
|
|
23
|
+
menu.removeAttribute("aria-hidden");
|
|
24
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
25
|
+
const menuHeight = menu.offsetHeight;
|
|
26
|
+
const spaceBelow = window.innerHeight - triggerRect.bottom;
|
|
27
|
+
const spaceAbove = triggerRect.top;
|
|
28
|
+
menu.classList.remove("stl-ui-dropdown-menu--above", "stl-ui-dropdown-menu--below");
|
|
29
|
+
if (spaceBelow < menuHeight && spaceAbove > spaceBelow) menu.classList.add("stl-ui-dropdown-menu--above");
|
|
30
|
+
else menu.classList.add("stl-ui-dropdown-menu--below");
|
|
31
|
+
}
|
|
32
|
+
function close() {
|
|
33
|
+
if (!trigger || !menu || !root) return;
|
|
34
|
+
root.setAttribute("aria-expanded", "false");
|
|
35
|
+
menu.dataset.state = "closed";
|
|
36
|
+
menu.setAttribute("aria-hidden", "true");
|
|
37
|
+
}
|
|
38
|
+
function renderSelectedFromItem(item) {
|
|
39
|
+
if (!selectedSlot) return;
|
|
40
|
+
const tmpl = item.querySelector("template[data-part=\"selected-template\"]");
|
|
41
|
+
if (!tmpl) {
|
|
42
|
+
console.error("Dropdown item template not found");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
selectedSlot.innerHTML = "";
|
|
46
|
+
selectedSlot.appendChild(tmpl.content.cloneNode(true));
|
|
47
|
+
selectedSlot.removeAttribute("data-placeholder");
|
|
48
|
+
}
|
|
49
|
+
function selectItem(item) {
|
|
50
|
+
if (!trigger) {
|
|
51
|
+
console.error("Dropdown trigger not found");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
items.forEach((i) => i.setAttribute("aria-selected", String(i === item)));
|
|
55
|
+
trigger.dataset.value = item.getAttribute("data-value") || "";
|
|
56
|
+
renderSelectedFromItem(item);
|
|
57
|
+
}
|
|
58
|
+
function handleItemSelection(e) {
|
|
59
|
+
const item = e.target.closest("[data-part=\"item\"]");
|
|
60
|
+
if (!item) {
|
|
61
|
+
console.error("Dropdown item not found");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!trigger) {
|
|
65
|
+
console.error("Dropdown trigger not found");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
selectItem(item);
|
|
69
|
+
onSelect?.(item.getAttribute("data-value") || "");
|
|
70
|
+
close();
|
|
71
|
+
trigger.focus();
|
|
72
|
+
}
|
|
73
|
+
function handleTriggerClick() {
|
|
74
|
+
if (!root) return false;
|
|
75
|
+
if (root.getAttribute("aria-expanded") === "true") {
|
|
76
|
+
close();
|
|
77
|
+
return false;
|
|
78
|
+
} else {
|
|
79
|
+
open();
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const initial = (initialValue ? items.find((i) => i.getAttribute("data-value") === initialValue) : items.find((i) => i.getAttribute("aria-selected") === "true")) ?? items[0];
|
|
84
|
+
if (initial) selectItem(initial);
|
|
85
|
+
trigger.addEventListener("click", () => {
|
|
86
|
+
handleTriggerClick();
|
|
87
|
+
});
|
|
88
|
+
trigger.addEventListener("keydown", (e) => {
|
|
89
|
+
if (e.key !== "Enter" && e.key !== " ") return;
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
if (handleTriggerClick()) items[0]?.focus();
|
|
92
|
+
});
|
|
93
|
+
menu.addEventListener("click", (e) => {
|
|
94
|
+
handleItemSelection(e);
|
|
95
|
+
});
|
|
96
|
+
document.addEventListener("keydown", (e) => {
|
|
97
|
+
if (!(root.getAttribute("aria-expanded") === "true")) return;
|
|
98
|
+
if (e.key === "Escape") {
|
|
99
|
+
close();
|
|
100
|
+
trigger.focus();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (e.key === "ArrowDown") {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
const activeElement = document.activeElement;
|
|
106
|
+
if (activeElement === trigger) {
|
|
107
|
+
items[0]?.focus();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
let nextSibling = activeElement?.nextElementSibling;
|
|
111
|
+
while (nextSibling && nextSibling.tagName.toLowerCase() === "hr") nextSibling = nextSibling.nextElementSibling;
|
|
112
|
+
if (nextSibling instanceof HTMLElement && items.includes(nextSibling)) nextSibling.focus();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (e.key === "ArrowUp") {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
const activeElement = document.activeElement;
|
|
118
|
+
if (activeElement === trigger) {
|
|
119
|
+
items[items.length - 1]?.focus();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
let prevSibling = activeElement?.previousElementSibling;
|
|
123
|
+
while (prevSibling && prevSibling.tagName.toLowerCase() === "hr") prevSibling = prevSibling.previousElementSibling;
|
|
124
|
+
if (prevSibling instanceof HTMLElement && items.includes(prevSibling)) prevSibling.focus();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
document.addEventListener("click", (e) => {
|
|
129
|
+
if (!root.contains(e.target)) close();
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
1
134
|
//#region src/scripts/dropdown-button.ts
|
|
2
135
|
function initDropdownButton({ dropdown, onSelect, onPrimaryAction }) {
|
|
3
136
|
const trigger = dropdown.querySelector("[data-part=\"trigger\"]");
|
|
4
137
|
const menu = dropdown.querySelector("[data-part=\"menu\"]");
|
|
5
138
|
const primaryAction = dropdown.querySelector("[data-part=\"primary-action\"]");
|
|
6
|
-
if (!trigger
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (primaryAction && primaryAction.contains(event.target)) toggleDropdown();
|
|
19
|
-
});
|
|
20
|
-
dropdown.querySelectorAll("[data-part=\"item\"]").forEach((item) => {
|
|
21
|
-
item.addEventListener("click", () => {
|
|
22
|
-
const value = item.getAttribute("data-value");
|
|
23
|
-
if (value) onSelect(value);
|
|
24
|
-
toggleDropdown();
|
|
25
|
-
});
|
|
26
|
-
});
|
|
139
|
+
if (!trigger) {
|
|
140
|
+
console.error("Dropdown trigger not found");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (!menu) {
|
|
144
|
+
console.error("Dropdown menu not found");
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (!primaryAction) {
|
|
148
|
+
console.error("Dropdown primary action not found");
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
27
151
|
primaryAction.addEventListener("click", () => {
|
|
28
152
|
onPrimaryAction(primaryAction);
|
|
29
153
|
});
|
|
154
|
+
initDropdown({
|
|
155
|
+
root: dropdown,
|
|
156
|
+
onSelect
|
|
157
|
+
});
|
|
30
158
|
}
|
|
31
159
|
|
|
32
160
|
//#endregion
|
|
33
|
-
export { initDropdownButton };
|
|
161
|
+
export { initDropdown, initDropdownButton };
|