@loadsmart/loadsmart-ui 7.6.0 → 7.7.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/dist/DragDropFile.context-oKnUu6d3.js +33 -0
- package/dist/{DragDropFile.context-D-EBrXnw.js.map → DragDropFile.context-oKnUu6d3.js.map} +1 -1
- package/dist/index.js +9104 -253
- package/dist/index.js.map +1 -1
- package/dist/miranda-compatibility.theme-C_FEacSw.js +2528 -0
- package/dist/{miranda-compatibility.theme-ChPV-BBw.js.map → miranda-compatibility.theme-C_FEacSw.js.map} +1 -1
- package/dist/prop-B8LY6G2g.js +81 -0
- package/dist/{prop-BwhJNJHO.js.map → prop-B8LY6G2g.js.map} +1 -1
- package/dist/testing/index.js +282 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/theming/index.js +22 -1
- package/dist/theming/index.js.map +1 -1
- package/dist/toArray-Dxb1kUxx.js +14 -0
- package/dist/{toArray-BW3gx_gH.js.map → toArray-Dxb1kUxx.js.map} +1 -1
- package/dist/tools/index.js +6 -1
- package/dist/tools/index.js.map +1 -1
- package/package.json +24 -54
- package/dist/DragDropFile.context-D-EBrXnw.js +0 -2
- package/dist/DragDropFile.context-jVTIKfj5.mjs +0 -29
- package/dist/DragDropFile.context-jVTIKfj5.mjs.map +0 -1
- package/dist/index.mjs +0 -8046
- package/dist/index.mjs.map +0 -1
- package/dist/miranda-compatibility.theme-ChPV-BBw.js +0 -2
- package/dist/miranda-compatibility.theme-DQDHkWzC.mjs +0 -2469
- package/dist/miranda-compatibility.theme-DQDHkWzC.mjs.map +0 -1
- package/dist/prop-5m3D4883.mjs +0 -54
- package/dist/prop-5m3D4883.mjs.map +0 -1
- package/dist/prop-BwhJNJHO.js +0 -2
- package/dist/testing/index.mjs +0 -228
- package/dist/testing/index.mjs.map +0 -1
- package/dist/theming/index.mjs +0 -20
- package/dist/theming/index.mjs.map +0 -1
- package/dist/toArray-BW3gx_gH.js +0 -2
- package/dist/toArray-DqgeO2ua.mjs +0 -8
- package/dist/toArray-DqgeO2ua.mjs.map +0 -1
- package/dist/tools/index.mjs +0 -7
- package/dist/tools/index.mjs.map +0 -1
- package/src/@types/@loadsmart/utilsFunction.d.ts +0 -5
- package/src/@types/@loadsmart/utilsObject.d.ts +0 -5
- package/src/@types/svg.d.ts +0 -4
- package/src/addons/Theme/register.js +0 -590
- package/src/common/BackButton/BackButton.tsx +0 -18
- package/src/common/BackButton/index.ts +0 -2
- package/src/common/CloseButton/CloseButton.tsx +0 -55
- package/src/common/CloseButton/index.ts +0 -2
- package/src/common/SelectionWrapper.tsx +0 -130
- package/src/components/Accordion/Accordion.context.tsx +0 -36
- package/src/components/Accordion/Accordion.stories.tsx +0 -186
- package/src/components/Accordion/Accordion.test.tsx +0 -209
- package/src/components/Accordion/Accordion.tsx +0 -233
- package/src/components/Accordion/index.ts +0 -2
- package/src/components/Banner/Banner.stories.tsx +0 -213
- package/src/components/Banner/Banner.test.tsx +0 -118
- package/src/components/Banner/Banner.tsx +0 -418
- package/src/components/Banner/index.tsx +0 -2
- package/src/components/Breadcrumbs/Breadbrumbs.test.tsx +0 -125
- package/src/components/Breadcrumbs/Breadcrumb.tsx +0 -92
- package/src/components/Breadcrumbs/Breadcrumbs.stories.tsx +0 -21
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +0 -54
- package/src/components/Breadcrumbs/index.ts +0 -4
- package/src/components/Button/Button.stories.tsx +0 -174
- package/src/components/Button/Button.test.tsx +0 -57
- package/src/components/Button/Button.tsx +0 -576
- package/src/components/Button/index.tsx +0 -2
- package/src/components/Calendar/Calendar.helpers.ts +0 -15
- package/src/components/Calendar/Calendar.stories.tsx +0 -168
- package/src/components/Calendar/Calendar.test.tsx +0 -316
- package/src/components/Calendar/Calendar.tsx +0 -130
- package/src/components/Calendar/Calendar.types.ts +0 -68
- package/src/components/Calendar/Date.helper.test.ts +0 -847
- package/src/components/Calendar/Date.helper.ts +0 -461
- package/src/components/Calendar/DateFormat.helper.test.ts +0 -171
- package/src/components/Calendar/DateFormat.helper.ts +0 -195
- package/src/components/Calendar/Month.helper.test.ts +0 -187
- package/src/components/Calendar/Month.helper.ts +0 -172
- package/src/components/Calendar/PickerModeToggle.tsx +0 -61
- package/src/components/Calendar/Pickers/DayPicker.test.tsx +0 -85
- package/src/components/Calendar/Pickers/DayPicker.tsx +0 -127
- package/src/components/Calendar/Pickers/MonthPicker.test.tsx +0 -77
- package/src/components/Calendar/Pickers/MonthPicker.tsx +0 -51
- package/src/components/Calendar/Pickers/PickerButton.tsx +0 -119
- package/src/components/Calendar/Pickers/YearPicker.test.tsx +0 -75
- package/src/components/Calendar/Pickers/YearPicker.tsx +0 -52
- package/src/components/Calendar/index.ts +0 -10
- package/src/components/Calendar/useCalendar.ts +0 -190
- package/src/components/Calendar/usePickerMode.ts +0 -48
- package/src/components/Card/Card.stories.tsx +0 -117
- package/src/components/Card/Card.test.tsx +0 -139
- package/src/components/Card/Card.tsx +0 -106
- package/src/components/Card/CardTitle.tsx +0 -43
- package/src/components/Card/index.ts +0 -2
- package/src/components/Checkbox/Checkbox.stories.tsx +0 -79
- package/src/components/Checkbox/Checkbox.test.tsx +0 -66
- package/src/components/Checkbox/Checkbox.tsx +0 -170
- package/src/components/Checkbox/index.ts +0 -2
- package/src/components/DatePicker/DatePicker.stories.tsx +0 -113
- package/src/components/DatePicker/DatePicker.test.tsx +0 -174
- package/src/components/DatePicker/DatePicker.tsx +0 -140
- package/src/components/DatePicker/DatePicker.types.ts +0 -30
- package/src/components/DatePicker/DateRangePicker.stories.tsx +0 -128
- package/src/components/DatePicker/DateRangePicker.test.tsx +0 -267
- package/src/components/DatePicker/DateRangePicker.tsx +0 -110
- package/src/components/DatePicker/index.ts +0 -3
- package/src/components/DatePicker/useDatePicker.ts +0 -201
- package/src/components/DatePicker/useDateRangePicker.ts +0 -224
- package/src/components/Dialog/Dialog.stories.tsx +0 -227
- package/src/components/Dialog/Dialog.test.tsx +0 -74
- package/src/components/Dialog/Dialog.tsx +0 -139
- package/src/components/Dialog/index.tsx +0 -4
- package/src/components/Dialog/useDialog.tsx +0 -59
- package/src/components/DragDropFile/DragDropFile.context.tsx +0 -39
- package/src/components/DragDropFile/DragDropFile.stories.tsx +0 -183
- package/src/components/DragDropFile/DragDropFile.tsx +0 -11
- package/src/components/DragDropFile/components/DropZone.test.tsx +0 -108
- package/src/components/DragDropFile/components/DropZone.tsx +0 -145
- package/src/components/DragDropFile/components/FileItem.tsx +0 -117
- package/src/components/DragDropFile/components/FileList.test.tsx +0 -119
- package/src/components/DragDropFile/components/FileList.tsx +0 -47
- package/src/components/DragDropFile/components/Wrapper.tsx +0 -22
- package/src/components/DragDropFile/index.ts +0 -9
- package/src/components/DragDropFile/mocks.ts +0 -23
- package/src/components/DragDropFile/styles.tsx +0 -81
- package/src/components/DragDropFile/types.ts +0 -85
- package/src/components/Drawer/Drawer.stories.tsx +0 -83
- package/src/components/Drawer/Drawer.test.tsx +0 -90
- package/src/components/Drawer/Drawer.tsx +0 -225
- package/src/components/Drawer/index.ts +0 -4
- package/src/components/Dropdown/Dropdown.context.ts +0 -13
- package/src/components/Dropdown/Dropdown.fixtures.ts +0 -15
- package/src/components/Dropdown/Dropdown.stories.tsx +0 -259
- package/src/components/Dropdown/Dropdown.test.tsx +0 -173
- package/src/components/Dropdown/Dropdown.tsx +0 -141
- package/src/components/Dropdown/Dropdown.types.ts +0 -59
- package/src/components/Dropdown/DropdownMenu.tsx +0 -263
- package/src/components/Dropdown/DropdownTrigger.tsx +0 -368
- package/src/components/Dropdown/index.ts +0 -15
- package/src/components/Dropdown/useDropdown.test.ts +0 -96
- package/src/components/Dropdown/useDropdown.ts +0 -65
- package/src/components/EmptyState/EmptyState.mocks.tsx +0 -60
- package/src/components/EmptyState/EmptyState.stories.tsx +0 -239
- package/src/components/EmptyState/EmptyState.test.tsx +0 -101
- package/src/components/EmptyState/EmptyState.tsx +0 -22
- package/src/components/EmptyState/EmptyState.types.ts +0 -59
- package/src/components/EmptyState/EmptyStateWithIcon.tsx +0 -42
- package/src/components/EmptyState/EmptyStateWithIllustration.tsx +0 -72
- package/src/components/EmptyState/Illustration.tsx +0 -29
- package/src/components/EmptyState/index.ts +0 -4
- package/src/components/ErrorMessage/ErrorMessage.stories.tsx +0 -26
- package/src/components/ErrorMessage/ErrorMessage.test.tsx +0 -24
- package/src/components/ErrorMessage/ErrorMessage.tsx +0 -19
- package/src/components/ErrorMessage/index.ts +0 -2
- package/src/components/HighlightMatch/HighlightMatch.stories.tsx +0 -24
- package/src/components/HighlightMatch/HighlightMatch.test.tsx +0 -37
- package/src/components/HighlightMatch/HighlightMatch.tsx +0 -29
- package/src/components/HighlightMatch/index.ts +0 -2
- package/src/components/Icon/Icon.tsx +0 -55
- package/src/components/Icon/assets/back.svg +0 -4
- package/src/components/Icon/assets/burger-menu.svg +0 -3
- package/src/components/Icon/assets/calendar.svg +0 -5
- package/src/components/Icon/assets/caret-down.svg +0 -4
- package/src/components/Icon/assets/caret-left.svg +0 -4
- package/src/components/Icon/assets/caret-right-last.svg +0 -4
- package/src/components/Icon/assets/caret-right.svg +0 -4
- package/src/components/Icon/assets/check.svg +0 -4
- package/src/components/Icon/assets/chevron-down.svg +0 -3
- package/src/components/Icon/assets/circle.svg +0 -3
- package/src/components/Icon/assets/close.svg +0 -4
- package/src/components/Icon/assets/dots-horizontal.svg +0 -1
- package/src/components/Icon/assets/information.svg +0 -4
- package/src/components/Icon/assets/minus.svg +0 -4
- package/src/components/Icon/assets/plus.svg +0 -4
- package/src/components/Icon/assets/refresh.svg +0 -3
- package/src/components/Icon/assets/sort-asc.svg +0 -7
- package/src/components/Icon/assets/sort-desc.svg +0 -7
- package/src/components/Icon/assets/sort.svg +0 -7
- package/src/components/Icon/assets/upload.svg +0 -3
- package/src/components/Icon/assets/warning.svg +0 -4
- package/src/components/Icon/index.ts +0 -2
- package/src/components/IconFactory/IconFactory.fixtures.tsx +0 -31
- package/src/components/IconFactory/IconFactory.stories.tsx +0 -120
- package/src/components/IconFactory/IconFactory.test.tsx +0 -36
- package/src/components/IconFactory/IconFactory.tsx +0 -75
- package/src/components/IconFactory/index.ts +0 -2
- package/src/components/Label/Label.stories.tsx +0 -47
- package/src/components/Label/Label.test.tsx +0 -80
- package/src/components/Label/Label.tsx +0 -120
- package/src/components/Label/index.ts +0 -2
- package/src/components/Layout/Box.tsx +0 -98
- package/src/components/Layout/Grid.tsx +0 -42
- package/src/components/Layout/Group.tsx +0 -55
- package/src/components/Layout/Layout.stories.tsx +0 -412
- package/src/components/Layout/Layout.tsx +0 -19
- package/src/components/Layout/Layout.types.ts +0 -9
- package/src/components/Layout/Layout.utils.ts +0 -20
- package/src/components/Layout/Sidebar.tsx +0 -75
- package/src/components/Layout/Stack.tsx +0 -63
- package/src/components/Layout/Switcher.tsx +0 -48
- package/src/components/Layout/index.tsx +0 -8
- package/src/components/Link/Link.stories.tsx +0 -22
- package/src/components/Link/Link.test.tsx +0 -79
- package/src/components/Link/Link.tsx +0 -114
- package/src/components/Link/index.ts +0 -3
- package/src/components/Link/useSafeLink.ts +0 -49
- package/src/components/Loaders/LoadingBar.stories.tsx +0 -36
- package/src/components/Loaders/LoadingBar.test.tsx +0 -35
- package/src/components/Loaders/LoadingBar.tsx +0 -65
- package/src/components/Loaders/LoadingDots.stories.tsx +0 -69
- package/src/components/Loaders/LoadingDots.test.tsx +0 -22
- package/src/components/Loaders/LoadingDots.tsx +0 -68
- package/src/components/Loaders/Spinner.stories.tsx +0 -24
- package/src/components/Loaders/Spinner.test.tsx +0 -35
- package/src/components/Loaders/Spinner.tsx +0 -68
- package/src/components/Loaders/index.tsx +0 -3
- package/src/components/Modal/Modal.stories.tsx +0 -121
- package/src/components/Modal/Modal.test.tsx +0 -46
- package/src/components/Modal/Modal.tsx +0 -163
- package/src/components/Modal/index.tsx +0 -2
- package/src/components/Pagination/Pagination.constants.ts +0 -7
- package/src/components/Pagination/Pagination.helper.ts +0 -88
- package/src/components/Pagination/Pagination.stories.tsx +0 -29
- package/src/components/Pagination/Pagination.test.tsx +0 -102
- package/src/components/Pagination/Pagination.tsx +0 -34
- package/src/components/Pagination/Pagination.types.ts +0 -55
- package/src/components/Pagination/PaginationItem.tsx +0 -74
- package/src/components/Pagination/index.ts +0 -2
- package/src/components/Pagination/usePagination.test.ts +0 -188
- package/src/components/Pagination/usePagination.ts +0 -87
- package/src/components/Popover/Popover.stories.tsx +0 -50
- package/src/components/Popover/Popover.test.tsx +0 -22
- package/src/components/Popover/Popover.tsx +0 -110
- package/src/components/Popover/Popover.types.ts +0 -39
- package/src/components/Popover/index.ts +0 -11
- package/src/components/ProgressBar/ProgressBar.stories.tsx +0 -47
- package/src/components/ProgressBar/ProgressBar.test.tsx +0 -40
- package/src/components/ProgressBar/ProgressBar.tsx +0 -89
- package/src/components/ProgressBar/index.tsx +0 -2
- package/src/components/Radio/Radio.stories.tsx +0 -75
- package/src/components/Radio/Radio.test.tsx +0 -66
- package/src/components/Radio/Radio.tsx +0 -153
- package/src/components/Radio/index.ts +0 -2
- package/src/components/Section/Section.test.tsx +0 -35
- package/src/components/Section/Section.tsx +0 -66
- package/src/components/Section/Sections.stories.tsx +0 -56
- package/src/components/Section/index.ts +0 -2
- package/src/components/Select/Select.constants.ts +0 -12
- package/src/components/Select/Select.context.ts +0 -11
- package/src/components/Select/Select.fixtures.ts +0 -167
- package/src/components/Select/Select.stories.tsx +0 -780
- package/src/components/Select/Select.test.tsx +0 -1109
- package/src/components/Select/Select.tsx +0 -271
- package/src/components/Select/Select.types.ts +0 -148
- package/src/components/Select/SelectCreatableOption.tsx +0 -20
- package/src/components/Select/SelectEmpty.test.tsx +0 -15
- package/src/components/Select/SelectEmpty.tsx +0 -29
- package/src/components/Select/SelectOption.test.tsx +0 -78
- package/src/components/Select/SelectOption.tsx +0 -79
- package/src/components/Select/SelectTrigger.tsx +0 -83
- package/src/components/Select/components.tsx +0 -14
- package/src/components/Select/index.ts +0 -12
- package/src/components/Select/useSelect.helpers.test.ts +0 -184
- package/src/components/Select/useSelect.helpers.ts +0 -63
- package/src/components/Select/useSelect.test.ts +0 -207
- package/src/components/Select/useSelect.ts +0 -540
- package/src/components/Select/useSelectExternal.ts +0 -26
- package/src/components/SideNavigation/Logo/Logo.test.tsx +0 -19
- package/src/components/SideNavigation/Logo/Logo.tsx +0 -26
- package/src/components/SideNavigation/Logo/index.ts +0 -1
- package/src/components/SideNavigation/Menu/Menu.test.tsx +0 -65
- package/src/components/SideNavigation/Menu/Menu.tsx +0 -53
- package/src/components/SideNavigation/Menu/MenuBaseItem.tsx +0 -64
- package/src/components/SideNavigation/Menu/MenuExpandable.tsx +0 -107
- package/src/components/SideNavigation/Menu/MenuLink.tsx +0 -37
- package/src/components/SideNavigation/Menu/index.ts +0 -1
- package/src/components/SideNavigation/Separator/Separator.test.tsx +0 -14
- package/src/components/SideNavigation/Separator/Separator.tsx +0 -20
- package/src/components/SideNavigation/Separator/index.ts +0 -1
- package/src/components/SideNavigation/SideNavigation.stories.tsx +0 -69
- package/src/components/SideNavigation/SideNavigation.test.tsx +0 -21
- package/src/components/SideNavigation/SideNavigation.tsx +0 -47
- package/src/components/SideNavigation/index.ts +0 -5
- package/src/components/SideNavigation/useSideNavigation.ts +0 -36
- package/src/components/Steps/ProgressSteps/ProgressStep.tsx +0 -163
- package/src/components/Steps/ProgressSteps/ProgressSteps.tsx +0 -37
- package/src/components/Steps/ProgressSteps/index.ts +0 -1
- package/src/components/Steps/Steps.fixtures.ts +0 -11
- package/src/components/Steps/Steps.helpers.ts +0 -11
- package/src/components/Steps/Steps.stories.tsx +0 -65
- package/src/components/Steps/Steps.test.tsx +0 -78
- package/src/components/Steps/Steps.tsx +0 -53
- package/src/components/Steps/Steps.types.ts +0 -5
- package/src/components/Steps/StepsContext.ts +0 -5
- package/src/components/Steps/StepsStep.tsx +0 -58
- package/src/components/Steps/index.ts +0 -6
- package/src/components/Steps/useStep.test.tsx +0 -217
- package/src/components/Steps/useSteps.ts +0 -131
- package/src/components/Switch/Switch.stories.tsx +0 -65
- package/src/components/Switch/Switch.test.tsx +0 -60
- package/src/components/Switch/Switch.tsx +0 -209
- package/src/components/Switch/index.ts +0 -2
- package/src/components/Table/Selection.tsx +0 -202
- package/src/components/Table/Table.fixtures.ts +0 -101
- package/src/components/Table/Table.stories.tsx +0 -568
- package/src/components/Table/Table.test.tsx +0 -310
- package/src/components/Table/Table.tsx +0 -523
- package/src/components/Table/Table.types.ts +0 -93
- package/src/components/Table/TableSortHandle.tsx +0 -31
- package/src/components/Table/index.tsx +0 -2
- package/src/components/Table/useSortBy.test.ts +0 -96
- package/src/components/Table/useSortBy.ts +0 -92
- package/src/components/Table/useSortBy.types.ts +0 -21
- package/src/components/TablePagination/RowsPerPage.tsx +0 -81
- package/src/components/TablePagination/TablePagination.stories.tsx +0 -42
- package/src/components/TablePagination/TablePagination.styles.ts +0 -13
- package/src/components/TablePagination/TablePagination.test.tsx +0 -111
- package/src/components/TablePagination/TablePagination.tsx +0 -49
- package/src/components/TablePagination/TablePagination.types.ts +0 -69
- package/src/components/TablePagination/TablePaginationActions.tsx +0 -144
- package/src/components/TablePagination/index.ts +0 -2
- package/src/components/Tabs/Tabs.stories.tsx +0 -78
- package/src/components/Tabs/Tabs.test.tsx +0 -103
- package/src/components/Tabs/Tabs.tsx +0 -287
- package/src/components/Tabs/Tabs.types.ts +0 -7
- package/src/components/Tabs/TabsContext.ts +0 -10
- package/src/components/Tabs/index.ts +0 -2
- package/src/components/Tag/Tag.stories.tsx +0 -112
- package/src/components/Tag/Tag.test.tsx +0 -19
- package/src/components/Tag/Tag.tsx +0 -393
- package/src/components/Tag/index.ts +0 -2
- package/src/components/Text/Text.stories.tsx +0 -59
- package/src/components/Text/Text.test.tsx +0 -48
- package/src/components/Text/Text.tsx +0 -14
- package/src/components/Text/index.ts +0 -2
- package/src/components/TextField/TextField.stories.tsx +0 -90
- package/src/components/TextField/TextField.test.tsx +0 -36
- package/src/components/TextField/TextField.tsx +0 -244
- package/src/components/TextField/index.ts +0 -6
- package/src/components/TextField/useTextField.tsx +0 -26
- package/src/components/Textarea/Textarea.stories.tsx +0 -101
- package/src/components/Textarea/Textarea.test.tsx +0 -14
- package/src/components/Textarea/Textarea.tsx +0 -230
- package/src/components/Textarea/index.ts +0 -2
- package/src/components/Toast/Toast.stories.tsx +0 -50
- package/src/components/Toast/Toast.test.tsx +0 -24
- package/src/components/Toast/Toast.tsx +0 -141
- package/src/components/Toast/icons/close.svg +0 -3
- package/src/components/Toast/icons/danger.svg +0 -4
- package/src/components/Toast/icons/neutral.svg +0 -4
- package/src/components/Toast/icons/success.svg +0 -3
- package/src/components/Toast/icons/warning.svg +0 -4
- package/src/components/Toast/index.tsx +0 -2
- package/src/components/ToggleGroup/Toggle.test.tsx +0 -76
- package/src/components/ToggleGroup/Toggle.tsx +0 -158
- package/src/components/ToggleGroup/ToggleGroup.constants.ts +0 -16
- package/src/components/ToggleGroup/ToggleGroup.stories.tsx +0 -145
- package/src/components/ToggleGroup/ToggleGroup.test.tsx +0 -237
- package/src/components/ToggleGroup/ToggleGroup.tsx +0 -165
- package/src/components/ToggleGroup/ToggleGroup.types.ts +0 -35
- package/src/components/ToggleGroup/ToggleGroupContext.ts +0 -13
- package/src/components/ToggleGroup/index.ts +0 -3
- package/src/components/Tooltip/Tooltip.stories.tsx +0 -82
- package/src/components/Tooltip/Tooltip.test.tsx +0 -49
- package/src/components/Tooltip/Tooltip.tsx +0 -185
- package/src/components/Tooltip/index.ts +0 -2
- package/src/components/TopNavigation/Logo/Logo.test.tsx +0 -21
- package/src/components/TopNavigation/Logo/Logo.tsx +0 -20
- package/src/components/TopNavigation/Logo/index.ts +0 -1
- package/src/components/TopNavigation/Menu/Menu.test.tsx +0 -125
- package/src/components/TopNavigation/Menu/Menu.tsx +0 -62
- package/src/components/TopNavigation/Menu/MenuItemDropdown.tsx +0 -118
- package/src/components/TopNavigation/Menu/MenuItemIcon.tsx +0 -50
- package/src/components/TopNavigation/Menu/index.ts +0 -1
- package/src/components/TopNavigation/OpenSideNavButton/OpenSideNavButton.tsx +0 -28
- package/src/components/TopNavigation/OpenSideNavButton/index.ts +0 -1
- package/src/components/TopNavigation/TopNavigation.stories.tsx +0 -42
- package/src/components/TopNavigation/TopNavigation.tsx +0 -47
- package/src/components/TopNavigation/index.ts +0 -2
- package/src/components/VisuallyHidden/VisuallyHidden.mdx +0 -26
- package/src/components/VisuallyHidden/VisuallyHidden.stories.tsx +0 -32
- package/src/components/VisuallyHidden/VisuallyHidden.test.tsx +0 -18
- package/src/components/VisuallyHidden/VisuallyHidden.tsx +0 -6
- package/src/components/VisuallyHidden/index.ts +0 -1
- package/src/docs/tools/DatePickerEvent.stories.mdx +0 -108
- package/src/docs/tools/DragDropFileEvent.stories.mdx +0 -75
- package/src/docs/tools/conditional.stories.mdx +0 -251
- package/src/docs/tools/selectEvent.stories.mdx +0 -121
- package/src/hooks/useClickOutside/index.ts +0 -1
- package/src/hooks/useClickOutside/useClickOutside.test.tsx +0 -116
- package/src/hooks/useClickOutside/useClickOutside.ts +0 -65
- package/src/hooks/useDidMount/index.ts +0 -1
- package/src/hooks/useDidMount/useDidMount.test.tsx +0 -38
- package/src/hooks/useDidMount/useDidMount.ts +0 -20
- package/src/hooks/useFingerprint/index.ts +0 -1
- package/src/hooks/useFingerprint/useFingerprint.test.ts +0 -76
- package/src/hooks/useFingerprint/useFingerprint.ts +0 -94
- package/src/hooks/useFocusTrap/index.ts +0 -2
- package/src/hooks/useFocusTrap/useFocusTrap.stories.tsx +0 -87
- package/src/hooks/useFocusTrap/useFocusTrap.test.tsx +0 -129
- package/src/hooks/useFocusTrap/useFocusTrap.ts +0 -187
- package/src/hooks/useFocusWithin/index.ts +0 -2
- package/src/hooks/useFocusWithin/useFocusWithin.test.tsx +0 -71
- package/src/hooks/useFocusWithin/useFocusWithin.ts +0 -62
- package/src/hooks/useHeightExpansionToggler/index.ts +0 -2
- package/src/hooks/useHeightExpansionToggler/useHeightExpansionToggler.test.tsx +0 -85
- package/src/hooks/useHeightExpansionToggler/useHeightExpansionToggler.ts +0 -54
- package/src/hooks/useID/index.ts +0 -1
- package/src/hooks/useID/useID.ts +0 -18
- package/src/hooks/useSelectable/SelectableStrategy.test.ts +0 -424
- package/src/hooks/useSelectable/SelectableStrategy.ts +0 -143
- package/src/hooks/useSelectable/index.ts +0 -8
- package/src/hooks/useSelectable/useSelectable.test.ts +0 -221
- package/src/hooks/useSelectable/useSelectable.ts +0 -156
- package/src/hooks/useSelectable/useSelectable.types.ts +0 -45
- package/src/hooks/useWindowResize/index.ts +0 -1
- package/src/hooks/useWindowResize/useWindowResize.ts +0 -27
- package/src/index.ts +0 -188
- package/src/stories/assets/code-brackets.svg +0 -1
- package/src/stories/assets/colors.svg +0 -1
- package/src/stories/assets/comments.svg +0 -1
- package/src/stories/assets/direction.svg +0 -1
- package/src/stories/assets/flow.svg +0 -1
- package/src/stories/assets/plugin.svg +0 -1
- package/src/stories/assets/repo.svg +0 -1
- package/src/stories/assets/stackalt.svg +0 -1
- package/src/stories/introduction.stories.mdx +0 -57
- package/src/stories/startPage.stories.mdx +0 -95
- package/src/styles/activatable.tsx +0 -30
- package/src/styles/disableable.tsx +0 -45
- package/src/styles/ellipsizable.tsx +0 -14
- package/src/styles/focusable.tsx +0 -32
- package/src/styles/font.test.ts +0 -31
- package/src/styles/font.tsx +0 -40
- package/src/styles/hidden.tsx +0 -29
- package/src/styles/hoverable.tsx +0 -30
- package/src/styles/transition.tsx +0 -25
- package/src/styles/typography.test.ts +0 -93
- package/src/styles/typography.ts +0 -190
- package/src/testing/DatePickerEvent/DatePickerEvent.ts +0 -117
- package/src/testing/DatePickerEvent/DateRangePickerEvent.ts +0 -83
- package/src/testing/DatePickerEvent/index.ts +0 -2
- package/src/testing/DragDropFileEvent/DragDropFileEvent.ts +0 -56
- package/src/testing/DragDropFileEvent/index.ts +0 -1
- package/src/testing/SelectEvent/SelectEvent.test.tsx +0 -192
- package/src/testing/SelectEvent/SelectEvent.ts +0 -264
- package/src/testing/SelectEvent/index.ts +0 -1
- package/src/testing/getInterpolatedStyles/getInterpolatedStyles.ts +0 -25
- package/src/testing/getInterpolatedStyles/index.ts +0 -1
- package/src/testing/index.ts +0 -6
- package/src/testing/renderWithDragDropFileProvider/index.ts +0 -1
- package/src/testing/renderWithDragDropFileProvider/renderWithDragDropFileProvider.tsx +0 -28
- package/src/tests/generator.ts +0 -127
- package/src/tests/renderer.tsx +0 -39
- package/src/theming/index.ts +0 -42
- package/src/theming/themes/alice.theme.ts +0 -1022
- package/src/theming/themes/index.ts +0 -3
- package/src/theming/themes/loadsmart.theme.ts +0 -1019
- package/src/theming/themes/miranda-compatibility.theme.ts +0 -972
- package/src/theming/theming.helpers.ts +0 -95
- package/src/tools/conditional.test.ts +0 -166
- package/src/tools/conditional.ts +0 -127
- package/src/tools/index.ts +0 -2
- package/src/tools/prop.test.ts +0 -52
- package/src/tools/prop.ts +0 -36
- package/src/utils/toolset/awaitTo.ts +0 -24
- package/src/utils/toolset/flatten.ts +0 -3
- package/src/utils/toolset/formatBytes.test.ts +0 -45
- package/src/utils/toolset/formatBytes.ts +0 -18
- package/src/utils/toolset/get.ts +0 -2
- package/src/utils/toolset/getID.test.ts +0 -57
- package/src/utils/toolset/getID.ts +0 -93
- package/src/utils/toolset/getOrdinalSuffix.test.ts +0 -27
- package/src/utils/toolset/getOrdinalSuffix.ts +0 -15
- package/src/utils/toolset/highlightMatch.test.tsx +0 -32
- package/src/utils/toolset/highlightMatch.tsx +0 -32
- package/src/utils/toolset/interleave.test.ts +0 -40
- package/src/utils/toolset/interleave.ts +0 -23
- package/src/utils/toolset/isEmpty.ts +0 -2
- package/src/utils/toolset/isThenable.test.ts +0 -40
- package/src/utils/toolset/isThenable.ts +0 -14
- package/src/utils/toolset/keyboard.ts +0 -50
- package/src/utils/toolset/omit.ts +0 -2
- package/src/utils/toolset/pluralize.ts +0 -16
- package/src/utils/toolset/range.ts +0 -2
- package/src/utils/toolset/rem.ts +0 -7
- package/src/utils/toolset/styledCompounds.ts +0 -22
- package/src/utils/toolset/toArray.ts +0 -16
- package/src/utils/types/ColorScheme.ts +0 -3
- package/src/utils/types/EventLike.ts +0 -11
- package/src/utils/types/InterpolatedStyle.ts +0 -3
- package/src/utils/types/Status.ts +0 -8
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { renderHook, act } from '@testing-library/react-hooks'
|
|
2
|
-
|
|
3
|
-
import useFingerprint from './useFingerprint'
|
|
4
|
-
|
|
5
|
-
describe('useFingerprint', () => {
|
|
6
|
-
it('starts up correctly', () => {
|
|
7
|
-
const items = ['A', 'B', 'C']
|
|
8
|
-
|
|
9
|
-
const { result } = renderHook(() => useFingerprint<string>((item) => item, items))
|
|
10
|
-
expect(result.current.fingerprint).toBeTruthy()
|
|
11
|
-
expect(typeof result.current.getFingerprint).toBe('function')
|
|
12
|
-
expect(typeof result.current.resetFingerprint).toBe('function')
|
|
13
|
-
expect(typeof result.current.hasSameFingerprint).toBe('function')
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('gets the same fingerprint for the same set of items', () => {
|
|
17
|
-
const items = ['A', 'B', 'C']
|
|
18
|
-
|
|
19
|
-
const { result } = renderHook(() => useFingerprint<string>((item) => item, items))
|
|
20
|
-
expect(result.current.fingerprint).toBe(result.current.getFingerprint(['A', 'B', 'C']))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('gets a different fingerprint when a new item is added', () => {
|
|
24
|
-
const items = ['A', 'B']
|
|
25
|
-
|
|
26
|
-
const { result } = renderHook(() => useFingerprint<string>((item) => item, items))
|
|
27
|
-
expect(result.current.fingerprint).not.toBe(result.current.getFingerprint(['A', 'B', 'C']))
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('gets a different fingerprint when an item is removed', () => {
|
|
31
|
-
const items = ['A', 'B', 'C']
|
|
32
|
-
|
|
33
|
-
const { result } = renderHook(() => useFingerprint<string>((item) => item, items))
|
|
34
|
-
expect(result.current.hasSameFingerprint(['B', 'C'])).toBe(false)
|
|
35
|
-
expect(result.current.hasSameFingerprint(['A', 'C'])).toBe(false)
|
|
36
|
-
expect(result.current.hasSameFingerprint(['A', 'B'])).toBe(false)
|
|
37
|
-
expect(result.current.hasSameFingerprint(['A'])).toBe(false)
|
|
38
|
-
expect(result.current.hasSameFingerprint(['B'])).toBe(false)
|
|
39
|
-
expect(result.current.hasSameFingerprint(['C'])).toBe(false)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('resets fingerprint correctly', () => {
|
|
43
|
-
const items = ['A', 'B', 'C']
|
|
44
|
-
|
|
45
|
-
const { result } = renderHook(() => useFingerprint<string>((item) => item, items))
|
|
46
|
-
const oldFingerprint = result.current.fingerprint
|
|
47
|
-
|
|
48
|
-
act(() => {
|
|
49
|
-
result.current.resetFingerprint(['D', 'E', 'F'])
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
expect(result.current.fingerprint).not.toBe(oldFingerprint)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('checks the fingerprint of a set of items against the current fingerprint, regardless order', () => {
|
|
56
|
-
const items = ['A', 'B', 'C']
|
|
57
|
-
|
|
58
|
-
const { result } = renderHook(() => useFingerprint<string>((item) => item, items))
|
|
59
|
-
expect(result.current.hasSameFingerprint(['D', 'E', 'F'])).toBe(false)
|
|
60
|
-
expect(result.current.hasSameFingerprint(['A', 'B', 'C'])).toBe(true)
|
|
61
|
-
expect(result.current.hasSameFingerprint(['A', 'C', 'B'])).toBe(true)
|
|
62
|
-
expect(result.current.hasSameFingerprint(['B', 'A', 'C'])).toBe(true)
|
|
63
|
-
expect(result.current.hasSameFingerprint(['B', 'C', 'A'])).toBe(true)
|
|
64
|
-
expect(result.current.hasSameFingerprint(['C', 'A', 'B'])).toBe(true)
|
|
65
|
-
expect(result.current.hasSameFingerprint(['C', 'B', 'A'])).toBe(true)
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('returns empty fingerprint if provided items is falsy', () => {
|
|
69
|
-
const items = ['A', 'B', 'C']
|
|
70
|
-
|
|
71
|
-
const { result } = renderHook(() => useFingerprint<string>((item) => item, items))
|
|
72
|
-
|
|
73
|
-
expect(result.current.getFingerprint(null)).toBe('')
|
|
74
|
-
expect(result.current.getFingerprint(undefined)).toBe('')
|
|
75
|
-
})
|
|
76
|
-
})
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { useState, useRef } from 'react'
|
|
2
|
-
|
|
3
|
-
import getID from 'utils/toolset/getID'
|
|
4
|
-
import isEmpty from 'utils/toolset/isEmpty'
|
|
5
|
-
|
|
6
|
-
type FingerprintAdapter<T> = (item: T) => string
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* This hook helps with stabilizing changes for components that rely on non-primitive props, more specifically, arrays,
|
|
10
|
-
* objects, maps, sets and so on; when we need to update an internal state based on such types of prop, we might run into an infinite loop.
|
|
11
|
-
* By creating a fingerprint - a string that identifies that set of items - we can garantee that the same set of items will
|
|
12
|
-
* always return the same fingerprint, thus, making check for changes more predictable.
|
|
13
|
-
*
|
|
14
|
-
* @param adapter - adapter function that gets a unique identifier for each item in the `items` prop
|
|
15
|
-
* @param items - list of items whose fingerprint should be checked.
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
function useFingerprint<T>(
|
|
19
|
-
adapter: FingerprintAdapter<T>,
|
|
20
|
-
items: T[]
|
|
21
|
-
): {
|
|
22
|
-
fingerprint: string
|
|
23
|
-
getFingerprint: (items?: T[] | null, insert?: boolean) => string
|
|
24
|
-
resetFingerprint: (items: T[]) => void
|
|
25
|
-
hasSameFingerprint: (otherItems: T[]) => boolean
|
|
26
|
-
} {
|
|
27
|
-
const knownRef = useRef({} as Record<string, T | string>)
|
|
28
|
-
const [fingerprint, setFingerprint] = useState(() => getFingerprint('', items, true))
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Get a fingerprint based on the sorted items identifiers.
|
|
32
|
-
*
|
|
33
|
-
* @param {string[]} items - array of items
|
|
34
|
-
* @param {boolean} update - update `known` with the provided `items`, if it contains different set of items.
|
|
35
|
-
* @returns {string}
|
|
36
|
-
*/
|
|
37
|
-
function getFingerprint(currentFingerprint: string, items?: T[] | null, update = false) {
|
|
38
|
-
const known = knownRef.current
|
|
39
|
-
|
|
40
|
-
const safeItems = items || []
|
|
41
|
-
|
|
42
|
-
let newKnown: Record<string, T | string> = {}
|
|
43
|
-
let hasSameItems = Object.keys(known).length === safeItems.length
|
|
44
|
-
|
|
45
|
-
for (let i = 0; i < safeItems.length; i++) {
|
|
46
|
-
const item = safeItems[i]
|
|
47
|
-
const key = adapter(item)
|
|
48
|
-
|
|
49
|
-
hasSameItems = hasSameItems && known[key] != null
|
|
50
|
-
|
|
51
|
-
newKnown = {
|
|
52
|
-
...newKnown,
|
|
53
|
-
// we associate a previously created or a new random value to compose the fingerprint
|
|
54
|
-
[key]: known[key] ?? getID(),
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (hasSameItems) {
|
|
59
|
-
return currentFingerprint
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (update) {
|
|
63
|
-
knownRef.current = newKnown
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const fingerprint = Object.keys(newKnown)
|
|
67
|
-
.sort()
|
|
68
|
-
.reduce((fingerprint, item) => {
|
|
69
|
-
return `${fingerprint}${newKnown[item] as string}`
|
|
70
|
-
}, '')
|
|
71
|
-
|
|
72
|
-
return fingerprint
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
fingerprint,
|
|
77
|
-
getFingerprint(items?: T[] | null, update = false) {
|
|
78
|
-
return getFingerprint(fingerprint, items, update)
|
|
79
|
-
},
|
|
80
|
-
resetFingerprint(items: T[]) {
|
|
81
|
-
setFingerprint(getFingerprint(fingerprint, items, true))
|
|
82
|
-
},
|
|
83
|
-
/**
|
|
84
|
-
* Check if the provided items have the same fingerprint.
|
|
85
|
-
* @param {string[]} otherItems - items
|
|
86
|
-
* @returns {boolean}
|
|
87
|
-
*/
|
|
88
|
-
hasSameFingerprint(otherItems: T[]) {
|
|
89
|
-
return fingerprint === getFingerprint(fingerprint, otherItems)
|
|
90
|
-
},
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export default useFingerprint
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import clsx from 'clsx'
|
|
3
|
-
import type { Story, Meta } from '@storybook/react'
|
|
4
|
-
|
|
5
|
-
import range from 'utils/toolset/range'
|
|
6
|
-
import useFocusTrap from './useFocusTrap'
|
|
7
|
-
|
|
8
|
-
import type { useFocusTrapProps } from './useFocusTrap'
|
|
9
|
-
|
|
10
|
-
export default {
|
|
11
|
-
title: 'Hooks/useFocusTrap',
|
|
12
|
-
} as Meta
|
|
13
|
-
|
|
14
|
-
function Experiment(props: { elements?: number } & useFocusTrapProps) {
|
|
15
|
-
const { elements = 2 } = props
|
|
16
|
-
const { containerRef, active, activate, deactivate } = useFocusTrap(props)
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<div className="space-y-4 text-center">
|
|
20
|
-
<p data-testid="trap-status">Trap is {active ? 'active' : 'inactive'}</p>
|
|
21
|
-
<div
|
|
22
|
-
ref={containerRef}
|
|
23
|
-
className={clsx('inline-flex flex-row justify-center space-x-2 p-4 border-2 rounded', {
|
|
24
|
-
'border-neutral-darker': active,
|
|
25
|
-
'border-neutral-lighter border-dashed': !active,
|
|
26
|
-
})}
|
|
27
|
-
>
|
|
28
|
-
{range(elements).map((_, index) => (
|
|
29
|
-
<button key={index} className="p-4 rounded bg-neutral-light" type="button">
|
|
30
|
-
{index + 1}
|
|
31
|
-
</button>
|
|
32
|
-
))}
|
|
33
|
-
</div>
|
|
34
|
-
<div className="flex flex-row justify-center space-x-2">
|
|
35
|
-
<button
|
|
36
|
-
className="p-2 bg-transparent border rounded border-neutral-darker"
|
|
37
|
-
type="button"
|
|
38
|
-
onClick={active ? deactivate : activate}
|
|
39
|
-
>
|
|
40
|
-
{active ? 'Deactivate' : 'Activate'}
|
|
41
|
-
</button>
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const Playground: Story<useFocusTrapProps> = (args) => {
|
|
48
|
-
return (
|
|
49
|
-
<div className="flex flex-col space-y-2">
|
|
50
|
-
<p>Activate the trap and tab through the numbered buttons</p>
|
|
51
|
-
<Experiment {...args} elements={3} />
|
|
52
|
-
</div>
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Playground.args = {
|
|
57
|
-
keys: ['TAB'],
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const TabTrap: Story<useFocusTrapProps> = (args) => {
|
|
61
|
-
return (
|
|
62
|
-
<div className="flex flex-col space-y-2">
|
|
63
|
-
<p>Activate the trap and tab through the numbered buttons</p>
|
|
64
|
-
<small>
|
|
65
|
-
Notice that tabbing through does <strong>not</strong> allow focus to exit the trap.
|
|
66
|
-
</small>
|
|
67
|
-
<Experiment {...args} elements={6} keys={['TAB']} />
|
|
68
|
-
</div>
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
TabTrap.args = {}
|
|
73
|
-
|
|
74
|
-
export const ArrowTrap: Story<useFocusTrapProps> = (args) => {
|
|
75
|
-
return (
|
|
76
|
-
<div className="flex flex-col space-y-2">
|
|
77
|
-
<p>
|
|
78
|
-
Activate the trap and navigate through the numbered buttons using the up and down arrow
|
|
79
|
-
keys.
|
|
80
|
-
</p>
|
|
81
|
-
<small>Notice that tabbing through allows focus to exit the trap.</small>
|
|
82
|
-
<Experiment {...args} elements={6} keys={['ARROW_UP', 'ARROW_DOWN']} />
|
|
83
|
-
</div>
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
ArrowTrap.args = {}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import renderer, { screen, fire, user } from '../../tests/renderer'
|
|
3
|
-
import { composeStories } from '@storybook/react'
|
|
4
|
-
|
|
5
|
-
import * as stories from './useFocusTrap.stories'
|
|
6
|
-
|
|
7
|
-
import type { useFocusTrapProps } from './useFocusTrap'
|
|
8
|
-
|
|
9
|
-
const { Playground } = composeStories(stories)
|
|
10
|
-
|
|
11
|
-
const setup = (props: Omit<useFocusTrapProps, 'containerRef'>) =>
|
|
12
|
-
renderer(<Playground {...props} />).render()
|
|
13
|
-
|
|
14
|
-
describe('useFocusTrap', () => {
|
|
15
|
-
it('focus on all elements when the trap is deactivated', () => {
|
|
16
|
-
const props = {}
|
|
17
|
-
|
|
18
|
-
setup(props)
|
|
19
|
-
|
|
20
|
-
screen.getByText('Trap is inactive')
|
|
21
|
-
|
|
22
|
-
user.tab()
|
|
23
|
-
expect(screen.getByText('1')).toHaveFocus()
|
|
24
|
-
|
|
25
|
-
user.tab()
|
|
26
|
-
expect(screen.getByText('2')).toHaveFocus()
|
|
27
|
-
|
|
28
|
-
user.tab()
|
|
29
|
-
expect(screen.getByText('3')).toHaveFocus()
|
|
30
|
-
|
|
31
|
-
user.tab()
|
|
32
|
-
expect(screen.getByText('Activate')).toHaveFocus()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('calls `onActivate` when the trap is activated', () => {
|
|
36
|
-
const props = {
|
|
37
|
-
onActivate: jest.fn(),
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
setup(props)
|
|
41
|
-
|
|
42
|
-
fire.click(screen.getByText('Activate'))
|
|
43
|
-
|
|
44
|
-
expect(props.onActivate).toHaveBeenCalled()
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('focus on all focusable elements [currently supported] inside the container when the trap is activated', () => {
|
|
48
|
-
const props = {}
|
|
49
|
-
|
|
50
|
-
setup(props)
|
|
51
|
-
|
|
52
|
-
fire.click(screen.getByText('Activate'))
|
|
53
|
-
|
|
54
|
-
screen.getByText('Trap is active')
|
|
55
|
-
|
|
56
|
-
user.tab()
|
|
57
|
-
expect(screen.getByText('1')).toHaveFocus()
|
|
58
|
-
|
|
59
|
-
user.tab()
|
|
60
|
-
expect(screen.getByText('2')).toHaveFocus()
|
|
61
|
-
|
|
62
|
-
user.tab()
|
|
63
|
-
expect(screen.getByText('3')).toHaveFocus()
|
|
64
|
-
|
|
65
|
-
// it circles back to the first focusable element
|
|
66
|
-
user.tab()
|
|
67
|
-
expect(screen.getByText('1')).toHaveFocus()
|
|
68
|
-
|
|
69
|
-
user.tab()
|
|
70
|
-
expect(screen.getByText('2')).toHaveFocus()
|
|
71
|
-
|
|
72
|
-
user.tab()
|
|
73
|
-
expect(screen.getByText('3')).toHaveFocus()
|
|
74
|
-
|
|
75
|
-
fire.click(screen.getByText('Deactivate'))
|
|
76
|
-
|
|
77
|
-
// returns to the normal tab sequence
|
|
78
|
-
user.tab()
|
|
79
|
-
expect(screen.getByText('Activate')).toHaveFocus()
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('focus with custom keys on all focusable elements [currently supported] inside the container when the trap is activated', () => {
|
|
83
|
-
const props = {
|
|
84
|
-
keys: ['ARROW_UP', 'ARROW_DOWN'],
|
|
85
|
-
} as useFocusTrapProps
|
|
86
|
-
|
|
87
|
-
setup(props)
|
|
88
|
-
|
|
89
|
-
fire.click(screen.getByText('Activate'))
|
|
90
|
-
|
|
91
|
-
screen.getByText('Trap is active')
|
|
92
|
-
|
|
93
|
-
user.tab()
|
|
94
|
-
|
|
95
|
-
expect(screen.getByText('1')).toHaveFocus()
|
|
96
|
-
|
|
97
|
-
fire.keyDown(document, { key: 'ArrowUp', code: 'ArrowUp' })
|
|
98
|
-
expect(screen.getByText('3')).toHaveFocus()
|
|
99
|
-
|
|
100
|
-
fire.keyDown(document, { key: 'ArrowUp', code: 'ArrowUp' })
|
|
101
|
-
expect(screen.getByText('2')).toHaveFocus()
|
|
102
|
-
|
|
103
|
-
// it circles back to the first focusable element
|
|
104
|
-
fire.keyDown(document, { key: 'ArrowUp', code: 'ArrowUp' })
|
|
105
|
-
expect(screen.getByText('1')).toHaveFocus()
|
|
106
|
-
|
|
107
|
-
fire.keyDown(document, { key: 'ArrowUp', code: 'ArrowUp' })
|
|
108
|
-
expect(screen.getByText('3')).toHaveFocus()
|
|
109
|
-
|
|
110
|
-
fire.click(screen.getByText('Deactivate'))
|
|
111
|
-
|
|
112
|
-
fire.keyDown(document, { key: 'ArrowUp', code: 'ArrowUp' })
|
|
113
|
-
// keeps focus where it was before
|
|
114
|
-
expect(screen.getByText('3')).toHaveFocus()
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
it('calls `onDeactivate` when the trap is deactivated', () => {
|
|
118
|
-
const props = {
|
|
119
|
-
onDeactivate: jest.fn(),
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
setup(props)
|
|
123
|
-
|
|
124
|
-
fire.click(screen.getByText('Activate'))
|
|
125
|
-
fire.click(screen.getByText('Deactivate'))
|
|
126
|
-
|
|
127
|
-
expect(props.onDeactivate).toHaveBeenCalled()
|
|
128
|
-
})
|
|
129
|
-
})
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import KeyboardKey, { getKeyboardKey } from 'utils/toolset/keyboard'
|
|
4
|
-
import isEmpty from 'utils/toolset/isEmpty'
|
|
5
|
-
|
|
6
|
-
import type { SupportedKey } from 'utils/toolset/keyboard'
|
|
7
|
-
|
|
8
|
-
export interface useFocusTrapProps {
|
|
9
|
-
onActivate?: () => void
|
|
10
|
-
onDeactivate?: () => void
|
|
11
|
-
keys?: SupportedKey[]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function getFocusedIndexAfterKeyPress(
|
|
15
|
-
e: React.KeyboardEvent,
|
|
16
|
-
currentFocused: number,
|
|
17
|
-
focusableCounter: number
|
|
18
|
-
): number {
|
|
19
|
-
const keyHandler: Record<React.KeyboardEvent['key'], (e: React.KeyboardEvent) => number> = {
|
|
20
|
-
Tab(e: React.KeyboardEvent): number {
|
|
21
|
-
return e.shiftKey ? -1 : 1
|
|
22
|
-
},
|
|
23
|
-
ArrowUp() {
|
|
24
|
-
return -1
|
|
25
|
-
},
|
|
26
|
-
ArrowDown() {
|
|
27
|
-
return 1
|
|
28
|
-
},
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function unknownKey() {
|
|
32
|
-
return 0
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const key = getKeyboardKey(e)
|
|
36
|
-
const increment = (keyHandler[key] || unknownKey)(e)
|
|
37
|
-
|
|
38
|
-
if (currentFocused === -1 && increment === -1) {
|
|
39
|
-
/**
|
|
40
|
-
* Prevent to skip one element when the initial increment is -1
|
|
41
|
-
* and `currentFocused` is -1, we don't .
|
|
42
|
-
* e.g.: focus has just been activated and user presses arrow up.
|
|
43
|
-
*/
|
|
44
|
-
return (increment + focusableCounter) % focusableCounter
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return (currentFocused + increment + focusableCounter) % focusableCounter
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getTabbableDescendants<T extends HTMLElement>(container: T | null) {
|
|
51
|
-
if (container == null) {
|
|
52
|
-
return []
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// TODO: add support for other focusable elements
|
|
56
|
-
return Array.from(container.querySelectorAll('button') || [])
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Custom hook that limits the focusable elements within a container, when activated.
|
|
61
|
-
*
|
|
62
|
-
* Based on https://developer.mozilla.org/en-US/docs/Web/Accessibility/Keyboard-navigable_JavaScript_widgets.
|
|
63
|
-
*
|
|
64
|
-
* @param {useFocusTrapProps} props
|
|
65
|
-
* @param {RefObject} props.containerRef - Ref to the container that will be the boundary for the focus trap.
|
|
66
|
-
* @param {() => void} props.onActivate - Called when the focus trap is activated.
|
|
67
|
-
* @param {() => void} props.onDeactivate - Called when the focus trap is deactivated.
|
|
68
|
-
* @param {(KeyboardEvent['key'])[]} props.keys - Keys that will move the focus inside
|
|
69
|
-
* the container (The current implementation only track focus for button elements). We current
|
|
70
|
-
* support `Tab`, `ArrowUp`, and `ArrowDown` keys. If not provided, only the `Tab` key will be used.
|
|
71
|
-
* @returns {Object}
|
|
72
|
-
*/
|
|
73
|
-
function useFocusTrap<T extends HTMLElement>(
|
|
74
|
-
props: useFocusTrapProps
|
|
75
|
-
): {
|
|
76
|
-
containerRef: (container: T | null) => void
|
|
77
|
-
active: boolean
|
|
78
|
-
activate: () => void
|
|
79
|
-
deactivate: () => void
|
|
80
|
-
} {
|
|
81
|
-
const { keys, onActivate, onDeactivate } = props
|
|
82
|
-
|
|
83
|
-
const [active, setActive] = useState(false)
|
|
84
|
-
const [currentFocused, setCurrentFocused] = useState(-1)
|
|
85
|
-
const mutationObserverRef = useRef<MutationObserver>()
|
|
86
|
-
const [focusableDescendants, setFocusableDescendants] = useState<HTMLElement[]>([])
|
|
87
|
-
|
|
88
|
-
function subscribeToDOMMutationEvents(container: HTMLElement) {
|
|
89
|
-
mutationObserverRef.current = new MutationObserver(function () {
|
|
90
|
-
setFocusableDescendants(getTabbableDescendants(container))
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
mutationObserverRef.current.observe(container, { childList: true })
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function unsubscribeToDOMMutationEvents() {
|
|
97
|
-
setCurrentFocused(-1)
|
|
98
|
-
if (mutationObserverRef.current) {
|
|
99
|
-
mutationObserverRef.current?.disconnect()
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const containerRef = useCallback(function initialize(container: HTMLElement | null) {
|
|
104
|
-
if (container != null) {
|
|
105
|
-
setFocusableDescendants(getTabbableDescendants(container))
|
|
106
|
-
subscribeToDOMMutationEvents(container)
|
|
107
|
-
} else {
|
|
108
|
-
unsubscribeToDOMMutationEvents()
|
|
109
|
-
}
|
|
110
|
-
}, [])
|
|
111
|
-
|
|
112
|
-
useEffect(function onMount() {
|
|
113
|
-
return function onUnmount() {
|
|
114
|
-
unsubscribeToDOMMutationEvents()
|
|
115
|
-
}
|
|
116
|
-
}, [])
|
|
117
|
-
|
|
118
|
-
useEffect(
|
|
119
|
-
function subscribeToKeyEvents() {
|
|
120
|
-
function handleKeyDownEvent(evt: KeyboardEvent) {
|
|
121
|
-
/**
|
|
122
|
-
* Brace yourselves for the nasty casting from globalThis.KeyboardEvent, which is
|
|
123
|
-
* the type used in the `addEventListener` callback, to React.KeyboardEvent ¯\_(ツ)_/¯
|
|
124
|
-
*/
|
|
125
|
-
const e = evt as unknown as React.KeyboardEvent
|
|
126
|
-
|
|
127
|
-
const supportedKeys = [...(keys || ['TAB'])]
|
|
128
|
-
|
|
129
|
-
if (!KeyboardKey(e).is(supportedKeys) || isEmpty(focusableDescendants)) {
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
e.preventDefault()
|
|
134
|
-
|
|
135
|
-
const newCurrentFocused = getFocusedIndexAfterKeyPress(
|
|
136
|
-
e,
|
|
137
|
-
currentFocused,
|
|
138
|
-
focusableDescendants.length
|
|
139
|
-
)
|
|
140
|
-
setCurrentFocused(newCurrentFocused)
|
|
141
|
-
focusableDescendants[newCurrentFocused].focus()
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function subscribe() {
|
|
145
|
-
document.addEventListener('keydown', handleKeyDownEvent)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function unsubscribe() {
|
|
149
|
-
document.removeEventListener('keydown', handleKeyDownEvent)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (active) {
|
|
153
|
-
subscribe()
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return function unsubscribeToKeyEvents() {
|
|
157
|
-
unsubscribe()
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
[active, keys, currentFocused, focusableDescendants]
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
const activate = useCallback(
|
|
164
|
-
function activate() {
|
|
165
|
-
setActive(true)
|
|
166
|
-
onActivate?.()
|
|
167
|
-
},
|
|
168
|
-
[onActivate]
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
const deactivate = useCallback(
|
|
172
|
-
function deactivate() {
|
|
173
|
-
setActive(false)
|
|
174
|
-
onDeactivate?.()
|
|
175
|
-
},
|
|
176
|
-
[onDeactivate]
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
return {
|
|
180
|
-
containerRef,
|
|
181
|
-
active,
|
|
182
|
-
activate,
|
|
183
|
-
deactivate,
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export default useFocusTrap
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import renderer, { screen, fire } from '../../tests/renderer'
|
|
3
|
-
|
|
4
|
-
import useFocusWithin from './useFocusWithin'
|
|
5
|
-
|
|
6
|
-
import type { useFocusWithinProps } from './useFocusWithin'
|
|
7
|
-
|
|
8
|
-
function Experiment(props: useFocusWithinProps) {
|
|
9
|
-
const { ref } = useFocusWithin<HTMLDivElement>(props)
|
|
10
|
-
|
|
11
|
-
return (
|
|
12
|
-
<div>
|
|
13
|
-
<div ref={ref}>
|
|
14
|
-
<button>Focusable</button>
|
|
15
|
-
</div>
|
|
16
|
-
<button>Ignorable</button>
|
|
17
|
-
</div>
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const setup = (props: useFocusWithinProps) => renderer(<Experiment {...props} />).render()
|
|
22
|
-
|
|
23
|
-
describe('useFocusWithin', () => {
|
|
24
|
-
it('calls onFocus when a descendant is focused', () => {
|
|
25
|
-
const props = {
|
|
26
|
-
onFocus: jest.fn(),
|
|
27
|
-
onBlur: jest.fn(),
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
setup(props)
|
|
31
|
-
|
|
32
|
-
fire.focus(screen.getByText('Focusable'))
|
|
33
|
-
expect(props.onFocus).toHaveBeenCalled()
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('does not call onFocus when a non-descendant is focused', () => {
|
|
37
|
-
const props = {
|
|
38
|
-
onFocus: jest.fn(),
|
|
39
|
-
onBlur: jest.fn(),
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
setup(props)
|
|
43
|
-
|
|
44
|
-
fire.focus(screen.getByText('Ignorable'))
|
|
45
|
-
expect(props.onFocus).not.toHaveBeenCalled()
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('calls onBlur when a descendant loses focus', () => {
|
|
49
|
-
const props = {
|
|
50
|
-
onFocus: jest.fn(),
|
|
51
|
-
onBlur: jest.fn(),
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
setup(props)
|
|
55
|
-
|
|
56
|
-
fire.blur(screen.getByText('Focusable'))
|
|
57
|
-
expect(props.onBlur).toHaveBeenCalled()
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('does not call onBlur when a non-descendant loses focus', () => {
|
|
61
|
-
const props = {
|
|
62
|
-
onFocus: jest.fn(),
|
|
63
|
-
onBlur: jest.fn(),
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
setup(props)
|
|
67
|
-
|
|
68
|
-
fire.blur(screen.getByText('Ignorable'))
|
|
69
|
-
expect(props.onBlur).not.toHaveBeenCalled()
|
|
70
|
-
})
|
|
71
|
-
})
|