@registrucentras/rc-ses-react-components 1.3.0 → 1.4.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/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/utils.d.ts +4 -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 +9 -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 +6 -5
- package/dist/library/icons.d.ts +27 -3
- package/dist/library/index.d.ts +6 -2
- package/dist/registrucentras-rc-ses-react-components.cjs +12 -12
- package/dist/registrucentras-rc-ses-react-components.js +3893 -2677
- 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/CheckboxFormControl.stories.d.ts +2 -2
- 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 +8 -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/Alert/index.test.tsx +3 -10
- package/src/components/common/Alert/index.tsx +44 -16
- 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 +5 -1
- package/src/components/layout/ServiceFormContainer/utils.ts +12 -0
- package/src/components/layout/ServiceWizardStepper/ServiceWizardStepper.css +69 -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 +48 -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 +53 -0
- package/src/components/layout/ServiceWizardStepper/index.tsx +56 -37
- package/src/examples/HorizontalMultiStepForm/index.tsx +64 -0
- package/src/examples/ListWithPagination/index.tsx +44 -0
- package/src/library/icons.ts +51 -4
- package/src/library/index.ts +6 -2
- package/src/main.tsx +10 -0
- package/src/stories/ServiceWizardStepper.stories.tsx +39 -0
- package/src/stories/components/Alert.stories.tsx +1 -8
- 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/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
|
@@ -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
|
|
|
@@ -33,7 +33,7 @@ describe('RcSesAlert', () => {
|
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
describe('container prop', () => {
|
|
36
|
-
test('
|
|
36
|
+
test('renders children correctly when container={true}', () => {
|
|
37
37
|
renderAlert(
|
|
38
38
|
<RcSesAlert container data-testid='alert'>
|
|
39
39
|
inside
|
|
@@ -43,7 +43,7 @@ describe('RcSesAlert', () => {
|
|
|
43
43
|
expect(screen.getByText('inside')).toBeInTheDocument()
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
test('
|
|
46
|
+
test('renders children correctly when container is ContainerProps object', () => {
|
|
47
47
|
renderAlert(
|
|
48
48
|
<RcSesAlert container={{ maxWidth: 'sm' }} data-testid='alert'>
|
|
49
49
|
inside sm
|
|
@@ -52,21 +52,14 @@ describe('RcSesAlert', () => {
|
|
|
52
52
|
expect(screen.getByText('inside sm')).toBeInTheDocument()
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
test('does not wrap children in a Container when container is not set', () => {
|
|
56
|
-
const { container } = renderAlert(<RcSesAlert>no container</RcSesAlert>)
|
|
57
|
-
// No MUI Container = no element with class MuiContainer-root
|
|
58
|
-
expect(container.querySelector('.MuiContainer-root')).toBeNull()
|
|
59
|
-
})
|
|
60
|
-
|
|
61
55
|
test('applies full-bleed sx overrides when container is set', () => {
|
|
62
56
|
const { container } = renderAlert(
|
|
63
57
|
<RcSesAlert container data-testid='alert'>
|
|
64
58
|
text
|
|
65
59
|
</RcSesAlert>,
|
|
66
60
|
)
|
|
67
|
-
// Verify the alert renders
|
|
61
|
+
// Verify the alert renders
|
|
68
62
|
expect(container.querySelector('.MuiAlert-root')).toBeInTheDocument()
|
|
69
|
-
expect(container.querySelector('.MuiContainer-root')).toBeInTheDocument()
|
|
70
63
|
})
|
|
71
64
|
|
|
72
65
|
test('merges caller sx on top of container sx', () => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Container,
|
|
3
2
|
ContainerProps,
|
|
4
3
|
Alert as MuiAlert,
|
|
5
4
|
AlertProps as MuiAlertProps,
|
|
@@ -15,33 +14,62 @@ const defaultProps: Partial<MuiAlertProps> = {
|
|
|
15
14
|
variant: 'outlined',
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
const containerSx: MuiAlertProps['sx'] = {
|
|
19
|
-
borderRadius: 0,
|
|
20
|
-
px: 0,
|
|
21
|
-
'& .MuiAlert-message': { p: 0, width: '100%' },
|
|
22
|
-
}
|
|
23
|
-
|
|
24
17
|
function RcSesAlert({ container, children, sx, ...props }: Props) {
|
|
25
18
|
const { t } = useTranslation('input', { keyPrefix: 'components.RcSesAlert' })
|
|
26
19
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
const isContainer = Boolean(container)
|
|
21
|
+
const containerParams = typeof container === 'object' ? container : {}
|
|
22
|
+
const maxWidth =
|
|
23
|
+
containerParams.maxWidth === undefined ? 'lg' : containerParams.maxWidth
|
|
24
|
+
const disableGutters = containerParams.disableGutters || false
|
|
25
|
+
|
|
26
|
+
let normalizedSx: any[] = []
|
|
27
|
+
if (sx) {
|
|
28
|
+
normalizedSx = Array.isArray(sx) ? sx : [sx]
|
|
29
|
+
}
|
|
32
30
|
|
|
33
31
|
return (
|
|
34
32
|
<MuiAlert
|
|
35
33
|
{...defaultProps}
|
|
36
34
|
{...props}
|
|
37
35
|
sx={[
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
isContainer &&
|
|
37
|
+
((theme) => {
|
|
38
|
+
let maxWidthValue: string | number = 'none'
|
|
39
|
+
|
|
40
|
+
if (maxWidth !== false) {
|
|
41
|
+
if (typeof maxWidth === 'string') {
|
|
42
|
+
maxWidthValue =
|
|
43
|
+
theme.breakpoints.values[
|
|
44
|
+
maxWidth as keyof typeof theme.breakpoints.values
|
|
45
|
+
] || maxWidth
|
|
46
|
+
} else {
|
|
47
|
+
maxWidthValue = maxWidth
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const containerStyles: Record<string, any> = {
|
|
52
|
+
borderRadius: 0,
|
|
53
|
+
'& .MuiAlert-message': { p: 0, width: '100%' },
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (maxWidthValue !== 'none') {
|
|
57
|
+
const gutterXs = disableGutters ? '' : ' + 16px'
|
|
58
|
+
const gutterSm = disableGutters ? '' : ' + 24px'
|
|
59
|
+
|
|
60
|
+
containerStyles.px = `calc(max((100% - ${maxWidthValue}px) / 2, 0px)${gutterXs})`
|
|
61
|
+
containerStyles[theme.breakpoints.up('sm')] = {
|
|
62
|
+
px: `calc(max((100% - ${maxWidthValue}px) / 2, 0px)${gutterSm})`,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return containerStyles
|
|
67
|
+
}),
|
|
68
|
+
...normalizedSx,
|
|
41
69
|
]}
|
|
42
70
|
closeText={t('close')}
|
|
43
71
|
>
|
|
44
|
-
{
|
|
72
|
+
{children}
|
|
45
73
|
</MuiAlert>
|
|
46
74
|
)
|
|
47
75
|
}
|
|
@@ -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
|