@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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/accordion/index.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createContext, useContext, useEffect, useRef } from 'react';\nimport type { ComponentProps } from 'react';\nimport { Slot } from '../utils/slot';\nimport { tagName, type AccordionElement } from './element';\n\n/*\n * Headless accordion: unstyled parts over the <govuk-react-accordion> element (./element.ts).\n * Every part except Root takes `asChild`.\n *\n * Without JavaScript every section is shown under its `Fallback` heading. Each section also\n * holds a hidden `Trigger` with the same heading, which the element shows on upgrade. Put the\n * heading text in a `Label` inside the trigger, so the element can name the button.\n *\n * Context only fills in defaults: in an island without a Root, pass `defaultExpanded` to Section.\n */\n\ntype Texts = {\n showSectionText?: string;\n hideSectionText?: string;\n showAllSectionsText?: string;\n hideAllSectionsText?: string;\n};\n\nconst AccordionContext = createContext<{ open?: string[]; texts: Texts }>({ texts: {} });\n\nconst SectionContext = createContext<{ expanded?: boolean }>({});\n\n/**\n * Hides the parts the element hides, over styles that set their `display`. Root renders it\n * inline; under a strict CSP, add it to a stylesheet instead.\n */\nexport const accordionCss = `${tagName} :is([data-accordion-fallback],[data-accordion-trigger],[data-accordion-controls])[hidden]{display:none!important}`;\n\nconst isAccordion = (element: HTMLElement): element is AccordionElement => 'pickedValue' in element;\n\nexport type RootProps = Omit<React.HTMLAttributes<HTMLElement>, 'defaultValue' | 'onChange'> & {\n /** The open sections' values, to control them once hydrated. */\n value?: string[];\n /** The sections open at first. */\n defaultValue?: string[];\n /** Called with the open sections' values when the user opens or closes a section. */\n onValueChange?: (value: string[]) => void;\n /** Whether to remember the open sections for the rest of the session, keyed by content id. Defaults to `true`, as in govuk-frontend. */\n rememberExpanded?: boolean;\n /** Each button's text while its section is closed. Defaults to \"Show\". */\n showSectionText?: string;\n /** Each button's text while its section is open. Defaults to \"Hide\". */\n hideSectionText?: string;\n /** The end of each button's accessible name while its section is closed. Defaults to \"Show this section\". */\n showSectionLabel?: string;\n /** The end of each button's accessible name while its section is open. Defaults to \"Hide this section\". */\n hideSectionLabel?: string;\n /** The \"show all\" button's text while a section is closed. Defaults to \"Show all sections\". */\n showAllSectionsText?: string;\n /** The \"show all\" button's text while every section is open. Defaults to \"Hide all sections\". */\n hideAllSectionsText?: string;\n /** Classes added to the element when it upgrades. */\n upgradedClass?: string;\n /** Classes added to open sections. */\n expandedSectionClass?: string;\n /** Classes added to the icons of closed sections, and the \"show all\" icon while a section is closed. */\n collapsedIconClass?: string;\n};\n\nexport function Root({\n value,\n defaultValue,\n onValueChange,\n rememberExpanded,\n showSectionText,\n hideSectionText,\n showSectionLabel,\n hideSectionLabel,\n showAllSectionsText,\n hideAllSectionsText,\n upgradedClass,\n expandedSectionClass,\n collapsedIconClass,\n children,\n ...props\n}: RootProps) {\n const element = useRef<HTMLElement>(null);\n const onValueChangeRef = useRef(onValueChange);\n const synced = useRef(false);\n\n useEffect(() => {\n onValueChangeRef.current = onValueChange;\n });\n\n useEffect(() => {\n const node = element.current;\n if (!node) return undefined;\n // A nested accordion's change bubbles through this one.\n const onChange = (event: CustomEvent<{ value: string[] }>) => {\n if (event.target === node) onValueChangeRef.current?.(event.detail.value);\n };\n node.addEventListener('govuk-react-accordion:change', onChange);\n return () => node.removeEventListener('govuk-react-accordion:change', onChange);\n }, []);\n\n // `value` is set once hydrated, so the server markup is uncontrolled and a click before\n // hydration still works. That click is then reported, rather than undone.\n const controlled = value?.join(' ');\n useEffect(() => {\n const node = element.current;\n if (!node || controlled === undefined) {\n node?.removeAttribute('value');\n return;\n }\n if (!synced.current) {\n synced.current = true;\n const picked = isAccordion(node) ? node.pickedValue : undefined;\n if (picked !== undefined && picked.join(' ') !== controlled && onValueChangeRef.current) {\n onValueChangeRef.current(picked);\n return;\n }\n }\n node.setAttribute('value', controlled);\n });\n\n const initial = value ?? defaultValue;\n return (\n <AccordionContext.Provider\n value={{ open: initial, texts: { showSectionText, hideSectionText, showAllSectionsText, hideAllSectionsText } }}\n >\n <style href={`${tagName}-css`} precedence=\"default\">\n {accordionCss}\n </style>\n {React.createElement(\n tagName,\n {\n ...props,\n ref: element,\n 'default-value': initial?.join(' '),\n 'remember-expanded': rememberExpanded === undefined ? undefined : String(rememberExpanded),\n 'show-section-text': showSectionText,\n 'hide-section-text': hideSectionText,\n 'show-section-label': showSectionLabel,\n 'hide-section-label': hideSectionLabel,\n 'show-all-sections-text': showAllSectionsText,\n 'hide-all-sections-text': hideAllSectionsText,\n 'upgraded-class': upgradedClass,\n 'expanded-section-class': expandedSectionClass,\n 'collapsed-icon-class': collapsedIconClass,\n // The element adds attributes on upgrade, so they can differ from the server's.\n suppressHydrationWarning: true,\n },\n children\n )}\n </AccordionContext.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 ControlsProps = PartProps<'div'>;\n\n/** Holds the \"show all\" button. Hidden until the element upgrades. */\nexport function Controls({ asChild, ...props }: ControlsProps) {\n const Element = asChild ? Slot : 'div';\n return <Element data-accordion-controls=\"\" hidden suppressHydrationWarning {...props} />;\n}\n\nexport type ShowAllProps = PartProps<'button'>;\n\n/** Shows every section, or hides every section when all are open. */\nexport function ShowAll({ asChild, ...props }: ShowAllProps) {\n if (asChild) return <Slot data-accordion-show-all=\"\" suppressHydrationWarning {...props} />;\n return <button type=\"button\" data-accordion-show-all=\"\" suppressHydrationWarning {...props} />;\n}\n\nexport type ShowAllTextProps = PartProps<'span'>;\n\n/** The \"show all\" button's text, which the element sets. */\nexport function ShowAllText({ asChild, children, ...props }: ShowAllTextProps) {\n const { texts } = useContext(AccordionContext);\n const Element = asChild ? Slot : 'span';\n // Rendered as the server would, so the element's text replaces it rather than adding to it.\n return (\n <Element data-accordion-show-all-text=\"\" suppressHydrationWarning {...props}>\n {children ?? texts.showAllSectionsText ?? 'Show all sections'}\n </Element>\n );\n}\n\nexport type SectionProps = PartProps<'div'> & {\n value: string;\n /** Whether it's open at first. Defaults to whether Root's value includes it. */\n defaultExpanded?: boolean;\n};\n\nexport function Section({ asChild, value, defaultExpanded, ...props }: SectionProps) {\n const context = useContext(AccordionContext);\n const expanded = defaultExpanded ?? context.open?.includes(value) ?? false;\n const Element = asChild ? Slot : 'div';\n return (\n <SectionContext.Provider value={{ expanded }}>\n <Element\n data-accordion-section=\"\"\n data-value={value}\n data-expanded={expanded ? '' : undefined}\n suppressHydrationWarning\n {...props}\n />\n </SectionContext.Provider>\n );\n}\n\nexport type FallbackProps = PartProps<'span'>;\n\n/** What shows without JavaScript in place of the trigger, such as the plain heading. Hidden on upgrade. */\nexport function Fallback({ asChild, ...props }: FallbackProps) {\n const Element = asChild ? Slot : 'span';\n return <Element data-accordion-fallback=\"\" suppressHydrationWarning {...props} />;\n}\n\nexport type TriggerProps = PartProps<'button'>;\n\n/** The button that shows and hides its section. Hidden until the element upgrades. */\nexport function Trigger({ asChild, ...props }: TriggerProps) {\n const shared = { 'data-accordion-trigger': '', hidden: true, suppressHydrationWarning: true };\n if (asChild) return <Slot {...shared} {...props} />;\n return <button type=\"button\" {...shared} {...props} />;\n}\n\nexport type LabelProps = PartProps<'span'>;\n\n/** Text in the trigger that names it, such as the heading or summary. */\nexport function Label({ asChild, ...props }: LabelProps) {\n const Element = asChild ? Slot : 'span';\n return <Element data-accordion-label=\"\" {...props} />;\n}\n\nexport type ToggleTextProps = PartProps<'span'>;\n\n/** The trigger's show or hide text, which the element sets. */\nexport function ToggleText({ asChild, children, ...props }: ToggleTextProps) {\n const { texts } = useContext(AccordionContext);\n const { expanded } = useContext(SectionContext);\n const Element = asChild ? Slot : 'span';\n // Rendered as the server would, so the element's text replaces it rather than adding to it.\n return (\n <Element data-accordion-toggle-text=\"\" suppressHydrationWarning {...props}>\n {children ?? (expanded ? (texts.hideSectionText ?? 'Hide') : (texts.showSectionText ?? 'Show'))}\n </Element>\n );\n}\n\nexport type IconProps = PartProps<'span'>;\n\n/** An icon in a trigger or the \"show all\" button, given `collapsedIconClass` while closed. */\nexport function Icon({ asChild, ...props }: IconProps) {\n const Element = asChild ? Slot : 'span';\n return <Element data-accordion-icon=\"\" suppressHydrationWarning {...props} />;\n}\n\nexport type ContentProps = PartProps<'div'>;\n\n/** The section's content. Give it an id, which the trigger's `aria-controls` names. */\nexport function Content({ asChild, ...props }: ContentProps) {\n const Element = asChild ? Slot : 'div';\n // The element hides it after upgrade.\n return <Element data-accordion-content=\"\" suppressHydrationWarning {...props} />;\n}\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAY,WAAW;AACvB,SAAS,eAAe,YAAY,WAAW,cAAc;AAuB7D,IAAM,mBAAmB,cAAiD,EAAE,OAAO,CAAC,EAAE,CAAC;AAEvF,IAAM,iBAAiB,cAAsC,CAAC,CAAC;AAMxD,IAAM,eAAe,GAAG,OAAO;AAEtC,IAAM,cAAc,CAAC,YAAsD,iBAAiB;AA+BrF,SAAS,KAAK;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAc;AACZ,QAAM,UAAU,OAAoB,IAAI;AACxC,QAAM,mBAAmB,OAAO,aAAa;AAC7C,QAAM,SAAS,OAAO,KAAK;AAE3B,YAAU,MAAM;AACd,qBAAiB,UAAU;AAAA,EAC7B,CAAC;AAED,YAAU,MAAM;AACd,UAAM,OAAO,QAAQ;AACrB,QAAI,CAAC,KAAM,QAAO;AAElB,UAAM,WAAW,CAAC,UAA4C;AAhGlE;AAiGM,UAAI,MAAM,WAAW,KAAM,wBAA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,GAAG,MAAM,GAAiB;AAC3D,QAAM,SAAS,EAAE,0BAA0B,IAAI,QAAQ,MAAM,0BAA0B,KAAK;AAC5F,MAAI,QAAS,QAAO,oCAAC,QAAM,GAAG,QAAS,GAAG,OAAO;AACjD,SAAO,oCAAC,YAAO,MAAK,UAAU,GAAG,QAAS,GAAG,OAAO;AACtD;AAKO,SAAS,MAAM,EAAE,SAAS,GAAG,MAAM,GAAe;AACvD,QAAM,UAAU,UAAU,OAAO;AACjC,SAAO,oCAAC,WAAQ,wBAAqB,IAAI,GAAG,OAAO;AACrD;AAKO,SAAS,WAAW,EAAE,SAAS,UAAU,GAAG,MAAM,GAAoB;AAlP7E;AAmPE,QAAM,EAAE,MAAM,IAAI,WAAW,gBAAgB;AAC7C,QAAM,EAAE,SAAS,IAAI,WAAW,cAAc;AAC9C,QAAM,UAAU,UAAU,OAAO;AAEjC,SACE,oCAAC,WAAQ,8BAA2B,IAAG,0BAAwB,MAAE,GAAG,SACjE,8BAAa,YAAY,WAAM,oBAAN,YAAyB,UAAW,WAAM,oBAAN,YAAyB,MACzF;AAEJ;AAKO,SAAS,KAAK,EAAE,SAAS,GAAG,MAAM,GAAc;AACrD,QAAM,UAAU,UAAU,OAAO;AACjC,SAAO,oCAAC,WAAQ,uBAAoB,IAAG,0BAAwB,MAAE,GAAG,OAAO;AAC7E;AAKO,SAAS,QAAQ,EAAE,SAAS,GAAG,MAAM,GAAiB;AAC3D,QAAM,UAAU,UAAU,OAAO;AAEjC,SAAO,oCAAC,WAAQ,0BAAuB,IAAG,0BAAwB,MAAE,GAAG,OAAO;AAChF;","names":[]}
|
package/dist/chunk-ECYGKE4D.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
// src/exit-this-page/element.ts
|
|
4
|
-
var tagName = "govuk-react-exit-this-page";
|
|
5
|
-
var messageNames = ["activated", "timed-out", "press-two-more-times", "press-one-more-time"];
|
|
6
|
-
var defaultMessages = {
|
|
7
|
-
activated: "Loading.",
|
|
8
|
-
"timed-out": "Exit this page expired.",
|
|
9
|
-
"press-two-more-times": "Shift, press 2 more times to exit.",
|
|
10
|
-
"press-one-more-time": "Shift, press 1 more time to exit."
|
|
11
|
-
};
|
|
12
|
-
var timeoutMs = 5e3;
|
|
13
|
-
var classesOf = (value) => (value != null ? value : "").split(/\s+/).filter(Boolean);
|
|
14
|
-
var overlayStyles = {
|
|
15
|
-
position: "fixed",
|
|
16
|
-
inset: "0",
|
|
17
|
-
"z-index": "2147483647",
|
|
18
|
-
background: "white"
|
|
19
|
-
};
|
|
20
|
-
if (typeof HTMLElement !== "undefined" && typeof customElements !== "undefined") {
|
|
21
|
-
class GovukReactExitThisPage extends HTMLElement {
|
|
22
|
-
constructor() {
|
|
23
|
-
super(...arguments);
|
|
24
|
-
this.presses = 0;
|
|
25
|
-
this.lastKeyWasModified = false;
|
|
26
|
-
this.onClick = (event) => {
|
|
27
|
-
if (event.defaultPrevented || event.button !== 0) return;
|
|
28
|
-
const link = event.target instanceof Element ? event.target.closest("a") : null;
|
|
29
|
-
if (!link) return;
|
|
30
|
-
const own = link.matches("[data-exit-this-page-button]") && link.closest(tagName) === this;
|
|
31
|
-
const skipLink = link.matches("[data-exit-this-page-skiplink]") && this.listening;
|
|
32
|
-
if (!own && !skipLink) return;
|
|
33
|
-
event.preventDefault();
|
|
34
|
-
this.exit();
|
|
35
|
-
};
|
|
36
|
-
this.onKeyup = (event) => {
|
|
37
|
-
if (!this.listening) return;
|
|
38
|
-
if (event.key === "Shift" && !this.lastKeyWasModified) {
|
|
39
|
-
this.presses += 1;
|
|
40
|
-
this.updateIndicator();
|
|
41
|
-
window.clearTimeout(this.messageTimeout);
|
|
42
|
-
if (this.presses >= 3) {
|
|
43
|
-
this.presses = 0;
|
|
44
|
-
window.clearTimeout(this.pressTimeout);
|
|
45
|
-
this.pressTimeout = void 0;
|
|
46
|
-
this.exit();
|
|
47
|
-
} else {
|
|
48
|
-
this.setStatus(this.message(this.presses === 1 ? "press-two-more-times" : "press-one-more-time"));
|
|
49
|
-
window.clearTimeout(this.pressTimeout);
|
|
50
|
-
this.pressTimeout = window.setTimeout(this.timeOut, timeoutMs);
|
|
51
|
-
}
|
|
52
|
-
} else if (this.pressTimeout !== void 0) {
|
|
53
|
-
this.timeOut();
|
|
54
|
-
}
|
|
55
|
-
this.lastKeyWasModified = event.shiftKey;
|
|
56
|
-
};
|
|
57
|
-
this.timeOut = () => {
|
|
58
|
-
window.clearTimeout(this.pressTimeout);
|
|
59
|
-
this.pressTimeout = void 0;
|
|
60
|
-
this.presses = 0;
|
|
61
|
-
this.setStatus(this.message("timed-out"));
|
|
62
|
-
this.messageTimeout = window.setTimeout(() => this.setStatus(""), timeoutMs);
|
|
63
|
-
this.updateIndicator();
|
|
64
|
-
};
|
|
65
|
-
/** Shows the page again when the browser brings it back from its cache. */
|
|
66
|
-
this.reset = (event) => {
|
|
67
|
-
var _a;
|
|
68
|
-
if (!event.persisted) return;
|
|
69
|
-
classesOf(this.getAttribute("hide-content-class")).forEach((name) => document.body.classList.remove(name));
|
|
70
|
-
(_a = this.overlay) == null ? void 0 : _a.remove();
|
|
71
|
-
this.overlay = void 0;
|
|
72
|
-
this.presses = 0;
|
|
73
|
-
this.setStatus("");
|
|
74
|
-
this.updateIndicator();
|
|
75
|
-
this.clearTimers();
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
connectedCallback() {
|
|
79
|
-
this.dataset.upgraded = "";
|
|
80
|
-
document.addEventListener("keyup", this.onKeyup, true);
|
|
81
|
-
document.addEventListener("click", this.onClick);
|
|
82
|
-
window.addEventListener("pageshow", this.reset);
|
|
83
|
-
}
|
|
84
|
-
disconnectedCallback() {
|
|
85
|
-
document.removeEventListener("keyup", this.onKeyup, true);
|
|
86
|
-
document.removeEventListener("click", this.onClick);
|
|
87
|
-
window.removeEventListener("pageshow", this.reset);
|
|
88
|
-
this.clearTimers();
|
|
89
|
-
this.presses = 0;
|
|
90
|
-
this.setStatus("");
|
|
91
|
-
this.updateIndicator();
|
|
92
|
-
}
|
|
93
|
-
exit() {
|
|
94
|
-
var _a;
|
|
95
|
-
const button = this.own("[data-exit-this-page-button]");
|
|
96
|
-
const href = button instanceof HTMLAnchorElement ? button.href : void 0;
|
|
97
|
-
const proceed = href !== void 0 && this.dispatchEvent(
|
|
98
|
-
new CustomEvent("govuk-react-exit-this-page:exit", { detail: { href }, bubbles: true, cancelable: true })
|
|
99
|
-
);
|
|
100
|
-
if (!href || !proceed) {
|
|
101
|
-
this.setStatus("");
|
|
102
|
-
this.updateIndicator();
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
this.setStatus("");
|
|
106
|
-
classesOf(this.getAttribute("hide-content-class")).forEach((name) => document.body.classList.add(name));
|
|
107
|
-
(_a = this.overlay) == null ? void 0 : _a.remove();
|
|
108
|
-
const overlay = document.createElement("div");
|
|
109
|
-
overlay.setAttribute("role", "alert");
|
|
110
|
-
const overlayClasses = classesOf(this.getAttribute("overlay-class"));
|
|
111
|
-
if (overlayClasses.length) overlay.classList.add(...overlayClasses);
|
|
112
|
-
else Object.entries(overlayStyles).forEach(([name, value]) => overlay.style.setProperty(name, value));
|
|
113
|
-
document.body.appendChild(overlay);
|
|
114
|
-
overlay.textContent = this.message("activated");
|
|
115
|
-
this.overlay = overlay;
|
|
116
|
-
window.location.href = href;
|
|
117
|
-
}
|
|
118
|
-
/** Only the page's first element listens to the page, as govuk-frontend's first instance does. */
|
|
119
|
-
get listening() {
|
|
120
|
-
return document.querySelector(tagName) === this;
|
|
121
|
-
}
|
|
122
|
-
own(selector) {
|
|
123
|
-
return Array.from(this.querySelectorAll(selector)).find(
|
|
124
|
-
(element) => element.closest(tagName) === this
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
message(name) {
|
|
128
|
-
var _a;
|
|
129
|
-
return (_a = this.getAttribute(name)) != null ? _a : defaultMessages[name];
|
|
130
|
-
}
|
|
131
|
-
// Keeps the text node React rendered, if any, so React can still update it.
|
|
132
|
-
setStatus(text) {
|
|
133
|
-
const status = this.own("[data-exit-this-page-status]");
|
|
134
|
-
if (!status || status.textContent === text) return;
|
|
135
|
-
const { firstChild } = status;
|
|
136
|
-
if (firstChild instanceof Text && status.childNodes.length === 1) firstChild.nodeValue = text;
|
|
137
|
-
else status.textContent = text;
|
|
138
|
-
}
|
|
139
|
-
clearTimers() {
|
|
140
|
-
window.clearTimeout(this.pressTimeout);
|
|
141
|
-
window.clearTimeout(this.messageTimeout);
|
|
142
|
-
this.pressTimeout = void 0;
|
|
143
|
-
this.messageTimeout = void 0;
|
|
144
|
-
}
|
|
145
|
-
updateIndicator() {
|
|
146
|
-
const indicator = this.own("[data-exit-this-page-indicator]");
|
|
147
|
-
if (!indicator) return;
|
|
148
|
-
const visible = this.presses > 0;
|
|
149
|
-
indicator.toggleAttribute("data-visible", visible);
|
|
150
|
-
classesOf(this.getAttribute("indicator-visible-class")).forEach(
|
|
151
|
-
(name) => indicator.classList.toggle(name, visible)
|
|
152
|
-
);
|
|
153
|
-
indicator.querySelectorAll("[data-exit-this-page-light]").forEach((light, index) => {
|
|
154
|
-
const on = index < this.presses;
|
|
155
|
-
light.toggleAttribute("data-on", on);
|
|
156
|
-
classesOf(this.getAttribute("light-on-class")).forEach((name) => light.classList.toggle(name, on));
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (!customElements.get(tagName)) customElements.define(tagName, GovukReactExitThisPage);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export {
|
|
164
|
-
tagName,
|
|
165
|
-
messageNames,
|
|
166
|
-
defaultMessages
|
|
167
|
-
};
|
|
168
|
-
//# sourceMappingURL=chunk-ECYGKE4D.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/exit-this-page/element.ts"],"sourcesContent":["/*\n * <govuk-react-exit-this-page>: a headless, light-DOM custom element that lets users leave a page\n * quickly, with or without React, as govuk-frontend's exit this page does.\n *\n * Without JavaScript the button is a link to a safe page. On upgrade, the button, a skip link, or\n * pressing Shift 3 times within 5 seconds hides the page, shows an overlay that says it's loading,\n * and goes to the button's `href`. A status tells screen readers how many more presses are needed.\n *\n * Markup inside the element:\n * - `[data-exit-this-page-button]`: the link to the safe page.\n * - `[data-exit-this-page-indicator]`: shows how many times Shift has been pressed, with\n * `[data-exit-this-page-light]` children. It gets `data-visible` while counting, and each light\n * `data-on` once pressed.\n * - `[data-exit-this-page-status]`: an empty status for screen readers. Make it visually hidden.\n *\n * Anywhere on the page, a link with `data-exit-this-page-skiplink` exits too. Only the page's\n * first element listens for Shift and the skip link.\n *\n * Before leaving, the element fires a cancelable, bubbling `govuk-react-exit-this-page:exit`\n * event. Cancel it to stay on the page.\n *\n * Attributes:\n * - `activated`, `timed-out`, `press-two-more-times`, `press-one-more-time`: the messages,\n * English by default.\n * - `indicator-visible-class`, `light-on-class`: classes for the indicator and its lights.\n * - `hide-content-class`: classes for `body` that hide the page behind the overlay.\n * - `overlay-class`: classes for the overlay. Without them, the overlay covers the page with\n * inline styles.\n */\n\nexport const tagName = 'govuk-react-exit-this-page';\n\nexport const messageNames = ['activated', 'timed-out', 'press-two-more-times', 'press-one-more-time'] as const;\n\nexport type MessageName = (typeof messageNames)[number];\n\n/** govuk-frontend's English messages. */\nexport const defaultMessages: Record<MessageName, string> = {\n activated: 'Loading.',\n 'timed-out': 'Exit this page expired.',\n 'press-two-more-times': 'Shift, press 2 more times to exit.',\n 'press-one-more-time': 'Shift, press 1 more time to exit.',\n};\n\nexport interface ExitThisPageElement extends HTMLElement {\n /** Hides the page and goes to the button's `href`, unless the exit event is cancelled. */\n exit(): void;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'govuk-react-exit-this-page': ExitThisPageElement;\n }\n interface HTMLElementEventMap {\n 'govuk-react-exit-this-page:exit': CustomEvent<{ href: string }>;\n }\n}\n\nconst timeoutMs = 5000;\n\nconst classesOf = (value: string | null) => (value ?? '').split(/\\s+/).filter(Boolean);\n\nconst overlayStyles: Record<string, string> = {\n position: 'fixed',\n inset: '0',\n 'z-index': '2147483647',\n background: 'white',\n};\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactExitThisPage extends HTMLElement implements ExitThisPageElement {\n private presses = 0;\n private lastKeyWasModified = false;\n private pressTimeout?: number;\n private messageTimeout?: number;\n private overlay?: HTMLElement;\n\n connectedCallback() {\n this.dataset.upgraded = '';\n document.addEventListener('keyup', this.onKeyup, true);\n document.addEventListener('click', this.onClick);\n window.addEventListener('pageshow', this.reset);\n }\n\n disconnectedCallback() {\n document.removeEventListener('keyup', this.onKeyup, true);\n document.removeEventListener('click', this.onClick);\n window.removeEventListener('pageshow', this.reset);\n this.clearTimers();\n // Moved elements start counting again.\n this.presses = 0;\n this.setStatus('');\n this.updateIndicator();\n }\n\n exit() {\n const button = this.own('[data-exit-this-page-button]');\n const href = button instanceof HTMLAnchorElement ? button.href : undefined;\n const proceed =\n href !== undefined &&\n this.dispatchEvent(\n new CustomEvent('govuk-react-exit-this-page:exit', { detail: { href }, bubbles: true, cancelable: true })\n );\n if (!href || !proceed) {\n // Staying on the page: clear the presses.\n this.setStatus('');\n this.updateIndicator();\n return;\n }\n this.setStatus('');\n classesOf(this.getAttribute('hide-content-class')).forEach((name) => document.body.classList.add(name));\n this.overlay?.remove();\n const overlay = document.createElement('div');\n overlay.setAttribute('role', 'alert');\n const overlayClasses = classesOf(this.getAttribute('overlay-class'));\n if (overlayClasses.length) overlay.classList.add(...overlayClasses);\n else Object.entries(overlayStyles).forEach(([name, value]) => overlay.style.setProperty(name, value));\n document.body.appendChild(overlay);\n overlay.textContent = this.message('activated');\n this.overlay = overlay;\n window.location.href = href;\n }\n\n /** Only the page's first element listens to the page, as govuk-frontend's first instance does. */\n private get listening() {\n return document.querySelector(tagName) === this;\n }\n\n private own(selector: string) {\n return Array.from(this.querySelectorAll<HTMLElement>(selector)).find(\n (element) => element.closest(tagName) === this\n );\n }\n\n private message(name: MessageName) {\n return this.getAttribute(name) ?? defaultMessages[name];\n }\n\n // Keeps the text node React rendered, if any, so React can still update it.\n private setStatus(text: string) {\n const status = this.own('[data-exit-this-page-status]');\n if (!status || status.textContent === text) return;\n const { firstChild } = status;\n if (firstChild instanceof Text && status.childNodes.length === 1) firstChild.nodeValue = text;\n else status.textContent = text;\n }\n\n private readonly onClick = (event: MouseEvent) => {\n if (event.defaultPrevented || event.button !== 0) return;\n const link = event.target instanceof Element ? event.target.closest('a') : null;\n if (!link) return;\n const own = link.matches('[data-exit-this-page-button]') && link.closest(tagName) === this;\n const skipLink = link.matches('[data-exit-this-page-skiplink]') && this.listening;\n if (!own && !skipLink) return;\n event.preventDefault();\n this.exit();\n };\n\n private readonly onKeyup = (event: KeyboardEvent) => {\n if (!this.listening) return;\n if (event.key === 'Shift' && !this.lastKeyWasModified) {\n this.presses += 1;\n this.updateIndicator();\n window.clearTimeout(this.messageTimeout);\n if (this.presses >= 3) {\n this.presses = 0;\n window.clearTimeout(this.pressTimeout);\n this.pressTimeout = undefined;\n this.exit();\n } else {\n this.setStatus(this.message(this.presses === 1 ? 'press-two-more-times' : 'press-one-more-time'));\n window.clearTimeout(this.pressTimeout);\n this.pressTimeout = window.setTimeout(this.timeOut, timeoutMs);\n }\n } else if (this.pressTimeout !== undefined) {\n this.timeOut();\n }\n this.lastKeyWasModified = event.shiftKey;\n };\n\n private readonly timeOut = () => {\n window.clearTimeout(this.pressTimeout);\n this.pressTimeout = undefined;\n this.presses = 0;\n this.setStatus(this.message('timed-out'));\n this.messageTimeout = window.setTimeout(() => this.setStatus(''), timeoutMs);\n this.updateIndicator();\n };\n\n /** Shows the page again when the browser brings it back from its cache. */\n private readonly reset = (event: PageTransitionEvent) => {\n // `pageshow` fires on every load too, which mustn't lose presses made before it.\n if (!event.persisted) return;\n classesOf(this.getAttribute('hide-content-class')).forEach((name) => document.body.classList.remove(name));\n this.overlay?.remove();\n this.overlay = undefined;\n this.presses = 0;\n this.setStatus('');\n this.updateIndicator();\n this.clearTimers();\n };\n\n private clearTimers() {\n window.clearTimeout(this.pressTimeout);\n window.clearTimeout(this.messageTimeout);\n this.pressTimeout = undefined;\n this.messageTimeout = undefined;\n }\n\n private updateIndicator() {\n const indicator = this.own('[data-exit-this-page-indicator]');\n if (!indicator) return;\n const visible = this.presses > 0;\n indicator.toggleAttribute('data-visible', visible);\n classesOf(this.getAttribute('indicator-visible-class')).forEach((name) =>\n indicator.classList.toggle(name, visible)\n );\n indicator.querySelectorAll('[data-exit-this-page-light]').forEach((light, index) => {\n const on = index < this.presses;\n light.toggleAttribute('data-on', on);\n classesOf(this.getAttribute('light-on-class')).forEach((name) => light.classList.toggle(name, on));\n });\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactExitThisPage);\n}\n"],"mappings":";;;AA8BO,IAAM,UAAU;AAEhB,IAAM,eAAe,CAAC,aAAa,aAAa,wBAAwB,qBAAqB;AAK7F,IAAM,kBAA+C;AAAA,EAC1D,WAAW;AAAA,EACX,aAAa;AAAA,EACb,wBAAwB;AAAA,EACxB,uBAAuB;AACzB;AAgBA,IAAM,YAAY;AAElB,IAAM,YAAY,CAAC,WAA0B,wBAAS,IAAI,MAAM,KAAK,EAAE,OAAO,OAAO;AAErF,IAAM,gBAAwC;AAAA,EAC5C,UAAU;AAAA,EACV,OAAO;AAAA,EACP,WAAW;AAAA,EACX,YAAY;AACd;AAEA,IAAI,OAAO,gBAAgB,eAAe,OAAO,mBAAmB,aAAa;AAAA,EAC/E,MAAM,+BAA+B,YAA2C;AAAA,IAAhF;AAAA;AACE,WAAQ,UAAU;AAClB,WAAQ,qBAAqB;AA2E7B,WAAiB,UAAU,CAAC,UAAsB;AAChD,YAAI,MAAM,oBAAoB,MAAM,WAAW,EAAG;AAClD,cAAM,OAAO,MAAM,kBAAkB,UAAU,MAAM,OAAO,QAAQ,GAAG,IAAI;AAC3E,YAAI,CAAC,KAAM;AACX,cAAM,MAAM,KAAK,QAAQ,8B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AAO,UAAU;AAClF,cAAM,KAAK,QAAQ,KAAK;AACxB,cAAM,gBAAgB,WAAW,EAAE;AACnC,kBAAU,KAAK,aAAa,gBAAgB,CAAC,EAAE,QAAQ,CAAC,SAAS,MAAM,UAAU,OAAO,MAAM,EAAE,CAAC;AAAA,MACnG,CAAC;AAAA,IACH;AAAA,EACF;AAEA,MAAI,CAAC,eAAe,IAAI,OAAO,EAAG,gBAAe,OAAO,SAAS,sBAAsB;AACzF;","names":[]}
|
package/dist/chunk-ESBMTI25.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __export = (target, all) => {
|
|
4
|
-
for (var name in all)
|
|
5
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
__export
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=chunk-ESBMTI25.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/chunk-ET7DCQM7.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
// src/choices/element.ts
|
|
4
|
-
var tagName = "govuk-react-choices";
|
|
5
|
-
var classesOf = (attribute) => {
|
|
6
|
-
var _a;
|
|
7
|
-
return (_a = attribute == null ? void 0 : attribute.split(/\s+/).filter(Boolean)) != null ? _a : [];
|
|
8
|
-
};
|
|
9
|
-
var isChoice = (element) => element instanceof HTMLInputElement && (element.type === "radio" || element.type === "checkbox");
|
|
10
|
-
if (typeof HTMLElement !== "undefined" && typeof customElements !== "undefined") {
|
|
11
|
-
class GovukReactChoices extends HTMLElement {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(...arguments);
|
|
14
|
-
this.upgraded = false;
|
|
15
|
-
this.onClick = (event) => {
|
|
16
|
-
const input = event.target;
|
|
17
|
-
if (!isChoice(input) || !this.owns(input)) return;
|
|
18
|
-
if (input.type === "radio") {
|
|
19
|
-
this.syncAll();
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
this.syncInput(input);
|
|
23
|
-
if (!input.checked) return;
|
|
24
|
-
const exclusive = input.hasAttribute("data-choices-exclusive");
|
|
25
|
-
const others = this.inputsNamed(input).filter(
|
|
26
|
-
(other) => other !== input && other.type === "checkbox" && other.checked && (exclusive || other.hasAttribute("data-choices-exclusive"))
|
|
27
|
-
);
|
|
28
|
-
window.setTimeout(() => {
|
|
29
|
-
others.filter((other) => other.checked).forEach((other) => {
|
|
30
|
-
if (other.disabled) other.checked = false;
|
|
31
|
-
else other.click();
|
|
32
|
-
});
|
|
33
|
-
this.syncAll();
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
// `reset` changes the choices with no event for each, after it fires.
|
|
37
|
-
this.onReset = (event) => {
|
|
38
|
-
if (event.target instanceof HTMLFormElement && this.choices().some((input) => input.form === event.target)) {
|
|
39
|
-
window.setTimeout(() => this.sync());
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
this.onChange = (event) => {
|
|
43
|
-
if (isChoice(event.target) && this.owns(event.target)) this.sync();
|
|
44
|
-
};
|
|
45
|
-
// A page restored from the back-forward cache keeps its choices.
|
|
46
|
-
this.onPageShow = () => this.sync();
|
|
47
|
-
}
|
|
48
|
-
connectedCallback() {
|
|
49
|
-
this.observer = new MutationObserver((records) => {
|
|
50
|
-
if (records.some((record) => record.type === "childList")) this.setup();
|
|
51
|
-
else {
|
|
52
|
-
if (this.upgraded) this.addUpgradedClasses();
|
|
53
|
-
this.sync();
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
this.observer.observe(this, { childList: true, subtree: true, attributes: true, attributeFilter: ["class"] });
|
|
57
|
-
this.addEventListener("click", this.onClick);
|
|
58
|
-
this.addEventListener("change", this.onChange);
|
|
59
|
-
window.addEventListener("pageshow", this.onPageShow);
|
|
60
|
-
document.addEventListener("reset", this.onReset, true);
|
|
61
|
-
this.setup();
|
|
62
|
-
}
|
|
63
|
-
disconnectedCallback() {
|
|
64
|
-
var _a;
|
|
65
|
-
(_a = this.observer) == null ? void 0 : _a.disconnect();
|
|
66
|
-
this.removeEventListener("click", this.onClick);
|
|
67
|
-
this.removeEventListener("change", this.onChange);
|
|
68
|
-
window.removeEventListener("pageshow", this.onPageShow);
|
|
69
|
-
document.removeEventListener("reset", this.onReset, true);
|
|
70
|
-
}
|
|
71
|
-
get root() {
|
|
72
|
-
const root = this.getRootNode();
|
|
73
|
-
return root instanceof Document || root instanceof ShadowRoot ? root : document;
|
|
74
|
-
}
|
|
75
|
-
/** The inputs with the same name and form, anywhere on the page. */
|
|
76
|
-
inputsNamed(input) {
|
|
77
|
-
return Array.from(this.root.querySelectorAll("input")).filter(
|
|
78
|
-
(other) => other.type === input.type && other.name === input.name && other.form === input.form
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
/** Syncs every element on the page, for choices that changed in another group. */
|
|
82
|
-
syncAll() {
|
|
83
|
-
Array.from(this.root.querySelectorAll(tagName)).forEach((element) => {
|
|
84
|
-
if (element instanceof GovukReactChoices) element.sync();
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
owns(element) {
|
|
88
|
-
return element.closest(tagName) === this;
|
|
89
|
-
}
|
|
90
|
-
choices() {
|
|
91
|
-
return Array.from(this.querySelectorAll("input")).filter((input) => isChoice(input) && this.owns(input));
|
|
92
|
-
}
|
|
93
|
-
target(input) {
|
|
94
|
-
const id = input.getAttribute("data-choices-controls");
|
|
95
|
-
if (!id) return void 0;
|
|
96
|
-
const root = this.getRootNode();
|
|
97
|
-
const target = root instanceof Document || root instanceof ShadowRoot ? root.getElementById(id) : null;
|
|
98
|
-
return target instanceof HTMLElement && target.hasAttribute("data-choices-conditional") ? target : void 0;
|
|
99
|
-
}
|
|
100
|
-
setup() {
|
|
101
|
-
const choices = this.choices();
|
|
102
|
-
if (!choices.length) return;
|
|
103
|
-
if (!this.upgraded) {
|
|
104
|
-
this.upgraded = true;
|
|
105
|
-
this.dataset.upgraded = "";
|
|
106
|
-
this.addUpgradedClasses();
|
|
107
|
-
}
|
|
108
|
-
this.sync();
|
|
109
|
-
}
|
|
110
|
-
addUpgradedClasses() {
|
|
111
|
-
classesOf(this.getAttribute("upgraded-class")).forEach((name) => this.classList.toggle(name, true));
|
|
112
|
-
}
|
|
113
|
-
sync() {
|
|
114
|
-
if (!this.upgraded) return;
|
|
115
|
-
this.choices().forEach((input) => this.syncInput(input));
|
|
116
|
-
}
|
|
117
|
-
syncInput(input) {
|
|
118
|
-
const target = this.target(input);
|
|
119
|
-
if (!target) return;
|
|
120
|
-
input.setAttribute("aria-controls", target.id);
|
|
121
|
-
input.setAttribute("aria-expanded", String(input.checked));
|
|
122
|
-
const hiddenClasses = classesOf(this.getAttribute("hidden-conditional-class"));
|
|
123
|
-
if (hiddenClasses.length) hiddenClasses.forEach((name) => target.classList.toggle(name, !input.checked));
|
|
124
|
-
else target.hidden = !input.checked;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (!customElements.get(tagName)) customElements.define(tagName, GovukReactChoices);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export {
|
|
131
|
-
tagName
|
|
132
|
-
};
|
|
133
|
-
//# sourceMappingURL=chunk-ET7DCQM7.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/choices/element.ts"],"sourcesContent":["/*\n * <govuk-react-choices>: a headless, light-DOM custom element for a group of radios or checkboxes,\n * with or without React. It reveals content when a choice is checked, and makes a checkbox such\n * as \"None of these\" exclusive, as govuk-frontend's radios and checkboxes do.\n *\n * Without JavaScript every conditional reveal is shown, and an exclusive checkbox is an ordinary\n * one. On upgrade each reveal shows only while its choice is checked, and the choice gets\n * `aria-controls` and `aria-expanded`.\n *\n * Markup inside the element:\n * - `input[type=radio]` or `input[type=checkbox]`: the choices. `data-choices-controls` names the\n * id of the content it reveals. A checkbox with `data-choices-exclusive` unchecks the other\n * checkboxes with its name when checked, and is unchecked when one of them is.\n * - `[data-choices-conditional]`: the content a choice reveals, with an id.\n *\n * As in govuk-frontend, that covers checkboxes with the same name and form anywhere on the page,\n * and checking a radio updates the reveals of its whole group, even across elements. Choices are\n * unchecked with `click()`, so `change` events fire and React's `onChange` sees them.\n *\n * Attributes:\n * - `upgraded-class`: classes for the element once upgraded.\n * - `hidden-conditional-class`: classes that hide a reveal. Without them, the element sets\n * `hidden` on it.\n */\n\nexport const tagName = 'govuk-react-choices';\n\nexport interface ChoicesElement extends HTMLElement {\n /** Shows and hides the reveals to match the choices, such as after setting `checked`. */\n sync(): void;\n}\n\nconst classesOf = (attribute: string | null) => attribute?.split(/\\s+/).filter(Boolean) ?? [];\n\nconst isChoice = (element: EventTarget | null): element is HTMLInputElement =>\n element instanceof HTMLInputElement && (element.type === 'radio' || element.type === 'checkbox');\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactChoices extends HTMLElement implements ChoicesElement {\n private upgraded = false;\n\n private observer?: MutationObserver;\n\n private readonly onClick = (event: Event) => {\n const input = event.target;\n if (!isChoice(input) || !this.owns(input)) return;\n if (input.type === 'radio') {\n // Checking a radio unchecks another, with no event for it, maybe in another group.\n this.syncAll();\n return;\n }\n this.syncInput(input);\n if (!input.checked) return;\n const exclusive = input.hasAttribute('data-choices-exclusive');\n // As govuk-frontend: every checkbox with the name in the form, even in another group.\n const others = this.inputsNamed(input).filter(\n (other) =>\n other !== input &&\n other.type === 'checkbox' &&\n other.checked &&\n (exclusive || other.hasAttribute('data-choices-exclusive'))\n );\n // Unchecked once this click, and React's updates for it, are done, so each is its own event\n // that React sees.\n window.setTimeout(() => {\n others\n .filter((other) => other.checked)\n .forEach((other) => {\n // A disabled checkbox ignores `click()`.\n if (other.disabled) other.checked = false;\n else other.click();\n });\n this.syncAll();\n });\n };\n\n // `reset` changes the choices with no event for each, after it fires.\n private readonly onReset = (event: Event) => {\n if (event.target instanceof HTMLFormElement && this.choices().some((input) => input.form === event.target)) {\n window.setTimeout(() => this.sync());\n }\n };\n\n private readonly onChange = (event: Event) => {\n if (isChoice(event.target) && this.owns(event.target)) this.sync();\n };\n\n // A page restored from the back-forward cache keeps its choices.\n private readonly onPageShow = () => this.sync();\n\n connectedCallback() {\n this.observer = new MutationObserver((records) => {\n if (records.some((record) => record.type === 'childList')) this.setup();\n else {\n // React can rewrite the element's own class.\n if (this.upgraded) this.addUpgradedClasses();\n this.sync();\n }\n });\n // Choices rendered later, and a class React rewrites.\n this.observer.observe(this, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] });\n this.addEventListener('click', this.onClick);\n this.addEventListener('change', this.onChange);\n window.addEventListener('pageshow', this.onPageShow);\n document.addEventListener('reset', this.onReset, true);\n this.setup();\n }\n\n disconnectedCallback() {\n this.observer?.disconnect();\n this.removeEventListener('click', this.onClick);\n this.removeEventListener('change', this.onChange);\n window.removeEventListener('pageshow', this.onPageShow);\n document.removeEventListener('reset', this.onReset, true);\n }\n\n private get root() {\n const root = this.getRootNode();\n return root instanceof Document || root instanceof ShadowRoot ? root : document;\n }\n\n /** The inputs with the same name and form, anywhere on the page. */\n private inputsNamed(input: HTMLInputElement) {\n return Array.from(this.root.querySelectorAll('input')).filter(\n (other) => other.type === input.type && other.name === input.name && other.form === input.form\n );\n }\n\n /** Syncs every element on the page, for choices that changed in another group. */\n private syncAll() {\n Array.from(this.root.querySelectorAll(tagName)).forEach((element) => {\n if (element instanceof GovukReactChoices) element.sync();\n });\n }\n\n private owns(element: Element) {\n return element.closest(tagName) === this;\n }\n\n private choices() {\n return Array.from(this.querySelectorAll('input')).filter((input) => isChoice(input) && this.owns(input));\n }\n\n private target(input: HTMLInputElement) {\n const id = input.getAttribute('data-choices-controls');\n if (!id) return undefined;\n const root = this.getRootNode();\n const target = root instanceof Document || root instanceof ShadowRoot ? root.getElementById(id) : null;\n return target instanceof HTMLElement && target.hasAttribute('data-choices-conditional') ? target : undefined;\n }\n\n private setup() {\n const choices = this.choices();\n if (!choices.length) return;\n if (!this.upgraded) {\n this.upgraded = true;\n this.dataset.upgraded = '';\n this.addUpgradedClasses();\n }\n this.sync();\n }\n\n private addUpgradedClasses() {\n // `toggle` with force leaves a class that's already there alone, so the observer isn't woken.\n classesOf(this.getAttribute('upgraded-class')).forEach((name) => this.classList.toggle(name, true));\n }\n\n sync() {\n if (!this.upgraded) return;\n this.choices().forEach((input) => this.syncInput(input));\n }\n\n private syncInput(input: HTMLInputElement) {\n const target = this.target(input);\n if (!target) return;\n input.setAttribute('aria-controls', target.id);\n input.setAttribute('aria-expanded', String(input.checked));\n const hiddenClasses = classesOf(this.getAttribute('hidden-conditional-class'));\n // `toggle` with force leaves a class that's already there alone, so the observer isn't woken.\n if (hiddenClasses.length) hiddenClasses.forEach((name) => target.classList.toggle(name, !input.checked));\n else target.hidden = !input.checked;\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactChoices);\n}\n"],"mappings":";;;AAyBO,IAAM,UAAU;AAOvB,IAAM,YAAY,CAAC,cAA0B;AAhC7C;AAgCgD,sDAAW,MAAM,OAAO,OAAO,aAA/B,YAA2C,CAAC;AAAA;AAE5F,IAAM,WAAW,CAAC,YAChB,mBAAmB,qBAAqB,QAAQ,SAAS,WAAW,QAAQ,SAAS;AAEvF,IAAI,OAAO,gBAAgB,eAAe,OAAO,mBAAmB,aAAa;AAAA,EAC/E,MAAM,0BAA0B,YAAsC;AAAA,IAAtE;AAAA;AACE,WAAQ,WAAW;AAInB,WAAiB,UAAU,CAAC,UAAiB;AAC3C,cAAM,QAAQ,MAAM;AACpB,YAAI,CAAC,SAAS,KAAK,KAAK,CAAC,KAAK,KAAK,KAAK,EAAG;AAC3C,YAAI,MAAM,SAAS,SAAS;AAE1B,eAAK,QAAQ;AACb;AAAA,QACF;AACA,aAAK,UAAU,KAAK;AACpB,YAAI,CAAC,MAAM,QAAS;AACpB,cAAM,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B3NKM.js";
|
|
8
|
-
import {
|
|
9
|
-
__export
|
|
10
|
-
} from "./chunk-ESBMTI25.js";
|
|
11
|
-
|
|
12
|
-
// src/tabs/index.tsx
|
|
13
|
-
var tabs_exports = {};
|
|
14
|
-
__export(tabs_exports, {
|
|
15
|
-
Content: () => Content,
|
|
16
|
-
Item: () => Item,
|
|
17
|
-
List: () => List,
|
|
18
|
-
RadioContent: () => RadioContent,
|
|
19
|
-
RadioTrigger: () => RadioTrigger,
|
|
20
|
-
RadiosRoot: () => RadiosRoot,
|
|
21
|
-
Root: () => Root,
|
|
22
|
-
Trigger: () => Trigger,
|
|
23
|
-
radiosFallbackCss: () => radiosFallbackCss
|
|
24
|
-
});
|
|
25
|
-
import * as React from "react";
|
|
26
|
-
import { createContext, useContext, useEffect, useId, useRef } from "react";
|
|
27
|
-
var TabsContext = createContext({});
|
|
28
|
-
var radiosFallbackCss = `${tagName}:not([data-upgraded]) [data-tabs-content]:has(> input[data-tabs-fallback]):not(:has(> input:checked)){display:none}`;
|
|
29
|
-
var radioId = (name, value) => `${name}-${value}`;
|
|
30
|
-
function Root(props) {
|
|
31
|
-
return /* @__PURE__ */ React.createElement(TabsRoot, { fallback: "links", ...props });
|
|
32
|
-
}
|
|
33
|
-
function RadiosRoot(props) {
|
|
34
|
-
return /* @__PURE__ */ React.createElement(TabsRoot, { fallback: "radios", ...props });
|
|
35
|
-
}
|
|
36
|
-
function TabsRoot({
|
|
37
|
-
children,
|
|
38
|
-
value,
|
|
39
|
-
defaultValue,
|
|
40
|
-
onValueChange,
|
|
41
|
-
preHydration = "ignore",
|
|
42
|
-
orientation,
|
|
43
|
-
fallback,
|
|
44
|
-
name,
|
|
45
|
-
media,
|
|
46
|
-
upgradedClass,
|
|
47
|
-
activeItemClass,
|
|
48
|
-
hiddenContentClass,
|
|
49
|
-
className,
|
|
50
|
-
...props
|
|
51
|
-
}) {
|
|
52
|
-
const generatedName = useId();
|
|
53
|
-
const groupName = name != null ? name : generatedName;
|
|
54
|
-
const ref = useRef(null);
|
|
55
|
-
const reported = useRef(false);
|
|
56
|
-
const initial = useRef({ value, preHydration, onValueChange });
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
var _a, _b;
|
|
59
|
-
const picked = (_a = ref.current) == null ? void 0 : _a.pickedValue;
|
|
60
|
-
if (reported.current || picked === void 0) return;
|
|
61
|
-
reported.current = true;
|
|
62
|
-
const start = initial.current;
|
|
63
|
-
if (start.value === void 0 || start.preHydration === "report") (_b = start.onValueChange) == null ? void 0 : _b.call(start, picked);
|
|
64
|
-
}, []);
|
|
65
|
-
return /* @__PURE__ */ React.createElement(TabsContext.Provider, { value: { selected: value != null ? value : defaultValue, name: groupName, onValueChange } }, fallback === "radios" && /* @__PURE__ */ React.createElement("style", { href: `${tagName}-radios-fallback`, precedence: "default" }, radiosFallbackCss), React.createElement(
|
|
66
|
-
tagName,
|
|
67
|
-
{
|
|
68
|
-
...props,
|
|
69
|
-
ref,
|
|
70
|
-
// The radios fallback switches tabs before upgrade, so it is styled as tabs from the start.
|
|
71
|
-
className: [className, fallback === "radios" && upgradedClass].filter(Boolean).join(" ") || void 0,
|
|
72
|
-
value,
|
|
73
|
-
"default-value": defaultValue,
|
|
74
|
-
fallback,
|
|
75
|
-
orientation,
|
|
76
|
-
"prefer-pick": preHydration === "report" ? "" : void 0,
|
|
77
|
-
media,
|
|
78
|
-
"upgraded-class": upgradedClass,
|
|
79
|
-
"active-item-class": activeItemClass,
|
|
80
|
-
"hidden-content-class": hiddenContentClass,
|
|
81
|
-
// The element adds attributes on upgrade, so they can differ from the server's.
|
|
82
|
-
suppressHydrationWarning: true
|
|
83
|
-
},
|
|
84
|
-
children
|
|
85
|
-
));
|
|
86
|
-
}
|
|
87
|
-
function List({ asChild, ...props }) {
|
|
88
|
-
const Element = asChild ? Slot : "div";
|
|
89
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-tabs-list": "", suppressHydrationWarning: true, ...props });
|
|
90
|
-
}
|
|
91
|
-
function Item({ asChild, value, ...props }) {
|
|
92
|
-
const Element = asChild ? Slot : "div";
|
|
93
|
-
return /* @__PURE__ */ React.createElement(Element, { "data-tabs-item": "", "data-value": value, suppressHydrationWarning: true, ...props });
|
|
94
|
-
}
|
|
95
|
-
function useIsland({ name }) {
|
|
96
|
-
var _a;
|
|
97
|
-
const context = useContext(TabsContext);
|
|
98
|
-
return {
|
|
99
|
-
name: (_a = name != null ? name : context.name) != null ? _a : tagName,
|
|
100
|
-
selected: context.selected,
|
|
101
|
-
onValueChange: context.onValueChange
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
var triggerData = (value) => ({
|
|
105
|
-
"data-tabs-trigger": "",
|
|
106
|
-
"data-value": value,
|
|
107
|
-
suppressHydrationWarning: true
|
|
108
|
-
});
|
|
109
|
-
function Trigger({ asChild, value, ...props }) {
|
|
110
|
-
const Element = asChild ? Slot : "a";
|
|
111
|
-
return /* @__PURE__ */ React.createElement(Element, { ...triggerData(value), href: `#${value}`, ...props });
|
|
112
|
-
}
|
|
113
|
-
function RadioTrigger({ asChild, value, name: nameProp, ...props }) {
|
|
114
|
-
const { name } = useIsland({ name: nameProp });
|
|
115
|
-
const Element = asChild ? Slot : "label";
|
|
116
|
-
return /* @__PURE__ */ React.createElement(Element, { ...triggerData(value), htmlFor: radioId(name, value), ...props });
|
|
117
|
-
}
|
|
118
|
-
function Content(props) {
|
|
119
|
-
return /* @__PURE__ */ React.createElement(Panel, { ...props });
|
|
120
|
-
}
|
|
121
|
-
function RadioContent(props) {
|
|
122
|
-
return /* @__PURE__ */ React.createElement(Panel, { radios: true, ...props });
|
|
123
|
-
}
|
|
124
|
-
function Panel({
|
|
125
|
-
asChild,
|
|
126
|
-
value,
|
|
127
|
-
children,
|
|
128
|
-
name: nameProp,
|
|
129
|
-
defaultSelected,
|
|
130
|
-
radios = false,
|
|
131
|
-
...props
|
|
132
|
-
}) {
|
|
133
|
-
const { name, selected, onValueChange } = useIsland({ name: nameProp });
|
|
134
|
-
const radio = (
|
|
135
|
-
// The selection, and in a RadiosRoot the no-JS state. `form` names no form, so the radio is
|
|
136
|
-
// never submitted with a form around it.
|
|
137
|
-
/* @__PURE__ */ React.createElement(
|
|
138
|
-
"input",
|
|
139
|
-
{
|
|
140
|
-
type: "radio",
|
|
141
|
-
name,
|
|
142
|
-
id: radioId(name, value),
|
|
143
|
-
form: `${name}-none`,
|
|
144
|
-
defaultChecked: defaultSelected != null ? defaultSelected : value === selected,
|
|
145
|
-
hidden: true,
|
|
146
|
-
"data-tabs-fallback": radios ? "" : void 0,
|
|
147
|
-
suppressHydrationWarning: true,
|
|
148
|
-
onChange: () => onValueChange == null ? void 0 : onValueChange(value)
|
|
149
|
-
}
|
|
150
|
-
)
|
|
151
|
-
);
|
|
152
|
-
const shared = {
|
|
153
|
-
id: value,
|
|
154
|
-
"data-tabs-content": "",
|
|
155
|
-
"data-value": value,
|
|
156
|
-
suppressHydrationWarning: true
|
|
157
|
-
};
|
|
158
|
-
if (asChild && React.isValidElement(children)) {
|
|
159
|
-
const child = children;
|
|
160
|
-
return /* @__PURE__ */ React.createElement(Slot, { ...shared, ...props }, React.cloneElement(child, void 0, radio, child.props.children));
|
|
161
|
-
}
|
|
162
|
-
return /* @__PURE__ */ React.createElement("div", { ...shared, ...props }, radio, children);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export {
|
|
166
|
-
radiosFallbackCss,
|
|
167
|
-
Root,
|
|
168
|
-
RadiosRoot,
|
|
169
|
-
List,
|
|
170
|
-
Item,
|
|
171
|
-
Trigger,
|
|
172
|
-
RadioTrigger,
|
|
173
|
-
Content,
|
|
174
|
-
RadioContent,
|
|
175
|
-
tabs_exports
|
|
176
|
-
};
|
|
177
|
-
//# sourceMappingURL=chunk-F5XFC4QJ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tabs/index.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createContext, useContext, useEffect, useId, useRef } from 'react';\nimport type { ComponentProps, ReactElement, ReactNode } from 'react';\nimport { Slot } from '../utils/slot';\nimport { tagName, type TabsElement } from './element';\n\n/*\n * Headless tabs: unstyled parts over the <govuk-react-tabs> element (./element.ts), which adds\n * the tab behaviour on upgrade. Every part except Root takes `asChild`.\n *\n * Each panel holds a hidden radio, and the radio group is the source of truth. A user's choice\n * fires the radio's native change, which React reports through the radio's `onChange`.\n *\n * Without JavaScript, `Root`'s tabs are links to every panel, and `RadiosRoot`'s are labels for the\n * panels' radios, so they switch panels without JavaScript too. Use `Trigger` and `Content` in a\n * `Root`, and `RadioTrigger` and `RadioContent` in a `RadiosRoot`.\n *\n * Context only fills in defaults: in an island without a Root, pass `name` and `defaultSelected`\n * to the parts. Each `value` is also its panel's id, so must be unique.\n */\n\nconst TabsContext = createContext<{\n selected?: string;\n name?: string;\n onValueChange?: (value: string) => void;\n}>({});\n\n/**\n * Shows only the checked radio's panel until the element upgrades, and below its `media`.\n * Root renders it inline; under a strict CSP, add it to a stylesheet instead.\n */\nexport const radiosFallbackCss = `${tagName}:not([data-upgraded]) [data-tabs-content]:has(> input[data-tabs-fallback]):not(:has(> input:checked)){display:none}`;\n\nconst radioId = (name: string, value: string) => `${name}-${value}`;\n\ntype BaseRootProps = {\n children?: ReactNode;\n /** The selected tab's value, to control the tabs. */\n value?: string;\n /** The tab selected at first, when uncontrolled. Defaults to the first tab. */\n defaultValue?: string;\n /** Called when the user selects a tab. */\n onValueChange?: (value: string) => void;\n /**\n * When controlled, what happens to a tab the user picked before hydration: \"ignore\" keeps\n * `value`, \"report\" calls `onValueChange` with the pick so you can adopt it.\n */\n preHydration?: 'ignore' | 'report';\n /** The axis of the arrow keys. */\n orientation?: 'horizontal' | 'vertical';\n /** The panels' radio group name. Defaults to a generated one. */\n name?: string;\n /** Only behave as tabs when this media query matches. */\n media?: string;\n /** Classes added to the element when it upgrades. */\n upgradedClass?: string;\n /** Classes added to the active item. */\n activeItemClass?: string;\n /** Classes added to inactive panels. */\n hiddenContentClass?: string;\n} & Omit<React.HTMLAttributes<HTMLElement>, 'defaultValue' | 'onChange'>;\n\nexport type RootProps = BaseRootProps;\n\n/** Tabs that are links to every panel without JavaScript. Use `Trigger` and `Content` inside it. */\nexport function Root(props: RootProps) {\n return <TabsRoot fallback=\"links\" {...props} />;\n}\n\nexport type RadiosRootProps = BaseRootProps &\n // Without JavaScript only the checked radio's panel shows, so one must be checked from the start.\n ({ value: string } | { defaultValue: string });\n\n/**\n * Tabs that switch panels without JavaScript too, through the panels' radios. Use `RadioTrigger`\n * and `RadioContent` inside it.\n */\nexport function RadiosRoot(props: RadiosRootProps) {\n return <TabsRoot fallback=\"radios\" {...props} />;\n}\n\nfunction TabsRoot({\n children,\n value,\n defaultValue,\n onValueChange,\n preHydration = 'ignore',\n orientation,\n fallback,\n name,\n media,\n upgradedClass,\n activeItemClass,\n hiddenContentClass,\n className,\n ...props\n}: BaseRootProps & { fallback: 'links' | 'radios' }) {\n const generatedName = useId();\n const groupName = name ?? generatedName;\n const ref = useRef<TabsElement>(null);\n\n // A tab the user picked before hydration fired no onChange that React saw, so report it once.\n // When controlled with \"ignore\", `value` wins, so there is nothing to report.\n const reported = useRef(false);\n const initial = useRef({ value, preHydration, onValueChange });\n useEffect(() => {\n const picked = ref.current?.pickedValue;\n if (reported.current || picked === undefined) return;\n reported.current = true;\n const start = initial.current;\n if (start.value === undefined || start.preHydration === 'report') start.onValueChange?.(picked);\n }, []);\n\n return (\n <TabsContext.Provider value={{ selected: value ?? defaultValue, name: groupName, onValueChange }}>\n {fallback === 'radios' && (\n <style href={`${tagName}-radios-fallback`} precedence=\"default\">\n {radiosFallbackCss}\n </style>\n )}\n {React.createElement(\n tagName,\n {\n ...props,\n ref,\n // The radios fallback switches tabs before upgrade, so it is styled as tabs from the start.\n className: [className, fallback === 'radios' && upgradedClass].filter(Boolean).join(' ') || undefined,\n value,\n 'default-value': defaultValue,\n fallback,\n orientation,\n 'prefer-pick': preHydration === 'report' ? '' : undefined,\n media,\n 'upgraded-class': upgradedClass,\n 'active-item-class': activeItemClass,\n 'hidden-content-class': hiddenContentClass,\n // The element adds attributes on upgrade, so they can differ from the server's.\n suppressHydrationWarning: true,\n },\n children\n )}\n </TabsContext.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 ListProps = PartProps<'div'>;\n\nexport function List({ asChild, ...props }: ListProps) {\n const Element = asChild ? Slot : 'div';\n return <Element data-tabs-list=\"\" suppressHydrationWarning {...props} />;\n}\n\nexport type ItemProps = PartProps<'div'> & { value: string };\n\n/** An optional wrapper around a tab, such as a list item. */\nexport function Item({ asChild, value, ...props }: ItemProps) {\n const Element = asChild ? Slot : 'div';\n return <Element data-tabs-item=\"\" data-value={value} suppressHydrationWarning {...props} />;\n}\n\n/** Set by Root. Pass it to a part rendered without a Root, such as in an island. */\ntype IslandProps = {\n /** The panels' radio group name. */\n name?: string;\n};\n\nfunction useIsland({ name }: IslandProps) {\n const context = useContext(TabsContext);\n return {\n name: name ?? context.name ?? tagName,\n selected: context.selected,\n onValueChange: context.onValueChange,\n };\n}\n\nexport type TriggerProps = React.HTMLAttributes<HTMLElement> & {\n /** Render the only child instead, with this part's props merged onto it. */\n asChild?: boolean;\n value: string;\n};\n\nconst triggerData = (value: string) => ({\n 'data-tabs-trigger': '',\n 'data-value': value,\n suppressHydrationWarning: true,\n});\n\n/** A tab in a `Root`: a link to its panel. */\nexport function Trigger({ asChild, value, ...props }: TriggerProps) {\n const Element = asChild ? Slot : 'a';\n return <Element {...triggerData(value)} href={`#${value}`} {...props} />;\n}\n\nexport type RadioTriggerProps = TriggerProps & IslandProps;\n\n/** A tab in a `RadiosRoot`: a label for its panel's radio. */\nexport function RadioTrigger({ asChild, value, name: nameProp, ...props }: RadioTriggerProps) {\n const { name } = useIsland({ name: nameProp });\n const Element = asChild ? Slot : 'label';\n return <Element {...triggerData(value)} htmlFor={radioId(name, value)} {...props} />;\n}\n\nexport type ContentProps = PartProps<'div'> &\n IslandProps & {\n value: string;\n /** Whether this panel's radio is checked at first. Defaults to Root's value. */\n defaultSelected?: boolean;\n };\n\n/** A panel in a `Root`. Its id is its `value`. */\nexport function Content(props: ContentProps) {\n return <Panel {...props} />;\n}\n\nexport type RadioContentProps = ContentProps;\n\n/** A panel in a `RadiosRoot`, shown without JavaScript only while its radio is checked. Its id is its `value`. */\nexport function RadioContent(props: RadioContentProps) {\n return <Panel radios {...props} />;\n}\n\nfunction Panel({\n asChild,\n value,\n children,\n name: nameProp,\n defaultSelected,\n radios = false,\n ...props\n}: ContentProps & { radios?: boolean }) {\n const { name, selected, onValueChange } = useIsland({ name: nameProp });\n const radio = (\n // The selection, and in a RadiosRoot the no-JS state. `form` names no form, so the radio is\n // never submitted with a form around it.\n <input\n type=\"radio\"\n name={name}\n id={radioId(name, value)}\n form={`${name}-none`}\n defaultChecked={defaultSelected ?? value === selected}\n hidden\n data-tabs-fallback={radios ? '' : undefined}\n suppressHydrationWarning\n onChange={() => onValueChange?.(value)}\n />\n );\n const shared = {\n id: value,\n 'data-tabs-content': '',\n 'data-value': value,\n suppressHydrationWarning: true,\n };\n if (asChild && React.isValidElement<{ children?: ReactNode }>(children)) {\n const child: ReactElement<{ children?: ReactNode }> = children;\n return (\n <Slot {...shared} {...props}>\n {React.cloneElement(child, undefined, radio, child.props.children)}\n </Slot>\n );\n }\n return (\n <div {...shared} {...props}>\n {radio}\n {children}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAY,WAAW;AACvB,SAAS,eAAe,YAAY,WAAW,OAAO,cAAc;AAoBpE,IAAM,cAAc,cAIjB,CAAC,CAAC;AAME,IAAM,oBAAoB,GAAG,OAAO;AAE3C,IAAM,UAAU,CAAC,MAAc,UAAkB,GAAG,IAAI,IAAI,KAAK;AAg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