@registrucentras/rc-ses-react-components 1.3.1 → 1.4.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 +3 -1
- package/dist/assets/IconProps.d.ts +4 -2
- package/dist/assets/icons/ArrowLeftIcon.d.ts +3 -0
- package/dist/assets/icons/ArrowRightIcon.d.ts +1 -1
- package/dist/assets/icons/BarcodeIcon.d.ts +3 -0
- package/dist/assets/icons/CalendarBlankIcon.d.ts +1 -1
- package/dist/assets/icons/CaretDoubleLeftBoldIcon.d.ts +1 -1
- package/dist/assets/icons/CaretDoubleRightBoldIcon.d.ts +1 -1
- package/dist/assets/icons/CaretDownBoldIcon.d.ts +1 -1
- package/dist/assets/icons/CaretDownFill.d.ts +2 -2
- package/dist/assets/icons/CaretDownIcon.d.ts +1 -1
- package/dist/assets/icons/CaretLeftBoldIcon.d.ts +1 -1
- package/dist/assets/icons/CaretLeftIcon.d.ts +1 -1
- package/dist/assets/icons/CaretRightBoldIcon.d.ts +1 -1
- package/dist/assets/icons/CheckBoldIcon.d.ts +1 -1
- package/dist/assets/icons/CheckCircleFillIcon.d.ts +2 -2
- package/dist/assets/icons/CheckUncheckedBoldIcon.d.ts +1 -1
- package/dist/assets/icons/CircleFilledIcon.d.ts +3 -0
- package/dist/assets/icons/CloseIcon.d.ts +1 -1
- package/dist/assets/icons/CollapseChevronsIcon.d.ts +1 -1
- package/dist/assets/icons/DotCircleFilledIcon.d.ts +3 -0
- package/dist/assets/icons/ExpandChevronsIcon.d.ts +1 -1
- package/dist/assets/icons/InfoFillIcon.d.ts +1 -1
- package/dist/assets/icons/MagnifyingGlassIcon.d.ts +2 -2
- package/dist/assets/icons/MapPinAreaIcon.d.ts +3 -0
- package/dist/assets/icons/MinusBoldIcon.d.ts +1 -1
- package/dist/assets/icons/PlusBoldIcon.d.ts +1 -1
- package/dist/assets/icons/QuestionFillIcon.d.ts +1 -1
- package/dist/assets/icons/QuestionIcon.d.ts +1 -1
- package/dist/assets/icons/ScalesIcon.d.ts +3 -0
- package/dist/assets/icons/ScrollIcon.d.ts +1 -1
- package/dist/assets/icons/SpinnerGapBoldIcon.d.ts +1 -1
- package/dist/assets/icons/UploadSimpleIcon.d.ts +1 -1
- package/dist/assets/icons/WarningDiamondFillIcon.d.ts +1 -1
- package/dist/assets/icons/WarningFillIcon.d.ts +1 -1
- package/dist/assets/icons/XCircleFillIcon.d.ts +2 -2
- package/dist/components/common/Button/index.d.ts +2 -2
- package/dist/components/common/Card/index.d.ts +31 -0
- package/dist/components/common/DataPagination/components/PaginationButton.d.ts +8 -0
- package/dist/components/common/DataPagination/index.d.ts +10 -0
- package/dist/components/layout/ServiceFormContainer/{components → AccordionFormContainer/components}/AccordionCollapseControls.d.ts +1 -1
- package/dist/components/layout/ServiceFormContainer/{index.d.ts → AccordionFormContainer/index.d.ts} +1 -1
- package/dist/components/layout/ServiceFormContainer/AccordionFormContainer/utils.d.ts +4 -0
- package/dist/components/layout/ServiceFormContainer/CardFormContainer/index.d.ts +11 -0
- package/dist/components/layout/ServiceWizardStepper/StepConnector.d.ts +7 -0
- package/dist/components/layout/ServiceWizardStepper/StepperTypes.d.ts +7 -0
- package/dist/components/layout/ServiceWizardStepper/components/CustomStepIcon.d.ts +3 -0
- package/dist/components/layout/ServiceWizardStepper/components/DesktopStepper.d.ts +10 -0
- package/dist/components/layout/ServiceWizardStepper/components/HorizontalStepperButton.d.ts +6 -0
- package/dist/components/layout/ServiceWizardStepper/components/MobileStepper.d.ts +8 -0
- package/dist/components/layout/ServiceWizardStepper/components/StyledStepLabel.d.ts +11 -0
- package/dist/components/layout/ServiceWizardStepper/index.d.ts +8 -5
- package/dist/library/icons.d.ts +27 -3
- package/dist/library/index.d.ts +12 -4
- package/dist/library/types.d.ts +4 -0
- package/dist/registrucentras-rc-ses-react-components.cjs +12 -12
- package/dist/registrucentras-rc-ses-react-components.js +3945 -2672
- package/dist/stories/ServiceWizardStepper.stories.d.ts +7 -0
- package/dist/stories/components/Accordion.stories.d.ts +2 -2
- package/dist/stories/components/Card.stories.d.ts +24 -0
- package/dist/stories/components/DataPagination.stories.d.ts +47 -0
- package/dist/stories/components/Icons.stories.d.ts +6 -0
- package/dist/stories/components/buttons/Button.stories.d.ts +10 -0
- package/dist/stories/components/form/CardFormContainer.stories.d.ts +7 -0
- package/dist/stories/components/form/CheckboxFormControl.stories.d.ts +2 -2
- package/dist/stories/components/form/ServiceFormContainer.stories.d.ts +1 -1
- package/dist/stories/components/inputs/Checkbox.stories.d.ts +2 -2
- package/dist/stories/components/inputs/FileUpload.stories.d.ts +2 -2
- package/dist/stories/components/inputs/NumberStepper.stories.d.ts +2 -2
- package/dist/stories/components/inputs/SearchableField.stories.d.ts +60 -60
- package/dist/stories/components/inputs/Select.stories.d.ts +126 -126
- package/dist/stories/components/inputs/TextField.stories.d.ts +113 -113
- package/dist/theme/light/MuiPagination.d.ts +2 -1
- package/package.json +2 -1
- package/src/App.tsx +12 -0
- package/src/assets/IconProps.ts +5 -2
- package/src/assets/icons/ArrowLeftIcon.tsx +16 -0
- package/src/assets/icons/ArrowRightIcon.tsx +8 -13
- package/src/assets/icons/BarcodeIcon.tsx +9 -0
- package/src/assets/icons/CalendarBlankIcon.tsx +4 -16
- package/src/assets/icons/CaretDoubleLeftBoldIcon.tsx +14 -12
- package/src/assets/icons/CaretDoubleRightBoldIcon.tsx +14 -12
- package/src/assets/icons/CaretDownBoldIcon.tsx +9 -12
- package/src/assets/icons/CaretDownFill.tsx +11 -10
- package/src/assets/icons/CaretDownIcon.tsx +4 -16
- package/src/assets/icons/CaretLeftBoldIcon.tsx +9 -12
- package/src/assets/icons/CaretLeftIcon.tsx +4 -16
- package/src/assets/icons/CaretRightBoldIcon.tsx +9 -12
- package/src/assets/icons/CheckBoldIcon.tsx +9 -24
- package/src/assets/icons/CheckCircleFillIcon.tsx +10 -14
- package/src/assets/icons/CheckUncheckedBoldIcon.tsx +4 -23
- package/src/assets/icons/CircleFilledIcon.tsx +11 -0
- package/src/assets/icons/CloseIcon.tsx +4 -16
- package/src/assets/icons/CollapseChevronsIcon.tsx +9 -13
- package/src/assets/icons/DotCircleFilledIcon.tsx +23 -0
- package/src/assets/icons/ExpandChevronsIcon.tsx +9 -13
- package/src/assets/icons/InfoFillIcon.tsx +4 -14
- package/src/assets/icons/MagnifyingGlassIcon.tsx +5 -12
- package/src/assets/icons/MapPinAreaIcon.tsx +9 -0
- package/src/assets/icons/MinusBoldIcon.tsx +4 -14
- package/src/assets/icons/PlusBoldIcon.tsx +4 -14
- package/src/assets/icons/QuestionFillIcon.tsx +9 -13
- package/src/assets/icons/QuestionIcon.tsx +4 -16
- package/src/assets/icons/ScalesIcon.tsx +9 -0
- package/src/assets/icons/ScrollIcon.tsx +4 -16
- package/src/assets/icons/SpinnerGapBoldIcon.tsx +9 -12
- package/src/assets/icons/UploadSimpleIcon.tsx +4 -16
- package/src/assets/icons/WarningDiamondFillIcon.tsx +9 -13
- package/src/assets/icons/WarningFillIcon.tsx +9 -13
- package/src/assets/icons/XCircleFillIcon.tsx +11 -10
- package/src/components/common/Button/index.tsx +34 -3
- package/src/components/common/Card/index.test.tsx +136 -0
- package/src/components/common/Card/index.tsx +231 -0
- package/src/components/common/DataPagination/components/PaginationButton.tsx +63 -0
- package/src/components/common/DataPagination/index.test.tsx +122 -0
- package/src/components/common/DataPagination/index.tsx +70 -0
- package/src/components/form/inputs/CheckboxFormControl.tsx +1 -11
- package/src/components/form/inputs/PhoneInputFormControl/components/AutocompleteInput.tsx +1 -1
- package/src/components/form/inputs/PhoneInputFormControl/index.tsx +3 -4
- package/src/components/layout/ServiceFormContainer/{index.tsx → AccordionFormContainer/index.tsx} +6 -2
- package/src/components/layout/ServiceFormContainer/AccordionFormContainer/utils.ts +12 -0
- package/src/components/layout/ServiceFormContainer/CardFormContainer/index.test.tsx +78 -0
- package/src/components/layout/ServiceFormContainer/CardFormContainer/index.tsx +68 -0
- package/src/components/layout/ServiceWizardStepper/ServiceWizardStepper.css +85 -0
- package/src/components/layout/ServiceWizardStepper/StepConnector.tsx +29 -0
- package/src/components/layout/ServiceWizardStepper/StepperTypes.ts +7 -0
- package/src/components/layout/ServiceWizardStepper/components/CustomStepIcon.test.tsx +22 -0
- package/src/components/layout/ServiceWizardStepper/components/CustomStepIcon.tsx +41 -0
- package/src/components/layout/ServiceWizardStepper/components/DesktopStepper.test.tsx +40 -0
- package/src/components/layout/ServiceWizardStepper/components/DesktopStepper.tsx +63 -0
- package/src/components/layout/ServiceWizardStepper/components/HorizontalStepperButton.test.tsx +24 -0
- package/src/components/layout/ServiceWizardStepper/components/HorizontalStepperButton.tsx +46 -0
- package/src/components/layout/ServiceWizardStepper/components/MobileStepper.test.tsx +21 -0
- package/src/components/layout/ServiceWizardStepper/components/MobileStepper.tsx +54 -0
- package/src/components/layout/ServiceWizardStepper/components/StyledStepLabel.tsx +57 -0
- package/src/components/layout/ServiceWizardStepper/index.tsx +63 -37
- package/src/examples/CardMultipleStepForm/index.tsx +93 -0
- package/src/examples/HorizontalMultiStepForm/index.tsx +64 -0
- package/src/examples/ListWithPagination/index.tsx +44 -0
- package/src/examples/MultipleStepForm/index.tsx +1 -1
- package/src/examples/SingleStepForm/index.tsx +1 -1
- package/src/library/icons.ts +51 -4
- package/src/library/index.ts +12 -3
- package/src/library/types.ts +5 -0
- package/src/main.tsx +15 -0
- package/src/stories/ServiceWizardStepper.stories.tsx +39 -0
- package/src/stories/components/Accordion.stories.tsx +1 -1
- package/src/stories/components/Card.stories.tsx +51 -0
- package/src/stories/components/Card.test.tsx +18 -0
- package/src/stories/components/DataPagination.stories.tsx +75 -0
- package/src/stories/components/Icons.stories.tsx +352 -0
- package/src/stories/components/buttons/Button.stories.tsx +30 -0
- package/src/stories/components/form/CardFormContainer.stories.tsx +135 -0
- package/src/stories/components/form/ServiceFormContainer.stories.tsx +1 -1
- package/src/theme/light/MuiAlert.tsx +10 -10
- package/src/theme/light/MuiButton.tsx +42 -15
- package/src/theme/light/MuiCard.tsx +2 -2
- package/src/theme/light/MuiPagination.ts +40 -12
- package/src/theme/light/index.tsx +2 -1
- package/src/types/buttons/ButtonProps.tsx +3 -1
- package/dist/assets/icons/CheckBoldDisabledIcon.d.ts +0 -3
- package/dist/components/layout/ServiceWizardStepper/components/ActiveStepIcon.d.ts +0 -2
- package/dist/components/layout/ServiceWizardStepper/components/CompletedStepIcon.d.ts +0 -2
- package/dist/components/layout/ServiceWizardStepper/components/PendingStepIcon.d.ts +0 -2
- package/src/assets/icons/CheckBoldDisabledIcon.tsx +0 -32
- package/src/components/layout/ServiceWizardStepper/components/ActiveStepIcon.tsx +0 -15
- package/src/components/layout/ServiceWizardStepper/components/CompletedStepIcon.tsx +0 -19
- package/src/components/layout/ServiceWizardStepper/components/PendingStepIcon.tsx +0 -15
- /package/src/components/layout/ServiceFormContainer/{components → AccordionFormContainer/components}/AccordionCollapseControls.tsx +0 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { XCircleIcon as XCircle } from '@phosphor-icons/react'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import IconProps from '../IconProps'
|
|
4
|
+
|
|
5
|
+
function XCircleFillIcon({ className, size = 24, fillColor, ...rest }: IconProps) {
|
|
4
6
|
return (
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
</SvgIcon>
|
|
7
|
+
<XCircle
|
|
8
|
+
{...rest}
|
|
9
|
+
className={className}
|
|
10
|
+
size={size}
|
|
11
|
+
weight='fill'
|
|
12
|
+
color={fillColor}
|
|
13
|
+
/>
|
|
13
14
|
)
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -1,18 +1,49 @@
|
|
|
1
1
|
import { Button as MuiButton, ButtonProps as MuiButtonProps } from '@mui/material'
|
|
2
2
|
|
|
3
|
+
import { ButtonProps } from '@/types/buttons/ButtonProps'
|
|
4
|
+
|
|
3
5
|
const defaultProps: Partial<MuiButtonProps> = {
|
|
4
6
|
color: 'primary',
|
|
5
7
|
disabled: false,
|
|
6
8
|
variant: 'contained',
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
const ICON_ONLY_SIZE_MAP = {
|
|
12
|
+
small: '2.25rem',
|
|
13
|
+
medium: '2.75rem',
|
|
14
|
+
large: '3rem',
|
|
15
|
+
} as const
|
|
16
|
+
|
|
17
|
+
type Props = ButtonProps & { to?: string }
|
|
10
18
|
|
|
11
19
|
function RcSesButton(props: Props) {
|
|
12
|
-
const { children, ...rest } = props
|
|
20
|
+
const { children, iconOnly, size = 'medium', sx, variant, ...rest } = props
|
|
21
|
+
|
|
22
|
+
const currentVariant = variant ?? defaultProps.variant
|
|
23
|
+
const isIconOnly =
|
|
24
|
+
!!iconOnly && (currentVariant === 'contained' || currentVariant === 'outlined')
|
|
13
25
|
|
|
14
26
|
return (
|
|
15
|
-
<MuiButton
|
|
27
|
+
<MuiButton
|
|
28
|
+
{...defaultProps}
|
|
29
|
+
{...rest}
|
|
30
|
+
size={size}
|
|
31
|
+
variant={variant}
|
|
32
|
+
sx={[
|
|
33
|
+
...(Array.isArray(sx) ? sx : [sx]),
|
|
34
|
+
isIconOnly
|
|
35
|
+
? {
|
|
36
|
+
minWidth: 0,
|
|
37
|
+
padding: 0,
|
|
38
|
+
width: ICON_ONLY_SIZE_MAP[size],
|
|
39
|
+
height: ICON_ONLY_SIZE_MAP[size],
|
|
40
|
+
'.MuiButton-startIcon, .MuiButton-endIcon': {
|
|
41
|
+
margin: 0,
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
: undefined,
|
|
45
|
+
]}
|
|
46
|
+
>
|
|
16
47
|
{children}
|
|
17
48
|
</MuiButton>
|
|
18
49
|
)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
+
import '@testing-library/jest-dom'
|
|
3
|
+
import { render, screen } from '@testing-library/react'
|
|
4
|
+
import { type ReactElement } from 'react'
|
|
5
|
+
import { describe, expect, test } from 'vitest'
|
|
6
|
+
|
|
7
|
+
import theme from '../../../theme/light'
|
|
8
|
+
import RcSesCard from './index'
|
|
9
|
+
|
|
10
|
+
const renderCard = (ui: ReactElement) =>
|
|
11
|
+
render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
|
|
12
|
+
|
|
13
|
+
describe('RcSesCard', () => {
|
|
14
|
+
test('renders title, description, children, and actions', () => {
|
|
15
|
+
renderCard(
|
|
16
|
+
<RcSesCard
|
|
17
|
+
title='Card title'
|
|
18
|
+
description='Card description'
|
|
19
|
+
leadingActions={<button type='button'>Back</button>}
|
|
20
|
+
trailingActions={<button type='button'>Continue</button>}
|
|
21
|
+
>
|
|
22
|
+
<div>Card content</div>
|
|
23
|
+
</RcSesCard>,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
expect(screen.getByText('Card title')).toBeInTheDocument()
|
|
27
|
+
expect(screen.getByText('Card description')).toBeInTheDocument()
|
|
28
|
+
expect(screen.getByText('Card content')).toBeInTheDocument()
|
|
29
|
+
expect(screen.getByRole('button', { name: 'Back' })).toBeInTheDocument()
|
|
30
|
+
expect(screen.getByRole('button', { name: 'Continue' })).toBeInTheDocument()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('omits optional description and actions when they are not provided', () => {
|
|
34
|
+
renderCard(
|
|
35
|
+
<RcSesCard title='Only title'>
|
|
36
|
+
<div>Only content</div>
|
|
37
|
+
</RcSesCard>,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
expect(screen.getByText('Only title')).toBeInTheDocument()
|
|
41
|
+
expect(screen.getByText('Only content')).toBeInTheDocument()
|
|
42
|
+
expect(screen.queryByRole('button')).not.toBeInTheDocument()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('forwards slot props to internal sections', () => {
|
|
46
|
+
const { container } = renderCard(
|
|
47
|
+
<RcSesCard
|
|
48
|
+
title='Slotted title'
|
|
49
|
+
description='Slotted description'
|
|
50
|
+
leadingActions={<button type='button'>Leading</button>}
|
|
51
|
+
trailingActions={<button type='button'>Trailing</button>}
|
|
52
|
+
slotProps={{
|
|
53
|
+
actions: { className: 'actions-slot' },
|
|
54
|
+
content: { className: 'content-slot' },
|
|
55
|
+
description: { className: 'description-slot' },
|
|
56
|
+
header: { className: 'header-slot' },
|
|
57
|
+
leadingActions: { className: 'leading-actions-slot' },
|
|
58
|
+
title: { className: 'title-slot' },
|
|
59
|
+
trailingActions: { className: 'trailing-actions-slot' },
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<div>Slotted content</div>
|
|
63
|
+
</RcSesCard>,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
expect(container.querySelector('.header-slot')).toBeInTheDocument()
|
|
67
|
+
expect(container.querySelector('.title-slot')).toBeInTheDocument()
|
|
68
|
+
expect(container.querySelector('.description-slot')).toBeInTheDocument()
|
|
69
|
+
expect(container.querySelector('.content-slot')).toBeInTheDocument()
|
|
70
|
+
expect(container.querySelector('.actions-slot')).toBeInTheDocument()
|
|
71
|
+
expect(container.querySelector('.leading-actions-slot')).toBeInTheDocument()
|
|
72
|
+
expect(container.querySelector('.trailing-actions-slot')).toBeInTheDocument()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('forwards testIds to internal sections', () => {
|
|
76
|
+
renderCard(
|
|
77
|
+
<RcSesCard
|
|
78
|
+
title='Test id title'
|
|
79
|
+
description='Test id description'
|
|
80
|
+
leadingActions={<button type='button'>Leading</button>}
|
|
81
|
+
trailingActions={<button type='button'>Trailing</button>}
|
|
82
|
+
testIds={{
|
|
83
|
+
root: 'card-root',
|
|
84
|
+
header: 'card-header',
|
|
85
|
+
title: 'card-title',
|
|
86
|
+
description: 'card-description',
|
|
87
|
+
content: 'card-content',
|
|
88
|
+
actions: 'card-actions',
|
|
89
|
+
leadingActions: 'card-leading-actions',
|
|
90
|
+
trailingActions: 'card-trailing-actions',
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
<div>Test id content</div>
|
|
94
|
+
</RcSesCard>,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
expect(screen.getByTestId('card-root')).toBeInTheDocument()
|
|
98
|
+
expect(screen.getByTestId('card-header')).toBeInTheDocument()
|
|
99
|
+
expect(screen.getByTestId('card-title')).toBeInTheDocument()
|
|
100
|
+
expect(screen.getByTestId('card-description')).toBeInTheDocument()
|
|
101
|
+
expect(screen.getByTestId('card-content')).toBeInTheDocument()
|
|
102
|
+
expect(screen.getByTestId('card-actions')).toBeInTheDocument()
|
|
103
|
+
expect(screen.getByTestId('card-leading-actions')).toBeInTheDocument()
|
|
104
|
+
expect(screen.getByTestId('card-trailing-actions')).toBeInTheDocument()
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('accepts a plain sx object on the card root', () => {
|
|
108
|
+
const { container } = renderCard(
|
|
109
|
+
<RcSesCard title='Root sx object' sx={{ borderStyle: 'dashed' }}>
|
|
110
|
+
<div>Content</div>
|
|
111
|
+
</RcSesCard>,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
expect(container.querySelector('.MuiCard-root')).toBeInTheDocument()
|
|
115
|
+
expect(screen.getByText('Root sx object')).toBeInTheDocument()
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test('accepts an sx array in slot props', () => {
|
|
119
|
+
const { container } = renderCard(
|
|
120
|
+
<RcSesCard
|
|
121
|
+
title='Array sx'
|
|
122
|
+
slotProps={{
|
|
123
|
+
title: {
|
|
124
|
+
className: 'array-sx-title',
|
|
125
|
+
sx: [{ letterSpacing: '0.01em' }, { textTransform: 'uppercase' }],
|
|
126
|
+
},
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
<div>Content</div>
|
|
130
|
+
</RcSesCard>,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
expect(container.querySelector('.array-sx-title')).toBeInTheDocument()
|
|
134
|
+
expect(screen.getByText('Array sx')).toBeInTheDocument()
|
|
135
|
+
})
|
|
136
|
+
})
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box,
|
|
3
|
+
BoxProps,
|
|
4
|
+
CardProps,
|
|
5
|
+
Card as MuiCard,
|
|
6
|
+
Stack,
|
|
7
|
+
StackProps,
|
|
8
|
+
SxProps,
|
|
9
|
+
Theme,
|
|
10
|
+
Typography,
|
|
11
|
+
TypographyProps,
|
|
12
|
+
} from '@mui/material'
|
|
13
|
+
import { ReactNode } from 'react'
|
|
14
|
+
|
|
15
|
+
import palette from '@/theme/palette'
|
|
16
|
+
|
|
17
|
+
export type RcSesCardTestIds = {
|
|
18
|
+
root?: string
|
|
19
|
+
header?: string
|
|
20
|
+
title?: string
|
|
21
|
+
description?: string
|
|
22
|
+
content?: string
|
|
23
|
+
actions?: string
|
|
24
|
+
leadingActions?: string
|
|
25
|
+
trailingActions?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type RcSesCardProps = Omit<CardProps, 'children' | 'title'> & {
|
|
29
|
+
title: ReactNode
|
|
30
|
+
description?: ReactNode
|
|
31
|
+
children: ReactNode
|
|
32
|
+
leadingActions?: ReactNode
|
|
33
|
+
trailingActions?: ReactNode
|
|
34
|
+
testIds?: RcSesCardTestIds
|
|
35
|
+
slotProps?: {
|
|
36
|
+
actions?: StackProps
|
|
37
|
+
content?: BoxProps
|
|
38
|
+
description?: TypographyProps
|
|
39
|
+
header?: StackProps
|
|
40
|
+
leadingActions?: StackProps
|
|
41
|
+
title?: TypographyProps
|
|
42
|
+
trailingActions?: StackProps
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type SxEntry =
|
|
47
|
+
Extract<SxProps<Theme>, ReadonlyArray<unknown>> extends ReadonlyArray<infer T>
|
|
48
|
+
? T
|
|
49
|
+
: never
|
|
50
|
+
|
|
51
|
+
function isSxArray(sx: SxProps<Theme>): sx is ReadonlyArray<SxEntry> {
|
|
52
|
+
return Array.isArray(sx)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function normalizeSx(sx: SxProps<Theme> | undefined): SxEntry[] {
|
|
56
|
+
if (sx === undefined) {
|
|
57
|
+
return []
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (isSxArray(sx)) {
|
|
61
|
+
return [...sx]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return [sx]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function RcSesCard({
|
|
68
|
+
title,
|
|
69
|
+
description,
|
|
70
|
+
children,
|
|
71
|
+
leadingActions,
|
|
72
|
+
trailingActions,
|
|
73
|
+
testIds,
|
|
74
|
+
slotProps,
|
|
75
|
+
sx,
|
|
76
|
+
...cardProps
|
|
77
|
+
}: RcSesCardProps) {
|
|
78
|
+
const actionsProps = slotProps?.actions
|
|
79
|
+
const contentProps = slotProps?.content
|
|
80
|
+
const descriptionProps = slotProps?.description
|
|
81
|
+
const headerProps = slotProps?.header
|
|
82
|
+
const leadingActionsProps = slotProps?.leadingActions
|
|
83
|
+
const titleProps = slotProps?.title
|
|
84
|
+
const trailingActionsProps = slotProps?.trailingActions
|
|
85
|
+
|
|
86
|
+
const normalizedSx = normalizeSx(sx)
|
|
87
|
+
const normalizedTitleSx = normalizeSx(titleProps?.sx)
|
|
88
|
+
const normalizedDescriptionSx = normalizeSx(descriptionProps?.sx)
|
|
89
|
+
const normalizedContentSx = normalizeSx(contentProps?.sx)
|
|
90
|
+
const normalizedActionsSx = normalizeSx(actionsProps?.sx)
|
|
91
|
+
const normalizedLeadingActionsSx = normalizeSx(leadingActionsProps?.sx)
|
|
92
|
+
const normalizedTrailingActionsSx = normalizeSx(trailingActionsProps?.sx)
|
|
93
|
+
|
|
94
|
+
const hasActions = Boolean(leadingActions || trailingActions)
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<MuiCard
|
|
98
|
+
{...cardProps}
|
|
99
|
+
data-testid={testIds?.root}
|
|
100
|
+
sx={[
|
|
101
|
+
{
|
|
102
|
+
display: 'flex',
|
|
103
|
+
flexDirection: 'column',
|
|
104
|
+
gap: { xs: '1rem', md: '1.5rem' },
|
|
105
|
+
p: { xs: '1.25rem 1.5rem 1.5rem', md: '1.5rem 2rem 2rem' },
|
|
106
|
+
},
|
|
107
|
+
...normalizedSx,
|
|
108
|
+
]}
|
|
109
|
+
>
|
|
110
|
+
<Stack {...headerProps} data-testid={testIds?.header} spacing={0.5}>
|
|
111
|
+
<Typography
|
|
112
|
+
color={palette.grey[900]}
|
|
113
|
+
data-testid={testIds?.title}
|
|
114
|
+
variant='h5'
|
|
115
|
+
{...titleProps}
|
|
116
|
+
sx={[
|
|
117
|
+
{
|
|
118
|
+
lineHeight: '1.75rem',
|
|
119
|
+
},
|
|
120
|
+
...normalizedTitleSx,
|
|
121
|
+
]}
|
|
122
|
+
>
|
|
123
|
+
{title}
|
|
124
|
+
</Typography>
|
|
125
|
+
|
|
126
|
+
{!!description && (
|
|
127
|
+
<Typography
|
|
128
|
+
color={palette.grey[800]}
|
|
129
|
+
data-testid={testIds?.description}
|
|
130
|
+
variant='body2'
|
|
131
|
+
{...descriptionProps}
|
|
132
|
+
sx={[
|
|
133
|
+
{
|
|
134
|
+
fontWeight: 300,
|
|
135
|
+
lineHeight: '1.25rem',
|
|
136
|
+
},
|
|
137
|
+
...normalizedDescriptionSx,
|
|
138
|
+
]}
|
|
139
|
+
>
|
|
140
|
+
{description}
|
|
141
|
+
</Typography>
|
|
142
|
+
)}
|
|
143
|
+
</Stack>
|
|
144
|
+
|
|
145
|
+
<Box
|
|
146
|
+
{...contentProps}
|
|
147
|
+
data-testid={testIds?.content}
|
|
148
|
+
sx={[
|
|
149
|
+
{
|
|
150
|
+
alignItems: 'center',
|
|
151
|
+
alignSelf: 'stretch',
|
|
152
|
+
backgroundColor: palette.grey[100],
|
|
153
|
+
borderRadius: '0.5rem',
|
|
154
|
+
display: 'flex',
|
|
155
|
+
flexDirection: 'column',
|
|
156
|
+
gap: '1.5rem',
|
|
157
|
+
justifyContent: 'center',
|
|
158
|
+
},
|
|
159
|
+
...normalizedContentSx,
|
|
160
|
+
]}
|
|
161
|
+
>
|
|
162
|
+
{children}
|
|
163
|
+
</Box>
|
|
164
|
+
|
|
165
|
+
{hasActions && (
|
|
166
|
+
<Stack
|
|
167
|
+
{...actionsProps}
|
|
168
|
+
data-testid={testIds?.actions}
|
|
169
|
+
direction={{ xs: 'column', md: 'row' }}
|
|
170
|
+
sx={[
|
|
171
|
+
{
|
|
172
|
+
alignItems: { xs: 'stretch', md: 'center' },
|
|
173
|
+
justifyContent: { xs: 'stretch', md: 'space-between' },
|
|
174
|
+
pt: '0.5rem',
|
|
175
|
+
width: '100%',
|
|
176
|
+
},
|
|
177
|
+
...normalizedActionsSx,
|
|
178
|
+
]}
|
|
179
|
+
spacing={{ xs: 1, md: 3 }}
|
|
180
|
+
>
|
|
181
|
+
{!!leadingActions && (
|
|
182
|
+
<Stack
|
|
183
|
+
{...leadingActionsProps}
|
|
184
|
+
data-testid={testIds?.leadingActions}
|
|
185
|
+
direction={{ xs: 'column', md: 'row' }}
|
|
186
|
+
sx={[
|
|
187
|
+
{
|
|
188
|
+
alignItems: { xs: 'stretch', md: 'center' },
|
|
189
|
+
minHeight: { md: '2.75rem' },
|
|
190
|
+
width: { xs: '100%', md: 'auto' },
|
|
191
|
+
|
|
192
|
+
'& > *': {
|
|
193
|
+
width: { xs: '100%', md: 'auto' },
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
...normalizedLeadingActionsSx,
|
|
197
|
+
]}
|
|
198
|
+
>
|
|
199
|
+
{leadingActions}
|
|
200
|
+
</Stack>
|
|
201
|
+
)}
|
|
202
|
+
|
|
203
|
+
{!!trailingActions && (
|
|
204
|
+
<Stack
|
|
205
|
+
{...trailingActionsProps}
|
|
206
|
+
data-testid={testIds?.trailingActions}
|
|
207
|
+
direction={{ xs: 'column', md: 'row' }}
|
|
208
|
+
sx={[
|
|
209
|
+
{
|
|
210
|
+
alignItems: { xs: 'stretch', md: 'center' },
|
|
211
|
+
justifyContent: { xs: 'stretch', md: 'flex-end' },
|
|
212
|
+
width: { xs: '100%', md: 'auto' },
|
|
213
|
+
|
|
214
|
+
'& > *': {
|
|
215
|
+
width: { xs: '100%', md: 'auto' },
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
...normalizedTrailingActionsSx,
|
|
219
|
+
]}
|
|
220
|
+
spacing={{ xs: 1, md: 1.5 }}
|
|
221
|
+
>
|
|
222
|
+
{trailingActions}
|
|
223
|
+
</Stack>
|
|
224
|
+
)}
|
|
225
|
+
</Stack>
|
|
226
|
+
)}
|
|
227
|
+
</MuiCard>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export default RcSesCard
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Button, ButtonProps } from '@mui/material'
|
|
2
|
+
import { Box } from '@mui/system'
|
|
3
|
+
|
|
4
|
+
import palette from '@/theme/palette'
|
|
5
|
+
|
|
6
|
+
interface PaginationButtonProps extends ButtonProps {
|
|
7
|
+
label: string
|
|
8
|
+
icon: React.ReactNode
|
|
9
|
+
iconPosition?: 'start' | 'end'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const baseButtonSx = {
|
|
13
|
+
'&&': {
|
|
14
|
+
minWidth: 40,
|
|
15
|
+
height: 40,
|
|
16
|
+
px: 1.5,
|
|
17
|
+
borderRadius: 2,
|
|
18
|
+
fontSize: 14,
|
|
19
|
+
fontWeight: 300,
|
|
20
|
+
textTransform: 'none',
|
|
21
|
+
backgroundColor: 'transparent',
|
|
22
|
+
color: palette.grey[800],
|
|
23
|
+
|
|
24
|
+
display: 'flex',
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
gap: 0.5,
|
|
27
|
+
|
|
28
|
+
'&:hover': {
|
|
29
|
+
backgroundColor: palette.grey[200],
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
'&:active': {
|
|
33
|
+
backgroundColor: palette.grey[300],
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
'&.Mui-focusVisible': {
|
|
37
|
+
border: `2px solid ${palette.grey[950]}`,
|
|
38
|
+
backgroundColor: palette.grey[50],
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
'&.Mui-disabled': {
|
|
42
|
+
backgroundColor: palette.grey[100],
|
|
43
|
+
color: palette.grey[500],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const PaginationButton = ({
|
|
49
|
+
label,
|
|
50
|
+
icon,
|
|
51
|
+
iconPosition = 'start',
|
|
52
|
+
...props
|
|
53
|
+
}: PaginationButtonProps) => (
|
|
54
|
+
<Button variant='text' color='inherit' disableRipple {...props} sx={baseButtonSx}>
|
|
55
|
+
{iconPosition === 'start' && icon}
|
|
56
|
+
|
|
57
|
+
<Box sx={{ display: { xs: 'none', sm: 'block' } }}>{label}</Box>
|
|
58
|
+
|
|
59
|
+
{iconPosition === 'end' && icon}
|
|
60
|
+
</Button>
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
export default PaginationButton
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { useMediaQuery } from '@mui/material'
|
|
2
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
3
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
4
|
+
import { ReactElement } from 'react'
|
|
5
|
+
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
|
6
|
+
|
|
7
|
+
import theme from '@/theme/light'
|
|
8
|
+
|
|
9
|
+
import DataPagination from './index'
|
|
10
|
+
|
|
11
|
+
vi.mock('@mui/material', async () => {
|
|
12
|
+
const actual = await vi.importActual<typeof import('@mui/material')>('@mui/material')
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
...actual,
|
|
16
|
+
useMediaQuery: vi.fn(() => false),
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const renderPagination = (ui: ReactElement) =>
|
|
21
|
+
render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
|
|
22
|
+
|
|
23
|
+
const mockedUseMediaQuery = vi.mocked(useMediaQuery)
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
mockedUseMediaQuery.mockReturnValue(false)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
describe('DataPagination', () => {
|
|
30
|
+
test('renders labels and disables previous button on first page', () => {
|
|
31
|
+
renderPagination(
|
|
32
|
+
<DataPagination count={5} prevLabel='Previous page' nextLabel='Next page' />,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
expect(screen.getByRole('button', { name: 'Previous page' })).toBeDisabled()
|
|
36
|
+
expect(screen.getByRole('button', { name: 'Next page' })).toBeEnabled()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('updates internal page and calls onChange in uncontrolled mode', () => {
|
|
40
|
+
const onChange = vi.fn()
|
|
41
|
+
|
|
42
|
+
renderPagination(
|
|
43
|
+
<DataPagination
|
|
44
|
+
count={3}
|
|
45
|
+
defaultPage={1}
|
|
46
|
+
onChange={onChange}
|
|
47
|
+
prevLabel='Previous page'
|
|
48
|
+
nextLabel='Next page'
|
|
49
|
+
/>,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
const nextButton = screen.getByRole('button', { name: 'Next page' })
|
|
53
|
+
|
|
54
|
+
fireEvent.click(nextButton)
|
|
55
|
+
fireEvent.click(nextButton)
|
|
56
|
+
|
|
57
|
+
expect(onChange).toHaveBeenNthCalledWith(1, 2)
|
|
58
|
+
expect(onChange).toHaveBeenNthCalledWith(2, 3)
|
|
59
|
+
expect(nextButton).toBeDisabled()
|
|
60
|
+
expect(screen.getByRole('button', { name: 'Previous page' })).toBeEnabled()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('does not call onChange when trying to go before page 1', () => {
|
|
64
|
+
const onChange = vi.fn()
|
|
65
|
+
|
|
66
|
+
renderPagination(
|
|
67
|
+
<DataPagination
|
|
68
|
+
count={4}
|
|
69
|
+
defaultPage={1}
|
|
70
|
+
onChange={onChange}
|
|
71
|
+
prevLabel='Previous page'
|
|
72
|
+
/>,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
fireEvent.click(screen.getByRole('button', { name: 'Previous page' }))
|
|
76
|
+
|
|
77
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('uses controlled page value and only emits next page in callback', () => {
|
|
81
|
+
const onChange = vi.fn()
|
|
82
|
+
|
|
83
|
+
renderPagination(
|
|
84
|
+
<DataPagination
|
|
85
|
+
count={5}
|
|
86
|
+
page={1}
|
|
87
|
+
onChange={onChange}
|
|
88
|
+
prevLabel='Previous page'
|
|
89
|
+
nextLabel='Next page'
|
|
90
|
+
/>,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
fireEvent.click(screen.getByRole('button', { name: 'Next page' }))
|
|
94
|
+
|
|
95
|
+
expect(onChange).toHaveBeenCalledWith(2)
|
|
96
|
+
expect(screen.getByRole('button', { name: 'Previous page' })).toBeDisabled()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test('shows 1 2 3 ... x page buttons on mobile', () => {
|
|
100
|
+
mockedUseMediaQuery.mockReturnValue(true)
|
|
101
|
+
|
|
102
|
+
renderPagination(<DataPagination count={10} defaultPage={1} />)
|
|
103
|
+
|
|
104
|
+
expect(screen.getByRole('button', { name: 'page 1' })).toBeInTheDocument()
|
|
105
|
+
expect(screen.getByRole('button', { name: 'Go to page 2' })).toBeInTheDocument()
|
|
106
|
+
expect(screen.getByRole('button', { name: 'Go to page 3' })).toBeInTheDocument()
|
|
107
|
+
expect(screen.queryByRole('button', { name: 'Go to page 4' })).not.toBeInTheDocument()
|
|
108
|
+
expect(screen.getByRole('button', { name: 'Go to page 10' })).toBeInTheDocument()
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test('shows 1 2 3 4 ... x page buttons on desktop', () => {
|
|
112
|
+
mockedUseMediaQuery.mockReturnValue(false)
|
|
113
|
+
|
|
114
|
+
renderPagination(<DataPagination count={10} defaultPage={1} />)
|
|
115
|
+
|
|
116
|
+
expect(screen.getByRole('button', { name: 'page 1' })).toBeInTheDocument()
|
|
117
|
+
expect(screen.getByRole('button', { name: 'Go to page 2' })).toBeInTheDocument()
|
|
118
|
+
expect(screen.getByRole('button', { name: 'Go to page 3' })).toBeInTheDocument()
|
|
119
|
+
expect(screen.getByRole('button', { name: 'Go to page 4' })).toBeInTheDocument()
|
|
120
|
+
expect(screen.getByRole('button', { name: 'Go to page 10' })).toBeInTheDocument()
|
|
121
|
+
})
|
|
122
|
+
})
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Pagination, useMediaQuery, useTheme } from '@mui/material'
|
|
2
|
+
import { Box } from '@mui/system'
|
|
3
|
+
import { useState } from 'react'
|
|
4
|
+
|
|
5
|
+
import ArrowLeftIcon from '@/assets/icons/ArrowLeftIcon'
|
|
6
|
+
import ArrowRightIcon from '@/assets/icons/ArrowRightIcon'
|
|
7
|
+
|
|
8
|
+
import PaginationButton from './components/PaginationButton'
|
|
9
|
+
|
|
10
|
+
export interface DataPaginationProps {
|
|
11
|
+
count: number
|
|
12
|
+
page?: number
|
|
13
|
+
defaultPage?: number
|
|
14
|
+
onChange?: (page: number) => void
|
|
15
|
+
prevLabel?: string
|
|
16
|
+
nextLabel?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const DataPagination = ({
|
|
20
|
+
count,
|
|
21
|
+
page,
|
|
22
|
+
defaultPage = 1,
|
|
23
|
+
onChange,
|
|
24
|
+
prevLabel = 'Atgal',
|
|
25
|
+
nextLabel = 'Kitas',
|
|
26
|
+
}: DataPaginationProps) => {
|
|
27
|
+
const theme = useTheme()
|
|
28
|
+
const isMobile = useMediaQuery(theme.breakpoints.down('sm'))
|
|
29
|
+
const isControlled = page !== undefined
|
|
30
|
+
const [internalPage, setInternalPage] = useState(defaultPage)
|
|
31
|
+
|
|
32
|
+
const currentPage = isControlled ? page : internalPage
|
|
33
|
+
|
|
34
|
+
const handlePageChange = (newPage: number) => {
|
|
35
|
+
if (newPage < 1 || newPage > count) return
|
|
36
|
+
|
|
37
|
+
if (!isControlled) {
|
|
38
|
+
setInternalPage(newPage)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onChange?.(newPage)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Box display='flex' alignItems='center' gap={1}>
|
|
46
|
+
<PaginationButton
|
|
47
|
+
onClick={() => handlePageChange(currentPage - 1)}
|
|
48
|
+
disabled={currentPage === 1}
|
|
49
|
+
label={prevLabel}
|
|
50
|
+
icon={<ArrowLeftIcon size={16} />}
|
|
51
|
+
/>
|
|
52
|
+
<Pagination
|
|
53
|
+
count={count}
|
|
54
|
+
page={currentPage}
|
|
55
|
+
siblingCount={isMobile ? 0 : 1}
|
|
56
|
+
boundaryCount={1}
|
|
57
|
+
onChange={(_, p) => handlePageChange(p)}
|
|
58
|
+
/>
|
|
59
|
+
<PaginationButton
|
|
60
|
+
onClick={() => handlePageChange(currentPage + 1)}
|
|
61
|
+
disabled={currentPage === count}
|
|
62
|
+
label={nextLabel}
|
|
63
|
+
icon={<ArrowRightIcon size={16} />}
|
|
64
|
+
iconPosition='end'
|
|
65
|
+
/>
|
|
66
|
+
</Box>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default DataPagination
|