@registrucentras/rc-ses-react-components 2.7.2 → 3.0.0-rc.0
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/assets/icons/phosphorIcons.d.ts +24 -0
- package/dist/components/common/Accordion/hooks/useAccordionController.d.ts +2 -1
- package/dist/components/common/Accordion/index.d.ts +18 -4
- package/dist/components/common/Accordion/types/AccordionControllerState.d.ts +1 -0
- package/dist/components/common/Card/index.d.ts +3 -0
- package/dist/components/common/CheckboxMark/index.d.ts +8 -0
- package/dist/components/common/DataPagination/components/ExpandButton.d.ts +7 -0
- package/dist/components/common/DataPagination/components/PaginationButton.d.ts +2 -1
- package/dist/components/common/DataPagination/index.d.ts +13 -3
- package/dist/components/common/DataPagination/paginationModel.d.ts +4 -0
- package/dist/components/common/Divider/index.d.ts +6 -0
- package/dist/components/common/EmptyState/index.d.ts +21 -0
- package/dist/components/common/IconWithSquareBackground/index.d.ts +2 -2
- package/dist/components/common/ImageCard/index.d.ts +5 -0
- package/dist/components/common/LinkTile/index.d.ts +11 -0
- package/dist/components/common/RadioMark/index.d.ts +8 -0
- package/dist/components/common/StepCard/StepCardFooter/index.d.ts +1 -1
- package/dist/components/common/TitleBlock/types.d.ts +4 -2
- package/dist/components/form/components/FormControlWrapper/index.d.ts +2 -1
- package/dist/components/form/inputs/Datepicker/RangeDatepicker.d.ts +23 -0
- package/dist/components/form/inputs/Datepicker/SingleDatepicker.d.ts +24 -0
- package/dist/components/form/inputs/Datepicker/components/CalendarViewsHeader.d.ts +18 -0
- package/dist/components/form/inputs/Datepicker/index.d.ts +10 -14
- package/dist/components/form/inputs/Datepicker/rangeModel.d.ts +4 -0
- package/dist/components/form/inputs/FileDropzone.d.ts +2 -2
- package/dist/components/form/inputs/RadioButtonGroup.d.ts +1 -0
- package/dist/components/form/inputs/Select/Select.styles.d.ts +84 -0
- package/dist/components/form/inputs/Select/components/OptionCheckbox.d.ts +2 -1
- package/dist/components/form/inputs/TextField.d.ts +27 -12
- package/dist/components/form/inputs/TextField.styles.d.ts +101 -0
- package/dist/components/layout/ServiceWizardStepper/stepperTokens.d.ts +5 -0
- package/dist/components/loaders/Loader/index.d.ts +12 -9
- package/dist/components/overlays/BottomSheet/index.d.ts +3 -2
- package/dist/components/overlays/Dialog/index.d.ts +1 -1
- package/dist/components/storybook/FileUploadTokenPreview.d.ts +4 -0
- package/dist/components/storybook/TabsTokenPreview.d.ts +3 -0
- package/dist/components/storybook/TokenDocs.d.ts +74 -0
- package/dist/library/index.d.ts +30 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +2 -2
- package/dist/registrucentras-rc-ses-react-components.js +11144 -8374
- package/dist/theme/backdropTokens.d.ts +6 -0
- package/dist/theme/borderTokens.d.ts +33 -0
- package/dist/theme/cards.d.ts +42 -73
- package/dist/theme/colorTokens.d.ts +146 -0
- package/dist/theme/effectTokens.d.ts +9 -0
- package/dist/theme/layoutTokens.d.ts +12 -0
- package/dist/theme/light/MuiAccordion.d.ts +2 -2
- package/dist/theme/light/MuiAccordionSummary.d.ts +19 -0
- package/dist/theme/light/MuiButton.d.ts +7 -0
- package/dist/theme/light/MuiInputBase.d.ts +2 -0
- package/dist/theme/light/MuiPickerPopper.d.ts +3 -0
- package/dist/theme/light/MuiTypography.d.ts +0 -14
- package/dist/theme/palette.d.ts +8 -0
- package/dist/theme/sizeTokens.d.ts +20 -0
- package/dist/theme/spacingRoleBasedTokens.d.ts +38 -0
- package/dist/theme/spacingTokens.d.ts +97 -0
- package/dist/theme/tokenTheme.d.ts +13 -0
- package/dist/theme/typographyTokens.d.ts +104 -0
- package/package.json +2 -2
- package/src/assets/icons/phosphorIcons.ts +11 -0
- package/src/components/common/Accordion/hooks/useAccordionController.tsx +39 -7
- package/src/components/common/Accordion/index.test.tsx +132 -0
- package/src/components/common/Accordion/index.tsx +302 -25
- package/src/components/common/Accordion/types/AccordionControllerState.ts +1 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.tsx +3 -3
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.tsx +8 -3
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +3 -2
- package/src/components/common/AdvancedList/components/AdvancedListItemShell/index.test.tsx +3 -3
- package/src/components/common/AdvancedList/components/AdvancedListItemShell/index.tsx +23 -19
- package/src/components/common/AdvancedList/index.test.tsx +4 -2
- package/src/components/common/Alert/index.tsx +10 -6
- package/src/components/common/Badge/index.tsx +50 -37
- package/src/components/common/Button/index.tsx +12 -10
- package/src/components/common/Card/index.tsx +6 -1
- package/src/components/common/CardShell/index.test.tsx +16 -6
- package/src/components/common/CheckboxMark/index.tsx +86 -0
- package/src/components/common/DataPagination/components/DataPaginationSkeleton.tsx +9 -7
- package/src/components/common/DataPagination/components/ExpandButton.tsx +48 -0
- package/src/components/common/DataPagination/components/PaginationButton.tsx +48 -21
- package/src/components/common/DataPagination/index.test.tsx +229 -12
- package/src/components/common/DataPagination/index.tsx +135 -60
- package/src/components/common/DataPagination/paginationModel.ts +35 -0
- package/src/components/common/Divider/index.test.tsx +33 -0
- package/src/components/common/Divider/index.tsx +52 -0
- package/src/components/common/EmptyState/index.test.tsx +56 -0
- package/src/components/common/EmptyState/index.tsx +211 -0
- package/src/components/common/FilterChip/index.tsx +24 -19
- package/src/components/common/IconWithCircularBackground.tsx +24 -6
- package/src/components/common/IconWithSquareBackground/index.test.tsx +14 -2
- package/src/components/common/IconWithSquareBackground/index.tsx +36 -17
- package/src/components/common/ImageCard/index.test.tsx +16 -0
- package/src/components/common/ImageCard/index.tsx +54 -1
- package/src/components/common/LinkTile/index.test.tsx +57 -0
- package/src/components/common/LinkTile/index.tsx +136 -0
- package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +39 -23
- package/src/components/common/ListWithIcons/index.test.tsx +20 -9
- package/src/components/common/ListWithIcons/index.tsx +6 -6
- package/src/components/common/Popover/index.tsx +11 -1
- package/src/components/common/RadioMark/index.tsx +76 -0
- package/src/components/common/SegmentedControl/components/SegmentButton/index.tsx +49 -25
- package/src/components/common/SegmentedControl/index.tsx +10 -6
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +7 -5
- package/src/components/common/SelectableCardList/index.test.tsx +8 -6
- package/src/components/common/SelectionMarks.test.tsx +92 -0
- package/src/components/common/ServiceLinks/ServiceLinkItem/index.tsx +20 -11
- package/src/components/common/ServiceLinks/index.tsx +3 -3
- package/src/components/common/SideNav/SideNavLayout.tsx +6 -1
- package/src/components/common/SideNav/components/SideNavPill.tsx +24 -12
- package/src/components/common/SideNav/components/SideNavPillList.tsx +18 -12
- package/src/components/common/SideNav/components/SideNavRow.tsx +22 -15
- package/src/components/common/SideNav/index.tsx +10 -9
- package/src/components/common/Snackbar/config.ts +27 -8
- package/src/components/common/Snackbar/index.tsx +39 -16
- package/src/components/common/StepCard/StepCardFooter/index.tsx +28 -6
- package/src/components/common/StepCard/index.tsx +18 -6
- package/src/components/common/Switch/index.tsx +10 -4
- package/src/components/common/Tabs/TabPanel.tsx +6 -3
- package/src/components/common/Tabs/TabsWrapper.tsx +15 -7
- package/src/components/common/TitleBlock/index.test.tsx +14 -17
- package/src/components/common/TitleBlock/index.tsx +120 -15
- package/src/components/common/TitleBlock/types.ts +4 -2
- package/src/components/common/Tooltip/index.tsx +32 -3
- package/src/components/form/components/FormControlWrapper/index.tsx +43 -14
- package/src/components/form/inputs/CheckboxFormControl.tsx +25 -13
- package/src/components/form/inputs/Datepicker/RangeDatepicker.tsx +356 -0
- package/src/components/form/inputs/Datepicker/SingleDatepicker.tsx +207 -0
- package/src/components/form/inputs/Datepicker/components/CalendarViewsHeader.tsx +335 -0
- package/src/components/form/inputs/Datepicker/components/RcSesDatepickerCalendarHeader.tsx +22 -10
- package/src/components/form/inputs/Datepicker/index.test.tsx +23 -18
- package/src/components/form/inputs/Datepicker/index.tsx +20 -150
- package/src/components/form/inputs/Datepicker/rangeModel.test.ts +35 -0
- package/src/components/form/inputs/Datepicker/rangeModel.ts +25 -0
- package/src/components/form/inputs/FileDropzone.tsx +73 -46
- package/src/components/form/inputs/FileUpload.tsx +25 -16
- package/src/components/form/inputs/NumberStepper.tsx +36 -14
- package/src/components/form/inputs/PhoneInputFormControl/components/AutocompleteInput.tsx +10 -5
- package/src/components/form/inputs/PhoneInputFormControl/components/ListboxComponent.tsx +7 -1
- package/src/components/form/inputs/PhoneInputFormControl/components/PopperComponent.tsx +5 -2
- package/src/components/form/inputs/PhoneInputFormControl/components/RowComponent.tsx +9 -5
- package/src/components/form/inputs/PhoneInputFormControl/index.tsx +48 -24
- package/src/components/form/inputs/RadioButtonGroup.tsx +14 -6
- package/src/components/form/inputs/Select/Select.styles.ts +76 -0
- package/src/components/form/inputs/Select/components/OptionCheckbox.tsx +6 -33
- package/src/components/form/inputs/Select/index.tsx +124 -86
- package/src/components/form/inputs/SimpleCheckbox.tsx +10 -3
- package/src/components/form/inputs/TextField.presets.test.tsx +284 -0
- package/src/components/form/inputs/TextField.styles.ts +96 -0
- package/src/components/form/inputs/TextField.test.tsx +153 -0
- package/src/components/form/inputs/TextField.tsx +315 -42
- package/src/components/layout/Footer/index.test.tsx +1 -1
- package/src/components/layout/Footer/index.tsx +17 -7
- package/src/components/layout/ServiceFormActions.tsx +5 -1
- package/src/components/layout/ServiceFormContainer/AccordionFormContainer/index.tsx +3 -3
- package/src/components/layout/ServiceHeader.tsx +19 -19
- package/src/components/layout/ServiceWizardStepper/ServiceWizardStepper.css +10 -10
- package/src/components/layout/ServiceWizardStepper/StepConnector.tsx +8 -5
- package/src/components/layout/ServiceWizardStepper/components/CustomStepIcon.tsx +22 -7
- package/src/components/layout/ServiceWizardStepper/components/HorizontalStepperButton.tsx +15 -11
- package/src/components/layout/ServiceWizardStepper/components/StyledStepLabel.tsx +28 -11
- package/src/components/layout/ServiceWizardStepper/stepperTokens.ts +8 -0
- package/src/components/loaders/FullPageLoader/index.test.tsx +18 -7
- package/src/components/loaders/FullPageLoader/index.tsx +14 -9
- package/src/components/loaders/Loader/index.tsx +48 -17
- package/src/components/overlays/BottomSheet/index.test.tsx +36 -3
- package/src/components/overlays/BottomSheet/index.tsx +54 -21
- package/src/components/overlays/Dialog/index.tsx +5 -23
- package/src/components/overlays/Drawer/index.tsx +29 -14
- package/src/components/overlays/Modal/index.tsx +46 -8
- package/src/components/storybook/FileUploadTokenPreview.tsx +68 -0
- package/src/components/storybook/TabsTokenPreview.tsx +58 -0
- package/src/components/storybook/TokenDocs.tsx +347 -0
- package/src/examples/MultipleStepForm/components/TermsAndConditionsForm.tsx +5 -1
- package/src/i18n/namespaces/input/en.json +48 -4
- package/src/i18n/namespaces/input/lt.json +48 -4
- package/src/library/index.ts +50 -0
- package/src/stories/atoms/Badge.stories.tsx +2 -1
- package/src/stories/atoms/Button.stories.tsx +124 -6
- package/src/stories/atoms/CheckboxMark.stories.tsx +79 -0
- package/src/stories/atoms/Divider.stories.tsx +129 -0
- package/src/stories/atoms/FilterChip.stories.tsx +9 -1
- package/src/stories/atoms/IconWithSquareBackground.stories.tsx +7 -7
- package/src/stories/atoms/Icons.stories.tsx +1 -1
- package/src/stories/atoms/NumberStepper.stories.tsx +44 -0
- package/src/stories/atoms/PhoneInput.stories.tsx +42 -0
- package/src/stories/atoms/RadioMark.stories.tsx +132 -0
- package/src/stories/atoms/Select.stories.tsx +139 -2
- package/src/stories/atoms/SimpleCheckbox.stories.tsx +74 -0
- package/src/stories/atoms/Switch.stories.tsx +46 -1
- package/src/stories/atoms/TextField.stories.tsx +508 -0
- package/src/stories/atoms/Tooltip.stories.tsx +5 -0
- package/src/stories/fixtures/foundations/Borders.stories.tsx +84 -0
- package/src/stories/fixtures/foundations/Effects.stories.tsx +204 -0
- package/src/stories/fixtures/foundations/Layout.stories.tsx +76 -0
- package/src/stories/fixtures/foundations/Sizes.stories.tsx +42 -0
- package/src/stories/fixtures/foundations/Spacing.stories.tsx +48 -0
- package/src/stories/fixtures/foundations/Typography.stories.tsx +49 -0
- package/src/stories/foundations/Borders.stories.tsx +179 -0
- package/src/stories/foundations/Colors.stories.tsx +253 -0
- package/src/stories/foundations/Effects.stories.tsx +116 -0
- package/src/stories/foundations/Layout.stories.tsx +177 -0
- package/src/stories/foundations/Sizes.stories.tsx +123 -0
- package/src/stories/foundations/Spacing.stories.tsx +159 -0
- package/src/stories/foundations/ThemeAdapter.stories.tsx +389 -0
- package/src/stories/foundations/Typography.stories.tsx +148 -0
- package/src/stories/molecules/Alert.stories.tsx +18 -0
- package/src/stories/molecules/Breadcrumbs.stories.tsx +51 -0
- package/src/stories/molecules/Card.stories.tsx +1 -1
- package/src/stories/molecules/CardShell.stories.tsx +1 -0
- package/src/stories/molecules/DatePicker.stories.tsx +133 -3
- package/src/stories/molecules/EmptyState.stories.tsx +106 -0
- package/src/stories/molecules/FormControlWrapper.stories.tsx +59 -0
- package/src/stories/molecules/LinkTile.stories.tsx +151 -0
- package/src/stories/molecules/ListWithIcons.stories.tsx +27 -2
- package/src/stories/molecules/RadioButtonGroup.stories.tsx +23 -0
- package/src/stories/molecules/SegmentedControl.stories.tsx +62 -1
- package/src/stories/molecules/Tabs.stories.tsx +4 -0
- package/src/stories/molecules/TitleBlock.stories.tsx +16 -16
- package/src/stories/organisms/Accordion.stories.tsx +132 -0
- package/src/stories/organisms/AdvancedListItemShell.stories.tsx +63 -23
- package/src/stories/organisms/BottomSheet.stories.tsx +48 -1
- package/src/stories/organisms/DataPagination.stories.tsx +127 -3
- package/src/stories/organisms/Dialog.stories.tsx +13 -0
- package/src/stories/organisms/FileDropzone.stories.tsx +6 -0
- package/src/stories/organisms/FileUpload.stories.tsx +4 -0
- package/src/stories/organisms/Footer.stories.tsx +20 -0
- package/src/stories/organisms/Modal.stories.tsx +53 -0
- package/src/stories/organisms/ServiceHeader.stories.tsx +25 -3
- package/src/stories/organisms/ServiceLinks.stories.tsx +1 -1
- package/src/stories/organisms/ServiceWizardStepper.stories.tsx +37 -1
- package/src/stories/organisms/SideNav.stories.tsx +8 -1
- package/src/theme/backdropTokens.test.ts +11 -0
- package/src/theme/backdropTokens.ts +11 -0
- package/src/theme/borderTokens.test.ts +59 -0
- package/src/theme/borderTokens.ts +36 -0
- package/src/theme/cards.ts +28 -28
- package/src/theme/colorTokens.test.ts +66 -0
- package/src/theme/colorTokens.ts +87 -0
- package/src/theme/effectTokens.test.ts +29 -0
- package/src/theme/effectTokens.ts +11 -0
- package/src/theme/layoutTokens.test.ts +42 -0
- package/src/theme/layoutTokens.ts +14 -0
- package/src/theme/light/MuiAccordion.tsx +30 -26
- package/src/theme/light/MuiAccordionDetails.ts +10 -5
- package/src/theme/light/MuiAccordionSummary.tsx +31 -17
- package/src/theme/light/MuiAlert.tsx +42 -65
- package/src/theme/light/MuiAutocomplete.ts +14 -7
- package/src/theme/light/MuiBreadcrumbs.tsx +17 -9
- package/src/theme/light/MuiButton.tsx +213 -204
- package/src/theme/light/MuiCard.tsx +5 -4
- package/src/theme/light/MuiCheckbox.ts +45 -14
- package/src/theme/light/MuiChip.tsx +3 -1
- package/src/theme/light/MuiDialog.ts +45 -6
- package/src/theme/light/MuiFormControl.ts +19 -9
- package/src/theme/light/MuiFormControlLabel.ts +16 -25
- package/src/theme/light/MuiFormGroup.ts +29 -26
- package/src/theme/light/MuiFormHelperText.ts +15 -4
- package/src/theme/light/MuiFormLabel.ts +20 -20
- package/src/theme/light/MuiInputBase.ts +49 -84
- package/src/theme/light/MuiOutlinedInput.ts +50 -6
- package/src/theme/light/MuiPagination.ts +21 -21
- package/src/theme/light/MuiPickerPopper.ts +17 -0
- package/src/theme/light/MuiPickersLayout.ts +63 -34
- package/src/theme/light/MuiPickersOutlinedInput.ts +38 -38
- package/src/theme/light/MuiPopover.ts +3 -1
- package/src/theme/light/MuiRadio.tsx +35 -52
- package/src/theme/light/MuiStepper.ts +21 -17
- package/src/theme/light/MuiSwitch.tsx +27 -23
- package/src/theme/light/MuiTab.tsx +27 -18
- package/src/theme/light/MuiTableCell.ts +4 -2
- package/src/theme/light/MuiTabs.tsx +11 -9
- package/src/theme/light/MuiTooltip.ts +2 -1
- package/src/theme/light/MuiTypography.tsx +0 -17
- package/src/theme/light/index.tsx +2 -0
- package/src/theme/light/themePalette.tsx +1 -0
- package/src/theme/palette.tsx +9 -0
- package/src/theme/sizeTokens.test.ts +37 -0
- package/src/theme/sizeTokens.ts +21 -0
- package/src/theme/spacingRoleBasedTokens.ts +41 -0
- package/src/theme/spacingTokens.test.ts +58 -0
- package/src/theme/spacingTokens.ts +114 -0
- package/src/theme/tokenTheme.test.tsx +402 -0
- package/src/theme/tokenTheme.ts +429 -0
- package/src/theme/tokens.css +476 -0
- package/src/theme/tokens.test.ts +174 -0
- package/src/theme/typographyTokens.test.ts +120 -0
- package/src/theme/typographyTokens.ts +119 -0
- package/dist/theme/spacing.d.ts +0 -4
- package/src/stories/foundations/Colors.mdx +0 -127
- package/src/theme/spacing.ts +0 -5
|
@@ -4,9 +4,11 @@ import { fireEvent, render, screen } from '@testing-library/react'
|
|
|
4
4
|
import { ReactElement } from 'react'
|
|
5
5
|
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
|
6
6
|
|
|
7
|
+
import i18n from '@/i18n/i18n'
|
|
7
8
|
import theme from '@/theme/light'
|
|
8
9
|
|
|
9
10
|
import DataPagination from '.'
|
|
11
|
+
import ExpandButton from './components/ExpandButton'
|
|
10
12
|
|
|
11
13
|
vi.mock('@mui/material', async () => {
|
|
12
14
|
const actual = await vi.importActual<typeof import('@mui/material')>('@mui/material')
|
|
@@ -22,7 +24,8 @@ const renderPagination = (ui: ReactElement) =>
|
|
|
22
24
|
|
|
23
25
|
const mockedUseMediaQuery = vi.mocked(useMediaQuery)
|
|
24
26
|
|
|
25
|
-
beforeEach(() => {
|
|
27
|
+
beforeEach(async () => {
|
|
28
|
+
await i18n.changeLanguage('lt')
|
|
26
29
|
mockedUseMediaQuery.mockReturnValue(false)
|
|
27
30
|
})
|
|
28
31
|
|
|
@@ -101,22 +104,236 @@ describe('DataPagination', () => {
|
|
|
101
104
|
|
|
102
105
|
renderPagination(<DataPagination count={10} defaultPage={1} />)
|
|
103
106
|
|
|
104
|
-
expect(screen.getByRole('button', { name: '
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
expect(screen.getByRole('button', { name: '
|
|
107
|
+
expect(screen.getByRole('button', { name: 'Eiti į 1 puslapį' })).toHaveAttribute(
|
|
108
|
+
'aria-current',
|
|
109
|
+
'page',
|
|
110
|
+
)
|
|
111
|
+
expect(screen.getByRole('button', { name: 'Eiti į 2 puslapį' })).toBeInTheDocument()
|
|
112
|
+
expect(screen.getByRole('button', { name: 'Eiti į 3 puslapį' })).toBeInTheDocument()
|
|
113
|
+
expect(
|
|
114
|
+
screen.queryByRole('button', { name: 'Eiti į 4 puslapį' }),
|
|
115
|
+
).not.toBeInTheDocument()
|
|
116
|
+
expect(screen.getByRole('button', { name: 'Eiti į 10 puslapį' })).toBeInTheDocument()
|
|
109
117
|
})
|
|
110
118
|
|
|
111
|
-
test('shows
|
|
119
|
+
test('shows five initial numeric buttons and the last page on desktop', () => {
|
|
112
120
|
mockedUseMediaQuery.mockReturnValue(false)
|
|
113
121
|
|
|
114
122
|
renderPagination(<DataPagination count={10} defaultPage={1} />)
|
|
115
123
|
|
|
116
|
-
expect(screen.getByRole('button', { name: '
|
|
117
|
-
expect(screen.getByRole('button', { name: '
|
|
118
|
-
expect(
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
expect(screen.getByRole('button', { name: 'Eiti į 1 puslapį' })).toBeInTheDocument()
|
|
125
|
+
expect(screen.getByRole('button', { name: 'Eiti į 5 puslapį' })).toBeInTheDocument()
|
|
126
|
+
expect(
|
|
127
|
+
screen.queryByRole('button', { name: 'Eiti į 6 puslapį' }),
|
|
128
|
+
).not.toBeInTheDocument()
|
|
129
|
+
expect(screen.getByRole('button', { name: 'Eiti į 10 puslapį' })).toBeInTheDocument()
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test.each([0, 1, 10])(
|
|
133
|
+
'hides record pagination for %i records on desktop',
|
|
134
|
+
(totalItems) => {
|
|
135
|
+
renderPagination(<DataPagination totalItems={totalItems} />)
|
|
136
|
+
expect(screen.queryByRole('navigation')).not.toBeInTheDocument()
|
|
137
|
+
},
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
test('ceil-divides records and exposes exactly one current page and disabled semantics', () => {
|
|
141
|
+
renderPagination(<DataPagination totalItems={23} defaultPage={3} />)
|
|
142
|
+
expect(screen.getByRole('navigation', { name: 'Puslapiavimas' })).toBeInTheDocument()
|
|
143
|
+
expect(screen.getByRole('button', { name: 'Eiti į 3 puslapį' })).toHaveAttribute(
|
|
144
|
+
'aria-current',
|
|
145
|
+
'page',
|
|
146
|
+
)
|
|
147
|
+
expect(document.querySelectorAll('[aria-current="page"]')).toHaveLength(1)
|
|
148
|
+
expect(
|
|
149
|
+
screen.queryByRole('button', { name: 'Eiti į 4 puslapį' }),
|
|
150
|
+
).not.toBeInTheDocument()
|
|
151
|
+
expect(screen.getByRole('button', { name: 'Kitas puslapis' })).toBeDisabled()
|
|
152
|
+
expect(screen.getByRole('button', { name: 'Kitas puslapis' })).toHaveAttribute(
|
|
153
|
+
'aria-disabled',
|
|
154
|
+
'true',
|
|
155
|
+
)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('uses five records per mobile page and supports independent service overrides', () => {
|
|
159
|
+
mockedUseMediaQuery.mockReturnValue(true)
|
|
160
|
+
const view = renderPagination(<DataPagination totalItems={11} desktopPageSize={3} />)
|
|
161
|
+
expect(screen.getByRole('button', { name: 'Eiti į 3 puslapį' })).toBeInTheDocument()
|
|
162
|
+
expect(
|
|
163
|
+
screen.queryByRole('button', { name: 'Eiti į 4 puslapį' }),
|
|
164
|
+
).not.toBeInTheDocument()
|
|
165
|
+
view.rerender(
|
|
166
|
+
<ThemeProvider theme={theme}>
|
|
167
|
+
<DataPagination totalItems={11} desktopPageSize={3} mobilePageSize={2} />
|
|
168
|
+
</ThemeProvider>,
|
|
169
|
+
)
|
|
170
|
+
expect(screen.getByRole('button', { name: 'Eiti į 6 puslapį' })).toBeInTheDocument()
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
test('preserves the first visible record across controlled breakpoint changes and reports size/page once', () => {
|
|
174
|
+
const onChange = vi.fn()
|
|
175
|
+
const onPageSizeChange = vi.fn()
|
|
176
|
+
const renderView = (page: number) => (
|
|
177
|
+
<ThemeProvider theme={theme}>
|
|
178
|
+
<DataPagination
|
|
179
|
+
totalItems={100}
|
|
180
|
+
page={page}
|
|
181
|
+
onChange={onChange}
|
|
182
|
+
onPageSizeChange={onPageSizeChange}
|
|
183
|
+
/>
|
|
184
|
+
</ThemeProvider>
|
|
185
|
+
)
|
|
186
|
+
const view = render(renderView(4))
|
|
187
|
+
mockedUseMediaQuery.mockReturnValue(true)
|
|
188
|
+
view.rerender(renderView(4))
|
|
189
|
+
expect(screen.getByRole('button', { name: 'Eiti į 7 puslapį' })).toHaveAttribute(
|
|
190
|
+
'aria-current',
|
|
191
|
+
'page',
|
|
192
|
+
)
|
|
193
|
+
expect(onChange).toHaveBeenCalledExactlyOnceWith(7)
|
|
194
|
+
expect(onPageSizeChange).toHaveBeenCalledExactlyOnceWith(5, 7)
|
|
195
|
+
view.rerender(renderView(7))
|
|
196
|
+
expect(onChange).toHaveBeenCalledTimes(1)
|
|
197
|
+
mockedUseMediaQuery.mockReturnValue(false)
|
|
198
|
+
view.rerender(renderView(7))
|
|
199
|
+
expect(screen.getByRole('button', { name: 'Eiti į 4 puslapį' })).toHaveAttribute(
|
|
200
|
+
'aria-current',
|
|
201
|
+
'page',
|
|
202
|
+
)
|
|
203
|
+
expect(onPageSizeChange).toHaveBeenLastCalledWith(10, 4)
|
|
204
|
+
expect(onChange).toHaveBeenLastCalledWith(4)
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
test('remaps an uncontrolled page when service sizes change and clamps a reduced total', () => {
|
|
208
|
+
const view = renderPagination(
|
|
209
|
+
<DataPagination totalItems={100} desktopPageSize={4} defaultPage={6} />,
|
|
210
|
+
)
|
|
211
|
+
view.rerender(
|
|
212
|
+
<ThemeProvider theme={theme}>
|
|
213
|
+
<DataPagination totalItems={100} desktopPageSize={10} defaultPage={6} />
|
|
214
|
+
</ThemeProvider>,
|
|
215
|
+
)
|
|
216
|
+
expect(screen.getByRole('button', { name: 'Eiti į 3 puslapį' })).toHaveAttribute(
|
|
217
|
+
'aria-current',
|
|
218
|
+
'page',
|
|
219
|
+
)
|
|
220
|
+
view.rerender(
|
|
221
|
+
<ThemeProvider theme={theme}>
|
|
222
|
+
<DataPagination totalItems={12} desktopPageSize={10} />
|
|
223
|
+
</ThemeProvider>,
|
|
224
|
+
)
|
|
225
|
+
expect(screen.getByRole('button', { name: 'Eiti į 2 puslapį' })).toHaveAttribute(
|
|
226
|
+
'aria-current',
|
|
227
|
+
'page',
|
|
228
|
+
)
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
test('legacy page counts do not remap on resize', () => {
|
|
232
|
+
const onChange = vi.fn()
|
|
233
|
+
const view = renderPagination(
|
|
234
|
+
<DataPagination count={10} defaultPage={4} onChange={onChange} />,
|
|
235
|
+
)
|
|
236
|
+
mockedUseMediaQuery.mockReturnValue(true)
|
|
237
|
+
view.rerender(
|
|
238
|
+
<ThemeProvider theme={theme}>
|
|
239
|
+
<DataPagination count={10} defaultPage={4} onChange={onChange} />
|
|
240
|
+
</ThemeProvider>,
|
|
241
|
+
)
|
|
242
|
+
expect(screen.getByRole('button', { name: 'Eiti į 4 puslapį' })).toHaveAttribute(
|
|
243
|
+
'aria-current',
|
|
244
|
+
'page',
|
|
245
|
+
)
|
|
246
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
test('round-trip resizing retains a record whose index is not aligned to the larger page size', () => {
|
|
250
|
+
mockedUseMediaQuery.mockReturnValue(true)
|
|
251
|
+
const view = renderPagination(<DataPagination totalItems={100} defaultPage={4} />)
|
|
252
|
+
mockedUseMediaQuery.mockReturnValue(false)
|
|
253
|
+
view.rerender(
|
|
254
|
+
<ThemeProvider theme={theme}>
|
|
255
|
+
<DataPagination totalItems={100} defaultPage={4} />
|
|
256
|
+
</ThemeProvider>,
|
|
257
|
+
)
|
|
258
|
+
expect(screen.getByRole('button', { name: 'Eiti į 2 puslapį' })).toHaveAttribute(
|
|
259
|
+
'aria-current',
|
|
260
|
+
'page',
|
|
261
|
+
)
|
|
262
|
+
mockedUseMediaQuery.mockReturnValue(true)
|
|
263
|
+
view.rerender(
|
|
264
|
+
<ThemeProvider theme={theme}>
|
|
265
|
+
<DataPagination totalItems={100} defaultPage={4} />
|
|
266
|
+
</ThemeProvider>,
|
|
267
|
+
)
|
|
268
|
+
expect(screen.getByRole('button', { name: 'Eiti į 4 puslapį' })).toHaveAttribute(
|
|
269
|
+
'aria-current',
|
|
270
|
+
'page',
|
|
271
|
+
)
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
test('desktop ellipses retain first, last and two neighbouring pages', () => {
|
|
275
|
+
renderPagination(<DataPagination count={20} defaultPage={10} />)
|
|
276
|
+
expect(
|
|
277
|
+
screen
|
|
278
|
+
.getAllByRole('button', { name: /Eiti į/ })
|
|
279
|
+
.map((button) => button.textContent),
|
|
280
|
+
).toEqual(['1', '8', '9', '10', '11', '12', '20'])
|
|
281
|
+
expect(document.querySelectorAll('.MuiPaginationItem-ellipsis')).toHaveLength(2)
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
test('loading only follows the network flag and restores the selected page', () => {
|
|
285
|
+
const view = renderPagination(
|
|
286
|
+
<DataPagination totalItems={100} defaultPage={4} isLoading />,
|
|
287
|
+
)
|
|
288
|
+
expect(screen.getByRole('navigation')).toHaveAttribute('aria-busy', 'true')
|
|
289
|
+
expect(screen.getByRole('status', { name: 'Įkeliami įrašai' })).toBeInTheDocument()
|
|
290
|
+
expect(screen.queryByRole('button')).not.toBeInTheDocument()
|
|
291
|
+
view.rerender(
|
|
292
|
+
<ThemeProvider theme={theme}>
|
|
293
|
+
<DataPagination totalItems={100} defaultPage={4} />
|
|
294
|
+
</ThemeProvider>,
|
|
295
|
+
)
|
|
296
|
+
expect(screen.getByRole('button', { name: 'Eiti į 4 puslapį' })).toHaveAttribute(
|
|
297
|
+
'aria-current',
|
|
298
|
+
'page',
|
|
299
|
+
)
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
test('invalid sizes fall back to defaults and clicking the active page does not emit', () => {
|
|
303
|
+
const onChange = vi.fn()
|
|
304
|
+
renderPagination(
|
|
305
|
+
<DataPagination
|
|
306
|
+
totalItems={11}
|
|
307
|
+
desktopPageSize={0}
|
|
308
|
+
mobilePageSize={NaN}
|
|
309
|
+
onChange={onChange}
|
|
310
|
+
/>,
|
|
311
|
+
)
|
|
312
|
+
expect(screen.getByRole('button', { name: 'Eiti į 2 puslapį' })).toBeInTheDocument()
|
|
313
|
+
fireEvent.click(screen.getByRole('button', { name: 'Eiti į 1 puslapį' }))
|
|
314
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
test('ExpandButton is a labelled, controlled alternative with expanded semantics', () => {
|
|
318
|
+
mockedUseMediaQuery.mockReturnValue(true)
|
|
319
|
+
const onClick = vi.fn()
|
|
320
|
+
const view = renderPagination(
|
|
321
|
+
<ExpandButton expanded={false} aria-controls='records' onClick={onClick} />,
|
|
322
|
+
)
|
|
323
|
+
const button = screen.getByRole('button', { name: 'Rodyti daugiau' })
|
|
324
|
+
expect(button).toHaveAttribute('aria-expanded', 'false')
|
|
325
|
+
expect(button).toHaveAttribute('aria-controls', 'records')
|
|
326
|
+
fireEvent.click(button)
|
|
327
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
328
|
+
view.rerender(
|
|
329
|
+
<ThemeProvider theme={theme}>
|
|
330
|
+
<ExpandButton expanded aria-controls='records' />
|
|
331
|
+
</ThemeProvider>,
|
|
332
|
+
)
|
|
333
|
+
expect(screen.getByRole('button', { name: 'Rodyti mažiau' })).toHaveAttribute(
|
|
334
|
+
'aria-expanded',
|
|
335
|
+
'true',
|
|
336
|
+
)
|
|
337
|
+
expect(screen.queryByRole('navigation')).not.toBeInTheDocument()
|
|
121
338
|
})
|
|
122
339
|
})
|
|
@@ -1,97 +1,172 @@
|
|
|
1
|
-
import { Box,
|
|
2
|
-
import { useState } from 'react'
|
|
1
|
+
import { Box, PaginationItem, useMediaQuery, useTheme } from '@mui/material'
|
|
2
|
+
import { useEffect, useRef, useState } from 'react'
|
|
3
|
+
import { useTranslation } from 'react-i18next'
|
|
3
4
|
|
|
4
5
|
import { ArrowLeftIcon, ArrowRightIcon } from '@/assets/icons/phosphorIcons'
|
|
6
|
+
import '@/i18n/i18n'
|
|
7
|
+
import { spacingTokens } from '@/theme/spacingTokens'
|
|
5
8
|
|
|
6
9
|
import DataPaginationSkeleton from './components/DataPaginationSkeleton'
|
|
7
10
|
import PaginationButton from './components/PaginationButton'
|
|
11
|
+
import { clampPage, getPaginationItems, positivePageSize } from './paginationModel'
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
count: number
|
|
13
|
+
interface PaginationOptions {
|
|
11
14
|
page?: number
|
|
12
15
|
defaultPage?: number
|
|
13
16
|
onChange?: (page: number) => void
|
|
17
|
+
desktopPageSize?: number
|
|
18
|
+
mobilePageSize?: number
|
|
19
|
+
onPageSizeChange?: (pageSize: number, page: number) => void
|
|
14
20
|
prevLabel?: string
|
|
15
21
|
nextLabel?: string
|
|
16
22
|
isLoading?: boolean
|
|
23
|
+
ariaLabel?: string
|
|
17
24
|
}
|
|
18
25
|
|
|
26
|
+
export type DataPaginationProps = PaginationOptions &
|
|
27
|
+
({ totalItems: number; count?: never } | { count: number; totalItems?: never })
|
|
28
|
+
|
|
19
29
|
const DataPagination = ({
|
|
20
30
|
count,
|
|
31
|
+
totalItems,
|
|
32
|
+
desktopPageSize,
|
|
33
|
+
mobilePageSize,
|
|
34
|
+
onPageSizeChange,
|
|
21
35
|
page,
|
|
22
36
|
defaultPage = 1,
|
|
23
37
|
onChange,
|
|
24
|
-
prevLabel
|
|
25
|
-
nextLabel
|
|
38
|
+
prevLabel,
|
|
39
|
+
nextLabel,
|
|
26
40
|
isLoading = false,
|
|
41
|
+
ariaLabel,
|
|
27
42
|
}: DataPaginationProps) => {
|
|
28
43
|
const theme = useTheme()
|
|
29
44
|
const isMobile = useMediaQuery(theme.breakpoints.down('md'))
|
|
30
|
-
const
|
|
31
|
-
const
|
|
45
|
+
const { t } = useTranslation('input', { keyPrefix: 'components.DataPagination' })
|
|
46
|
+
const pageSize = isMobile
|
|
47
|
+
? positivePageSize(mobilePageSize, 5)
|
|
48
|
+
: positivePageSize(desktopPageSize, 10)
|
|
49
|
+
const rawCount = totalItems !== undefined ? Math.ceil(totalItems / pageSize) : count
|
|
50
|
+
const pageCount = Number.isFinite(rawCount) ? Math.max(0, Math.floor(rawCount)) : 0
|
|
51
|
+
const [state, setState] = useState({
|
|
52
|
+
page: page ?? defaultPage,
|
|
53
|
+
externalPage: page,
|
|
54
|
+
pageSize,
|
|
55
|
+
firstItemIndex: (clampPage(page ?? defaultPage, pageCount) - 1) * pageSize,
|
|
56
|
+
})
|
|
32
57
|
|
|
33
|
-
|
|
58
|
+
let nextPage = page !== state.externalPage ? (page ?? state.page) : state.page
|
|
59
|
+
let { firstItemIndex } = state
|
|
60
|
+
if (page !== state.externalPage && nextPage !== state.page)
|
|
61
|
+
firstItemIndex = (clampPage(nextPage, pageCount) - 1) * pageSize
|
|
62
|
+
if (totalItems !== undefined && state.pageSize !== pageSize)
|
|
63
|
+
nextPage = Math.floor(firstItemIndex / pageSize) + 1
|
|
64
|
+
const currentPage = clampPage(nextPage, pageCount)
|
|
65
|
+
if (currentPage !== nextPage) firstItemIndex = (currentPage - 1) * pageSize
|
|
34
66
|
|
|
35
|
-
|
|
36
|
-
|
|
67
|
+
if (
|
|
68
|
+
state.page !== currentPage ||
|
|
69
|
+
state.externalPage !== page ||
|
|
70
|
+
state.pageSize !== pageSize ||
|
|
71
|
+
state.firstItemIndex !== firstItemIndex
|
|
72
|
+
)
|
|
73
|
+
setState({ page: currentPage, externalPage: page, pageSize, firstItemIndex })
|
|
37
74
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
75
|
+
const committed = useRef({ page: currentPage, pageSize, pageCount })
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
const previous = committed.current
|
|
78
|
+
committed.current = { page: currentPage, pageSize, pageCount }
|
|
79
|
+
const sizeChanged = totalItems !== undefined && previous.pageSize !== pageSize
|
|
80
|
+
if (sizeChanged) onPageSizeChange?.(pageSize, currentPage)
|
|
81
|
+
if (
|
|
82
|
+
(sizeChanged || previous.pageCount !== pageCount) &&
|
|
83
|
+
previous.page !== currentPage
|
|
84
|
+
)
|
|
85
|
+
onChange?.(currentPage)
|
|
86
|
+
}, [currentPage, pageSize, pageCount, totalItems, onChange, onPageSizeChange])
|
|
41
87
|
|
|
88
|
+
const handlePageChange = (newPage: number) => {
|
|
89
|
+
if (isLoading || newPage < 1 || newPage > pageCount || newPage === currentPage) return
|
|
90
|
+
if (page === undefined)
|
|
91
|
+
setState({ ...state, page: newPage, firstItemIndex: (newPage - 1) * pageSize })
|
|
42
92
|
onChange?.(newPage)
|
|
43
93
|
}
|
|
44
94
|
|
|
45
|
-
if (isLoading)
|
|
46
|
-
return (
|
|
47
|
-
<Box
|
|
48
|
-
sx={{
|
|
49
|
-
display: 'flex',
|
|
50
|
-
alignItems: 'center',
|
|
51
|
-
gap: 1,
|
|
52
|
-
}}
|
|
53
|
-
>
|
|
54
|
-
<DataPaginationSkeleton isMobile={isMobile} />
|
|
55
|
-
</Box>
|
|
56
|
-
)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const hidePagination = count <= 1
|
|
60
|
-
|
|
61
|
-
if (hidePagination) {
|
|
62
|
-
return null
|
|
63
|
-
}
|
|
95
|
+
if (pageCount <= 1 && (!isLoading || totalItems !== undefined)) return null
|
|
64
96
|
|
|
65
97
|
return (
|
|
66
98
|
<Box
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
gap: 1,
|
|
71
|
-
}}
|
|
99
|
+
component='nav'
|
|
100
|
+
aria-label={ariaLabel ?? t('navigation')}
|
|
101
|
+
aria-busy={isLoading || undefined}
|
|
72
102
|
>
|
|
73
|
-
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
{isLoading ? (
|
|
104
|
+
<Box
|
|
105
|
+
role='status'
|
|
106
|
+
aria-label={t('loading')}
|
|
107
|
+
sx={{
|
|
108
|
+
display: 'flex',
|
|
109
|
+
gap: { xs: 0, md: spacingTokens['spacing-aliases-pagination-button-gap'] },
|
|
110
|
+
}}
|
|
111
|
+
>
|
|
112
|
+
<DataPaginationSkeleton isMobile={isMobile} />
|
|
113
|
+
</Box>
|
|
114
|
+
) : (
|
|
115
|
+
<Box
|
|
116
|
+
component='ul'
|
|
117
|
+
sx={{
|
|
118
|
+
display: 'flex',
|
|
119
|
+
alignItems: 'center',
|
|
120
|
+
flexWrap: 'nowrap',
|
|
121
|
+
listStyle: 'none',
|
|
122
|
+
p: 0,
|
|
123
|
+
m: 0,
|
|
124
|
+
gap: spacingTokens['spacing-aliases-pagination-button-gap'],
|
|
125
|
+
'@media (max-width: 359px)': { gap: 0 },
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
<Box component='li'>
|
|
129
|
+
<PaginationButton
|
|
130
|
+
onClick={() => handlePageChange(currentPage - 1)}
|
|
131
|
+
disabled={currentPage === 1}
|
|
132
|
+
aria-label={prevLabel ?? t('previous')}
|
|
133
|
+
label={prevLabel ?? t('previousText')}
|
|
134
|
+
icon={<ArrowLeftIcon size={16} aria-hidden />}
|
|
135
|
+
/>
|
|
136
|
+
</Box>
|
|
137
|
+
{getPaginationItems(pageCount, currentPage, isMobile).map((item) => (
|
|
138
|
+
<Box
|
|
139
|
+
component='li'
|
|
140
|
+
key={item}
|
|
141
|
+
aria-hidden={typeof item !== 'number' || undefined}
|
|
142
|
+
>
|
|
143
|
+
{typeof item === 'number' ? (
|
|
144
|
+
<PaginationItem
|
|
145
|
+
type='page'
|
|
146
|
+
page={item}
|
|
147
|
+
selected={item === currentPage}
|
|
148
|
+
aria-label={t('page', { page: item })}
|
|
149
|
+
aria-current={item === currentPage ? 'page' : undefined}
|
|
150
|
+
onClick={() => handlePageChange(item)}
|
|
151
|
+
sx={{ minWidth: 40, width: 40, p: 0 }}
|
|
152
|
+
/>
|
|
153
|
+
) : (
|
|
154
|
+
<PaginationItem type={item} />
|
|
155
|
+
)}
|
|
156
|
+
</Box>
|
|
157
|
+
))}
|
|
158
|
+
<Box component='li'>
|
|
159
|
+
<PaginationButton
|
|
160
|
+
onClick={() => handlePageChange(currentPage + 1)}
|
|
161
|
+
disabled={currentPage === pageCount}
|
|
162
|
+
aria-label={nextLabel ?? t('next')}
|
|
163
|
+
label={nextLabel ?? t('nextText')}
|
|
164
|
+
icon={<ArrowRightIcon size={16} aria-hidden />}
|
|
165
|
+
iconPosition='end'
|
|
166
|
+
/>
|
|
167
|
+
</Box>
|
|
168
|
+
</Box>
|
|
169
|
+
)}
|
|
95
170
|
</Box>
|
|
96
171
|
)
|
|
97
172
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type PaginationItem = number | 'start-ellipsis' | 'end-ellipsis'
|
|
2
|
+
|
|
3
|
+
export const positivePageSize = (value: number | undefined, fallback: number) =>
|
|
4
|
+
value !== undefined && Number.isFinite(value) && value >= 1
|
|
5
|
+
? Math.floor(value)
|
|
6
|
+
: fallback
|
|
7
|
+
|
|
8
|
+
export const clampPage = (page: number, count: number) =>
|
|
9
|
+
Math.max(1, Math.min(Number.isFinite(page) ? Math.floor(page) : 1, Math.max(1, count)))
|
|
10
|
+
|
|
11
|
+
export function getPaginationItems(
|
|
12
|
+
count: number,
|
|
13
|
+
page: number,
|
|
14
|
+
mobile: boolean,
|
|
15
|
+
): PaginationItem[] {
|
|
16
|
+
if (count <= (mobile ? 5 : 7)) return Array.from({ length: count }, (_, i) => i + 1)
|
|
17
|
+
|
|
18
|
+
let visible: number[]
|
|
19
|
+
if (mobile) {
|
|
20
|
+
if (page <= 3) visible = [1, 2, 3, count]
|
|
21
|
+
else if (page >= count - 2) visible = [1, count - 2, count - 1, count]
|
|
22
|
+
else visible = [1, page, count]
|
|
23
|
+
} else {
|
|
24
|
+
const start = Math.max(1, Math.min(page - 2, count - 4))
|
|
25
|
+
visible = [...new Set([1, ...Array.from({ length: 5 }, (_, i) => start + i), count])]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const items: PaginationItem[] = []
|
|
29
|
+
visible.forEach((number, index) => {
|
|
30
|
+
if (index > 0 && number - visible[index - 1] > 1)
|
|
31
|
+
items.push(number <= page ? 'start-ellipsis' : 'end-ellipsis')
|
|
32
|
+
items.push(number)
|
|
33
|
+
})
|
|
34
|
+
return items
|
|
35
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react'
|
|
2
|
+
import { describe, expect, test } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import RcSesDivider from '.'
|
|
5
|
+
|
|
6
|
+
describe('Divider', () => {
|
|
7
|
+
test('decoration is hidden without an implicit separator role', () => {
|
|
8
|
+
const { container } = render(<RcSesDivider />)
|
|
9
|
+
expect(container.firstChild).toHaveAttribute('aria-hidden', 'true')
|
|
10
|
+
expect(screen.queryByRole('separator')).not.toBeInTheDocument()
|
|
11
|
+
expect(container.querySelector('hr')).not.toBeInTheDocument()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('semantic separator exposes its accessible name and horizontal orientation', () => {
|
|
15
|
+
render(<RcSesDivider role='separator' aria-label='Veiksmų grupės' />)
|
|
16
|
+
const separator = screen.getByRole('separator', { name: 'Veiksmų grupės' })
|
|
17
|
+
expect(separator).toHaveAttribute('aria-orientation', 'horizontal')
|
|
18
|
+
expect(separator).not.toHaveAttribute('aria-hidden')
|
|
19
|
+
expect(separator).not.toHaveAttribute('tabindex')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('works as a list child without adding a focus target', () => {
|
|
23
|
+
const { container } = render(
|
|
24
|
+
<ul>
|
|
25
|
+
<li>Pirma grupė</li>
|
|
26
|
+
<RcSesDivider component='li' inset={16} />
|
|
27
|
+
<li>Antra grupė</li>
|
|
28
|
+
</ul>,
|
|
29
|
+
)
|
|
30
|
+
expect(screen.queryByRole('separator')).not.toBeInTheDocument()
|
|
31
|
+
expect(container.querySelectorAll('ul > li')).toHaveLength(3)
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Box, BoxProps } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
import normalizeSx from '@/components/utils/normalizeSx'
|
|
4
|
+
import { borderTokens } from '@/theme/borderTokens'
|
|
5
|
+
import { colorTokens } from '@/theme/colorTokens'
|
|
6
|
+
import { spacingRoleBasedTokens } from '@/theme/spacingRoleBasedTokens'
|
|
7
|
+
import '@/theme/tokens.css'
|
|
8
|
+
|
|
9
|
+
export interface DividerProps extends Omit<
|
|
10
|
+
BoxProps,
|
|
11
|
+
'children' | 'role' | 'aria-hidden' | 'aria-orientation'
|
|
12
|
+
> {
|
|
13
|
+
inset?: 'none' | 16
|
|
14
|
+
role?: 'separator'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default function RcSesDivider({
|
|
18
|
+
inset = 'none',
|
|
19
|
+
role,
|
|
20
|
+
sx,
|
|
21
|
+
...props
|
|
22
|
+
}: DividerProps) {
|
|
23
|
+
return (
|
|
24
|
+
<Box
|
|
25
|
+
{...props}
|
|
26
|
+
role={role}
|
|
27
|
+
aria-hidden={role === 'separator' ? undefined : true}
|
|
28
|
+
aria-orientation={role === 'separator' ? 'horizontal' : undefined}
|
|
29
|
+
sx={[
|
|
30
|
+
{
|
|
31
|
+
position: 'relative',
|
|
32
|
+
width: '100%',
|
|
33
|
+
height: spacingRoleBasedTokens['space-16'],
|
|
34
|
+
flexShrink: 0,
|
|
35
|
+
margin: 0,
|
|
36
|
+
padding: 0,
|
|
37
|
+
border: 0,
|
|
38
|
+
'&::after': {
|
|
39
|
+
content: '""',
|
|
40
|
+
position: 'absolute',
|
|
41
|
+
top: spacingRoleBasedTokens['space-8'],
|
|
42
|
+
insetInline: spacingRoleBasedTokens[inset === 16 ? 'space-16' : 'space-0'],
|
|
43
|
+
height: borderTokens['stroke-1'],
|
|
44
|
+
backgroundColor: colorTokens['border-subtle'],
|
|
45
|
+
pointerEvents: 'none',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
...normalizeSx(sx),
|
|
49
|
+
]}
|
|
50
|
+
/>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
3
|
+
import { describe, expect, test, vi } from 'vitest'
|
|
4
|
+
|
|
5
|
+
import theme from '@/theme/light'
|
|
6
|
+
|
|
7
|
+
import RcSesEmptyState from '.'
|
|
8
|
+
|
|
9
|
+
const content = { title: 'Nėra rezultatų', description: 'Pakeiskite paiešką' }
|
|
10
|
+
|
|
11
|
+
describe('EmptyState', () => {
|
|
12
|
+
test('uses the requested heading hierarchy and associates the region', () => {
|
|
13
|
+
render(<RcSesEmptyState {...content} headingLevel={3} />)
|
|
14
|
+
expect(screen.getByRole('heading', { level: 3 })).toHaveTextContent(content.title)
|
|
15
|
+
expect(screen.getByRole('region', { name: content.title })).toBeInTheDocument()
|
|
16
|
+
expect(screen.getByRole('status')).toBeEmptyDOMElement()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('announces only warning/error when requested and clears stale announcements', async () => {
|
|
20
|
+
const { rerender } = render(<RcSesEmptyState {...content} type='error' />)
|
|
21
|
+
expect(screen.getByRole('status')).toBeEmptyDOMElement()
|
|
22
|
+
rerender(<RcSesEmptyState {...content} type='error' announce />)
|
|
23
|
+
await waitFor(() =>
|
|
24
|
+
expect(screen.getByRole('status')).toHaveTextContent(
|
|
25
|
+
`${content.title}. ${content.description}`,
|
|
26
|
+
),
|
|
27
|
+
)
|
|
28
|
+
rerender(<RcSesEmptyState {...content} type='info' announce />)
|
|
29
|
+
expect(screen.getByRole('status')).toBeEmptyDOMElement()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('compact hides hints; showAction hides the duplicate action', () => {
|
|
33
|
+
const onClick = vi.fn()
|
|
34
|
+
const { rerender } = render(
|
|
35
|
+
<ThemeProvider theme={theme}>
|
|
36
|
+
<RcSesEmptyState
|
|
37
|
+
{...content}
|
|
38
|
+
size='compact'
|
|
39
|
+
hint='Patarimas'
|
|
40
|
+
action={{ label: 'Ieškoti', onClick }}
|
|
41
|
+
/>
|
|
42
|
+
</ThemeProvider>,
|
|
43
|
+
)
|
|
44
|
+
expect(screen.queryByText('Patarimas')).not.toBeInTheDocument()
|
|
45
|
+
fireEvent.click(screen.getByRole('button', { name: 'Ieškoti' }))
|
|
46
|
+
expect(onClick).toHaveBeenCalledOnce()
|
|
47
|
+
rerender(
|
|
48
|
+
<RcSesEmptyState
|
|
49
|
+
{...content}
|
|
50
|
+
showAction={false}
|
|
51
|
+
action={{ label: 'Ieškoti', onClick }}
|
|
52
|
+
/>,
|
|
53
|
+
)
|
|
54
|
+
expect(screen.queryByRole('button')).not.toBeInTheDocument()
|
|
55
|
+
})
|
|
56
|
+
})
|