@tsed/react-formio 3.0.0-alpha.9 → 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 +1204 -1101
- package/dist/chunks/react-select-animated.esm.js.map +1 -1
- 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.js +5 -5
- package/dist/molecules/forms/form-control/FormControl.js.map +1 -1
- package/dist/molecules/forms/input-tags/InputTags.js +14 -14
- package/dist/molecules/forms/input-tags/InputTags.js.map +1 -1
- package/dist/molecules/forms/input-tags/components/ChoicesTags.d.ts +27 -27
- package/dist/molecules/forms/input-tags/components/ChoicesTags.js +32 -32
- package/dist/molecules/forms/input-tags/components/ChoicesTags.js.map +1 -1
- package/dist/molecules/forms/input-tags/components/ReactTags.js +289 -300
- package/dist/molecules/forms/input-tags/components/ReactTags.js.map +1 -1
- package/dist/molecules/forms/input-text/InputText.js +3 -3
- package/dist/molecules/forms/input-text/InputText.js.map +1 -1
- package/dist/molecules/forms/select/Select.interface.d.ts +5 -2
- package/dist/molecules/forms/select/Select.js.map +1 -1
- package/dist/molecules/forms/select/components/ChoicesSelect.js +70 -72
- package/dist/molecules/forms/select/components/ChoicesSelect.js.map +1 -1
- package/dist/molecules/forms/select/components/HtmlSelect.js +8 -8
- package/dist/molecules/forms/select/components/HtmlSelect.js.map +1 -1
- package/dist/molecules/forms/select/components/ReactSelect.js +13 -14
- 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 +1 -1
- 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/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 +6 -3
- package/dist/organisms/form/builder/FormEdit.js +45 -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.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 +1 -1
- 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 +5 -2
- package/src/molecules/forms/form-control/FormControl.stories.tsx +1 -1
- package/src/molecules/forms/input-tags/InputTags.tsx +1 -1
- package/src/molecules/forms/input-tags/components/ChoicesTags.stories.tsx +1 -1
- package/src/molecules/forms/input-tags/components/ChoicesTags.tsx +4 -4
- package/src/molecules/forms/input-tags/components/ReactTags.stories.tsx +1 -1
- package/src/molecules/forms/input-text/InputText.stories.tsx +2 -2
- package/src/molecules/forms/select/Select.interface.ts +5 -2
- package/src/molecules/forms/select/components/ChoicesSelect.stories.tsx +2 -2
- package/src/molecules/forms/select/components/ChoicesSelect.tsx +2 -2
- package/src/molecules/forms/select/components/HtmlSelect.stories.tsx +2 -2
- package/src/molecules/forms/select/components/ReactSelect.stories.tsx +2 -2
- package/src/molecules/forms/select/hooks/useOptions.ts +5 -1
- 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 +28 -25
- 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 +11 -7
- package/src/organisms/form/builder/FormEdit.tsx +12 -6
- package/src/organisms/form/builder/FormEditCtas.tsx +10 -10
- package/src/organisms/form/builder/useFormBuilder.ts +12 -7
- package/src/organisms/form/builder/useFormEdit.ts +1 -1
- 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 +13 -17
- 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/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/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,36 @@
|
|
|
1
|
+
import { getComponent, registerComponent } from "../../../registries/components";
|
|
2
|
+
import type { InputText as DefaultInputText } from "../../forms/input-text/InputText";
|
|
3
|
+
import type { FilterProps } from "../components/DefaultFilter";
|
|
4
|
+
import { useUniqValues } from "../hooks/useUniqValues";
|
|
5
|
+
import { FilterTextOptions } from "./Filters";
|
|
6
|
+
|
|
7
|
+
export function TextFieldFilter<Data = any>({ header, options }: FilterProps<Data, FilterTextOptions>) {
|
|
8
|
+
const InputText = getComponent<typeof DefaultInputText>("InputText");
|
|
9
|
+
const columnFilterValue = header.column.getFilterValue();
|
|
10
|
+
const uniqValues = useUniqValues<Data>({ header, filterVariant: "text" });
|
|
11
|
+
const datalistId = `data_list_${header.column.id}`;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
{!options.disableDatalist && (
|
|
16
|
+
<datalist id={datalistId}>
|
|
17
|
+
{uniqValues.map((value: any) => (
|
|
18
|
+
<option value={value} key={value} />
|
|
19
|
+
))}
|
|
20
|
+
</datalist>
|
|
21
|
+
)}
|
|
22
|
+
<InputText<string>
|
|
23
|
+
size='small'
|
|
24
|
+
placeholder={`Filter by ${header.column.columnDef.header}`}
|
|
25
|
+
{...options}
|
|
26
|
+
name={`filter_${header.column.id}`}
|
|
27
|
+
data-testid={`filter_${header.column.id}`}
|
|
28
|
+
value={(columnFilterValue ?? "") as string}
|
|
29
|
+
list={datalistId}
|
|
30
|
+
onChange={(_, value) => header.column.setFilterValue(value)}
|
|
31
|
+
/>
|
|
32
|
+
</>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
registerComponent("Filter.text", TextFieldFilter);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ColumnDef,
|
|
3
|
+
getCoreRowModel,
|
|
4
|
+
getFacetedRowModel,
|
|
5
|
+
getFacetedUniqueValues,
|
|
6
|
+
getFilteredRowModel,
|
|
7
|
+
getPaginationRowModel,
|
|
8
|
+
getSortedRowModel,
|
|
9
|
+
type TableOptions,
|
|
10
|
+
type TableState,
|
|
11
|
+
useReactTable
|
|
12
|
+
} from "@tanstack/react-table";
|
|
13
|
+
import { useEffect } from "react";
|
|
14
|
+
|
|
15
|
+
import { useI18n } from "../../../hooks/useI18n.js";
|
|
16
|
+
import { type FormOptions, type JSON, Operation } from "../../../interfaces";
|
|
17
|
+
import { getComponent } from "../../../registries/components";
|
|
18
|
+
import type { DefaultCellOperations } from "../components/DefaultCellOperations";
|
|
19
|
+
|
|
20
|
+
export interface UseTableProps<Data extends { [key: string]: JSON } = { [key: string]: JSON }>
|
|
21
|
+
extends Omit<TableOptions<Data>, "getCoreRowModel" | "onClick"> {
|
|
22
|
+
operations: Operation<Data>[];
|
|
23
|
+
metadata?: Record<string, unknown>;
|
|
24
|
+
i18n?: FormOptions["i18n"];
|
|
25
|
+
onClick?: (data: Data, operation: Operation<Data>) => void;
|
|
26
|
+
manualFaceted?: boolean;
|
|
27
|
+
onChange?: (query: TableState) => void;
|
|
28
|
+
pageSizes?: number[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useTable<Data extends { [key: string]: JSON } = { [key: string]: JSON }>(props: UseTableProps<Data>) {
|
|
32
|
+
const Operations = getComponent<typeof DefaultCellOperations<Data>>("CellOperations");
|
|
33
|
+
const { t } = useI18n(props.i18n);
|
|
34
|
+
|
|
35
|
+
// const [pagination, setPagination] = useState({
|
|
36
|
+
// pageIndex: 0, //initial page index
|
|
37
|
+
// pageSize: 10 //default page size
|
|
38
|
+
// });
|
|
39
|
+
|
|
40
|
+
const operations = props.operations.length
|
|
41
|
+
? ([
|
|
42
|
+
{
|
|
43
|
+
id: "operations",
|
|
44
|
+
header: t("Operations"),
|
|
45
|
+
cell: (info) => (
|
|
46
|
+
<Operations info={info} operations={props.operations} metadata={props.metadata} onClick={props.onClick} i18n={t} />
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
] satisfies ColumnDef<Data>[])
|
|
50
|
+
: [];
|
|
51
|
+
|
|
52
|
+
const tableInstance = useReactTable({
|
|
53
|
+
...props,
|
|
54
|
+
columns: [...props.columns, ...operations],
|
|
55
|
+
getCoreRowModel: getCoreRowModel(),
|
|
56
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
57
|
+
getFilteredRowModel: !props.manualFiltering ? getFilteredRowModel() : undefined,
|
|
58
|
+
getSortedRowModel: !props.manualSorting ? getSortedRowModel() : undefined,
|
|
59
|
+
getFacetedRowModel: !props.manualFaceted ? getFacetedRowModel() : undefined, // client-side faceting
|
|
60
|
+
getFacetedUniqueValues: !props.manualFaceted ? getFacetedUniqueValues() : undefined // generate unique values for select filter/autocomplete
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const { columnFilters, sorting, pagination, columnOrder, columnPinning, columnSizing, columnSizingInfo, columnVisibility, globalFilter } =
|
|
64
|
+
tableInstance.getState();
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (props.onChange) {
|
|
68
|
+
props.onChange(tableInstance.getState());
|
|
69
|
+
}
|
|
70
|
+
}, [columnFilters, sorting, pagination, columnOrder, columnPinning, columnSizing, columnSizingInfo, columnVisibility, globalFilter]);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
i18n: t,
|
|
74
|
+
tableInstance
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Header } from "@tanstack/react-table";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
|
|
4
|
+
export function useUniqValues<Data = any>({ header, filterVariant }: { header: Header<Data, unknown>; filterVariant: string }) {
|
|
5
|
+
return useMemo(
|
|
6
|
+
() => (filterVariant === "range" ? [] : Array.from(header.column.getFacetedUniqueValues().keys()).flat().sort().slice(0, 5000)),
|
|
7
|
+
|
|
8
|
+
[header.column, filterVariant]
|
|
9
|
+
);
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RowData } from "@tanstack/react-table";
|
|
2
|
+
import { TdHTMLAttributes } from "react";
|
|
3
|
+
|
|
4
|
+
import { FilterOptions } from "../filters/Filters";
|
|
5
|
+
|
|
6
|
+
declare module "@tanstack/react-table" {
|
|
7
|
+
//allows us to define custom properties for our columns
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
+
interface ColumnMeta<TData extends RowData, TValue> {
|
|
10
|
+
filter?: FilterOptions;
|
|
11
|
+
sort?: string;
|
|
12
|
+
cellProps?: TdHTMLAttributes<HTMLTableCellElement>;
|
|
13
|
+
/**
|
|
14
|
+
* Hide the cell
|
|
15
|
+
*/
|
|
16
|
+
hidden?: boolean;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,32 +1,75 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../interfaces/extends";
|
|
2
|
+
|
|
3
|
+
import { Components } from "@formio/js";
|
|
4
|
+
import { ColumnDef, ColumnDefResolved, createColumnHelper } from "@tanstack/react-table";
|
|
5
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
6
|
+
import get from "lodash/get";
|
|
2
7
|
|
|
3
8
|
import type { ComponentType, FormType } from "../../../interfaces";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (component.type === "
|
|
23
|
-
(
|
|
24
|
-
(column as any).choices = component.data.values;
|
|
9
|
+
import { getComponent } from "../../../registries/components";
|
|
10
|
+
import type { DefaultCell } from "../components/DefaultCell";
|
|
11
|
+
import type { FilterVariants } from "../filters/Filters.js";
|
|
12
|
+
|
|
13
|
+
const MAP_TYPES: Record<string, FilterVariants> = {
|
|
14
|
+
number: "range",
|
|
15
|
+
currency: "range",
|
|
16
|
+
checkbox: "boolean"
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function mapFormToColumns<Data = any>(form: FormType, columns: ColumnDefResolved<Data, any>[] = []): ColumnDef<Data, any>[] {
|
|
20
|
+
const columnHelper = createColumnHelper<Data>();
|
|
21
|
+
const columnsToKeep = cloneDeep(columns);
|
|
22
|
+
|
|
23
|
+
const Cell = getComponent<typeof DefaultCell>("Cell");
|
|
24
|
+
|
|
25
|
+
const columnsFromComponents = form.components
|
|
26
|
+
.flatMap((component) => {
|
|
27
|
+
if (component.type === "tabs") {
|
|
28
|
+
return component.components?.flatMap((subComponent: ComponentType) => subComponent.components);
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
31
|
+
return [component];
|
|
32
|
+
})
|
|
33
|
+
.filter((component) => component?.tableView)
|
|
34
|
+
.map((c) => {
|
|
35
|
+
const component = c as ComponentType;
|
|
36
|
+
const cmp: any = Components.create(component, {}, null);
|
|
37
|
+
|
|
38
|
+
const columnIndex = columnsToKeep.findIndex(({ accessorKey }) => {
|
|
39
|
+
return accessorKey === `data.${component.key}`;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
let column = columnsToKeep[columnIndex];
|
|
43
|
+
|
|
44
|
+
if (column) {
|
|
45
|
+
columnsToKeep.splice(columnIndex, 1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return columnHelper.accessor(`data.${component.key}` as any, {
|
|
49
|
+
header: (component.label || component.title || component.key)?.replace(/:/, ""),
|
|
50
|
+
cell: (info) => {
|
|
51
|
+
return <Cell value={info.getValue() as Data} render={(value: Data) => cmp.asString(value)} />;
|
|
52
|
+
},
|
|
53
|
+
meta: {
|
|
54
|
+
filter: { variant: MAP_TYPES[component.type!] || "text" },
|
|
55
|
+
...(column?.meta || {})
|
|
56
|
+
},
|
|
57
|
+
...(column || {})
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const mergedColumns = columnsFromComponents.concat(columnsToKeep as any[]).map((column, index) => ({
|
|
62
|
+
...column,
|
|
63
|
+
meta: {
|
|
64
|
+
...(column.meta || {}),
|
|
65
|
+
order: get(column, "meta.order", index * 10)
|
|
66
|
+
},
|
|
67
|
+
cell:
|
|
68
|
+
column.cell ||
|
|
69
|
+
((info) => {
|
|
70
|
+
return <Cell value={info.getValue() as Data} render={(value: Data) => value} />;
|
|
71
|
+
})
|
|
72
|
+
}));
|
|
30
73
|
|
|
31
|
-
return
|
|
74
|
+
return mergedColumns.sort((a, b) => (a.meta.order > b.meta.order ? 1 : -1)) as ColumnDef<Data, any>[];
|
|
32
75
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import classnames from "classnames";
|
|
2
|
+
import { PropsWithChildren, useCallback, useEffect, useRef } from "react";
|
|
3
|
+
|
|
4
|
+
import { useKeyboardControls } from "../../hooks/useKeyboardControls.js";
|
|
5
|
+
import { registerComponent } from "../../registries/components.js";
|
|
6
|
+
import { iconClass } from "../../utils/iconClass.js";
|
|
7
|
+
import { useActiveTab, useRegisterTabControl, useTabsUid } from "./hooks/tabControl.js";
|
|
8
|
+
|
|
9
|
+
export interface TabProps {
|
|
10
|
+
icon?: string;
|
|
11
|
+
isActive?: boolean;
|
|
12
|
+
className?: string;
|
|
13
|
+
after?: React.ReactNode;
|
|
14
|
+
value: number;
|
|
15
|
+
/**
|
|
16
|
+
* on tab select handler
|
|
17
|
+
*/
|
|
18
|
+
onClick?: (value: number) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Tab({ onClick, icon, value, children, className, after }: PropsWithChildren<TabProps>) {
|
|
22
|
+
const uid = useTabsUid();
|
|
23
|
+
const ref = useRef<HTMLButtonElement>(null);
|
|
24
|
+
const activeTab = useActiveTab();
|
|
25
|
+
const dispatch = useRegisterTabControl({ value, ref });
|
|
26
|
+
const previousActiveTab = useRef(activeTab);
|
|
27
|
+
|
|
28
|
+
const isActive = useRef(activeTab === value);
|
|
29
|
+
isActive.current = activeTab === value;
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (previousActiveTab.current !== activeTab && value === activeTab) {
|
|
33
|
+
ref.current?.focus();
|
|
34
|
+
onClick?.(value);
|
|
35
|
+
}
|
|
36
|
+
if (previousActiveTab.current !== activeTab) {
|
|
37
|
+
previousActiveTab.current = activeTab;
|
|
38
|
+
}
|
|
39
|
+
}, [value, onClick, activeTab]);
|
|
40
|
+
|
|
41
|
+
const start = useCallback(() => {
|
|
42
|
+
dispatch({ type: "start" });
|
|
43
|
+
}, [dispatch]);
|
|
44
|
+
|
|
45
|
+
const end = useCallback(() => {
|
|
46
|
+
dispatch({ type: "end" });
|
|
47
|
+
}, [dispatch]);
|
|
48
|
+
|
|
49
|
+
const up = useCallback(() => {
|
|
50
|
+
dispatch({ type: "previous" });
|
|
51
|
+
}, [dispatch]);
|
|
52
|
+
|
|
53
|
+
const down = useCallback(() => {
|
|
54
|
+
dispatch({ type: "next" });
|
|
55
|
+
}, [dispatch]);
|
|
56
|
+
|
|
57
|
+
const left = useCallback(() => {
|
|
58
|
+
const isRTL = document.documentElement.dir === "rtl";
|
|
59
|
+
|
|
60
|
+
dispatch({ type: isRTL ? "next" : "previous" });
|
|
61
|
+
}, [dispatch]);
|
|
62
|
+
|
|
63
|
+
const right = useCallback(() => {
|
|
64
|
+
const isRTL = document.documentElement.dir === "rtl";
|
|
65
|
+
|
|
66
|
+
dispatch({ type: isRTL ? "previous" : "next" });
|
|
67
|
+
}, [dispatch]);
|
|
68
|
+
|
|
69
|
+
const handleKeyDown = useKeyboardControls({
|
|
70
|
+
start,
|
|
71
|
+
end,
|
|
72
|
+
up,
|
|
73
|
+
down,
|
|
74
|
+
left,
|
|
75
|
+
right
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const handleClick = useCallback(() => {
|
|
79
|
+
dispatch({ type: "update", payload: value });
|
|
80
|
+
}, [dispatch, value]);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div title={"button-wrapper"} className={classnames("tw-tabs__button-wrapper", className, { "-active": isActive.current }, className)}>
|
|
84
|
+
<button
|
|
85
|
+
ref={ref}
|
|
86
|
+
id={`Tab_${value}_${uid}`}
|
|
87
|
+
data-name='Tab'
|
|
88
|
+
title='button-tab'
|
|
89
|
+
role='tab'
|
|
90
|
+
aria-selected={isActive.current}
|
|
91
|
+
aria-controls={`TabPanel_${value}_${uid}`}
|
|
92
|
+
tabIndex={isActive.current ? 0 : -1}
|
|
93
|
+
className={"tw-tabs__button"}
|
|
94
|
+
onClick={handleClick}
|
|
95
|
+
onKeyDown={handleKeyDown}
|
|
96
|
+
>
|
|
97
|
+
{icon && <i className={classnames(iconClass(undefined, icon), "tw-tabs__button-icon")} />}
|
|
98
|
+
<span className={"tw-tabs__button-label"}>{children}</span>
|
|
99
|
+
{after}
|
|
100
|
+
</button>
|
|
101
|
+
<div className='tw-tabs__button-border' />
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
registerComponent("Tab", Tab);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Children, isValidElement, PropsWithChildren, ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import { registerComponent } from "../../registries/components.js";
|
|
4
|
+
|
|
5
|
+
export function TabList(props: PropsWithChildren<{}>) {
|
|
6
|
+
const before: ReactNode[] = [];
|
|
7
|
+
const after: ReactNode[] = [];
|
|
8
|
+
const items: ReactNode[] = [];
|
|
9
|
+
|
|
10
|
+
Children.forEach(props.children, (child) => {
|
|
11
|
+
if (isValidElement(child)) {
|
|
12
|
+
if ((child.type as any)?.name === "Tab") {
|
|
13
|
+
items.push(child);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (items.length > 0) {
|
|
19
|
+
after.push(child);
|
|
20
|
+
} else {
|
|
21
|
+
before.push(child);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<nav className='tw-tabs__header'>
|
|
27
|
+
<div className='tw-tabs__header-wrapper'>
|
|
28
|
+
<div className='tw-tabs__header-border' />
|
|
29
|
+
{before}
|
|
30
|
+
<div role='tablist'>{items}</div>
|
|
31
|
+
{after}
|
|
32
|
+
</div>
|
|
33
|
+
</nav>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
registerComponent("TabList", TabList);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import classnames from "classnames";
|
|
2
|
+
|
|
3
|
+
import { registerComponent } from "../../registries/components.js";
|
|
4
|
+
import { useActiveTab, useTabsUid } from "./hooks/tabControl.js";
|
|
5
|
+
|
|
6
|
+
export interface TabPanelProps {
|
|
7
|
+
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Tab panel index<br/>
|
|
10
|
+
* _Can be **0** or **1** indexed_
|
|
11
|
+
*/
|
|
12
|
+
value: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function TabPanel({ value, className, children }: React.PropsWithChildren<TabPanelProps>) {
|
|
16
|
+
const tabSelected = useActiveTab();
|
|
17
|
+
const uid = useTabsUid();
|
|
18
|
+
const isActive = tabSelected === value;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div
|
|
22
|
+
id={`TabPanel_${value}_${uid}`}
|
|
23
|
+
data-name={`TabPanel_${value}`}
|
|
24
|
+
role='tabpanel'
|
|
25
|
+
aria-hidden={!isActive}
|
|
26
|
+
aria-labelledby={`Tab_${value}_${uid}`}
|
|
27
|
+
tabIndex={isActive ? 0 : -1}
|
|
28
|
+
className={classnames("tw-tabs__panel", className, {
|
|
29
|
+
"-active": isActive
|
|
30
|
+
})}
|
|
31
|
+
>
|
|
32
|
+
{children}
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
registerComponent("TabPanel", TabPanel);
|
|
@@ -1,87 +1,140 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import { userEvent } from "@testing-library/user-event";
|
|
2
3
|
import { expect, vi } from "vitest";
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { Tab } from "./Tab.js";
|
|
6
|
+
import { TabList } from "./TabList.js";
|
|
7
|
+
import { TabPanel } from "./TabPanel.js";
|
|
8
|
+
import { Tabs } from "./Tabs.js";
|
|
9
|
+
import { TabsBody } from "./TabsBody.js";
|
|
10
|
+
|
|
11
|
+
const props = {
|
|
12
|
+
reverse: false,
|
|
13
|
+
items: [
|
|
14
|
+
{
|
|
15
|
+
action: "edit",
|
|
16
|
+
exact: true,
|
|
17
|
+
icon: "edit",
|
|
18
|
+
label: "Edit",
|
|
19
|
+
children: <div className='bg-red-100 p-5'>Edit</div>
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
action: "submissions",
|
|
23
|
+
exact: false,
|
|
24
|
+
icon: "data",
|
|
25
|
+
label: "Data",
|
|
26
|
+
children: <div className='bg-orange-100 p-5'>Data</div>
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
action: "preview",
|
|
30
|
+
exact: true,
|
|
31
|
+
icon: "test-tube",
|
|
32
|
+
label: "Preview",
|
|
33
|
+
children: <div className='bg-yellow-100 p-5'>Preview</div>
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
action: "actions",
|
|
37
|
+
exact: false,
|
|
38
|
+
icon: "paper-plane",
|
|
39
|
+
label: "Actions",
|
|
40
|
+
children: <div className='bg-green-100 p-5'>Actions</div>
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
action: "access",
|
|
44
|
+
exact: true,
|
|
45
|
+
icon: "lock",
|
|
46
|
+
label: "Access",
|
|
47
|
+
children: <div className='bg-blue-100 p-5'>Access</div>
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
action: "export",
|
|
51
|
+
exact: true,
|
|
52
|
+
icon: "download",
|
|
53
|
+
label: "Export",
|
|
54
|
+
children: <div className='bg-purple-100 p-5'>Export</div>
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
action: "delete",
|
|
58
|
+
exact: true,
|
|
59
|
+
icon: "trash",
|
|
60
|
+
label: "Delete",
|
|
61
|
+
roles: ["administrator", "owner"],
|
|
62
|
+
children: <div className='bg-gray-100 p-5'>Trash</div>
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
onClick: vi.fn()
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
function TestComponent({
|
|
69
|
+
selected,
|
|
70
|
+
onClick,
|
|
71
|
+
reverse,
|
|
72
|
+
items
|
|
73
|
+
}: {
|
|
74
|
+
selected?: number;
|
|
75
|
+
onClick?: (item: any) => void;
|
|
76
|
+
reverse?: boolean;
|
|
77
|
+
items: any[];
|
|
78
|
+
}) {
|
|
79
|
+
return (
|
|
80
|
+
<Tabs selected={selected}>
|
|
81
|
+
<TabList>
|
|
82
|
+
{items.map((item, index) => {
|
|
83
|
+
return (
|
|
84
|
+
<Tab onClick={() => onClick?.(item)} key={index} icon={item.icon} value={index} className={reverse ? "-reverse" : ""}>
|
|
85
|
+
{item.label}
|
|
86
|
+
</Tab>
|
|
87
|
+
);
|
|
88
|
+
})}
|
|
89
|
+
</TabList>
|
|
90
|
+
<TabsBody>
|
|
91
|
+
{items.map((item, index) => {
|
|
92
|
+
return (
|
|
93
|
+
<TabPanel key={index} value={index}>
|
|
94
|
+
{item.children}
|
|
95
|
+
</TabPanel>
|
|
96
|
+
);
|
|
97
|
+
})}
|
|
98
|
+
</TabsBody>
|
|
99
|
+
</Tabs>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
6
102
|
|
|
7
103
|
describe("<Tabs>", () => {
|
|
8
|
-
it("should display the tabs component and children", () => {
|
|
9
|
-
|
|
10
|
-
{
|
|
11
|
-
action: "back",
|
|
12
|
-
exact: true,
|
|
13
|
-
icon: "chevron-left",
|
|
14
|
-
back: true
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
action: "edit",
|
|
18
|
-
exact: true,
|
|
19
|
-
icon: "edit",
|
|
20
|
-
label: "Edit"
|
|
21
|
-
}
|
|
22
|
-
];
|
|
104
|
+
it("should display the tabs component and children", async () => {
|
|
105
|
+
render(<TestComponent {...props} />);
|
|
23
106
|
|
|
24
|
-
|
|
107
|
+
// Vérifie que tous les onglets sont présents
|
|
108
|
+
expect(screen.getByRole("tab", { name: "Edit" })).toBeInTheDocument();
|
|
109
|
+
expect(screen.getByRole("tab", { name: "Data" })).toBeInTheDocument();
|
|
110
|
+
expect(screen.getByRole("tab", { name: "Preview" })).toBeInTheDocument();
|
|
111
|
+
expect(screen.getByRole("tab", { name: "Actions" })).toBeInTheDocument();
|
|
112
|
+
expect(screen.getByRole("tab", { name: "Access" })).toBeInTheDocument();
|
|
113
|
+
expect(screen.getByRole("tab", { name: "Export" })).toBeInTheDocument();
|
|
114
|
+
expect(screen.getByRole("tab", { name: "Delete" })).toBeInTheDocument();
|
|
25
115
|
|
|
26
|
-
|
|
116
|
+
await waitFor(() => expect(screen.getByRole("tabpanel")).toHaveTextContent("Edit"));
|
|
27
117
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const editButtonTabWrapper = buttonsTabWrapper[1];
|
|
118
|
+
// Clique sur l'onglet "Preview" et vérifie le contenu
|
|
119
|
+
await userEvent.click(screen.getByRole("tab", { name: "Preview" }));
|
|
31
120
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
121
|
+
expect(props.onClick).toHaveBeenCalledWith(
|
|
122
|
+
expect.objectContaining({
|
|
123
|
+
action: "preview"
|
|
124
|
+
})
|
|
125
|
+
);
|
|
35
126
|
|
|
36
|
-
|
|
37
|
-
const fontAwsomeEditIcon = "fa fa-edit";
|
|
127
|
+
await waitFor(() => expect(screen.getByRole("tabpanel")).toHaveTextContent("Preview"));
|
|
38
128
|
|
|
39
|
-
|
|
129
|
+
// Clique sur l'onglet "Delete" et vérifie le contenu
|
|
130
|
+
await userEvent.click(screen.getByRole("tab", { name: "Delete" }));
|
|
40
131
|
|
|
41
|
-
expect(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
132
|
+
expect(props.onClick).toHaveBeenCalledWith(
|
|
133
|
+
expect.objectContaining({
|
|
134
|
+
action: "delete"
|
|
135
|
+
})
|
|
136
|
+
);
|
|
46
137
|
|
|
47
|
-
expect(
|
|
48
|
-
expect(editButtonTabWrapper).not.toContainHTML("-back");
|
|
49
|
-
expect(editButtonTab).toBeInTheDocument();
|
|
50
|
-
expect(editButtonTab).toContainHTML(fontAwsomeEditIcon);
|
|
51
|
-
expect(editButtonTab).toHaveTextContent("Edit");
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should call dispatcher when clicking on a button tab", () => {
|
|
55
|
-
const items = [
|
|
56
|
-
{
|
|
57
|
-
action: "back",
|
|
58
|
-
exact: true,
|
|
59
|
-
icon: "chevron-left",
|
|
60
|
-
back: true
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
action: "edit",
|
|
64
|
-
exact: true,
|
|
65
|
-
icon: "edit",
|
|
66
|
-
label: "Edit"
|
|
67
|
-
}
|
|
68
|
-
];
|
|
69
|
-
const onClick = vi.fn();
|
|
70
|
-
|
|
71
|
-
render(<Tabs items={items} onClick={onClick} />);
|
|
72
|
-
|
|
73
|
-
const buttonsTab = screen.getAllByTitle("button-tab");
|
|
74
|
-
const chevronLeftButtonTab = buttonsTab[0];
|
|
75
|
-
const editButtonTab = buttonsTab[1];
|
|
76
|
-
|
|
77
|
-
fireEvent.click(chevronLeftButtonTab);
|
|
78
|
-
|
|
79
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
80
|
-
expect(onClick).toHaveBeenCalledWith(items[0]);
|
|
81
|
-
|
|
82
|
-
fireEvent.click(editButtonTab);
|
|
83
|
-
|
|
84
|
-
expect(onClick).toHaveBeenCalledTimes(2);
|
|
85
|
-
expect(onClick).toHaveBeenCalledWith(items[1]);
|
|
138
|
+
await waitFor(() => expect(screen.getByRole("tabpanel")).toHaveTextContent("Trash"));
|
|
86
139
|
});
|
|
87
140
|
});
|