@sqrzro/admin 1.0.0-beta.1
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/.eslintrc +4 -0
- package/.gitattributes +1 -0
- package/.prettierrc +9 -0
- package/.storybook/main.js +40 -0
- package/.storybook/manager.js +4 -0
- package/.storybook/postcss.config.js +3 -0
- package/.storybook/preview.js +11 -0
- package/.storybook/theme.js +7 -0
- package/.stylelintrc +9 -0
- package/LICENSE +5 -0
- package/README.md +9 -0
- package/__mocks__/squarezero-utility.ts +40 -0
- package/assets/logo-horizontal-dark.svg +21 -0
- package/assets/logo-horizontal-white.svg +21 -0
- package/assets/logo-vertical-dark.svg +21 -0
- package/assets/logo-vertical-white.svg +21 -0
- package/dist/index.css +3554 -0
- package/dist/index.js +5099 -0
- package/dist/index.js.map +1 -0
- package/dist/types/components/Alert/index.d.ts +10 -0
- package/dist/types/components/Allow/index.d.ts +13 -0
- package/dist/types/components/App/index.d.ts +19 -0
- package/dist/types/components/AutoSuggest/index.d.ts +60 -0
- package/dist/types/components/Button/index.d.ts +36 -0
- package/dist/types/components/CalendarInput/index.d.ts +10 -0
- package/dist/types/components/CheckboxList/index.d.ts +4 -0
- package/dist/types/components/ConnectedDropdown/index.d.ts +8 -0
- package/dist/types/components/ConnectedList/index.d.ts +4 -0
- package/dist/types/components/ConnectedScene/index.d.ts +11 -0
- package/dist/types/components/ConnectedTable/index.d.ts +4 -0
- package/dist/types/components/ContentBlock/index.d.ts +6 -0
- package/dist/types/components/DateInput/index.d.ts +7 -0
- package/dist/types/components/Document/index.d.ts +6 -0
- package/dist/types/components/Dropdown/index.d.ts +14 -0
- package/dist/types/components/Fieldset/index.d.ts +11 -0
- package/dist/types/components/FileInput/index.d.ts +4 -0
- package/dist/types/components/FilterLink/index.d.ts +7 -0
- package/dist/types/components/Form/index.d.ts +11 -0
- package/dist/types/components/FormActions/index.d.ts +9 -0
- package/dist/types/components/FormField/index.d.ts +27 -0
- package/dist/types/components/FormRepeater/index.d.ts +8 -0
- package/dist/types/components/ImageInput/index.d.ts +4 -0
- package/dist/types/components/InfoPanel/index.d.ts +8 -0
- package/dist/types/components/Link/__mocks__/index.d.ts +6 -0
- package/dist/types/components/Link/index.d.ts +13 -0
- package/dist/types/components/List/index.d.ts +23 -0
- package/dist/types/components/ListActions/index.d.ts +9 -0
- package/dist/types/components/LoginForm/index.d.ts +3 -0
- package/dist/types/components/Message/index.d.ts +7 -0
- package/dist/types/components/ModalActions/index.d.ts +11 -0
- package/dist/types/components/MoneyInput/index.d.ts +10 -0
- package/dist/types/components/PasswordForm/index.d.ts +3 -0
- package/dist/types/components/PasswordInput/index.d.ts +8 -0
- package/dist/types/components/RadioList/index.d.ts +4 -0
- package/dist/types/components/Scene/index.d.ts +10 -0
- package/dist/types/components/SummaryList/index.d.ts +8 -0
- package/dist/types/components/Switch/index.d.ts +9 -0
- package/dist/types/components/Table/index.d.ts +13 -0
- package/dist/types/components/Tag/index.d.ts +8 -0
- package/dist/types/components/TextArea/index.d.ts +4 -0
- package/dist/types/components/TextInput/index.d.ts +17 -0
- package/dist/types/components/WebsiteInput/index.d.ts +10 -0
- package/dist/types/components/WeekCalendar/index.d.ts +12 -0
- package/dist/types/core/AppHeader/index.d.ts +3 -0
- package/dist/types/core/AppLogo/index.d.ts +6 -0
- package/dist/types/core/AppLogoImage/index.d.ts +3 -0
- package/dist/types/core/AppLogoPlaceholder/index.d.ts +3 -0
- package/dist/types/core/Assistive/index.d.ts +6 -0
- package/dist/types/core/Banner/index.d.ts +3 -0
- package/dist/types/core/BuildModal/index.d.ts +3 -0
- package/dist/types/core/Calendar/index.d.ts +11 -0
- package/dist/types/core/CalendarDay/index.d.ts +16 -0
- package/dist/types/core/CalendarMonth/index.d.ts +12 -0
- package/dist/types/core/CalendarNavigation/index.d.ts +9 -0
- package/dist/types/core/CalendarWeek/index.d.ts +14 -0
- package/dist/types/core/ChkRad/index.d.ts +10 -0
- package/dist/types/core/ChkRadIcon/index.d.ts +7 -0
- package/dist/types/core/ChkRadList/index.d.ts +15 -0
- package/dist/types/core/CloseButton/index.d.ts +9 -0
- package/dist/types/core/ConfirmModal/index.d.ts +3 -0
- package/dist/types/core/ConnectedRepeater/index.d.ts +26 -0
- package/dist/types/core/ConnectedRepeaterComponent/index.d.ts +24 -0
- package/dist/types/core/Container/index.d.ts +7 -0
- package/dist/types/core/DropdownPanel/index.d.ts +18 -0
- package/dist/types/core/EmptyMessage/index.d.ts +12 -0
- package/dist/types/core/ErrorBoundary/index.d.ts +15 -0
- package/dist/types/core/ErrorMessage/index.d.ts +8 -0
- package/dist/types/core/FilterItem/index.d.ts +10 -0
- package/dist/types/core/Filters/index.d.ts +11 -0
- package/dist/types/core/FixedActions/index.d.ts +12 -0
- package/dist/types/core/FormError/index.d.ts +6 -0
- package/dist/types/core/FormLabel/index.d.ts +8 -0
- package/dist/types/core/FormLegend/index.d.ts +6 -0
- package/dist/types/core/Header/index.d.ts +8 -0
- package/dist/types/core/Icon/index.d.ts +7 -0
- package/dist/types/core/IconButton/Icon/index.d.ts +7 -0
- package/dist/types/core/IconButton/index.d.ts +11 -0
- package/dist/types/core/InputPanel/index.d.ts +8 -0
- package/dist/types/core/ListItem/index.d.ts +16 -0
- package/dist/types/core/ListItemAction/index.d.ts +4 -0
- package/dist/types/core/ListItemActions/index.d.ts +8 -0
- package/dist/types/core/ListItemMetaItem/index.d.ts +10 -0
- package/dist/types/core/ListItemTitle/index.d.ts +9 -0
- package/dist/types/core/Loader/index.d.ts +6 -0
- package/dist/types/core/MeActions/index.d.ts +3 -0
- package/dist/types/core/MePanel/index.d.ts +9 -0
- package/dist/types/core/Modal/index.d.ts +12 -0
- package/dist/types/core/Navigation/index.d.ts +3 -0
- package/dist/types/core/NavigationDivider/index.d.ts +3 -0
- package/dist/types/core/NavigationItem/index.d.ts +7 -0
- package/dist/types/core/Pagination/index.d.ts +7 -0
- package/dist/types/core/PaginationItem/index.d.ts +7 -0
- package/dist/types/core/Panel/index.d.ts +8 -0
- package/dist/types/core/RadialProgress/index.d.ts +8 -0
- package/dist/types/core/StaticTextInput/index.d.ts +12 -0
- package/dist/types/core/Styled/index.d.ts +6 -0
- package/dist/types/core/SummaryListItem/index.d.ts +15 -0
- package/dist/types/core/TableActionsCell/index.d.ts +8 -0
- package/dist/types/core/TableCell/index.d.ts +8 -0
- package/dist/types/core/TableHead/index.d.ts +8 -0
- package/dist/types/core/TableRow/index.d.ts +13 -0
- package/dist/types/core/Tabs/index.d.ts +11 -0
- package/dist/types/core/TextInputAncillary/index.d.ts +11 -0
- package/dist/types/core/Toast/index.d.ts +3 -0
- package/dist/types/core/WeekCalendarDay/index.d.ts +14 -0
- package/dist/types/filters/BooleanFilter/index.d.ts +5 -0
- package/dist/types/filters/DateFilter/index.d.ts +5 -0
- package/dist/types/filters/DropdownFilter/index.d.ts +5 -0
- package/dist/types/filters/QuickDateFilter/index.d.ts +5 -0
- package/dist/types/filters/interfaces.d.ts +36 -0
- package/dist/types/hooks/useAccessiblePanel.d.ts +13 -0
- package/dist/types/hooks/useAppContext.d.ts +37 -0
- package/dist/types/hooks/useClickOutside.d.ts +3 -0
- package/dist/types/hooks/useConnectedList.d.ts +7 -0
- package/dist/types/hooks/useFilters.d.ts +3 -0
- package/dist/types/hooks/useForm.d.ts +26 -0
- package/dist/types/hooks/useFormData.d.ts +9 -0
- package/dist/types/hooks/useLayout.d.ts +6 -0
- package/dist/types/hooks/useModal.d.ts +12 -0
- package/dist/types/hooks/useVariant.d.ts +6 -0
- package/dist/types/index.d.ts +187 -0
- package/dist/types/scenes/Error404Scene.d.ts +3 -0
- package/dist/types/services/BuildService.d.ts +5 -0
- package/dist/types/services/ConfirmService.d.ts +12 -0
- package/dist/types/services/DateService.d.ts +17 -0
- package/dist/types/services/DownloadService.d.ts +5 -0
- package/dist/types/services/FilterComponentService.d.ts +8 -0
- package/dist/types/services/FilterService.d.ts +13 -0
- package/dist/types/services/FormatService.d.ts +7 -0
- package/dist/types/services/ToastService.d.ts +5 -0
- package/dist/types/utility/MockRouter/index.d.ts +2 -0
- package/dist/types/utility/StorybookPanel/index.d.ts +7 -0
- package/dist/types/utility/TestChangeHandler/index.d.ts +8 -0
- package/dist/types/utility/create-app.d.ts +4 -0
- package/dist/types/utility/interfaces.d.ts +72 -0
- package/dist/types/utility/prop-types.d.ts +40 -0
- package/docs/guides/01-installation.story.mdx +33 -0
- package/docs/guides/02-configuration.story.mdx +80 -0
- package/docs/guides/03-pages.story.mdx +18 -0
- package/docs/guides/04-integration.story.mdx +33 -0
- package/docs/guides/a11y.story.mdx +7 -0
- package/docs/guides/theming.story.mdx +7 -0
- package/docs/introduction.story.mdx +17 -0
- package/jest.config.js +19 -0
- package/package.json +101 -0
- package/postcss.config.js +3 -0
- package/rollup.config.js +36 -0
- package/scripts/create-exports.js +74 -0
- package/scripts/update-license.js +8 -0
- package/squarezero.config.js +5 -0
- package/src/components/Alert/Alert.module.css +50 -0
- package/src/components/Alert/Alert.spec.tsx +63 -0
- package/src/components/Alert/Alert.story.tsx +23 -0
- package/src/components/Alert/index.tsx +67 -0
- package/src/components/Allow/Allow.spec.tsx +37 -0
- package/src/components/Allow/index.tsx +42 -0
- package/src/components/App/App.module.css +22 -0
- package/src/components/App/App.spec.tsx +128 -0
- package/src/components/App/index.tsx +108 -0
- package/src/components/AutoSuggest/AutoSuggest.module.css +8 -0
- package/src/components/AutoSuggest/AutoSuggest.spec.tsx +211 -0
- package/src/components/AutoSuggest/AutoSuggest.story.tsx +30 -0
- package/src/components/AutoSuggest/index.tsx +216 -0
- package/src/components/Button/Button.module.css +95 -0
- package/src/components/Button/Button.spec.tsx +69 -0
- package/src/components/Button/Button.story.tsx +39 -0
- package/src/components/Button/index.tsx +99 -0
- package/src/components/CalendarInput/CalendarInput.module.css +8 -0
- package/src/components/CalendarInput/CalendarInput.spec.tsx +206 -0
- package/src/components/CalendarInput/CalendarInput.story.tsx +62 -0
- package/src/components/CalendarInput/index.tsx +122 -0
- package/src/components/CheckboxList/CheckboxList.spec.tsx +83 -0
- package/src/components/CheckboxList/index.tsx +53 -0
- package/src/components/ConnectedDropdown/index.tsx +56 -0
- package/src/components/ConnectedList/index.tsx +15 -0
- package/src/components/ConnectedScene/index.tsx +95 -0
- package/src/components/ConnectedTable/index.tsx +17 -0
- package/src/components/ContentBlock/ContentBlock.module.css +8 -0
- package/src/components/ContentBlock/ContentBlock.spec.tsx +15 -0
- package/src/components/ContentBlock/index.tsx +16 -0
- package/src/components/DateInput/DateInput.module.css +15 -0
- package/src/components/DateInput/DateInput.spec.tsx +91 -0
- package/src/components/DateInput/index.tsx +149 -0
- package/src/components/Document/index.tsx +20 -0
- package/src/components/Dropdown/Dropdown.module.css +8 -0
- package/src/components/Dropdown/Dropdown.spec.tsx +286 -0
- package/src/components/Dropdown/Dropdown.story.tsx +53 -0
- package/src/components/Dropdown/index.tsx +224 -0
- package/src/components/Fieldset/Fieldset.spec.tsx +22 -0
- package/src/components/Fieldset/Fieldset.story.tsx +21 -0
- package/src/components/Fieldset/index.tsx +30 -0
- package/src/components/FileInput/FileInput.module.css +18 -0
- package/src/components/FileInput/FileInput.spec.tsx +42 -0
- package/src/components/FileInput/FileInput.story.tsx +6 -0
- package/src/components/FileInput/index.tsx +72 -0
- package/src/components/FilterLink/FilterLink.module.css +9 -0
- package/src/components/FilterLink/FilterLink.spec.tsx +20 -0
- package/src/components/FilterLink/index.tsx +31 -0
- package/src/components/Form/Form.spec.tsx +68 -0
- package/src/components/Form/index.tsx +87 -0
- package/src/components/FormActions/FormActions.spec.tsx +10 -0
- package/src/components/FormActions/FormActions.story.tsx +23 -0
- package/src/components/FormActions/index.tsx +31 -0
- package/src/components/FormField/FormField.module.css +71 -0
- package/src/components/FormField/FormField.spec.tsx +137 -0
- package/src/components/FormField/FormField.story.tsx +22 -0
- package/src/components/FormField/index.tsx +162 -0
- package/src/components/FormRepeater/FormRepeater.module.css +3 -0
- package/src/components/FormRepeater/FormRepeater.spec.tsx +127 -0
- package/src/components/FormRepeater/index.tsx +118 -0
- package/src/components/ImageInput/ImageInput.module.css +74 -0
- package/src/components/ImageInput/ImageInput.spec.tsx +45 -0
- package/src/components/ImageInput/ImageInput.story.tsx +6 -0
- package/src/components/ImageInput/index.tsx +91 -0
- package/src/components/InfoPanel/InfoPanel.module.css +18 -0
- package/src/components/InfoPanel/InfoPanel.spec.tsx +15 -0
- package/src/components/InfoPanel/InfoPanel.story.tsx +32 -0
- package/src/components/InfoPanel/index.tsx +25 -0
- package/src/components/Link/Link.spec.tsx +62 -0
- package/src/components/Link/__mocks__/index.tsx +24 -0
- package/src/components/Link/index.tsx +51 -0
- package/src/components/List/List.module.css +9 -0
- package/src/components/List/List.spec.tsx +311 -0
- package/src/components/List/List.story.tsx +92 -0
- package/src/components/List/index.tsx +79 -0
- package/src/components/ListActions/ListActions.spec.tsx +10 -0
- package/src/components/ListActions/ListActions.story.tsx +6 -0
- package/src/components/ListActions/index.tsx +31 -0
- package/src/components/LoginForm/LoginForm.module.css +21 -0
- package/src/components/LoginForm/LoginForm.spec.tsx +63 -0
- package/src/components/LoginForm/index.tsx +102 -0
- package/src/components/Message/Message.module.css +14 -0
- package/src/components/Message/Message.spec.tsx +20 -0
- package/src/components/Message/index.tsx +27 -0
- package/src/components/ModalActions/ModalActions.module.css +5 -0
- package/src/components/ModalActions/ModalActions.spec.tsx +53 -0
- package/src/components/ModalActions/ModalActions.story.tsx +6 -0
- package/src/components/ModalActions/index.tsx +47 -0
- package/src/components/MoneyInput/MoneyInput.spec.tsx +17 -0
- package/src/components/MoneyInput/MoneyInput.story.tsx +6 -0
- package/src/components/MoneyInput/index.tsx +16 -0
- package/src/components/PasswordForm/PasswordForm.module.css +21 -0
- package/src/components/PasswordForm/index.tsx +94 -0
- package/src/components/PasswordInput/PasswordInput.module.css +23 -0
- package/src/components/PasswordInput/PasswordInput.spec.tsx +31 -0
- package/src/components/PasswordInput/PasswordInput.story.tsx +16 -0
- package/src/components/PasswordInput/index.tsx +27 -0
- package/src/components/RadioList/RadioList.spec.tsx +45 -0
- package/src/components/RadioList/index.tsx +10 -0
- package/src/components/Scene/Scene.spec.tsx +123 -0
- package/src/components/Scene/Scene.story.tsx +6 -0
- package/src/components/Scene/index.tsx +58 -0
- package/src/components/SummaryList/SummaryList.module.css +16 -0
- package/src/components/SummaryList/SummaryList.spec.tsx +77 -0
- package/src/components/SummaryList/SummaryList.story.tsx +11 -0
- package/src/components/SummaryList/index.tsx +37 -0
- package/src/components/Switch/Switch.module.css +86 -0
- package/src/components/Switch/Switch.spec.tsx +64 -0
- package/src/components/Switch/index.tsx +85 -0
- package/src/components/Table/Table.module.css +14 -0
- package/src/components/Table/Table.spec.tsx +128 -0
- package/src/components/Table/Table.story.tsx +101 -0
- package/src/components/Table/index.tsx +114 -0
- package/src/components/Tag/Tag.module.css +37 -0
- package/src/components/Tag/Tag.spec.tsx +10 -0
- package/src/components/Tag/Tag.story.tsx +55 -0
- package/src/components/Tag/index.tsx +27 -0
- package/src/components/TextArea/TextArea.module.css +23 -0
- package/src/components/TextArea/TextArea.spec.tsx +77 -0
- package/src/components/TextArea/index.tsx +59 -0
- package/src/components/TextInput/TextInput.module.css +57 -0
- package/src/components/TextInput/TextInput.spec.tsx +134 -0
- package/src/components/TextInput/TextInput.story.tsx +24 -0
- package/src/components/TextInput/index.tsx +146 -0
- package/src/components/WebsiteInput/WebsiteInput.spec.tsx +17 -0
- package/src/components/WebsiteInput/index.tsx +16 -0
- package/src/components/WeekCalendar/WeekCalendar.module.css +19 -0
- package/src/components/WeekCalendar/index.tsx +80 -0
- package/src/core/AppHeader/index.tsx +23 -0
- package/src/core/AppLogo/AppLogo.module.css +19 -0
- package/src/core/AppLogo/index.tsx +33 -0
- package/src/core/AppLogoImage/index.tsx +19 -0
- package/src/core/AppLogoPlaceholder/index.tsx +26 -0
- package/src/core/Assistive/Assistive.module.css +10 -0
- package/src/core/Assistive/index.tsx +18 -0
- package/src/core/Banner/Banner.module.css +36 -0
- package/src/core/Banner/index.tsx +25 -0
- package/src/core/BuildModal/index.tsx +119 -0
- package/src/core/Calendar/index.tsx +116 -0
- package/src/core/CalendarDay/CalendarDay.module.css +61 -0
- package/src/core/CalendarDay/index.tsx +82 -0
- package/src/core/CalendarMonth/CalendarMonth.module.css +13 -0
- package/src/core/CalendarMonth/index.tsx +101 -0
- package/src/core/CalendarNavigation/CalendarNavigation.module.css +26 -0
- package/src/core/CalendarNavigation/index.tsx +56 -0
- package/src/core/CalendarWeek/index.tsx +95 -0
- package/src/core/ChkRad/ChkRad.module.css +31 -0
- package/src/core/ChkRad/ChkRad.spec.tsx +72 -0
- package/src/core/ChkRad/index.tsx +80 -0
- package/src/core/ChkRadIcon/ChkRadIcon.module.css +28 -0
- package/src/core/ChkRadIcon/index.tsx +33 -0
- package/src/core/ChkRadList/ChkRadList.module.css +10 -0
- package/src/core/ChkRadList/index.tsx +85 -0
- package/src/core/CloseButton/CloseButton.spec.tsx +36 -0
- package/src/core/CloseButton/index.tsx +31 -0
- package/src/core/ConfirmModal/ConfirmModal.spec.tsx +88 -0
- package/src/core/ConfirmModal/index.tsx +51 -0
- package/src/core/ConnectedRepeater/index.tsx +248 -0
- package/src/core/ConnectedRepeaterComponent/index.tsx +66 -0
- package/src/core/Container/Container.module.css +12 -0
- package/src/core/Container/index.tsx +35 -0
- package/src/core/DropdownPanel/DropdownPanel.module.css +68 -0
- package/src/core/DropdownPanel/index.tsx +92 -0
- package/src/core/EmptyMessage/EmptyMessage.module.css +18 -0
- package/src/core/EmptyMessage/index.tsx +31 -0
- package/src/core/ErrorBoundary/ErrorBoundary.spec.tsx +33 -0
- package/src/core/ErrorBoundary/index.tsx +42 -0
- package/src/core/ErrorMessage/ErrorMessage.module.css +25 -0
- package/src/core/ErrorMessage/ErrorMessage.spec.tsx +31 -0
- package/src/core/ErrorMessage/index.tsx +37 -0
- package/src/core/FilterItem/FilterItem.module.css +104 -0
- package/src/core/FilterItem/index.tsx +164 -0
- package/src/core/Filters/Filters.module.css +86 -0
- package/src/core/Filters/Filters.spec.tsx +533 -0
- package/src/core/Filters/index.tsx +158 -0
- package/src/core/FixedActions/FixedActions.module.css +24 -0
- package/src/core/FixedActions/index.tsx +52 -0
- package/src/core/FormError/FormError.module.css +7 -0
- package/src/core/FormError/index.tsx +18 -0
- package/src/core/FormLabel/FormLabel.module.css +15 -0
- package/src/core/FormLabel/index.tsx +25 -0
- package/src/core/FormLegend/FormLegend.module.css +13 -0
- package/src/core/FormLegend/index.tsx +18 -0
- package/src/core/Header/Header.module.css +35 -0
- package/src/core/Header/index.tsx +37 -0
- package/src/core/Icon/Icon.spec.tsx +31 -0
- package/src/core/Icon/index.tsx +64 -0
- package/src/core/IconButton/Icon/Icon.spec.tsx +31 -0
- package/src/core/IconButton/Icon/index.tsx +64 -0
- package/src/core/IconButton/IconButton.module.css +32 -0
- package/src/core/IconButton/index.tsx +55 -0
- package/src/core/InputPanel/InputPanel.module.css +70 -0
- package/src/core/InputPanel/index.tsx +28 -0
- package/src/core/ListItem/ListItem.module.css +28 -0
- package/src/core/ListItem/ListItem.story.tsx +28 -0
- package/src/core/ListItem/index.tsx +99 -0
- package/src/core/ListItemAction/ListItemAction.module.css +28 -0
- package/src/core/ListItemAction/index.tsx +30 -0
- package/src/core/ListItemActions/ListItemActions.module.css +94 -0
- package/src/core/ListItemActions/index.tsx +55 -0
- package/src/core/ListItemMetaItem/ListItemMetaItem.module.css +18 -0
- package/src/core/ListItemMetaItem/index.tsx +54 -0
- package/src/core/ListItemTitle/ListItemTitle.module.css +14 -0
- package/src/core/ListItemTitle/ListItemTitle.spec.tsx +33 -0
- package/src/core/ListItemTitle/index.tsx +72 -0
- package/src/core/Loader/Loader.module.css +57 -0
- package/src/core/Loader/Loader.story.tsx +8 -0
- package/src/core/Loader/index.tsx +27 -0
- package/src/core/MeActions/MeActions.module.css +45 -0
- package/src/core/MeActions/index.tsx +46 -0
- package/src/core/MePanel/MePanel.module.css +75 -0
- package/src/core/MePanel/index.tsx +45 -0
- package/src/core/Modal/Modal.module.css +84 -0
- package/src/core/Modal/Modal.spec.tsx +51 -0
- package/src/core/Modal/index.tsx +66 -0
- package/src/core/Navigation/Navigation.module.css +83 -0
- package/src/core/Navigation/Navigation.spec.tsx +101 -0
- package/src/core/Navigation/index.tsx +109 -0
- package/src/core/NavigationDivider/NavigationDivider.module.css +18 -0
- package/src/core/NavigationDivider/index.tsx +13 -0
- package/src/core/NavigationItem/NavigationItem.module.css +51 -0
- package/src/core/NavigationItem/index.tsx +59 -0
- package/src/core/Pagination/Pagination.module.css +15 -0
- package/src/core/Pagination/index.tsx +100 -0
- package/src/core/PaginationItem/PaginationItem.module.css +33 -0
- package/src/core/PaginationItem/index.tsx +46 -0
- package/src/core/Panel/Panel.module.css +15 -0
- package/src/core/Panel/index.tsx +31 -0
- package/src/core/RadialProgress/RadialProgress.module.css +78 -0
- package/src/core/RadialProgress/index.tsx +52 -0
- package/src/core/StaticTextInput/StaticTextInput.module.css +79 -0
- package/src/core/StaticTextInput/StaticTextInput.spec.tsx +133 -0
- package/src/core/StaticTextInput/index.tsx +114 -0
- package/src/core/Styled/Styled.spec.tsx +38 -0
- package/src/core/Styled/Styled.story.tsx +10 -0
- package/src/core/Styled/index.tsx +62 -0
- package/src/core/SummaryListItem/SummaryListItem.module.css +28 -0
- package/src/core/SummaryListItem/index.tsx +60 -0
- package/src/core/TableActionsCell/TableActionsCell.module.css +3 -0
- package/src/core/TableActionsCell/index.tsx +37 -0
- package/src/core/TableCell/TableCell.module.css +16 -0
- package/src/core/TableCell/index.tsx +39 -0
- package/src/core/TableHead/TableHead.module.css +12 -0
- package/src/core/TableHead/index.tsx +48 -0
- package/src/core/TableRow/index.tsx +64 -0
- package/src/core/Tabs/Tabs.module.css +50 -0
- package/src/core/Tabs/index.tsx +94 -0
- package/src/core/TextInputAncillary/TextInputAncillary.module.css +64 -0
- package/src/core/TextInputAncillary/index.tsx +72 -0
- package/src/core/Toast/Toast.module.css +55 -0
- package/src/core/Toast/Toast.spec.tsx +78 -0
- package/src/core/Toast/index.tsx +81 -0
- package/src/core/WeekCalendarDay/WeekCalendarDay.module.css +32 -0
- package/src/core/WeekCalendarDay/index.tsx +68 -0
- package/src/filters/BooleanFilter/index.tsx +46 -0
- package/src/filters/DateFilter/index.tsx +36 -0
- package/src/filters/DropdownFilter/index.tsx +53 -0
- package/src/filters/QuickDateFilter/index.tsx +74 -0
- package/src/filters/interfaces.ts +40 -0
- package/src/hooks/useAccessiblePanel.spec.tsx +88 -0
- package/src/hooks/useAccessiblePanel.ts +74 -0
- package/src/hooks/useAppContext.ts +77 -0
- package/src/hooks/useClickOutside.ts +49 -0
- package/src/hooks/useConnectedList.ts +26 -0
- package/src/hooks/useFilters.ts +26 -0
- package/src/hooks/useForm.spec.ts +126 -0
- package/src/hooks/useForm.ts +99 -0
- package/src/hooks/useFormData.spec.ts +40 -0
- package/src/hooks/useFormData.ts +27 -0
- package/src/hooks/useLayout.spec.ts +55 -0
- package/src/hooks/useLayout.ts +29 -0
- package/src/hooks/useModal.spec.tsx +63 -0
- package/src/hooks/useModal.ts +60 -0
- package/src/hooks/useVariant.spec.ts +14 -0
- package/src/hooks/useVariant.ts +34 -0
- package/src/index.ts +194 -0
- package/src/scenes/Error404Scene.tsx +5 -0
- package/src/services/BuildService.spec.ts +56 -0
- package/src/services/BuildService.ts +34 -0
- package/src/services/ConfirmService.ts +21 -0
- package/src/services/DateService.spec.ts +87 -0
- package/src/services/DateService.ts +137 -0
- package/src/services/DownloadService.spec.ts +29 -0
- package/src/services/DownloadService.ts +14 -0
- package/src/services/FilterComponentService.tsx +46 -0
- package/src/services/FilterService.spec.ts +87 -0
- package/src/services/FilterService.ts +58 -0
- package/src/services/FormatService.spec.ts +83 -0
- package/src/services/FormatService.ts +55 -0
- package/src/services/ToastService.spec.ts +44 -0
- package/src/services/ToastService.ts +19 -0
- package/src/styles/layout.css +64 -0
- package/src/styles/variables.css +85 -0
- package/src/typings.d.ts +4 -0
- package/src/utility/MockRouter/index.ts +45 -0
- package/src/utility/StorybookPanel/StorybookPanel.module.css +9 -0
- package/src/utility/StorybookPanel/index.tsx +25 -0
- package/src/utility/TestChangeHandler/TestChangeHandler.module.css +7 -0
- package/src/utility/TestChangeHandler/TestChangeHandler.spec.tsx +24 -0
- package/src/utility/TestChangeHandler/index.tsx +54 -0
- package/src/utility/create-app.tsx +29 -0
- package/src/utility/interfaces.ts +119 -0
- package/src/utility/prop-types.ts +67 -0
- package/tests/setupFilesAfterEnv.js +10 -0
- package/tsconfig.json +26 -0
- package/tsconfig.types.json +9 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import StorybookPanel from '@utility/StorybookPanel';
|
|
4
|
+
|
|
5
|
+
import Button from '@components/Button';
|
|
6
|
+
import FormActions from './index';
|
|
7
|
+
|
|
8
|
+
export default { title: 'Components/FormActions', component: FormActions };
|
|
9
|
+
|
|
10
|
+
export const Basic = (): React.ReactElement => (
|
|
11
|
+
<StorybookPanel>
|
|
12
|
+
<FormActions label="Lorem Ipsum" />
|
|
13
|
+
</StorybookPanel>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const WithChildren = (): React.ReactElement => (
|
|
17
|
+
<StorybookPanel>
|
|
18
|
+
<FormActions label="Lorem Ipsum">
|
|
19
|
+
<Button variant="danger">Dolor</Button>
|
|
20
|
+
<Button variant="bordered">Adiscit Exceptor</Button>
|
|
21
|
+
</FormActions>
|
|
22
|
+
</StorybookPanel>
|
|
23
|
+
);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import FixedActions from '@core/FixedActions';
|
|
5
|
+
|
|
6
|
+
interface FormActionsProps {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
isDisabled?: boolean;
|
|
9
|
+
isLoading?: boolean;
|
|
10
|
+
label: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const FormActions: React.FunctionComponent<FormActionsProps> = ({
|
|
14
|
+
children,
|
|
15
|
+
label,
|
|
16
|
+
isDisabled,
|
|
17
|
+
isLoading,
|
|
18
|
+
}) => (
|
|
19
|
+
<FixedActions isDisabled={isDisabled} isLoading={isLoading} label={label} type="submit">
|
|
20
|
+
{children}
|
|
21
|
+
</FixedActions>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
FormActions.propTypes = {
|
|
25
|
+
label: PropTypes.string.isRequired,
|
|
26
|
+
children: PropTypes.node,
|
|
27
|
+
isDisabled: PropTypes.bool,
|
|
28
|
+
isLoading: PropTypes.bool,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default FormActions;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
clear: both;
|
|
3
|
+
display: grid;
|
|
4
|
+
grid-template-columns: 1fr auto;
|
|
5
|
+
grid-template-rows: repeat(3, auto);
|
|
6
|
+
margin-bottom: 3rem;
|
|
7
|
+
position: relative;
|
|
8
|
+
|
|
9
|
+
&:last-child {
|
|
10
|
+
margin-bottom: .5rem;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@media (--media-lrg) {
|
|
14
|
+
grid-template-columns: min(50rem, 100%) auto;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.rootHasError {
|
|
19
|
+
&::before {
|
|
20
|
+
background-color: var(--clr-error5);
|
|
21
|
+
bottom: -1.5rem;
|
|
22
|
+
content: '';
|
|
23
|
+
left: clamp(-3rem, -3.75vw, -1.5rem);
|
|
24
|
+
position: absolute;
|
|
25
|
+
right: clamp(-3rem, -3.75vw, -1.5rem);
|
|
26
|
+
top: -1.5rem;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.rootIsShallow {
|
|
31
|
+
margin-bottom: 1.5rem;
|
|
32
|
+
|
|
33
|
+
&:last-child {
|
|
34
|
+
margin-bottom: .5rem;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.rootWidthFull {
|
|
39
|
+
grid-template-columns: 1fr auto;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.label {
|
|
43
|
+
margin-bottom: 1rem;
|
|
44
|
+
position: relative;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.field {
|
|
48
|
+
grid-area: 2 / 1 / 3 / 2;
|
|
49
|
+
position: relative;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.action {
|
|
53
|
+
display: flex;
|
|
54
|
+
grid-area: 2 / 2 / 3 / 3;
|
|
55
|
+
margin-left: 1rem;
|
|
56
|
+
position: relative;
|
|
57
|
+
|
|
58
|
+
& > * {
|
|
59
|
+
width: auto;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
& > *:not(:last-child) {
|
|
63
|
+
margin-right: .5rem;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.error {
|
|
68
|
+
grid-area: 3 / 1 / 4 / 2;
|
|
69
|
+
margin-top: 1rem;
|
|
70
|
+
position: relative;
|
|
71
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
|
|
5
|
+
import TestChangeHandler from '@utility/TestChangeHandler';
|
|
6
|
+
|
|
7
|
+
import FormField from './index';
|
|
8
|
+
|
|
9
|
+
describe('FormField', () => {
|
|
10
|
+
it('should render', () => {
|
|
11
|
+
render(<FormField name="lorem" />);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should render defaults', () => {
|
|
15
|
+
render(<FormField name="lorem" />);
|
|
16
|
+
|
|
17
|
+
expect(screen.getByRole('textbox')).toHaveAttribute('name', 'lorem');
|
|
18
|
+
expect(screen.getByTestId('form-field-root')).toHaveClass('root');
|
|
19
|
+
expect(screen.queryByRole('button')).toBeNull();
|
|
20
|
+
expect(screen.queryByText('(Optional)')).toBeNull();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should have action', () => {
|
|
24
|
+
const mockFn = jest.fn();
|
|
25
|
+
render(<FormField action={{ label: 'Lorem', onClick: mockFn }} name="lorem" />);
|
|
26
|
+
|
|
27
|
+
const button = screen.getByRole('button');
|
|
28
|
+
expect(button).toHaveTextContent(/^Lorem$/u);
|
|
29
|
+
expect(button).not.toBeDisabled();
|
|
30
|
+
|
|
31
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
32
|
+
userEvent.click(button);
|
|
33
|
+
expect(mockFn).toHaveBeenCalledTimes(1);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should have variant action', () => {
|
|
37
|
+
const mockFn = jest.fn();
|
|
38
|
+
render(
|
|
39
|
+
<FormField
|
|
40
|
+
action={{ label: 'Lorem', onClick: mockFn, variant: 'danger' }}
|
|
41
|
+
name="lorem"
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(screen.getByRole('button')).toHaveClass('root rootDanger');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should have disabled action', () => {
|
|
49
|
+
const mockFn = jest.fn();
|
|
50
|
+
render(
|
|
51
|
+
<FormField
|
|
52
|
+
action={{ isDisabled: true, label: 'Lorem', onClick: mockFn }}
|
|
53
|
+
name="lorem"
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const button = screen.getByRole('button');
|
|
58
|
+
expect(button).toBeDisabled();
|
|
59
|
+
|
|
60
|
+
userEvent.click(button);
|
|
61
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should have action while disabled', () => {
|
|
65
|
+
const mockFn = jest.fn();
|
|
66
|
+
render(<FormField action={{ label: 'Lorem', onClick: mockFn }} name="lorem" isDisabled />);
|
|
67
|
+
|
|
68
|
+
const button = screen.getByRole('button');
|
|
69
|
+
expect(button).toBeDisabled();
|
|
70
|
+
|
|
71
|
+
userEvent.click(button);
|
|
72
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should have error', () => {
|
|
76
|
+
render(<FormField error="Lorem" name="lorem" />);
|
|
77
|
+
|
|
78
|
+
expect(screen.getByTestId('form-field-root')).toHaveClass('root rootHasError');
|
|
79
|
+
expect(screen.getByText('Lorem')).not.toBeNull();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should have label', () => {
|
|
83
|
+
render(<FormField label="Lorem" name="lorem" />);
|
|
84
|
+
expect(screen.getByText('Lorem')).not.toBeNull();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should have custom id', () => {
|
|
88
|
+
render(<FormField id="ipsum" name="lorem" />);
|
|
89
|
+
expect(screen.getByRole('textbox')).toHaveAttribute('id', 'ipsum');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should render component', () => {
|
|
93
|
+
render(<FormField name="lorem" render={(): React.ReactElement => <div>Lorem</div>} />);
|
|
94
|
+
expect(screen.getByTestId('form-field-root')).toHaveTextContent(/^Lorem$/u);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should have value', () => {
|
|
98
|
+
render(<FormField name="lorem" value="Lorem" />);
|
|
99
|
+
expect(screen.getByRole('textbox')).toHaveValue('Lorem');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should be disabled', () => {
|
|
103
|
+
render(<FormField name="lorem" isDisabled />);
|
|
104
|
+
expect(screen.getByRole('textbox')).toBeDisabled();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should be optional', () => {
|
|
108
|
+
render(<FormField label="Lorem" name="lorem" isOptional />);
|
|
109
|
+
expect(screen.getByText('(Optional)')).not.toBeNull();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should have full width', () => {
|
|
113
|
+
render(<FormField name="lorem" width="full" />);
|
|
114
|
+
expect(screen.getByTestId('form-field-root')).toHaveClass('root rootWidthFull');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should handle onchange', () => {
|
|
118
|
+
render(
|
|
119
|
+
<TestChangeHandler>
|
|
120
|
+
<FormField name="lorem" />
|
|
121
|
+
</TestChangeHandler>
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
userEvent.type(screen.getByRole('textbox'), 'lorem');
|
|
125
|
+
expect(screen.getByRole('textbox')).toHaveValue('lorem');
|
|
126
|
+
expect(screen.getByTestId('test-change-handler-value')).toHaveTextContent('lorem');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should handle onkeydown', () => {
|
|
130
|
+
const mockFn = jest.fn();
|
|
131
|
+
render(<FormField name="lorem" onKeyDown={mockFn} />);
|
|
132
|
+
|
|
133
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
134
|
+
userEvent.type(screen.getByRole('textbox'), 'a');
|
|
135
|
+
expect(mockFn).toHaveBeenCalledTimes(1);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormField from './index';
|
|
3
|
+
|
|
4
|
+
export default { title: 'Components/FormField', component: FormField };
|
|
5
|
+
|
|
6
|
+
export const Default = (): React.ReactElement => <FormField label="Lorem Ipsum" name="lorem" />;
|
|
7
|
+
|
|
8
|
+
export const WithoutLabel = (): React.ReactElement => <FormField name="lorem" />;
|
|
9
|
+
|
|
10
|
+
export const WithError = (): React.ReactElement => <FormField error="Lorem Ipsum" name="lorem" />;
|
|
11
|
+
|
|
12
|
+
export const Optional = (): React.ReactElement => (
|
|
13
|
+
<FormField label="Lorem Ipsum" name="lorem" isOptional />
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const CustomRender = (): React.ReactElement => (
|
|
17
|
+
<FormField
|
|
18
|
+
label="Lorem Ipsum"
|
|
19
|
+
name="lorem"
|
|
20
|
+
render={(props): JSX.Element => <span>{JSON.stringify(props)}</span>}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
import { ucwords } from '@sqrzro/utility';
|
|
6
|
+
|
|
7
|
+
import FormError from '@core/FormError';
|
|
8
|
+
import FormLabel from '@core/FormLabel';
|
|
9
|
+
|
|
10
|
+
import Button from '@components/Button';
|
|
11
|
+
import TextInput from '@components/TextInput';
|
|
12
|
+
|
|
13
|
+
import type { InputProps, SimpleAction } from '@utility/interfaces';
|
|
14
|
+
|
|
15
|
+
import styles from './FormField.module.css';
|
|
16
|
+
|
|
17
|
+
export interface FormFieldComponentProps extends InputProps {
|
|
18
|
+
action?: SimpleAction | null;
|
|
19
|
+
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface FormFieldProps extends FormFieldComponentProps {
|
|
23
|
+
error?: string;
|
|
24
|
+
isOptional?: boolean;
|
|
25
|
+
isShallow?: boolean;
|
|
26
|
+
label?: string | null;
|
|
27
|
+
render?: ((props: FormFieldComponentProps) => React.ReactNode) | null;
|
|
28
|
+
width?: 'full' | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Render some kind of form control, plus a label and error message if specified. By default, it
|
|
33
|
+
* will render a `TextInput`. Using the `render` prop however, you can render any component you
|
|
34
|
+
* like. The rendered component will be passed the following props from `FormField`:
|
|
35
|
+
*
|
|
36
|
+
* ```
|
|
37
|
+
* name, value, hasError, isOptional, onChange
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* The rendered component can then handle these in any way it likes.
|
|
41
|
+
*/
|
|
42
|
+
const FormField: React.FunctionComponent<FormFieldProps> = ({
|
|
43
|
+
action,
|
|
44
|
+
error,
|
|
45
|
+
id,
|
|
46
|
+
isDisabled,
|
|
47
|
+
isOptional,
|
|
48
|
+
isShallow,
|
|
49
|
+
label,
|
|
50
|
+
name,
|
|
51
|
+
onChange,
|
|
52
|
+
onKeyDown,
|
|
53
|
+
render,
|
|
54
|
+
value,
|
|
55
|
+
width,
|
|
56
|
+
}) => {
|
|
57
|
+
const props = {
|
|
58
|
+
id,
|
|
59
|
+
name,
|
|
60
|
+
hasError: Boolean(error),
|
|
61
|
+
isDisabled,
|
|
62
|
+
isOptional,
|
|
63
|
+
onChange,
|
|
64
|
+
onKeyDown,
|
|
65
|
+
};
|
|
66
|
+
const component = render
|
|
67
|
+
? render
|
|
68
|
+
: (): React.ReactNode => <TextInput value={value?.toString()} {...props} />;
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div
|
|
72
|
+
className={classNames(
|
|
73
|
+
styles.root,
|
|
74
|
+
error && styles.rootHasError,
|
|
75
|
+
isShallow && styles.rootIsShallow,
|
|
76
|
+
width && styles[`rootWidth${ucwords(width)}`]
|
|
77
|
+
)}
|
|
78
|
+
data-testid="form-field-root"
|
|
79
|
+
>
|
|
80
|
+
{label ? (
|
|
81
|
+
<div className={styles.label}>
|
|
82
|
+
<FormLabel htmlFor={`c_${name}`} isOptional={isOptional}>
|
|
83
|
+
{label}
|
|
84
|
+
</FormLabel>
|
|
85
|
+
</div>
|
|
86
|
+
) : null}
|
|
87
|
+
<div className={styles.field}>{component({ value, ...props })}</div>
|
|
88
|
+
{action ? (
|
|
89
|
+
<div className={styles.action}>
|
|
90
|
+
<Button
|
|
91
|
+
isDisabled={isDisabled || action.isDisabled}
|
|
92
|
+
onClick={action.onClick}
|
|
93
|
+
variant={action.variant}
|
|
94
|
+
>
|
|
95
|
+
{action.label}
|
|
96
|
+
</Button>
|
|
97
|
+
</div>
|
|
98
|
+
) : null}
|
|
99
|
+
{error ? (
|
|
100
|
+
<div className={styles.error}>
|
|
101
|
+
<FormError message={error} />
|
|
102
|
+
</div>
|
|
103
|
+
) : null}
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* This is necessary to ensure `<Form />` components can still identify a `FormField` even after
|
|
110
|
+
* minification (in production mode)
|
|
111
|
+
*/
|
|
112
|
+
FormField.displayName = 'FormField';
|
|
113
|
+
|
|
114
|
+
FormField.propTypes = {
|
|
115
|
+
/**
|
|
116
|
+
* The name of the field. Passed to the rendered component, as well as being used to link the
|
|
117
|
+
* label to the form control, for accessibility
|
|
118
|
+
*/
|
|
119
|
+
name: PropTypes.string.isRequired,
|
|
120
|
+
|
|
121
|
+
action: PropTypes.shape({
|
|
122
|
+
isDisabled: PropTypes.bool,
|
|
123
|
+
label: PropTypes.string.isRequired,
|
|
124
|
+
onClick: PropTypes.func.isRequired,
|
|
125
|
+
}),
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* An error message. If specified, an error message is displayed and a bool value `hasError` is
|
|
129
|
+
* passed to the rendered component
|
|
130
|
+
*/
|
|
131
|
+
error: PropTypes.string,
|
|
132
|
+
|
|
133
|
+
id: PropTypes.string,
|
|
134
|
+
|
|
135
|
+
isDisabled: PropTypes.bool,
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* If the field is not required (and has a label), a small label is displayed indicating this
|
|
139
|
+
*/
|
|
140
|
+
isOptional: PropTypes.bool,
|
|
141
|
+
|
|
142
|
+
isShallow: PropTypes.bool,
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The form label that will appear above the rendered component. Not required, but recommended
|
|
146
|
+
* for accessibility
|
|
147
|
+
*/
|
|
148
|
+
label: PropTypes.string,
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* A function that should return a component. The first and only argument of the function is an
|
|
152
|
+
* object containing the `props` defined in the introduction above.
|
|
153
|
+
*/
|
|
154
|
+
render: PropTypes.func,
|
|
155
|
+
// eslint-disable-next-line react/forbid-prop-types
|
|
156
|
+
value: PropTypes.any,
|
|
157
|
+
width: PropTypes.oneOf(['full']),
|
|
158
|
+
onChange: PropTypes.func,
|
|
159
|
+
onKeyDown: PropTypes.func,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export default FormField;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
|
|
5
|
+
import TestChangeHandler from '@utility/TestChangeHandler';
|
|
6
|
+
|
|
7
|
+
import FormRepeater from './index';
|
|
8
|
+
|
|
9
|
+
describe('FormRepeater', () => {
|
|
10
|
+
it('should render', () => {
|
|
11
|
+
render(<FormRepeater name="lorem" />);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should render the initial field', () => {
|
|
15
|
+
render(<FormRepeater name="lorem" />);
|
|
16
|
+
expect(screen.getAllByRole('textbox')).toHaveLength(1);
|
|
17
|
+
expect(screen.getAllByRole('textbox')[0]).toHaveValue('');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should render an additional empty field', () => {
|
|
21
|
+
render(<FormRepeater name="lorem" value={['Lorem']} />);
|
|
22
|
+
expect(screen.getAllByRole('textbox')).toHaveLength(2);
|
|
23
|
+
expect(screen.getAllByRole('textbox')[0]).toHaveValue('Lorem');
|
|
24
|
+
expect(screen.getAllByRole('textbox')[1]).toHaveValue('');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should render remove buttons', () => {
|
|
28
|
+
render(<FormRepeater name="lorem" value={['Lorem']} />);
|
|
29
|
+
expect(screen.getAllByText('Remove')).toHaveLength(1);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should render labels', () => {
|
|
33
|
+
render(<FormRepeater label="Lorem" name="lorem" value={['Lorem', 'Ipsum']} />);
|
|
34
|
+
expect(screen.getByText('Lorem')).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should have unique ids for each textinput', () => {
|
|
38
|
+
render(<FormRepeater name="lorem" value={['Lorem', 'Ipsum']} />);
|
|
39
|
+
expect(screen.getAllByRole('textbox')[0]).toHaveAttribute('id', 'c_lorem_0');
|
|
40
|
+
expect(screen.getAllByRole('textbox')[1]).toHaveAttribute('id', 'c_lorem_1');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should handle max properly', () => {
|
|
44
|
+
render(<FormRepeater max={3} name="lorem" value={['Lorem', 'Ipsum', 'Dolor']} />);
|
|
45
|
+
expect(screen.getAllByRole('textbox')).toHaveLength(3);
|
|
46
|
+
expect(screen.getAllByText('Remove')).toHaveLength(3);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should handle null values properly', () => {
|
|
50
|
+
render(<FormRepeater name="lorem" value={['Lorem', null]} />);
|
|
51
|
+
expect(screen.getAllByRole('textbox')).toHaveLength(3);
|
|
52
|
+
expect(screen.getAllByRole('textbox')[1]).toHaveValue('');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should handle onChange ', () => {
|
|
56
|
+
render(
|
|
57
|
+
<TestChangeHandler>
|
|
58
|
+
<FormRepeater name="lorem" />
|
|
59
|
+
</TestChangeHandler>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
userEvent.type(screen.getAllByRole('textbox')[0], 'Ipsum');
|
|
63
|
+
expect(screen.getAllByRole('textbox')[0]).toHaveValue('Ipsum');
|
|
64
|
+
expect(screen.getByTestId('test-change-handler-value')).toHaveTextContent('["Ipsum"]');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should handle onChange with existing ', () => {
|
|
68
|
+
render(
|
|
69
|
+
<TestChangeHandler defaultValue={['Lorem']}>
|
|
70
|
+
<FormRepeater name="lorem" />
|
|
71
|
+
</TestChangeHandler>
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
userEvent.type(screen.getAllByRole('textbox')[0], 'Ipsum');
|
|
75
|
+
|
|
76
|
+
expect(screen.getAllByRole('textbox')[0]).toHaveValue('LoremIpsum');
|
|
77
|
+
expect(screen.getByTestId('test-change-handler-value')).toHaveTextContent('["LoremIpsum"]');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should handle onChange with new', () => {
|
|
81
|
+
render(
|
|
82
|
+
<TestChangeHandler defaultValue={['Lorem']}>
|
|
83
|
+
<FormRepeater name="lorem" />
|
|
84
|
+
</TestChangeHandler>
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
userEvent.type(screen.getAllByRole('textbox')[1], 'Ipsum');
|
|
88
|
+
|
|
89
|
+
expect(screen.getAllByRole('textbox')[1]).toHaveValue('Ipsum');
|
|
90
|
+
expect(screen.getByTestId('test-change-handler-value')).toHaveTextContent(
|
|
91
|
+
'["Lorem","Ipsum"]'
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should handle change if no onChange', () => {
|
|
96
|
+
const mockFn = jest.fn();
|
|
97
|
+
render(<FormRepeater name="lorem" />);
|
|
98
|
+
|
|
99
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
100
|
+
userEvent.type(screen.getAllByRole('textbox')[0], 'a');
|
|
101
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should handle remove', () => {
|
|
105
|
+
const mockFn = jest.fn();
|
|
106
|
+
render(<FormRepeater name="lorem" onChange={mockFn} value={['Lorem', 'Ipsum', 'Dolor']} />);
|
|
107
|
+
|
|
108
|
+
expect(screen.getAllByRole('textbox')).toHaveLength(4);
|
|
109
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
110
|
+
|
|
111
|
+
userEvent.click(screen.getAllByText('Remove')[0]);
|
|
112
|
+
|
|
113
|
+
expect(mockFn).toHaveBeenCalledTimes(1);
|
|
114
|
+
expect(mockFn).toHaveBeenLastCalledWith({
|
|
115
|
+
target: { name: 'lorem', value: ['Ipsum', 'Dolor'] },
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should handle remove if no onChange', () => {
|
|
120
|
+
const mockFn = jest.fn();
|
|
121
|
+
render(<FormRepeater name="lorem" value={['Lorem']} />);
|
|
122
|
+
|
|
123
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
124
|
+
userEvent.click(screen.getAllByText('Remove')[0]);
|
|
125
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import FormField from '@components/FormField';
|
|
5
|
+
|
|
6
|
+
import type { InputProps, InputValue, SimpleAction, SimpleEvent } from '@utility/interfaces';
|
|
7
|
+
|
|
8
|
+
import styles from './FormRepeater.module.css';
|
|
9
|
+
|
|
10
|
+
interface FormRepeaterProps extends InputProps {
|
|
11
|
+
label?: string;
|
|
12
|
+
max?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Parse the values that have been passed in as `value`, and prepare them for the `FormField`s.
|
|
16
|
+
const parseValues = (value?: InputValue, max?: number): string[] => {
|
|
17
|
+
// If there is no value, or an empty value, then return an array.
|
|
18
|
+
if (!value || !Array.isArray(value) || !value.length) {
|
|
19
|
+
return [''];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* Otherwise, return the existing array, and an empty string (for the new field, if the max is
|
|
24
|
+
* Not reached).
|
|
25
|
+
*/
|
|
26
|
+
const stringifiedValue = value.map((item) => (item || '').toString());
|
|
27
|
+
|
|
28
|
+
return max && value.length >= max ? [...stringifiedValue] : [...stringifiedValue, ''];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const getAction = (
|
|
32
|
+
onClick: () => void,
|
|
33
|
+
values: string[],
|
|
34
|
+
index: number,
|
|
35
|
+
max?: number
|
|
36
|
+
): SimpleAction | null => {
|
|
37
|
+
if (index === values.length - 1 && index !== (max || 0) - 1) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
label: 'Remove',
|
|
43
|
+
onClick,
|
|
44
|
+
variant: ['bordered', 'danger'],
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const FormRepeater: React.FunctionComponent<FormRepeaterProps> = ({
|
|
49
|
+
label,
|
|
50
|
+
max,
|
|
51
|
+
name,
|
|
52
|
+
onChange,
|
|
53
|
+
value,
|
|
54
|
+
}) => {
|
|
55
|
+
const values = parseValues(value, max);
|
|
56
|
+
|
|
57
|
+
const handleChange = (event: SimpleEvent, index: number): void => {
|
|
58
|
+
if (!onChange) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const newValue = [
|
|
63
|
+
...values.slice(0, index),
|
|
64
|
+
event.target.value,
|
|
65
|
+
...values.slice(index + 1),
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
onChange({
|
|
69
|
+
target: {
|
|
70
|
+
name,
|
|
71
|
+
value: newValue.filter(Boolean),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handleRemove = (index: number): void => {
|
|
77
|
+
if (!onChange) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const newValue = [...values.slice(0, index), ...values.slice(index + 1)];
|
|
82
|
+
|
|
83
|
+
onChange({
|
|
84
|
+
target: {
|
|
85
|
+
name,
|
|
86
|
+
value: newValue.filter(Boolean),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div className={styles.root}>
|
|
93
|
+
{/* eslint-disable react/no-array-index-key */}
|
|
94
|
+
{values.map((_item, index) => (
|
|
95
|
+
<FormField
|
|
96
|
+
key={index}
|
|
97
|
+
action={getAction(() => handleRemove(index), values, index, max)}
|
|
98
|
+
id={`c_${name}_${index}`}
|
|
99
|
+
label={index === 0 ? label : null}
|
|
100
|
+
name={name}
|
|
101
|
+
onChange={(event): void => handleChange(event, index)}
|
|
102
|
+
value={values[index]}
|
|
103
|
+
isShallow
|
|
104
|
+
/>
|
|
105
|
+
))}
|
|
106
|
+
{/* eslint-enable react/no-array-index-key */}
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
FormRepeater.propTypes = {
|
|
112
|
+
name: PropTypes.string.isRequired,
|
|
113
|
+
label: PropTypes.string,
|
|
114
|
+
max: PropTypes.number,
|
|
115
|
+
onChange: PropTypes.func,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export default FormRepeater;
|