@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,216 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
import { ApiService, parseNumeric } from '@sqrzro/utility';
|
|
6
|
+
|
|
7
|
+
import DropdownPanel from '@core/DropdownPanel';
|
|
8
|
+
import type { DropdownItem } from '@core/DropdownPanel';
|
|
9
|
+
import ErrorMessage from '@core/ErrorMessage';
|
|
10
|
+
import InputPanel from '@core/InputPanel';
|
|
11
|
+
|
|
12
|
+
import TextInput from '@components/TextInput';
|
|
13
|
+
|
|
14
|
+
import useAccessiblePanel from '@hooks/useAccessiblePanel';
|
|
15
|
+
import useClickOutside from '@hooks/useClickOutside';
|
|
16
|
+
|
|
17
|
+
import type { InputProps, SimpleEvent } from '@utility/interfaces';
|
|
18
|
+
|
|
19
|
+
import styles from './AutoSuggest.module.css';
|
|
20
|
+
|
|
21
|
+
const transformSuggestions = (data: (DropdownItem | string)[] | null): DropdownItem[] => {
|
|
22
|
+
if (!data) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
return data.map((item) => (typeof item === 'object' ? item : { id: item, name: item }));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
interface AutoSuggestProps extends InputProps {
|
|
29
|
+
/**
|
|
30
|
+
* An array of strings to filter for the suggestions. If a `remote` prop is specified, this is
|
|
31
|
+
* ignored.
|
|
32
|
+
*/
|
|
33
|
+
data?: (DropdownItem | string)[] | null;
|
|
34
|
+
|
|
35
|
+
/** The URL for the endpoint that will return the suggestions */
|
|
36
|
+
remote?: string | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* As a user types, suggestions based on they've typed are displayed in a panel below. When a user
|
|
41
|
+
* clicks a suggestion, the value is updated. Under the hood, it is more or less a combination of a
|
|
42
|
+
* `TextInput` and a `DropdownPanel`.
|
|
43
|
+
*
|
|
44
|
+
* ## Request Methods
|
|
45
|
+
*
|
|
46
|
+
* At its most basic, the suggestions are a predefined array of `data`. However,
|
|
47
|
+
* if the `remote` prop is specified, the AutoSuggest will `GET` that endpoint as the user types.
|
|
48
|
+
* The following will be appended onto the query:
|
|
49
|
+
*
|
|
50
|
+
* ````
|
|
51
|
+
* ?search={value}
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* The endpoint should then handle filtering the data, and returning an array of the results. If the
|
|
55
|
+
* value of the input changes before the previous `GET` request has completed, that one is
|
|
56
|
+
* cancelled and a new one started, with the updated search query.
|
|
57
|
+
*
|
|
58
|
+
* ## Data Formats
|
|
59
|
+
*
|
|
60
|
+
* The data returned should be one of two formats. The choice of format has an impact on how the
|
|
61
|
+
* value is stored, and the label that is displayed.
|
|
62
|
+
*
|
|
63
|
+
* The most basic format is an array of strings. The value is stored as the string itself, and the
|
|
64
|
+
* label displays the same string. This is most useful for situations where no relationships are
|
|
65
|
+
* required on the backend, and the `AutoSuggest` is purely being used to assist the user in
|
|
66
|
+
* defining a value.
|
|
67
|
+
*
|
|
68
|
+
* An example of this data would be:
|
|
69
|
+
*
|
|
70
|
+
* ```
|
|
71
|
+
* ['apple', 'banana', 'carrot']
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* The second format is an array of objects. The value is stored as the `id` of the object, and the
|
|
75
|
+
* label displays the `name` of the object. This is most useful for situations where a relationship
|
|
76
|
+
* is required on the backend, and the `AutoSuggest` is being used to assist the user in defining
|
|
77
|
+
* a value. With this format, the `AutoSuggest` works more like a `Dropdown`.
|
|
78
|
+
*
|
|
79
|
+
* For example:
|
|
80
|
+
*
|
|
81
|
+
* ```
|
|
82
|
+
* [{ id: 1, name: 'apple' }, { id: 2, name: 'banana' }, { id: 3, name: 'carrot' }]
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
const AutoSuggest: React.FunctionComponent<AutoSuggestProps> = ({
|
|
86
|
+
data,
|
|
87
|
+
name,
|
|
88
|
+
remote,
|
|
89
|
+
value,
|
|
90
|
+
hasError,
|
|
91
|
+
onChange,
|
|
92
|
+
}) => {
|
|
93
|
+
const [suggestions, setSuggestions] = useState<(DropdownItem | string)[] | null>(null);
|
|
94
|
+
|
|
95
|
+
const [isOpen, setIsOpen, node] = useClickOutside();
|
|
96
|
+
const [isError, setIsError] = useState(false);
|
|
97
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
98
|
+
|
|
99
|
+
const getLocalData = (search: string): void => {
|
|
100
|
+
if (!data || !data.length) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const rgx = new RegExp(`^${search}.*`, 'iu');
|
|
105
|
+
const response = data.filter((item) =>
|
|
106
|
+
rgx.exec(typeof item === 'string' ? item : item.name)
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
setIsOpen(Boolean(response.length));
|
|
110
|
+
setSuggestions(response);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const getData = async (search: string): Promise<void> => {
|
|
114
|
+
if (!remote) {
|
|
115
|
+
getLocalData(search);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
setIsLoading(true);
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
const response = await ApiService.get<{ data: string[] }>([remote, { search }], {
|
|
123
|
+
isCancellable: true,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
setSuggestions(response.data.data);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
setIsError(true);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
setIsLoading(false);
|
|
132
|
+
setIsOpen(true);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const handleChange = (event: SimpleEvent): void => {
|
|
136
|
+
if (onChange) {
|
|
137
|
+
onChange(event);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!event.target.value) {
|
|
141
|
+
setIsOpen(false);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
void getData(event.target.value.toString());
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const handleSuggest = (item: DropdownItem): void => {
|
|
149
|
+
const simpleEvent: SimpleEvent = {
|
|
150
|
+
target: { name, value: item.id },
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
if (onChange) {
|
|
154
|
+
onChange(simpleEvent);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
setIsOpen(false);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
if (isError) {
|
|
161
|
+
return <ErrorMessage isMini />;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const parsedValue = parseNumeric(value);
|
|
165
|
+
const transformed = transformSuggestions(suggestions);
|
|
166
|
+
|
|
167
|
+
const { handleKeyboard } = useAccessiblePanel<HTMLInputElement>({
|
|
168
|
+
data: transformed,
|
|
169
|
+
name,
|
|
170
|
+
onChange,
|
|
171
|
+
value: parsedValue,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<div ref={node} className={classNames(styles.root, isOpen && styles.rootOpen)}>
|
|
176
|
+
<TextInput
|
|
177
|
+
autocomplete={false}
|
|
178
|
+
hasError={hasError}
|
|
179
|
+
isLoading={isLoading}
|
|
180
|
+
name={name}
|
|
181
|
+
onChange={handleChange}
|
|
182
|
+
onKeyDown={handleKeyboard}
|
|
183
|
+
value={parsedValue}
|
|
184
|
+
/>
|
|
185
|
+
{isOpen && suggestions && suggestions.length ? (
|
|
186
|
+
<InputPanel isScrollable>
|
|
187
|
+
<DropdownPanel
|
|
188
|
+
data={transformed}
|
|
189
|
+
name={name}
|
|
190
|
+
onChange={({ item }): void => handleSuggest(item)}
|
|
191
|
+
value={parsedValue}
|
|
192
|
+
/>
|
|
193
|
+
</InputPanel>
|
|
194
|
+
) : null}
|
|
195
|
+
</div>
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
AutoSuggest.propTypes = {
|
|
200
|
+
name: PropTypes.string.isRequired,
|
|
201
|
+
data: PropTypes.arrayOf(
|
|
202
|
+
PropTypes.oneOfType([
|
|
203
|
+
PropTypes.string.isRequired,
|
|
204
|
+
PropTypes.shape({
|
|
205
|
+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
206
|
+
name: PropTypes.string.isRequired,
|
|
207
|
+
}).isRequired,
|
|
208
|
+
]).isRequired
|
|
209
|
+
),
|
|
210
|
+
hasError: PropTypes.bool,
|
|
211
|
+
remote: PropTypes.string,
|
|
212
|
+
value: PropTypes.string,
|
|
213
|
+
onChange: PropTypes.func,
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export default AutoSuggest;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
-webkit-appearance: none;
|
|
3
|
+
align-items: center;
|
|
4
|
+
background-color: var(--clr-link);
|
|
5
|
+
border: .2rem var(--clr-link) solid;
|
|
6
|
+
border-radius: .5rem;
|
|
7
|
+
color: var(--clr-white);
|
|
8
|
+
cursor: pointer;
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
font-family: inherit;
|
|
12
|
+
font-size: var(--fs-sml);
|
|
13
|
+
font-weight: var(--fw-bold);
|
|
14
|
+
height: var(--input-height);
|
|
15
|
+
justify-content: center;
|
|
16
|
+
min-width: 10rem;
|
|
17
|
+
padding: 0 1.8rem;
|
|
18
|
+
position: relative;
|
|
19
|
+
text-align: center;
|
|
20
|
+
transition: background-color .15s, border-color .15s;
|
|
21
|
+
white-space: nowrap;
|
|
22
|
+
|
|
23
|
+
&:hover {
|
|
24
|
+
background-color: var(--clr-link-hover);
|
|
25
|
+
border-color: var(--clr-link-hover);
|
|
26
|
+
color: var(--clr-white);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&:focus {
|
|
30
|
+
outline: none;
|
|
31
|
+
|
|
32
|
+
&::before {
|
|
33
|
+
border: .1rem var(--clr-grey500) dashed;
|
|
34
|
+
border-radius: .7rem;
|
|
35
|
+
bottom: -.5rem;
|
|
36
|
+
content: '';
|
|
37
|
+
left: -.5rem;
|
|
38
|
+
position: absolute;
|
|
39
|
+
right: -.5rem;
|
|
40
|
+
top: -.5rem;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.rootLink {
|
|
46
|
+
background-color: transparent;
|
|
47
|
+
border-color: transparent;
|
|
48
|
+
color: var(--clr-link);
|
|
49
|
+
|
|
50
|
+
&:hover {
|
|
51
|
+
background-color: transparent;
|
|
52
|
+
border-color: transparent;
|
|
53
|
+
color: var(--clr-link-hover);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.rootBordered {
|
|
58
|
+
background-color: transparent;
|
|
59
|
+
color: var(--clr-link);
|
|
60
|
+
|
|
61
|
+
&:hover {
|
|
62
|
+
background-color: transparent;
|
|
63
|
+
border-color: var(--clr-link-hover);
|
|
64
|
+
color: var(--clr-link-hover);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.rootDanger {
|
|
69
|
+
background-color: var(--clr-danger);
|
|
70
|
+
border-color: var(--clr-danger);
|
|
71
|
+
|
|
72
|
+
&:hover {
|
|
73
|
+
background-color: var(--clr-danger-dark);
|
|
74
|
+
border-color: var(--clr-danger-dark);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.rootBorderedDanger {
|
|
79
|
+
background-color: transparent;
|
|
80
|
+
border-color: var(--clr-danger);
|
|
81
|
+
color: var(--clr-danger);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.rootIsDisabled {
|
|
85
|
+
background-color: var(--clr-grey400);
|
|
86
|
+
border-color: var(--clr-grey400);
|
|
87
|
+
color: var(--clr-grey700);
|
|
88
|
+
opacity: .3;
|
|
89
|
+
pointer-events: none;
|
|
90
|
+
user-select: none;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.rootIsFullWidth {
|
|
94
|
+
width: 100%;
|
|
95
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import Button from './index';
|
|
5
|
+
|
|
6
|
+
describe('Button', () => {
|
|
7
|
+
it('should render', () => {
|
|
8
|
+
render(<Button>Lorem</Button>);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should render default', () => {
|
|
12
|
+
render(<Button>Lorem</Button>);
|
|
13
|
+
|
|
14
|
+
const button = screen.getByRole('button');
|
|
15
|
+
|
|
16
|
+
expect(button).toBeInTheDocument();
|
|
17
|
+
expect(button).toHaveAttribute('type', 'button');
|
|
18
|
+
expect(button).toHaveTextContent(/^Lorem$/u);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should render link', () => {
|
|
22
|
+
render(<Button to="lorem">Lorem</Button>);
|
|
23
|
+
|
|
24
|
+
const link = screen.getByRole('link');
|
|
25
|
+
|
|
26
|
+
expect(link).toBeInTheDocument();
|
|
27
|
+
expect(link).toHaveAttribute('href', '/lorem');
|
|
28
|
+
expect(link).toHaveTextContent(/^Lorem$/u);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should render type', () => {
|
|
32
|
+
render(<Button type="submit">Lorem</Button>);
|
|
33
|
+
|
|
34
|
+
const button = screen.getByRole('button');
|
|
35
|
+
|
|
36
|
+
expect(button).toHaveAttribute('type', 'submit');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should render variant', () => {
|
|
40
|
+
render(<Button variant="secondary">Lorem</Button>);
|
|
41
|
+
|
|
42
|
+
const button = screen.getByRole('button');
|
|
43
|
+
|
|
44
|
+
expect(button).toHaveClass('root rootSecondary');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should render variant array', () => {
|
|
48
|
+
render(<Button variant={['danger', 'bordered']}>Lorem</Button>);
|
|
49
|
+
|
|
50
|
+
const button = screen.getByRole('button');
|
|
51
|
+
expect(button).toHaveClass('root rootBorderedDanger');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should render variant array with null', () => {
|
|
55
|
+
render(<Button variant={['danger', 'bordered']}>Lorem</Button>);
|
|
56
|
+
|
|
57
|
+
const button = screen.getByRole('button');
|
|
58
|
+
expect(button).toHaveClass('root rootBorderedDanger');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should render disabled', () => {
|
|
62
|
+
render(<Button isDisabled>Lorem</Button>);
|
|
63
|
+
|
|
64
|
+
const button = screen.getByRole('button');
|
|
65
|
+
|
|
66
|
+
expect(button).toHaveClass('root rootIsDisabled');
|
|
67
|
+
expect(button).toBeDisabled();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Story } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import Button from './index';
|
|
5
|
+
import type { ButtonProps } from './index';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Components/Button',
|
|
9
|
+
component: Button,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const Template: Story<ButtonProps> = (props) => <Button {...props} />;
|
|
13
|
+
|
|
14
|
+
export const Basic = Template.bind({});
|
|
15
|
+
|
|
16
|
+
Basic.args = {
|
|
17
|
+
children: 'Lorem Ipsum',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const Danger = Template.bind({});
|
|
21
|
+
|
|
22
|
+
Danger.args = {
|
|
23
|
+
children: 'Lorem Ipsum',
|
|
24
|
+
variant: 'danger',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const Bordered = Template.bind({});
|
|
28
|
+
|
|
29
|
+
Bordered.args = {
|
|
30
|
+
children: 'Lorem Ipsum',
|
|
31
|
+
variant: 'bordered',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const Disabled = Template.bind({});
|
|
35
|
+
|
|
36
|
+
Disabled.args = {
|
|
37
|
+
children: 'Lorem Ipsum',
|
|
38
|
+
isDisabled: true,
|
|
39
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
import Link from '@components/Link';
|
|
6
|
+
|
|
7
|
+
import useVariant from '@hooks/useVariant';
|
|
8
|
+
|
|
9
|
+
import type { ButtonVariant } from '@utility/interfaces';
|
|
10
|
+
import { ButtonVariantPropType } from '@utility/prop-types';
|
|
11
|
+
|
|
12
|
+
import styles from './Button.module.css';
|
|
13
|
+
|
|
14
|
+
export interface ButtonProps {
|
|
15
|
+
/** Probably the button text, but could be any HTML element or React component */
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
|
|
18
|
+
/** If set to true, the Button will be greyed out and non-interactive */
|
|
19
|
+
isDisabled?: boolean | null;
|
|
20
|
+
isFullWidth?: boolean | null;
|
|
21
|
+
onClick?: React.MouseEventHandler<HTMLAnchorElement | HTMLButtonElement>;
|
|
22
|
+
|
|
23
|
+
/** If specified, the Button will be created as a Link element. */
|
|
24
|
+
to?: string;
|
|
25
|
+
|
|
26
|
+
/** The type of button. Button's with a type of `submit` will submit a parent form */
|
|
27
|
+
type?: 'button' | 'submit';
|
|
28
|
+
|
|
29
|
+
/** With the exception of `bordered` these variants correspond to the theme colours */
|
|
30
|
+
variant?: ButtonVariant | ButtonVariant[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Either a `Link` component or a `button` element, depending on whether a `to` prop is specified.
|
|
35
|
+
*
|
|
36
|
+
* As a `Link`, it provides navigation between pages, and as a `button` it will handle the
|
|
37
|
+
* `onClick` function when clicked (if one is specified).
|
|
38
|
+
*
|
|
39
|
+
* ## to & onClick
|
|
40
|
+
*
|
|
41
|
+
* Although it is possible to omit both the `to` and `onClick` props, there will
|
|
42
|
+
* be nearly zero situations where this would be useful. It is also possible to include both props.
|
|
43
|
+
* This will create a `Link` component, and handle the `onClick` function before navigation.
|
|
44
|
+
*
|
|
45
|
+
* ## Styles
|
|
46
|
+
*
|
|
47
|
+
* The `Button` will stretch to the full width of its parent element. If you wish to have a smaller
|
|
48
|
+
* width, you can wrap it in a `div`, and then wrap that `div` in a component with a flex property.
|
|
49
|
+
* Components like `ListActions` and `ModalActions` do this for you.
|
|
50
|
+
*/
|
|
51
|
+
const Button: React.FunctionComponent<ButtonProps> = ({
|
|
52
|
+
to,
|
|
53
|
+
children,
|
|
54
|
+
type,
|
|
55
|
+
variant,
|
|
56
|
+
isDisabled,
|
|
57
|
+
isFullWidth,
|
|
58
|
+
onClick,
|
|
59
|
+
}) => {
|
|
60
|
+
const { applyVariantClassName } = useVariant<ButtonVariant>(variant);
|
|
61
|
+
|
|
62
|
+
const className = classNames(
|
|
63
|
+
styles.root,
|
|
64
|
+
applyVariantClassName(styles),
|
|
65
|
+
isDisabled && styles.rootIsDisabled,
|
|
66
|
+
isFullWidth && styles.rootIsFullWidth
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (to) {
|
|
70
|
+
return (
|
|
71
|
+
<Link className={className} onClick={onClick} to={to}>
|
|
72
|
+
{children}
|
|
73
|
+
</Link>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<button
|
|
79
|
+
className={className}
|
|
80
|
+
disabled={isDisabled || false}
|
|
81
|
+
onClick={onClick}
|
|
82
|
+
type={type === 'submit' ? 'submit' : 'button'}
|
|
83
|
+
>
|
|
84
|
+
{children}
|
|
85
|
+
</button>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
Button.propTypes = {
|
|
90
|
+
children: PropTypes.node.isRequired,
|
|
91
|
+
isDisabled: PropTypes.bool,
|
|
92
|
+
isFullWidth: PropTypes.bool,
|
|
93
|
+
to: PropTypes.string,
|
|
94
|
+
type: PropTypes.oneOf(['button', 'submit']),
|
|
95
|
+
variant: ButtonVariantPropType,
|
|
96
|
+
onClick: PropTypes.func,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export default Button;
|