@onewelcome/react-lib-components 5.0.0 → 5.2.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/dist/cjs/Button/Button.module.cjs.js +1 -1
- package/dist/cjs/Button/IconButton.module.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridActions/DataGridColumnsToggle.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridActions/DataGridColumnsToggle.cjs.js.map +1 -1
- package/dist/cjs/Form/Radio/Radio.cjs.js.map +1 -1
- package/dist/cjs/Form/Select/Option.cjs.js +1 -1
- package/dist/cjs/Form/Select/Option.cjs.js.map +1 -1
- package/dist/cjs/Icon/Icon.module.cjs.js +1 -1
- package/dist/cjs/Link/Link.module.cjs.js +1 -1
- package/dist/cjs/Notifications/BaseModal/BaseModal.cjs.js +1 -1
- package/dist/cjs/Notifications/BaseModal/BaseModal.cjs.js.map +1 -1
- package/dist/cjs/Notifications/BaseModal/useRepeatFocus.cjs.js +2 -0
- package/dist/cjs/Notifications/BaseModal/useRepeatFocus.cjs.js.map +1 -0
- package/dist/cjs/Stepper/Step.cjs.js +1 -1
- package/dist/cjs/Stepper/Step.cjs.js.map +1 -1
- package/dist/cjs/Stepper/Step.module.cjs.js +1 -1
- package/dist/cjs/Stepper/Stepper.cjs.js +1 -1
- package/dist/cjs/Stepper/Stepper.cjs.js.map +1 -1
- package/dist/cjs/Stepper/Stepper.module.cjs.js +1 -1
- package/dist/cjs/Tooltip/Tooltip.cjs.js +1 -1
- package/dist/cjs/Tooltip/Tooltip.cjs.js.map +1 -1
- package/dist/cjs/Wizard/Wizard.cjs.js.map +1 -1
- package/dist/cjs/Wizard/WizardActions/WizardActions.cjs.js.map +1 -1
- package/dist/cjs/Wizard/WizardStateProvider.cjs.js.map +1 -1
- package/dist/cjs/Wizard/WizardSteps/WizardSteps.cjs.js.map +1 -1
- package/dist/cjs/src/components/Notifications/BaseModal/useRepeatFocus.d.ts +7 -0
- package/dist/cjs/src/components/Stepper/Step.d.ts +5 -3
- package/dist/cjs/src/components/Stepper/Stepper.d.ts +3 -1
- package/dist/cjs/src/components/Wizard/WizardActions/WizardActions.d.ts +3 -0
- package/dist/cjs/src/components/Wizard/WizardStateProvider.d.ts +3 -0
- package/dist/cjs/src/components/Wizard/WizardSteps/WizardSteps.d.ts +3 -0
- package/dist/cjs/src/index.d.ts +1 -0
- package/dist/esm/Button/Button.module.esm.js +1 -1
- package/dist/esm/Button/IconButton.module.esm.js +1 -1
- package/dist/esm/DataGrid/DataGridActions/DataGridColumnsToggle.esm.js +1 -1
- package/dist/esm/DataGrid/DataGridActions/DataGridColumnsToggle.esm.js.map +1 -1
- package/dist/esm/Form/Radio/Radio.esm.js.map +1 -1
- package/dist/esm/Form/Select/Option.esm.js +1 -1
- package/dist/esm/Form/Select/Option.esm.js.map +1 -1
- package/dist/esm/Icon/Icon.module.esm.js +1 -1
- package/dist/esm/Link/Link.module.esm.js +1 -1
- package/dist/esm/Notifications/BaseModal/BaseModal.esm.js +1 -1
- package/dist/esm/Notifications/BaseModal/BaseModal.esm.js.map +1 -1
- package/dist/esm/Notifications/BaseModal/useRepeatFocus.esm.js +2 -0
- package/dist/esm/Notifications/BaseModal/useRepeatFocus.esm.js.map +1 -0
- package/dist/esm/Stepper/Step.esm.js +1 -1
- package/dist/esm/Stepper/Step.esm.js.map +1 -1
- package/dist/esm/Stepper/Step.module.esm.js +1 -1
- package/dist/esm/Stepper/Stepper.esm.js +1 -1
- package/dist/esm/Stepper/Stepper.esm.js.map +1 -1
- package/dist/esm/Stepper/Stepper.module.esm.js +1 -1
- package/dist/esm/Tooltip/Tooltip.esm.js +1 -1
- package/dist/esm/Tooltip/Tooltip.esm.js.map +1 -1
- package/dist/esm/Wizard/Wizard.esm.js.map +1 -1
- package/dist/esm/Wizard/WizardActions/WizardActions.esm.js.map +1 -1
- package/dist/esm/Wizard/WizardStateProvider.esm.js.map +1 -1
- package/dist/esm/Wizard/WizardSteps/WizardSteps.esm.js.map +1 -1
- package/dist/esm/src/components/Notifications/BaseModal/useRepeatFocus.d.ts +7 -0
- package/dist/esm/src/components/Stepper/Step.d.ts +5 -3
- package/dist/esm/src/components/Stepper/Stepper.d.ts +3 -1
- package/dist/esm/src/components/Wizard/WizardActions/WizardActions.d.ts +3 -0
- package/dist/esm/src/components/Wizard/WizardStateProvider.d.ts +3 -0
- package/dist/esm/src/components/Wizard/WizardSteps/WizardSteps.d.ts +3 -0
- package/dist/esm/src/index.d.ts +1 -0
- package/package.json +2 -1
- package/src/components/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +5 -1
- package/src/components/Form/Radio/Radio.tsx +3 -1
- package/src/components/Form/Select/Option.tsx +1 -1
- package/src/components/Notifications/BaseModal/BaseModal.test.tsx +36 -1
- package/src/components/Notifications/BaseModal/BaseModal.tsx +10 -3
- package/src/components/Notifications/BaseModal/useRepeatFocus.tsx +73 -0
- package/src/components/Stepper/Step.module.scss +129 -59
- package/src/components/Stepper/Step.tsx +57 -54
- package/src/components/Stepper/Stepper.module.scss +12 -8
- package/src/components/Stepper/Stepper.test.tsx +3 -3
- package/src/components/Stepper/Stepper.tsx +17 -7
- package/src/components/Tooltip/Tooltip.tsx +2 -2
- package/src/components/Wizard/Wizard.tsx +3 -0
- package/src/components/Wizard/WizardActions/WizardActions.tsx +3 -0
- package/src/components/Wizard/WizardStateProvider.tsx +3 -0
- package/src/components/Wizard/WizardSteps/WizardSteps.tsx +3 -0
- package/src/index.ts +1 -0
- package/src/mixins.module.scss +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.esm.js","sources":["../../../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, {\n ComponentPropsWithRef,\n createRef,\n ForwardRefRenderFunction,\n ReactElement,\n ReactNode,\n RefObject,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState\n} from \"react\";\nimport { Icon, Icons } from \"../Icon/Icon\";\nimport classes from \"./Tooltip.module.scss\";\nimport { generateID } from \"../../util/helper\";\nimport { Offset, Placement, usePosition } from \"../../hooks/usePosition\";\nimport { createPortal } from \"react-dom\";\nimport { useGetDomRoot } from \"../../hooks/useGetDomRoot\";\n\nexport interface Props extends ComponentPropsWithRef<\"div\"> {\n label: ReactNode;\n title?: string;\n children: string;\n domRoot?: HTMLElement;\n location?: \"left\" | \"right\" | \"top\" | \"bottom\";\n color?: \"black\" | \"blue\";\n position?: \"start\" | \"center\" | \"end\";\n}\n\ninterface DefaultPosition {\n placement: Placement;\n offset: Offset;\n transformOrigin: Placement;\n}\n\ntype Location = \"left\" | \"right\" | \"top\" | \"bottom\";\ntype Position = \"start\" | \"end\";\ntype LocationPosition = `${Location}${Capitalize<Position>}` | `${Location}`;\nconst locations: Record<LocationPosition, DefaultPosition> = {\n left: {\n placement: { horizontal: \"left\", vertical: \"center\" },\n offset: { left: 0, right: 12, top: 0, bottom: 0 },\n transformOrigin: { horizontal: \"right\", vertical: \"center\" }\n },\n leftEnd: {\n placement: { horizontal: \"left\", vertical: \"top\" },\n offset: { left: 0, right: 12, top: -12, bottom: 0 },\n transformOrigin: { horizontal: \"right\", vertical: \"top\" }\n },\n leftStart: {\n placement: { horizontal: \"left\", vertical: \"bottom\" },\n offset: { left: 0, right: 12, top: 0, bottom: -12 },\n transformOrigin: { horizontal: \"right\", vertical: \"bottom\" }\n },\n right: {\n placement: { horizontal: \"right\", vertical: \"center\" },\n offset: { left: 12, right: 0, top: 0, bottom: 0 },\n transformOrigin: { horizontal: \"left\", vertical: \"center\" }\n },\n rightEnd: {\n placement: { horizontal: \"right\", vertical: \"top\" },\n offset: { left: 12, right: 0, top: -12, bottom: 0 },\n transformOrigin: { horizontal: \"left\", vertical: \"top\" }\n },\n rightStart: {\n placement: { horizontal: \"right\", vertical: \"bottom\" },\n offset: { left: 12, right: 0, top: 0, bottom: -12 },\n transformOrigin: { horizontal: \"left\", vertical: \"bottom\" }\n },\n top: {\n placement: { horizontal: \"center\", vertical: \"top\" },\n offset: { left: 0, right: 0, top: 0, bottom: 12 },\n transformOrigin: { horizontal: \"center\", vertical: \"bottom\" }\n },\n topEnd: {\n placement: { horizontal: \"left\", vertical: \"top\" },\n offset: { left: -12, right: 0, top: 0, bottom: 12 },\n transformOrigin: { horizontal: \"left\", vertical: \"bottom\" }\n },\n topStart: {\n placement: { horizontal: \"right\", vertical: \"top\" },\n offset: { left: 0, right: -12, top: 0, bottom: 12 },\n transformOrigin: { horizontal: \"right\", vertical: \"bottom\" }\n },\n bottom: {\n placement: { horizontal: \"center\", vertical: \"bottom\" },\n offset: { left: 0, right: 0, top: 12, bottom: 0 },\n transformOrigin: { horizontal: \"center\", vertical: \"top\" }\n },\n bottomEnd: {\n placement: { horizontal: \"left\", vertical: \"bottom\" },\n offset: { left: -12, right: 0, top: 12, bottom: 0 },\n transformOrigin: { horizontal: \"left\", vertical: \"top\" }\n },\n bottomStart: {\n placement: { horizontal: \"right\", vertical: \"bottom\" },\n offset: { left: 0, right: -12, top: 12, bottom: 0 },\n transformOrigin: { horizontal: \"right\", vertical: \"top\" }\n }\n};\n\nconst TooltipComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (\n {\n title,\n children,\n className,\n domRoot,\n label,\n location = \"right\",\n position = \"center\",\n color = \"black\",\n ...rest\n }: Props,\n ref\n) => {\n const [identifier] = useState(generateID());\n const [visible, setVisible] = useState(false);\n const wrappingDivRef = (ref as RefObject<HTMLDivElement>) || createRef<HTMLDivElement>();\n const { root } = useGetDomRoot(domRoot, wrappingDivRef);\n\n const relativeElement = useRef<HTMLDivElement>(null);\n const elementToBePositioned = useRef<HTMLDivElement>(null);\n\n const determinedLocation = useMemo(() => {\n if (position === \"center\") {\n return location;\n }\n\n return `${location}${position.charAt(0).toUpperCase() + position.slice(1)}` as LocationPosition;\n }, [location, position]);\n\n const { top, bottom, right, left, calculatePosition } = usePosition({\n relativeElement: relativeElement,\n elementToBePositioned: elementToBePositioned,\n placement: locations[determinedLocation].placement,\n offset: locations[determinedLocation].offset,\n transformOrigin: locations[determinedLocation].transformOrigin\n });\n\n useEffect(() => {\n if (!visible) return;\n\n function escapePressHandler(event: KeyboardEvent) {\n if (event.key === \"Escape\") {\n setVisible(false);\n }\n }\n\n document.addEventListener(\"keyup\", escapePressHandler);\n\n return () => {\n document.removeEventListener(\"keyup\", escapePressHandler);\n };\n }, [visible]);\n\n useLayoutEffect(() => {\n calculatePosition();\n }, [visible]);\n\n const renderChildren = () => {\n if (React.isValidElement(label)) {\n return React.cloneElement(label as ReactElement, {\n onFocus: () => setVisible(true),\n onBlur: () => setVisible(false),\n \"aria-describedby\": identifier,\n tabIndex: 0,\n className: classes[\"label\"]\n });\n }\n\n return (\n <span\n className={classes[\"label\"]}\n tabIndex={0}\n onFocus={() => setVisible(true)}\n onBlur={() => setVisible(false)}\n aria-describedby={identifier}\n >\n {label}\n </span>\n );\n };\n\n const tooltipClasses = `${classes[\"tooltip\"]} ${classes[color]} ${\n visible ? classes[\"visible\"] : \"\"\n } ${classes[determinedLocation.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, \"$1-$2\").toLowerCase()]}`;\n\n return (\n <div {...rest} ref={wrappingDivRef} className={`${classes.wrapper} ${className ?? \"\"}`}>\n {renderChildren()}\n <div className={`${classes[\"tooltip-wrapper\"]}`}>\n <Icon\n ref={relativeElement}\n tag=\"div\"\n onMouseEnter={() => setVisible(true)}\n onMouseLeave={() => setVisible(false)}\n icon={Icons.InfoCircle}\n className={classes.icon}\n />\n {createPortal(\n <div\n ref={elementToBePositioned}\n style={{\n ...rest.style,\n top: top,\n left: left,\n right: right,\n bottom: bottom\n }}\n aria-hidden={!visible}\n id={identifier}\n className={tooltipClasses}\n >\n {title && <span className={classes[\"tooltip-title\"]}>{title}</span>}\n {children}\n </div>,\n root\n )}\n </div>\n </div>\n );\n};\n\nexport const Tooltip = React.forwardRef(TooltipComponent);\n"],"names":["locations","left","placement","horizontal","vertical","offset","right","top","bottom","transformOrigin","leftEnd","leftStart","rightEnd","rightStart","topEnd","topStart","bottomEnd","bottomStart","TooltipComponent","title","children","className","domRoot","label","location","position","color","rest","ref","identifier","useState","generateID","visible","setVisible","wrappingDivRef","createRef","root","useGetDomRoot","relativeElement","useRef","elementToBePositioned","determinedLocation","useMemo","charAt","toUpperCase","slice","calculatePosition","usePosition","useEffect","escapePressHandler","event","key","document","addEventListener","removeEventListener","useLayoutEffect","renderChildren","React","isValidElement","cloneElement","onFocus","onBlur","tabIndex","classes","createElement","tooltipClasses","replace","toLowerCase","wrapper","Icon","tag","onMouseEnter","onMouseLeave","icon","Icons","InfoCircle","createPortal","style","id","Tooltip","forwardRef"],"mappings":"6aAuDA,MAAMA,EAAuD,CAC3DC,KAAM,CACJC,UAAW,CAAEC,WAAY,OAAQC,SAAU,UAC3CC,OAAQ,CAAEJ,KAAM,EAAGK,MAAO,GAAIC,IAAK,EAAGC,OAAQ,GAC9CC,gBAAiB,CAAEN,WAAY,QAASC,SAAU,WAEpDM,QAAS,CACPR,UAAW,CAAEC,WAAY,OAAQC,SAAU,OAC3CC,OAAQ,CAAEJ,KAAM,EAAGK,MAAO,GAAIC,KAAM,GAAIC,OAAQ,GAChDC,gBAAiB,CAAEN,WAAY,QAASC,SAAU,QAEpDO,UAAW,CACTT,UAAW,CAAEC,WAAY,OAAQC,SAAU,UAC3CC,OAAQ,CAAEJ,KAAM,EAAGK,MAAO,GAAIC,IAAK,EAAGC,QAAS,IAC/CC,gBAAiB,CAAEN,WAAY,QAASC,SAAU,WAEpDE,MAAO,CACLJ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OkC,EAAME,aAAapC,EAAuB,CAC/CqC,QAAS,IAAM3B,EAAW,MAC1B4B,OAAQ,IAAM5B,EAAW,OACzB,mBAAoBJ,EACpBiC,SAAU,EACVzC,UAAW0C,EAAQ,WAIvB,OACEN,EACEO,cAAA,OAAA,CAAA3C,UAAW0C,EAAQ,SACnBD,SAAU,EACVF,QAAS,IAAM3B,EAAW,MAC1B4B,OAAQ,IAAM5B,EAAW,OACP,mBAAAJ,GAEjBN,EAEH,EAGJ,MAAM0C,EAAiB,GAAGF,EAAQ,cAAcA,EAAQrC,MACtDM,EAAU+B,EAAQ,WAAa,MAC7BA,EAAQtB,EAAmByB,QAAQ,+BAAgC,SAASC,iBAEhF,OACEV,0BAAS9B,EAAMC,IAAKM,EAAgBb,UAAW,GAAG0C,EAAQK,WAAW/C,IAAS,MAATA,SAAA,EAAAA,EAAa,MAC/EmC,IACDC,EAAAO,cAAA,MAAA,CAAK3C,UAAW,GAAG0C,EAAQ,sBACzBN,EAAAO,cAACK,EACC,CAAAzC,IAAKU,EACLgC,IAAI,MACJC,aAAc,IAAMtC,EAAW,MAC/BuC,aAAc,IAAMvC,EAAW,OAC/BwC,KAAMC,EAAMC,WACZtD,UAAW0C,EAAQU,OAEpBG,EACCnB,EACEO,cAAA,MAAA,CAAApC,IAAKY,EACLqC,MAAO,IACFlD,EAAKkD,MACRtE,IAAKA,EACLN,KAAMA,EACNK,MAAOA,EACPE,OAAQA,GAEG,eAACwB,EACd8C,GAAIjD,EACJR,UAAW4C,GAEV9C,GAASsC,EAAMO,cAAA,OAAA,CAAA3C,UAAW0C,EAAQ,kBAAmB5C,GACrDC,GAEHgB,IAIN,EAGS,MAAA2C,EAAUtB,EAAMuB,WAAW9D"}
|
|
1
|
+
{"version":3,"file":"Tooltip.esm.js","sources":["../../../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, {\n ComponentPropsWithRef,\n createRef,\n ForwardRefRenderFunction,\n ReactElement,\n ReactNode,\n RefObject,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState\n} from \"react\";\nimport { Icon, Icons } from \"../Icon/Icon\";\nimport classes from \"./Tooltip.module.scss\";\nimport { generateID } from \"../../util/helper\";\nimport { Offset, Placement, usePosition } from \"../../hooks/usePosition\";\nimport { createPortal } from \"react-dom\";\nimport { useGetDomRoot } from \"../../hooks/useGetDomRoot\";\n\nexport interface Props extends ComponentPropsWithRef<\"div\"> {\n label: ReactNode;\n title?: string;\n children: string;\n domRoot?: HTMLElement;\n location?: \"left\" | \"right\" | \"top\" | \"bottom\";\n color?: \"black\" | \"blue\";\n position?: \"start\" | \"center\" | \"end\";\n}\n\ninterface DefaultPosition {\n placement: Placement;\n offset: Offset;\n transformOrigin: Placement;\n}\n\ntype Location = \"left\" | \"right\" | \"top\" | \"bottom\";\ntype Position = \"start\" | \"end\";\ntype LocationPosition = `${Location}${Capitalize<Position>}` | `${Location}`;\nconst locations: Record<LocationPosition, DefaultPosition> = {\n left: {\n placement: { horizontal: \"left\", vertical: \"center\" },\n offset: { left: 0, right: 12, top: 0, bottom: 0 },\n transformOrigin: { horizontal: \"right\", vertical: \"center\" }\n },\n leftEnd: {\n placement: { horizontal: \"left\", vertical: \"top\" },\n offset: { left: 0, right: 12, top: -12, bottom: 0 },\n transformOrigin: { horizontal: \"right\", vertical: \"top\" }\n },\n leftStart: {\n placement: { horizontal: \"left\", vertical: \"bottom\" },\n offset: { left: 0, right: 12, top: 0, bottom: -12 },\n transformOrigin: { horizontal: \"right\", vertical: \"bottom\" }\n },\n right: {\n placement: { horizontal: \"right\", vertical: \"center\" },\n offset: { left: 12, right: 0, top: 0, bottom: 0 },\n transformOrigin: { horizontal: \"left\", vertical: \"center\" }\n },\n rightEnd: {\n placement: { horizontal: \"right\", vertical: \"top\" },\n offset: { left: 12, right: 0, top: -12, bottom: 0 },\n transformOrigin: { horizontal: \"left\", vertical: \"top\" }\n },\n rightStart: {\n placement: { horizontal: \"right\", vertical: \"bottom\" },\n offset: { left: 12, right: 0, top: 0, bottom: -12 },\n transformOrigin: { horizontal: \"left\", vertical: \"bottom\" }\n },\n top: {\n placement: { horizontal: \"center\", vertical: \"top\" },\n offset: { left: 0, right: 0, top: 0, bottom: 12 },\n transformOrigin: { horizontal: \"center\", vertical: \"bottom\" }\n },\n topEnd: {\n placement: { horizontal: \"left\", vertical: \"top\" },\n offset: { left: -12, right: 0, top: 0, bottom: 12 },\n transformOrigin: { horizontal: \"left\", vertical: \"bottom\" }\n },\n topStart: {\n placement: { horizontal: \"right\", vertical: \"top\" },\n offset: { left: 0, right: -12, top: 0, bottom: 12 },\n transformOrigin: { horizontal: \"right\", vertical: \"bottom\" }\n },\n bottom: {\n placement: { horizontal: \"center\", vertical: \"bottom\" },\n offset: { left: 0, right: 0, top: 12, bottom: 0 },\n transformOrigin: { horizontal: \"center\", vertical: \"top\" }\n },\n bottomEnd: {\n placement: { horizontal: \"left\", vertical: \"bottom\" },\n offset: { left: -12, right: 0, top: 12, bottom: 0 },\n transformOrigin: { horizontal: \"left\", vertical: \"top\" }\n },\n bottomStart: {\n placement: { horizontal: \"right\", vertical: \"bottom\" },\n offset: { left: 0, right: -12, top: 12, bottom: 0 },\n transformOrigin: { horizontal: \"right\", vertical: \"top\" }\n }\n};\n\nconst TooltipComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (\n {\n title,\n children,\n className,\n domRoot,\n label,\n location = \"right\",\n position = \"center\",\n color = \"black\",\n ...rest\n }: Props,\n ref\n) => {\n const [identifier] = useState(generateID());\n const [visible, setVisible] = useState(false);\n const wrappingDivRef = (ref as RefObject<HTMLDivElement>) || createRef<HTMLDivElement>();\n const { root } = useGetDomRoot(domRoot, wrappingDivRef);\n\n const relativeElement = useRef<HTMLDivElement>(null);\n const elementToBePositioned = useRef<HTMLDivElement>(null);\n\n const determinedLocation = useMemo(() => {\n if (position === \"center\") {\n return location;\n }\n\n return `${location}${position.charAt(0).toUpperCase() + position.slice(1)}` as LocationPosition;\n }, [location, position]);\n\n const { top, bottom, right, left, calculatePosition } = usePosition({\n relativeElement: relativeElement,\n elementToBePositioned: elementToBePositioned,\n placement: locations[determinedLocation].placement,\n offset: locations[determinedLocation].offset,\n transformOrigin: locations[determinedLocation].transformOrigin\n });\n\n useEffect(() => {\n if (!visible) return;\n\n const escapePressHandler = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n setVisible(false);\n }\n };\n\n document.addEventListener(\"keyup\", escapePressHandler);\n\n return () => {\n document.removeEventListener(\"keyup\", escapePressHandler);\n };\n }, [visible]);\n\n useLayoutEffect(() => {\n calculatePosition();\n }, [visible]);\n\n const renderChildren = () => {\n if (React.isValidElement(label)) {\n return React.cloneElement(label as ReactElement, {\n onFocus: () => setVisible(true),\n onBlur: () => setVisible(false),\n \"aria-describedby\": identifier,\n tabIndex: 0,\n className: classes[\"label\"]\n });\n }\n\n return (\n <span\n className={classes[\"label\"]}\n tabIndex={0}\n onFocus={() => setVisible(true)}\n onBlur={() => setVisible(false)}\n aria-describedby={identifier}\n >\n {label}\n </span>\n );\n };\n\n const tooltipClasses = `${classes[\"tooltip\"]} ${classes[color]} ${\n visible ? classes[\"visible\"] : \"\"\n } ${classes[determinedLocation.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, \"$1-$2\").toLowerCase()]}`;\n\n return (\n <div {...rest} ref={wrappingDivRef} className={`${classes.wrapper} ${className ?? \"\"}`}>\n {renderChildren()}\n <div className={`${classes[\"tooltip-wrapper\"]}`}>\n <Icon\n ref={relativeElement}\n tag=\"div\"\n onMouseEnter={() => setVisible(true)}\n onMouseLeave={() => setVisible(false)}\n icon={Icons.InfoCircle}\n className={classes.icon}\n />\n {createPortal(\n <div\n ref={elementToBePositioned}\n style={{\n ...rest.style,\n top: top,\n left: left,\n right: right,\n bottom: bottom\n }}\n aria-hidden={!visible}\n id={identifier}\n className={tooltipClasses}\n >\n {title && <span className={classes[\"tooltip-title\"]}>{title}</span>}\n {children}\n </div>,\n root\n )}\n </div>\n </div>\n );\n};\n\nexport const Tooltip = React.forwardRef(TooltipComponent);\n"],"names":["locations","left","placement","horizontal","vertical","offset","right","top","bottom","transformOrigin","leftEnd","leftStart","rightEnd","rightStart","topEnd","topStart","bottomEnd","bottomStart","TooltipComponent","title","children","className","domRoot","label","location","position","color","rest","ref","identifier","useState","generateID","visible","setVisible","wrappingDivRef","createRef","root","useGetDomRoot","relativeElement","useRef","elementToBePositioned","determinedLocation","useMemo","charAt","toUpperCase","slice","calculatePosition","usePosition","useEffect","escapePressHandler","event","key","document","addEventListener","removeEventListener","useLayoutEffect","renderChildren","React","isValidElement","cloneElement","onFocus","onBlur","tabIndex","classes","createElement","tooltipClasses","replace","toLowerCase","wrapper","Icon","tag","onMouseEnter","onMouseLeave","icon","Icons","InfoCircle","createPortal","style","id","Tooltip","forwardRef"],"mappings":"6aAuDA,MAAMA,EAAuD,CAC3DC,KAAM,CACJC,UAAW,CAAEC,WAAY,OAAQC,SAAU,UAC3CC,OAAQ,CAAEJ,KAAM,EAAGK,MAAO,GAAIC,IAAK,EAAGC,OAAQ,GAC9CC,gBAAiB,CAAEN,WAAY,QAASC,SAAU,WAEpDM,QAAS,CACPR,UAAW,CAAEC,WAAY,OAAQC,SAAU,OAC3CC,OAAQ,CAAEJ,KAAM,EAAGK,MAAO,GAAIC,KAAM,GAAIC,OAAQ,GAChDC,gBAAiB,CAAEN,WAAY,QAASC,SAAU,QAEpDO,UAAW,CACTT,UAAW,CAAEC,WAAY,OAAQC,SAAU,UAC3CC,OAAQ,CAAEJ,KAAM,EA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../src/components/Wizard/Wizard.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { Fragment, useContext, useEffect } from \"react\";\nimport { Step } from \"./BaseWizardSteps/BaseWizardSteps\";\nimport { WizardStateContext, WizardStateProvider } from \"./WizardStateProvider\";\nimport { setWizardState } from \"./wizardStateReducer\";\n\nexport type WizardMode = \"add\" | \"edit\";\n\nexport interface Props {\n steps: Step[];\n mode: WizardMode;\n initialStepNo?: number;\n onStepChange: (stepNo: number) => void;\n children: React.ReactNode;\n}\n\nconst useSetWizardState = (steps: Step[], mode: WizardMode) => {\n const { dispatch } = useContext(WizardStateContext);\n\n useEffect(() => {\n dispatch(setWizardState(steps, mode));\n }, [steps, mode]);\n};\n\nconst useStepChanging = (onStepChange: (stepNo: number) => void) => {\n const {\n state: { currentStepNo }\n } = useContext(WizardStateContext);\n\n useEffect(() => {\n onStepChange(currentStepNo);\n }, [currentStepNo]);\n};\n\nconst WizardContent = ({ steps, mode, onStepChange, children }: Props) => {\n useSetWizardState(steps, mode);\n useStepChanging(onStepChange);\n\n return <Fragment>{children}</Fragment>;\n};\n\nexport const Wizard = (props: Props) => {\n const { steps, initialStepNo: currentStepNo = 0, mode } = props;\n return (\n <WizardStateProvider initialState={{ steps, currentStepNo, mode }}>\n <WizardContent {...props} />\n </WizardStateProvider>\n );\n};\n"],"names":["useSetWizardState","steps","mode","dispatch","useContext","WizardStateContext","useEffect","setWizardState","useStepChanging","onStepChange","state","currentStepNo","WizardContent","children","React","createElement","Fragment","Wizard","props","initialStepNo","WizardStateProvider","initialState"],"mappings":"2NA+BA,MAAMA,EAAoB,CAACC,EAAeC,KACxC,MAAMC,SAAEA,GAAaC,EAAWC,GAEhCC,GAAU,KACRH,EAASI,EAAeN,EAAOC,GAAM,GACpC,CAACD,EAAOC,GAAM,EAGnB,MAAMM,EAAmBC,IACvB,MACEC,OAAOC,cAAEA,IACPP,EAAWC,GAEfC,GAAU,KACRG,EAAaE,EAAc,GAC1B,CAACA,GAAe,
|
|
1
|
+
{"version":3,"file":"Wizard.esm.js","sources":["../../../../../src/components/Wizard/Wizard.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { Fragment, useContext, useEffect } from \"react\";\nimport { Step } from \"./BaseWizardSteps/BaseWizardSteps\";\nimport { WizardStateContext, WizardStateProvider } from \"./WizardStateProvider\";\nimport { setWizardState } from \"./wizardStateReducer\";\n\nexport type WizardMode = \"add\" | \"edit\";\n\nexport interface Props {\n steps: Step[];\n mode: WizardMode;\n initialStepNo?: number;\n onStepChange: (stepNo: number) => void;\n children: React.ReactNode;\n}\n\nconst useSetWizardState = (steps: Step[], mode: WizardMode) => {\n const { dispatch } = useContext(WizardStateContext);\n\n useEffect(() => {\n dispatch(setWizardState(steps, mode));\n }, [steps, mode]);\n};\n\nconst useStepChanging = (onStepChange: (stepNo: number) => void) => {\n const {\n state: { currentStepNo }\n } = useContext(WizardStateContext);\n\n useEffect(() => {\n onStepChange(currentStepNo);\n }, [currentStepNo]);\n};\n\n/**\n * @deprecated\n */\nconst WizardContent = ({ steps, mode, onStepChange, children }: Props) => {\n useSetWizardState(steps, mode);\n useStepChanging(onStepChange);\n\n return <Fragment>{children}</Fragment>;\n};\n\nexport const Wizard = (props: Props) => {\n const { steps, initialStepNo: currentStepNo = 0, mode } = props;\n return (\n <WizardStateProvider initialState={{ steps, currentStepNo, mode }}>\n <WizardContent {...props} />\n </WizardStateProvider>\n );\n};\n"],"names":["useSetWizardState","steps","mode","dispatch","useContext","WizardStateContext","useEffect","setWizardState","useStepChanging","onStepChange","state","currentStepNo","WizardContent","children","React","createElement","Fragment","Wizard","props","initialStepNo","WizardStateProvider","initialState"],"mappings":"2NA+BA,MAAMA,EAAoB,CAACC,EAAeC,KACxC,MAAMC,SAAEA,GAAaC,EAAWC,GAEhCC,GAAU,KACRH,EAASI,EAAeN,EAAOC,GAAM,GACpC,CAACD,EAAOC,GAAM,EAGnB,MAAMM,EAAmBC,IACvB,MACEC,OAAOC,cAAEA,IACPP,EAAWC,GAEfC,GAAU,KACRG,EAAaE,EAAc,GAC1B,CAACA,GAAe,EAMrB,MAAMC,EAAgB,EAAGX,QAAOC,OAAMO,eAAcI,eAClDb,EAAkBC,EAAOC,GACzBM,EAAgBC,GAEhB,OAAOK,EAACC,cAAAC,EAAU,KAAAH,EAAoB,EAG3B,MAAAI,EAAUC,IACrB,MAAMjB,MAAEA,EAAOkB,cAAeR,EAAgB,EAACT,KAAEA,GAASgB,EAC1D,OACEJ,EAAAC,cAACK,EAAmB,CAACC,aAAc,CAAEpB,QAAOU,gBAAeT,SACzDY,EAAAC,cAACH,EAAkB,IAAAM,IAErB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WizardActions.esm.js","sources":["../../../../../../src/components/Wizard/WizardActions/WizardActions.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { Fragment, useContext, useMemo } from \"react\";\nimport { Button, Props as ButtonProps } from \"../../Button/Button\";\nimport { Step } from \"../BaseWizardSteps/BaseWizardSteps\";\nimport { WizardMode } from \"../Wizard\";\nimport { WizardStateContext } from \"../WizardStateProvider\";\nimport { changeCurrentStepNo } from \"../wizardStateReducer\";\n\nexport interface Props extends React.HTMLProps<HTMLDivElement> {\n actions: {\n previous: {\n label: string;\n onClick: () => void;\n previousButtonProps?: ButtonProps;\n };\n next: {\n label: string;\n onClick: (currentStepNo: number) => boolean;\n nextButtonProps?: ButtonProps;\n };\n saveAndClose: {\n label: string;\n onClick: (currentStepNo: number) => void;\n saveAndCloseButtonProps?: ButtonProps;\n };\n };\n}\n\nconst calculateNextStepNo = (steps: Step[], currentStepNo: number) => () =>\n steps.findIndex((step, stepNo) => stepNo > currentStepNo && !step.disabled);\n\nconst calculatePrevStepNo = (steps: Step[], currentStepNo: number) => () => {\n const reversedCurrentStepNo = steps.length - 1 - currentStepNo;\n const reversedPrevStepNo = [...steps]\n .reverse()\n .findIndex((step, stepNo) => stepNo > reversedCurrentStepNo && !step.disabled);\n if (reversedPrevStepNo > 0) {\n return steps.length - 1 - reversedPrevStepNo;\n }\n return -1;\n};\n\nconst useNextStepNo = (mode: WizardMode, currentStepNo: number, steps: Step[]) =>\n useMemo(calculateNextStepNo(steps, currentStepNo), [mode, currentStepNo, steps]);\n\nconst usePreviousStepNo = (mode: WizardMode, currentStepNo: number, steps: Step[]) =>\n useMemo(calculatePrevStepNo(steps, currentStepNo), [mode, currentStepNo, steps]);\n\nexport const WizardActions = ({ actions }: Props) => {\n const {\n state: { mode, steps, currentStepNo },\n dispatch\n } = useContext(WizardStateContext);\n const nextStepNo = useNextStepNo(mode, currentStepNo, steps);\n const hasNextStep = nextStepNo !== -1;\n const previousStepNo = usePreviousStepNo(mode, currentStepNo, steps);\n const hasPreviousStep = previousStepNo !== -1;\n const isLastStepOrEditMode = !hasNextStep || mode === \"edit\";\n\n const changeStepNo = (direction: \"forward\" | \"backward\") => {\n if (direction === \"forward\") {\n hasNextStep && dispatch(changeCurrentStepNo(nextStepNo));\n } else {\n hasPreviousStep && dispatch(changeCurrentStepNo(previousStepNo));\n }\n };\n\n const onNextWrapper = () => {\n actions.next.onClick(currentStepNo) && changeStepNo(\"forward\");\n };\n\n const onPreviousWrapper = () => {\n actions.previous.onClick?.();\n changeStepNo(\"backward\");\n };\n\n const onSaveAndCloseWrapper = () => {\n actions.saveAndClose.onClick(currentStepNo);\n };\n\n return (\n <Fragment>\n {hasPreviousStep && (\n <Button variant=\"outline\" onClick={onPreviousWrapper}>\n {actions.previous.label}\n </Button>\n )}\n {hasNextStep && (\n <Button variant={mode === \"edit\" ? \"outline\" : \"fill\"} onClick={onNextWrapper}>\n {actions.next.label}\n </Button>\n )}\n {isLastStepOrEditMode && (\n <Button onClick={onSaveAndCloseWrapper}>{actions.saveAndClose.label}</Button>\n )}\n </Fragment>\n );\n};\n"],"names":["calculateNextStepNo","steps","currentStepNo","findIndex","step","stepNo","disabled","calculatePrevStepNo","reversedCurrentStepNo","length","reversedPrevStepNo","reverse","useNextStepNo","mode","useMemo","usePreviousStepNo","WizardActions","actions","state","dispatch","useContext","WizardStateContext","nextStepNo","hasNextStep","previousStepNo","hasPreviousStep","isLastStepOrEditMode","changeStepNo","direction","changeCurrentStepNo","onNextWrapper","next","onClick","onPreviousWrapper","_b","previous","onSaveAndCloseWrapper","saveAndClose","React","Fragment","createElement","Button","variant","label"],"mappings":"2PA2CA,MAAMA,EAAsB,CAACC,EAAeC,IAA0B,IACpED,EAAME,WAAU,CAACC,EAAMC,IAAWA,EAASH,IAAkBE,EAAKE,WAEpE,MAAMC,EAAsB,CAACN,EAAeC,IAA0B,KACpE,MAAMM,EAAwBP,EAAMQ,OAAS,EAAIP,EACjD,MAAMQ,EAAqB,IAAIT,GAC5BU,UACAR,WAAU,CAACC,EAAMC,IAAWA,EAASG,IAA0BJ,EAAKE,WACvE,GAAII,EAAqB,EACvB,OAAOT,EAAMQ,OAAS,EAAIC,EAE5B,OAAQ,CAAC,EAGX,MAAME,EAAgB,CAACC,EAAkBX,EAAuBD,IAC9Da,EAAQd,EAAoBC,EAAOC,GAAgB,CAACW,EAAMX,EAAeD,IAE3E,MAAMc,EAAoB,CAACF,EAAkBX,EAAuBD,IAClEa,EAAQP,EAAoBN,EAAOC,GAAgB,CAACW,EAAMX,EAAeD,
|
|
1
|
+
{"version":3,"file":"WizardActions.esm.js","sources":["../../../../../../src/components/Wizard/WizardActions/WizardActions.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { Fragment, useContext, useMemo } from \"react\";\nimport { Button, Props as ButtonProps } from \"../../Button/Button\";\nimport { Step } from \"../BaseWizardSteps/BaseWizardSteps\";\nimport { WizardMode } from \"../Wizard\";\nimport { WizardStateContext } from \"../WizardStateProvider\";\nimport { changeCurrentStepNo } from \"../wizardStateReducer\";\n\nexport interface Props extends React.HTMLProps<HTMLDivElement> {\n actions: {\n previous: {\n label: string;\n onClick: () => void;\n previousButtonProps?: ButtonProps;\n };\n next: {\n label: string;\n onClick: (currentStepNo: number) => boolean;\n nextButtonProps?: ButtonProps;\n };\n saveAndClose: {\n label: string;\n onClick: (currentStepNo: number) => void;\n saveAndCloseButtonProps?: ButtonProps;\n };\n };\n}\n\nconst calculateNextStepNo = (steps: Step[], currentStepNo: number) => () =>\n steps.findIndex((step, stepNo) => stepNo > currentStepNo && !step.disabled);\n\nconst calculatePrevStepNo = (steps: Step[], currentStepNo: number) => () => {\n const reversedCurrentStepNo = steps.length - 1 - currentStepNo;\n const reversedPrevStepNo = [...steps]\n .reverse()\n .findIndex((step, stepNo) => stepNo > reversedCurrentStepNo && !step.disabled);\n if (reversedPrevStepNo > 0) {\n return steps.length - 1 - reversedPrevStepNo;\n }\n return -1;\n};\n\nconst useNextStepNo = (mode: WizardMode, currentStepNo: number, steps: Step[]) =>\n useMemo(calculateNextStepNo(steps, currentStepNo), [mode, currentStepNo, steps]);\n\nconst usePreviousStepNo = (mode: WizardMode, currentStepNo: number, steps: Step[]) =>\n useMemo(calculatePrevStepNo(steps, currentStepNo), [mode, currentStepNo, steps]);\n\n/**\n * @deprecated\n */\nexport const WizardActions = ({ actions }: Props) => {\n const {\n state: { mode, steps, currentStepNo },\n dispatch\n } = useContext(WizardStateContext);\n const nextStepNo = useNextStepNo(mode, currentStepNo, steps);\n const hasNextStep = nextStepNo !== -1;\n const previousStepNo = usePreviousStepNo(mode, currentStepNo, steps);\n const hasPreviousStep = previousStepNo !== -1;\n const isLastStepOrEditMode = !hasNextStep || mode === \"edit\";\n\n const changeStepNo = (direction: \"forward\" | \"backward\") => {\n if (direction === \"forward\") {\n hasNextStep && dispatch(changeCurrentStepNo(nextStepNo));\n } else {\n hasPreviousStep && dispatch(changeCurrentStepNo(previousStepNo));\n }\n };\n\n const onNextWrapper = () => {\n actions.next.onClick(currentStepNo) && changeStepNo(\"forward\");\n };\n\n const onPreviousWrapper = () => {\n actions.previous.onClick?.();\n changeStepNo(\"backward\");\n };\n\n const onSaveAndCloseWrapper = () => {\n actions.saveAndClose.onClick(currentStepNo);\n };\n\n return (\n <Fragment>\n {hasPreviousStep && (\n <Button variant=\"outline\" onClick={onPreviousWrapper}>\n {actions.previous.label}\n </Button>\n )}\n {hasNextStep && (\n <Button variant={mode === \"edit\" ? \"outline\" : \"fill\"} onClick={onNextWrapper}>\n {actions.next.label}\n </Button>\n )}\n {isLastStepOrEditMode && (\n <Button onClick={onSaveAndCloseWrapper}>{actions.saveAndClose.label}</Button>\n )}\n </Fragment>\n );\n};\n"],"names":["calculateNextStepNo","steps","currentStepNo","findIndex","step","stepNo","disabled","calculatePrevStepNo","reversedCurrentStepNo","length","reversedPrevStepNo","reverse","useNextStepNo","mode","useMemo","usePreviousStepNo","WizardActions","actions","state","dispatch","useContext","WizardStateContext","nextStepNo","hasNextStep","previousStepNo","hasPreviousStep","isLastStepOrEditMode","changeStepNo","direction","changeCurrentStepNo","onNextWrapper","next","onClick","onPreviousWrapper","_b","previous","onSaveAndCloseWrapper","saveAndClose","React","Fragment","createElement","Button","variant","label"],"mappings":"2PA2CA,MAAMA,EAAsB,CAACC,EAAeC,IAA0B,IACpED,EAAME,WAAU,CAACC,EAAMC,IAAWA,EAASH,IAAkBE,EAAKE,WAEpE,MAAMC,EAAsB,CAACN,EAAeC,IAA0B,KACpE,MAAMM,EAAwBP,EAAMQ,OAAS,EAAIP,EACjD,MAAMQ,EAAqB,IAAIT,GAC5BU,UACAR,WAAU,CAACC,EAAMC,IAAWA,EAASG,IAA0BJ,EAAKE,WACvE,GAAII,EAAqB,EACvB,OAAOT,EAAMQ,OAAS,EAAIC,EAE5B,OAAQ,CAAC,EAGX,MAAME,EAAgB,CAACC,EAAkBX,EAAuBD,IAC9Da,EAAQd,EAAoBC,EAAOC,GAAgB,CAACW,EAAMX,EAAeD,IAE3E,MAAMc,EAAoB,CAACF,EAAkBX,EAAuBD,IAClEa,EAAQP,EAAoBN,EAAOC,GAAgB,CAACW,EAAMX,EAAeD,UAK9De,EAAgB,EAAGC,cAC9B,MACEC,OAAOL,KAAEA,EAAIZ,MAAEA,EAAKC,cAAEA,GAAeiB,SACrCA,GACEC,EAAWC,GACf,MAAMC,EAAaV,EAAcC,EAAMX,EAAeD,GACtD,MAAMsB,EAAcD,KAAgB,EACpC,MAAME,EAAiBT,EAAkBF,EAAMX,EAAeD,GAC9D,MAAMwB,EAAkBD,KAAoB,EAC5C,MAAME,GAAwBH,GAAeV,IAAS,OAEtD,MAAMc,EAAgBC,IACpB,GAAIA,IAAc,UAChBL,GAAeJ,EAASU,EAAoBP,SAE5CG,GAAmBN,EAASU,EAAoBL,GACjD,EAGH,MAAMM,EAAgB,KACpBb,EAAQc,KAAKC,QAAQ9B,IAAkByB,EAAa,UAAU,EAGhE,MAAMM,EAAoB,cACxBC,KAAAjB,EAAQkB,UAASH,6CACjBL,EAAa,WAAW,EAG1B,MAAMS,EAAwB,KAC5BnB,EAAQoB,aAAaL,QAAQ9B,EAAc,EAG7C,OACEoC,gBAACC,EAAQ,KACNd,GACCa,EAAAE,cAACC,EAAO,CAAAC,QAAQ,UAAUV,QAASC,GAChChB,EAAQkB,SAASQ,OAGrBpB,GACCe,EAACE,cAAAC,EAAO,CAAAC,QAAS7B,IAAS,OAAS,UAAY,OAAQmB,QAASF,GAC7Db,EAAQc,KAAKY,OAGjBjB,GACCY,EAAAE,cAACC,EAAO,CAAAT,QAASI,GAAwBnB,EAAQoB,aAAaM,OAGlE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WizardStateProvider.esm.js","sources":["../../../../../src/components/Wizard/WizardStateProvider.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { createContext, Dispatch, useReducer } from \"react\";\nimport { WizardActions, WizardStateType, reducer } from \"./wizardStateReducer\";\n\nconst WizardStateContext = createContext<{\n state: WizardStateType;\n dispatch: Dispatch<WizardActions>;\n}>({\n state: {} as WizardStateType,\n dispatch: () => null\n});\n\nexport interface Props {\n initialState: WizardStateType;\n children?: React.ReactNode;\n}\n\nconst WizardStateProvider = ({ children, initialState }: Props) => {\n const [state, dispatch] = useReducer(reducer, initialState);\n return (\n <WizardStateContext.Provider value={{ state, dispatch }}>\n {children}\n </WizardStateContext.Provider>\n );\n};\n\nexport { WizardStateProvider, WizardStateContext };\n"],"names":["WizardStateContext","createContext","state","dispatch","WizardStateProvider","children","initialState","useReducer","reducer","React","createElement","Provider","value"],"mappings":"+GAmBM,MAAAA,EAAqBC,EAGxB,CACDC,MAAO,CAAqB,EAC5BC,SAAU,IAAM,
|
|
1
|
+
{"version":3,"file":"WizardStateProvider.esm.js","sources":["../../../../../src/components/Wizard/WizardStateProvider.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { createContext, Dispatch, useReducer } from \"react\";\nimport { WizardActions, WizardStateType, reducer } from \"./wizardStateReducer\";\n\nconst WizardStateContext = createContext<{\n state: WizardStateType;\n dispatch: Dispatch<WizardActions>;\n}>({\n state: {} as WizardStateType,\n dispatch: () => null\n});\n\nexport interface Props {\n initialState: WizardStateType;\n children?: React.ReactNode;\n}\n\n/**\n * @deprecated\n */\nconst WizardStateProvider = ({ children, initialState }: Props) => {\n const [state, dispatch] = useReducer(reducer, initialState);\n return (\n <WizardStateContext.Provider value={{ state, dispatch }}>\n {children}\n </WizardStateContext.Provider>\n );\n};\n\nexport { WizardStateProvider, WizardStateContext };\n"],"names":["WizardStateContext","createContext","state","dispatch","WizardStateProvider","children","initialState","useReducer","reducer","React","createElement","Provider","value"],"mappings":"+GAmBM,MAAAA,EAAqBC,EAGxB,CACDC,MAAO,CAAqB,EAC5BC,SAAU,IAAM,OAWZ,MAAAC,EAAsB,EAAGC,WAAUC,mBACvC,MAAOJ,EAAOC,GAAYI,EAAWC,EAASF,GAC9C,OACEG,EAACC,cAAAV,EAAmBW,UAASC,MAAO,CAAEV,QAAOC,aAC1CE,EAEH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WizardSteps.esm.js","sources":["../../../../../../src/components/Wizard/WizardSteps/WizardSteps.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { ForwardRefRenderFunction, ComponentPropsWithRef, useContext } from \"react\";\nimport { WizardStateContext } from \"../WizardStateProvider\";\nimport { BaseWizardSteps } from \"../BaseWizardSteps/BaseWizardSteps\";\nimport { changeCurrentStepNo } from \"../wizardStateReducer\";\n\nexport interface Props extends ComponentPropsWithRef<\"div\"> {\n onStepClick: (currentStepNo: number, selectedStepNo: number) => boolean;\n}\n\nconst WizardStepsComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (\n { onStepClick, ...rest }: Props,\n ref\n) => {\n const {\n state: { currentStepNo, mode, steps },\n dispatch\n } = useContext(WizardStateContext);\n\n const onClick = (selectedStepNo: number) => {\n onStepClick(currentStepNo, selectedStepNo) && dispatch(changeCurrentStepNo(selectedStepNo));\n };\n\n return (\n <BaseWizardSteps\n {...rest}\n ref={ref}\n onClick={onClick}\n steps={steps}\n currentStepNo={currentStepNo}\n futureStepsClickable={mode === \"edit\"}\n />\n );\n};\n\nexport const WizardSteps = React.forwardRef(WizardStepsComponent);\n"],"names":["WizardStepsComponent","onStepClick","rest","ref","state","currentStepNo","mode","steps","dispatch","useContext","WizardStateContext","onClick","selectedStepNo","changeCurrentStepNo","React","createElement","BaseWizardSteps","futureStepsClickable","WizardSteps","forwardRef"],"mappings":"wPAyBA,MAAMA,EAAwE,EAC1EC,iBAAgBC,GAClBC,KAEA,MACEC,OAAOC,cAAEA,EAAaC,KAAEA,EAAIC,MAAEA,GAAOC,SACrCA,GACEC,EAAWC,GAEf,MAAMC,EAAWC,IACfX,EAAYI,EAAeO,IAAmBJ,EAASK,EAAoBD,GAAgB,EAG7F,OACEE,EAAAC,cAACC,EAAe,IACVd,EACJC,IAAKA,EACLQ,QAASA,EACTJ,MAAOA,EACPF,cAAeA,EACfY,qBAAsBX,IAAS,QAEjC,
|
|
1
|
+
{"version":3,"file":"WizardSteps.esm.js","sources":["../../../../../../src/components/Wizard/WizardSteps/WizardSteps.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { ForwardRefRenderFunction, ComponentPropsWithRef, useContext } from \"react\";\nimport { WizardStateContext } from \"../WizardStateProvider\";\nimport { BaseWizardSteps } from \"../BaseWizardSteps/BaseWizardSteps\";\nimport { changeCurrentStepNo } from \"../wizardStateReducer\";\n\nexport interface Props extends ComponentPropsWithRef<\"div\"> {\n onStepClick: (currentStepNo: number, selectedStepNo: number) => boolean;\n}\n\nconst WizardStepsComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (\n { onStepClick, ...rest }: Props,\n ref\n) => {\n const {\n state: { currentStepNo, mode, steps },\n dispatch\n } = useContext(WizardStateContext);\n\n const onClick = (selectedStepNo: number) => {\n onStepClick(currentStepNo, selectedStepNo) && dispatch(changeCurrentStepNo(selectedStepNo));\n };\n\n return (\n <BaseWizardSteps\n {...rest}\n ref={ref}\n onClick={onClick}\n steps={steps}\n currentStepNo={currentStepNo}\n futureStepsClickable={mode === \"edit\"}\n />\n );\n};\n\n/**\n * @deprecated\n */\nexport const WizardSteps = React.forwardRef(WizardStepsComponent);\n"],"names":["WizardStepsComponent","onStepClick","rest","ref","state","currentStepNo","mode","steps","dispatch","useContext","WizardStateContext","onClick","selectedStepNo","changeCurrentStepNo","React","createElement","BaseWizardSteps","futureStepsClickable","WizardSteps","forwardRef"],"mappings":"wPAyBA,MAAMA,EAAwE,EAC1EC,iBAAgBC,GAClBC,KAEA,MACEC,OAAOC,cAAEA,EAAaC,KAAEA,EAAIC,MAAEA,GAAOC,SACrCA,GACEC,EAAWC,GAEf,MAAMC,EAAWC,IACfX,EAAYI,EAAeO,IAAmBJ,EAASK,EAAoBD,GAAgB,EAG7F,OACEE,EAAAC,cAACC,EAAe,IACVd,EACJC,IAAKA,EACLQ,QAASA,EACTJ,MAAOA,EACPF,cAAeA,EACfY,qBAAsBX,IAAS,QAEjC,EAMS,MAAAY,EAAcJ,EAAMK,WAAWnB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* @description This is a hook that will make sure that when a modal is open and the user tabs through the it,
|
|
4
|
+
* the focus will be repeated and the user will not lose their entire focusable element to an element in the background
|
|
5
|
+
* that is being blocked by the modal.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useRepeatFocus: (ref: RefObject<HTMLDivElement>) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ComponentPropsWithRef, ForwardRefRenderFunction } from "react";
|
|
2
2
|
export type StepStatus = "waiting" | "current" | "done" | "error";
|
|
3
|
-
export interface Props extends ComponentPropsWithRef<"
|
|
3
|
+
export interface Props extends Omit<ComponentPropsWithRef<"div">, "onClick"> {
|
|
4
4
|
status: StepStatus;
|
|
5
5
|
label: string;
|
|
6
6
|
caption?: string;
|
|
@@ -8,6 +8,8 @@ export interface Props extends ComponentPropsWithRef<"button"> {
|
|
|
8
8
|
lastStep?: boolean;
|
|
9
9
|
disabled?: boolean;
|
|
10
10
|
direction?: "horizontal" | "vertical";
|
|
11
|
+
textPosition?: "bottom" | "right";
|
|
12
|
+
onClick?: (event: React.MouseEvent<HTMLButtonElement | HTMLDivElement>) => void;
|
|
11
13
|
}
|
|
12
|
-
export declare const StepComponent: ForwardRefRenderFunction<
|
|
13
|
-
export declare const Step: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<
|
|
14
|
+
export declare const StepComponent: ForwardRefRenderFunction<HTMLDivElement, Props>;
|
|
15
|
+
export declare const Step: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -3,5 +3,7 @@ import { Props as StepProps } from "./Step";
|
|
|
3
3
|
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
4
4
|
steps: StepProps[];
|
|
5
5
|
direction: "horizontal" | "vertical";
|
|
6
|
+
textPosition?: "bottom" | "right";
|
|
6
7
|
}
|
|
7
|
-
export declare const
|
|
8
|
+
export declare const gapBetweenStepsInRem = 0.5;
|
|
9
|
+
export declare const Stepper: ({ steps, direction, textPosition, className, ...rest }: Props) => React.JSX.Element;
|
|
@@ -8,5 +8,8 @@ export interface Props {
|
|
|
8
8
|
initialState: WizardStateType;
|
|
9
9
|
children?: React.ReactNode;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated
|
|
13
|
+
*/
|
|
11
14
|
declare const WizardStateProvider: ({ children, initialState }: Props) => React.JSX.Element;
|
|
12
15
|
export { WizardStateProvider, WizardStateContext };
|
|
@@ -2,4 +2,7 @@ import React, { ComponentPropsWithRef } from "react";
|
|
|
2
2
|
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
3
3
|
onStepClick: (currentStepNo: number, selectedStepNo: number) => boolean;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated
|
|
7
|
+
*/
|
|
5
8
|
export declare const WizardSteps: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
package/dist/esm/src/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export { StatusIndicator } from "./components/StatusIndicator/StatusIndicator";
|
|
|
37
37
|
export type { Props as StatusIndicatorProps } from "./components/StatusIndicator/StatusIndicator";
|
|
38
38
|
export { Stepper } from "./components/Stepper/Stepper";
|
|
39
39
|
export type { Props as StepperProps } from "./components/Stepper/Stepper";
|
|
40
|
+
export type { Props as StepProps } from "./components/Stepper/Step";
|
|
40
41
|
export { Pagination } from "./components/Pagination/Pagination";
|
|
41
42
|
export type { Props as PaginationProps, PageChangeLabels, PaginationTranslations, PageSize } from "./components/Pagination/Pagination";
|
|
42
43
|
export { useRepeater } from "./hooks/useRepeater";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"homepage": "http://onewelcome.github.io/react-lib-components",
|
|
3
3
|
"name": "@onewelcome/react-lib-components",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.2.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "OneWelcome B.V.",
|
|
7
7
|
"main": "dist/cjs/src/index.cjs.js",
|
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
"npm-run-all": "^4.1.5",
|
|
110
110
|
"postcss": "^8.4.31",
|
|
111
111
|
"postcss-modules": "^6.0.0",
|
|
112
|
+
"postcss-url": "^10.1.3",
|
|
112
113
|
"prettier": "^3.0.3",
|
|
113
114
|
"react": "^18.2.0",
|
|
114
115
|
"react-dom": "^18.2.0",
|
|
@@ -76,7 +76,11 @@ const DataGridColumnsToggleComponent: ForwardRefRenderFunction<HTMLDivElement, P
|
|
|
76
76
|
>
|
|
77
77
|
{open &&
|
|
78
78
|
createPortal(
|
|
79
|
-
<div
|
|
79
|
+
<div
|
|
80
|
+
aria-hidden="true"
|
|
81
|
+
className={classes["backdrop"]}
|
|
82
|
+
onClick={handleBackdropClick}
|
|
83
|
+
></div>,
|
|
80
84
|
domRoot
|
|
81
85
|
)}
|
|
82
86
|
{open && (
|
|
@@ -61,7 +61,9 @@ const RadioComponent: ForwardRefRenderFunction<HTMLInputElement, Props> = (
|
|
|
61
61
|
parentHelperId
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
const onChangeHandler = (
|
|
64
|
+
const onChangeHandler = (
|
|
65
|
+
event: React.ChangeEvent<HTMLInputElement> | React.MouseEvent | React.KeyboardEvent
|
|
66
|
+
) => {
|
|
65
67
|
if (disabled) {
|
|
66
68
|
return;
|
|
67
69
|
}
|
|
@@ -83,7 +83,7 @@ const OptionComponent: ForwardRefRenderFunction<HTMLLIElement, Props> = (
|
|
|
83
83
|
disabled ? classes.disabled : ""
|
|
84
84
|
} ${className ?? ""}`}
|
|
85
85
|
onClick={onSelectHandler}
|
|
86
|
-
|
|
86
|
+
onKeyDown={event => {
|
|
87
87
|
if (event.code === "Enter") {
|
|
88
88
|
event.stopPropagation();
|
|
89
89
|
event.preventDefault();
|
|
@@ -18,6 +18,7 @@ import React, { useEffect, useRef } from "react";
|
|
|
18
18
|
import { BaseModal, Props } from "./BaseModal";
|
|
19
19
|
import { render, getByText, queryByText, fireEvent } from "@testing-library/react";
|
|
20
20
|
import userEvent from "@testing-library/user-event";
|
|
21
|
+
import { act } from "react-dom/test-utils";
|
|
21
22
|
|
|
22
23
|
const classNames = ["class11", "class12"];
|
|
23
24
|
const containerClassNames = ["class21", "class22"];
|
|
@@ -36,7 +37,17 @@ const createBaseModal = (params?: (defaultParams: Props) => Props) => {
|
|
|
36
37
|
if (params) {
|
|
37
38
|
parameters = params(defaultParams);
|
|
38
39
|
}
|
|
39
|
-
const queries = render(
|
|
40
|
+
const queries = render(
|
|
41
|
+
<BaseModal {...parameters} data-testid="BaseModal">
|
|
42
|
+
<button>Button 1</button>
|
|
43
|
+
<button>Button 2</button>
|
|
44
|
+
<button>Button 3</button>
|
|
45
|
+
<span>{defaultParams.children}</span>
|
|
46
|
+
<button>Button 4</button>
|
|
47
|
+
<button>Button 5</button>
|
|
48
|
+
<button>Button 6</button>
|
|
49
|
+
</BaseModal>
|
|
50
|
+
);
|
|
40
51
|
const slideInModal = queries.getByTestId("BaseModal");
|
|
41
52
|
|
|
42
53
|
return {
|
|
@@ -130,6 +141,30 @@ describe("BaseModal", () => {
|
|
|
130
141
|
fireEvent.keyDown(modal, { key: "Escape" });
|
|
131
142
|
expect(defaultParams.onClose).toHaveBeenCalledTimes(2);
|
|
132
143
|
});
|
|
144
|
+
|
|
145
|
+
it("should repeat focus back to the first button when tabbing through the modal", async () => {
|
|
146
|
+
const { getByText } = createBaseModal();
|
|
147
|
+
|
|
148
|
+
const firstButton = getByText("Button 1");
|
|
149
|
+
const lastButton = getByText("Button 6");
|
|
150
|
+
|
|
151
|
+
await act(() => {
|
|
152
|
+
firstButton.focus();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
await userEvent.tab();
|
|
156
|
+
await userEvent.tab();
|
|
157
|
+
await userEvent.tab();
|
|
158
|
+
await userEvent.tab();
|
|
159
|
+
await userEvent.tab();
|
|
160
|
+
await userEvent.tab();
|
|
161
|
+
|
|
162
|
+
expect(firstButton).toHaveFocus();
|
|
163
|
+
|
|
164
|
+
await userEvent.tab({ shift: true });
|
|
165
|
+
|
|
166
|
+
expect(lastButton).toHaveFocus();
|
|
167
|
+
});
|
|
133
168
|
});
|
|
134
169
|
|
|
135
170
|
describe("ref should work", () => {
|
|
@@ -19,12 +19,15 @@ import React, {
|
|
|
19
19
|
ComponentPropsWithRef,
|
|
20
20
|
useEffect,
|
|
21
21
|
useRef,
|
|
22
|
-
ReactElement
|
|
22
|
+
ReactElement,
|
|
23
|
+
RefObject,
|
|
24
|
+
createRef
|
|
23
25
|
} from "react";
|
|
24
26
|
import { createPortal } from "react-dom";
|
|
25
27
|
import { useGetDomRoot } from "../../../hooks/useGetDomRoot";
|
|
26
28
|
import classes from "./BaseModal.module.scss";
|
|
27
29
|
import { labelId, descriptionId } from "./BaseModalContext";
|
|
30
|
+
import { useRepeatFocus } from "./useRepeatFocus";
|
|
28
31
|
|
|
29
32
|
const SCROLL_PROPERTY_NAME = "overflow";
|
|
30
33
|
const SCROLL_PROPERTY_VALUE = "hidden";
|
|
@@ -90,6 +93,7 @@ const BaseModalComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
|
|
|
90
93
|
) => {
|
|
91
94
|
useSetBodyScroll(open);
|
|
92
95
|
const wrappingDivRef = useRef<HTMLDivElement>(null);
|
|
96
|
+
const modalRef = (ref as RefObject<HTMLDivElement>) || createRef<HTMLDivElement>();
|
|
93
97
|
const { root } = useGetDomRoot(domRoot, wrappingDivRef);
|
|
94
98
|
|
|
95
99
|
const handleEscKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
@@ -99,9 +103,11 @@ const BaseModalComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
|
|
|
99
103
|
}
|
|
100
104
|
};
|
|
101
105
|
|
|
106
|
+
useRepeatFocus(modalRef);
|
|
107
|
+
|
|
102
108
|
useEffect(() => {
|
|
103
109
|
if (open) {
|
|
104
|
-
|
|
110
|
+
modalRef.current?.focus();
|
|
105
111
|
}
|
|
106
112
|
}, [open]);
|
|
107
113
|
|
|
@@ -122,7 +128,7 @@ const BaseModalComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
|
|
|
122
128
|
{createPortal(
|
|
123
129
|
<div
|
|
124
130
|
{...rest}
|
|
125
|
-
ref={
|
|
131
|
+
ref={modalRef}
|
|
126
132
|
id={id}
|
|
127
133
|
className={`${classes["modal"]} ${open ? classes["visible"] : ""} ${className}`}
|
|
128
134
|
role="dialog"
|
|
@@ -137,6 +143,7 @@ const BaseModalComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
|
|
|
137
143
|
>
|
|
138
144
|
<div
|
|
139
145
|
{...backdropProps}
|
|
146
|
+
aria-hidden={true}
|
|
140
147
|
className={`${classes["backdrop"]} ${backdropProps?.className ?? ""}`}
|
|
141
148
|
onClick={handleBackdropClick}
|
|
142
149
|
></div>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 OneWelcome B.V.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { RefObject, useEffect } from "react";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @description This is a hook that will make sure that when a modal is open and the user tabs through the it,
|
|
21
|
+
* the focus will be repeated and the user will not lose their entire focusable element to an element in the background
|
|
22
|
+
* that is being blocked by the modal.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export const useRepeatFocus = (ref: RefObject<HTMLDivElement>) => {
|
|
26
|
+
const getFocusableElement = (
|
|
27
|
+
element: HTMLElement,
|
|
28
|
+
position: "first" | "last"
|
|
29
|
+
): HTMLElement | null => {
|
|
30
|
+
const focusableSelectors =
|
|
31
|
+
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
|
|
32
|
+
const focusableElements = element.querySelectorAll<HTMLElement>(focusableSelectors);
|
|
33
|
+
|
|
34
|
+
if (position === "first") {
|
|
35
|
+
return focusableElements[0] || null;
|
|
36
|
+
} else if (position === "last") {
|
|
37
|
+
return focusableElements[focusableElements.length - 1] || null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!ref.current || !open) return;
|
|
45
|
+
|
|
46
|
+
const lastFocusableElement = getFocusableElement(ref.current, "last");
|
|
47
|
+
const firstFocusableElement = getFocusableElement(ref.current, "first");
|
|
48
|
+
|
|
49
|
+
if (!lastFocusableElement || !firstFocusableElement) return;
|
|
50
|
+
|
|
51
|
+
const handleTabKeyPress = (event: KeyboardEvent) => {
|
|
52
|
+
if (event.key !== "Tab") return;
|
|
53
|
+
|
|
54
|
+
if (event.shiftKey) {
|
|
55
|
+
if (document.activeElement === firstFocusableElement) {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
lastFocusableElement?.focus();
|
|
58
|
+
}
|
|
59
|
+
} else if (document.activeElement === lastFocusableElement) {
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
firstFocusableElement?.focus();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
lastFocusableElement.addEventListener("keydown", handleTabKeyPress);
|
|
66
|
+
firstFocusableElement.addEventListener("keydown", handleTabKeyPress);
|
|
67
|
+
|
|
68
|
+
return () => {
|
|
69
|
+
lastFocusableElement.removeEventListener("keydown", handleTabKeyPress);
|
|
70
|
+
firstFocusableElement.removeEventListener("keydown", handleTabKeyPress);
|
|
71
|
+
};
|
|
72
|
+
}, [ref, open]);
|
|
73
|
+
};
|