@cruk/cruk-react-components 6.0.3 → 6.1.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 +5 -22
- package/lib/node_modules/@babel/runtime/helpers/esm/extends.js.map +1 -1
- package/lib/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js.map +1 -1
- package/lib/node_modules/@babel/runtime/helpers/esm/typeof.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/focusInside.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/focusInside.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/focusIsHidden.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/focusIsHidden.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/focusSolver.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/focusSolver.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/focusables.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/focusables.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/moveFocusInside.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/moveFocusInside.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/return-focus.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/sibling.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/sibling.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/solver.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/solver.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/DOMutils.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/DOMutils.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/all-affected.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/all-affected.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/auto-focus.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/auto-focus.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/correctFocus.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/correctFocus.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/getActiveElement.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/getActiveElement.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/is.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/parenting.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/parenting.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/tabOrder.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/tabOrder.js.map +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/tabUtils.js +1 -1
- package/lib/node_modules/focus-lock/dist/es2015/utils/tabUtils.js.map +1 -1
- package/lib/node_modules/react-clientside-effect/lib/index.es.js +1 -1
- package/lib/node_modules/react-clientside-effect/lib/index.es.js.map +1 -1
- package/lib/node_modules/react-focus-lock/dist/es2015/Combination.js +1 -1
- package/lib/node_modules/react-focus-lock/dist/es2015/Combination.js.map +1 -1
- package/lib/node_modules/react-focus-lock/dist/es2015/Lock.js +1 -1
- package/lib/node_modules/react-focus-lock/dist/es2015/Lock.js.map +1 -1
- package/lib/node_modules/react-focus-lock/dist/es2015/Trap.js +1 -1
- package/lib/node_modules/react-focus-lock/dist/es2015/Trap.js.map +1 -1
- package/lib/node_modules/react-focus-lock/dist/es2015/medium.js +1 -1
- package/lib/node_modules/react-focus-lock/dist/es2015/medium.js.map +1 -1
- package/lib/node_modules/react-intersection-observer/dist/index.js +1 -1
- package/lib/node_modules/react-intersection-observer/dist/index.js.map +1 -1
- package/lib/node_modules/tslib/tslib.es6.js.map +1 -1
- package/lib/node_modules/use-callback-ref/dist/es2015/useMergeRef.js +1 -1
- package/lib/node_modules/use-callback-ref/dist/es2015/useMergeRef.js.map +1 -1
- package/lib/node_modules/use-callback-ref/dist/es2015/useRef.js +1 -1
- package/lib/node_modules/use-callback-ref/dist/es2015/useRef.js.map +1 -1
- package/lib/node_modules/use-sidecar/dist/es2015/medium.js +1 -1
- package/lib/node_modules/use-sidecar/dist/es2015/medium.js.map +1 -1
- package/lib/playwright/index.d.ts +1 -0
- package/lib/playwright/utils.d.ts +19 -0
- package/lib/playwright-ct.config.d.ts +2 -0
- package/lib/{components → src/components}/AddressLookup/AddressLookup.stories.d.ts +1 -1
- package/lib/src/components/AddressLookup/index.js +1 -1
- package/lib/src/components/AddressLookup/index.js.map +1 -1
- package/lib/src/components/AddressLookup/styles.js +1 -1
- package/lib/src/components/AddressLookup/styles.js.map +1 -1
- package/lib/{components → src/components}/Avatar/Avatar.stories.d.ts +1 -1
- package/lib/src/components/Avatar/index.js.map +1 -1
- package/lib/src/components/Avatar/styles.js +1 -1
- package/lib/src/components/Avatar/styles.js.map +1 -1
- package/lib/{components → src/components}/Badge/Badge.stories.d.ts +1 -1
- package/lib/src/components/Badge/index.js.map +1 -1
- package/lib/src/components/Badge/styles.js +1 -1
- package/lib/src/components/Badge/styles.js.map +1 -1
- package/lib/{components → src/components}/Box/Box.stories.d.ts +1 -1
- package/lib/src/components/Box/index.js.map +1 -1
- package/lib/src/components/Box/styles.js +1 -1
- package/lib/src/components/Box/styles.js.map +1 -1
- package/lib/{components → src/components}/Button/Button.stories.d.ts +1 -1
- package/lib/src/components/Button/index.js +1 -1
- package/lib/src/components/Button/index.js.map +1 -1
- package/lib/src/components/Button/styles.js +1 -1
- package/lib/src/components/Button/styles.js.map +1 -1
- package/lib/{components → src/components}/Carousel/Carousel.stories.d.ts +1 -1
- package/lib/src/components/Carousel/Dots.js +1 -1
- package/lib/src/components/Carousel/Dots.js.map +1 -1
- package/lib/src/components/Carousel/index.js +1 -1
- package/lib/src/components/Carousel/index.js.map +1 -1
- package/lib/src/components/Carousel/styles.js +1 -1
- package/lib/src/components/Carousel/styles.js.map +1 -1
- package/lib/{components → src/components}/Checkbox/Checkbox.stories.d.ts +1 -1
- package/lib/src/components/Checkbox/index.js.map +1 -1
- package/lib/src/components/Checkbox/styles.js +1 -1
- package/lib/src/components/Checkbox/styles.js.map +1 -1
- package/lib/{components → src/components}/Collapse/Collapse.stories.d.ts +1 -1
- package/lib/src/components/Collapse/index.js +1 -1
- package/lib/src/components/Collapse/index.js.map +1 -1
- package/lib/src/components/Collapse/styles.js +1 -1
- package/lib/src/components/Collapse/styles.js.map +1 -1
- package/lib/{components → src/components}/DateField/DateField.stories.d.ts +1 -1
- package/lib/src/components/DateField/index.js +1 -1
- package/lib/src/components/DateField/index.js.map +1 -1
- package/lib/src/components/DateField/styles.js +1 -1
- package/lib/src/components/DateField/styles.js.map +1 -1
- package/lib/src/components/Divider.js.map +1 -1
- package/lib/{components → src/components}/ErrorText/ErrorText.stories.d.ts +1 -1
- package/lib/src/components/ErrorText/index.js.map +1 -1
- package/lib/src/components/ErrorText/styles.js +1 -1
- package/lib/src/components/ErrorText/styles.js.map +1 -1
- package/lib/src/components/Flex.js +1 -1
- package/lib/src/components/Flex.js.map +1 -1
- package/lib/src/components/Fontface.js +1 -1
- package/lib/src/components/Fontface.js.map +1 -1
- package/lib/{components → src/components}/Footer/Footer.stories.d.ts +1 -1
- package/lib/src/components/Footer/index.js +1 -1
- package/lib/src/components/Footer/index.js.map +1 -1
- package/lib/src/components/Footer/styles.js +1 -1
- package/lib/src/components/Footer/styles.js.map +1 -1
- package/lib/src/components/GlobalStyle.d.ts +2 -0
- package/lib/src/components/GlobalStyle.js +1 -1
- package/lib/src/components/GlobalStyle.js.map +1 -1
- package/lib/src/components/GlobalStyleNoFontFace.d.ts +2 -0
- package/lib/src/components/GlobalStyleNoFontFace.js +1 -1
- package/lib/src/components/GlobalStyleNoFontFace.js.map +1 -1
- package/lib/{components → src/components}/Header/Header.stories.d.ts +1 -1
- package/lib/src/components/Header/index.js +1 -1
- package/lib/src/components/Header/index.js.map +1 -1
- package/lib/src/components/Header/styles.js +1 -1
- package/lib/src/components/Header/styles.js.map +1 -1
- package/lib/{components → src/components}/Heading/Heading.stories.d.ts +1 -1
- package/lib/src/components/Heading/index.js.map +1 -1
- package/lib/src/components/Heading/styles.js +1 -1
- package/lib/src/components/Heading/styles.js.map +1 -1
- package/lib/{components → src/components}/IconFa/IconFa.stories.d.ts +1 -1
- package/lib/src/components/IconFa/index.js.map +1 -1
- package/lib/src/components/IconFa/styles.js +1 -1
- package/lib/src/components/IconFa/styles.js.map +1 -1
- package/lib/{components → src/components}/InfoBox/InfoBox.stories.d.ts +1 -1
- package/lib/src/components/InfoBox/index.js.map +1 -1
- package/lib/src/components/InfoBox/styles.js +1 -1
- package/lib/src/components/InfoBox/styles.js.map +1 -1
- package/lib/{components → src/components}/LabelWrapper/index.d.ts +4 -4
- package/lib/src/components/LabelWrapper/index.js +1 -1
- package/lib/src/components/LabelWrapper/index.js.map +1 -1
- package/lib/{components → src/components}/LabelWrapper/styles.d.ts +1 -1
- package/lib/src/components/LabelWrapper/styles.js +1 -1
- package/lib/src/components/LabelWrapper/styles.js.map +1 -1
- package/lib/{components → src/components}/LegendWrapper/LegendWrapper.stories.d.ts +1 -1
- package/lib/{components → src/components}/LegendWrapper/index.d.ts +1 -1
- package/lib/src/components/LegendWrapper/index.js +1 -1
- package/lib/src/components/LegendWrapper/index.js.map +1 -1
- package/lib/src/components/LegendWrapper/styles.js +1 -1
- package/lib/src/components/LegendWrapper/styles.js.map +1 -1
- package/lib/{components → src/components}/Link/Link.stories.d.ts +1 -1
- package/lib/src/components/Link/index.js.map +1 -1
- package/lib/src/components/Link/styles.js +1 -1
- package/lib/src/components/Link/styles.js.map +1 -1
- package/lib/{components → src/components}/Loader/Loader.stories.d.ts +1 -1
- package/lib/src/components/Loader/index.js.map +1 -1
- package/lib/src/components/Loader/styles.js +1 -1
- package/lib/src/components/Loader/styles.js.map +1 -1
- package/lib/{components → src/components}/Modal/Modal.stories.d.ts +1 -1
- package/lib/src/components/Modal/TestModalWithContent.d.ts +2 -0
- package/lib/src/components/Modal/TestModalWithState.d.ts +2 -0
- package/lib/src/components/Modal/index.js +1 -1
- package/lib/src/components/Modal/index.js.map +1 -1
- package/lib/src/components/Modal/styles.js +1 -1
- package/lib/src/components/Modal/styles.js.map +1 -1
- package/lib/{components → src/components}/Pagination/Pagination.stories.d.ts +1 -1
- package/lib/src/components/Pagination/index.js.map +1 -1
- package/lib/src/components/Pagination/styles.js +1 -1
- package/lib/src/components/Pagination/styles.js.map +1 -1
- package/lib/{components → src/components}/PopOver/Popover.stories.d.ts +1 -1
- package/lib/src/components/PopOver/TestPopOverWithContent.d.ts +2 -0
- package/lib/src/components/PopOver/index.js +1 -1
- package/lib/src/components/PopOver/index.js.map +1 -1
- package/lib/src/components/PopOver/styles.js +1 -1
- package/lib/src/components/PopOver/styles.js.map +1 -1
- package/lib/{components → src/components}/ProgressBar/ProgressBar.stories.d.ts +1 -1
- package/lib/src/components/ProgressBar/index.js.map +1 -1
- package/lib/src/components/ProgressBar/styles.js +1 -1
- package/lib/src/components/ProgressBar/styles.js.map +1 -1
- package/lib/{components → src/components}/Radio/Radio.stories.d.ts +1 -1
- package/lib/src/components/Radio/index.js.map +1 -1
- package/lib/src/components/Radio/styles.js +1 -1
- package/lib/src/components/Radio/styles.js.map +1 -1
- package/lib/{components → src/components}/RadioConsent/Radio.stories.d.ts +1 -1
- package/lib/src/components/RadioConsent/index.js +1 -1
- package/lib/src/components/RadioConsent/index.js.map +1 -1
- package/lib/src/components/RadioConsent/styles.js +1 -1
- package/lib/src/components/RadioConsent/styles.js.map +1 -1
- package/lib/{components → src/components}/Select/Selelct.stories.d.ts +2 -2
- package/lib/{components → src/components}/Select/index.d.ts +3 -3
- package/lib/src/components/Select/index.js +1 -1
- package/lib/src/components/Select/index.js.map +1 -1
- package/lib/src/components/Select/styles.js +1 -1
- package/lib/src/components/Select/styles.js.map +1 -1
- package/lib/src/components/Spacing/index.js.map +1 -1
- package/lib/{components → src/components}/Step/Step.stories.d.ts +1 -1
- package/lib/src/components/Step/index.js +1 -1
- package/lib/src/components/Step/index.js.map +1 -1
- package/lib/src/components/Step/styles.js +1 -1
- package/lib/src/components/Step/styles.js.map +1 -1
- package/lib/{components → src/components}/Text/Text.stories.d.ts +1 -1
- package/lib/src/components/Text/index.js.map +1 -1
- package/lib/src/components/Text/styles.js +1 -1
- package/lib/src/components/Text/styles.js.map +1 -1
- package/lib/{components → src/components}/TextAreaField/TextAreaField.stories.d.ts +1 -1
- package/lib/src/components/TextAreaField/index.js.map +1 -1
- package/lib/src/components/TextAreaField/styles.js +1 -1
- package/lib/src/components/TextAreaField/styles.js.map +1 -1
- package/lib/{components → src/components}/TextField/TextField.stories.d.ts +2 -2
- package/lib/{components → src/components}/TextField/index.d.ts +3 -3
- package/lib/src/components/TextField/index.js +1 -1
- package/lib/src/components/TextField/index.js.map +1 -1
- package/lib/src/components/TextField/styles.js +1 -1
- package/lib/src/components/TextField/styles.js.map +1 -1
- package/lib/src/components/ThemeCheatSheet.d.ts +7 -0
- package/lib/{components → src/components}/Totaliser/Totaliser.stories.d.ts +1 -1
- package/lib/src/components/Totaliser/index.js.map +1 -1
- package/lib/src/components/Totaliser/styles.js +1 -1
- package/lib/src/components/Totaliser/styles.js.map +1 -1
- package/lib/{components → src/components}/UserBlock/UserBlock.stories.d.ts +1 -1
- package/lib/src/components/UserBlock/index.js.map +1 -1
- package/lib/src/components/UserBlock/styles.js +1 -1
- package/lib/src/components/UserBlock/styles.js.map +1 -1
- package/lib/src/hooks/useEffectBrowser.js +1 -1
- package/lib/src/hooks/useEffectBrowser.js.map +1 -1
- package/lib/src/hooks/useKey.js +1 -1
- package/lib/src/hooks/useKey.js.map +1 -1
- package/lib/src/hooks/useLayoutEffectBrowser.js +1 -1
- package/lib/src/hooks/useLayoutEffectBrowser.js.map +1 -1
- package/lib/src/hooks/useScrollPosition.js +1 -1
- package/lib/src/hooks/useScrollPosition.js.map +1 -1
- package/lib/src/themes/bowelbabe.js.map +1 -1
- package/lib/src/themes/cruk.js.map +1 -1
- package/lib/src/themes/rfl.js.map +1 -1
- package/lib/src/themes/su2c.js +1 -1
- package/lib/src/themes/su2c.js.map +1 -1
- package/lib/src/utils/Helper.js +1 -1
- package/lib/src/utils/Helper.js.map +1 -1
- package/lib/src/utils/debounce.js +1 -1
- package/lib/src/utils/debounce.js.map +1 -1
- package/lib/src/utils/themeUtils.js.map +1 -1
- package/lib/vite.config.d.ts +2 -0
- package/package.json +25 -46
- package/lib/components/GlobalStyle.d.ts +0 -2
- package/lib/components/GlobalStyleNoFontFace.d.ts +0 -2
- package/lib/components/ThemeCheatSheet.d.ts +0 -7
- /package/lib/{components/AddressLookup/AddressLookUp.test.cypress.d.ts → src/components/AddressLookup/AddressLookup.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/AddressLookup/index.d.ts +0 -0
- /package/lib/{components → src/components}/AddressLookup/styles.d.ts +0 -0
- /package/lib/{components → src/components}/AllThemesWrapper.d.ts +0 -0
- /package/lib/{components/Avatar/Avatar.test.cypress.d.ts → src/components/Avatar/Avatar.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Avatar/index.d.ts +0 -0
- /package/lib/{components → src/components}/Avatar/styles.d.ts +0 -0
- /package/lib/{components/Badge/Badge.test.cypress.d.ts → src/components/Badge/Badge.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Badge/index.d.ts +0 -0
- /package/lib/{components → src/components}/Badge/styles.d.ts +0 -0
- /package/lib/{components/Box/Box.test.cypress.d.ts → src/components/Box/Box.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Box/index.d.ts +0 -0
- /package/lib/{components → src/components}/Box/styles.d.ts +0 -0
- /package/lib/{components/Button/Button.test.cypress.d.ts → src/components/Button/Button.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Button/index.d.ts +0 -0
- /package/lib/{components → src/components}/Button/styles.d.ts +0 -0
- /package/lib/{components/Carousel/Carousel.test.cypress.d.ts → src/components/Carousel/Carousel.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Carousel/Dots.d.ts +0 -0
- /package/lib/{components → src/components}/Carousel/index.d.ts +0 -0
- /package/lib/{components → src/components}/Carousel/styles.d.ts +0 -0
- /package/lib/{components/Checkbox/CheckBox.test.cypress.d.ts → src/components/Checkbox/Checkbox.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Checkbox/index.d.ts +0 -0
- /package/lib/{components → src/components}/Checkbox/styles.d.ts +0 -0
- /package/lib/{components/Collapse/Collapse.test.cypress.d.ts → src/components/Collapse/Collapse.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Collapse/index.d.ts +0 -0
- /package/lib/{components → src/components}/Collapse/styles.d.ts +0 -0
- /package/lib/{components/DateField/DateField.test.cypress.d.ts → src/components/DateField/DateField.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/DateField/index.d.ts +0 -0
- /package/lib/{components → src/components}/DateField/styles.d.ts +0 -0
- /package/lib/{components → src/components}/Divider.d.ts +0 -0
- /package/lib/{components/ErrorText/ErrorText.test.cypress.d.ts → src/components/ErrorText/ErrorText.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/ErrorText/index.d.ts +0 -0
- /package/lib/{components → src/components}/ErrorText/styles.d.ts +0 -0
- /package/lib/{components → src/components}/Flex.d.ts +0 -0
- /package/lib/{components → src/components}/Fontface.d.ts +0 -0
- /package/lib/{components/Footer/Footer.test.cypress.d.ts → src/components/Footer/Footer.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Footer/index.d.ts +0 -0
- /package/lib/{components → src/components}/Footer/styles.d.ts +0 -0
- /package/lib/{components/Header/Header.test.cypress.d.ts → src/components/Header/Header.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Header/index.d.ts +0 -0
- /package/lib/{components → src/components}/Header/styles.d.ts +0 -0
- /package/lib/{components/Heading/Heading.test.cypress.d.ts → src/components/Heading/Heading.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Heading/index.d.ts +0 -0
- /package/lib/{components → src/components}/Heading/styles.d.ts +0 -0
- /package/lib/{components/IconFa/IconFa.test.cypress.d.ts → src/components/IconFa/IconFa.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/IconFa/index.d.ts +0 -0
- /package/lib/{components → src/components}/IconFa/styles.d.ts +0 -0
- /package/lib/{components/InfoBox/InfoBox.test.cypress.d.ts → src/components/InfoBox/InfoBox.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/InfoBox/index.d.ts +0 -0
- /package/lib/{components → src/components}/InfoBox/styles.d.ts +0 -0
- /package/lib/{components/LegendWrapper/LegendWrapper.test.cypress.d.ts → src/components/LegendWrapper/LegendWrapper.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/LegendWrapper/styles.d.ts +0 -0
- /package/lib/{components/Link/Link.test.cypress.d.ts → src/components/Link/Link.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Link/index.d.ts +0 -0
- /package/lib/{components → src/components}/Link/styles.d.ts +0 -0
- /package/lib/{components/Loader/Loader.test.cypress.d.ts → src/components/Loader/Loader.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Loader/index.d.ts +0 -0
- /package/lib/{components → src/components}/Loader/styles.d.ts +0 -0
- /package/lib/{components/Modal/Modal.test.cypress.d.ts → src/components/Modal/Modal.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Modal/index.d.ts +0 -0
- /package/lib/{components → src/components}/Modal/styles.d.ts +0 -0
- /package/lib/{components/Pagination/Pagination.test.cypress.d.ts → src/components/Pagination/Pagination.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Pagination/index.d.ts +0 -0
- /package/lib/{components → src/components}/Pagination/styles.d.ts +0 -0
- /package/lib/{components/PopOver/PopOver.test.cypress.d.ts → src/components/PopOver/PopOver.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/PopOver/index.d.ts +0 -0
- /package/lib/{components → src/components}/PopOver/styles.d.ts +0 -0
- /package/lib/{components/ProgressBar/ProgressBar.test.cypress.d.ts → src/components/ProgressBar/ProgressBar.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/ProgressBar/index.d.ts +0 -0
- /package/lib/{components → src/components}/ProgressBar/styles.d.ts +0 -0
- /package/lib/{components/Radio/Radio.test.cypress.d.ts → src/components/Radio/Radio.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Radio/index.d.ts +0 -0
- /package/lib/{components → src/components}/Radio/styles.d.ts +0 -0
- /package/lib/{components/RadioConsent/RadioConsent.test.cypress.d.ts → src/components/RadioConsent/RadioConsent.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/RadioConsent/index.d.ts +0 -0
- /package/lib/{components → src/components}/RadioConsent/styles.d.ts +0 -0
- /package/lib/{components/Select/Select.test.cypress.d.ts → src/components/Select/Select.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Select/styles.d.ts +0 -0
- /package/lib/{components → src/components}/Spacing/index.d.ts +0 -0
- /package/lib/{components/Step/Step.test.cypress.d.ts → src/components/Step/Step.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Step/index.d.ts +0 -0
- /package/lib/{components → src/components}/Step/styles.d.ts +0 -0
- /package/lib/{components/Text/Text.test.cypress.d.ts → src/components/Text/Text.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Text/index.d.ts +0 -0
- /package/lib/{components → src/components}/Text/styles.d.ts +0 -0
- /package/lib/{components/TextAreaField/TextAreaField.test.cypress.d.ts → src/components/TextAreaField/TextAreaField.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/TextAreaField/index.d.ts +0 -0
- /package/lib/{components → src/components}/TextAreaField/styles.d.ts +0 -0
- /package/lib/{components/TextField/TextField.test.cypress.d.ts → src/components/TextField/TextField.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/TextField/styles.d.ts +0 -0
- /package/lib/{components/Totaliser/Totaliser.test.cypress.d.ts → src/components/Totaliser/Totaliser.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/Totaliser/index.d.ts +0 -0
- /package/lib/{components → src/components}/Totaliser/styles.d.ts +0 -0
- /package/lib/{components/UserBlock/UserBlock.test.cypress.d.ts → src/components/UserBlock/UserBlock.spec.d.ts} +0 -0
- /package/lib/{components → src/components}/UserBlock/index.d.ts +0 -0
- /package/lib/{components → src/components}/UserBlock/styles.d.ts +0 -0
- /package/lib/{components → src/components}/index.d.ts +0 -0
- /package/lib/{hooks → src/hooks}/useEffectBrowser.d.ts +0 -0
- /package/lib/{hooks → src/hooks}/useKey.d.ts +0 -0
- /package/lib/{hooks → src/hooks}/useLayoutEffectBrowser.d.ts +0 -0
- /package/lib/{hooks → src/hooks}/useScrollPosition.d.ts +0 -0
- /package/lib/{themes → src/themes}/bowelbabe.d.ts +0 -0
- /package/lib/{themes → src/themes}/cruk.d.ts +0 -0
- /package/lib/{themes → src/themes}/rfl.d.ts +0 -0
- /package/lib/{themes → src/themes}/su2c.d.ts +0 -0
- /package/lib/{types.d.ts → src/types.d.ts} +0 -0
- /package/lib/{utils → src/utils}/Helper.d.ts +0 -0
- /package/lib/{utils → src/utils}/__tests__/testHelpers.test.d.ts +0 -0
- /package/lib/{utils → src/utils}/debounce.d.ts +0 -0
- /package/lib/{utils → src/utils}/themeUtils.d.ts +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type ThemeType } from "src/components";
|
|
3
|
+
type themeNameType = "CRUK" | "SU2C" | "RFL" | "Bowelbabe";
|
|
4
|
+
export type ThemeTypeWithName = {
|
|
5
|
+
name: themeNameType;
|
|
6
|
+
theme: ThemeType;
|
|
7
|
+
};
|
|
8
|
+
export declare function testAccessibilityForTheme({ componentName, themeName, component, ignoreRules, }: {
|
|
9
|
+
componentName: string;
|
|
10
|
+
themeName: "CRUK" | "SU2C" | "RFL" | "Bowelbabe";
|
|
11
|
+
component: () => React.ReactElement;
|
|
12
|
+
ignoreRules?: string[];
|
|
13
|
+
}): void;
|
|
14
|
+
export declare function testAccessibilityOnAllThemes({ componentName, component, ignoreRules, }: {
|
|
15
|
+
componentName: string;
|
|
16
|
+
component: () => React.ReactElement;
|
|
17
|
+
ignoreRules?: string[];
|
|
18
|
+
}): void;
|
|
19
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__rest as e,__assign as t}from"../../../node_modules/tslib/tslib.es6.js";import n,{useState as r,useRef as o,useCallback as s,useEffect as a}from"react";import{useTheme as i}from"styled-components";import{faChevronRight as l}from"../../../node_modules/@fortawesome/free-solid-svg-icons/index.js";import{useKey as c}from"../../hooks/useKey.js";import{debounce as d}from"../../utils/debounce.js";import{removeCommasFromObjectStringValues as u}from"../../utils/Helper.js";import{Text as m}from"../Text/index.js";import{TextField as f}from"../TextField/index.js";import{IconFa as p}from"../IconFa/index.js";import{crukTheme as h}from"../../themes/cruk.js";import{ScreenReaderOnly as g,ListWrapper as v,List as y,ListItem as E}from"./styles.js";var w=function(w){var b=w.apiKey,x=w.countries,
|
|
1
|
+
import{__rest as e,__assign as t}from"../../../node_modules/tslib/tslib.es6.js";import n,{useState as r,useRef as o,useCallback as s,useEffect as a}from"react";import{useTheme as i}from"styled-components";import{faChevronRight as l}from"../../../node_modules/@fortawesome/free-solid-svg-icons/index.js";import{useKey as c}from"../../hooks/useKey.js";import{debounce as d}from"../../utils/debounce.js";import{removeCommasFromObjectStringValues as u}from"../../utils/Helper.js";import{Text as m}from"../Text/index.js";import{TextField as f}from"../TextField/index.js";import{IconFa as p}from"../IconFa/index.js";import{crukTheme as h}from"../../themes/cruk.js";import{ScreenReaderOnly as g,ListWrapper as v,List as y,ListItem as E}from"./styles.js";var w=function(w){var b=w.apiKey,x=w.countries,I=w.errorMessage,j=w.hasError,T=w.isValid,V=w.isValidVisible,k=w.isInvalidVisible,A=w.label,C=w.hintText,K=w.ref,D=w.onAddressError,F=void 0===D?function(e){console.log(e)}:D,S=w.onAddressSelected,M=w.onChange,_=w.onBlur,B=e(w,["apiKey","countries","errorMessage","hasError","isValid","isValidVisible","isInvalidVisible","label","hintText","ref","onAddressError","onAddressSelected","onChange","onBlur"]),H=r([]),L=H[0],O=H[1],U=r(-1),q=U[0],R=U[1],W=o(null),$=i(),z=t(t({},h),$),G=function(){R(-1),O([])},J=s(d(500,function(e){N(e)}),[]),N=function(e,t){if(void 0===t&&(t=""),0===e.length)return O([]);var n="".concat("https://api.addressy.com/Capture/Interactive/Find/v1.1/json3.ws","?Key=").concat(b,"&Text=").concat(e,"&Container=").concat(t);return void 0!==x&&(n="".concat(n,"&Countries=").concat(x.join(","))),fetch(n).then(function(e){if(!e.ok)throw new Error("Something went wrong please try again");return e.json()}).then(function(e){var t;if((null===(t=null==e?void 0:e.Items)||void 0===t?void 0:t.length)>0&&e.Items[0].Error)throw new Error("Something went wrong please try again");return O(e.Items||[]),null}).catch(function(e){return F(e)}),null},P=function(e){fetch("".concat("https://api.addressy.com/Capture/Interactive/Retrieve/v1/json3.ws","?Key=").concat(b,"&Id=").concat(e)).then(function(e){if(!e.ok)throw new Error("Something went wrong please try again");return e.json()}).then(function(e){var t=e.Items[0],n=u(t);return S(n),G(),null}).catch(function(e){return F(e)})},Q=function(e){return"Address"===e.Type?P(e.Id):(N(e.Text,e.Id),null)},X=function(e){W.current&&e.target instanceof HTMLElement&&!W.current.contains(e.target)&&G()};return a(function(){return document.addEventListener("mousedown",X),function(){document.removeEventListener("mousedown",X)}}),c(function(){G()},{detectKeys:["Escape","Tab"]},[]),n.createElement(n.Fragment,null,n.createElement(f,t({"aria-activedescendant":L.length?"addressOptions-".concat(q):"","aria-owns":"found_addresses","aria-autocomplete":"both","aria-expanded":L.length?"true":"false",autoComplete:"off",hasError:j||!!I,errorMessage:I,hintText:null!=C?C:"Start typing your address or postcode",isValid:T,isValidVisible:V,isInvalidVisible:k,label:null!=A?A:"Home address",ref:K,required:!0,role:"combobox",type:"search"},B,{onKeyDown:function(e){"Enter"===e.key&&L[q]?(e.preventDefault(),"Address"===L[q].Type&&P(L[q].Id),N(L[q].Text,L[q].Id),R(-1)):"ArrowUp"===e.key?(e.preventDefault(),q<=-1&&R(L.length-1),R(q-1)):"ArrowDown"===e.key?(e.preventDefault(),q+1>=L.length&&R(0),R(q+1)):R(-1)},onChange:function(e){J(e.target.value),M&&M(e)},onBlur:function(e){var t=!!L.length;_&&!t&&_(e)}})),!!L.length&&n.createElement(n.Fragment,null,n.createElement(g,{role:"status","aria-live":"assertive"},!!L.length&&"We have found ".concat(L.length," result").concat(1!==L.length?"s":""," matching your search. Use up and down arrow keys to navigate")),n.createElement(v,{ref:W},n.createElement(y,{"aria-label":"found addresses",id:"found_addresses",role:"listbox",theme:z},L.map(function(e,t){return n.createElement(E,{tabIndex:0,id:"addressOptions-".concat(t),$isActive:t===q,key:e.Id,onClick:function(){Q(e)},onKeyDown:function(t){"Enter"===t.key&&Q(e)},role:"option","data-hj-suppress":!0,theme:z},n.createElement(m,{as:"span","data-hj-suppress":!0},e.Text," ",e.Description),"Address"!==e.Type&&n.createElement(n.Fragment,null,n.createElement(g,null,"press enter for these addresses"),n.createElement(p,{faIcon:l})))})))))};export{w as AddressLookup,w as default};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/AddressLookup/index.tsx"],"sourcesContent":["import React, {\n useCallback,\n useEffect,\n useState,\n useRef,\n type InputHTMLAttributes,\n type Ref,\n type FocusEvent,\n type ChangeEvent,\n type KeyboardEvent,\n type ReactNode,\n} from \"react\";\nimport { useTheme } from \"styled-components\";\nimport { faChevronRight } from \"@fortawesome/free-solid-svg-icons\";\n\nimport { type AddressDataType, type AddressOptionsType } from \"../../types\";\nimport { useKey } from \"../../hooks/useKey\";\n\nimport { debounce } from \"../../utils/debounce\";\nimport { removeCommasFromObjectStringValues } from \"../../utils/Helper\";\nimport { Text } from \"../Text\";\nimport { TextField } from \"../TextField\";\nimport { IconFa } from \"../IconFa\";\nimport { crukTheme as defaultTheme } from \"../../themes/cruk\";\n\nimport { ListWrapper, ListItem, ScreenReaderOnly, List } from \"./styles\";\n\nconst FIND_URL =\n \"https://api.addressy.com/Capture/Interactive/Find/v1.1/json3.ws\";\nconst RETRIEVE_URL =\n \"https://api.addressy.com/Capture/Interactive/Retrieve/v1/json3.ws\";\n\nexport type AddressLookupProps = InputHTMLAttributes<HTMLInputElement> & {\n /** api key for loqate */\n apiKey: string;\n /** list of countries codes you want the address look up to search within */\n countries?: string[];\n /** callback function which is passed the selected address data */\n onAddressSelected: (address: AddressDataType) => void;\n /** error message */\n errorMessage?: string;\n /** when true a input has a red border */\n hasError?: boolean;\n /** flag which effects the check or cross icons to the right of the input */\n isValid?: boolean;\n /** flag to hide or show the check icon when valid */\n isValidVisible?: boolean;\n /** flag to hide or show the cross icon when invalid */\n isInvalidVisible?: boolean;\n /** label text */\n label?: string;\n /** hint text text */\n hintText?: ReactNode;\n /** callback function which is passed the error */\n onAddressError?: (error: Error) => void;\n /** onBlur handler */\n onBlur?: (e: FocusEvent) => void;\n /** attach a DOM reference variable to your component */\n ref?: Ref<HTMLInputElement>;\n};\n\n/**\n * This component creates a combobox for a user to type in a post code or partial address and be presented with a of verified addresses.\n * We use Loqate (formerly Addressy and Postcode Anywhere) API v3, we have looked at v4 but it is more expensive without many benefits for our use case.\n * You will need a Loqate api key, the examples below use \"MG17-ZD93-FF33-KF13\" our development key.\n * This component is generally only used for country codes including \"GBR\", \"GGY\", \"IMN\", \"JEY\". An example of this behavior is included bellow.\n */\nexport const AddressLookup = ({\n apiKey,\n countries,\n errorMessage,\n hasError,\n isValid,\n isValidVisible,\n isInvalidVisible,\n label,\n hintText,\n ref,\n onAddressError = (error: Error) => {\n console.log(error);\n },\n onAddressSelected,\n onChange,\n onBlur,\n ...props\n}: AddressLookupProps) => {\n const [addressOptions, setAddressOptions] = useState<AddressOptionsType[]>(\n [],\n );\n const [activeOption, setActiveOption] = useState(-1);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const foundTheme = useTheme();\n const theme = {\n ...defaultTheme,\n ...foundTheme,\n };\n\n const clearOptions = () => {\n setActiveOption(-1);\n setAddressOptions([]);\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const searchDebounced = useCallback(\n debounce(500, (query: string) => {\n search(query);\n }),\n [],\n );\n\n const search = (query: string, id = \"\") => {\n if (query.length === 0) return setAddressOptions([]);\n let searchUrl = `${FIND_URL}?Key=${apiKey}&Text=${query}&Container=${id}`;\n if (countries !== undefined) {\n searchUrl = `${searchUrl}&Countries=${countries.join(\",\")}`;\n }\n fetch(searchUrl)\n .then((res: Response) => {\n if (!res.ok) throw new Error(\"Something went wrong please try again\");\n return res.json();\n })\n .then((data: { Items: AddressOptionsType[] }) => {\n // Occasionally get the error \"The query didn't respond fast enough, it may be too complex.\"\n // returned with a 200 response. Example query \"n17 6t\"\n if (data.Items[0].Error)\n throw new Error(\"Something went wrong please try again\");\n setAddressOptions(data.Items || []);\n return null;\n })\n .catch((err) => onAddressError(err as Error));\n return null;\n };\n\n const getAddress = (id: string) => {\n fetch(`${RETRIEVE_URL}?Key=${apiKey}&Id=${id}`)\n .then((res: Response) => {\n if (!res.ok) throw new Error(\"Something went wrong please try again\");\n return res.json();\n })\n .then((data: { Items: AddressDataType[] }) => {\n const selectedAddress = data.Items[0];\n const selectedAddressWithoutCommas =\n removeCommasFromObjectStringValues<AddressDataType>(selectedAddress);\n onAddressSelected(selectedAddressWithoutCommas);\n clearOptions();\n return null;\n })\n .catch((err) => onAddressError(err as Error));\n };\n\n const selectAddress = (address: AddressOptionsType) => {\n if (address.Type === \"Address\") return getAddress(address.Id);\n search(address.Text, address.Id);\n return null;\n };\n\n const handleKeyDown = (e: KeyboardEvent): void => {\n if (e.key === \"Enter\" && addressOptions[activeOption]) {\n e.preventDefault();\n if (addressOptions[activeOption].Type === \"Address\")\n getAddress(addressOptions[activeOption].Id);\n search(\n addressOptions[activeOption].Text,\n addressOptions[activeOption].Id,\n );\n setActiveOption(-1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n if (activeOption <= -1) setActiveOption(addressOptions.length - 1);\n setActiveOption(activeOption - 1);\n } else if (e.key === \"ArrowDown\") {\n e.preventDefault();\n if (activeOption + 1 >= addressOptions.length) setActiveOption(0);\n setActiveOption(activeOption + 1);\n } else {\n setActiveOption(-1);\n }\n };\n\n const handleChange = (e: ChangeEvent<HTMLInputElement>) => {\n searchDebounced(e.target.value);\n if (onChange) onChange(e);\n };\n\n const handleBlur = (e: FocusEvent) => {\n const isOptionsOpen = !!addressOptions.length;\n if (onBlur && !isOptionsOpen) onBlur(e);\n };\n\n const handleClickOutside = (event: MouseEvent) => {\n if (\n wrapperRef.current &&\n event.target instanceof HTMLElement &&\n !wrapperRef.current.contains(event.target)\n )\n clearOptions();\n };\n\n useEffect(() => {\n document.addEventListener(\"mousedown\", handleClickOutside);\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n };\n });\n\n useKey(\n () => {\n clearOptions();\n },\n {\n detectKeys: [\"Escape\", \"Tab\"],\n },\n [],\n );\n\n return (\n <>\n <TextField\n aria-activedescendant={\n addressOptions.length ? `addressOptions-${activeOption}` : \"\"\n }\n aria-owns=\"found_addresses\"\n aria-autocomplete=\"both\"\n aria-expanded={addressOptions.length ? \"true\" : \"false\"}\n autoComplete=\"off\"\n hasError={hasError || !!errorMessage}\n errorMessage={errorMessage}\n hintText={hintText ?? \"Start typing your address or postcode\"}\n isValid={isValid}\n isValidVisible={isValidVisible}\n isInvalidVisible={isInvalidVisible}\n label={label ?? \"Home address\"}\n ref={ref}\n required\n role=\"combobox\"\n type=\"search\"\n {...props}\n onKeyDown={handleKeyDown}\n onChange={handleChange}\n onBlur={handleBlur}\n />\n\n {!!addressOptions.length && (\n <>\n <ScreenReaderOnly role=\"status\" aria-live=\"assertive\">\n {!!addressOptions.length &&\n `We have found ${addressOptions.length} result${\n addressOptions.length !== 1 ? \"s\" : \"\"\n } matching your search. Use up and down arrow keys to navigate`}\n </ScreenReaderOnly>\n <ListWrapper ref={wrapperRef}>\n <List\n aria-label=\"found addresses\"\n id=\"found_addresses\"\n role=\"listbox\"\n theme={theme}\n >\n {addressOptions.map((address, index) => (\n <ListItem\n tabIndex={0}\n id={`addressOptions-${index}`}\n $isActive={index === activeOption}\n key={address.Id}\n onClick={() => {\n selectAddress(address);\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\") {\n selectAddress(address);\n }\n }}\n role=\"option\"\n data-hj-suppress\n theme={theme}\n >\n <Text as=\"span\" data-hj-suppress>\n {address.Text} {address.Description}\n </Text>\n {address.Type !== \"Address\" && (\n <>\n <ScreenReaderOnly>\n press enter for these addresses\n </ScreenReaderOnly>\n <IconFa faIcon={faChevronRight} />\n </>\n )}\n </ListItem>\n ))}\n </List>\n </ListWrapper>\n </>\n )}\n </>\n );\n};\n\nexport default AddressLookup;\n"],"names":["AddressLookup","_a","apiKey","countries","errorMessage","hasError","isValid","isValidVisible","isInvalidVisible","label","hintText","ref","_b","onAddressError","error","console","log","onAddressSelected","onChange","onBlur","props","__rest","_c","useState","addressOptions","setAddressOptions","_d","activeOption","setActiveOption","wrapperRef","useRef","foundTheme","useTheme","theme","__assign","defaultTheme","clearOptions","searchDebounced","useCallback","debounce","query","search","id","length","searchUrl","concat","undefined","join","fetch","then","res","ok","Error","json","data","Items","catch","err","getAddress","selectedAddress","selectedAddressWithoutCommas","removeCommasFromObjectStringValues","selectAddress","address","Type","Id","Text","handleClickOutside","event","current","target","HTMLElement","contains","useEffect","document","addEventListener","removeEventListener","useKey","detectKeys","React","createElement","Fragment","TextField","autoComplete","required","role","type","onKeyDown","e","key","preventDefault","value","isOptionsOpen","ScreenReaderOnly","ListWrapper","List","map","index","ListItem","tabIndex","onClick","as","Description","IconFa","faIcon","faChevronRight"],"mappings":"2uBA2BA,IAwCaA,EAAgB,SAACC,GAC5B,IAAAC,EAAMD,EAAAC,OACNC,cACAC,EAAYH,EAAAG,aACZC,EAAQJ,EAAAI,SACRC,EAAOL,EAAAK,QACPC,EAAcN,EAAAM,eACdC,qBACAC,EAAKR,EAAAQ,MACLC,EAAQT,EAAAS,SACRC,EAAGV,EAAAU,IACHC,EAECX,EAAAY,eAFDA,OAAc,IAAAD,EAAG,SAACE,GAChBC,QAAQC,IAAIF,EACb,EAAAF,EACDK,EAAiBhB,EAAAgB,kBACjBC,EAAQjB,EAAAiB,SACRC,EAAMlB,EAAAkB,OACHC,EAAKC,EAAApB,EAjBoB,kLAmBtBqB,EAAsCC,EAC1C,IADKC,EAAcF,EAAA,GAAEG,EAAiBH,EAAA,GAGlCI,EAAkCH,GAAW,GAA5CI,EAAYD,EAAA,GAAEE,EAAeF,EAAA,GAC9BG,EAAaC,EAAuB,MACpCC,EAAaC,IACbC,EACDC,EAAAA,EAAA,CAAA,EAAAC,GACAJ,GAGCK,EAAe,WACnBR,GAAgB,GAChBH,EAAkB,GACnB,EAGKY,EAAkBC,EACtBC,EAAS,KAAK,SAACC,GACbC,EAAOD,EACR,IACD,IAGIC,EAAS,SAACD,EAAeE,GAC7B,QAD6B,IAAAA,IAAAA,EAAO,IACf,IAAjBF,EAAMG,OAAc,OAAOlB,EAAkB,IACjD,IAAImB,EAAY,GAAAC,OApFlB,kEAoF6B,SAAAA,OAAQ3C,EAAM,UAAA2C,OAASL,EAAK,eAAAK,OAAcH,GAkBrE,YAjBkBI,IAAd3C,IACFyC,EAAY,GAAGC,OAAAD,EAAuB,eAAAC,OAAA1C,EAAU4C,KAAK,OAEvDC,MAAMJ,GACHK,MAAK,SAACC,GACL,IAAKA,EAAIC,GAAI,MAAM,IAAIC,MAAM,yCAC7B,OAAOF,EAAIG,MACZ,IACAJ,MAAK,SAACK,GAGL,GAAIA,EAAKC,MAAM,GAAGH,MAChB,MAAM,IAAIA,MAAM,yCAElB,OADA3B,EAAkB6B,EAAKC,OAAS,IACzB,IACR,IACAC,OAAM,SAACC,GAAQ,OAAA5C,EAAe4C,MAC1B,IACR,EAEKC,EAAa,SAAChB,GAClBM,MAAM,UAxGR,oEAwGuB,SAAAH,OAAQ3C,EAAa,QAAA2C,OAAAH,IACvCO,MAAK,SAACC,GACL,IAAKA,EAAIC,GAAI,MAAM,IAAIC,MAAM,yCAC7B,OAAOF,EAAIG,MACZ,IACAJ,MAAK,SAACK,GACL,IAAMK,EAAkBL,EAAKC,MAAM,GAC7BK,EACJC,EAAoDF,GAGtD,OAFA1C,EAAkB2C,GAClBxB,IACO,IACR,IACAoB,OAAM,SAACC,GAAQ,OAAA5C,EAAe4C,KAClC,EAEKK,EAAgB,SAACC,GACrB,MAAqB,YAAjBA,EAAQC,KAA2BN,EAAWK,EAAQE,KAC1DxB,EAAOsB,EAAQG,KAAMH,EAAQE,IACtB,KACR,EAmCKE,EAAqB,SAACC,GAExBvC,EAAWwC,SACXD,EAAME,kBAAkBC,cACvB1C,EAAWwC,QAAQG,SAASJ,EAAME,SAEnClC,GACH,EAmBD,OAjBAqC,GAAU,WAER,OADAC,SAASC,iBAAiB,YAAaR,GAChC,WACLO,SAASE,oBAAoB,YAAaT,EAC3C,CACH,IAEAU,GACE,WACEzC,GACF,GACA,CACE0C,WAAY,CAAC,SAAU,QAEzB,IAIAC,EAAAC,cAAAD,EAAAE,SAAA,KACEF,EAACC,cAAAE,6BAEG1D,EAAemB,OAAS,kBAAAE,OAAkBlB,GAAiB,GAAE,YAErD,kBAAiB,oBACT,OACH,gBAAAH,EAAemB,OAAS,OAAS,QAChDwC,aAAa,MACb9E,SAAUA,KAAcD,EACxBA,aAAcA,EACdM,SAAUA,QAAAA,EAAY,wCACtBJ,QAASA,EACTC,eAAgBA,EAChBC,iBAAkBA,EAClBC,MAAOA,QAAAA,EAAS,eAChBE,IAAKA,EACLyE,UAAQ,EACRC,KAAK,WACLC,KAAK,UACDlE,GACJmE,UAjFgB,SAACC,GACP,UAAVA,EAAEC,KAAmBjE,EAAeG,IACtC6D,EAAEE,iBACwC,YAAtClE,EAAeG,GAAcqC,MAC/BN,EAAWlC,EAAeG,GAAcsC,IAC1CxB,EACEjB,EAAeG,GAAcuC,KAC7B1C,EAAeG,GAAcsC,IAE/BrC,GAAgB,IACG,YAAV4D,EAAEC,KACXD,EAAEE,iBACE/D,IAAkB,GAAEC,EAAgBJ,EAAemB,OAAS,GAChEf,EAAgBD,EAAe,IACZ,cAAV6D,EAAEC,KACXD,EAAEE,iBACE/D,EAAe,GAAKH,EAAemB,QAAQf,EAAgB,GAC/DA,EAAgBD,EAAe,IAE/BC,GAAgB,EAEnB,EA6DKV,SA3De,SAACsE,GACpBnD,EAAgBmD,EAAElB,OAAOqB,OACrBzE,GAAUA,EAASsE,EACxB,EAyDKrE,OAvDa,SAACqE,GAClB,IAAMI,IAAkBpE,EAAemB,OACnCxB,IAAWyE,GAAezE,EAAOqE,EACtC,OAuDMhE,EAAemB,QAChBoC,EAAAC,cAAAD,EAAAE,SAAA,KACEF,EAAAC,cAACa,EAAgB,CAACR,KAAK,SAAQ,YAAW,eACrC7D,EAAemB,QAChB,iBAAAE,OAAiBrB,EAAemB,yBACJ,IAA1BnB,EAAemB,OAAe,IAAM,qEAG1CoC,EAAAC,cAACc,EAAW,CAACnF,IAAKkB,GAChBkD,EAACC,cAAAe,gBACY,kBACXrD,GAAG,kBACH2C,KAAK,UACLpD,MAAOA,GAENT,EAAewE,KAAI,SAACjC,EAASkC,GAAU,OACtClB,EAAAC,cAACkB,EAAQ,CACPC,SAAU,EACVzD,GAAI,kBAAAG,OAAkBoD,aACXA,IAAUtE,EACrB8D,IAAK1B,EAAQE,GACbmC,QAAS,WACPtC,EAAcC,EAChB,EACAwB,UAAW,SAACC,GACI,UAAVA,EAAEC,KACJ3B,EAAcC,EAElB,EACAsB,KAAK,SAEL,oBAAA,EAAApD,MAAOA,GAEP8C,EAAAC,cAACd,EAAI,CAACmC,GAAG,OAAM,oBAAA,GACZtC,EAAQG,SAAOH,EAAQuC,aAER,YAAjBvC,EAAQC,MACPe,EAAAC,cAAAD,EAAAE,SAAA,KACEF,EAAAC,cAACa,EAEkB,KAAA,mCACnBd,EAAAC,cAACuB,EAAO,CAAAC,OAAQC,KA1BgB,OAqCtD"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/AddressLookup/index.tsx"],"sourcesContent":["import React, {\n useCallback,\n useEffect,\n useState,\n useRef,\n type InputHTMLAttributes,\n type Ref,\n type FocusEvent,\n type ChangeEvent,\n type KeyboardEvent,\n type ReactNode,\n} from \"react\";\nimport { useTheme } from \"styled-components\";\nimport { faChevronRight } from \"@fortawesome/free-solid-svg-icons\";\n\nimport { type AddressDataType, type AddressOptionsType } from \"../../types\";\nimport { useKey } from \"../../hooks/useKey\";\n\nimport { debounce } from \"../../utils/debounce\";\nimport { removeCommasFromObjectStringValues } from \"../../utils/Helper\";\nimport { Text } from \"../Text\";\nimport { TextField } from \"../TextField\";\nimport { IconFa } from \"../IconFa\";\nimport { crukTheme as defaultTheme } from \"../../themes/cruk\";\n\nimport { ListWrapper, ListItem, ScreenReaderOnly, List } from \"./styles\";\n\nconst FIND_URL =\n \"https://api.addressy.com/Capture/Interactive/Find/v1.1/json3.ws\";\nconst RETRIEVE_URL =\n \"https://api.addressy.com/Capture/Interactive/Retrieve/v1/json3.ws\";\n\nexport type AddressLookupProps = InputHTMLAttributes<HTMLInputElement> & {\n /** api key for loqate */\n apiKey: string;\n /** list of countries codes you want the address look up to search within */\n countries?: string[];\n /** callback function which is passed the selected address data */\n onAddressSelected: (address: AddressDataType) => void;\n /** error message */\n errorMessage?: string;\n /** when true a input has a red border */\n hasError?: boolean;\n /** flag which effects the check or cross icons to the right of the input */\n isValid?: boolean;\n /** flag to hide or show the check icon when valid */\n isValidVisible?: boolean;\n /** flag to hide or show the cross icon when invalid */\n isInvalidVisible?: boolean;\n /** label text */\n label?: string;\n /** hint text text */\n hintText?: ReactNode;\n /** callback function which is passed the error */\n onAddressError?: (error: Error) => void;\n /** onBlur handler */\n onBlur?: (e: FocusEvent) => void;\n /** attach a DOM reference variable to your component */\n ref?: Ref<HTMLInputElement>;\n};\n\n/**\n * This component creates a combobox for a user to type in a post code or partial address and be presented with a of verified addresses.\n * We use Loqate (formerly Addressy and Postcode Anywhere) API v3, we have looked at v4 but it is more expensive without many benefits for our use case.\n * You will need a Loqate api key, the examples below use \"MG17-ZD93-FF33-KF13\" our development key.\n * This component is generally only used for country codes including \"GBR\", \"GGY\", \"IMN\", \"JEY\". An example of this behavior is included bellow.\n */\nexport const AddressLookup = ({\n apiKey,\n countries,\n errorMessage,\n hasError,\n isValid,\n isValidVisible,\n isInvalidVisible,\n label,\n hintText,\n ref,\n onAddressError = (error: Error) => {\n console.log(error);\n },\n onAddressSelected,\n onChange,\n onBlur,\n ...props\n}: AddressLookupProps) => {\n const [addressOptions, setAddressOptions] = useState<AddressOptionsType[]>(\n [],\n );\n const [activeOption, setActiveOption] = useState(-1);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const foundTheme = useTheme();\n const theme = {\n ...defaultTheme,\n ...foundTheme,\n };\n\n const clearOptions = () => {\n setActiveOption(-1);\n setAddressOptions([]);\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const searchDebounced = useCallback(\n debounce(500, (query: string) => {\n search(query);\n }),\n [],\n );\n\n const search = (query: string, id = \"\") => {\n if (query.length === 0) return setAddressOptions([]);\n let searchUrl = `${FIND_URL}?Key=${apiKey}&Text=${query}&Container=${id}`;\n if (countries !== undefined) {\n searchUrl = `${searchUrl}&Countries=${countries.join(\",\")}`;\n }\n fetch(searchUrl)\n .then((res: Response) => {\n if (!res.ok) throw new Error(\"Something went wrong please try again\");\n return res.json();\n })\n .then((data: { Items: AddressOptionsType[] }) => {\n // Occasionally get the error \"The query didn't respond fast enough, it may be too complex.\"\n // returned with a 200 response. Example query \"n17 6t\"\n if (data?.Items?.length > 0 && data.Items[0].Error)\n throw new Error(\"Something went wrong please try again\");\n setAddressOptions(data.Items || []);\n return null;\n })\n .catch((err) => onAddressError(err as Error));\n return null;\n };\n\n const getAddress = (id: string) => {\n fetch(`${RETRIEVE_URL}?Key=${apiKey}&Id=${id}`)\n .then((res: Response) => {\n if (!res.ok) throw new Error(\"Something went wrong please try again\");\n return res.json();\n })\n .then((data: { Items: AddressDataType[] }) => {\n const selectedAddress = data.Items[0];\n const selectedAddressWithoutCommas =\n removeCommasFromObjectStringValues<AddressDataType>(selectedAddress);\n onAddressSelected(selectedAddressWithoutCommas);\n clearOptions();\n return null;\n })\n .catch((err) => onAddressError(err as Error));\n };\n\n const selectAddress = (address: AddressOptionsType) => {\n if (address.Type === \"Address\") return getAddress(address.Id);\n search(address.Text, address.Id);\n return null;\n };\n\n const handleKeyDown = (e: KeyboardEvent): void => {\n if (e.key === \"Enter\" && addressOptions[activeOption]) {\n e.preventDefault();\n if (addressOptions[activeOption].Type === \"Address\")\n getAddress(addressOptions[activeOption].Id);\n search(\n addressOptions[activeOption].Text,\n addressOptions[activeOption].Id,\n );\n setActiveOption(-1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n if (activeOption <= -1) setActiveOption(addressOptions.length - 1);\n setActiveOption(activeOption - 1);\n } else if (e.key === \"ArrowDown\") {\n e.preventDefault();\n if (activeOption + 1 >= addressOptions.length) setActiveOption(0);\n setActiveOption(activeOption + 1);\n } else {\n setActiveOption(-1);\n }\n };\n\n const handleChange = (e: ChangeEvent<HTMLInputElement>) => {\n searchDebounced(e.target.value);\n if (onChange) onChange(e);\n };\n\n const handleBlur = (e: FocusEvent) => {\n const isOptionsOpen = !!addressOptions.length;\n if (onBlur && !isOptionsOpen) onBlur(e);\n };\n\n const handleClickOutside = (event: MouseEvent) => {\n if (\n wrapperRef.current &&\n event.target instanceof HTMLElement &&\n !wrapperRef.current.contains(event.target)\n )\n clearOptions();\n };\n\n useEffect(() => {\n document.addEventListener(\"mousedown\", handleClickOutside);\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n };\n });\n\n useKey(\n () => {\n clearOptions();\n },\n {\n detectKeys: [\"Escape\", \"Tab\"],\n },\n [],\n );\n\n return (\n <>\n <TextField\n aria-activedescendant={\n addressOptions.length ? `addressOptions-${activeOption}` : \"\"\n }\n aria-owns=\"found_addresses\"\n aria-autocomplete=\"both\"\n aria-expanded={addressOptions.length ? \"true\" : \"false\"}\n autoComplete=\"off\"\n hasError={hasError || !!errorMessage}\n errorMessage={errorMessage}\n hintText={hintText ?? \"Start typing your address or postcode\"}\n isValid={isValid}\n isValidVisible={isValidVisible}\n isInvalidVisible={isInvalidVisible}\n label={label ?? \"Home address\"}\n ref={ref}\n required\n role=\"combobox\"\n type=\"search\"\n {...props}\n onKeyDown={handleKeyDown}\n onChange={handleChange}\n onBlur={handleBlur}\n />\n\n {!!addressOptions.length && (\n <>\n <ScreenReaderOnly role=\"status\" aria-live=\"assertive\">\n {!!addressOptions.length &&\n `We have found ${addressOptions.length} result${\n addressOptions.length !== 1 ? \"s\" : \"\"\n } matching your search. Use up and down arrow keys to navigate`}\n </ScreenReaderOnly>\n <ListWrapper ref={wrapperRef}>\n <List\n aria-label=\"found addresses\"\n id=\"found_addresses\"\n role=\"listbox\"\n theme={theme}\n >\n {addressOptions.map((address, index) => (\n <ListItem\n tabIndex={0}\n id={`addressOptions-${index}`}\n $isActive={index === activeOption}\n key={address.Id}\n onClick={() => {\n selectAddress(address);\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\") {\n selectAddress(address);\n }\n }}\n role=\"option\"\n data-hj-suppress\n theme={theme}\n >\n <Text as=\"span\" data-hj-suppress>\n {address.Text} {address.Description}\n </Text>\n {address.Type !== \"Address\" && (\n <>\n <ScreenReaderOnly>\n press enter for these addresses\n </ScreenReaderOnly>\n <IconFa faIcon={faChevronRight} />\n </>\n )}\n </ListItem>\n ))}\n </List>\n </ListWrapper>\n </>\n )}\n </>\n );\n};\n\nexport default AddressLookup;\n"],"names":["AddressLookup","_a","apiKey","countries","errorMessage","hasError","isValid","isValidVisible","isInvalidVisible","label","hintText","ref","_b","onAddressError","error","console","log","onAddressSelected","onChange","onBlur","props","__rest","_c","useState","addressOptions","setAddressOptions","_d","activeOption","setActiveOption","wrapperRef","useRef","foundTheme","useTheme","theme","__assign","defaultTheme","clearOptions","searchDebounced","useCallback","debounce","query","search","id","length","searchUrl","concat","undefined","join","fetch","then","res","ok","Error","json","data","Items","catch","err","getAddress","selectedAddress","selectedAddressWithoutCommas","removeCommasFromObjectStringValues","selectAddress","address","Type","Id","Text","handleClickOutside","event","current","target","HTMLElement","contains","useEffect","document","addEventListener","removeEventListener","useKey","detectKeys","React","createElement","Fragment","TextField","autoComplete","required","role","type","onKeyDown","e","key","preventDefault","value","isOptionsOpen","ScreenReaderOnly","ListWrapper","List","map","index","ListItem","tabIndex","onClick","as","Description","IconFa","faIcon","faChevronRight"],"mappings":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__makeTemplateObject as n}from"../../../node_modules/tslib/tslib.es6.js";import o from"styled-components";var i,r,e,t,p=o.div(i||(i=n(["\n position: relative;\n"],["\n position: relative;\n"]))),d=o.ul(r||(r=n(["\n background-color: ",";\n border-radius: 3px;\n border: 2px solid #ccc;\n box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.2);\n list-style: none;\n margin-top: 0;\n max-height: 400px;\n overflow-y: auto;\n padding: 0;\n position: absolute;\n width: 100%;\n z-index: 999;\n"],["\n background-color: ",";\n border-radius: 3px;\n border: 2px solid #ccc;\n box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.2);\n list-style: none;\n margin-top: 0;\n max-height: 400px;\n overflow-y: auto;\n padding: 0;\n position: absolute;\n width: 100%;\n z-index: 999;\n"])),
|
|
1
|
+
import{__makeTemplateObject as n}from"../../../node_modules/tslib/tslib.es6.js";import o from"styled-components";var i,r,e,t,p=o.div(i||(i=n(["\n position: relative;\n"],["\n position: relative;\n"]))),d=o.ul(r||(r=n(["\n background-color: ",";\n border-radius: 3px;\n border: 2px solid #ccc;\n box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.2);\n list-style: none;\n margin-top: 0;\n max-height: 400px;\n overflow-y: auto;\n padding: 0;\n position: absolute;\n width: 100%;\n z-index: 999;\n"],["\n background-color: ",";\n border-radius: 3px;\n border: 2px solid #ccc;\n box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.2);\n list-style: none;\n margin-top: 0;\n max-height: 400px;\n overflow-y: auto;\n padding: 0;\n position: absolute;\n width: 100%;\n z-index: 999;\n"])),function(n){return n.theme.colors.backgroundLight}),a=o.li(e||(e=n(["\n align-items: center;\n background-color: ",";\n cursor: pointer;\n display: flex;\n justify-content: space-between;\n padding: 5px;\n &:hover,\n &:focus {\n background-color: #ddd;\n }\n"],["\n align-items: center;\n background-color: ",";\n cursor: pointer;\n display: flex;\n justify-content: space-between;\n padding: 5px;\n &:hover,\n &:focus {\n background-color: #ddd;\n }\n"])),function(n){var o=n.theme;return n.$isActive?o.colors.backgroundMid:o.colors.backgroundLight}),s=o.div(t||(t=n(["\n border: 0px;\n clip: rect(0px, 0px, 0px, 0px);\n height: 1px;\n margin-bottom: -1px;\n margin-right: -1px;\n overflow: hidden;\n padding: 0px;\n position: absolute;\n white-space: nowrap;\n width: 1px;\n"],["\n border: 0px;\n clip: rect(0px, 0px, 0px, 0px);\n height: 1px;\n margin-bottom: -1px;\n margin-right: -1px;\n overflow: hidden;\n padding: 0px;\n position: absolute;\n white-space: nowrap;\n width: 1px;\n"])));export{d as List,a as ListItem,p as ListWrapper,s as ScreenReaderOnly};
|
|
2
2
|
//# sourceMappingURL=styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sources":["../../../../src/components/AddressLookup/styles.ts"],"sourcesContent":["import styled from \"styled-components\";\nimport { type ThemeType } from \"../../types\";\n\ninterface ListWrapperProps extends React.HTMLProps<HTMLDivElement> {\n tabIndex?: number;\n}\n\ntype ListProps = {\n theme: ThemeType;\n $isActive?: boolean;\n};\n\nexport const ListWrapper = styled.div<ListWrapperProps>`\n position: relative;\n`;\n\nexport const List = styled.ul<\n ListProps & { ref?: React.Ref<HTMLUListElement> }\n>`\n background-color: ${({ theme }) => theme.colors.backgroundLight};\n border-radius: 3px;\n border: 2px solid #ccc;\n box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.2);\n list-style: none;\n margin-top: 0;\n max-height: 400px;\n overflow-y: auto;\n padding: 0;\n position: absolute;\n width: 100%;\n z-index: 999;\n`;\n\nexport const ListItem = styled.li<\n ListProps & {\n ref?: React.Ref<HTMLLIElement>;\n }\n>`\n align-items: center;\n background-color: ${({ theme, $isActive }: ListProps) =>\n $isActive ? theme.colors.backgroundMid : theme.colors.backgroundLight};\n cursor: pointer;\n display: flex;\n justify-content: space-between;\n padding: 5px;\n &:hover,\n &:focus {\n background-color: #ddd;\n }\n`;\n\n// TODO move to its own component\nexport const ScreenReaderOnly = styled.div`\n border: 0px;\n clip: rect(0px, 0px, 0px, 0px);\n height: 1px;\n margin-bottom: -1px;\n margin-right: -1px;\n overflow: hidden;\n padding: 0px;\n position: absolute;\n white-space: nowrap;\n width: 1px;\n`;\n"],"names":["ListWrapper","styled","div","templateObject_1","__makeTemplateObject","List","ul","templateObject_2","_a","theme","colors","backgroundLight","ListItem","li","templateObject_3","$isActive","backgroundMid","ScreenReaderOnly","templateObject_4"],"mappings":"
|
|
1
|
+
{"version":3,"file":"styles.js","sources":["../../../../src/components/AddressLookup/styles.ts"],"sourcesContent":["import styled from \"styled-components\";\nimport { type ThemeType } from \"../../types\";\n\ninterface ListWrapperProps extends React.HTMLProps<HTMLDivElement> {\n tabIndex?: number;\n}\n\ntype ListProps = {\n theme: ThemeType;\n $isActive?: boolean;\n};\n\nexport const ListWrapper = styled.div<ListWrapperProps>`\n position: relative;\n`;\n\nexport const List = styled.ul<\n ListProps & { ref?: React.Ref<HTMLUListElement> }\n>`\n background-color: ${({ theme }) => theme.colors.backgroundLight};\n border-radius: 3px;\n border: 2px solid #ccc;\n box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.2);\n list-style: none;\n margin-top: 0;\n max-height: 400px;\n overflow-y: auto;\n padding: 0;\n position: absolute;\n width: 100%;\n z-index: 999;\n`;\n\nexport const ListItem = styled.li<\n ListProps & {\n ref?: React.Ref<HTMLLIElement>;\n }\n>`\n align-items: center;\n background-color: ${({ theme, $isActive }: ListProps) =>\n $isActive ? theme.colors.backgroundMid : theme.colors.backgroundLight};\n cursor: pointer;\n display: flex;\n justify-content: space-between;\n padding: 5px;\n &:hover,\n &:focus {\n background-color: #ddd;\n }\n`;\n\n// TODO move to its own component\nexport const ScreenReaderOnly = styled.div`\n border: 0px;\n clip: rect(0px, 0px, 0px, 0px);\n height: 1px;\n margin-bottom: -1px;\n margin-right: -1px;\n overflow: hidden;\n padding: 0px;\n position: absolute;\n white-space: nowrap;\n width: 1px;\n`;\n"],"names":["ListWrapper","styled","div","templateObject_1","__makeTemplateObject","List","ul","templateObject_2","_a","theme","colors","backgroundLight","ListItem","li","templateObject_3","$isActive","backgroundMid","ScreenReaderOnly","templateObject_4"],"mappings":"iHAYO,YAAMA,EAAcC,EAAOC,IAAGC,IAAAA,EAAAC,EAAA,CAAA,6BAAA,CAAkB,gCAI1CC,EAAOJ,EAAOK,GAAEC,IAAAA,EAAAH,EAAA,CAAA,yBAAA,kQAAA,CAE5B,yBACgE,oQAA3C,SAACI,GAAc,OAAPA,EAAAC,MAAaC,OAAOC,eAAb,GAcxBC,EAAWX,EAAOY,GAAEC,IAAAA,EAAAV,EAAA,CAAA,iDAAA,4JAAA,CAIhC,iDAGwE,8JADnD,SAACI,OAAEC,EAAKD,EAAAC,MAC1B,OADqCD,EAAAO,UACzBN,EAAMC,OAAOM,cAAgBP,EAAMC,OAAOC,eAAtD,GAYSM,EAAmBhB,EAAOC,IAAGgB,IAAAA,EAAAd,EAAA,CAAA,4NAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/Avatar/index.tsx"],"sourcesContent":["import React, { type ImgHTMLAttributes } from \"react\";\nimport { useTheme } from \"styled-components\";\n\nimport { crukTheme as defaultTheme } from \"../../themes/cruk\";\n\nimport { StyledAvatar } from \"./styles\";\n\nexport type AvatarProps = ImgHTMLAttributes<HTMLElement> & {\n /** name of user/entity */\n name?: string;\n /** image url */\n url?: string;\n /** image size */\n size?: \"s\" | \"m\" | \"l\" | \"xl\";\n};\n\n/**\n *\n * You can use an avatar to display ownership of an item of content. If you pass a URL of an image that will be displayed otherwise the first letter of the name will be used to display a branded avatar.\n */\nexport function Avatar({\n url,\n name,\n size = \"m\",\n alt = \"\",\n ...rest\n}: AvatarProps) {\n const foundTheme = useTheme();\n const theme = {\n ...defaultTheme,\n ...foundTheme,\n };\n\n const avatarUrl = () => {\n if (url) return url;\n const fileName =\n name &&\n typeof name === \"string\" &&\n name !== \"Anonymous\" &&\n /[a-z]/i.exec(name[0].trim())\n ? `icon-avatar-${name[0].trim().toUpperCase()}.png`\n : \"icon-avatar-Anonymous.png\";\n\n return `${theme.avatar.path}${fileName}`;\n };\n\n return (\n <StyledAvatar\n {...rest}\n $size={theme.avatar[size || \"m\"]}\n src={avatarUrl()}\n alt={alt}\n />\n );\n}\n\nexport default Avatar;\n"],"names":["Avatar","_a","url","name","_b","size","_c","alt","rest","__rest","foundTheme","useTheme","theme","__assign","defaultTheme","React","createElement","StyledAvatar","avatar","src","fileName","exec","trim","concat","toUpperCase","path","avatarUrl"],"mappings":"8OAoBM,SAAUA,EAAOC,GACrB,IAAAC,QACAC,SACAC,EAAAH,EAAAI,KAAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/Avatar/index.tsx"],"sourcesContent":["import React, { type ImgHTMLAttributes } from \"react\";\nimport { useTheme } from \"styled-components\";\n\nimport { crukTheme as defaultTheme } from \"../../themes/cruk\";\n\nimport { StyledAvatar } from \"./styles\";\n\nexport type AvatarProps = ImgHTMLAttributes<HTMLElement> & {\n /** name of user/entity */\n name?: string;\n /** image url */\n url?: string;\n /** image size */\n size?: \"s\" | \"m\" | \"l\" | \"xl\";\n};\n\n/**\n *\n * You can use an avatar to display ownership of an item of content. If you pass a URL of an image that will be displayed otherwise the first letter of the name will be used to display a branded avatar.\n */\nexport function Avatar({\n url,\n name,\n size = \"m\",\n alt = \"\",\n ...rest\n}: AvatarProps) {\n const foundTheme = useTheme();\n const theme = {\n ...defaultTheme,\n ...foundTheme,\n };\n\n const avatarUrl = () => {\n if (url) return url;\n const fileName =\n name &&\n typeof name === \"string\" &&\n name !== \"Anonymous\" &&\n /[a-z]/i.exec(name[0].trim())\n ? `icon-avatar-${name[0].trim().toUpperCase()}.png`\n : \"icon-avatar-Anonymous.png\";\n\n return `${theme.avatar.path}${fileName}`;\n };\n\n return (\n <StyledAvatar\n {...rest}\n $size={theme.avatar[size || \"m\"]}\n src={avatarUrl()}\n alt={alt}\n />\n );\n}\n\nexport default Avatar;\n"],"names":["Avatar","_a","url","name","_b","size","_c","alt","rest","__rest","foundTheme","useTheme","theme","__assign","defaultTheme","React","createElement","StyledAvatar","avatar","src","fileName","exec","trim","concat","toUpperCase","path","avatarUrl"],"mappings":"8OAoBM,SAAUA,EAAOC,GACrB,IAAAC,QACAC,SACAC,EAAAH,EAAAI,KAAAA,OAAI,IAAAD,EAAG,MACPE,EAAAL,EAAAM,IAAAA,OAAG,IAAAD,EAAG,KACHE,EAAIC,EAAAR,EALc,CAAA,MAAA,OAAA,OAAA,QAOfS,EAAaC,IACbC,EAAKC,EAAAA,EAAA,CAAA,EACNC,GACAJ,GAgBL,OACEK,EAAAC,cAACC,EAAYJ,EAAA,GACPL,SACGI,EAAMM,OAAOb,GAAQ,KAC5Bc,IAjBc,WAChB,GAAIjB,EAAK,OAAOA,EAChB,IAAMkB,EACJjB,GACgB,iBAATA,GACE,cAATA,GACA,SAASkB,KAAKlB,EAAK,GAAGmB,QAClB,eAAAC,OAAepB,EAAK,GAAGmB,OAAOE,cAAa,QAC3C,4BAEN,MAAO,GAAAD,OAAGX,EAAMM,OAAOO,MAAIF,OAAGH,EAChC,CAMSM,GACLnB,IAAKA,IAGX"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__makeTemplateObject as r}from"../../../node_modules/tslib/tslib.es6.js";import o from"styled-components";var e,n=o.img(e||(e=r(["\n box-sizing: border-box;\n border-radius: 50%;\n height: ",";\n object-fit: cover;\n width: ",";\n border-style: solid;\n border-width: 2px;\n border-color: ",";\n"],["\n box-sizing: border-box;\n border-radius: 50%;\n height: ",";\n object-fit: cover;\n width: ",";\n border-style: solid;\n border-width: 2px;\n border-color: ",";\n"])),
|
|
1
|
+
import{__makeTemplateObject as r}from"../../../node_modules/tslib/tslib.es6.js";import o from"styled-components";var e,n=o.img(e||(e=r(["\n box-sizing: border-box;\n border-radius: 50%;\n height: ",";\n object-fit: cover;\n width: ",";\n border-style: solid;\n border-width: 2px;\n border-color: ",";\n"],["\n box-sizing: border-box;\n border-radius: 50%;\n height: ",";\n object-fit: cover;\n width: ",";\n border-style: solid;\n border-width: 2px;\n border-color: ",";\n"])),function(r){return r.$size},function(r){return r.$size},function(r){return r.theme.colors.avatarBorder});export{n as StyledAvatar,n as default};
|
|
2
2
|
//# sourceMappingURL=styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sources":["../../../../src/components/Avatar/styles.ts"],"sourcesContent":["import styled from \"styled-components\";\nimport { type ThemeType } from \"../../types\";\n\nexport const StyledAvatar = styled.img<{\n $size?: string;\n theme: ThemeType;\n}>`\n box-sizing: border-box;\n border-radius: 50%;\n height: ${({ $size }) => $size};\n object-fit: cover;\n width: ${({ $size }) => $size};\n border-style: solid;\n border-width: 2px;\n border-color: ${({ theme }) => theme.colors.avatarBorder};\n`;\n\nexport default StyledAvatar;\n"],"names":["StyledAvatar","styled","img","templateObject_1","__makeTemplateObject","_a","$size","theme","colors","avatarBorder"],"mappings":"
|
|
1
|
+
{"version":3,"file":"styles.js","sources":["../../../../src/components/Avatar/styles.ts"],"sourcesContent":["import styled from \"styled-components\";\nimport { type ThemeType } from \"../../types\";\n\nexport const StyledAvatar = styled.img<{\n $size?: string;\n theme: ThemeType;\n}>`\n box-sizing: border-box;\n border-radius: 50%;\n height: ${({ $size }) => $size};\n object-fit: cover;\n width: ${({ $size }) => $size};\n border-style: solid;\n border-width: 2px;\n border-color: ${({ theme }) => theme.colors.avatarBorder};\n`;\n\nexport default StyledAvatar;\n"],"names":["StyledAvatar","styled","img","templateObject_1","__makeTemplateObject","_a","$size","theme","colors","avatarBorder"],"mappings":"iHAGO,MAAMA,EAAeC,EAAOC,IAAGC,IAAAA,EAAAC,EAAA,CAAA,iEAAA,qCAAA,oEAAA,OAAA,CAGpC,iEAG8B,qCAED,oEAG2B,SAL9C,SAACC,GAAc,OAAPA,EAAAC,KAAO,EAEhB,SAACD,GAAc,OAAPA,EAAAC,KAAO,EAGR,SAACD,GAAc,OAAPA,EAAAE,MAAaC,OAAOC,YAAb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/Badge/index.tsx"],"sourcesContent":["import React, { type ReactNode } from \"react\";\nimport { useTheme } from \"styled-components\";\n\nimport { type SpaceType } from \"../../types\";\nimport { crukTheme as defaultTheme } from \"../../themes/cruk\";\n\nimport { StyledBadge } from \"./styles\";\nimport { themeColorOrString } from \"../../utils/themeUtils\";\n\nexport type BadgeProps = {\n /** background colour of badge */\n backgroundColor?: string;\n /** border colour of badge */\n borderColor?: string;\n /** text colour of badge */\n textColor?: string;\n /** size of badge */\n size?: SpaceType;\n /** contents of badge */\n children?: ReactNode;\n /** forces shape to have equal width and height set by size attribute */\n isSquare?: boolean;\n};\n\n/**\n * Displays a numeric or icon indicator. You can use the icon prop to\nindicate the importance of the badge to the user.\n\nNote that depending on how they are used, badges may be confusing for users\nof screen readers and similar assistive technologies. While the styling of\nbadges provides a visual cue as to their purpose, these users will simply\nbe presented with the content of the badge. Depending on the specific\nsituation, these badges may seem like random additional words or numbers\nat the end of a sentence, link, or button. Unless the context is clear,\nconsider including additional context with a visually hidden piece of\nadditional text.\n */\nexport function Badge({\n children,\n size = \"xs\",\n backgroundColor = \"primary\",\n borderColor = \"transparent\",\n textColor = \"textOnPrimary\",\n isSquare,\n}: BadgeProps) {\n const foundTheme = useTheme();\n const theme = {\n ...defaultTheme,\n ...foundTheme,\n };\n\n const isSquareCalculated = isSquare ?? !(typeof children === \"string\");\n\n return (\n <StyledBadge\n theme={theme}\n $isSquare={isSquareCalculated}\n $size={size}\n $backgroundColor={themeColorOrString(backgroundColor, theme)}\n $borderColor={themeColorOrString(borderColor, theme)}\n $textColor={themeColorOrString(textColor, theme)}\n >\n {children}\n </StyledBadge>\n );\n}\n\nexport default Badge;\n"],"names":["Badge","_a","children","_b","size","_c","backgroundColor","_d","borderColor","_e","textColor","isSquare","foundTheme","useTheme","theme","__assign","defaultTheme","isSquareCalculated","React","createElement","StyledBadge","$isSquare","$size","$backgroundColor","themeColorOrString","$borderColor"],"mappings":"gSAqCM,SAAUA,EAAMC,GACpB,IAAAC,EAAQD,EAAAC,SACRC,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/Badge/index.tsx"],"sourcesContent":["import React, { type ReactNode } from \"react\";\nimport { useTheme } from \"styled-components\";\n\nimport { type SpaceType } from \"../../types\";\nimport { crukTheme as defaultTheme } from \"../../themes/cruk\";\n\nimport { StyledBadge } from \"./styles\";\nimport { themeColorOrString } from \"../../utils/themeUtils\";\n\nexport type BadgeProps = {\n /** background colour of badge */\n backgroundColor?: string;\n /** border colour of badge */\n borderColor?: string;\n /** text colour of badge */\n textColor?: string;\n /** size of badge */\n size?: SpaceType;\n /** contents of badge */\n children?: ReactNode;\n /** forces shape to have equal width and height set by size attribute */\n isSquare?: boolean;\n};\n\n/**\n * Displays a numeric or icon indicator. You can use the icon prop to\nindicate the importance of the badge to the user.\n\nNote that depending on how they are used, badges may be confusing for users\nof screen readers and similar assistive technologies. While the styling of\nbadges provides a visual cue as to their purpose, these users will simply\nbe presented with the content of the badge. Depending on the specific\nsituation, these badges may seem like random additional words or numbers\nat the end of a sentence, link, or button. Unless the context is clear,\nconsider including additional context with a visually hidden piece of\nadditional text.\n */\nexport function Badge({\n children,\n size = \"xs\",\n backgroundColor = \"primary\",\n borderColor = \"transparent\",\n textColor = \"textOnPrimary\",\n isSquare,\n}: BadgeProps) {\n const foundTheme = useTheme();\n const theme = {\n ...defaultTheme,\n ...foundTheme,\n };\n\n const isSquareCalculated = isSquare ?? !(typeof children === \"string\");\n\n return (\n <StyledBadge\n theme={theme}\n $isSquare={isSquareCalculated}\n $size={size}\n $backgroundColor={themeColorOrString(backgroundColor, theme)}\n $borderColor={themeColorOrString(borderColor, theme)}\n $textColor={themeColorOrString(textColor, theme)}\n >\n {children}\n </StyledBadge>\n );\n}\n\nexport default Badge;\n"],"names":["Badge","_a","children","_b","size","_c","backgroundColor","_d","borderColor","_e","textColor","isSquare","foundTheme","useTheme","theme","__assign","defaultTheme","isSquareCalculated","React","createElement","StyledBadge","$isSquare","$size","$backgroundColor","themeColorOrString","$borderColor"],"mappings":"gSAqCM,SAAUA,EAAMC,GACpB,IAAAC,EAAQD,EAAAC,SACRC,EAAAF,EAAAG,KAAAA,OAAI,IAAAD,EAAG,KAAIA,EACXE,EAAAJ,EAAAK,gBAAAA,aAAkB,UAASD,EAC3BE,EAAAN,EAAAO,YAAAA,OAAW,IAAAD,EAAG,gBACdE,EAAAR,EAAAS,UAAAA,OAAS,IAAAD,EAAG,gBAAeA,EAC3BE,EAAQV,EAAAU,SAEFC,EAAaC,IACbC,EAAKC,EAAAA,EAAA,CAAA,EACNC,GACAJ,GAGCK,EAAqBN,QAAAA,IAAkC,iBAAbT,GAEhD,OACEgB,EAAAC,cAACC,EAAW,CACVN,MAAOA,EAAKO,UACDJ,EAAkBK,MACtBlB,EAAImB,iBACOC,EAAmBlB,EAAiBQ,GAAMW,aAC9CD,EAAmBhB,EAAaM,cAClCU,EAAmBd,EAAWI,IAEzCZ,EAGP"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__makeTemplateObject as n}from"../../../node_modules/tslib/tslib.es6.js";import r from"styled-components";var e,t=r.span(e||(e=n(["\n display: inline-block;\n border-width: 1px;\n border-style: solid;\n text-align: center;\n font-size: ",";\n padding: ",";\n border-radius: ",";\n height: ",";\n width: ",";\n line-height: ",";\n min-width: ",";\n\n background-color: ",";\n border-color: ",";\n color: ",";\n"],["\n display: inline-block;\n border-width: 1px;\n border-style: solid;\n text-align: center;\n font-size: ",";\n padding: ",";\n border-radius: ",";\n height: ",";\n width: ",";\n line-height: ",";\n min-width: ",";\n\n background-color: ",";\n border-color: ",";\n color: ",";\n"])),
|
|
1
|
+
import{__makeTemplateObject as n}from"../../../node_modules/tslib/tslib.es6.js";import r from"styled-components";var e,t=r.span(e||(e=n(["\n display: inline-block;\n border-width: 1px;\n border-style: solid;\n text-align: center;\n font-size: ",";\n padding: ",";\n border-radius: ",";\n height: ",";\n width: ",";\n line-height: ",";\n min-width: ",";\n\n background-color: ",";\n border-color: ",";\n color: ",";\n"],["\n display: inline-block;\n border-width: 1px;\n border-style: solid;\n text-align: center;\n font-size: ",";\n padding: ",";\n border-radius: ",";\n height: ",";\n width: ",";\n line-height: ",";\n min-width: ",";\n\n background-color: ",";\n border-color: ",";\n color: ",";\n"])),function(n){return n.theme.fontSizes.m},function(n){var r=n.theme;return n.$isSquare?0:r.spacing.xxs},function(n){return n.$isSquare?"50%":" 1.5rem"},function(n){var r=n.$isSquare,e=n.$size,t=n.theme;return r?"calc(".concat(t.spacing[e]," + ").concat(t.spacing.xs,")"):"auto"},function(n){var r=n.$isSquare,e=n.$size,t=n.theme;return r?"calc(".concat(t.spacing[e]," + ").concat(t.spacing.xs,")"):"auto"},function(n){var r=n.$isSquare,e=n.$size,t=n.theme;return r?"calc(".concat(t.spacing[e]," + ").concat(t.spacing.xs,")"):" 1rem"},function(n){var r=n.$size,e=n.theme;return"calc(".concat(e.spacing[r]," + ").concat(e.spacing.xs,")")},function(n){return n.$backgroundColor},function(n){return n.$borderColor},function(n){return n.$textColor});export{t as StyledBadge,t as default};
|
|
2
2
|
//# sourceMappingURL=styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sources":["../../../../src/components/Badge/styles.ts"],"sourcesContent":["import styled from \"styled-components\";\n\nimport { type SpaceType, type ThemeType } from \"../../types\";\n\nexport const StyledBadge = styled.span<{\n $backgroundColor: string;\n $borderColor: string;\n $textColor: string;\n $isSquare: boolean;\n $size: SpaceType;\n theme: ThemeType;\n}>`\n display: inline-block;\n border-width: 1px;\n border-style: solid;\n text-align: center;\n font-size: ${({ theme }) => theme.fontSizes.m};\n padding: ${({ theme, $isSquare }) => ($isSquare ? 0 : theme.spacing.xxs)};\n border-radius: ${({ $isSquare }) => ($isSquare ? \"50%\" : ` 1.5rem`)};\n height: ${({ $isSquare, $size, theme }) =>\n $isSquare ? `calc(${theme.spacing[$size]} + ${theme.spacing.xs})` : `auto`};\n width: ${({ $isSquare, $size, theme }) =>\n $isSquare ? `calc(${theme.spacing[$size]} + ${theme.spacing.xs})` : `auto`};\n line-height: ${({ $isSquare, $size, theme }) =>\n $isSquare\n ? `calc(${theme.spacing[$size]} + ${theme.spacing.xs})`\n : ` 1rem`};\n min-width: ${({ $size, theme }) =>\n `calc(${theme.spacing[$size]} + ${theme.spacing.xs})`};\n\n background-color: ${({ $backgroundColor }) => $backgroundColor};\n border-color: ${({ $borderColor }) => $borderColor};\n color: ${({ $textColor }) => $textColor};\n`;\n\nexport default StyledBadge;\n"],"names":["StyledBadge","styled","span","templateObject_1","__makeTemplateObject","_a","theme","fontSizes","m","$isSquare","spacing","xxs","$size","concat","xs","$backgroundColor","$borderColor","$textColor"],"mappings":"iHAIO,MAAMA,EAAcC,EAAOC,KAAIC,IAAAA,EAAAC,EAAA,CAAA,iHAAA,iBAAA,uBAAA,gBAAA,eAAA,qBAAA,mBAAA,4BAAA,sBAAA,eAAA,OAAA,CAOpC,iHAK6C,iBAC2B,uBACL,gBAES,eAEA,qBAI/D,mBAE0C,4BAEO,sBACZ,eACX,
|
|
1
|
+
{"version":3,"file":"styles.js","sources":["../../../../src/components/Badge/styles.ts"],"sourcesContent":["import styled from \"styled-components\";\n\nimport { type SpaceType, type ThemeType } from \"../../types\";\n\nexport const StyledBadge = styled.span<{\n $backgroundColor: string;\n $borderColor: string;\n $textColor: string;\n $isSquare: boolean;\n $size: SpaceType;\n theme: ThemeType;\n}>`\n display: inline-block;\n border-width: 1px;\n border-style: solid;\n text-align: center;\n font-size: ${({ theme }) => theme.fontSizes.m};\n padding: ${({ theme, $isSquare }) => ($isSquare ? 0 : theme.spacing.xxs)};\n border-radius: ${({ $isSquare }) => ($isSquare ? \"50%\" : ` 1.5rem`)};\n height: ${({ $isSquare, $size, theme }) =>\n $isSquare ? `calc(${theme.spacing[$size]} + ${theme.spacing.xs})` : `auto`};\n width: ${({ $isSquare, $size, theme }) =>\n $isSquare ? `calc(${theme.spacing[$size]} + ${theme.spacing.xs})` : `auto`};\n line-height: ${({ $isSquare, $size, theme }) =>\n $isSquare\n ? `calc(${theme.spacing[$size]} + ${theme.spacing.xs})`\n : ` 1rem`};\n min-width: ${({ $size, theme }) =>\n `calc(${theme.spacing[$size]} + ${theme.spacing.xs})`};\n\n background-color: ${({ $backgroundColor }) => $backgroundColor};\n border-color: ${({ $borderColor }) => $borderColor};\n color: ${({ $textColor }) => $textColor};\n`;\n\nexport default StyledBadge;\n"],"names":["StyledBadge","styled","span","templateObject_1","__makeTemplateObject","_a","theme","fontSizes","m","$isSquare","spacing","xxs","$size","concat","xs","$backgroundColor","$borderColor","$textColor"],"mappings":"iHAIO,MAAMA,EAAcC,EAAOC,KAAIC,IAAAA,EAAAC,EAAA,CAAA,iHAAA,iBAAA,uBAAA,gBAAA,eAAA,qBAAA,mBAAA,4BAAA,sBAAA,eAAA,OAAA,CAOpC,iHAK6C,iBAC2B,uBACL,gBAES,eAEA,qBAI/D,mBAE0C,4BAEO,sBACZ,eACX,SAhB1B,SAACC,GAAc,OAAPA,EAAAC,MAAaC,UAAUC,CAAhB,EACjB,SAACH,OAAEC,EAAKD,EAAAC,MAAkB,OAAPD,EAAAI,UAAoB,EAAIH,EAAMI,QAAQC,GAA/B,EACpB,SAACN,GAAkB,OAAPA,EAAAI,UAAoB,MAAQ,SAArB,EAC1B,SAACJ,GAAE,IAAAI,cAAWG,EAAKP,EAAAO,MAAEN,EAAKD,EAAAC,MAClC,OAAAG,EAAY,eAAQH,EAAMI,QAAQE,GAAM,OAAAC,OAAMP,EAAMI,QAAQI,GAAE,KAAM,MAApE,EACO,SAACT,GAAE,IAAAI,cAAWG,EAAKP,EAAAO,MAAEN,EAAKD,EAAAC,MACjC,OAAAG,EAAY,eAAQH,EAAMI,QAAQE,GAAM,OAAAC,OAAMP,EAAMI,QAAQI,GAAE,KAAM,MAApE,EACa,SAACT,GAAE,IAAAI,cAAWG,EAAKP,EAAAO,MAAEN,EAAKD,EAAAC,MACvC,OAAAG,EACI,QAAAI,OAAQP,EAAMI,QAAQE,GAAM,OAAAC,OAAMP,EAAMI,QAAQI,GAAE,KAClD,OAFJ,EAGW,SAACT,OAAEO,EAAKP,EAAAO,MAAEN,EAAKD,EAAAC,MAC1B,MAAA,QAAAO,OAAQP,EAAMI,QAAQE,GAAM,OAAAC,OAAMP,EAAMI,QAAQI,GAAE,IAAlD,EAEkB,SAACT,GAAyB,OAAPA,EAAAU,gBAAO,EAC9B,SAACV,GAAqB,OAAPA,EAAAW,YAAO,EAC7B,SAACX,GAAmB,OAAPA,EAAAY,UAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/Box/index.tsx"],"sourcesContent":["import React, {\n type HTMLAttributes,\n type Ref,\n type ReactNode,\n type ElementType,\n} from \"react\";\nimport { useTheme } from \"styled-components\";\n\nimport { crukTheme as defaultTheme } from \"../../themes/cruk\";\n\nimport {\n spacingPropsToSpacingPropsInternal,\n type SpacingProps,\n} from \"../Spacing\";\nimport { StyledBox } from \"./styles\";\n\nexport type BoxProps = SpacingProps &\n HTMLAttributes<HTMLElement> & {\n /** background color of box, this will add default padding */\n backgroundColor?: string;\n ref?: Ref<HTMLDivElement>;\n children?: ReactNode;\n /** styled-component polymorphic feature so you take the styling of a box and cast the component to be a \"span\" for example */\n as?: ElementType;\n };\n\n/**\n * Box is used to wrap other components to add margin and padding.\n * The values will be in the t-shirt sizes specified in the theme sizes.\n * The more specific the the target the higher priority the css will have.\n * For example `margin` will be overridden by the `marginVertical` or `marginHorizontal` props. `marginTop`, `marginBottom`, `marginLeft`, `marginRight` will override the the `marginVertical` and `marginHorizontal` props.\n */\nexport const Box = ({ ...props }: BoxProps) => {\n const { children, backgroundColor, ref, ...rest } = props;\n const foundTheme = useTheme();\n const theme = {\n ...defaultTheme,\n ...foundTheme,\n };\n const restWithInternalSpacingProps = spacingPropsToSpacingPropsInternal(rest);\n\n return (\n <StyledBox\n theme={theme}\n $backgroundColor={backgroundColor}\n {...restWithInternalSpacingProps}\n ref={ref}\n >\n {children}\n </StyledBox>\n );\n};\n\nexport default Box;\n"],"names":["Box","_a","props","__rest","children","backgroundColor","ref","rest","foundTheme","useTheme","theme","__assign","defaultTheme","restWithInternalSpacingProps","spacingPropsToSpacingPropsInternal","React","createElement","StyledBox","$backgroundColor"],"mappings":"oTAgCO,IAAMA,EAAM,SAACC,OAAKC,EAAKC,EAAAF,EAAV,IACVG,EAA4CF,EAAKE,SAAvCC,EAAkCH,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/Box/index.tsx"],"sourcesContent":["import React, {\n type HTMLAttributes,\n type Ref,\n type ReactNode,\n type ElementType,\n} from \"react\";\nimport { useTheme } from \"styled-components\";\n\nimport { crukTheme as defaultTheme } from \"../../themes/cruk\";\n\nimport {\n spacingPropsToSpacingPropsInternal,\n type SpacingProps,\n} from \"../Spacing\";\nimport { StyledBox } from \"./styles\";\n\nexport type BoxProps = SpacingProps &\n HTMLAttributes<HTMLElement> & {\n /** background color of box, this will add default padding */\n backgroundColor?: string;\n ref?: Ref<HTMLDivElement>;\n children?: ReactNode;\n /** styled-component polymorphic feature so you take the styling of a box and cast the component to be a \"span\" for example */\n as?: ElementType;\n };\n\n/**\n * Box is used to wrap other components to add margin and padding.\n * The values will be in the t-shirt sizes specified in the theme sizes.\n * The more specific the the target the higher priority the css will have.\n * For example `margin` will be overridden by the `marginVertical` or `marginHorizontal` props. `marginTop`, `marginBottom`, `marginLeft`, `marginRight` will override the the `marginVertical` and `marginHorizontal` props.\n */\nexport const Box = ({ ...props }: BoxProps) => {\n const { children, backgroundColor, ref, ...rest } = props;\n const foundTheme = useTheme();\n const theme = {\n ...defaultTheme,\n ...foundTheme,\n };\n const restWithInternalSpacingProps = spacingPropsToSpacingPropsInternal(rest);\n\n return (\n <StyledBox\n theme={theme}\n $backgroundColor={backgroundColor}\n {...restWithInternalSpacingProps}\n ref={ref}\n >\n {children}\n </StyledBox>\n );\n};\n\nexport default Box;\n"],"names":["Box","_a","props","__rest","children","backgroundColor","ref","rest","foundTheme","useTheme","theme","__assign","defaultTheme","restWithInternalSpacingProps","spacingPropsToSpacingPropsInternal","React","createElement","StyledBox","$backgroundColor"],"mappings":"oTAgCO,IAAMA,EAAM,SAACC,OAAKC,EAAKC,EAAAF,EAAV,IACVG,EAA4CF,EAAKE,SAAvCC,EAAkCH,EAAKG,gBAAtBC,EAAiBJ,MAATK,IAASL,EAA9C,CAAA,WAAA,kBAAA,QACAM,EAAaC,IACbC,EAAKC,EAAAA,EAAA,CAAA,EACNC,GACAJ,GAECK,EAA+BC,EAAmCP,GAExE,OACEQ,EAAAC,cAACC,KACCP,MAAOA,EAAKQ,iBACMb,GACdQ,EAA4B,CAChCP,IAAKA,IAEJF,EAGP"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__makeTemplateObject as n}from"../../../node_modules/tslib/tslib.es6.js";import o from"styled-components";import{spacing as r}from"../Spacing/index.js";var t,a=o.div(t||(t=n(["\n background-color: ",";\n padding: ",";\n margin: 0 0 "," 0;\n\n &:last-child {\n margin-bottom: 0;\n }\n\n background-color: ",";\n\n ","\n"],["\n background-color: ",";\n padding: ",";\n margin: 0 0 "," 0;\n\n &:last-child {\n margin-bottom: 0;\n }\n\n background-color: ",";\n\n ","\n"])),
|
|
1
|
+
import{__makeTemplateObject as n}from"../../../node_modules/tslib/tslib.es6.js";import o from"styled-components";import{spacing as r}from"../Spacing/index.js";var t,a=o.div(t||(t=n(["\n background-color: ",";\n padding: ",";\n margin: 0 0 "," 0;\n\n &:last-child {\n margin-bottom: 0;\n }\n\n background-color: ",";\n\n ","\n"],["\n background-color: ",";\n padding: ",";\n margin: 0 0 "," 0;\n\n &:last-child {\n margin-bottom: 0;\n }\n\n background-color: ",";\n\n ","\n"])),function(n){return n.theme.colors.backgroundLight},function(n){var o=n.theme;return n.$backgroundColor?o.spacing.s:0},function(n){return n.theme.spacing.m},function(n){var o=n.theme,r=n.$backgroundColor;return r&&void 0!==o.colors[r]?o.colors[r]:r||"transparent"},function(n){return r(n,n.theme)});export{a as StyledBox,a as default};
|
|
2
2
|
//# sourceMappingURL=styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sources":["../../../../src/components/Box/styles.ts"],"sourcesContent":["import styled from \"styled-components\";\n\nimport { spacing, type SpacingPropsInternal } from \"../Spacing\";\nimport { type ColorKeyType, type ThemeType } from \"../../types\";\n\ntype StyledBoxProps = SpacingPropsInternal & {\n $backgroundColor?: string;\n $css?: string;\n theme: ThemeType;\n};\n\nexport const StyledBox = styled.div<StyledBoxProps>`\n background-color: ${({ theme }) => theme.colors.backgroundLight};\n padding: ${({ theme, $backgroundColor }) =>\n $backgroundColor ? theme.spacing.s : 0};\n margin: 0 0 ${({ theme }) => theme.spacing.m} 0;\n\n &:last-child {\n margin-bottom: 0;\n }\n\n background-color: ${({ theme, $backgroundColor }) =>\n $backgroundColor &&\n typeof theme.colors[$backgroundColor as ColorKeyType] !== \"undefined\"\n ? theme.colors[$backgroundColor as ColorKeyType]\n : $backgroundColor || \"transparent\"};\n\n ${(props) => spacing(props, props.theme as ThemeType)}\n`;\n\nexport default StyledBox;\n"],"names":["StyledBox","styled","div","_a","theme","colors","backgroundLight","$backgroundColor","spacing","s","m","props"],"mappings":"qKAWaA,EAAYC,EAAOC,0KAAmB,yBACc,iBAEvB,oBACI,8EAUL,UAEc,
|
|
1
|
+
{"version":3,"file":"styles.js","sources":["../../../../src/components/Box/styles.ts"],"sourcesContent":["import styled from \"styled-components\";\n\nimport { spacing, type SpacingPropsInternal } from \"../Spacing\";\nimport { type ColorKeyType, type ThemeType } from \"../../types\";\n\ntype StyledBoxProps = SpacingPropsInternal & {\n $backgroundColor?: string;\n $css?: string;\n theme: ThemeType;\n};\n\nexport const StyledBox = styled.div<StyledBoxProps>`\n background-color: ${({ theme }) => theme.colors.backgroundLight};\n padding: ${({ theme, $backgroundColor }) =>\n $backgroundColor ? theme.spacing.s : 0};\n margin: 0 0 ${({ theme }) => theme.spacing.m} 0;\n\n &:last-child {\n margin-bottom: 0;\n }\n\n background-color: ${({ theme, $backgroundColor }) =>\n $backgroundColor &&\n typeof theme.colors[$backgroundColor as ColorKeyType] !== \"undefined\"\n ? theme.colors[$backgroundColor as ColorKeyType]\n : $backgroundColor || \"transparent\"};\n\n ${(props) => spacing(props, props.theme as ThemeType)}\n`;\n\nexport default StyledBox;\n"],"names":["StyledBox","styled","div","_a","theme","colors","backgroundLight","$backgroundColor","spacing","s","m","props"],"mappings":"qKAWaA,EAAYC,EAAOC,0KAAmB,yBACc,iBAEvB,oBACI,8EAUL,UAEc,QAfjC,SAACC,GAAc,OAAPA,EAAAC,MAAaC,OAAOC,eAAb,EACxB,SAACH,OAAEC,EAAKD,EAAAC,MACjB,OADmCD,EAAAI,iBAChBH,EAAMI,QAAQC,EAAI,CAArC,EACY,SAACN,GAAc,OAAPA,EAAAC,MAAaI,QAAQE,CAAd,EAMT,SAACP,OAAEC,EAAKD,EAAAC,MAAEG,EAAgBJ,EAAAI,iBAC5C,OAAAA,QAC0D,IAAnDH,EAAMC,OAAOE,GAChBH,EAAMC,OAAOE,GACbA,GAAoB,aAHxB,EAKA,SAACI,GAAU,OAAAH,EAAQG,EAAOA,EAAMP,MAAmB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__assign as e,__rest as r}from"../../../node_modules/tslib/tslib.es6.js";import t from"react";import{useTheme as o}from"styled-components";import{crukTheme as n}from"../../themes/cruk.js";import{IconFa as i}from"../IconFa/index.js";import{StyledButton as l,Spacer as a}from"./styles.js";var m=function(m){var s=o(),c=e(e({},n),s),f=m.appearance,p=void 0===f?"primary":f,u=m.isIconButton,d=void 0!==u&&u,h=m.full,v=void 0!==h&&h,y=m.size,b=void 0===y?"m":y,j=m.children,I=m.ref,$=r(m,["appearance","isIconButton","full","size","children","ref"]),g=t.Children.toArray(j),z="string"==typeof g[0],B=g[0],k=!(!d&&(1===g.length&&!z&&(null==B?void 0:B.type))!==i);return t.createElement(l,e({as:m.href?"a":"button"},m.href?{role:"button"}:{},{$full:!!v,$size:b,$appearance:p,$isIconButton:k},$,{theme:c,ref:I}),m.children&&g.length?t.Children.map(m.children,
|
|
1
|
+
import{__assign as e,__rest as r}from"../../../node_modules/tslib/tslib.es6.js";import t from"react";import{useTheme as o}from"styled-components";import{crukTheme as n}from"../../themes/cruk.js";import{IconFa as i}from"../IconFa/index.js";import{StyledButton as l,Spacer as a}from"./styles.js";var m=function(m){var s=o(),c=e(e({},n),s),f=m.appearance,p=void 0===f?"primary":f,u=m.isIconButton,d=void 0!==u&&u,h=m.full,v=void 0!==h&&h,y=m.size,b=void 0===y?"m":y,j=m.children,I=m.ref,$=r(m,["appearance","isIconButton","full","size","children","ref"]),g=t.Children.toArray(j),z="string"==typeof g[0],B=g[0],k=!(!d&&(1===g.length&&!z&&(null==B?void 0:B.type))!==i);return t.createElement(l,e({as:m.href?"a":"button"},m.href?{role:"button"}:{},{$full:!!v,$size:b,$appearance:p,$isIconButton:k},$,{theme:c,ref:I}),m.children&&g.length?t.Children.map(m.children,function(e,r){return t.createElement(a,{theme:c,key:r},e)}):null)};export{m as Button,m as default};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/Button/index.tsx"],"sourcesContent":["import React, {\n type ReactNode,\n type ButtonHTMLAttributes,\n type Ref,\n type ReactElement,\n type ElementType,\n} from \"react\";\nimport { useTheme } from \"styled-components\";\n\nimport { crukTheme as defaultTheme } from \"../../themes/cruk\";\nimport { IconFa } from \"../IconFa\";\n\nimport { Spacer, StyledButton } from \"./styles\";\nimport { type ButtonAppearanceType } from \"../../types\";\n\nexport type ButtonProps = ButtonHTMLAttributes<HTMLElement> & {\n /** the look and feel of the button */\n appearance?: ButtonAppearanceType;\n /** flag to stretch but to 100% width */\n full?: boolean;\n /** this is a url which will convert the button to an anchor tag */\n href?: string;\n /** the height of the button, this will add padding not increase text size */\n size?: \"m\" | \"l\";\n css?: unknown;\n /** styled-components polymorphism where you can use the styling of a button but convert to another element like an anchor tag */\n as?: ElementType;\n /** flag to force button into an icon button shape which is square or round */\n isIconButton?: boolean;\n /** Element reference */\n ref?: Ref<HTMLElement>;\n /** Component reference */\n children?: ReactNode;\n};\n\n/**\n * Design system documentation CRUK https://zeroheight.com/23de8a59a/p/180ef6-buttons/b/32e1a2\n *\n * Design system documentation SU2C https://zeroheight.com/79db39f7e/p/22ff0e-button/b/32e1a2\n */\nexport const Button = (props: ButtonProps) => {\n const foundTheme = useTheme();\n const theme = {\n ...defaultTheme,\n ...foundTheme,\n };\n const {\n appearance = \"primary\",\n isIconButton = false,\n full = false,\n size = \"m\",\n children,\n ref,\n ...rest\n } = props;\n\n const childArray = React.Children.toArray(children);\n const isChildString = typeof childArray[0] === \"string\";\n const firstElement = childArray[0] as ReactElement<HTMLElement>;\n\n // button has a fixed width if there is a single icon\n const setIconButton = !!(\n isIconButton ||\n (childArray.length === 1 && !isChildString && firstElement?.type) === IconFa\n );\n\n return (\n <StyledButton\n as={props.href ? \"a\" : \"button\"}\n {...(props.href ? { role: \"button\" } : {})}\n $full={!!full}\n $size={size}\n $appearance={appearance}\n $isIconButton={setIconButton}\n {...rest}\n theme={theme}\n ref={ref}\n >\n {props.children && childArray.length\n ? React.Children.map(\n props.children,\n (child: ReactNode, index: number) => (\n <Spacer theme={theme} key={index}>\n {child}\n </Spacer>\n ),\n )\n : null}\n </StyledButton>\n );\n};\n\nexport default Button;\n"],"names":["Button","props","foundTheme","useTheme","theme","__assign","defaultTheme","_a","appearance","_b","isIconButton","_c","full","_d","size","children","ref","rest","childArray","React","Children","toArray","isChildString","firstElement","setIconButton","length","type","IconFa","createElement","StyledButton","as","href","role","$full","$size","$appearance","$isIconButton","map","child","index","Spacer","key"],"mappings":"sSAwCO,IAAMA,EAAS,SAACC,GACrB,IAAMC,EAAaC,IACbC,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/Button/index.tsx"],"sourcesContent":["import React, {\n type ReactNode,\n type ButtonHTMLAttributes,\n type Ref,\n type ReactElement,\n type ElementType,\n} from \"react\";\nimport { useTheme } from \"styled-components\";\n\nimport { crukTheme as defaultTheme } from \"../../themes/cruk\";\nimport { IconFa } from \"../IconFa\";\n\nimport { Spacer, StyledButton } from \"./styles\";\nimport { type ButtonAppearanceType } from \"../../types\";\n\nexport type ButtonProps = ButtonHTMLAttributes<HTMLElement> & {\n /** the look and feel of the button */\n appearance?: ButtonAppearanceType;\n /** flag to stretch but to 100% width */\n full?: boolean;\n /** this is a url which will convert the button to an anchor tag */\n href?: string;\n /** the height of the button, this will add padding not increase text size */\n size?: \"m\" | \"l\";\n css?: unknown;\n /** styled-components polymorphism where you can use the styling of a button but convert to another element like an anchor tag */\n as?: ElementType;\n /** flag to force button into an icon button shape which is square or round */\n isIconButton?: boolean;\n /** Element reference */\n ref?: Ref<HTMLElement>;\n /** Component reference */\n children?: ReactNode;\n};\n\n/**\n * Design system documentation CRUK https://zeroheight.com/23de8a59a/p/180ef6-buttons/b/32e1a2\n *\n * Design system documentation SU2C https://zeroheight.com/79db39f7e/p/22ff0e-button/b/32e1a2\n */\nexport const Button = (props: ButtonProps) => {\n const foundTheme = useTheme();\n const theme = {\n ...defaultTheme,\n ...foundTheme,\n };\n const {\n appearance = \"primary\",\n isIconButton = false,\n full = false,\n size = \"m\",\n children,\n ref,\n ...rest\n } = props;\n\n const childArray = React.Children.toArray(children);\n const isChildString = typeof childArray[0] === \"string\";\n const firstElement = childArray[0] as ReactElement<HTMLElement>;\n\n // button has a fixed width if there is a single icon\n const setIconButton = !!(\n isIconButton ||\n (childArray.length === 1 && !isChildString && firstElement?.type) === IconFa\n );\n\n return (\n <StyledButton\n as={props.href ? \"a\" : \"button\"}\n {...(props.href ? { role: \"button\" } : {})}\n $full={!!full}\n $size={size}\n $appearance={appearance}\n $isIconButton={setIconButton}\n {...rest}\n theme={theme}\n ref={ref}\n >\n {props.children && childArray.length\n ? React.Children.map(\n props.children,\n (child: ReactNode, index: number) => (\n <Spacer theme={theme} key={index}>\n {child}\n </Spacer>\n ),\n )\n : null}\n </StyledButton>\n );\n};\n\nexport default Button;\n"],"names":["Button","props","foundTheme","useTheme","theme","__assign","defaultTheme","_a","appearance","_b","isIconButton","_c","full","_d","size","children","ref","rest","childArray","React","Children","toArray","isChildString","firstElement","setIconButton","length","type","IconFa","createElement","StyledButton","as","href","role","$full","$size","$appearance","$isIconButton","map","child","index","Spacer","key"],"mappings":"sSAwCO,IAAMA,EAAS,SAACC,GACrB,IAAMC,EAAaC,IACbC,EAAKC,EAAAA,EAAA,CAAA,EACNC,GACAJ,GAGHK,EAOEN,EAAKO,WAPPA,aAAa,UAASD,EACtBE,EAMER,EAAKS,aANPA,OAAY,IAAAD,GAAQA,EACpBE,EAKEV,EAAKW,KALPA,OAAI,IAAAD,GAAQA,EACZE,EAIEZ,EAAKa,KAJPA,OAAI,IAAAD,EAAG,IAAGA,EACVE,EAGEd,EAAKc,SAFPC,EAEEf,EAAKe,IADJC,IACDhB,EARE,CAAA,aAAA,eAAA,OAAA,OAAA,WAAA,QAUAiB,EAAaC,EAAMC,SAASC,QAAQN,GACpCO,EAAyC,iBAAlBJ,EAAW,GAClCK,EAAeL,EAAW,GAG1BM,KACJd,IACuB,IAAtBQ,EAAWO,SAAiBH,IAAiBC,aAAY,EAAZA,EAAcG,SAAUC,GAGxE,OACER,EAAAS,cAACC,EAAYxB,EAAA,CACXyB,GAAI7B,EAAM8B,KAAO,IAAM,UAClB9B,EAAM8B,KAAO,CAAEC,KAAM,UAAa,CAAA,EAAG,CAAAC,QACjCrB,EAAIsB,MACNpB,EAAIqB,YACE3B,EAAU4B,cACRZ,GACXP,EAAI,CACRb,MAAOA,EACPY,IAAKA,IAEJf,EAAMc,UAAYG,EAAWO,OAC1BN,EAAMC,SAASiB,IACbpC,EAAMc,SACN,SAACuB,EAAkBC,GAAkB,OACnCpB,EAAAS,cAACY,EAAM,CAACpC,MAAOA,EAAOqC,IAAKF,GACxBD,EAEJ,GAEH,KAGV"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__makeTemplateObject as n}from"../../../node_modules/tslib/tslib.es6.js";import o,{css as r}from"styled-components";var t,e,c,a,i,l,d,s,u="3rem",b="4rem",m=o.span(t||(t=n(["\n margin-left: ",";\n &:first-of-type {\n margin-left: 0;\n }\n"],["\n margin-left: ",";\n &:first-of-type {\n margin-left: 0;\n }\n"])),
|
|
1
|
+
import{__makeTemplateObject as n}from"../../../node_modules/tslib/tslib.es6.js";import o,{css as r}from"styled-components";var t,e,c,a,i,l,d,s,u="3rem",b="4rem",m=o.span(t||(t=n(["\n margin-left: ",";\n &:first-of-type {\n margin-left: 0;\n }\n"],["\n margin-left: ",";\n &:first-of-type {\n margin-left: 0;\n }\n"])),function(n){return n.theme.spacing.xxs}),h=o.button(s||(s=n(["\n box-sizing: border-box;\n min-height: ",";\n height: min-content;\n display: inline-block;\n vertical-align: middle;\n\n padding: ",";\n width: ",";\n min-width: ",";\n\n border-radius: ",";\n border-style: solid;\n border-width: ",";\n\n transition:\n color 0.2s ease,\n background-color 0.2s ease,\n border-color 0.2s ease;\n\n cursor: pointer;\n font-size: ",";\n font-family: ",";\n font-weight: ",";\n text-align: center;\n text-transform: ",";\n text-decoration: ",";\n\n &:focus-visible {\n outline: auto;\n }\n\n ","\n\n ","\n\n ","\n \n ","\n\n ","\n\n ","\n"],["\n box-sizing: border-box;\n min-height: ",";\n height: min-content;\n display: inline-block;\n vertical-align: middle;\n\n padding: ",";\n width: ",";\n min-width: ",";\n\n border-radius: ",";\n border-style: solid;\n border-width: ",";\n\n transition:\n color 0.2s ease,\n background-color 0.2s ease,\n border-color 0.2s ease;\n\n cursor: pointer;\n font-size: ",";\n font-family: ",";\n font-weight: ",";\n text-align: center;\n text-transform: ",";\n text-decoration: ",";\n\n &:focus-visible {\n outline: auto;\n }\n\n ","\n\n ","\n\n ","\n \n ","\n\n ","\n\n ","\n"])),u,function(n){var o=n.theme;return n.$isIconButton?"0":"calc( (".concat(u," - ( ").concat(o.button.buttonBorderThickness," * 2) - ").concat(o.typography.lineHeight," ) / 2) ").concat(o.button.horizontalPadding)},function(n){return n.$isIconButton?"".concat(u):"auto"},function(n){return n.$isIconButton?"".concat(u):"auto"},function(n){return n.theme.button.borderRadius},function(n){return n.theme.button.buttonBorderThickness},function(n){return n.theme.fontSizes.m},function(n){return n.theme.typography.fontFamilyButtons},function(n){return n.theme.typography.fontWeightButtons},function(n){return n.theme.button.textTransform},function(n){return n.theme.button.textDecoration},function(o){return"primary"===o.$appearance&&r(e||(e=n(["\n background-color: ",";\n border-color: ",";\n color: "," !important;\n &:focus,\n &:hover {\n background-color: ",";\n border-color: ",";\n color: "," !important;\n }\n &:disabled {\n cursor: not-allowed;\n background-color: ",";\n color: "," !important;\n border-color: ",";\n }\n "],["\n background-color: ",";\n border-color: ",";\n color: "," !important;\n &:focus,\n &:hover {\n background-color: ",";\n border-color: ",";\n color: "," !important;\n }\n &:disabled {\n cursor: not-allowed;\n background-color: ",";\n color: "," !important;\n border-color: ",";\n }\n "])),o.theme.colors.buttonPrimaryBackground,o.theme.colors.buttonPrimaryBorder,o.theme.colors.buttonPrimaryText,o.theme.colors.buttonPrimaryBackgroundHover,o.theme.colors.buttonPrimaryBorderHover,o.theme.colors.buttonPrimaryTextHover,o.theme.colors.buttonPrimaryDisabledBackground,o.theme.colors.buttonPrimaryDisabledText,o.theme.colors.buttonPrimaryDisabledBorder)},function(o){return"secondary"===o.$appearance&&r(c||(c=n(["\n background-color: ",";\n border-color: ",";\n color: "," !important;\n &:focus,\n &:hover {\n background-color: ",";\n border-color: ",";\n color: "," !important;\n }\n &:disabled {\n cursor: not-allowed;\n background-color: ",";\n color: "," !important;\n border-color: ",";\n }\n "],["\n background-color: ",";\n border-color: ",";\n color: "," !important;\n &:focus,\n &:hover {\n background-color: ",";\n border-color: ",";\n color: "," !important;\n }\n &:disabled {\n cursor: not-allowed;\n background-color: ",";\n color: "," !important;\n border-color: ",";\n }\n "])),o.theme.colors.buttonSecondaryBackground,o.theme.colors.buttonSecondaryBorder,o.theme.colors.buttonSecondaryText,o.theme.colors.buttonSecondaryBackgroundHover,o.theme.colors.buttonSecondaryBorderHover,o.theme.colors.buttonSecondaryTextHover,o.theme.colors.buttonSecondaryDisabledBackground,o.theme.colors.buttonSecondaryDisabledText,o.theme.colors.buttonSecondaryDisabledBorder)},function(o){return"tertiary"===o.$appearance&&r(a||(a=n(["\n display: inline-block;\n padding: 0;\n border: 0px;\n background-color: rgba(255, 255, 255, 0);\n transition: color 0.2s ease;\n color: ",";\n &:focus,\n &:hover {\n color: ",";\n }\n &:disabled {\n cursor: not-allowed;\n background-color: transparent;\n color: "," !important;\n border-color: transparent;\n }\n "],["\n display: inline-block;\n padding: 0;\n border: 0px;\n background-color: rgba(255, 255, 255, 0);\n transition: color 0.2s ease;\n color: ",";\n &:focus,\n &:hover {\n color: ",";\n }\n &:disabled {\n cursor: not-allowed;\n background-color: transparent;\n color: "," !important;\n border-color: transparent;\n }\n "])),o.theme.colors.buttonTertiaryText,o.theme.colors.buttonTertiaryTextHover,o.theme.colors.buttonTertiaryDisabledText)},function(o){var t=o.theme,e=o.$size,c=o.$isIconButton;return"l"===e&&r(i||(i=n(["\n min-height: ",";\n border-radius: ",";\n padding: ",";\n min-width: ",";\n height: ",";\n "],["\n min-height: ",";\n border-radius: ",";\n padding: ",";\n min-width: ",";\n height: ",";\n "])),b,t.button.borderRadiusLarge,c?"0":"calc( (".concat(b," - ( ").concat(t.button.buttonBorderThickness," * 2) - ").concat(t.typography.lineHeight," ) / 2) ").concat(t.spacing.m),c?"".concat(b):"auto",c?"".concat(b):"min-content")},function(o){return o.$full&&r(l||(l=n(["\n width: 100%;\n "],["\n width: 100%;\n "])))},function(o){return o.$css&&r(d||(d=n(["\n ","\n "],["\n ","\n "])),o.$css)});export{m as Spacer,h as StyledButton};
|
|
2
2
|
//# sourceMappingURL=styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sources":["../../../../src/components/Button/styles.ts"],"sourcesContent":["import styled, { css } from \"styled-components\";\n\nimport { type ThemeType, type ButtonAppearanceType } from \"../../types\";\n\nconst BUTTON_HEIGHT = \"3rem\";\nconst BUTTON_HEIGHT_LARGE = \"4rem\";\n\nexport const Spacer = styled.span<{ theme: ThemeType }>`\n margin-left: ${({ theme }) => theme.spacing.xxs};\n &:first-of-type {\n margin-left: 0;\n }\n`;\n\nexport const StyledButton = styled.button<{\n theme: ThemeType;\n href?: string;\n $isIconButton: boolean;\n $appearance?: ButtonAppearanceType;\n $full?: boolean;\n $size?: \"m\" | \"l\";\n $css?: string;\n}>`\n box-sizing: border-box;\n min-height: ${BUTTON_HEIGHT};\n height: min-content;\n display: inline-block;\n vertical-align: middle;\n\n padding: ${({ theme, $isIconButton }) =>\n $isIconButton\n ? \"0\"\n : `calc( (${BUTTON_HEIGHT} - ( ${theme.button.buttonBorderThickness} * 2) - ${theme.typography.lineHeight} ) / 2) ${theme.button.horizontalPadding}`};\n width: ${({ $isIconButton }) =>\n $isIconButton ? `${BUTTON_HEIGHT}` : \"auto\"};\n min-width: ${({ $isIconButton }) =>\n $isIconButton ? `${BUTTON_HEIGHT}` : \"auto\"};\n\n border-radius: ${({ theme }) => theme.button.borderRadius};\n border-style: solid;\n border-width: ${({ theme }) => theme.button.buttonBorderThickness};\n\n transition:\n color 0.2s ease,\n background-color 0.2s ease,\n border-color 0.2s ease;\n\n cursor: pointer;\n font-size: ${({\n theme: {\n fontSizes: { m },\n },\n }) => m};\n font-family: ${({\n theme: {\n typography: { fontFamilyButtons },\n },\n }) => fontFamilyButtons};\n font-weight: ${({\n theme: {\n typography: { fontWeightButtons },\n },\n }) => fontWeightButtons};\n text-align: center;\n text-transform: ${({ theme }) => theme.button.textTransform};\n text-decoration: ${({ theme }) => theme.button.textDecoration};\n\n &:focus-visible {\n outline: auto;\n }\n\n ${(props) =>\n props.$appearance === \"primary\" &&\n css`\n background-color: ${props.theme.colors.buttonPrimaryBackground};\n border-color: ${props.theme.colors.buttonPrimaryBorder};\n color: ${props.theme.colors.buttonPrimaryText} !important;\n &:focus,\n &:hover {\n background-color: ${props.theme.colors.buttonPrimaryBackgroundHover};\n border-color: ${props.theme.colors.buttonPrimaryBorderHover};\n color: ${props.theme.colors.buttonPrimaryTextHover} !important;\n }\n &:disabled {\n cursor: not-allowed;\n background-color: ${props.theme.colors.buttonPrimaryDisabledBackground};\n color: ${props.theme.colors.buttonPrimaryDisabledText} !important;\n border-color: ${props.theme.colors.buttonPrimaryDisabledBorder};\n }\n `}\n\n ${(props) =>\n props.$appearance === \"secondary\" &&\n css`\n background-color: ${props.theme.colors.buttonSecondaryBackground};\n border-color: ${props.theme.colors.buttonSecondaryBorder};\n color: ${props.theme.colors.buttonSecondaryText} !important;\n &:focus,\n &:hover {\n background-color: ${props.theme.colors.buttonSecondaryBackgroundHover};\n border-color: ${props.theme.colors.buttonSecondaryBorderHover};\n color: ${props.theme.colors.buttonSecondaryTextHover} !important;\n }\n &:disabled {\n cursor: not-allowed;\n background-color: ${props.theme.colors\n .buttonSecondaryDisabledBackground};\n color: ${props.theme.colors.buttonSecondaryDisabledText} !important;\n border-color: ${props.theme.colors.buttonSecondaryDisabledBorder};\n }\n `}\n\n ${(props) =>\n props.$appearance === \"tertiary\" &&\n css`\n display: inline-block;\n padding: 0;\n border: 0px;\n background-color: rgba(255, 255, 255, 0);\n transition: color 0.2s ease;\n color: ${props.theme.colors.buttonTertiaryText};\n &:focus,\n &:hover {\n color: ${props.theme.colors.buttonTertiaryTextHover};\n }\n &:disabled {\n cursor: not-allowed;\n background-color: transparent;\n color: ${props.theme.colors.buttonTertiaryDisabledText} !important;\n border-color: transparent;\n }\n `}\n \n ${({ theme, $size, $isIconButton }) =>\n $size === \"l\" &&\n css`\n min-height: ${BUTTON_HEIGHT_LARGE};\n border-radius: ${theme.button.borderRadiusLarge};\n padding: ${$isIconButton\n ? \"0\"\n : `calc( (${BUTTON_HEIGHT_LARGE} - ( ${theme.button.buttonBorderThickness} * 2) - ${theme.typography.lineHeight} ) / 2) ${theme.spacing.m}`};\n min-width: ${$isIconButton ? `${BUTTON_HEIGHT_LARGE}` : \"auto\"};\n height: ${$isIconButton ? `${BUTTON_HEIGHT_LARGE}` : \"min-content\"};\n `}\n\n ${(props) =>\n props.$full &&\n css`\n width: 100%;\n `}\n\n ${(props) =>\n props.$css &&\n css`\n ${props.$css}\n `}\n`;\n"],"names":["BUTTON_HEIGHT","BUTTON_HEIGHT_LARGE","Spacer","styled","span","templateObject_1","__makeTemplateObject","_a","theme","spacing","xxs","StyledButton","button","$isIconButton","concat","buttonBorderThickness","typography","lineHeight","horizontalPadding","borderRadius","fontSizes","m","fontFamilyButtons","fontWeightButtons","textTransform","textDecoration","props","$appearance","css","colors","buttonPrimaryBackground","buttonPrimaryBorder","buttonPrimaryText","buttonPrimaryBackgroundHover","buttonPrimaryBorderHover","buttonPrimaryTextHover","buttonPrimaryDisabledBackground","buttonPrimaryDisabledText","buttonPrimaryDisabledBorder","templateObject_3","buttonSecondaryBackground","buttonSecondaryBorder","buttonSecondaryText","buttonSecondaryBackgroundHover","buttonSecondaryBorderHover","buttonSecondaryTextHover","buttonSecondaryDisabledBackground","buttonSecondaryDisabledText","buttonSecondaryDisabledBorder","templateObject_4","buttonTertiaryText","buttonTertiaryTextHover","buttonTertiaryDisabledText","$size","templateObject_5","borderRadiusLarge","$full","templateObject_6","$css","templateObject_7"],"mappings":"2HAIA,oBAAMA,EAAgB,OAChBC,EAAsB,OAEfC,EAASC,EAAOC,KAAIC,IAAAA,EAAAC,EAAA,CAAA,oBAAA,sDAAA,CAAsB,oBACN,
|
|
1
|
+
{"version":3,"file":"styles.js","sources":["../../../../src/components/Button/styles.ts"],"sourcesContent":["import styled, { css } from \"styled-components\";\n\nimport { type ThemeType, type ButtonAppearanceType } from \"../../types\";\n\nconst BUTTON_HEIGHT = \"3rem\";\nconst BUTTON_HEIGHT_LARGE = \"4rem\";\n\nexport const Spacer = styled.span<{ theme: ThemeType }>`\n margin-left: ${({ theme }) => theme.spacing.xxs};\n &:first-of-type {\n margin-left: 0;\n }\n`;\n\nexport const StyledButton = styled.button<{\n theme: ThemeType;\n href?: string;\n $isIconButton: boolean;\n $appearance?: ButtonAppearanceType;\n $full?: boolean;\n $size?: \"m\" | \"l\";\n $css?: string;\n}>`\n box-sizing: border-box;\n min-height: ${BUTTON_HEIGHT};\n height: min-content;\n display: inline-block;\n vertical-align: middle;\n\n padding: ${({ theme, $isIconButton }) =>\n $isIconButton\n ? \"0\"\n : `calc( (${BUTTON_HEIGHT} - ( ${theme.button.buttonBorderThickness} * 2) - ${theme.typography.lineHeight} ) / 2) ${theme.button.horizontalPadding}`};\n width: ${({ $isIconButton }) =>\n $isIconButton ? `${BUTTON_HEIGHT}` : \"auto\"};\n min-width: ${({ $isIconButton }) =>\n $isIconButton ? `${BUTTON_HEIGHT}` : \"auto\"};\n\n border-radius: ${({ theme }) => theme.button.borderRadius};\n border-style: solid;\n border-width: ${({ theme }) => theme.button.buttonBorderThickness};\n\n transition:\n color 0.2s ease,\n background-color 0.2s ease,\n border-color 0.2s ease;\n\n cursor: pointer;\n font-size: ${({\n theme: {\n fontSizes: { m },\n },\n }) => m};\n font-family: ${({\n theme: {\n typography: { fontFamilyButtons },\n },\n }) => fontFamilyButtons};\n font-weight: ${({\n theme: {\n typography: { fontWeightButtons },\n },\n }) => fontWeightButtons};\n text-align: center;\n text-transform: ${({ theme }) => theme.button.textTransform};\n text-decoration: ${({ theme }) => theme.button.textDecoration};\n\n &:focus-visible {\n outline: auto;\n }\n\n ${(props) =>\n props.$appearance === \"primary\" &&\n css`\n background-color: ${props.theme.colors.buttonPrimaryBackground};\n border-color: ${props.theme.colors.buttonPrimaryBorder};\n color: ${props.theme.colors.buttonPrimaryText} !important;\n &:focus,\n &:hover {\n background-color: ${props.theme.colors.buttonPrimaryBackgroundHover};\n border-color: ${props.theme.colors.buttonPrimaryBorderHover};\n color: ${props.theme.colors.buttonPrimaryTextHover} !important;\n }\n &:disabled {\n cursor: not-allowed;\n background-color: ${props.theme.colors.buttonPrimaryDisabledBackground};\n color: ${props.theme.colors.buttonPrimaryDisabledText} !important;\n border-color: ${props.theme.colors.buttonPrimaryDisabledBorder};\n }\n `}\n\n ${(props) =>\n props.$appearance === \"secondary\" &&\n css`\n background-color: ${props.theme.colors.buttonSecondaryBackground};\n border-color: ${props.theme.colors.buttonSecondaryBorder};\n color: ${props.theme.colors.buttonSecondaryText} !important;\n &:focus,\n &:hover {\n background-color: ${props.theme.colors.buttonSecondaryBackgroundHover};\n border-color: ${props.theme.colors.buttonSecondaryBorderHover};\n color: ${props.theme.colors.buttonSecondaryTextHover} !important;\n }\n &:disabled {\n cursor: not-allowed;\n background-color: ${props.theme.colors\n .buttonSecondaryDisabledBackground};\n color: ${props.theme.colors.buttonSecondaryDisabledText} !important;\n border-color: ${props.theme.colors.buttonSecondaryDisabledBorder};\n }\n `}\n\n ${(props) =>\n props.$appearance === \"tertiary\" &&\n css`\n display: inline-block;\n padding: 0;\n border: 0px;\n background-color: rgba(255, 255, 255, 0);\n transition: color 0.2s ease;\n color: ${props.theme.colors.buttonTertiaryText};\n &:focus,\n &:hover {\n color: ${props.theme.colors.buttonTertiaryTextHover};\n }\n &:disabled {\n cursor: not-allowed;\n background-color: transparent;\n color: ${props.theme.colors.buttonTertiaryDisabledText} !important;\n border-color: transparent;\n }\n `}\n \n ${({ theme, $size, $isIconButton }) =>\n $size === \"l\" &&\n css`\n min-height: ${BUTTON_HEIGHT_LARGE};\n border-radius: ${theme.button.borderRadiusLarge};\n padding: ${$isIconButton\n ? \"0\"\n : `calc( (${BUTTON_HEIGHT_LARGE} - ( ${theme.button.buttonBorderThickness} * 2) - ${theme.typography.lineHeight} ) / 2) ${theme.spacing.m}`};\n min-width: ${$isIconButton ? `${BUTTON_HEIGHT_LARGE}` : \"auto\"};\n height: ${$isIconButton ? `${BUTTON_HEIGHT_LARGE}` : \"min-content\"};\n `}\n\n ${(props) =>\n props.$full &&\n css`\n width: 100%;\n `}\n\n ${(props) =>\n props.$css &&\n css`\n ${props.$css}\n `}\n`;\n"],"names":["BUTTON_HEIGHT","BUTTON_HEIGHT_LARGE","Spacer","styled","span","templateObject_1","__makeTemplateObject","_a","theme","spacing","xxs","StyledButton","button","$isIconButton","concat","buttonBorderThickness","typography","lineHeight","horizontalPadding","borderRadius","fontSizes","m","fontFamilyButtons","fontWeightButtons","textTransform","textDecoration","props","$appearance","css","colors","buttonPrimaryBackground","buttonPrimaryBorder","buttonPrimaryText","buttonPrimaryBackgroundHover","buttonPrimaryBorderHover","buttonPrimaryTextHover","buttonPrimaryDisabledBackground","buttonPrimaryDisabledText","buttonPrimaryDisabledBorder","templateObject_3","buttonSecondaryBackground","buttonSecondaryBorder","buttonSecondaryText","buttonSecondaryBackgroundHover","buttonSecondaryBorderHover","buttonSecondaryTextHover","buttonSecondaryDisabledBackground","buttonSecondaryDisabledText","buttonSecondaryDisabledBorder","templateObject_4","buttonTertiaryText","buttonTertiaryTextHover","buttonTertiaryDisabledText","$size","templateObject_5","borderRadiusLarge","$full","templateObject_6","$css","templateObject_7"],"mappings":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"react";import{faCaretLeft as n,faCaretRight as t}from"../../../node_modules/@fortawesome/free-solid-svg-icons/index.js";import{IconFa as r}from"../IconFa/index.js";import{ButtonWrapper as o,CarouselButton as l,VerticalAlign as c,ScreenReaderOnly as a,DotContainer as i,Dot as s}from"./styles.js";var u=function(u){var m=u.count,d=u.currentPosition,f=void 0===d?0:d,E=u.scrollToPosition,p=u.next,v=u.previous,x=f!==m-1,k=0!==f,b=Array.from({length:m},
|
|
1
|
+
import e from"react";import{faCaretLeft as n,faCaretRight as t}from"../../../node_modules/@fortawesome/free-solid-svg-icons/index.js";import{IconFa as r}from"../IconFa/index.js";import{ButtonWrapper as o,CarouselButton as l,VerticalAlign as c,ScreenReaderOnly as a,DotContainer as i,Dot as s}from"./styles.js";var u=function(u){var m=u.count,d=u.currentPosition,f=void 0===d?0:d,E=u.scrollToPosition,p=u.next,v=u.previous,x=f!==m-1,k=0!==f,b=Array.from({length:m},function(e,n){return"arrayIndex".concat(n)});return e.createElement(o,null,e.createElement(l,{disabled:!k,"aria-label":"previous",onClick:function(){v()}},e.createElement(c,null,e.createElement(r,{faIcon:n,size:"1.25em"}),e.createElement(a,null,"Scroll carousel to previous index"))),e.createElement(i,{$count:m},b.map(function(n,t){var r=t===f;return e.createElement(s,{key:n,role:"switch","aria-checked":r,onClick:function(){E(t)},$selected:r},e.createElement(a,null,"Scroll carousel to index ".concat(t)))})),e.createElement(l,{disabled:!x,"aria-label":"next",onClick:function(){p()}},e.createElement(c,null,e.createElement(r,{faIcon:t,size:"1.25em"}),e.createElement(a,null,"Scroll carousel to previous index"))))};export{u as Dots,u as default};
|
|
2
2
|
//# sourceMappingURL=Dots.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dots.js","sources":["../../../../src/components/Carousel/Dots.tsx"],"sourcesContent":["import React from \"react\";\nimport { faCaretLeft, faCaretRight } from \"@fortawesome/free-solid-svg-icons\";\n\nimport { IconFa } from \"../IconFa\";\n\nimport {\n DotContainer,\n Dot,\n CarouselButton,\n ButtonWrapper,\n VerticalAlign,\n ScreenReaderOnly,\n} from \"./styles\";\n\nexport const Dots = ({\n count,\n currentPosition = 0,\n scrollToPosition,\n next,\n previous,\n}: {\n count: number;\n currentPosition: number;\n scrollToPosition: (to: number) => void;\n next: () => void;\n previous: () => void;\n}) => {\n const moreOnRight = currentPosition !== count - 1;\n const moreOnLeft = currentPosition !== 0;\n const countArray = Array.from({ length: count }, (e, i) => `arrayIndex${i}`);\n\n return (\n <ButtonWrapper>\n <CarouselButton\n disabled={!moreOnLeft}\n aria-label=\"previous\"\n onClick={() => {\n previous();\n }}\n >\n <VerticalAlign>\n <IconFa faIcon={faCaretLeft} size=\"1.25em\" />\n <ScreenReaderOnly>Scroll carousel to previous index</ScreenReaderOnly>\n </VerticalAlign>\n </CarouselButton>\n\n <DotContainer $count={count}>\n {countArray.map((item, index) => {\n const isSelected = index === currentPosition;\n const scrollTo = () => {\n scrollToPosition(index);\n };\n return (\n <Dot\n key={item}\n role=\"switch\"\n aria-checked={isSelected}\n onClick={scrollTo}\n $selected={isSelected}\n >\n <ScreenReaderOnly>{`Scroll carousel to index ${index}`}</ScreenReaderOnly>\n </Dot>\n );\n })}\n </DotContainer>\n\n <CarouselButton\n disabled={!moreOnRight}\n aria-label=\"next\"\n onClick={() => {\n next();\n }}\n >\n <VerticalAlign>\n <IconFa faIcon={faCaretRight} size=\"1.25em\" />\n <ScreenReaderOnly>Scroll carousel to previous index</ScreenReaderOnly>\n </VerticalAlign>\n </CarouselButton>\n </ButtonWrapper>\n );\n};\n\nexport default Dots;\n"],"names":["Dots","_a","count","_b","currentPosition","scrollToPosition","next","previous","moreOnRight","moreOnLeft","countArray","Array","from","length","e","i","concat","React","ButtonWrapper","createElement","CarouselButton","disabled","onClick","VerticalAlign","IconFa","faIcon","faCaretLeft","size","ScreenReaderOnly","DotContainer","$count","map","item","index","isSelected","Dot","key","role","faCaretRight"],"mappings":"sTAcO,IAAMA,EAAO,SAACC,GACnB,IAAAC,UACAC,EAAAF,EAAAG,gBAAAA,aAAkB,EAACD,EACnBE,qBACAC,EAAIL,EAAAK,KACJC,EAAQN,EAAAM,SAQFC,EAAcJ,IAAoBF,EAAQ,EAC1CO,EAAiC,IAApBL,EACbM,EAAaC,MAAMC,KAAK,CAAEC,OAAQX,
|
|
1
|
+
{"version":3,"file":"Dots.js","sources":["../../../../src/components/Carousel/Dots.tsx"],"sourcesContent":["import React from \"react\";\nimport { faCaretLeft, faCaretRight } from \"@fortawesome/free-solid-svg-icons\";\n\nimport { IconFa } from \"../IconFa\";\n\nimport {\n DotContainer,\n Dot,\n CarouselButton,\n ButtonWrapper,\n VerticalAlign,\n ScreenReaderOnly,\n} from \"./styles\";\n\nexport const Dots = ({\n count,\n currentPosition = 0,\n scrollToPosition,\n next,\n previous,\n}: {\n count: number;\n currentPosition: number;\n scrollToPosition: (to: number) => void;\n next: () => void;\n previous: () => void;\n}) => {\n const moreOnRight = currentPosition !== count - 1;\n const moreOnLeft = currentPosition !== 0;\n const countArray = Array.from({ length: count }, (e, i) => `arrayIndex${i}`);\n\n return (\n <ButtonWrapper>\n <CarouselButton\n disabled={!moreOnLeft}\n aria-label=\"previous\"\n onClick={() => {\n previous();\n }}\n >\n <VerticalAlign>\n <IconFa faIcon={faCaretLeft} size=\"1.25em\" />\n <ScreenReaderOnly>Scroll carousel to previous index</ScreenReaderOnly>\n </VerticalAlign>\n </CarouselButton>\n\n <DotContainer $count={count}>\n {countArray.map((item, index) => {\n const isSelected = index === currentPosition;\n const scrollTo = () => {\n scrollToPosition(index);\n };\n return (\n <Dot\n key={item}\n role=\"switch\"\n aria-checked={isSelected}\n onClick={scrollTo}\n $selected={isSelected}\n >\n <ScreenReaderOnly>{`Scroll carousel to index ${index}`}</ScreenReaderOnly>\n </Dot>\n );\n })}\n </DotContainer>\n\n <CarouselButton\n disabled={!moreOnRight}\n aria-label=\"next\"\n onClick={() => {\n next();\n }}\n >\n <VerticalAlign>\n <IconFa faIcon={faCaretRight} size=\"1.25em\" />\n <ScreenReaderOnly>Scroll carousel to previous index</ScreenReaderOnly>\n </VerticalAlign>\n </CarouselButton>\n </ButtonWrapper>\n );\n};\n\nexport default Dots;\n"],"names":["Dots","_a","count","_b","currentPosition","scrollToPosition","next","previous","moreOnRight","moreOnLeft","countArray","Array","from","length","e","i","concat","React","ButtonWrapper","createElement","CarouselButton","disabled","onClick","VerticalAlign","IconFa","faIcon","faCaretLeft","size","ScreenReaderOnly","DotContainer","$count","map","item","index","isSelected","Dot","key","role","faCaretRight"],"mappings":"sTAcO,IAAMA,EAAO,SAACC,GACnB,IAAAC,UACAC,EAAAF,EAAAG,gBAAAA,aAAkB,EAACD,EACnBE,qBACAC,EAAIL,EAAAK,KACJC,EAAQN,EAAAM,SAQFC,EAAcJ,IAAoBF,EAAQ,EAC1CO,EAAiC,IAApBL,EACbM,EAAaC,MAAMC,KAAK,CAAEC,OAAQX,GAAS,SAACY,EAAGC,GAAM,MAAA,aAAAC,OAAaD,EAAG,GAE3E,OACEE,gBAACC,EAAa,KACZD,EAAAE,cAACC,EAAc,CACbC,UAAWZ,EAAU,aACV,WACXa,QAAS,WACPf,MAGFU,EAAAE,cAACI,EAAa,KACZN,EAAAE,cAACK,GAAOC,OAAQC,EAAaC,KAAK,WAClCV,EAAAE,cAACS,EAAgB,KAAA,uCAIrBX,EAAAE,cAACU,EAAY,CAAAC,OAAS5B,GACnBQ,EAAWqB,IAAI,SAACC,EAAMC,GACrB,IAAMC,EAAaD,IAAU7B,EAI7B,OACEa,EAAAE,cAACgB,GACCC,IAAKJ,EACLK,KAAK,wBACSH,EACdZ,QARa,WACfjB,EAAiB4B,EACnB,YAOeC,GAEXjB,EAAAE,cAACS,OAAkB,4BAAAZ,OAA4BiB,IAGrD,IAGFhB,EAAAE,cAACC,EAAc,CACbC,UAAWb,EAAW,aACX,OACXc,QAAS,WACPhB,MAGFW,EAAAE,cAACI,EAAa,KACZN,EAAAE,cAACK,GAAOC,OAAQa,EAAcX,KAAK,WACnCV,EAAAE,cAACS,EAAgB,KAAA,uCAK3B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{memo as t,useState as n,useRef as r,useEffect as l}from"react";import{InView as o}from"../../../node_modules/react-intersection-observer/dist/index.js";import{Box as i}from"../Box/index.js";import{Dots as c}from"./Dots.js";import{CarouselWrapper as u,CarouselScrollArea as s,CarouselCard as a,CarouselCardInner as d}from"./styles.js";var f=function(t){var f=t.startPosition,m=t.children,h=t.onPositionChanged,v=t.shrinkUnselectedPages,g=void 0!==v&&v,E=t.fullWidthChild,p=void 0!==E&&E,C=e.useRef(void 0),$=void 0!==f,x=n(f||0),P=x[0],T=x[1],y=n(!$),j=y[0],W=y[1],k=r(null),b=e.Children.toArray(m).filter(Boolean),B=function(e){if(null==k?void 0:k.current){var t=k.current.scrollWidth,n=0===e,r=e===k.current.children.length-1,l=k.current.children[e];if(!l)return;var o=l.offsetLeft;n?k.current.scrollTo(0,0):r?k.current.scrollTo(t,0):k.current.scrollTo(o,0),j||W(!0)}};l(
|
|
1
|
+
import e,{memo as t,useState as n,useRef as r,useEffect as l}from"react";import{InView as o}from"../../../node_modules/react-intersection-observer/dist/index.js";import{Box as i}from"../Box/index.js";import{Dots as c}from"./Dots.js";import{CarouselWrapper as u,CarouselScrollArea as s,CarouselCard as a,CarouselCardInner as d}from"./styles.js";var f=function(t){var f=t.startPosition,m=t.children,h=t.onPositionChanged,v=t.shrinkUnselectedPages,g=void 0!==v&&v,E=t.fullWidthChild,p=void 0!==E&&E,C=e.useRef(void 0),$=void 0!==f,x=n(f||0),P=x[0],T=x[1],y=n(!$),j=y[0],W=y[1],k=r(null),b=e.Children.toArray(m).filter(Boolean),B=function(e){if(null==k?void 0:k.current){var t=k.current.scrollWidth,n=0===e,r=e===k.current.children.length-1,l=k.current.children[e];if(!l)return;var o=l.offsetLeft;n?k.current.scrollTo(0,0):r?k.current.scrollTo(t,0):k.current.scrollTo(o,0),j||W(!0)}};l(function(){$&&W(!1)},[f]),l(function(){j||B(f||0)},[j]);var S=1===b.length;return e.createElement(e.Fragment,null,e.createElement(i,null,e.createElement(u,null,e.createElement(s,{ref:k,"aria-live":"assertive",$smoothScrolling:j,tabIndex:0},b.map(function(t,n){var r=n===P,l="card-".concat(n);return e.createElement(a,{key:l,$onlyChild:S,$fullWidthChild:p},e.createElement(o,{threshold:.5,as:"div",onChange:function(e){var t;e&&P!==(t=n)&&(T(t),C&&clearTimeout(null==C?void 0:C.current),C.current=setTimeout(function(){h&&j&&h(t)},500))}},e.createElement(d,{$onlyChild:S,$isSelected:r,$shrinkUnselectedPages:g,$fullWidthChild:p},t)))})))),b.length>1?e.createElement(i,null,e.createElement(c,{count:b.length,currentPosition:P,scrollToPosition:B,next:function(){B(P+1)},previous:function(){B(P-1)}})):null)};t(f);export{f as Carousel};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/Carousel/index.tsx"],"sourcesContent":["import React, {\n useState,\n useRef,\n useEffect,\n memo,\n type ReactNode,\n} from \"react\";\nimport { InView } from \"react-intersection-observer\";\n\nimport { Box } from \"../Box\";\nimport { Dots } from \"./Dots\";\n\nimport {\n CarouselWrapper,\n CarouselCardInner,\n CarouselCard,\n CarouselScrollArea,\n} from \"./styles\";\n\nexport type CarouselProps = {\n /** Index in which the carousel is scrolled to on mount */\n startPosition?: number;\n /** call back for on position changed first prop is the possition */\n onPositionChanged?: (position: number) => void;\n /** show item left and right of current smaller than current item */\n shrinkUnselectedPages?: boolean;\n /** childrent item of the carousel */\n children?: ReactNode;\n /** set carousel image to full width of parent */\n fullWidthChild?: boolean;\n};\n\n/**\n *\n * Lightweight carousel component that works with mouse and touch events,\n * Accepts react node array as children so will work with any html element as a child.\n *\n * Also works with external state that holds carousel postion,\n * by accepting a starting position as a prop, whilst also accepting a handler\n * with current position as a prop triggered when carousel component is interacted with.\n */\nexport const Carousel = ({\n startPosition,\n children,\n onPositionChanged,\n shrinkUnselectedPages = false,\n fullWidthChild = false,\n}: CarouselProps) => {\n const timer = React.useRef<NodeJS.Timeout | string | number | undefined>(\n undefined,\n );\n const isStartPositionSet = typeof startPosition !== \"undefined\";\n const [currentPosition, setCurrentPosition] = useState(startPosition || 0);\n const [smoothScrolling, setSmoothScrolling] = useState(!isStartPositionSet);\n const scrollRef = useRef<HTMLUListElement>(null);\n\n // remove null children\n const childArray = React.Children.toArray(children).filter(Boolean);\n\n const setPosition = (to: number) => {\n if (currentPosition === to) return;\n setCurrentPosition(to);\n\n if (timer) {\n clearTimeout(timer?.current);\n }\n timer.current = setTimeout(() => {\n if (onPositionChanged && smoothScrolling) {\n // Timer to debounce and only send the new position at the end of the scroll.\n // When using external state which also sets start position,\n // if scrolling to a new position past multiple cards,\n // it would effectively scroll to the past the first adjacent card,\n // receive the postion of the first card and stop there before it scrolls any further.\n onPositionChanged(to);\n }\n }, 500);\n };\n\n const next = () => {\n scrollToPosition(currentPosition + 1);\n };\n\n const previous = () => {\n scrollToPosition(currentPosition - 1);\n };\n\n const scrollToPosition = (to: number) => {\n if (scrollRef?.current) {\n const containerWidth = scrollRef.current.scrollWidth;\n const totalItems = scrollRef.current.children.length;\n const atBegining = to === 0;\n const atEnd = to === totalItems - 1;\n\n const item = scrollRef.current.children[to] as HTMLElement;\n if (!item) return;\n const newScroll = item.offsetLeft;\n\n if (atBegining) {\n scrollRef.current.scrollTo(0, 0);\n } else if (atEnd) {\n scrollRef.current.scrollTo(containerWidth, 0);\n } else {\n scrollRef.current.scrollTo(newScroll, 0);\n }\n\n // always resume normal smooth scrolling behaviour after the first scroll\n if (!smoothScrolling) {\n setSmoothScrolling(true);\n }\n }\n };\n\n // Stop smooth scrolling when moving to a starting position\n useEffect(() => {\n if (isStartPositionSet) {\n setSmoothScrolling(false);\n }\n }, [startPosition]);\n\n useEffect(() => {\n if (!smoothScrolling) {\n scrollToPosition(startPosition || 0);\n }\n }, [smoothScrolling]);\n\n const onlyChild = childArray.length === 1;\n\n return (\n <>\n <Box>\n <CarouselWrapper>\n <CarouselScrollArea\n ref={scrollRef}\n aria-live=\"assertive\"\n $smoothScrolling={smoothScrolling}\n tabIndex={0}\n >\n {childArray.map((child, index) => {\n const isSelected = index === currentPosition;\n const keyString = `card-${index}`;\n return (\n <CarouselCard\n key={keyString}\n $onlyChild={onlyChild}\n $fullWidthChild={fullWidthChild}\n >\n <InView\n threshold={0.5}\n as=\"div\"\n onChange={(inView) => {\n if (inView) {\n setPosition(index);\n }\n }}\n >\n <CarouselCardInner\n $onlyChild={onlyChild}\n $isSelected={isSelected}\n $shrinkUnselectedPages={shrinkUnselectedPages}\n $fullWidthChild={fullWidthChild}\n >\n {child}\n </CarouselCardInner>\n </InView>\n </CarouselCard>\n );\n })}\n </CarouselScrollArea>\n </CarouselWrapper>\n </Box>\n {childArray.length > 1 ? (\n <Box>\n <Dots\n count={childArray.length}\n currentPosition={currentPosition}\n scrollToPosition={scrollToPosition}\n next={next}\n previous={previous}\n />\n </Box>\n ) : null}\n </>\n );\n};\n\nexport default memo(Carousel);\n"],"names":["Carousel","_a","startPosition","children","onPositionChanged","_b","shrinkUnselectedPages","_c","fullWidthChild","timer","React","useRef","undefined","isStartPositionSet","_d","useState","currentPosition","setCurrentPosition","_e","smoothScrolling","setSmoothScrolling","scrollRef","childArray","Children","toArray","filter","Boolean","scrollToPosition","to","current","containerWidth","scrollWidth","atBegining","atEnd","length","item","newScroll","offsetLeft","scrollTo","useEffect","onlyChild","createElement","Fragment","Box","CarouselWrapper","CarouselScrollArea","ref","tabIndex","map","child","index","isSelected","keyString","concat","CarouselCard","key","$onlyChild","$fullWidthChild","InView","threshold","as","onChange","inView","clearTimeout","setTimeout","CarouselCardInner","$isSelected","$shrinkUnselectedPages","Dots","count","next","previous","memo"],"mappings":"wVAyCO,IAAMA,EAAW,SAACC,OACvBC,EAAaD,EAAAC,cACbC,EAAQF,EAAAE,SACRC,EAAiBH,EAAAG,kBACjBC,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/Carousel/index.tsx"],"sourcesContent":["import React, {\n useState,\n useRef,\n useEffect,\n memo,\n type ReactNode,\n} from \"react\";\nimport { InView } from \"react-intersection-observer\";\n\nimport { Box } from \"../Box\";\nimport { Dots } from \"./Dots\";\n\nimport {\n CarouselWrapper,\n CarouselCardInner,\n CarouselCard,\n CarouselScrollArea,\n} from \"./styles\";\n\nexport type CarouselProps = {\n /** Index in which the carousel is scrolled to on mount */\n startPosition?: number;\n /** call back for on position changed first prop is the possition */\n onPositionChanged?: (position: number) => void;\n /** show item left and right of current smaller than current item */\n shrinkUnselectedPages?: boolean;\n /** childrent item of the carousel */\n children?: ReactNode;\n /** set carousel image to full width of parent */\n fullWidthChild?: boolean;\n};\n\n/**\n *\n * Lightweight carousel component that works with mouse and touch events,\n * Accepts react node array as children so will work with any html element as a child.\n *\n * Also works with external state that holds carousel postion,\n * by accepting a starting position as a prop, whilst also accepting a handler\n * with current position as a prop triggered when carousel component is interacted with.\n */\nexport const Carousel = ({\n startPosition,\n children,\n onPositionChanged,\n shrinkUnselectedPages = false,\n fullWidthChild = false,\n}: CarouselProps) => {\n const timer = React.useRef<NodeJS.Timeout | string | number | undefined>(\n undefined,\n );\n const isStartPositionSet = typeof startPosition !== \"undefined\";\n const [currentPosition, setCurrentPosition] = useState(startPosition || 0);\n const [smoothScrolling, setSmoothScrolling] = useState(!isStartPositionSet);\n const scrollRef = useRef<HTMLUListElement>(null);\n\n // remove null children\n const childArray = React.Children.toArray(children).filter(Boolean);\n\n const setPosition = (to: number) => {\n if (currentPosition === to) return;\n setCurrentPosition(to);\n\n if (timer) {\n clearTimeout(timer?.current);\n }\n timer.current = setTimeout(() => {\n if (onPositionChanged && smoothScrolling) {\n // Timer to debounce and only send the new position at the end of the scroll.\n // When using external state which also sets start position,\n // if scrolling to a new position past multiple cards,\n // it would effectively scroll to the past the first adjacent card,\n // receive the postion of the first card and stop there before it scrolls any further.\n onPositionChanged(to);\n }\n }, 500);\n };\n\n const next = () => {\n scrollToPosition(currentPosition + 1);\n };\n\n const previous = () => {\n scrollToPosition(currentPosition - 1);\n };\n\n const scrollToPosition = (to: number) => {\n if (scrollRef?.current) {\n const containerWidth = scrollRef.current.scrollWidth;\n const totalItems = scrollRef.current.children.length;\n const atBegining = to === 0;\n const atEnd = to === totalItems - 1;\n\n const item = scrollRef.current.children[to] as HTMLElement;\n if (!item) return;\n const newScroll = item.offsetLeft;\n\n if (atBegining) {\n scrollRef.current.scrollTo(0, 0);\n } else if (atEnd) {\n scrollRef.current.scrollTo(containerWidth, 0);\n } else {\n scrollRef.current.scrollTo(newScroll, 0);\n }\n\n // always resume normal smooth scrolling behaviour after the first scroll\n if (!smoothScrolling) {\n setSmoothScrolling(true);\n }\n }\n };\n\n // Stop smooth scrolling when moving to a starting position\n useEffect(() => {\n if (isStartPositionSet) {\n setSmoothScrolling(false);\n }\n }, [startPosition]);\n\n useEffect(() => {\n if (!smoothScrolling) {\n scrollToPosition(startPosition || 0);\n }\n }, [smoothScrolling]);\n\n const onlyChild = childArray.length === 1;\n\n return (\n <>\n <Box>\n <CarouselWrapper>\n <CarouselScrollArea\n ref={scrollRef}\n aria-live=\"assertive\"\n $smoothScrolling={smoothScrolling}\n tabIndex={0}\n >\n {childArray.map((child, index) => {\n const isSelected = index === currentPosition;\n const keyString = `card-${index}`;\n return (\n <CarouselCard\n key={keyString}\n $onlyChild={onlyChild}\n $fullWidthChild={fullWidthChild}\n >\n <InView\n threshold={0.5}\n as=\"div\"\n onChange={(inView) => {\n if (inView) {\n setPosition(index);\n }\n }}\n >\n <CarouselCardInner\n $onlyChild={onlyChild}\n $isSelected={isSelected}\n $shrinkUnselectedPages={shrinkUnselectedPages}\n $fullWidthChild={fullWidthChild}\n >\n {child}\n </CarouselCardInner>\n </InView>\n </CarouselCard>\n );\n })}\n </CarouselScrollArea>\n </CarouselWrapper>\n </Box>\n {childArray.length > 1 ? (\n <Box>\n <Dots\n count={childArray.length}\n currentPosition={currentPosition}\n scrollToPosition={scrollToPosition}\n next={next}\n previous={previous}\n />\n </Box>\n ) : null}\n </>\n );\n};\n\nexport default memo(Carousel);\n"],"names":["Carousel","_a","startPosition","children","onPositionChanged","_b","shrinkUnselectedPages","_c","fullWidthChild","timer","React","useRef","undefined","isStartPositionSet","_d","useState","currentPosition","setCurrentPosition","_e","smoothScrolling","setSmoothScrolling","scrollRef","childArray","Children","toArray","filter","Boolean","scrollToPosition","to","current","containerWidth","scrollWidth","atBegining","atEnd","length","item","newScroll","offsetLeft","scrollTo","useEffect","onlyChild","createElement","Fragment","Box","CarouselWrapper","CarouselScrollArea","ref","tabIndex","map","child","index","isSelected","keyString","concat","CarouselCard","key","$onlyChild","$fullWidthChild","InView","threshold","as","onChange","inView","clearTimeout","setTimeout","CarouselCardInner","$isSelected","$shrinkUnselectedPages","Dots","count","next","previous","memo"],"mappings":"wVAyCO,IAAMA,EAAW,SAACC,OACvBC,EAAaD,EAAAC,cACbC,EAAQF,EAAAE,SACRC,EAAiBH,EAAAG,kBACjBC,EAAAJ,EAAAK,sBAAAA,OAAqB,IAAAD,KACrBE,EAAAN,EAAAO,eAAAA,OAAc,IAAAD,GAAQA,EAEhBE,EAAQC,EAAMC,YAClBC,GAEIC,OAA8C,IAAlBX,EAC5BY,EAAwCC,EAASb,GAAiB,GAAjEc,EAAeF,EAAA,GAAEG,OAClBC,EAAwCH,GAAUF,GAAjDM,EAAeD,EAAA,GAAEE,EAAkBF,EAAA,GACpCG,EAAYV,EAAyB,MAGrCW,EAAaZ,EAAMa,SAASC,QAAQrB,GAAUsB,OAAOC,SA6BrDC,EAAmB,SAACC,GACxB,GAAIP,aAAS,EAATA,EAAWQ,QAAS,CACtB,IAAMC,EAAiBT,EAAUQ,QAAQE,YAEnCC,EAAoB,IAAPJ,EACbK,EAAQL,IAFKP,EAAUQ,QAAQ1B,SAAS+B,OAEZ,EAE5BC,EAAOd,EAAUQ,QAAQ1B,SAASyB,GACxC,IAAKO,EAAM,OACX,IAAMC,EAAYD,EAAKE,WAEnBL,EACFX,EAAUQ,QAAQS,SAAS,EAAG,GACrBL,EACTZ,EAAUQ,QAAQS,SAASR,EAAgB,GAE3CT,EAAUQ,QAAQS,SAASF,EAAW,GAInCjB,GACHC,GAAmB,GAGzB,EAGAmB,EAAU,WACJ1B,GACFO,GAAmB,EAEvB,EAAG,CAAClB,IAEJqC,EAAU,WACHpB,GACHQ,EAAiBzB,GAAiB,EAEtC,EAAG,CAACiB,IAEJ,IAAMqB,EAAkC,IAAtBlB,EAAWY,OAE7B,OACExB,EAAA+B,cAAA/B,EAAAgC,SAAA,KACEhC,EAAA+B,cAACE,EAAG,KACFjC,EAAA+B,cAACG,EAAe,KACdlC,EAAA+B,cAACI,GACCC,IAAKzB,EAAS,YACJ,6BACQF,EAClB4B,SAAU,GAETzB,EAAW0B,IAAI,SAACC,EAAOC,GACtB,IAAMC,EAAaD,IAAUlC,EACvBoC,EAAY,QAAAC,OAAQH,GAC1B,OACExC,EAAA+B,cAACa,EAAY,CACXC,IAAKH,EAASI,WACFhB,EAASiB,gBACJjD,GAEjBE,EAAA+B,cAACiB,EAAM,CACLC,UAAW,GACXC,GAAG,MACHC,SAAU,SAACC,GA1FT,IAAClC,EA2FGkC,GA1FlB9C,KADeY,EA4FasB,KA1FhCjC,EAAmBW,GAEfnB,GACFsD,aAAatD,eAAAA,EAAOoB,SAEtBpB,EAAMoB,QAAUmC,WAAW,WACrB5D,GAAqBe,GAMvBf,EAAkBwB,IAEnB,QAgFalB,EAAA+B,cAACwB,EAAiB,CAAAT,WACJhB,EAAS0B,YACRf,EAAUgB,uBACC7D,EAAqBmD,gBAC5BjD,GAEhByC,UAShB3B,EAAWY,OAAS,EACnBxB,EAAA+B,cAACE,EAAG,KACFjC,EAAA+B,cAAC2B,EAAI,CACHC,MAAO/C,EAAWY,OAClBlB,gBAAiBA,EACjBW,iBAAkBA,EAClB2C,KAlGG,WACX3C,EAAiBX,EAAkB,EACrC,EAiGUuD,SA/FO,WACf5C,EAAiBX,EAAkB,EACrC,KAgGQ,KAGV,EAEewD,EAAKxE"}
|