@lmfaole/basics 0.3.0 → 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.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +78 -350
  3. package/basic-components/basic-accordion/README.md +53 -0
  4. package/{components → basic-components}/basic-accordion/index.d.ts +5 -5
  5. package/basic-components/basic-accordion/index.js +413 -0
  6. package/basic-components/basic-alert/README.md +48 -0
  7. package/basic-components/basic-alert/index.d.ts +53 -0
  8. package/basic-components/basic-alert/index.js +189 -0
  9. package/basic-components/basic-alert/register.js +3 -0
  10. package/basic-components/basic-carousel/README.md +108 -0
  11. package/basic-components/basic-carousel/index.d.ts +73 -0
  12. package/basic-components/basic-carousel/index.js +255 -0
  13. package/basic-components/basic-carousel/register.js +3 -0
  14. package/basic-components/basic-dialog/README.md +57 -0
  15. package/basic-components/basic-popover/README.md +56 -0
  16. package/basic-components/basic-summary-table/README.md +93 -0
  17. package/{components → basic-components}/basic-summary-table/index.js +188 -42
  18. package/basic-components/basic-table/README.md +89 -0
  19. package/{components → basic-components}/basic-table/index.js +203 -145
  20. package/basic-components/basic-tabs/README.md +63 -0
  21. package/basic-components/basic-tabs/register.d.ts +1 -0
  22. package/basic-components/basic-toast/README.md +62 -0
  23. package/basic-components/basic-toast/index.d.ts +68 -0
  24. package/basic-components/basic-toast/index.js +690 -0
  25. package/basic-components/basic-toast/register.d.ts +1 -0
  26. package/basic-components/basic-toast/register.js +3 -0
  27. package/basic-components/basic-toc/README.md +43 -0
  28. package/basic-components/basic-toc/register.d.ts +1 -0
  29. package/basic-styling/components/basic-accordion.css +99 -0
  30. package/basic-styling/components/basic-alert.css +27 -0
  31. package/basic-styling/components/basic-carousel.css +183 -0
  32. package/basic-styling/components/basic-dialog.css +41 -0
  33. package/basic-styling/components/basic-popover.css +52 -0
  34. package/basic-styling/components/basic-summary-table.css +98 -0
  35. package/basic-styling/components/basic-table.css +66 -0
  36. package/basic-styling/components/basic-tabs.css +61 -0
  37. package/basic-styling/components/basic-toast.css +102 -0
  38. package/basic-styling/components/basic-toc.css +30 -0
  39. package/basic-styling/components.css +11 -0
  40. package/basic-styling/forms.css +55 -0
  41. package/basic-styling/global.css +62 -0
  42. package/basic-styling/index.css +2 -0
  43. package/basic-styling/interaction.css +90 -0
  44. package/basic-styling/tokens/base.css +19 -0
  45. package/basic-styling/tokens/palette.css +229 -0
  46. package/basic-styling/tokens/palette.tokens.json +1787 -0
  47. package/index.d.ts +10 -7
  48. package/index.js +10 -7
  49. package/package.json +61 -76
  50. package/components/basic-accordion/index.js +0 -387
  51. package/readme.mdx +0 -6
  52. /package/{components → basic-components}/basic-accordion/register.d.ts +0 -0
  53. /package/{components → basic-components}/basic-accordion/register.js +0 -0
  54. /package/{components/basic-dialog → basic-components/basic-alert}/register.d.ts +0 -0
  55. /package/{components/basic-popover → basic-components/basic-carousel}/register.d.ts +0 -0
  56. /package/{components → basic-components}/basic-dialog/index.d.ts +0 -0
  57. /package/{components → basic-components}/basic-dialog/index.js +0 -0
  58. /package/{components/basic-summary-table → basic-components/basic-dialog}/register.d.ts +0 -0
  59. /package/{components → basic-components}/basic-dialog/register.js +0 -0
  60. /package/{components → basic-components}/basic-popover/index.d.ts +0 -0
  61. /package/{components → basic-components}/basic-popover/index.js +0 -0
  62. /package/{components/basic-table → basic-components/basic-popover}/register.d.ts +0 -0
  63. /package/{components → basic-components}/basic-popover/register.js +0 -0
  64. /package/{components → basic-components}/basic-summary-table/index.d.ts +0 -0
  65. /package/{components/basic-tabs → basic-components/basic-summary-table}/register.d.ts +0 -0
  66. /package/{components → basic-components}/basic-summary-table/register.js +0 -0
  67. /package/{components → basic-components}/basic-table/index.d.ts +0 -0
  68. /package/{components/basic-toc → basic-components/basic-table}/register.d.ts +0 -0
  69. /package/{components → basic-components}/basic-table/register.js +0 -0
  70. /package/{components → basic-components}/basic-tabs/index.d.ts +0 -0
  71. /package/{components → basic-components}/basic-tabs/index.js +0 -0
  72. /package/{components → basic-components}/basic-tabs/register.js +0 -0
  73. /package/{components → basic-components}/basic-toc/index.d.ts +0 -0
  74. /package/{components → basic-components}/basic-toc/index.js +0 -0
  75. /package/{components → basic-components}/basic-toc/register.js +0 -0
