@govuk-react/primitives 0.2.0 → 0.3.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/README.md +100 -25
- package/dist/{accordion-element.d.ts → accordion/element.d.ts} +5 -5
- package/dist/accordion/element.js +302 -0
- package/dist/accordion/element.js.map +1 -0
- package/dist/accordion/index.d.ts +70 -0
- package/dist/accordion/index.js +140 -0
- package/dist/accordion/index.js.map +1 -0
- package/dist/auto-focus/element.d.ts +1 -0
- package/dist/auto-focus/element.js +75 -0
- package/dist/auto-focus/element.js.map +1 -0
- package/dist/auto-focus/index.d.ts +15 -0
- package/dist/auto-focus/index.js +39 -0
- package/dist/auto-focus/index.js.map +1 -0
- package/dist/{autocomplete-element.d.ts → autocomplete/element.d.ts} +11 -11
- package/dist/autocomplete/element.js +597 -0
- package/dist/autocomplete/element.js.map +1 -0
- package/dist/{index-D7lMYMUR.d.ts → autocomplete/index.d.ts} +39 -62
- package/dist/autocomplete/index.js +100 -0
- package/dist/autocomplete/index.js.map +1 -0
- package/dist/button/element.d.ts +1 -0
- package/dist/button/element.js +59 -0
- package/dist/button/element.js.map +1 -0
- package/dist/button/index.d.ts +10 -0
- package/dist/button/index.js +9 -0
- package/dist/button/index.js.map +1 -0
- package/dist/character-count/element.d.ts +12 -0
- package/dist/character-count/element.js +287 -0
- package/dist/character-count/element.js.map +1 -0
- package/dist/character-count/index.d.ts +57 -0
- package/dist/character-count/index.js +79 -0
- package/dist/character-count/index.js.map +1 -0
- package/dist/character-count/messages.d.ts +20 -0
- package/dist/character-count/messages.js +54 -0
- package/dist/character-count/messages.js.map +1 -0
- package/dist/choices/element.d.ts +10 -0
- package/dist/choices/element.js +177 -0
- package/dist/choices/element.js.map +1 -0
- package/dist/{index-WuGvkTxu.d.ts → choices/index.d.ts} +30 -44
- package/dist/choices/index.js +37 -0
- package/dist/choices/index.js.map +1 -0
- package/dist/{disclosure-element.d.ts → disclosure/element.d.ts} +5 -5
- package/dist/disclosure/element.js +132 -0
- package/dist/disclosure/element.js.map +1 -0
- package/dist/{index-D4Gzyvfu.d.ts → disclosure/index.d.ts} +43 -56
- package/dist/disclosure/index.js +76 -0
- package/dist/disclosure/index.js.map +1 -0
- package/dist/exit-this-page/element.d.ts +19 -0
- package/dist/exit-this-page/element.js +200 -0
- package/dist/exit-this-page/element.js.map +1 -0
- package/dist/{index-qF0jIQCW.d.ts → exit-this-page/index.d.ts} +44 -68
- package/dist/exit-this-page/index.js +54 -0
- package/dist/exit-this-page/index.js.map +1 -0
- package/dist/file-upload/element.d.ts +28 -0
- package/dist/file-upload/element.js +270 -0
- package/dist/file-upload/element.js.map +1 -0
- package/dist/file-upload/index.d.ts +46 -0
- package/dist/file-upload/index.js +65 -0
- package/dist/file-upload/index.js.map +1 -0
- package/dist/focus-links/element.d.ts +1 -0
- package/dist/focus-links/element.js +90 -0
- package/dist/focus-links/element.js.map +1 -0
- package/dist/{index-BR3MAGF8.d.ts → focus-links/index.d.ts} +24 -35
- package/dist/focus-links/index.js +7 -0
- package/dist/focus-links/index.js.map +1 -0
- package/dist/index.d.ts +13 -17
- package/dist/index.js +13 -72
- package/dist/index.js.map +1 -1
- package/dist/inline/accordion-element.js +1 -1
- package/dist/inline/auto-focus-element.js +1 -1
- package/dist/inline/autocomplete-element.js +1 -1
- package/dist/inline/character-count-element.js +1 -1
- package/dist/inline/choices-element.js +1 -1
- package/dist/inline/disclosure-element.js +1 -1
- package/dist/inline/exit-this-page-element.js +1 -1
- package/dist/inline/file-upload-element.js +1 -1
- package/dist/inline/focus-links-element.js +1 -1
- package/dist/inline/modal-element.js +1 -1
- package/dist/inline/password-input-element.js +1 -1
- package/dist/inline/tabs-element.js +1 -1
- package/dist/inline-script/index.d.ts +26 -0
- package/dist/inline-script/index.js +31 -0
- package/dist/inline-script/index.js.map +1 -0
- package/dist/{modal-element.d.ts → modal/element.d.ts} +2 -4
- package/dist/modal/element.js +229 -0
- package/dist/modal/element.js.map +1 -0
- package/dist/modal/index.d.ts +41 -0
- package/dist/modal/index.js +145 -0
- package/dist/modal/index.js.map +1 -0
- package/dist/password-input/element.d.ts +1 -0
- package/dist/password-input/element.js +150 -0
- package/dist/password-input/element.js.map +1 -0
- package/dist/{index-sEHnx4-M.d.ts → password-input/index.d.ts} +33 -49
- package/dist/password-input/index.js +37 -0
- package/dist/password-input/index.js.map +1 -0
- package/dist/styles.css +11 -0
- package/dist/{tabs-element.d.ts → tabs/element.d.ts} +5 -5
- package/dist/tabs/element.js +423 -0
- package/dist/tabs/element.js.map +1 -0
- package/dist/tabs/index.d.ts +74 -0
- package/dist/tabs/index.js +142 -0
- package/dist/tabs/index.js.map +1 -0
- package/dist/utils/change-details.d.ts +11 -0
- package/dist/utils/change-details.js +3 -0
- package/dist/utils/change-details.js.map +1 -0
- package/dist/utils/dom.d.ts +9 -0
- package/dist/utils/dom.js +27 -0
- package/dist/utils/dom.js.map +1 -0
- package/dist/utils/on-property-change.d.ts +7 -0
- package/dist/utils/on-property-change.js +19 -0
- package/dist/utils/on-property-change.js.map +1 -0
- package/dist/utils/set-focus.d.ts +11 -0
- package/dist/utils/set-focus.js +38 -0
- package/dist/utils/set-focus.js.map +1 -0
- package/dist/utils/set-up-when-ready.d.ts +6 -0
- package/dist/utils/set-up-when-ready.js +16 -0
- package/dist/utils/set-up-when-ready.js.map +1 -0
- package/dist/utils/slot.d.ts +15 -0
- package/dist/utils/slot.js +62 -0
- package/dist/utils/slot.js.map +1 -0
- package/dist/utils/translation.d.ts +13 -0
- package/dist/utils/translation.js +57 -0
- package/dist/utils/translation.js.map +1 -0
- package/package.json +17 -4
- package/dist/accordion-element.js +0 -9
- package/dist/accordion-element.js.map +0 -1
- package/dist/accordion.d.ts +0 -2
- package/dist/accordion.js +0 -34
- package/dist/accordion.js.map +0 -1
- package/dist/auto-focus-element.d.ts +0 -3
- package/dist/auto-focus-element.js +0 -10
- package/dist/auto-focus-element.js.map +0 -1
- package/dist/auto-focus.d.ts +0 -2
- package/dist/auto-focus.js +0 -15
- package/dist/auto-focus.js.map +0 -1
- package/dist/autocomplete-element.js +0 -12
- package/dist/autocomplete-element.js.map +0 -1
- package/dist/autocomplete.d.ts +0 -4
- package/dist/autocomplete.js +0 -25
- package/dist/autocomplete.js.map +0 -1
- package/dist/button-element.d.ts +0 -2
- package/dist/button-element.js +0 -3
- package/dist/button-element.js.map +0 -1
- package/dist/button.d.ts +0 -2
- package/dist/button.js +0 -12
- package/dist/button.js.map +0 -1
- package/dist/character-count-element.d.ts +0 -10
- package/dist/character-count-element.js +0 -10
- package/dist/character-count-element.js.map +0 -1
- package/dist/character-count.d.ts +0 -3
- package/dist/character-count.js +0 -26
- package/dist/character-count.js.map +0 -1
- package/dist/choices-element.d.ts +0 -8
- package/dist/choices-element.js +0 -9
- package/dist/choices-element.js.map +0 -1
- package/dist/choices.d.ts +0 -2
- package/dist/choices.js +0 -16
- package/dist/choices.js.map +0 -1
- package/dist/chunk-2IHAQAYF.js +0 -23
- package/dist/chunk-2IHAQAYF.js.map +0 -1
- package/dist/chunk-2ZJVSNC2.js +0 -31
- package/dist/chunk-2ZJVSNC2.js.map +0 -1
- package/dist/chunk-47NMY4SS.js +0 -108
- package/dist/chunk-47NMY4SS.js.map +0 -1
- package/dist/chunk-4XAR4FFG.js +0 -83
- package/dist/chunk-4XAR4FFG.js.map +0 -1
- package/dist/chunk-5HWRMQK2.js +0 -91
- package/dist/chunk-5HWRMQK2.js.map +0 -1
- package/dist/chunk-6ZFU4VYW.js +0 -41
- package/dist/chunk-6ZFU4VYW.js.map +0 -1
- package/dist/chunk-B2I4J5NL.js +0 -264
- package/dist/chunk-B2I4J5NL.js.map +0 -1
- package/dist/chunk-DPERPCUH.js +0 -188
- package/dist/chunk-DPERPCUH.js.map +0 -1
- package/dist/chunk-ECYGKE4D.js +0 -168
- package/dist/chunk-ECYGKE4D.js.map +0 -1
- package/dist/chunk-ESBMTI25.js +0 -11
- package/dist/chunk-ESBMTI25.js.map +0 -1
- package/dist/chunk-ET7DCQM7.js +0 -133
- package/dist/chunk-ET7DCQM7.js.map +0 -1
- package/dist/chunk-F5XFC4QJ.js +0 -177
- package/dist/chunk-F5XFC4QJ.js.map +0 -1
- package/dist/chunk-GVGBDSDN.js +0 -78
- package/dist/chunk-GVGBDSDN.js.map +0 -1
- package/dist/chunk-IZQ2C4BC.js +0 -351
- package/dist/chunk-IZQ2C4BC.js.map +0 -1
- package/dist/chunk-L7E6GN2D.js +0 -87
- package/dist/chunk-L7E6GN2D.js.map +0 -1
- package/dist/chunk-LWIA644X.js +0 -34
- package/dist/chunk-LWIA644X.js.map +0 -1
- package/dist/chunk-NX4B3NKM.js +0 -35
- package/dist/chunk-NX4B3NKM.js.map +0 -1
- package/dist/chunk-PNWPGD7B.js +0 -68
- package/dist/chunk-PNWPGD7B.js.map +0 -1
- package/dist/chunk-QLQ6O7OW.js +0 -111
- package/dist/chunk-QLQ6O7OW.js.map +0 -1
- package/dist/chunk-RDUPELOK.js +0 -55
- package/dist/chunk-RDUPELOK.js.map +0 -1
- package/dist/chunk-RPMHI67T.js +0 -104
- package/dist/chunk-RPMHI67T.js.map +0 -1
- package/dist/chunk-TE4RUYVK.js +0 -97
- package/dist/chunk-TE4RUYVK.js.map +0 -1
- package/dist/chunk-TJVBFRIE.js +0 -60
- package/dist/chunk-TJVBFRIE.js.map +0 -1
- package/dist/chunk-U5OKNKYC.js +0 -510
- package/dist/chunk-U5OKNKYC.js.map +0 -1
- package/dist/chunk-UXJO4AJP.js +0 -290
- package/dist/chunk-UXJO4AJP.js.map +0 -1
- package/dist/chunk-VNXXENCU.js +0 -39
- package/dist/chunk-VNXXENCU.js.map +0 -1
- package/dist/chunk-XGK73UCD.js +0 -62
- package/dist/chunk-XGK73UCD.js.map +0 -1
- package/dist/chunk-XJYLFTYE.js +0 -157
- package/dist/chunk-XJYLFTYE.js.map +0 -1
- package/dist/chunk-YCESNTXQ.js +0 -241
- package/dist/chunk-YCESNTXQ.js.map +0 -1
- package/dist/chunk-ZTJLVNR4.js +0 -62
- package/dist/chunk-ZTJLVNR4.js.map +0 -1
- package/dist/disclosure-element.js +0 -9
- package/dist/disclosure-element.js.map +0 -1
- package/dist/disclosure.d.ts +0 -2
- package/dist/disclosure.js +0 -16
- package/dist/disclosure.js.map +0 -1
- package/dist/exit-this-page-element.d.ts +0 -22
- package/dist/exit-this-page-element.js +0 -13
- package/dist/exit-this-page-element.js.map +0 -1
- package/dist/exit-this-page.d.ts +0 -3
- package/dist/exit-this-page.js +0 -25
- package/dist/exit-this-page.js.map +0 -1
- package/dist/file-upload-element.d.ts +0 -27
- package/dist/file-upload-element.js +0 -14
- package/dist/file-upload-element.js.map +0 -1
- package/dist/file-upload.d.ts +0 -3
- package/dist/file-upload.js +0 -25
- package/dist/file-upload.js.map +0 -1
- package/dist/focus-links-element.d.ts +0 -3
- package/dist/focus-links-element.js +0 -10
- package/dist/focus-links-element.js.map +0 -1
- package/dist/focus-links.d.ts +0 -2
- package/dist/focus-links.js +0 -12
- package/dist/focus-links.js.map +0 -1
- package/dist/index--FxJgSOS.d.ts +0 -108
- package/dist/index-Bul0NJh_.d.ts +0 -310
- package/dist/index-CikOyFud.d.ts +0 -54
- package/dist/index-D8N5vxTL.d.ts +0 -90
- package/dist/index-DMWpkC_d.d.ts +0 -105
- package/dist/index-DN7fGMc3.d.ts +0 -20
- package/dist/index-DPXR1Yua.d.ts +0 -69
- package/dist/inline-script.d.ts +0 -29
- package/dist/inline-script.js +0 -63
- package/dist/inline-script.js.map +0 -1
- package/dist/modal-element.js +0 -11
- package/dist/modal-element.js.map +0 -1
- package/dist/modal.d.ts +0 -2
- package/dist/modal.js +0 -20
- package/dist/modal.js.map +0 -1
- package/dist/password-input-element.d.ts +0 -3
- package/dist/password-input-element.js +0 -9
- package/dist/password-input-element.js.map +0 -1
- package/dist/password-input.d.ts +0 -2
- package/dist/password-input.js +0 -18
- package/dist/password-input.js.map +0 -1
- package/dist/tabs-element.js +0 -9
- package/dist/tabs-element.js.map +0 -1
- package/dist/tabs.d.ts +0 -2
- package/dist/tabs.js +0 -28
- package/dist/tabs.js.map +0 -1
- package/dist/translation-BnpO2mN2.d.ts +0 -4
package/dist/chunk-5HWRMQK2.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import {
|
|
3
|
-
defaults,
|
|
4
|
-
statusText,
|
|
5
|
-
tagName
|
|
6
|
-
} from "./chunk-YCESNTXQ.js";
|
|
7
|
-
import {
|
|
8
|
-
translationAttributes
|
|
9
|
-
} from "./chunk-RDUPELOK.js";
|
|
10
|
-
import {
|
|
11
|
-
Slot
|
|
12
|
-
} from "./chunk-NX4B3NKM.js";
|
|
13
|
-
import {
|
|
14
|
-
__export
|
|
15
|
-
} from "./chunk-ESBMTI25.js";
|
|
16
|
-
|
|
17
|
-
// src/file-upload/index.tsx
|
|
18
|
-
var file_upload_exports = {};
|
|
19
|
-
__export(file_upload_exports, {
|
|
20
|
-
Announcements: () => Announcements,
|
|
21
|
-
Button: () => Button,
|
|
22
|
-
DropZone: () => DropZone,
|
|
23
|
-
Input: () => Input,
|
|
24
|
-
Root: () => Root,
|
|
25
|
-
Separator: () => Separator,
|
|
26
|
-
Status: () => Status
|
|
27
|
-
});
|
|
28
|
-
import * as React from "react";
|
|
29
|
-
import { createContext, useContext, useState } from "react";
|
|
30
|
-
var InitialStatus = createContext(defaults["no-file-chosen"]);
|
|
31
|
-
function Root({
|
|
32
|
-
noFileChosen,
|
|
33
|
-
multipleFilesChosen,
|
|
34
|
-
enteredDropZone,
|
|
35
|
-
leftDropZone,
|
|
36
|
-
emptyClass,
|
|
37
|
-
draggingClass,
|
|
38
|
-
disabledClass,
|
|
39
|
-
...props
|
|
40
|
-
}) {
|
|
41
|
-
const [initial] = useState(() => statusText([], { "no-file-chosen": noFileChosen }, props.lang || "en"));
|
|
42
|
-
return /* @__PURE__ */ React.createElement(InitialStatus.Provider, { value: initial }, React.createElement(tagName, {
|
|
43
|
-
...props,
|
|
44
|
-
// The element owns `data-upgraded`.
|
|
45
|
-
suppressHydrationWarning: true,
|
|
46
|
-
"no-file-chosen": noFileChosen,
|
|
47
|
-
...translationAttributes("multiple-files-chosen", multipleFilesChosen),
|
|
48
|
-
"entered-drop-zone": enteredDropZone,
|
|
49
|
-
"left-drop-zone": leftDropZone,
|
|
50
|
-
"empty-class": emptyClass,
|
|
51
|
-
"dragging-class": draggingClass,
|
|
52
|
-
"disabled-class": disabledClass
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
function DropZone({ asChild, ...props }) {
|
|
56
|
-
const Element = asChild ? Slot : "div";
|
|
57
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-file-upload-drop-zone": "", suppressHydrationWarning: true, ...props });
|
|
58
|
-
}
|
|
59
|
-
function Input({ asChild, ...props }) {
|
|
60
|
-
const Element = asChild ? Slot : "input";
|
|
61
|
-
return /* @__PURE__ */ React.createElement(Element, { type: "file", suppressHydrationWarning: true, ...props });
|
|
62
|
-
}
|
|
63
|
-
function Button({ asChild, ...props }) {
|
|
64
|
-
const Element = asChild ? Slot : "button";
|
|
65
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-file-upload-button": "", type: "button", hidden: true, suppressHydrationWarning: true, ...props });
|
|
66
|
-
}
|
|
67
|
-
function Status({ asChild, children, ...props }) {
|
|
68
|
-
const initial = useContext(InitialStatus);
|
|
69
|
-
const Element = asChild ? Slot : "span";
|
|
70
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-file-upload-status": "", "aria-live": "polite", suppressHydrationWarning: true, ...props }, children != null ? children : initial);
|
|
71
|
-
}
|
|
72
|
-
function Separator({ asChild, children = ", ", ...props }) {
|
|
73
|
-
const Element = asChild ? Slot : "span";
|
|
74
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-file-upload-separator": "", suppressHydrationWarning: true, ...props }, children);
|
|
75
|
-
}
|
|
76
|
-
function Announcements({ asChild, ...props }) {
|
|
77
|
-
const Element = asChild ? Slot : "span";
|
|
78
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-file-upload-announcements": "", "aria-live": "assertive", suppressHydrationWarning: true, ...props });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export {
|
|
82
|
-
Root,
|
|
83
|
-
DropZone,
|
|
84
|
-
Input,
|
|
85
|
-
Button,
|
|
86
|
-
Status,
|
|
87
|
-
Separator,
|
|
88
|
-
Announcements,
|
|
89
|
-
file_upload_exports
|
|
90
|
-
};
|
|
91
|
-
//# sourceMappingURL=chunk-5HWRMQK2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/file-upload/index.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createContext, useContext, useState } from 'react';\nimport type { ComponentProps } from 'react';\nimport { Slot } from '../utils/slot';\nimport { translationAttributes, type Translation } from '../utils/translation';\nimport { defaults, statusText, tagName } from './element';\n\nexport type { Translation } from '../utils/translation';\n\n/*\n * Headless file upload: unstyled parts over the <govuk-react-file-upload> element (./element.ts),\n * which shows the button on upgrade, hides the input and handles dropped files. Every part except\n * Root takes `asChild`.\n *\n * The input's files are the state, owned by the browser, so there is nothing to control. Without\n * JavaScript the native file input shows and the button stays hidden.\n */\n\nexport type RootProps = React.HTMLAttributes<HTMLElement> & {\n /** Shown while no file is chosen. Defaults to \"No file chosen\". */\n noFileChosen?: string;\n /** Shown when more than one file is chosen. `%{count}` is the number. Defaults to \"%{count} files chosen\". */\n multipleFilesChosen?: Translation;\n /** Announced when the user drags files into the drop zone. Defaults to \"Entered drop zone\". */\n enteredDropZone?: string;\n /** Announced when the user drags files out of the drop zone. Defaults to \"Left drop zone\". */\n leftDropZone?: string;\n /** Classes for the button while no file is chosen. */\n emptyClass?: string;\n /** Classes for the button while files are dragged over the drop zone. */\n draggingClass?: string;\n /** Classes for the drop zone while the input is disabled. */\n disabledClass?: string;\n};\n\n// What the status starts with, so the element only changes text React rendered.\nconst InitialStatus = createContext<string>(defaults['no-file-chosen']);\n\nexport function Root({\n noFileChosen,\n multipleFilesChosen,\n enteredDropZone,\n leftDropZone,\n emptyClass,\n draggingClass,\n disabledClass,\n ...props\n}: RootProps) {\n // Rendered once and then left to the element, so a re-render never puts back a stale status.\n const [initial] = useState(() => statusText([], { 'no-file-chosen': noFileChosen }, props.lang || 'en'));\n return (\n <InitialStatus.Provider value={initial}>\n {React.createElement(tagName, {\n ...props,\n // The element owns `data-upgraded`.\n suppressHydrationWarning: true,\n 'no-file-chosen': noFileChosen,\n ...translationAttributes('multiple-files-chosen', multipleFilesChosen),\n 'entered-drop-zone': enteredDropZone,\n 'left-drop-zone': leftDropZone,\n 'empty-class': emptyClass,\n 'dragging-class': draggingClass,\n 'disabled-class': disabledClass,\n })}\n </InitialStatus.Provider>\n );\n}\n\ntype PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E> & {\n /** Render the only child instead, with this part's props merged onto it. */\n asChild?: boolean;\n};\n\nexport type DropZoneProps = PartProps<'div'>;\n\n/** The area that shows files are being dragged over it. Holds the button and the input. */\nexport function DropZone({ asChild, ...props }: DropZoneProps) {\n const Element = asChild ? Slot : 'div';\n // The element owns its disabled classes after upgrade.\n return <Element data-file-upload-drop-zone=\"\" suppressHydrationWarning {...props} />;\n}\n\nexport type InputProps = Omit<PartProps<'input'>, 'type'>;\n\n/** The file input, with an `id` and a `label`. Shown without JavaScript, and hidden on upgrade. */\nexport function Input({ asChild, ...props }: InputProps) {\n const Element = asChild ? Slot : 'input';\n // The element owns `id` and `hidden` after upgrade.\n return <Element type=\"file\" suppressHydrationWarning {...props} />;\n}\n\nexport type ButtonProps = PartProps<'button'>;\n\n/**\n * Opens the file picker, and takes dropped files. Hidden until the element upgrades, when it\n * takes the input's id, so the input's label names it. Holds `Status`.\n */\nexport function Button({ asChild, ...props }: ButtonProps) {\n const Element = asChild ? Slot : 'button';\n // The element owns `id`, `hidden`, `disabled`, its ARIA and its classes after upgrade.\n return <Element data-file-upload-button=\"\" type=\"button\" hidden suppressHydrationWarning {...props} />;\n}\n\nexport type StatusProps = PartProps<'span'>;\n\n/** Which files are chosen: \"No file chosen\", the file's name, or how many files. In `Button`. */\nexport function Status({ asChild, children, ...props }: StatusProps) {\n const initial = useContext(InitialStatus);\n const Element = asChild ? Slot : 'span';\n // The element owns its text after upgrade.\n return (\n <Element data-file-upload-status=\"\" aria-live=\"polite\" suppressHydrationWarning {...props}>\n {children ?? initial}\n </Element>\n );\n}\n\nexport type SeparatorProps = PartProps<'span'>;\n\n/** Between the label and the button's text in the button's accessible name. Defaults to \", \". In `Button`. */\nexport function Separator({ asChild, children = ', ', ...props }: SeparatorProps) {\n const Element = asChild ? Slot : 'span';\n // The element owns its `id` after upgrade.\n return (\n <Element data-file-upload-separator=\"\" suppressHydrationWarning {...props}>\n {children}\n </Element>\n );\n}\n\nexport type AnnouncementsProps = PartProps<'span'>;\n\n/** Announces entering and leaving the drop zone. Make it visually hidden. */\nexport function Announcements({ asChild, ...props }: AnnouncementsProps) {\n const Element = asChild ? Slot : 'span';\n // The element owns its text after upgrade.\n return <Element data-file-upload-announcements=\"\" aria-live=\"assertive\" suppressHydrationWarning {...props} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAY,WAAW;AACvB,SAAS,eAAe,YAAY,gBAAgB;AAmCpD,IAAM,gBAAgB,cAAsB,SAAS,gBAAgB,CAAC;AAE/D,SAAS,KAAK;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAc;AAEZ,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM,WAAW,CAAC,GAAG,EAAE,kBAAkB,aAAa,GAAG,MAAM,QAAQ,IAAI,CAAC;AACvG,SACE,oCAAC,cAAc,UAAd,EAAuB,OAAO,WACtB,oBAAc,SAAS;AAAA,IAC5B,GAAG;AAAA;AAAA,IAEH,0B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9G;","names":[]}
|
package/dist/chunk-6ZFU4VYW.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import {
|
|
3
|
-
tagName
|
|
4
|
-
} from "./chunk-XGK73UCD.js";
|
|
5
|
-
import {
|
|
6
|
-
Slot
|
|
7
|
-
} from "./chunk-NX4B3NKM.js";
|
|
8
|
-
import {
|
|
9
|
-
__export
|
|
10
|
-
} from "./chunk-ESBMTI25.js";
|
|
11
|
-
|
|
12
|
-
// src/auto-focus/index.tsx
|
|
13
|
-
var auto_focus_exports = {};
|
|
14
|
-
__export(auto_focus_exports, {
|
|
15
|
-
Root: () => Root,
|
|
16
|
-
Target: () => Target
|
|
17
|
-
});
|
|
18
|
-
import * as React from "react";
|
|
19
|
-
import { isValidElement } from "react";
|
|
20
|
-
function Root({ disabled, ...props }) {
|
|
21
|
-
return React.createElement(tagName, { ...props, disabled: disabled ? "" : void 0 });
|
|
22
|
-
}
|
|
23
|
-
function tabIndexOf({ asChild, tabIndex, children }) {
|
|
24
|
-
if (tabIndex !== void 0 || !asChild) return tabIndex;
|
|
25
|
-
return isValidElement(children) ? children.props.tabIndex : void 0;
|
|
26
|
-
}
|
|
27
|
-
function Target({ asChild, disabled, ...props }) {
|
|
28
|
-
const Element = asChild ? Slot : "div";
|
|
29
|
-
let focus = {};
|
|
30
|
-
if (!disabled) {
|
|
31
|
-
focus = tabIndexOf({ asChild, ...props }) === void 0 ? { tabIndex: -1, autoFocus: true, "data-focus-tabindex": "" } : { autoFocus: true };
|
|
32
|
-
}
|
|
33
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-auto-focus": "", suppressHydrationWarning: true, ...focus, ...props });
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export {
|
|
37
|
-
Root,
|
|
38
|
-
Target,
|
|
39
|
-
auto_focus_exports
|
|
40
|
-
};
|
|
41
|
-
//# sourceMappingURL=chunk-6ZFU4VYW.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auto-focus/index.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { isValidElement } from 'react';\nimport type { ComponentProps } from 'react';\nimport { Slot } from '../utils/slot';\nimport { tagName } from './element';\n\n/*\n * Headless auto focus: the <govuk-react-auto-focus> element (./element.ts) moves focus to its\n * `Target` when it appears. The server renders the target with `autofocus`, so the browser focuses\n * it when the page loads, even without JavaScript.\n */\n\nexport type RootProps = React.HTMLAttributes<HTMLElement> & {\n /** Don't move focus. */\n disabled?: boolean;\n};\n\nexport function Root({ disabled, ...props }: RootProps) {\n return React.createElement(tagName, { ...props, disabled: disabled ? '' : undefined });\n}\n\nexport type TargetProps = ComponentProps<'div'> & {\n /** Render the only child instead, with this part's props merged onto it. */\n asChild?: boolean;\n /** Don't move focus. Pass the same as to `Root`. */\n disabled?: boolean;\n};\n\n/** The tabindex of the target, or with `asChild`, of its child. */\nfunction tabIndexOf({ asChild, tabIndex, children }: TargetProps) {\n if (tabIndex !== undefined || !asChild) return tabIndex;\n return isValidElement<{ tabIndex?: number }>(children) ? children.props.tabIndex : undefined;\n}\n\n/** What gets focus. */\nexport function Target({ asChild, disabled, ...props }: TargetProps) {\n const Element = asChild ? Slot : 'div';\n let focus = {};\n if (!disabled) {\n // `data-focus-tabindex` says the tabindex is only for this, so it goes when focus moves on.\n focus =\n tabIndexOf({ asChild, ...props }) === undefined\n ? { tabIndex: -1, autoFocus: true, 'data-focus-tabindex': '' }\n : { autoFocus: true };\n }\n // The element owns `tabindex` and `autofocus` after it has moved focus.\n return <Element data-auto-focus=\"\" suppressHydrationWarning {...focus} {...props} />;\n}\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAY,WAAW;AACvB,SAAS,sBAAsB;AAgBxB,SAAS,KAAK,EAAE,UAAU,GAAG,MAAM,GAAc;AACtD,SAAa,oBAAc,SAAS,EAAE,GAAG,OAAO,UAAU,WAAW,KAAK,OAAU,CAAC;AACvF;AAUA,SAAS,WAAW,EAAE,SAAS,UAAU,SAAS,GAAgB;AAChE,MAAI,aAAa,UAAa,CAAC,QAAS,QAAO;AAC/C,SAAO,eAAsC,QAAQ,IAAI,SAAS,MAAM,WAAW;AACrF;AAGO,SAAS,OAAO,EAAE,SAAS,UAAU,GAAG,MAAM,GAAgB;AACnE,QAAM,UAAU,UAAU,OAAO;AACjC,MAAI,QAAQ,CAAC;AACb,MAAI,CAAC,UAAU;AAEb,YACE,WAAW,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,SAClC,EAAE,UAAU,IAAI,WAAW,MAAM,uBAAuB,GAAG,IAC3D,EAAE,WAAW,KAAK;AAAA,EAC1B;AAEA,SAAO,oCAAC,WAAQ,mBAAgB,IAAG,0BAAwB,MAAE,GAAG,OAAQ,GAAG,OAAO;AACpF;","names":[]}
|
package/dist/chunk-B2I4J5NL.js
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
// src/accordion/element.ts
|
|
4
|
-
var tagName = "govuk-react-accordion";
|
|
5
|
-
var defaults = {
|
|
6
|
-
"show-section-text": "Show",
|
|
7
|
-
"hide-section-text": "Hide",
|
|
8
|
-
"show-section-label": "Show this section",
|
|
9
|
-
"hide-section-label": "Hide this section",
|
|
10
|
-
"show-all-sections-text": "Show all sections",
|
|
11
|
-
"hide-all-sections-text": "Hide all sections"
|
|
12
|
-
};
|
|
13
|
-
var valuesOf = (attribute) => attribute == null ? void 0 : attribute.split(/\s+/).filter(Boolean);
|
|
14
|
-
var setText = (element, text) => {
|
|
15
|
-
if (element.textContent !== text) element.textContent = text;
|
|
16
|
-
};
|
|
17
|
-
var classesOf = (attribute) => {
|
|
18
|
-
var _a;
|
|
19
|
-
return (_a = attribute == null ? void 0 : attribute.split(/\s+/).filter(Boolean)) != null ? _a : [];
|
|
20
|
-
};
|
|
21
|
-
if (typeof HTMLElement !== "undefined" && typeof customElements !== "undefined") {
|
|
22
|
-
class GovukReactAccordion extends HTMLElement {
|
|
23
|
-
constructor() {
|
|
24
|
-
super(...arguments);
|
|
25
|
-
this.open = /* @__PURE__ */ new Set();
|
|
26
|
-
this.upgraded = false;
|
|
27
|
-
this.controlled = false;
|
|
28
|
-
this.prepared = /* @__PURE__ */ new WeakSet();
|
|
29
|
-
this.onClick = (event) => {
|
|
30
|
-
var _a;
|
|
31
|
-
const target = event.target instanceof Element ? event.target : null;
|
|
32
|
-
const trigger = target == null ? void 0 : target.closest("button[data-accordion-trigger]");
|
|
33
|
-
if (trigger && this.ownsElement(trigger)) {
|
|
34
|
-
const value = (_a = this.sectionOf(trigger)) == null ? void 0 : _a.dataset.value;
|
|
35
|
-
if (value === void 0) return;
|
|
36
|
-
const next = new Set(this.open);
|
|
37
|
-
if (next.has(value)) next.delete(value);
|
|
38
|
-
else next.add(value);
|
|
39
|
-
this.change(next);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const showAll = target == null ? void 0 : target.closest("button[data-accordion-show-all]");
|
|
43
|
-
if (showAll && this.ownsElement(showAll)) {
|
|
44
|
-
const values = this.sections.map((section) => {
|
|
45
|
-
var _a2;
|
|
46
|
-
return (_a2 = section.dataset.value) != null ? _a2 : "";
|
|
47
|
-
});
|
|
48
|
-
this.change(new Set(this.allOpen ? [] : values));
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
// Find in page opens a collapsed section that holds the match.
|
|
52
|
-
this.onBeforeMatch = (event) => {
|
|
53
|
-
const section = event.target instanceof Element ? this.sectionOf(event.target) : void 0;
|
|
54
|
-
const value = section == null ? void 0 : section.dataset.value;
|
|
55
|
-
if (value === void 0 || this.open.has(value)) return;
|
|
56
|
-
this.change(/* @__PURE__ */ new Set([...this.open, value]), true);
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
static get observedAttributes() {
|
|
60
|
-
return ["value"];
|
|
61
|
-
}
|
|
62
|
-
get openValues() {
|
|
63
|
-
return this.upgraded ? [...this.open] : void 0;
|
|
64
|
-
}
|
|
65
|
-
get pickedValue() {
|
|
66
|
-
return this.picked;
|
|
67
|
-
}
|
|
68
|
-
connectedCallback() {
|
|
69
|
-
this.observer = new MutationObserver((records) => {
|
|
70
|
-
if (!this.upgraded) {
|
|
71
|
-
this.setup();
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (records.some((record) => record.type === "childList"))
|
|
75
|
-
this.sections.forEach((section) => this.prepare(section));
|
|
76
|
-
this.render();
|
|
77
|
-
});
|
|
78
|
-
this.observer.observe(this, { childList: true, subtree: true, attributes: true, attributeFilter: ["class"] });
|
|
79
|
-
if (this.upgraded) {
|
|
80
|
-
this.listen();
|
|
81
|
-
this.render();
|
|
82
|
-
} else {
|
|
83
|
-
this.setup();
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
disconnectedCallback() {
|
|
87
|
-
var _a;
|
|
88
|
-
(_a = this.observer) == null ? void 0 : _a.disconnect();
|
|
89
|
-
this.removeEventListener("click", this.onClick);
|
|
90
|
-
this.removeEventListener("beforematch", this.onBeforeMatch, true);
|
|
91
|
-
}
|
|
92
|
-
attributeChangedCallback() {
|
|
93
|
-
const value = valuesOf(this.getAttribute("value"));
|
|
94
|
-
this.controlled = value !== void 0;
|
|
95
|
-
if (!value) return;
|
|
96
|
-
this.open = new Set(value);
|
|
97
|
-
this.render();
|
|
98
|
-
}
|
|
99
|
-
get sections() {
|
|
100
|
-
return this.own("[data-accordion-section]");
|
|
101
|
-
}
|
|
102
|
-
get allOpen() {
|
|
103
|
-
return this.sections.every((section) => {
|
|
104
|
-
var _a;
|
|
105
|
-
return this.open.has((_a = section.dataset.value) != null ? _a : "");
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
own(selector) {
|
|
109
|
-
return Array.from(this.querySelectorAll(selector)).filter((element) => this.ownsElement(element));
|
|
110
|
-
}
|
|
111
|
-
ownsElement(element) {
|
|
112
|
-
return element.closest(tagName) === this;
|
|
113
|
-
}
|
|
114
|
-
sectionOf(element) {
|
|
115
|
-
const section = element.closest("[data-accordion-section]");
|
|
116
|
-
return section && this.ownsElement(section) ? section : void 0;
|
|
117
|
-
}
|
|
118
|
-
find(section, selector) {
|
|
119
|
-
return Array.from(section.querySelectorAll(selector)).find(
|
|
120
|
-
(element) => this.sectionOf(element) === section
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
text(name) {
|
|
124
|
-
var _a;
|
|
125
|
-
return (_a = this.getAttribute(name)) != null ? _a : defaults[name];
|
|
126
|
-
}
|
|
127
|
-
get remember() {
|
|
128
|
-
return this.getAttribute("remember-expanded") !== "false";
|
|
129
|
-
}
|
|
130
|
-
setup() {
|
|
131
|
-
const sections = this.sections;
|
|
132
|
-
if (!sections.some((section) => this.find(section, "button[data-accordion-trigger]"))) return;
|
|
133
|
-
this.upgraded = true;
|
|
134
|
-
const value = valuesOf(this.getAttribute("value"));
|
|
135
|
-
this.controlled = value !== void 0;
|
|
136
|
-
this.open = new Set(value != null ? value : valuesOf(this.getAttribute("default-value")));
|
|
137
|
-
this.dataset.upgraded = "";
|
|
138
|
-
const upgradedClasses = classesOf(this.getAttribute("upgraded-class"));
|
|
139
|
-
if (upgradedClasses.length) this.classList.add(...upgradedClasses);
|
|
140
|
-
this.own("[data-accordion-controls]").forEach((controls) => {
|
|
141
|
-
controls.hidden = false;
|
|
142
|
-
});
|
|
143
|
-
sections.forEach((section) => this.prepare(section));
|
|
144
|
-
this.listen();
|
|
145
|
-
this.render();
|
|
146
|
-
}
|
|
147
|
-
listen() {
|
|
148
|
-
this.addEventListener("click", this.onClick);
|
|
149
|
-
this.addEventListener("beforematch", this.onBeforeMatch, true);
|
|
150
|
-
}
|
|
151
|
-
/** Swaps a section's fallback for its trigger, once, and sets its first state. */
|
|
152
|
-
prepare(section) {
|
|
153
|
-
var _a;
|
|
154
|
-
const trigger = this.find(section, "button[data-accordion-trigger]");
|
|
155
|
-
if (!trigger || this.prepared.has(section)) return;
|
|
156
|
-
this.prepared.add(section);
|
|
157
|
-
const value = (_a = section.dataset.value) != null ? _a : "";
|
|
158
|
-
if (!this.controlled) {
|
|
159
|
-
const defaultValue = valuesOf(this.getAttribute("default-value"));
|
|
160
|
-
if (defaultValue ? defaultValue.includes(value) : section.hasAttribute("data-expanded")) this.open.add(value);
|
|
161
|
-
this.restore(section);
|
|
162
|
-
}
|
|
163
|
-
Array.from(section.querySelectorAll("[data-accordion-fallback]")).filter((fallback) => this.sectionOf(fallback) === section).forEach((fallback) => {
|
|
164
|
-
fallback.hidden = true;
|
|
165
|
-
});
|
|
166
|
-
trigger.hidden = false;
|
|
167
|
-
const content = this.find(section, "[data-accordion-content]");
|
|
168
|
-
if (content == null ? void 0 : content.id) trigger.setAttribute("aria-controls", content.id);
|
|
169
|
-
}
|
|
170
|
-
/** A section remembered from earlier in the session, as in govuk-frontend. */
|
|
171
|
-
restore(section) {
|
|
172
|
-
var _a;
|
|
173
|
-
const id = (_a = this.find(section, "[data-accordion-content]")) == null ? void 0 : _a.id;
|
|
174
|
-
const value = section.dataset.value;
|
|
175
|
-
if (!this.remember || !id || value === void 0) return;
|
|
176
|
-
try {
|
|
177
|
-
const state = window.sessionStorage.getItem(id);
|
|
178
|
-
if (state === "true") this.open.add(value);
|
|
179
|
-
else if (state === "false") this.open.delete(value);
|
|
180
|
-
} catch (e) {
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/** Remembers the sections that changed, as govuk-frontend does. */
|
|
184
|
-
store(previous) {
|
|
185
|
-
if (!this.remember) return;
|
|
186
|
-
this.sections.forEach((section) => {
|
|
187
|
-
var _a, _b;
|
|
188
|
-
const value = (_a = section.dataset.value) != null ? _a : "";
|
|
189
|
-
const id = (_b = this.find(section, "[data-accordion-content]")) == null ? void 0 : _b.id;
|
|
190
|
-
if (!id || previous.has(value) === this.open.has(value)) return;
|
|
191
|
-
try {
|
|
192
|
-
window.sessionStorage.setItem(id, String(this.open.has(value)));
|
|
193
|
-
} catch (e) {
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
change(next, force = false) {
|
|
198
|
-
const value = this.sections.map((section) => {
|
|
199
|
-
var _a;
|
|
200
|
-
return (_a = section.dataset.value) != null ? _a : "";
|
|
201
|
-
}).filter((v) => next.has(v));
|
|
202
|
-
if (!this.controlled || force) {
|
|
203
|
-
const previous = this.open;
|
|
204
|
-
this.open = new Set(value);
|
|
205
|
-
if (!this.controlled) {
|
|
206
|
-
this.picked = value;
|
|
207
|
-
this.store(previous);
|
|
208
|
-
}
|
|
209
|
-
this.render();
|
|
210
|
-
}
|
|
211
|
-
this.dispatchEvent(new CustomEvent("govuk-react-accordion:change", { detail: { value }, bubbles: true }));
|
|
212
|
-
}
|
|
213
|
-
render() {
|
|
214
|
-
if (!this.upgraded) return;
|
|
215
|
-
const expandedClasses = classesOf(this.getAttribute("expanded-section-class"));
|
|
216
|
-
const collapsedIconClasses = classesOf(this.getAttribute("collapsed-icon-class"));
|
|
217
|
-
const setIcon = (root, expanded) => {
|
|
218
|
-
Array.from(root.querySelectorAll("[data-accordion-icon]")).forEach((icon) => {
|
|
219
|
-
collapsedIconClasses.forEach((name) => icon.classList.toggle(name, !expanded));
|
|
220
|
-
});
|
|
221
|
-
};
|
|
222
|
-
this.sections.forEach((section) => {
|
|
223
|
-
var _a;
|
|
224
|
-
const expanded = this.open.has((_a = section.dataset.value) != null ? _a : "");
|
|
225
|
-
const trigger = this.find(section, "button[data-accordion-trigger]");
|
|
226
|
-
const content = this.find(section, "[data-accordion-content]");
|
|
227
|
-
section.dataset.state = expanded ? "open" : "closed";
|
|
228
|
-
expandedClasses.forEach((name) => section.classList.toggle(name, expanded));
|
|
229
|
-
if (content) {
|
|
230
|
-
if (expanded) content.removeAttribute("hidden");
|
|
231
|
-
else content.setAttribute("hidden", "until-found");
|
|
232
|
-
}
|
|
233
|
-
if (!trigger) return;
|
|
234
|
-
trigger.setAttribute("aria-expanded", String(expanded));
|
|
235
|
-
const labels = Array.from(trigger.querySelectorAll("[data-accordion-label]")).map(
|
|
236
|
-
(label) => {
|
|
237
|
-
var _a2, _b;
|
|
238
|
-
return (_b = (_a2 = label.textContent) == null ? void 0 : _a2.trim()) != null ? _b : "";
|
|
239
|
-
}
|
|
240
|
-
);
|
|
241
|
-
trigger.setAttribute(
|
|
242
|
-
"aria-label",
|
|
243
|
-
[...labels, this.text(expanded ? "hide-section-label" : "show-section-label")].join(" , ")
|
|
244
|
-
);
|
|
245
|
-
const toggleText = trigger.querySelector("[data-accordion-toggle-text]");
|
|
246
|
-
if (toggleText) setText(toggleText, this.text(expanded ? "hide-section-text" : "show-section-text"));
|
|
247
|
-
setIcon(trigger, expanded);
|
|
248
|
-
});
|
|
249
|
-
const allOpen = this.allOpen;
|
|
250
|
-
this.own("button[data-accordion-show-all]").forEach((showAll) => {
|
|
251
|
-
showAll.setAttribute("aria-expanded", String(allOpen));
|
|
252
|
-
const text = showAll.querySelector("[data-accordion-show-all-text]");
|
|
253
|
-
if (text) setText(text, this.text(allOpen ? "hide-all-sections-text" : "show-all-sections-text"));
|
|
254
|
-
setIcon(showAll, allOpen);
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (!customElements.get(tagName)) customElements.define(tagName, GovukReactAccordion);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export {
|
|
262
|
-
tagName
|
|
263
|
-
};
|
|
264
|
-
//# sourceMappingURL=chunk-B2I4J5NL.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/accordion/element.ts"],"sourcesContent":["/*\n * <govuk-react-accordion>: a headless, light-DOM custom element that lets users show and hide\n * sections of content, with or without React.\n *\n * Without JavaScript every section is shown, under a plain heading. Each section also holds a\n * hidden button with the same heading. On upgrade the element shows the buttons and hides the\n * plain headings, then each button shows and hides its section's content, and a \"show all\"\n * button shows or hides every section. The rendered markup is never moved, so React can keep\n * rendering it. Content is hidden with `hidden=\"until-found\"`, so find in page still opens it.\n *\n * Markup inside the element:\n * - `[data-accordion-controls]` (optional): holds the \"show all\" button. Rendered `hidden`.\n * - `button[data-accordion-show-all]`, with a `[data-accordion-show-all-text]` for its text.\n * - `[data-accordion-section][data-value]`: a section. `data-expanded` opens it at first.\n * - `[data-accordion-fallback]`: the plain heading and summary, hidden on upgrade.\n * - `button[data-accordion-trigger]`: rendered `hidden`. Its accessible name is the text of its\n * `[data-accordion-label]` elements and the show or hide label. Its\n * `[data-accordion-toggle-text]` shows the show or hide text.\n * - `[data-accordion-content]`: the content, with an id.\n * - `[data-accordion-icon]` (optional): in the buttons, given `collapsed-icon-class` while\n * collapsed.\n *\n * Attributes:\n * - `value`: the open sections' values, separated by spaces, to control them. A user's click only\n * fires the change event, and the sections change when `value` does.\n * - `default-value`: the sections open at first, instead of `data-expanded`.\n * - `remember-expanded`: \"false\" stops the open sections being remembered in session storage,\n * keyed by content id, as govuk-frontend does.\n * - `show-section-text`, `hide-section-text`, `show-section-label`, `hide-section-label`,\n * `show-all-sections-text`, `hide-all-sections-text`: the text, English by default.\n * - `upgraded-class`, `expanded-section-class`, `collapsed-icon-class`: classes to add, for styles\n * keyed off classes rather than `data-upgraded`, `data-state` and `aria-expanded`.\n *\n * A user's click fires a bubbling `govuk-react-accordion:change` event with `{ value }`, the open\n * sections' values.\n */\n\ndeclare global {\n interface HTMLElementEventMap {\n 'govuk-react-accordion:change': CustomEvent<{ value: string[] }>;\n }\n}\n\nexport const tagName = 'govuk-react-accordion';\n\nexport interface AccordionElement extends HTMLElement {\n /** The open sections' values, once upgraded. */\n readonly openValues: string[] | undefined;\n /** The open sections after the user's last change before `value` was first set, such as before React hydrated. */\n readonly pickedValue: string[] | undefined;\n}\n\nconst defaults = {\n 'show-section-text': 'Show',\n 'hide-section-text': 'Hide',\n 'show-section-label': 'Show this section',\n 'hide-section-label': 'Hide this section',\n 'show-all-sections-text': 'Show all sections',\n 'hide-all-sections-text': 'Hide all sections',\n};\n\nconst valuesOf = (attribute: string | null) => attribute?.split(/\\s+/).filter(Boolean);\n\n// Writing the same text again would still wake the MutationObserver.\nconst setText = (element: Element, text: string) => {\n if (element.textContent !== text) element.textContent = text;\n};\n\nconst classesOf = (attribute: string | null) => attribute?.split(/\\s+/).filter(Boolean) ?? [];\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactAccordion extends HTMLElement implements AccordionElement {\n static get observedAttributes() {\n return ['value'];\n }\n\n private open = new Set<string>();\n\n private upgraded = false;\n\n private controlled = false;\n\n private picked?: string[];\n\n private readonly prepared = new WeakSet<HTMLElement>();\n\n private observer?: MutationObserver;\n\n private readonly onClick = (event: MouseEvent) => {\n const target = event.target instanceof Element ? event.target : null;\n const trigger = target?.closest('button[data-accordion-trigger]');\n if (trigger && this.ownsElement(trigger)) {\n const value = this.sectionOf(trigger)?.dataset.value;\n if (value === undefined) return;\n const next = new Set(this.open);\n if (next.has(value)) next.delete(value);\n else next.add(value);\n this.change(next);\n return;\n }\n const showAll = target?.closest('button[data-accordion-show-all]');\n if (showAll && this.ownsElement(showAll)) {\n const values = this.sections.map((section) => section.dataset.value ?? '');\n this.change(new Set(this.allOpen ? [] : values));\n }\n };\n\n // Find in page opens a collapsed section that holds the match.\n private readonly onBeforeMatch = (event: Event) => {\n const section = event.target instanceof Element ? this.sectionOf(event.target) : undefined;\n const value = section?.dataset.value;\n if (value === undefined || this.open.has(value)) return;\n this.change(new Set([...this.open, value]), true);\n };\n\n get openValues() {\n return this.upgraded ? [...this.open] : undefined;\n }\n\n get pickedValue() {\n return this.picked;\n }\n\n connectedCallback() {\n // Sections can be parsed or rendered later, and React can rewrite a class attribute.\n this.observer = new MutationObserver((records) => {\n if (!this.upgraded) {\n this.setup();\n return;\n }\n if (records.some((record) => record.type === 'childList'))\n this.sections.forEach((section) => this.prepare(section));\n this.render();\n });\n this.observer.observe(this, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] });\n if (this.upgraded) {\n // Moved, rather than new: keep the open sections.\n this.listen();\n this.render();\n } else {\n this.setup();\n }\n }\n\n disconnectedCallback() {\n this.observer?.disconnect();\n this.removeEventListener('click', this.onClick);\n this.removeEventListener('beforematch', this.onBeforeMatch, true);\n }\n\n attributeChangedCallback() {\n const value = valuesOf(this.getAttribute('value'));\n this.controlled = value !== undefined;\n if (!value) return;\n this.open = new Set(value);\n this.render();\n }\n\n private get sections() {\n return this.own('[data-accordion-section]');\n }\n\n private get allOpen() {\n return this.sections.every((section) => this.open.has(section.dataset.value ?? ''));\n }\n\n private own(selector: string) {\n // Leave nested accordions to their own element.\n return Array.from(this.querySelectorAll<HTMLElement>(selector)).filter((element) => this.ownsElement(element));\n }\n\n private ownsElement(element: Element) {\n return element.closest(tagName) === this;\n }\n\n private sectionOf(element: Element) {\n const section = element.closest<HTMLElement>('[data-accordion-section]');\n return section && this.ownsElement(section) ? section : undefined;\n }\n\n private find(section: HTMLElement, selector: string) {\n return Array.from(section.querySelectorAll<HTMLElement>(selector)).find(\n (element) => this.sectionOf(element) === section\n );\n }\n\n private text(name: keyof typeof defaults) {\n return this.getAttribute(name) ?? defaults[name];\n }\n\n private get remember() {\n return this.getAttribute('remember-expanded') !== 'false';\n }\n\n private setup() {\n const sections = this.sections;\n if (!sections.some((section) => this.find(section, 'button[data-accordion-trigger]'))) return;\n this.upgraded = true;\n const value = valuesOf(this.getAttribute('value'));\n this.controlled = value !== undefined;\n this.open = new Set(value ?? valuesOf(this.getAttribute('default-value')));\n this.dataset.upgraded = '';\n const upgradedClasses = classesOf(this.getAttribute('upgraded-class'));\n if (upgradedClasses.length) this.classList.add(...upgradedClasses);\n this.own('[data-accordion-controls]').forEach((controls) => {\n controls.hidden = false;\n });\n sections.forEach((section) => this.prepare(section));\n this.listen();\n this.render();\n }\n\n private listen() {\n this.addEventListener('click', this.onClick);\n // `beforematch` doesn't bubble.\n this.addEventListener('beforematch', this.onBeforeMatch, true);\n }\n\n /** Swaps a section's fallback for its trigger, once, and sets its first state. */\n private prepare(section: HTMLElement) {\n const trigger = this.find(section, 'button[data-accordion-trigger]');\n if (!trigger || this.prepared.has(section)) return;\n this.prepared.add(section);\n const value = section.dataset.value ?? '';\n if (!this.controlled) {\n const defaultValue = valuesOf(this.getAttribute('default-value'));\n if (defaultValue ? defaultValue.includes(value) : section.hasAttribute('data-expanded')) this.open.add(value);\n this.restore(section);\n }\n Array.from(section.querySelectorAll<HTMLElement>('[data-accordion-fallback]'))\n .filter((fallback) => this.sectionOf(fallback) === section)\n .forEach((fallback) => {\n fallback.hidden = true;\n });\n trigger.hidden = false;\n const content = this.find(section, '[data-accordion-content]');\n if (content?.id) trigger.setAttribute('aria-controls', content.id);\n }\n\n /** A section remembered from earlier in the session, as in govuk-frontend. */\n private restore(section: HTMLElement) {\n const id = this.find(section, '[data-accordion-content]')?.id;\n const value = section.dataset.value;\n if (!this.remember || !id || value === undefined) return;\n try {\n const state = window.sessionStorage.getItem(id);\n if (state === 'true') this.open.add(value);\n else if (state === 'false') this.open.delete(value);\n } catch {\n // Storage can be unavailable.\n }\n }\n\n /** Remembers the sections that changed, as govuk-frontend does. */\n private store(previous: Set<string>) {\n if (!this.remember) return;\n this.sections.forEach((section) => {\n const value = section.dataset.value ?? '';\n const id = this.find(section, '[data-accordion-content]')?.id;\n if (!id || previous.has(value) === this.open.has(value)) return;\n try {\n window.sessionStorage.setItem(id, String(this.open.has(value)));\n } catch {\n // Storage can be unavailable.\n }\n });\n }\n\n private change(next: Set<string>, force = false) {\n const value = this.sections.map((section) => section.dataset.value ?? '').filter((v) => next.has(v));\n // Find in page must show the match, so it opens the section even when controlled.\n if (!this.controlled || force) {\n const previous = this.open;\n this.open = new Set(value);\n if (!this.controlled) {\n this.picked = value;\n this.store(previous);\n }\n this.render();\n }\n this.dispatchEvent(new CustomEvent('govuk-react-accordion:change', { detail: { value }, bubbles: true }));\n }\n\n private render() {\n if (!this.upgraded) return;\n const expandedClasses = classesOf(this.getAttribute('expanded-section-class'));\n const collapsedIconClasses = classesOf(this.getAttribute('collapsed-icon-class'));\n const setIcon = (root: HTMLElement, expanded: boolean) => {\n Array.from(root.querySelectorAll<HTMLElement>('[data-accordion-icon]')).forEach((icon) => {\n collapsedIconClasses.forEach((name) => icon.classList.toggle(name, !expanded));\n });\n };\n this.sections.forEach((section) => {\n const expanded = this.open.has(section.dataset.value ?? '');\n const trigger = this.find(section, 'button[data-accordion-trigger]');\n const content = this.find(section, '[data-accordion-content]');\n section.dataset.state = expanded ? 'open' : 'closed';\n expandedClasses.forEach((name) => section.classList.toggle(name, expanded));\n if (content) {\n if (expanded) content.removeAttribute('hidden');\n else content.setAttribute('hidden', 'until-found');\n }\n if (!trigger) return;\n trigger.setAttribute('aria-expanded', String(expanded));\n const labels = Array.from(trigger.querySelectorAll('[data-accordion-label]')).map(\n (label) => label.textContent?.trim() ?? ''\n );\n trigger.setAttribute(\n 'aria-label',\n [...labels, this.text(expanded ? 'hide-section-label' : 'show-section-label')].join(' , ')\n );\n const toggleText = trigger.querySelector('[data-accordion-toggle-text]');\n if (toggleText) setText(toggleText, this.text(expanded ? 'hide-section-text' : 'show-section-text'));\n setIcon(trigger, expanded);\n });\n const allOpen = this.allOpen;\n this.own('button[data-accordion-show-all]').forEach((showAll) => {\n showAll.setAttribute('aria-expanded', String(allOpen));\n const text = showAll.querySelector('[data-accordion-show-all-text]');\n if (text) setText(text, this.text(allOpen ? 'hide-all-sections-text' : 'show-all-sections-text'));\n setIcon(showAll, allOpen);\n });\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactAccordion);\n}\n"],"mappings":";;;AA2CO,IAAM,UAAU;AASvB,IAAM,WAAW;AAAA,EACf,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EACrB,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,0BAA0B;AAAA,EAC1B,0BAA0B;AAC5B;AAEA,IAAM,WAAW,CAAC,cAA6B,uCAAW,MAAM,OAAO,OAAO;AAG9E,IAAM,UAAU,CAAC,SAAkB,SAAiB;AAClD,MAAI,QAAQ,gBAA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E,YAAI,WAAY,SAAQ,YAAY,KAAK,KAAK,WAAW,sBAAsB,mBAAmB,CAAC;AACnG,gBAAQ,SAAS,QAAQ;AAAA,MAC3B,CAAC;AACD,YAAM,UAAU,KAAK;AACrB,WAAK,IAAI,iCAAiC,EAAE,QAAQ,CAAC,YAAY;AAC/D,gBAAQ,aAAa,iBAAiB,OAAO,OAAO,CAAC;AACrD,cAAM,OAAO,QAAQ,cAAc,gCAAgC;AACnE,YAAI,KAAM,SAAQ,MAAM,KAAK,KAAK,UAAU,2BAA2B,wBAAwB,CAAC;AAChG,gBAAQ,SAAS,OAAO;AAAA,MAC1B,CAAC;AAAA,IACH;AAAA,EACF;AAEA,MAAI,CAAC,eAAe,IAAI,OAAO,EAAG,gBAAe,OAAO,SAAS,mBAAmB;AACtF;","names":["_a"]}
|
package/dist/chunk-DPERPCUH.js
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import {
|
|
3
|
-
tagName
|
|
4
|
-
} from "./chunk-B2I4J5NL.js";
|
|
5
|
-
import {
|
|
6
|
-
Slot
|
|
7
|
-
} from "./chunk-NX4B3NKM.js";
|
|
8
|
-
import {
|
|
9
|
-
__export
|
|
10
|
-
} from "./chunk-ESBMTI25.js";
|
|
11
|
-
|
|
12
|
-
// src/accordion/index.tsx
|
|
13
|
-
var accordion_exports = {};
|
|
14
|
-
__export(accordion_exports, {
|
|
15
|
-
Content: () => Content,
|
|
16
|
-
Controls: () => Controls,
|
|
17
|
-
Fallback: () => Fallback,
|
|
18
|
-
Icon: () => Icon,
|
|
19
|
-
Label: () => Label,
|
|
20
|
-
Root: () => Root,
|
|
21
|
-
Section: () => Section,
|
|
22
|
-
ShowAll: () => ShowAll,
|
|
23
|
-
ShowAllText: () => ShowAllText,
|
|
24
|
-
ToggleText: () => ToggleText,
|
|
25
|
-
Trigger: () => Trigger,
|
|
26
|
-
accordionCss: () => accordionCss
|
|
27
|
-
});
|
|
28
|
-
import * as React from "react";
|
|
29
|
-
import { createContext, useContext, useEffect, useRef } from "react";
|
|
30
|
-
var AccordionContext = createContext({ texts: {} });
|
|
31
|
-
var SectionContext = createContext({});
|
|
32
|
-
var accordionCss = `${tagName} :is([data-accordion-fallback],[data-accordion-trigger],[data-accordion-controls])[hidden]{display:none!important}`;
|
|
33
|
-
var isAccordion = (element) => "pickedValue" in element;
|
|
34
|
-
function Root({
|
|
35
|
-
value,
|
|
36
|
-
defaultValue,
|
|
37
|
-
onValueChange,
|
|
38
|
-
rememberExpanded,
|
|
39
|
-
showSectionText,
|
|
40
|
-
hideSectionText,
|
|
41
|
-
showSectionLabel,
|
|
42
|
-
hideSectionLabel,
|
|
43
|
-
showAllSectionsText,
|
|
44
|
-
hideAllSectionsText,
|
|
45
|
-
upgradedClass,
|
|
46
|
-
expandedSectionClass,
|
|
47
|
-
collapsedIconClass,
|
|
48
|
-
children,
|
|
49
|
-
...props
|
|
50
|
-
}) {
|
|
51
|
-
const element = useRef(null);
|
|
52
|
-
const onValueChangeRef = useRef(onValueChange);
|
|
53
|
-
const synced = useRef(false);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
onValueChangeRef.current = onValueChange;
|
|
56
|
-
});
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
const node = element.current;
|
|
59
|
-
if (!node) return void 0;
|
|
60
|
-
const onChange = (event) => {
|
|
61
|
-
var _a;
|
|
62
|
-
if (event.target === node) (_a = onValueChangeRef.current) == null ? void 0 : _a.call(onValueChangeRef, event.detail.value);
|
|
63
|
-
};
|
|
64
|
-
node.addEventListener("govuk-react-accordion:change", onChange);
|
|
65
|
-
return () => node.removeEventListener("govuk-react-accordion:change", onChange);
|
|
66
|
-
}, []);
|
|
67
|
-
const controlled = value == null ? void 0 : value.join(" ");
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
const node = element.current;
|
|
70
|
-
if (!node || controlled === void 0) {
|
|
71
|
-
node == null ? void 0 : node.removeAttribute("value");
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (!synced.current) {
|
|
75
|
-
synced.current = true;
|
|
76
|
-
const picked = isAccordion(node) ? node.pickedValue : void 0;
|
|
77
|
-
if (picked !== void 0 && picked.join(" ") !== controlled && onValueChangeRef.current) {
|
|
78
|
-
onValueChangeRef.current(picked);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
node.setAttribute("value", controlled);
|
|
83
|
-
});
|
|
84
|
-
const initial = value != null ? value : defaultValue;
|
|
85
|
-
return /* @__PURE__ */ React.createElement(
|
|
86
|
-
AccordionContext.Provider,
|
|
87
|
-
{
|
|
88
|
-
value: { open: initial, texts: { showSectionText, hideSectionText, showAllSectionsText, hideAllSectionsText } }
|
|
89
|
-
},
|
|
90
|
-
/* @__PURE__ */ React.createElement("style", { href: `${tagName}-css`, precedence: "default" }, accordionCss),
|
|
91
|
-
React.createElement(
|
|
92
|
-
tagName,
|
|
93
|
-
{
|
|
94
|
-
...props,
|
|
95
|
-
ref: element,
|
|
96
|
-
"default-value": initial == null ? void 0 : initial.join(" "),
|
|
97
|
-
"remember-expanded": rememberExpanded === void 0 ? void 0 : String(rememberExpanded),
|
|
98
|
-
"show-section-text": showSectionText,
|
|
99
|
-
"hide-section-text": hideSectionText,
|
|
100
|
-
"show-section-label": showSectionLabel,
|
|
101
|
-
"hide-section-label": hideSectionLabel,
|
|
102
|
-
"show-all-sections-text": showAllSectionsText,
|
|
103
|
-
"hide-all-sections-text": hideAllSectionsText,
|
|
104
|
-
"upgraded-class": upgradedClass,
|
|
105
|
-
"expanded-section-class": expandedSectionClass,
|
|
106
|
-
"collapsed-icon-class": collapsedIconClass,
|
|
107
|
-
// The element adds attributes on upgrade, so they can differ from the server's.
|
|
108
|
-
suppressHydrationWarning: true
|
|
109
|
-
},
|
|
110
|
-
children
|
|
111
|
-
)
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
function Controls({ asChild, ...props }) {
|
|
115
|
-
const Element = asChild ? Slot : "div";
|
|
116
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-accordion-controls": "", hidden: true, suppressHydrationWarning: true, ...props });
|
|
117
|
-
}
|
|
118
|
-
function ShowAll({ asChild, ...props }) {
|
|
119
|
-
if (asChild) return /* @__PURE__ */ React.createElement(Slot, { "data-accordion-show-all": "", suppressHydrationWarning: true, ...props });
|
|
120
|
-
return /* @__PURE__ */ React.createElement("button", { type: "button", "data-accordion-show-all": "", suppressHydrationWarning: true, ...props });
|
|
121
|
-
}
|
|
122
|
-
function ShowAllText({ asChild, children, ...props }) {
|
|
123
|
-
var _a;
|
|
124
|
-
const { texts } = useContext(AccordionContext);
|
|
125
|
-
const Element = asChild ? Slot : "span";
|
|
126
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-accordion-show-all-text": "", suppressHydrationWarning: true, ...props }, (_a = children != null ? children : texts.showAllSectionsText) != null ? _a : "Show all sections");
|
|
127
|
-
}
|
|
128
|
-
function Section({ asChild, value, defaultExpanded, ...props }) {
|
|
129
|
-
var _a, _b;
|
|
130
|
-
const context = useContext(AccordionContext);
|
|
131
|
-
const expanded = (_b = defaultExpanded != null ? defaultExpanded : (_a = context.open) == null ? void 0 : _a.includes(value)) != null ? _b : false;
|
|
132
|
-
const Element = asChild ? Slot : "div";
|
|
133
|
-
return /* @__PURE__ */ React.createElement(SectionContext.Provider, { value: { expanded } }, /* @__PURE__ */ React.createElement(
|
|
134
|
-
Element,
|
|
135
|
-
{
|
|
136
|
-
"data-accordion-section": "",
|
|
137
|
-
"data-value": value,
|
|
138
|
-
"data-expanded": expanded ? "" : void 0,
|
|
139
|
-
suppressHydrationWarning: true,
|
|
140
|
-
...props
|
|
141
|
-
}
|
|
142
|
-
));
|
|
143
|
-
}
|
|
144
|
-
function Fallback({ asChild, ...props }) {
|
|
145
|
-
const Element = asChild ? Slot : "span";
|
|
146
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-accordion-fallback": "", suppressHydrationWarning: true, ...props });
|
|
147
|
-
}
|
|
148
|
-
function Trigger({ asChild, ...props }) {
|
|
149
|
-
const shared = { "data-accordion-trigger": "", hidden: true, suppressHydrationWarning: true };
|
|
150
|
-
if (asChild) return /* @__PURE__ */ React.createElement(Slot, { ...shared, ...props });
|
|
151
|
-
return /* @__PURE__ */ React.createElement("button", { type: "button", ...shared, ...props });
|
|
152
|
-
}
|
|
153
|
-
function Label({ asChild, ...props }) {
|
|
154
|
-
const Element = asChild ? Slot : "span";
|
|
155
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-accordion-label": "", ...props });
|
|
156
|
-
}
|
|
157
|
-
function ToggleText({ asChild, children, ...props }) {
|
|
158
|
-
var _a, _b;
|
|
159
|
-
const { texts } = useContext(AccordionContext);
|
|
160
|
-
const { expanded } = useContext(SectionContext);
|
|
161
|
-
const Element = asChild ? Slot : "span";
|
|
162
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-accordion-toggle-text": "", suppressHydrationWarning: true, ...props }, children != null ? children : expanded ? (_a = texts.hideSectionText) != null ? _a : "Hide" : (_b = texts.showSectionText) != null ? _b : "Show");
|
|
163
|
-
}
|
|
164
|
-
function Icon({ asChild, ...props }) {
|
|
165
|
-
const Element = asChild ? Slot : "span";
|
|
166
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-accordion-icon": "", suppressHydrationWarning: true, ...props });
|
|
167
|
-
}
|
|
168
|
-
function Content({ asChild, ...props }) {
|
|
169
|
-
const Element = asChild ? Slot : "div";
|
|
170
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-accordion-content": "", suppressHydrationWarning: true, ...props });
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export {
|
|
174
|
-
accordionCss,
|
|
175
|
-
Root,
|
|
176
|
-
Controls,
|
|
177
|
-
ShowAll,
|
|
178
|
-
ShowAllText,
|
|
179
|
-
Section,
|
|
180
|
-
Fallback,
|
|
181
|
-
Trigger,
|
|
182
|
-
Label,
|
|
183
|
-
ToggleText,
|
|
184
|
-
Icon,
|
|
185
|
-
Content,
|
|
186
|
-
accordion_exports
|
|
187
|
-
};
|
|
188
|
-
//# sourceMappingURL=chunk-DPERPCUH.js.map
|