@tsed/react-formio 3.0.0-alpha.8 → 3.0.0-rc.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/dist/all.d.ts +0 -0
- package/dist/all.js +38 -0
- package/dist/all.js.map +1 -0
- package/dist/atoms/icon/Icon.d.ts +4 -3
- package/dist/atoms/icon/Icon.js +9 -8
- package/dist/atoms/icon/Icon.js.map +1 -1
- package/dist/chunks/_commonjsHelpers.js +30 -3
- package/dist/chunks/_commonjsHelpers.js.map +1 -1
- package/dist/chunks/index.js +33 -30
- package/dist/chunks/index.js.map +1 -1
- package/dist/chunks/index.module.js +16 -16
- package/dist/chunks/index.module.js.map +1 -1
- package/dist/chunks/index2.js +56953 -0
- package/dist/chunks/index2.js.map +1 -0
- package/dist/chunks/react-select-animated.esm.js +3616 -0
- package/dist/chunks/react-select-animated.esm.js.map +1 -0
- package/dist/contexts/FormioContext.d.ts +19 -0
- package/dist/contexts/FormioContext.js +35 -0
- package/dist/contexts/FormioContext.js.map +1 -0
- package/dist/hooks/keyboard.constants.d.ts +38 -0
- package/dist/hooks/keyboard.constants.js +7 -0
- package/dist/hooks/keyboard.constants.js.map +1 -0
- package/dist/hooks/useFormioContext.d.ts +10 -0
- package/dist/hooks/useFormioContext.js +12 -0
- package/dist/hooks/useFormioContext.js.map +1 -0
- package/dist/hooks/useI18n.d.ts +4 -0
- package/dist/hooks/useI18n.js +9 -0
- package/dist/hooks/useI18n.js.map +1 -0
- package/dist/hooks/useKeyboardControls.d.ts +12 -0
- package/dist/hooks/useKeyboardControls.js +35 -0
- package/dist/hooks/useKeyboardControls.js.map +1 -0
- package/dist/hooks/useTooltip.js.map +1 -1
- package/dist/index.d.ts +1 -6
- package/dist/index.js +18 -13
- package/dist/index.js.map +1 -1
- package/dist/interfaces/ComponentType.d.ts +6 -2
- package/dist/interfaces/FormBuilderOptions.d.ts +7 -0
- package/dist/interfaces/FormBuilderOptions.js +2 -0
- package/dist/interfaces/FormBuilderOptions.js.map +1 -0
- package/dist/interfaces/FormOptions.d.ts +6 -13
- package/dist/interfaces/FormType.d.ts +4 -11
- package/dist/interfaces/Operation.d.ts +13 -4
- package/dist/interfaces/SubmissionType.d.ts +5 -10
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/molecules/alert/Alert.js.map +1 -1
- package/dist/molecules/button/Button.d.ts +18 -5
- package/dist/molecules/button/Button.js +24 -28
- package/dist/molecules/button/Button.js.map +1 -1
- package/dist/molecules/card/Card.js +9 -7
- package/dist/molecules/card/Card.js.map +1 -1
- package/dist/molecules/forms/form-control/FormControl.d.ts +14 -12
- package/dist/molecules/forms/form-control/FormControl.js +46 -22
- package/dist/molecules/forms/form-control/FormControl.js.map +1 -1
- package/dist/molecules/forms/input-tags/InputTags.d.ts +2 -8
- package/dist/molecules/forms/input-tags/InputTags.interface.d.ts +7 -0
- package/dist/molecules/forms/input-tags/InputTags.interface.js +2 -0
- package/dist/molecules/forms/input-tags/InputTags.interface.js.map +1 -0
- package/dist/molecules/forms/input-tags/InputTags.js +21 -27
- package/dist/molecules/forms/input-tags/InputTags.js.map +1 -1
- package/dist/molecules/forms/input-tags/all.d.ts +2 -0
- package/dist/molecules/forms/input-tags/all.js +9 -0
- package/dist/molecules/forms/input-tags/all.js.map +1 -0
- package/dist/molecules/forms/input-tags/components/ChoicesTags.d.ts +307 -0
- package/dist/molecules/forms/input-tags/components/ChoicesTags.js +51 -0
- package/dist/molecules/forms/input-tags/components/ChoicesTags.js.map +1 -0
- package/dist/molecules/forms/input-tags/components/ReactTags.d.ts +2 -0
- package/dist/molecules/forms/input-tags/components/ReactTags.js +1926 -0
- package/dist/molecules/forms/input-tags/components/ReactTags.js.map +1 -0
- package/dist/molecules/forms/input-text/InputText.d.ts +2 -14
- package/dist/molecules/forms/input-text/InputText.interface.d.ts +4 -0
- package/dist/molecules/forms/input-text/InputText.interface.js +2 -0
- package/dist/molecules/forms/input-text/InputText.interface.js.map +1 -0
- package/dist/molecules/forms/input-text/InputText.js +46 -56
- package/dist/molecules/forms/input-text/InputText.js.map +1 -1
- package/dist/molecules/forms/select/Select.d.ts +1 -1
- package/dist/molecules/forms/select/{Select.interfaces.d.ts → Select.interface.d.ts} +8 -10
- package/dist/molecules/forms/select/Select.interface.js +2 -0
- package/dist/molecules/forms/select/Select.interface.js.map +1 -0
- package/dist/molecules/forms/select/Select.js +9 -10
- package/dist/molecules/forms/select/Select.js.map +1 -1
- package/dist/molecules/forms/select/all.d.ts +1 -1
- package/dist/molecules/forms/select/all.js +1 -0
- package/dist/molecules/forms/select/all.js.map +1 -1
- package/dist/molecules/forms/select/components/ChoicesSelect.d.ts +1 -1
- package/dist/molecules/forms/select/components/ChoicesSelect.js +72 -83
- package/dist/molecules/forms/select/components/ChoicesSelect.js.map +1 -1
- package/dist/molecules/forms/select/components/HtmlSelect.d.ts +1 -1
- package/dist/molecules/forms/select/components/HtmlSelect.js +17 -16
- package/dist/molecules/forms/select/components/HtmlSelect.js.map +1 -1
- package/dist/molecules/forms/select/components/ReactSelect.d.ts +1 -1
- package/dist/molecules/forms/select/components/ReactSelect.js +28 -3034
- package/dist/molecules/forms/select/components/ReactSelect.js.map +1 -1
- package/dist/molecules/forms/select/components/choices.template.js +2340 -2257
- package/dist/molecules/forms/select/components/choices.template.js.map +1 -1
- package/dist/molecules/forms/select/hooks/useOptions.d.ts +3 -3
- package/dist/molecules/forms/select/hooks/useOptions.js +15 -15
- package/dist/molecules/forms/select/hooks/useOptions.js.map +1 -1
- package/dist/molecules/loader/Loader.d.ts +4 -4
- package/dist/molecules/loader/Loader.js +16 -8
- package/dist/molecules/loader/Loader.js.map +1 -1
- package/dist/molecules/modal/Modal.js +23 -24
- package/dist/molecules/modal/Modal.js.map +1 -1
- package/dist/molecules/pagination/Pagination.d.ts +7 -6
- package/dist/molecules/pagination/Pagination.js +48 -57
- package/dist/molecules/pagination/Pagination.js.map +1 -1
- package/dist/molecules/pagination/PaginationButton.js +10 -10
- package/dist/molecules/pagination/PaginationButton.js.map +1 -1
- package/dist/molecules/pagination/all.js +5 -4
- package/dist/molecules/pagination/all.js.map +1 -1
- package/dist/molecules/pagination/utils/getPageNumbers.js.map +1 -0
- package/dist/molecules/table/Table.d.ts +16 -2
- package/dist/molecules/table/Table.js +53 -77
- package/dist/molecules/table/Table.js.map +1 -1
- package/dist/molecules/table/all.d.ts +0 -0
- package/dist/molecules/table/all.js +19 -0
- package/dist/molecules/table/all.js.map +1 -0
- package/dist/molecules/table/components/DefaultArrowSort.d.ts +5 -1
- package/dist/molecules/table/components/DefaultArrowSort.js +17 -5
- package/dist/molecules/table/components/DefaultArrowSort.js.map +1 -1
- package/dist/molecules/table/components/DefaultCell.d.ts +5 -1
- package/dist/molecules/table/components/DefaultCell.js +8 -6
- package/dist/molecules/table/components/DefaultCell.js.map +1 -1
- package/dist/molecules/table/components/DefaultCellFooter.d.ts +6 -0
- package/dist/molecules/table/components/DefaultCellFooter.js +12 -0
- package/dist/molecules/table/components/DefaultCellFooter.js.map +1 -0
- package/dist/molecules/table/components/DefaultCellHeader.d.ts +5 -8
- package/dist/molecules/table/components/DefaultCellHeader.js +25 -9
- package/dist/molecules/table/components/DefaultCellHeader.js.map +1 -1
- package/dist/molecules/table/components/DefaultCellOperations.d.ts +16 -10
- package/dist/molecules/table/components/DefaultCellOperations.js +23 -14
- package/dist/molecules/table/components/DefaultCellOperations.js.map +1 -1
- package/dist/molecules/table/components/DefaultFilter.d.ts +11 -0
- package/dist/molecules/table/components/DefaultFilter.js +15 -0
- package/dist/molecules/table/components/DefaultFilter.js.map +1 -0
- package/dist/molecules/table/components/DefaultOperationButton.d.ts +16 -12
- package/dist/molecules/table/components/DefaultOperationButton.js +16 -31
- package/dist/molecules/table/components/DefaultOperationButton.js.map +1 -1
- package/dist/molecules/table/filters/Filters.d.js +2 -0
- package/dist/molecules/table/filters/Filters.d.js.map +1 -0
- package/dist/molecules/table/filters/RangeFilter.d.ts +3 -0
- package/dist/molecules/table/filters/RangeFilter.js +41 -0
- package/dist/molecules/table/filters/RangeFilter.js.map +1 -0
- package/dist/molecules/table/filters/SelectFilter.d.ts +3 -0
- package/dist/molecules/table/filters/SelectFilter.js +33 -0
- package/dist/molecules/table/filters/SelectFilter.js.map +1 -0
- package/dist/molecules/table/filters/TextFieldFilter.d.ts +3 -0
- package/dist/molecules/table/filters/TextFieldFilter.js +27 -0
- package/dist/molecules/table/filters/TextFieldFilter.js.map +1 -0
- package/dist/molecules/table/hooks/useTable.d.ts +23 -0
- package/dist/molecules/table/hooks/useTable.js +35 -0
- package/dist/molecules/table/hooks/useTable.js.map +1 -0
- package/dist/molecules/table/hooks/useUniqValues.d.ts +5 -0
- package/dist/molecules/table/hooks/useUniqValues.js +11 -0
- package/dist/molecules/table/hooks/useUniqValues.js.map +1 -0
- package/dist/molecules/table/interfaces/extends.d.ts +14 -0
- package/dist/molecules/table/interfaces/extends.js +2 -0
- package/dist/molecules/table/interfaces/extends.js.map +1 -0
- package/dist/molecules/table/utils/mapFormToColumns.d.ts +2 -2
- package/dist/molecules/table/utils/mapFormToColumns.js +34 -18
- package/dist/molecules/table/utils/mapFormToColumns.js.map +1 -1
- package/dist/molecules/tabs/Tab.d.ts +13 -0
- package/dist/molecules/tabs/Tab.js +66 -0
- package/dist/molecules/tabs/Tab.js.map +1 -0
- package/dist/molecules/tabs/TabList.d.ts +2 -0
- package/dist/molecules/tabs/TabList.js +23 -0
- package/dist/molecules/tabs/TabList.js.map +1 -0
- package/dist/molecules/tabs/TabPanel.d.ts +9 -0
- package/dist/molecules/tabs/TabPanel.js +27 -0
- package/dist/molecules/tabs/TabPanel.js.map +1 -0
- package/dist/molecules/tabs/Tabs.d.ts +4 -16
- package/dist/molecules/tabs/Tabs.js +7 -67
- package/dist/molecules/tabs/Tabs.js.map +1 -1
- package/dist/molecules/tabs/TabsBody.d.ts +1 -0
- package/dist/molecules/tabs/TabsBody.js +10 -0
- package/dist/molecules/tabs/TabsBody.js.map +1 -0
- package/dist/molecules/tabs/TabsLegacy.d.ts +18 -0
- package/dist/molecules/tabs/TabsLegacy.js +49 -0
- package/dist/molecules/tabs/TabsLegacy.js.map +1 -0
- package/dist/molecules/tabs/all.d.ts +5 -0
- package/dist/molecules/tabs/all.js +13 -0
- package/dist/molecules/tabs/all.js.map +1 -0
- package/dist/molecules/tabs/context/TabControl.d.ts +52 -0
- package/dist/molecules/tabs/context/TabControl.js +85 -0
- package/dist/molecules/tabs/context/TabControl.js.map +1 -0
- package/dist/molecules/tabs/hooks/tabControl.d.ts +44 -0
- package/dist/molecules/tabs/hooks/tabControl.js +34 -0
- package/dist/molecules/tabs/hooks/tabControl.js.map +1 -0
- package/dist/organisms/form/Form.js.map +1 -1
- package/dist/organisms/form/access/FormAccess.js +41 -41
- package/dist/organisms/form/access/FormAccess.js.map +1 -1
- package/dist/organisms/form/access/FormAccess.schema.js +1 -0
- package/dist/organisms/form/access/FormAccess.schema.js.map +1 -1
- package/dist/organisms/form/access/FormAccess.utils.js +2 -2
- package/dist/organisms/form/access/FormAccess.utils.js.map +1 -1
- package/dist/organisms/form/actions/FormAction.js +34 -0
- package/dist/organisms/form/actions/FormAction.js.map +1 -0
- package/dist/organisms/form/builder/FormBuilder.js.map +1 -1
- package/dist/organisms/form/builder/FormEdit.d.ts +7 -3
- package/dist/organisms/form/builder/FormEdit.js +46 -42
- package/dist/organisms/form/builder/FormEdit.js.map +1 -1
- package/dist/organisms/form/builder/FormEdit.reducer.js.map +1 -1
- package/dist/organisms/form/builder/FormEditCtas.d.ts +2 -2
- package/dist/organisms/form/builder/FormEditCtas.js +36 -35
- package/dist/organisms/form/builder/FormEditCtas.js.map +1 -1
- package/dist/organisms/form/builder/FormParameters.d.ts +3 -2
- package/dist/organisms/form/builder/FormParameters.js +19 -18
- package/dist/organisms/form/builder/FormParameters.js.map +1 -1
- package/dist/organisms/form/builder/all.js +17 -13
- package/dist/organisms/form/builder/all.js.map +1 -1
- package/dist/organisms/form/builder/useFormBuilder.d.ts +4 -4
- package/dist/organisms/form/builder/useFormBuilder.js +36 -33
- package/dist/organisms/form/builder/useFormBuilder.js.map +1 -1
- package/dist/organisms/form/builder/useFormEdit.d.ts +2 -2
- package/dist/organisms/form/builder/useFormEdit.js +1 -1
- package/dist/organisms/form/builder/useFormEdit.js.map +1 -1
- package/dist/organisms/form/exports/FormExport.d.ts +6 -0
- package/dist/organisms/form/exports/FormExport.js +56 -0
- package/dist/organisms/form/exports/FormExport.js.map +1 -0
- package/dist/organisms/form/preview/FormPreview.d.ts +6 -0
- package/dist/organisms/form/preview/FormPreview.js +12 -0
- package/dist/organisms/form/preview/FormPreview.js.map +1 -0
- package/dist/organisms/form/settings/FormSettings.js +28 -28
- package/dist/organisms/form/settings/FormSettings.js.map +1 -1
- package/dist/organisms/form/settings/FormSettings.schema.js.map +1 -1
- package/dist/organisms/form/settings/FormSettings.utils.js.map +1 -1
- package/dist/organisms/form/useForm.d.ts +2 -1
- package/dist/organisms/form/useForm.js +664 -661
- package/dist/organisms/form/useForm.js.map +1 -1
- package/dist/organisms/modal/RemoveModal.js +16 -17
- package/dist/organisms/modal/RemoveModal.js.map +1 -1
- package/dist/organisms/table/actions/ActionsTable.d.ts +4 -3
- package/dist/organisms/table/actions/ActionsTable.js +21 -33
- package/dist/organisms/table/actions/ActionsTable.js.map +1 -1
- package/dist/organisms/table/forms/FormsTable.d.ts +2 -3
- package/dist/organisms/table/forms/FormsTable.js +48 -27
- package/dist/organisms/table/forms/FormsTable.js.map +1 -1
- package/dist/organisms/table/forms/components/FormsCell.d.ts +5 -0
- package/dist/organisms/table/forms/components/FormsCell.js +50 -0
- package/dist/organisms/table/forms/components/FormsCell.js.map +1 -0
- package/dist/organisms/table/submissions/SubmissionsTable.d.ts +12 -4
- package/dist/organisms/table/submissions/SubmissionsTable.js +10 -17
- package/dist/organisms/table/submissions/SubmissionsTable.js.map +1 -1
- package/dist/organisms/views/FormViews.d.ts +24 -0
- package/dist/organisms/views/FormViews.js +97 -0
- package/dist/organisms/views/FormViews.js.map +1 -0
- package/dist/registries/components.js +12 -11
- package/dist/registries/components.js.map +1 -1
- package/dist/utils/getEventValue.js.map +1 -1
- package/dist/utils/iconClass.js +4 -5
- package/dist/utils/iconClass.js.map +1 -1
- package/dist/utils/mapPagination.js.map +1 -1
- package/dist/utils/stopPropagationWrapper.js.map +1 -1
- package/package.json +10 -8
- package/readme.md +7 -8
- package/src/all.ts +34 -0
- package/src/atoms/icon/Icon.stories.tsx +71 -22
- package/src/atoms/icon/Icon.tsx +14 -4
- package/src/contexts/FormioContext.tsx +89 -0
- package/src/hooks/keyboard.constants.ts +40 -0
- package/src/hooks/useFormioContext.ts +13 -0
- package/src/hooks/useI18n.ts +9 -0
- package/src/hooks/useKeyboardControls.spec.tsx +208 -0
- package/src/hooks/useKeyboardControls.ts +84 -0
- package/src/index.ts +17 -13
- package/src/interfaces/ComponentType.ts +2 -2
- package/src/interfaces/FormBuilderOptions.ts +9 -0
- package/src/interfaces/FormOptions.ts +7 -13
- package/src/interfaces/FormType.ts +5 -11
- package/src/interfaces/Operation.ts +10 -4
- package/src/interfaces/SubmissionType.ts +9 -8
- package/src/interfaces/index.ts +1 -0
- package/src/molecules/__fixtures__/build.js +28 -0
- package/src/molecules/__fixtures__/form-schema.json +76 -195
- package/src/molecules/__fixtures__/form-submissions.json +11846 -46
- package/src/molecules/__fixtures__/products.json +81539 -0
- package/src/molecules/button/Button.stories.tsx +1 -1
- package/src/molecules/button/Button.tsx +43 -24
- package/src/molecules/card/Card.tsx +4 -0
- package/src/molecules/forms/form-control/FormControl.spec.tsx +7 -4
- package/src/molecules/forms/form-control/FormControl.stories.tsx +4 -4
- package/src/molecules/forms/form-control/FormControl.tsx +46 -20
- package/src/molecules/forms/input-tags/InputTags.interface.ts +9 -0
- package/src/molecules/forms/input-tags/InputTags.tsx +20 -42
- package/src/molecules/forms/input-tags/all.ts +6 -0
- package/src/molecules/forms/input-tags/components/ChoicesTags.stories.tsx +110 -0
- package/src/molecules/forms/input-tags/components/ChoicesTags.tsx +72 -0
- package/src/molecules/forms/input-tags/components/ReactTags.stories.tsx +140 -0
- package/src/molecules/forms/input-tags/components/ReactTags.tsx +38 -0
- package/src/molecules/forms/input-text/InputText.interface.ts +5 -0
- package/src/molecules/forms/input-text/InputText.spec.tsx +1 -1
- package/src/molecules/forms/input-text/InputText.stories.tsx +4 -4
- package/src/molecules/forms/input-text/InputText.tsx +38 -53
- package/src/molecules/forms/select/{Select.interfaces.ts → Select.interface.ts} +8 -10
- package/src/molecules/forms/select/Select.tsx +5 -3
- package/src/molecules/forms/select/all.ts +2 -1
- package/src/molecules/forms/select/components/ChoicesSelect.stories.tsx +8 -7
- package/src/molecules/forms/select/components/ChoicesSelect.tsx +9 -18
- package/src/molecules/forms/select/components/HtmlSelect.stories.tsx +7 -7
- package/src/molecules/forms/select/components/HtmlSelect.tsx +3 -2
- package/src/molecules/forms/select/components/ReactSelect.stories.tsx +10 -8
- package/src/molecules/forms/select/components/ReactSelect.tsx +1 -1
- package/src/molecules/forms/select/hooks/useOptions.ts +6 -2
- package/src/molecules/loader/Loader.spec.tsx +2 -2
- package/src/molecules/loader/Loader.stories.tsx +7 -4
- package/src/molecules/loader/Loader.tsx +16 -6
- package/src/molecules/modal/Modal.stories.tsx +1 -1
- package/src/molecules/pagination/Pagination.spec.tsx +11 -11
- package/src/molecules/pagination/Pagination.stories.tsx +32 -10
- package/src/molecules/pagination/Pagination.tsx +29 -26
- package/src/molecules/table/Table.stories.tsx +284 -101
- package/src/molecules/table/Table.tsx +91 -86
- package/src/molecules/table/all.ts +16 -0
- package/src/molecules/table/components/DefaultArrowSort.tsx +20 -4
- package/src/molecules/table/components/DefaultCell.tsx +10 -1
- package/src/molecules/table/components/DefaultCellFooter.tsx +16 -0
- package/src/molecules/table/components/DefaultCellHeader.tsx +33 -13
- package/src/molecules/table/components/DefaultCellOperations.tsx +31 -20
- package/src/molecules/table/components/DefaultFilter.tsx +42 -0
- package/src/molecules/table/components/DefaultOperationButton.tsx +19 -34
- package/src/molecules/table/filters/Filters.d.ts +31 -0
- package/src/molecules/table/filters/RangeFilter.tsx +43 -0
- package/src/molecules/table/filters/SelectFilter.tsx +47 -0
- package/src/molecules/table/filters/TextFieldFilter.tsx +36 -0
- package/src/molecules/table/hooks/useTable.tsx +76 -0
- package/src/molecules/table/hooks/useUniqValues.tsx +10 -0
- package/src/molecules/table/interfaces/extends.ts +18 -0
- package/src/molecules/table/utils/mapFormToColumns.tsx +69 -26
- package/src/molecules/tabs/Tab.tsx +106 -0
- package/src/molecules/tabs/TabList.tsx +37 -0
- package/src/molecules/tabs/TabPanel.tsx +37 -0
- package/src/molecules/tabs/Tabs.spec.tsx +126 -73
- package/src/molecules/tabs/Tabs.stories.tsx +298 -65
- package/src/molecules/tabs/Tabs.tsx +10 -81
- package/src/molecules/tabs/TabsBody.tsx +11 -0
- package/src/molecules/tabs/TabsLegacy.stories.tsx +103 -0
- package/src/molecules/tabs/TabsLegacy.tsx +86 -0
- package/src/molecules/tabs/all.ts +5 -0
- package/src/molecules/tabs/context/TabControl.tsx +166 -0
- package/src/molecules/tabs/hooks/tabControl.spec.tsx +388 -0
- package/src/molecules/tabs/hooks/tabControl.ts +52 -0
- package/src/organisms/__fixtures__/form-firstname.fixture.json +1 -0
- package/src/organisms/__fixtures__/form.fixture.json +1 -0
- package/src/organisms/form/Form.stories.tsx +104 -124
- package/src/organisms/form/access/FormAccess.schema.ts +1 -0
- package/src/organisms/form/access/FormAccess.stories.tsx +6 -4
- package/src/organisms/form/actions/FormAction.stories.tsx +426 -0
- package/src/organisms/form/{action → actions}/FormAction.tsx +2 -2
- package/src/organisms/form/builder/FormBuilder.stories.tsx +7 -4
- package/src/organisms/form/builder/FormEdit.reducer.spec.ts +136 -0
- package/src/organisms/form/builder/FormEdit.stories.tsx +16 -13
- package/src/organisms/form/builder/FormEdit.tsx +15 -7
- package/src/organisms/form/builder/FormEditCtas.tsx +10 -10
- package/src/organisms/form/builder/FormParameters.tsx +8 -4
- package/src/organisms/form/builder/all.ts +4 -0
- package/src/organisms/form/builder/useFormBuilder.ts +12 -7
- package/src/organisms/form/builder/useFormEdit.ts +3 -3
- package/src/organisms/form/exports/FormExport.stories.tsx +68 -0
- package/src/organisms/form/exports/FormExport.tsx +61 -0
- package/src/organisms/form/preview/FormPreview.stories.tsx +58 -0
- package/src/organisms/form/preview/FormPreview.tsx +23 -0
- package/src/organisms/form/settings/FormSettings.component.spec.tsx +3 -1
- package/src/organisms/form/settings/FormSettings.stories.tsx +2 -2
- package/src/organisms/form/settings/FormSettings.tsx +6 -6
- package/src/organisms/form/useForm.ts +2 -3
- package/src/organisms/modal/RemoveModal.stories.tsx +1 -1
- package/src/organisms/table/actions/ActionsTable.spec.tsx +7 -5
- package/src/organisms/table/actions/ActionsTable.stories.tsx +48 -45
- package/src/organisms/table/actions/ActionsTable.tsx +14 -18
- package/src/organisms/table/forms/FormsTable.stories.tsx +2 -0
- package/src/organisms/table/forms/FormsTable.tsx +53 -23
- package/src/organisms/table/forms/components/FormsCell.tsx +53 -0
- package/src/organisms/table/submissions/SubmissionsTable.stories.tsx +101 -57
- package/src/organisms/table/submissions/SubmissionsTable.tsx +12 -5
- package/src/organisms/views/FormViews.stories.tsx +221 -0
- package/src/organisms/views/FormViews.tsx +148 -0
- package/src/registries/components.ts +7 -1
- package/src/utils/iconClass.ts +1 -3
- package/vite.config.mts +2 -2
- package/dist/molecules/forms/select/Select.interfaces.js +0 -2
- package/dist/molecules/forms/select/Select.interfaces.js.map +0 -1
- package/dist/molecules/table/components/DefaultCells.d.ts +0 -4
- package/dist/molecules/table/components/DefaultCells.js +0 -23
- package/dist/molecules/table/components/DefaultCells.js.map +0 -1
- package/dist/molecules/table/components/DefaultRow.d.ts +0 -12
- package/dist/molecules/table/components/DefaultRow.js +0 -26
- package/dist/molecules/table/components/DefaultRow.js.map +0 -1
- package/dist/molecules/table/components/DragNDropContainer.d.ts +0 -4
- package/dist/molecules/table/components/DragNDropContainer.js +0 -10
- package/dist/molecules/table/components/DragNDropContainer.js.map +0 -1
- package/dist/molecules/table/filters/DefaultColumnFilter.d.ts +0 -10
- package/dist/molecules/table/filters/DefaultColumnFilter.js +0 -29
- package/dist/molecules/table/filters/DefaultColumnFilter.js.map +0 -1
- package/dist/molecules/table/filters/SelectColumnFilter.d.ts +0 -10
- package/dist/molecules/table/filters/SelectColumnFilter.js +0 -34
- package/dist/molecules/table/filters/SelectColumnFilter.js.map +0 -1
- package/dist/molecules/table/filters/SliderColumnFilter.d.ts +0 -9
- package/dist/molecules/table/filters/SliderColumnFilter.js +0 -27
- package/dist/molecules/table/filters/SliderColumnFilter.js.map +0 -1
- package/dist/molecules/table/hooks/useCustomTable.d.ts +0 -128
- package/dist/molecules/table/hooks/useCustomTable.js +0 -130
- package/dist/molecules/table/hooks/useCustomTable.js.map +0 -1
- package/dist/molecules/table/hooks/useDragnDropRow.d.ts +0 -272
- package/dist/molecules/table/hooks/useDragnDropRow.js +0 -40
- package/dist/molecules/table/hooks/useDragnDropRow.js.map +0 -1
- package/dist/molecules/table/hooks/useOperations.d.ts +0 -11
- package/dist/molecules/table/hooks/useOperations.js +0 -25
- package/dist/molecules/table/hooks/useOperations.js.map +0 -1
- package/dist/molecules/table/index.d.ts +0 -15
- package/dist/molecules/table/index.js +0 -35
- package/dist/molecules/table/index.js.map +0 -1
- package/dist/molecules/table/utils/getPageNumbers.js.map +0 -1
- package/dist/molecules/table/utils/swapElements.d.ts +0 -1
- package/dist/molecules/table/utils/swapElements.js +0 -5
- package/dist/molecules/table/utils/swapElements.js.map +0 -1
- package/dist/organisms/form/action/FormAction.js +0 -32
- package/dist/organisms/form/action/FormAction.js.map +0 -1
- package/dist/organisms/table/forms/components/FormCell.d.ts +0 -6
- package/dist/organisms/table/forms/components/FormCell.js +0 -50
- package/dist/organisms/table/forms/components/FormCell.js.map +0 -1
- package/dist/typings.d.js +0 -2
- package/dist/typings.d.js.map +0 -1
- package/src/molecules/forms/input-tags/InputTags.stories.tsx +0 -81
- package/src/molecules/table/components/DefaultCells.tsx +0 -30
- package/src/molecules/table/components/DefaultRow.tsx +0 -52
- package/src/molecules/table/components/DragNDropContainer.tsx +0 -7
- package/src/molecules/table/filters/DefaultColumnFilter.spec.tsx +0 -33
- package/src/molecules/table/filters/DefaultColumnFilter.tsx +0 -38
- package/src/molecules/table/filters/SelectColumnFilter.spec.tsx +0 -68
- package/src/molecules/table/filters/SelectColumnFilter.tsx +0 -51
- package/src/molecules/table/filters/SliderColumnFilter.tsx +0 -28
- package/src/molecules/table/hooks/useCustomTable.tsx +0 -268
- package/src/molecules/table/hooks/useDragnDropRow.ts +0 -80
- package/src/molecules/table/hooks/useOperations.tsx +0 -39
- package/src/molecules/table/index.ts +0 -15
- package/src/molecules/table/utils/swapElements.spec.ts +0 -7
- package/src/molecules/table/utils/swapElements.ts +0 -7
- package/src/organisms/form/action/FormAction.stories.tsx +0 -364
- package/src/organisms/table/forms/components/FormCell.tsx +0 -47
- package/src/typings.d.ts +0 -3
- package/tsconfig.app.json +0 -11
- package/tsconfig.json +0 -21
- package/tsconfig.node.json +0 -13
- package/tsconfig.spec.json +0 -14
- /package/dist/molecules/{table → pagination}/utils/getPageNumbers.d.ts +0 -0
- /package/dist/molecules/{table → pagination}/utils/getPageNumbers.js +0 -0
- /package/dist/organisms/form/{action → actions}/FormAction.d.ts +0 -0
- /package/src/molecules/{table → pagination}/utils/getPageNumbers.ts +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import "./all.js";
|
|
2
|
+
|
|
3
|
+
import { CSSProperties, ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
import { useI18n } from "../../hooks/useI18n.js";
|
|
6
|
+
import type { FormOptions } from "../../interfaces/index.js";
|
|
7
|
+
import { getComponent } from "../../registries/components.js";
|
|
8
|
+
import type { Tab as DefaultTab } from "./Tab.js";
|
|
9
|
+
import type { TabList as DefaultTabList } from "./TabList.js";
|
|
10
|
+
import type { TabPanel as DefaultTabPanel } from "./TabPanel.js";
|
|
11
|
+
import type { Tabs as DefaultTabs } from "./Tabs.js";
|
|
12
|
+
import type { TabsBody as DefaultTabsBody } from "./TabsBody.js";
|
|
13
|
+
|
|
14
|
+
export interface TabsItemProps extends Record<string, any> {
|
|
15
|
+
label?: string;
|
|
16
|
+
icon?: string;
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface TabsLegacyProps extends Record<string, any> {
|
|
21
|
+
AddButton?: any;
|
|
22
|
+
current?: TabsItemProps;
|
|
23
|
+
items?: TabsItemProps[];
|
|
24
|
+
style?: CSSProperties;
|
|
25
|
+
className?: string;
|
|
26
|
+
reverse?: boolean;
|
|
27
|
+
onClick?: (item: TabsItemProps) => void;
|
|
28
|
+
i18n?: FormOptions["i18n"];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function TabsLegacy({
|
|
32
|
+
style,
|
|
33
|
+
current,
|
|
34
|
+
items = [],
|
|
35
|
+
HeaderChildren,
|
|
36
|
+
AddButton,
|
|
37
|
+
className,
|
|
38
|
+
onClick,
|
|
39
|
+
reverse,
|
|
40
|
+
after,
|
|
41
|
+
...additionalProps
|
|
42
|
+
}: TabsLegacyProps) {
|
|
43
|
+
const Tab = getComponent<typeof DefaultTab>("Tab");
|
|
44
|
+
const TabsBody = getComponent<typeof DefaultTabsBody>("TabsBody");
|
|
45
|
+
const TabList = getComponent<typeof DefaultTabList>("TabList");
|
|
46
|
+
const TabPanel = getComponent<typeof DefaultTabPanel>("TabPanel");
|
|
47
|
+
const Tabs = getComponent<typeof DefaultTabs>("Tabs");
|
|
48
|
+
const tabs = items.filter((item) => item.label || item.icon);
|
|
49
|
+
const { t } = useI18n(additionalProps.i18n);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Tabs className={className} style={style}>
|
|
53
|
+
<div>
|
|
54
|
+
<TabList>
|
|
55
|
+
{tabs.map((item, index) => {
|
|
56
|
+
return (
|
|
57
|
+
<Tab
|
|
58
|
+
key={index}
|
|
59
|
+
onClick={() => {
|
|
60
|
+
onClick && onClick(item);
|
|
61
|
+
}}
|
|
62
|
+
icon={item.icon}
|
|
63
|
+
value={index}
|
|
64
|
+
className={reverse ? "-reverse" : ""}
|
|
65
|
+
after={after}
|
|
66
|
+
>
|
|
67
|
+
{t(item.label || "")}
|
|
68
|
+
</Tab>
|
|
69
|
+
);
|
|
70
|
+
})}
|
|
71
|
+
{AddButton && <AddButton {...additionalProps} current={current} />}
|
|
72
|
+
</TabList>
|
|
73
|
+
{HeaderChildren && <HeaderChildren {...additionalProps} current={current} />}
|
|
74
|
+
</div>
|
|
75
|
+
<TabsBody>
|
|
76
|
+
{tabs.map((item, index) => {
|
|
77
|
+
return (
|
|
78
|
+
<TabPanel key={index} value={index}>
|
|
79
|
+
{item.children || item.content}
|
|
80
|
+
</TabPanel>
|
|
81
|
+
);
|
|
82
|
+
})}
|
|
83
|
+
</TabsBody>
|
|
84
|
+
</Tabs>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, type Dispatch, type PropsWithChildren, type RefObject, useCallback, useId, useReducer } from "react";
|
|
4
|
+
|
|
5
|
+
type RefTab<T extends HTMLElement = HTMLElement> = RefObject<T>;
|
|
6
|
+
type RefTabs<T extends HTMLElement = HTMLElement> = Map<number, RefTab<T>>;
|
|
7
|
+
|
|
8
|
+
type TabsUpdateAction = {
|
|
9
|
+
type: "update";
|
|
10
|
+
payload: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type TabsRegisterAction<T extends HTMLElement = HTMLElement> = {
|
|
14
|
+
type: "register";
|
|
15
|
+
payload: { value: number; ref: RefObject<T> };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type TabsUnregisterAction = {
|
|
19
|
+
type: "unregister";
|
|
20
|
+
payload: { value: number };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type TabsAction<T extends HTMLElement = HTMLElement> =
|
|
24
|
+
| { type: "start" | "end" | "previous" | "next" }
|
|
25
|
+
| TabsUpdateAction
|
|
26
|
+
| TabsRegisterAction<T>
|
|
27
|
+
| TabsUnregisterAction;
|
|
28
|
+
|
|
29
|
+
interface TabsState<T extends HTMLElement = HTMLElement> {
|
|
30
|
+
uid: string;
|
|
31
|
+
value: number;
|
|
32
|
+
refs: RefTabs<T>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface TabControl<T extends HTMLElement = HTMLElement> extends TabsState<T> {
|
|
36
|
+
uid: string;
|
|
37
|
+
value: number;
|
|
38
|
+
refs: RefTabs<T>;
|
|
39
|
+
dispatch: Dispatch<TabsAction>;
|
|
40
|
+
register: (value: number, ref: RefTab<T>) => void;
|
|
41
|
+
unregister: (value: number) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function next(state: TabsState) {
|
|
45
|
+
const keys = [...state.refs.keys()];
|
|
46
|
+
const index = keys.findIndex((value) => value === state.value);
|
|
47
|
+
const nextIndex = (index + 1) % keys.length;
|
|
48
|
+
|
|
49
|
+
return { ...state, value: keys[nextIndex] };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function previous(state: TabsState) {
|
|
53
|
+
const keys = [...state.refs.keys()];
|
|
54
|
+
const index = keys.findIndex((value) => value === state.value);
|
|
55
|
+
const previousIndex = (index - 1 + keys.length) % keys.length;
|
|
56
|
+
|
|
57
|
+
return { ...state, value: keys[previousIndex] };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function start(state: TabsState) {
|
|
61
|
+
const keys = [...state.refs.keys()];
|
|
62
|
+
const firstIndex = keys[0];
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
...state,
|
|
66
|
+
value: firstIndex
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function end(state: TabsState) {
|
|
71
|
+
const keys = [...state.refs.keys()];
|
|
72
|
+
const lastIndex = keys[keys.length - 1];
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
...state,
|
|
76
|
+
value: lastIndex
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function unregister(state: TabsState, action: TabsUnregisterAction) {
|
|
81
|
+
const deletedRefs = new Map(state.refs);
|
|
82
|
+
deletedRefs.delete(action.payload.value);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
...state,
|
|
86
|
+
refs: deletedRefs
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function register(state: TabsState, action: TabsRegisterAction) {
|
|
91
|
+
return {
|
|
92
|
+
...state,
|
|
93
|
+
refs: new Map(state.refs).set(action.payload.value, action.payload.ref)
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function update(state: TabsState, action: TabsUpdateAction) {
|
|
98
|
+
return { ...state, value: action.payload };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const actions = {
|
|
102
|
+
next,
|
|
103
|
+
previous,
|
|
104
|
+
start,
|
|
105
|
+
end,
|
|
106
|
+
register,
|
|
107
|
+
unregister,
|
|
108
|
+
update
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function tabsReducer(state: TabsState, action: TabsAction): TabsState {
|
|
112
|
+
if (action.type in actions) {
|
|
113
|
+
const actionFunction = actions[action.type as keyof typeof actions] as (state: TabsState, action: TabsAction) => TabsState;
|
|
114
|
+
|
|
115
|
+
return actionFunction(state, action);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return state;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const TabControlContext = createContext<TabControl>({
|
|
122
|
+
uid: "",
|
|
123
|
+
value: 0,
|
|
124
|
+
refs: new Map(),
|
|
125
|
+
dispatch: () => {
|
|
126
|
+
console.warn("Tab Controller Context dispatch used outside of Provider");
|
|
127
|
+
},
|
|
128
|
+
register: () => {
|
|
129
|
+
console.warn("Tab Controller Context register used outside of Provider");
|
|
130
|
+
},
|
|
131
|
+
unregister: () => {
|
|
132
|
+
console.warn("Tab Controller Context unregister used outside of Provider");
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
TabControlContext.displayName = "TabControlContext";
|
|
137
|
+
|
|
138
|
+
export interface TabsProviderProps {
|
|
139
|
+
selected?: number;
|
|
140
|
+
/**
|
|
141
|
+
* The selected tab value
|
|
142
|
+
* @deprecated Min props as no effect on the Tabs component and will be removed in future versions
|
|
143
|
+
*/
|
|
144
|
+
min?: number;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The selected tab value
|
|
148
|
+
* @deprecated Max props as no effect on the Tabs component and will be removed in future versions
|
|
149
|
+
*/
|
|
150
|
+
max?: number;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function TabsProvider({ selected = 0, children }: PropsWithChildren<TabsProviderProps>) {
|
|
154
|
+
const uid = useId();
|
|
155
|
+
const [state, dispatch] = useReducer(tabsReducer, { uid, value: selected, refs: new Map() });
|
|
156
|
+
|
|
157
|
+
const register = useCallback(<T extends HTMLElement>(value: number, ref: RefTab<T>) => {
|
|
158
|
+
dispatch({ type: "register", payload: { value, ref } });
|
|
159
|
+
}, []);
|
|
160
|
+
|
|
161
|
+
const unregister = useCallback((value: number) => {
|
|
162
|
+
dispatch({ type: "unregister", payload: { value } });
|
|
163
|
+
}, []);
|
|
164
|
+
|
|
165
|
+
return <TabControlContext.Provider value={{ ...state, dispatch, register, unregister }}>{children}</TabControlContext.Provider>;
|
|
166
|
+
}
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { act, render, renderHook, screen } from "@testing-library/react";
|
|
2
|
+
import { userEvent } from "@testing-library/user-event";
|
|
3
|
+
import { type PropsWithChildren, useContext, useRef } from "react";
|
|
4
|
+
|
|
5
|
+
import { TabControlContext, TabsProvider } from "../context/TabControl";
|
|
6
|
+
import { Tab } from "../Tab.js";
|
|
7
|
+
import { useActiveTab, useRegisterTabControl, useTabControls, useTabDispatch } from "./tabControl";
|
|
8
|
+
|
|
9
|
+
interface Config {
|
|
10
|
+
selected: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const createWrapper = ({ selected }: Config = { selected: 3 }) => {
|
|
14
|
+
return ({ children }: PropsWithChildren) => {
|
|
15
|
+
return <TabsProvider selected={selected}>{children}</TabsProvider>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe("tab control hooks", () => {
|
|
20
|
+
beforeAll(() => {
|
|
21
|
+
vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterAll(() => {
|
|
25
|
+
vi.mocked(console.warn).mockReset();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("useActiveTab()", () => {
|
|
29
|
+
it("returns the current tab value", () => {
|
|
30
|
+
const { result } = renderHook(useActiveTab, { wrapper: createWrapper() });
|
|
31
|
+
|
|
32
|
+
expect(result.current).toBe(3);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("useRegisterTabControl()", () => {
|
|
37
|
+
it("returns the dispatch function", () => {
|
|
38
|
+
const { result } = renderHook(() => useRegisterTabControl({ value: 0, ref: useRef(null) }), {
|
|
39
|
+
wrapper: createWrapper()
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(result.current).toEqual(expect.any(Function));
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("register and unregister", () => {
|
|
46
|
+
const { result, unmount } = renderHook(() => {
|
|
47
|
+
const div = document.createElement("div");
|
|
48
|
+
|
|
49
|
+
return useRegisterTabControl({ value: 0, ref: useRef<HTMLDivElement>(div) });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
unmount();
|
|
53
|
+
|
|
54
|
+
expect(result.current).toEqual(expect.any(Function));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("without provider", () => {
|
|
58
|
+
it("log a warning", async () => {
|
|
59
|
+
const { result, unmount } = renderHook(() => {
|
|
60
|
+
const div = document.createElement("div");
|
|
61
|
+
return useRegisterTabControl({ value: 0, ref: useRef<HTMLDivElement>(div) });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
await act(() => result.current({ type: "update", payload: 4 }));
|
|
65
|
+
|
|
66
|
+
unmount();
|
|
67
|
+
|
|
68
|
+
expect(console.warn).toHaveBeenCalledWith("Tab Controller Context dispatch used outside of Provider");
|
|
69
|
+
expect(console.warn).toHaveBeenCalledWith("Tab Controller Context register used outside of Provider");
|
|
70
|
+
expect(console.warn).toHaveBeenCalledWith("Tab Controller Context unregister used outside of Provider");
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("useTabDispatch()", () => {
|
|
76
|
+
it("returns the dispatch function", () => {
|
|
77
|
+
const { result } = renderHook(useTabDispatch, {
|
|
78
|
+
wrapper: createWrapper()
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
expect(result.current).toEqual(expect.any(Function));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("without provider", () => {
|
|
85
|
+
it("log a warning", async () => {
|
|
86
|
+
const { result } = renderHook(useTabDispatch);
|
|
87
|
+
|
|
88
|
+
await act(() => result.current({ type: "update", payload: 4 }));
|
|
89
|
+
|
|
90
|
+
expect(console.warn).toHaveBeenCalledWith("Tab Controller Context dispatch used outside of Provider");
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("dispatch update", () => {
|
|
95
|
+
it("update the state", async () => {
|
|
96
|
+
const Test = () => {
|
|
97
|
+
const dispatch = useTabDispatch();
|
|
98
|
+
const tab = useActiveTab();
|
|
99
|
+
|
|
100
|
+
const update = () => {
|
|
101
|
+
dispatch({ type: "update", payload: 4 });
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<>
|
|
106
|
+
<button onClick={update}>update</button>
|
|
107
|
+
<output name='result'>{tab}</output>
|
|
108
|
+
</>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
render(<Test />, { wrapper: createWrapper() });
|
|
113
|
+
|
|
114
|
+
const button = screen.getByRole("button");
|
|
115
|
+
const output = screen.getByRole("status");
|
|
116
|
+
|
|
117
|
+
expect(output).toHaveValue("3");
|
|
118
|
+
|
|
119
|
+
await userEvent.click(button);
|
|
120
|
+
|
|
121
|
+
expect(output).toHaveValue("4");
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe("dispatch end", () => {
|
|
126
|
+
it("update the state", async () => {
|
|
127
|
+
const Test = () => {
|
|
128
|
+
const dispatch = useTabDispatch();
|
|
129
|
+
const tab = useActiveTab();
|
|
130
|
+
|
|
131
|
+
const end = () => {
|
|
132
|
+
dispatch({ type: "end" });
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<>
|
|
137
|
+
<Tab value={0}>Label 0</Tab>
|
|
138
|
+
<Tab value={3}>Label 3</Tab>
|
|
139
|
+
<Tab value={5}>Label 5</Tab>
|
|
140
|
+
|
|
141
|
+
<button onClick={end}>end</button>
|
|
142
|
+
|
|
143
|
+
<output name='result'>{tab}</output>
|
|
144
|
+
</>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
render(<Test />, { wrapper: createWrapper() });
|
|
149
|
+
|
|
150
|
+
const button = screen.getByRole("button");
|
|
151
|
+
const output = screen.getByRole("status");
|
|
152
|
+
|
|
153
|
+
expect(output).toHaveValue("3");
|
|
154
|
+
|
|
155
|
+
await userEvent.click(button);
|
|
156
|
+
expect(output).toHaveValue("5");
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("dispatch start", () => {
|
|
161
|
+
it("update the state", async () => {
|
|
162
|
+
const Test = () => {
|
|
163
|
+
const dispatch = useTabDispatch();
|
|
164
|
+
const tab = useActiveTab();
|
|
165
|
+
|
|
166
|
+
const start = () => {
|
|
167
|
+
dispatch({ type: "start" });
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<>
|
|
172
|
+
<Tab value={0}>Label 0</Tab>
|
|
173
|
+
<Tab value={3}>Label 3</Tab>
|
|
174
|
+
<Tab value={5}>Label 5</Tab>
|
|
175
|
+
<button onClick={start}>start</button>
|
|
176
|
+
<output name='result'>{tab}</output>
|
|
177
|
+
</>
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
render(<Test />, { wrapper: createWrapper() });
|
|
182
|
+
|
|
183
|
+
const button = screen.getByRole("button");
|
|
184
|
+
const output = screen.getByRole("status");
|
|
185
|
+
|
|
186
|
+
expect(output).toHaveValue("3");
|
|
187
|
+
|
|
188
|
+
await userEvent.click(button);
|
|
189
|
+
|
|
190
|
+
expect(output).toHaveValue("0");
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("dispatch next", () => {
|
|
195
|
+
it("update the state", async () => {
|
|
196
|
+
const Test = () => {
|
|
197
|
+
const dispatch = useTabDispatch();
|
|
198
|
+
const tab = useActiveTab();
|
|
199
|
+
|
|
200
|
+
const next = () => {
|
|
201
|
+
dispatch({ type: "next" });
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<>
|
|
206
|
+
<Tab value={0}>Label 0</Tab>
|
|
207
|
+
<Tab value={3}>Label 3</Tab>
|
|
208
|
+
<Tab value={4}>Label 4</Tab>
|
|
209
|
+
<Tab value={5}>Label 5</Tab>
|
|
210
|
+
<button onClick={next}>next</button>
|
|
211
|
+
<output name='result'>{tab}</output>
|
|
212
|
+
</>
|
|
213
|
+
);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
render(<Test />, { wrapper: createWrapper() });
|
|
217
|
+
|
|
218
|
+
const button = screen.getByRole("button");
|
|
219
|
+
const output = screen.getByRole("status");
|
|
220
|
+
|
|
221
|
+
expect(output).toHaveValue("3");
|
|
222
|
+
|
|
223
|
+
await userEvent.click(button);
|
|
224
|
+
|
|
225
|
+
expect(output).toHaveValue("4");
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe("when current tab is last one", () => {
|
|
229
|
+
it("loop to the first tab", async () => {
|
|
230
|
+
const Test = () => {
|
|
231
|
+
const dispatch = useTabDispatch();
|
|
232
|
+
const tab = useActiveTab();
|
|
233
|
+
|
|
234
|
+
const next = () => {
|
|
235
|
+
dispatch({ type: "next" });
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
return (
|
|
239
|
+
<>
|
|
240
|
+
<Tab value={0}>Label 0</Tab>
|
|
241
|
+
<Tab value={3}>Label 3</Tab>
|
|
242
|
+
<Tab value={4}>Label 4</Tab>
|
|
243
|
+
<Tab value={5}>Label 5</Tab>
|
|
244
|
+
<button onClick={next}>next</button>
|
|
245
|
+
<output name='result'>{tab}</output>
|
|
246
|
+
</>
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
render(<Test />, { wrapper: createWrapper({ selected: 5 }) });
|
|
251
|
+
|
|
252
|
+
const button = screen.getByRole("button");
|
|
253
|
+
const output = screen.getByRole("status");
|
|
254
|
+
|
|
255
|
+
expect(output).toHaveValue("5");
|
|
256
|
+
|
|
257
|
+
await userEvent.click(button);
|
|
258
|
+
|
|
259
|
+
expect(output).toHaveValue("0");
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe("dispatch previous", () => {
|
|
265
|
+
it("update the state", async () => {
|
|
266
|
+
const Test = () => {
|
|
267
|
+
const dispatch = useTabDispatch();
|
|
268
|
+
const tab = useActiveTab();
|
|
269
|
+
|
|
270
|
+
const previous = () => {
|
|
271
|
+
dispatch({ type: "previous" });
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
return (
|
|
275
|
+
<>
|
|
276
|
+
<Tab value={0}>Label 0</Tab>
|
|
277
|
+
<Tab value={2}>Label 2</Tab>
|
|
278
|
+
<Tab value={3}>Label 3</Tab>
|
|
279
|
+
<Tab value={4}>Label 4</Tab>
|
|
280
|
+
<Tab value={5}>Label 5</Tab>
|
|
281
|
+
<button onClick={previous}>previous</button>
|
|
282
|
+
<output name='result'>{tab}</output>
|
|
283
|
+
</>
|
|
284
|
+
);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
render(<Test />, { wrapper: createWrapper() });
|
|
288
|
+
|
|
289
|
+
const button = screen.getByRole("button");
|
|
290
|
+
const output = screen.getByRole("status");
|
|
291
|
+
|
|
292
|
+
expect(output).toHaveValue("3");
|
|
293
|
+
|
|
294
|
+
await userEvent.click(button);
|
|
295
|
+
|
|
296
|
+
expect(output).toHaveValue("2");
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe("when current tab is first one", () => {
|
|
300
|
+
it("loop to the last tab", async () => {
|
|
301
|
+
const Test = () => {
|
|
302
|
+
const dispatch = useTabDispatch();
|
|
303
|
+
const tab = useActiveTab();
|
|
304
|
+
|
|
305
|
+
const previous = () => {
|
|
306
|
+
dispatch({ type: "previous" });
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
return (
|
|
310
|
+
<>
|
|
311
|
+
<Tab value={0}>Label 0</Tab>
|
|
312
|
+
<Tab value={2}>Label 2</Tab>
|
|
313
|
+
<Tab value={3}>Label 3</Tab>
|
|
314
|
+
<Tab value={4}>Label 4</Tab>
|
|
315
|
+
<Tab value={5}>Label 5</Tab>
|
|
316
|
+
<button onClick={previous}>previous</button>
|
|
317
|
+
<output name='result'>{tab}</output>
|
|
318
|
+
</>
|
|
319
|
+
);
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
render(<Test />, { wrapper: createWrapper({ selected: 0 }) });
|
|
323
|
+
|
|
324
|
+
const button = screen.getByRole("button");
|
|
325
|
+
const output = screen.getByRole("status");
|
|
326
|
+
|
|
327
|
+
expect(output).toHaveValue("0");
|
|
328
|
+
|
|
329
|
+
await userEvent.click(button);
|
|
330
|
+
|
|
331
|
+
expect(output).toHaveValue("5");
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
describe("useTabControl()", () => {
|
|
338
|
+
it("retuns the elements registered map", () => {
|
|
339
|
+
const Test = () => {
|
|
340
|
+
const div = document.createElement("div");
|
|
341
|
+
const ref = useRef(div);
|
|
342
|
+
|
|
343
|
+
useRegisterTabControl({ value: 0, ref });
|
|
344
|
+
|
|
345
|
+
const controls = useTabControls();
|
|
346
|
+
|
|
347
|
+
return <output name='result'>{controls.size}</output>;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
render(<Test />, { wrapper: createWrapper() });
|
|
351
|
+
|
|
352
|
+
const output = screen.getByRole("status");
|
|
353
|
+
|
|
354
|
+
expect(output).toHaveValue("1");
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("allow unregister", async () => {
|
|
358
|
+
const Test = () => {
|
|
359
|
+
const div = document.createElement("div");
|
|
360
|
+
const ref = useRef(div);
|
|
361
|
+
|
|
362
|
+
const { register, unregister } = useContext(TabControlContext);
|
|
363
|
+
const controls = useTabControls();
|
|
364
|
+
|
|
365
|
+
return (
|
|
366
|
+
<>
|
|
367
|
+
<button onClick={() => register(0, ref)}>REGISTER</button>
|
|
368
|
+
<button onClick={() => unregister(0)}>UNREGISTER</button>
|
|
369
|
+
<output name='result'>{controls.size}</output>
|
|
370
|
+
</>
|
|
371
|
+
);
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
render(<Test />, { wrapper: createWrapper() });
|
|
375
|
+
|
|
376
|
+
const register = screen.getByRole("button", { name: "REGISTER" });
|
|
377
|
+
const unregister = screen.getByRole("button", { name: "UNREGISTER" });
|
|
378
|
+
|
|
379
|
+
await userEvent.click(register);
|
|
380
|
+
|
|
381
|
+
expect(screen.getByRole("status")).toHaveValue("1");
|
|
382
|
+
|
|
383
|
+
await userEvent.click(unregister);
|
|
384
|
+
|
|
385
|
+
expect(screen.getByRole("status")).toHaveValue("0");
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type RefObject, useContext, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
import { TabControlContext } from "../context/TabControl";
|
|
4
|
+
|
|
5
|
+
export const useActiveTab = () => {
|
|
6
|
+
const { value } = useContext(TabControlContext);
|
|
7
|
+
|
|
8
|
+
return value;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const useTabDispatch = () => {
|
|
12
|
+
const { dispatch } = useContext(TabControlContext);
|
|
13
|
+
|
|
14
|
+
return dispatch;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const useTabsUid = () => {
|
|
18
|
+
const { uid } = useContext(TabControlContext);
|
|
19
|
+
|
|
20
|
+
return uid;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
interface Props<T extends HTMLElement> {
|
|
24
|
+
value: number;
|
|
25
|
+
ref: RefObject<T>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useRegisterTabControl<T extends HTMLElement>({ value, ref }: Props<T>) {
|
|
29
|
+
const { dispatch, register, unregister } = useContext(TabControlContext);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
register(value, ref);
|
|
33
|
+
|
|
34
|
+
return () => {
|
|
35
|
+
unregister(value);
|
|
36
|
+
};
|
|
37
|
+
}, [value, ref, register, unregister]);
|
|
38
|
+
|
|
39
|
+
return dispatch;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const useTabControls = () => {
|
|
43
|
+
const { refs } = useContext(TabControlContext);
|
|
44
|
+
|
|
45
|
+
return refs;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const useActiveTabControl = () => {
|
|
49
|
+
const { value, refs } = useContext(TabControlContext);
|
|
50
|
+
|
|
51
|
+
return [value, refs.get(value)] as const;
|
|
52
|
+
};
|