package/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- export * from "./components/basic-accordion";
2
- export * from "./components/basic-dialog";
3
- export * from "./components/basic-popover";
4
- export * from "./components/basic-summary-table";
5
- export * from "./components/basic-table";
6
- export * from "./components/basic-toc";
7
- export * from "./components/basic-tabs";
1
+ export * from "./basic-components/basic-alert";
2
+ export * from "./basic-components/basic-accordion";
3
+ export * from "./basic-components/basic-carousel";
4
+ export * from "./basic-components/basic-dialog";
5
+ export * from "./basic-components/basic-popover";
6
+ export * from "./basic-components/basic-summary-table";
7
+ export * from "./basic-components/basic-table";
8
+ export * from "./basic-components/basic-toc";
9
+ export * from "./basic-components/basic-tabs";
10
+ export * from "./basic-components/basic-toast";
package/index.js CHANGED
@@ -1,7 +1,10 @@
1
- export * from "./components/basic-accordion/index.js";
2
- export * from "./components/basic-dialog/index.js";
3
- export * from "./components/basic-popover/index.js";
4
- export * from "./components/basic-summary-table/index.js";
5
- export * from "./components/basic-table/index.js";
6
- export * from "./components/basic-toc/index.js";
7
- export * from "./components/basic-tabs/index.js";
1
+ export * from "./basic-components/basic-alert/index.js";
2
+ export * from "./basic-components/basic-accordion/index.js";
3
+ export * from "./basic-components/basic-carousel/index.js";
4
+ export * from "./basic-components/basic-dialog/index.js";
5
+ export * from "./basic-components/basic-popover/index.js";
6
+ export * from "./basic-components/basic-summary-table/index.js";
7
+ export * from "./basic-components/basic-table/index.js";
8
+ export * from "./basic-components/basic-toc/index.js";
9
+ export * from "./basic-components/basic-tabs/index.js";
10
+ export * from "./basic-components/basic-toast/index.js";
package/package.json CHANGED
@@ -1,92 +1,70 @@
1
1
  {
2
2
  "name": "@lmfaole/basics",
3
- "version": "0.3.0",
4
- "description": "Simple unstyled custom elements and DOM helpers.",
3
+ "version": "0.5.0",
4
+ "description": "Simple custom elements and DOM helpers with optional starter styles.",
5
5
  "type": "module",
6
6
  "sideEffects": [
7
- "./components/basic-accordion/register.js",
8
- "./components/basic-dialog/register.js",
9
- "./components/basic-popover/register.js",
10
- "./components/basic-summary-table/register.js",
11
- "./components/basic-table/register.js",
12
- "./components/basic-toc/register.js",
13
- "./components/basic-tabs/register.js"
7
+ "./basic-styling/**/*.css",
8
+ "./basic-components/basic-alert/register.js",
9
+ "./basic-components/basic-accordion/register.js",
10
+ "./basic-components/basic-carousel/register.js",
11
+ "./basic-components/basic-dialog/register.js",
12
+ "./basic-components/basic-popover/register.js",
13
+ "./basic-components/basic-summary-table/register.js",
14
+ "./basic-components/basic-table/register.js",
15
+ "./basic-components/basic-toc/register.js",
16
+ "./basic-components/basic-tabs/register.js",
17
+ "./basic-components/basic-toast/register.js"
14
18
  ],
15
19
  "exports": {
16
20
  ".": {
17
21
  "types": "./index.d.ts",
18
22
  "import": "./index.js"
19
23
  },
20
- "./components/basic-accordion": {
21
- "types": "./components/basic-accordion/index.d.ts",
22
- "import": "./components/basic-accordion/index.js"
24
+ "./basic-styling": "./basic-styling/index.css",
25
+ "./basic-styling/*.css": "./basic-styling/*.css",
26
+ "./basic-styling/components/*.css": "./basic-styling/components/*.css",
27
+ "./basic-styling/tokens/*.css": "./basic-styling/tokens/*.css",
28
+ "./basic-styling/tokens/*.json": "./basic-styling/tokens/*.json",
29
+ "./basic-components/*/register": {
30
+ "types": "./basic-components/*/register.d.ts",
31
+ "import": "./basic-components/*/register.js"
23
32
  },
24
- "./components/basic-accordion/register": {
25
- "types": "./components/basic-accordion/register.d.ts",
26
- "import": "./components/basic-accordion/register.js"
33
+ "./basic-components/*": {
34
+ "types": "./basic-components/*/index.d.ts",
35
+ "import": "./basic-components/*/index.js"
27
36
  },
28
- "./components/basic-dialog": {
29
- "types": "./components/basic-dialog/index.d.ts",
30
- "import": "./components/basic-dialog/index.js"
37
+ "./components/*/register": {
38
+ "types": "./basic-components/*/register.d.ts",
39
+ "import": "./basic-components/*/register.js"
31
40
  },
32
- "./components/basic-dialog/register": {
33
- "types": "./components/basic-dialog/register.d.ts",
34
- "import": "./components/basic-dialog/register.js"
35
- },
36
- "./components/basic-popover": {
37
- "types": "./components/basic-popover/index.d.ts",
38
- "import": "./components/basic-popover/index.js"
39
- },
40
- "./components/basic-popover/register": {
41
- "types": "./components/basic-popover/register.d.ts",
42
- "import": "./components/basic-popover/register.js"
43
- },
44
- "./components/basic-summary-table": {
45
- "types": "./components/basic-summary-table/index.d.ts",
46
- "import": "./components/basic-summary-table/index.js"
47
- },
48
- "./components/basic-summary-table/register": {
49
- "types": "./components/basic-summary-table/register.d.ts",
50
- "import": "./components/basic-summary-table/register.js"
51
- },
52
- "./components/basic-table": {
53
- "types": "./components/basic-table/index.d.ts",
54
- "import": "./components/basic-table/index.js"
55
- },
56
- "./components/basic-table/register": {
57
- "types": "./components/basic-table/register.d.ts",
58
- "import": "./components/basic-table/register.js"
59
- },
60
- "./components/basic-toc": {
61
- "types": "./components/basic-toc/index.d.ts",
62
- "import": "./components/basic-toc/index.js"
63
- },
64
- "./components/basic-toc/register": {
65
- "types": "./components/basic-toc/register.d.ts",
66
- "import": "./components/basic-toc/register.js"
67
- },
68
- "./components/basic-tabs": {
69
- "types": "./components/basic-tabs/index.d.ts",
70
- "import": "./components/basic-tabs/index.js"
71
- },
72
- "./components/basic-tabs/register": {
73
- "types": "./components/basic-tabs/register.d.ts",
74
- "import": "./components/basic-tabs/register.js"
41
+ "./components/*": {
42
+ "types": "./basic-components/*/index.d.ts",
43
+ "import": "./basic-components/*/index.js"
75
44
  }
76
45
  },
77
46
  "files": [
47
+ "LICENSE",
78
48
  "README.md",
79
49
  "index.js",
80
50
  "index.d.ts",
81
- "components/*/index.js",
82
- "components/*/index.d.ts",
83
- "components/*/register.js",
84
- "components/*/register.d.ts"
51
+ "basic-styling/**/*.css",
52
+ "basic-styling/**/*.json",
53
+ "basic-components/*/index.js",
54
+ "basic-components/*/index.d.ts",
55
+ "basic-components/*/README.md",
56
+ "basic-components/*/register.js",
57
+ "basic-components/*/register.d.ts"
85
58
  ],
86
59
  "keywords": [
60
+ "alert",
87
61
  "accordion",
62
+ "carousel",
88
63
  "custom-element",
89
64
  "dialog",
65
+ "toast",
66
+ "notification",
67
+ "basic-carousel",
90
68
  "basic-summary-table",
91
69
  "basic-tabs",
92
70
  "basic-table",
@@ -94,6 +72,7 @@
94
72
  "modal",
95
73
  "popover",
96
74
  "overlay",
75
+ "slider",
97
76
  "table-of-contents",
98
77
  "summary-table",
99
78
  "tabs",
@@ -104,7 +83,10 @@
104
83
  "vanilla-js",
105
84
  "web-components"
106
85
  ],
107
- "license": "ISC",
86
+ "license": "MIT",
87
+ "engines": {
88
+ "node": ">=24.0.0"
89
+ },
108
90
  "repository": {
109
91
  "type": "git",
110
92
  "url": "git+https://github.com/lmfaole/basics.git"
@@ -114,17 +96,17 @@
114
96
  },
115
97
  "homepage": "https://github.com/lmfaole/basics",
116
98
  "devDependencies": {
117
- "@changesets/cli": "2.29.7",
118
- "@chromatic-com/storybook": "^5.0.2",
119
- "@storybook/addon-a11y": "^10.3.1",
120
- "@storybook/addon-docs": "10.3.1",
121
- "@storybook/addon-vitest": "10.3.1",
122
- "@storybook/web-components-vite": "^10.3.1",
123
- "@vitest/browser-playwright": "4.1.0",
124
- "@vitest/coverage-v8": "4.1.0",
99
+ "@changesets/cli": "2.30.0",
100
+ "@chromatic-com/storybook": "^5.1.1",
101
+ "@storybook/addon-a11y": "^10.3.3",
102
+ "@storybook/addon-docs": "10.3.3",
103
+ "@storybook/addon-vitest": "10.3.3",
104
+ "@storybook/web-components-vite": "^10.3.3",
105
+ "@vitest/browser-playwright": "4.1.2",
106
+ "@vitest/coverage-v8": "4.1.2",
125
107
  "playwright": "^1.58.2",
126
- "storybook": "^10.3.1",
127
- "vitest": "^4.1.0"
108
+ "storybook": "^10.3.3",
109
+ "vitest": "^4.1.2"
128
110
  },
129
111
  "publishConfig": {
130
112
  "access": "public",
@@ -132,6 +114,9 @@
132
114
  },
133
115
  "scripts": {
134
116
  "changeset": "changeset",
117
+ "check:breaking-change-codemods": "node scripts/check-breaking-change-codemods.mjs",
118
+ "check:generated-files": "node scripts/generate-palette-tokens.mjs --check",
119
+ "check:package": "node scripts/check-package-exports.mjs",
135
120
  "version-packages": "changeset version",
136
121
  "release": "pnpm test && changeset publish",
137
122
  "storybook": "storybook dev -p 6006 --no-open",
@@ -1,387 +0,0 @@
1
- const ElementBase = globalThis.Element ?? class {};
2
- const HTMLElementBase = globalThis.HTMLElement ?? class {};
3
- const HTMLButtonElementBase = globalThis.HTMLButtonElement ?? class {};
4
-
5
- export const ACCORDION_TAG_NAME = "basic-accordion";
6
-
7
- const TRIGGER_SELECTOR = "[data-accordion-trigger]";
8
- const PANEL_SELECTOR = "[data-accordion-panel]";
9
-
10
- let nextAccordionInstanceId = 1;
11
-
12
- function collectOwnedElements(root, scope, selector) {
13
- return Array.from(scope.querySelectorAll(selector)).filter(
14
- (element) => element instanceof HTMLElementBase && element.closest(ACCORDION_TAG_NAME) === root,
15
- );
16
- }
17
-
18
- function isAccordionItemDisabled(trigger) {
19
- return trigger.hasAttribute("disabled") || trigger.getAttribute("aria-disabled") === "true";
20
- }
21
-
22
- function findFirstEnabledAccordionIndex(itemStates) {
23
- for (let index = 0; index < itemStates.length; index += 1) {
24
- if (!itemStates[index]?.disabled) {
25
- return index;
26
- }
27
- }
28
-
29
- return -1;
30
- }
31
-
32
- function findLastEnabledAccordionIndex(itemStates) {
33
- for (let index = itemStates.length - 1; index >= 0; index -= 1) {
34
- if (!itemStates[index]?.disabled) {
35
- return index;
36
- }
37
- }
38
-
39
- return -1;
40
- }
41
-
42
- export function getInitialOpenAccordionIndexes(
43
- itemStates,
44
- { multiple = false, collapsible = false } = {},
45
- ) {
46
- const explicitOpenIndexes = [];
47
-
48
- for (let index = 0; index < itemStates.length; index += 1) {
49
- const itemState = itemStates[index];
50
-
51
- if (itemState?.open && !itemState.disabled) {
52
- explicitOpenIndexes.push(index);
53
- }
54
- }
55
-
56
- if (multiple) {
57
- return explicitOpenIndexes;
58
- }
59
-
60
- if (explicitOpenIndexes.length > 0) {
61
- return [explicitOpenIndexes[0]];
62
- }
63
-
64
- if (collapsible) {
65
- return [];
66
- }
67
-
68
- const firstEnabledIndex = findFirstEnabledAccordionIndex(itemStates);
69
- return firstEnabledIndex === -1 ? [] : [firstEnabledIndex];
70
- }
71
-
72
- export function findNextEnabledAccordionIndex(itemStates, startIndex, direction) {
73
- if (itemStates.length === 0) {
74
- return -1;
75
- }
76
-
77
- const step = direction < 0 ? -1 : 1;
78
- let nextIndex = startIndex;
79
-
80
- for (let checked = 0; checked < itemStates.length; checked += 1) {
81
- nextIndex += step;
82
-
83
- if (nextIndex < 0) {
84
- nextIndex = itemStates.length - 1;
85
- } else if (nextIndex >= itemStates.length) {
86
- nextIndex = 0;
87
- }
88
-
89
- if (!itemStates[nextIndex]?.disabled) {
90
- return nextIndex;
91
- }
92
- }
93
-
94
- return -1;
95
- }
96
-
97
- export class AccordionElement extends HTMLElementBase {
98
- static observedAttributes = ["data-collapsible", "data-multiple"];
99
-
100
- #instanceId = `${ACCORDION_TAG_NAME}-${nextAccordionInstanceId++}`;
101
- #triggers = [];
102
- #panels = [];
103
- #openIndexes = new Set();
104
- #focusIndex = -1;
105
- #eventsBound = false;
106
-
107
- connectedCallback() {
108
- if (!this.#eventsBound) {
109
- this.addEventListener("click", this.#handleClick);
110
- this.addEventListener("keydown", this.#handleKeyDown);
111
- this.#eventsBound = true;
112
- }
113
-
114
- this.#sync({ resetOpen: true });
115
- }
116
-
117
- disconnectedCallback() {
118
- if (!this.#eventsBound) {
119
- return;
120
- }
121
-
122
- this.removeEventListener("click", this.#handleClick);
123
- this.removeEventListener("keydown", this.#handleKeyDown);
124
- this.#eventsBound = false;
125
- }
126
-
127
- attributeChangedCallback() {
128
- this.#sync({ resetOpen: true });
129
- }
130
-
131
- #handleClick = (event) => {
132
- if (!(event.target instanceof ElementBase)) {
133
- return;
134
- }
135
-
136
- const trigger = event.target.closest(TRIGGER_SELECTOR);
137
-
138
- if (
139
- !(trigger instanceof HTMLElementBase)
140
- || trigger.closest(ACCORDION_TAG_NAME) !== this
141
- ) {
142
- return;
143
- }
144
-
145
- const triggerIndex = this.#triggers.indexOf(trigger);
146
-
147
- if (triggerIndex === -1) {
148
- return;
149
- }
150
-
151
- this.#toggleIndex(triggerIndex, { focus: true });
152
- };
153
-
154
- #handleKeyDown = (event) => {
155
- if (!(event.target instanceof ElementBase)) {
156
- return;
157
- }
158
-
159
- const currentTrigger = event.target.closest(TRIGGER_SELECTOR);
160
-
161
- if (
162
- !(currentTrigger instanceof HTMLElementBase)
163
- || currentTrigger.closest(ACCORDION_TAG_NAME) !== this
164
- ) {
165
- return;
166
- }
167
-
168
- const itemStates = this.#getItemStates();
169
- const currentIndex = this.#triggers.indexOf(currentTrigger);
170
- let nextIndex = -1;
171
-
172
- if (currentIndex === -1 || currentIndex >= itemStates.length) {
173
- return;
174
- }
175
-
176
- switch (event.key) {
177
- case "ArrowDown":
178
- nextIndex = findNextEnabledAccordionIndex(itemStates, currentIndex, 1);
179
- break;
180
- case "ArrowUp":
181
- nextIndex = findNextEnabledAccordionIndex(itemStates, currentIndex, -1);
182
- break;
183
- case "Home":
184
- nextIndex = findFirstEnabledAccordionIndex(itemStates);
185
- break;
186
- case "End":
187
- nextIndex = findLastEnabledAccordionIndex(itemStates);
188
- break;
189
- case " ":
190
- case "Enter":
191
- event.preventDefault();
192
- this.#toggleIndex(currentIndex, { focus: true });
193
- return;
194
- default:
195
- return;
196
- }
197
-
198
- if (nextIndex === -1) {
199
- return;
200
- }
201
-
202
- event.preventDefault();
203
- this.#focusIndex = nextIndex;
204
- this.#applyState({ focus: true });
205
- };
206
-
207
- #getItemStates() {
208
- const pairCount = Math.min(this.#triggers.length, this.#panels.length);
209
-
210
- return this.#triggers.slice(0, pairCount).map((trigger, index) => ({
211
- disabled: isAccordionItemDisabled(trigger),
212
- open: trigger.hasAttribute("data-open")
213
- || trigger.getAttribute("aria-expanded") === "true"
214
- || this.#panels[index]?.hasAttribute("data-open"),
215
- }));
216
- }
217
-
218
- #isCollapsible() {
219
- return this.hasAttribute("data-collapsible");
220
- }
221
-
222
- #isMultiple() {
223
- return this.hasAttribute("data-multiple");
224
- }
225
-
226
- #getNextFocusableIndex(itemStates) {
227
- for (const openIndex of this.#openIndexes) {
228
- if (!itemStates[openIndex]?.disabled) {
229
- return openIndex;
230
- }
231
- }
232
-
233
- return findFirstEnabledAccordionIndex(itemStates);
234
- }
235
-
236
- #sync({ resetOpen = false } = {}) {
237
- this.#triggers = collectOwnedElements(this, this, TRIGGER_SELECTOR);
238
- this.#panels = collectOwnedElements(this, this, PANEL_SELECTOR);
239
-
240
- const itemStates = this.#getItemStates();
241
-
242
- if (resetOpen) {
243
- this.#openIndexes = new Set(
244
- getInitialOpenAccordionIndexes(itemStates, {
245
- multiple: this.#isMultiple(),
246
- collapsible: this.#isCollapsible(),
247
- }),
248
- );
249
- } else {
250
- const nextOpenIndexes = Array.from(this.#openIndexes).filter(
251
- (index) => index >= 0 && index < itemStates.length && !itemStates[index]?.disabled,
252
- );
253
-
254
- if (!this.#isMultiple() && nextOpenIndexes.length > 1) {
255
- nextOpenIndexes.splice(1);
256
- }
257
-
258
- if (
259
- !this.#isMultiple()
260
- && nextOpenIndexes.length === 0
261
- && !this.#isCollapsible()
262
- ) {
263
- const fallbackIndex = findFirstEnabledAccordionIndex(itemStates);
264
-
265
- if (fallbackIndex !== -1) {
266
- nextOpenIndexes.push(fallbackIndex);
267
- }
268
- }
269
-
270
- this.#openIndexes = new Set(nextOpenIndexes);
271
- }
272
-
273
- if (resetOpen || itemStates[this.#focusIndex]?.disabled || this.#focusIndex >= itemStates.length) {
274
- this.#focusIndex = this.#getNextFocusableIndex(itemStates);
275
- }
276
-
277
- this.#applyState();
278
- }
279
-
280
- #applyState({ focus = false } = {}) {
281
- const pairCount = Math.min(this.#triggers.length, this.#panels.length);
282
- const baseId = this.id || this.#instanceId;
283
-
284
- for (let index = 0; index < this.#triggers.length; index += 1) {
285
- const trigger = this.#triggers[index];
286
- const panel = index < pairCount ? this.#panels[index] : null;
287
- const disabled = index >= pairCount || isAccordionItemDisabled(trigger);
288
- const open = !disabled && this.#openIndexes.has(index);
289
- const focusable = !disabled && index === this.#focusIndex;
290
-
291
- if (!trigger.id) {
292
- trigger.id = `${baseId}-trigger-${index + 1}`;
293
- }
294
-
295
- if (trigger instanceof HTMLButtonElementBase && !trigger.hasAttribute("type")) {
296
- trigger.type = "button";
297
- }
298
-
299
- trigger.setAttribute("aria-expanded", String(open));
300
- trigger.tabIndex = focusable ? 0 : -1;
301
- trigger.toggleAttribute("data-open", open);
302
-
303
- if (panel) {
304
- if (!panel.id) {
305
- panel.id = `${baseId}-panel-${index + 1}`;
306
- }
307
-
308
- trigger.setAttribute("aria-controls", panel.id);
309
- } else {
310
- trigger.removeAttribute("aria-controls");
311
- }
312
- }
313
-
314
- for (let index = 0; index < this.#panels.length; index += 1) {
315
- const panel = this.#panels[index];
316
- const trigger = this.#triggers[index];
317
- const open = index < pairCount
318
- && !isAccordionItemDisabled(trigger)
319
- && this.#openIndexes.has(index);
320
-
321
- if (!panel.id) {
322
- panel.id = `${baseId}-panel-${index + 1}`;
323
- }
324
-
325
- panel.setAttribute("role", "region");
326
-
327
- if (trigger?.id) {
328
- panel.setAttribute("aria-labelledby", trigger.id);
329
- } else {
330
- panel.removeAttribute("aria-labelledby");
331
- }
332
-
333
- panel.hidden = !open;
334
- panel.toggleAttribute("data-open", open);
335
- }
336
-
337
- if (focus && this.#focusIndex !== -1) {
338
- this.#triggers[this.#focusIndex]?.focus();
339
- }
340
- }
341
-
342
- #toggleIndex(index, { focus = false } = {}) {
343
- const itemStates = this.#getItemStates();
344
-
345
- if (index < 0 || index >= itemStates.length || itemStates[index]?.disabled) {
346
- return;
347
- }
348
-
349
- const nextOpenIndexes = new Set(this.#openIndexes);
350
- const isOpen = nextOpenIndexes.has(index);
351
-
352
- if (this.#isMultiple()) {
353
- if (isOpen) {
354
- nextOpenIndexes.delete(index);
355
- } else {
356
- nextOpenIndexes.add(index);
357
- }
358
- } else if (isOpen) {
359
- if (!this.#isCollapsible()) {
360
- this.#focusIndex = index;
361
- this.#applyState({ focus });
362
- return;
363
- }
364
-
365
- nextOpenIndexes.clear();
366
- } else {
367
- nextOpenIndexes.clear();
368
- nextOpenIndexes.add(index);
369
- }
370
-
371
- this.#openIndexes = nextOpenIndexes;
372
- this.#focusIndex = index;
373
- this.#applyState({ focus });
374
- }
375
- }
376
-
377
- export function defineAccordion(registry = globalThis.customElements) {
378
- if (!registry?.get || !registry?.define) {
379
- return AccordionElement;
380
- }
381
-
382
- if (!registry.get(ACCORDION_TAG_NAME)) {
383
- registry.define(ACCORDION_TAG_NAME, AccordionElement);
384
- }
385
-
386
- return AccordionElement;
387
- }
package/readme.mdx DELETED
@@ -1,6 +0,0 @@
1
- import { Markdown, Meta } from "@storybook/addon-docs/blocks";
2
- import Readme from "./README.md?raw";
3
-
4
- <Meta title="Overview/Readme" />
5
-
6
- <Markdown>{Readme}</Markdown>