@registrucentras/rc-ses-react-components 2.0.0-rc.9 → 2.1.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 +4 -0
- package/dist/assets/icons/ShoppingCartIcon.d.ts +3 -0
- package/dist/components/common/CardShell/index.d.ts +1 -1
- package/dist/components/common/CardShell/types.d.ts +10 -0
- package/dist/components/common/ListWithIcons/ListWithIcons.types.d.ts +4 -1
- package/dist/components/common/StepCard/StepCardFooter/index.d.ts +34 -0
- package/dist/components/common/StepCard/index.d.ts +3 -0
- package/dist/components/common/StepCard/types.d.ts +39 -0
- package/dist/components/common/TitleBlock/types.d.ts +1 -1
- package/dist/components/layout/ServiceFormContainer/CardFormContainer/index.d.ts +3 -0
- package/dist/components/loaders/LoadingSpinner/index.d.ts +1 -4
- package/dist/library/icons.d.ts +2 -1
- package/dist/library/index.d.ts +2 -1
- package/dist/library/types.d.ts +4 -3
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +2091 -1888
- package/dist/theme/cards.d.ts +12 -12
- package/dist/theme/light/MuiTypography.d.ts +14 -0
- package/dist/theme/palette.d.ts +124 -124
- package/dist/theme/spacing.d.ts +4 -0
- package/package.json +2 -1
- package/src/assets/icons/ShoppingCartIcon.tsx +16 -0
- package/src/components/common/Button/index.test.tsx +20 -11
- package/src/components/common/Button/index.tsx +8 -44
- package/src/components/common/CardShell/index.tsx +6 -2
- package/src/components/common/CardShell/types.ts +10 -0
- package/src/components/common/ListWithIcons/ListWithIcons.types.ts +22 -1
- package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +13 -4
- package/src/components/common/ListWithIcons/index.test.tsx +42 -0
- package/src/components/common/StepCard/StepCardFooter/index.test.tsx +162 -0
- package/src/components/common/StepCard/StepCardFooter/index.tsx +120 -0
- package/src/components/common/StepCard/index.test.tsx +120 -0
- package/src/components/common/StepCard/index.tsx +74 -0
- package/src/components/common/StepCard/types.ts +45 -0
- package/src/components/common/TitleBlock/types.ts +1 -1
- package/src/components/form/inputs/SearchableField.test.tsx +1 -1
- package/src/components/layout/ServiceFormContainer/CardFormContainer/index.tsx +3 -0
- package/src/components/loaders/LoadingSpinner/index.tsx +3 -26
- package/src/examples/ListWithPagination/index.tsx +2 -1
- package/src/i18n/namespaces/common/en.json +7 -0
- package/src/i18n/namespaces/common/lt.json +7 -0
- package/src/library/icons.ts +2 -0
- package/src/library/index.ts +2 -0
- package/src/library/types.ts +17 -2
- package/src/stories/atoms/Button.stories.tsx +202 -497
- package/src/stories/foundations/ThemedMuiComponents.stories.tsx +2 -2
- package/src/stories/molecules/CardShell.stories.tsx +36 -2
- package/src/stories/molecules/DatePicker.stories.tsx +1 -2
- package/src/stories/molecules/ListWithIcons.stories.tsx +26 -0
- package/src/stories/molecules/Popover.stories.tsx +1 -1
- package/src/stories/molecules/StepCard.stories.tsx +181 -0
- package/src/stories/molecules/TitleBlock.stories.tsx +2 -2
- package/src/stories/organisms/AdvancedListItem.stories.tsx +80 -0
- package/src/stories/organisms/CardFormContainer.stories.tsx +1 -1
- package/src/stories/organisms/Dialog.stories.tsx +1 -2
- package/src/theme/light/MuiButton.tsx +54 -0
- package/src/theme/light/MuiCard.tsx +9 -7
- package/src/theme/light/MuiTypography.tsx +17 -0
- package/src/theme/palette.tsx +7 -7
- package/src/theme/spacing.ts +5 -0
|
@@ -2,22 +2,31 @@ import { Box, Skeleton, Tooltip, Typography } from '@mui/material'
|
|
|
2
2
|
|
|
3
3
|
import palette from '@/theme/palette'
|
|
4
4
|
|
|
5
|
-
import { ListWithIconsItemData } from '../ListWithIcons.types'
|
|
5
|
+
import { ListWithIconsItemData, ListWithIconsItemTone } from '../ListWithIcons.types'
|
|
6
6
|
|
|
7
7
|
interface Props extends ListWithIconsItemData {
|
|
8
8
|
isLoading?: boolean
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
const TEXT_TONE_COLORS: Record<ListWithIconsItemTone, string> = {
|
|
12
|
+
default: palette.grey[900],
|
|
13
|
+
secondary: palette.grey[600],
|
|
14
|
+
muted: palette.grey[500],
|
|
15
|
+
link: palette.primary['700'],
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
const ListWithIconsItem = ({
|
|
12
19
|
icon,
|
|
13
20
|
text,
|
|
14
21
|
disabled,
|
|
15
22
|
tooltip,
|
|
16
|
-
textColor,
|
|
23
|
+
textColor = 'secondary',
|
|
17
24
|
isLoading,
|
|
18
25
|
}: Props) => {
|
|
19
26
|
const Icon = icon
|
|
20
27
|
|
|
28
|
+
const resolvedColor = TEXT_TONE_COLORS[textColor as ListWithIconsItemTone] ?? textColor
|
|
29
|
+
|
|
21
30
|
const content = (
|
|
22
31
|
<Box
|
|
23
32
|
sx={{
|
|
@@ -29,7 +38,7 @@ const ListWithIconsItem = ({
|
|
|
29
38
|
>
|
|
30
39
|
{Icon && (
|
|
31
40
|
<Box sx={{ display: 'flex', alignItems: 'center', height: 20 }}>
|
|
32
|
-
<Icon fillColor={
|
|
41
|
+
<Icon fillColor={resolvedColor} size={16} />
|
|
33
42
|
</Box>
|
|
34
43
|
)}
|
|
35
44
|
<Typography
|
|
@@ -40,7 +49,7 @@ const ListWithIconsItem = ({
|
|
|
40
49
|
fontWeight: 300,
|
|
41
50
|
whiteSpace: 'normal',
|
|
42
51
|
wordBreak: 'break-word',
|
|
43
|
-
color:
|
|
52
|
+
color: resolvedColor,
|
|
44
53
|
}}
|
|
45
54
|
>
|
|
46
55
|
{text}
|
|
@@ -4,6 +4,7 @@ import { type ReactElement } from 'react'
|
|
|
4
4
|
import { describe, expect, test } from 'vitest'
|
|
5
5
|
|
|
6
6
|
import theme from '@/theme/light'
|
|
7
|
+
import { grey, primary, secondary } from '@/theme/palette'
|
|
7
8
|
|
|
8
9
|
import ListWithIcons from '.'
|
|
9
10
|
|
|
@@ -62,4 +63,45 @@ describe('ListWithIcons', () => {
|
|
|
62
63
|
|
|
63
64
|
expect(await screen.findByRole('tooltip')).toHaveTextContent('Helpful tooltip text')
|
|
64
65
|
})
|
|
66
|
+
|
|
67
|
+
test('applies the DS Text token color for the given textColor tone name', () => {
|
|
68
|
+
renderListWithIcons(
|
|
69
|
+
<ListWithIcons
|
|
70
|
+
items={[
|
|
71
|
+
{ text: 'Default text', textColor: 'default' },
|
|
72
|
+
{ text: 'Secondary text', textColor: 'secondary' },
|
|
73
|
+
{ text: 'Muted text', textColor: 'muted' },
|
|
74
|
+
{ text: 'Link text', textColor: 'link' },
|
|
75
|
+
]}
|
|
76
|
+
/>,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
expect(screen.getByText('Default text')).toHaveStyle({ color: grey[900] })
|
|
80
|
+
expect(screen.getByText('Secondary text')).toHaveStyle({ color: grey[600] })
|
|
81
|
+
expect(screen.getByText('Muted text')).toHaveStyle({ color: grey[500] })
|
|
82
|
+
expect(screen.getByText('Link text')).toHaveStyle({ color: primary['700'] })
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('falls back to the secondary tone color/icon fill when textColor is omitted', () => {
|
|
86
|
+
const StubIcon = ({ fillColor }: { fillColor?: string }) => (
|
|
87
|
+
<span data-testid='stub-icon' data-fill-color={fillColor}>
|
|
88
|
+
icon
|
|
89
|
+
</span>
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
renderListWithIcons(
|
|
93
|
+
<ListWithIcons items={[{ icon: StubIcon, text: 'No explicit color' }]} />,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
expect(screen.getByText('No explicit color')).toHaveStyle({ color: grey[600] })
|
|
97
|
+
expect(screen.getByTestId('stub-icon')).toHaveAttribute('data-fill-color', grey[600])
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('accepts a raw palette color value for textColor, not just a named tone', () => {
|
|
101
|
+
renderListWithIcons(
|
|
102
|
+
<ListWithIcons items={[{ text: 'Custom colored', textColor: secondary['700'] }]} />,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
expect(screen.getByText('Custom colored')).toHaveStyle({ color: secondary['700'] })
|
|
106
|
+
})
|
|
65
107
|
})
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import RcSesStepCardFooter from '.'
|
|
5
|
+
|
|
6
|
+
const STEP_COUNT = 3
|
|
7
|
+
|
|
8
|
+
describe('RcSesStepCardFooter', () => {
|
|
9
|
+
describe('First step (activeStep === 0)', () => {
|
|
10
|
+
it('renders Atšaukti + Tęsti and no back arrow', () => {
|
|
11
|
+
render(<RcSesStepCardFooter activeStep={0} stepCount={STEP_COUNT} />)
|
|
12
|
+
|
|
13
|
+
expect(screen.getByRole('button', { name: 'Atšaukti' })).toBeInTheDocument()
|
|
14
|
+
expect(screen.getByRole('button', { name: 'Tęsti' })).toBeInTheDocument()
|
|
15
|
+
expect(screen.queryByRole('button', { name: 'Atgal' })).not.toBeInTheDocument()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('calls onCancel on leading click and onNext on trailing click', () => {
|
|
19
|
+
const onCancel = vi.fn()
|
|
20
|
+
const onNext = vi.fn()
|
|
21
|
+
const onBack = vi.fn()
|
|
22
|
+
|
|
23
|
+
render(
|
|
24
|
+
<RcSesStepCardFooter
|
|
25
|
+
activeStep={0}
|
|
26
|
+
stepCount={STEP_COUNT}
|
|
27
|
+
onCancel={onCancel}
|
|
28
|
+
onNext={onNext}
|
|
29
|
+
onBack={onBack}
|
|
30
|
+
/>,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
fireEvent.click(screen.getByRole('button', { name: 'Atšaukti' }))
|
|
34
|
+
fireEvent.click(screen.getByRole('button', { name: 'Tęsti' }))
|
|
35
|
+
|
|
36
|
+
expect(onCancel).toHaveBeenCalledTimes(1)
|
|
37
|
+
expect(onNext).toHaveBeenCalledTimes(1)
|
|
38
|
+
expect(onBack).not.toHaveBeenCalled()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('does not render the price summary even if totalPrice is passed', () => {
|
|
42
|
+
render(
|
|
43
|
+
<RcSesStepCardFooter activeStep={0} stepCount={STEP_COUNT} totalPrice='4,01 €' />,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
expect(screen.queryByText('4,01 €')).not.toBeInTheDocument()
|
|
47
|
+
expect(screen.queryByText(/Suma be PVM/i)).not.toBeInTheDocument()
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
describe('Middle step (0 < activeStep < stepCount - 1)', () => {
|
|
52
|
+
it('renders Atgal + Tęsti', () => {
|
|
53
|
+
render(<RcSesStepCardFooter activeStep={1} stepCount={STEP_COUNT} />)
|
|
54
|
+
|
|
55
|
+
expect(screen.getByRole('button', { name: /Atgal/ })).toBeInTheDocument()
|
|
56
|
+
expect(screen.getByRole('button', { name: 'Tęsti' })).toBeInTheDocument()
|
|
57
|
+
expect(screen.queryByRole('button', { name: 'Atšaukti' })).not.toBeInTheDocument()
|
|
58
|
+
expect(
|
|
59
|
+
screen.queryByRole('button', { name: /Pridėti į krepšelį/ }),
|
|
60
|
+
).not.toBeInTheDocument()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('routes leading click to onBack (not onCancel)', () => {
|
|
64
|
+
const onBack = vi.fn()
|
|
65
|
+
const onCancel = vi.fn()
|
|
66
|
+
|
|
67
|
+
render(
|
|
68
|
+
<RcSesStepCardFooter
|
|
69
|
+
activeStep={1}
|
|
70
|
+
stepCount={STEP_COUNT}
|
|
71
|
+
onBack={onBack}
|
|
72
|
+
onCancel={onCancel}
|
|
73
|
+
/>,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
fireEvent.click(screen.getByRole('button', { name: /Atgal/ }))
|
|
77
|
+
|
|
78
|
+
expect(onBack).toHaveBeenCalledTimes(1)
|
|
79
|
+
expect(onCancel).not.toHaveBeenCalled()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('does not render the price summary', () => {
|
|
83
|
+
render(
|
|
84
|
+
<RcSesStepCardFooter activeStep={1} stepCount={STEP_COUNT} totalPrice='4,01 €' />,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
expect(screen.queryByText('4,01 €')).not.toBeInTheDocument()
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
describe('Last step (activeStep >= stepCount - 1)', () => {
|
|
92
|
+
it('renders Atgal + "Pridėti į krepšelį"', () => {
|
|
93
|
+
render(<RcSesStepCardFooter activeStep={2} stepCount={STEP_COUNT} />)
|
|
94
|
+
|
|
95
|
+
expect(screen.getByRole('button', { name: /Atgal/ })).toBeInTheDocument()
|
|
96
|
+
expect(
|
|
97
|
+
screen.getByRole('button', { name: /Pridėti į krepšelį/ }),
|
|
98
|
+
).toBeInTheDocument()
|
|
99
|
+
expect(screen.queryByRole('button', { name: 'Tęsti' })).not.toBeInTheDocument()
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('renders the price summary when totalPrice is provided', () => {
|
|
103
|
+
render(
|
|
104
|
+
<RcSesStepCardFooter activeStep={2} stepCount={STEP_COUNT} totalPrice='4,01 €' />,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
expect(screen.getByText('Suma be PVM:')).toBeInTheDocument()
|
|
108
|
+
expect(screen.getByText('4,01 €')).toBeInTheDocument()
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('omits the price summary when totalPrice is missing', () => {
|
|
112
|
+
render(<RcSesStepCardFooter activeStep={2} stepCount={STEP_COUNT} />)
|
|
113
|
+
|
|
114
|
+
expect(screen.queryByText(/Suma be PVM/i)).not.toBeInTheDocument()
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('calls onNext when "Pridėti į krepšelį" is clicked', () => {
|
|
118
|
+
const onNext = vi.fn()
|
|
119
|
+
|
|
120
|
+
render(
|
|
121
|
+
<RcSesStepCardFooter
|
|
122
|
+
activeStep={2}
|
|
123
|
+
stepCount={STEP_COUNT}
|
|
124
|
+
onNext={onNext}
|
|
125
|
+
totalPrice='4,01 €'
|
|
126
|
+
/>,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
fireEvent.click(screen.getByRole('button', { name: /Pridėti į krepšelį/ }))
|
|
130
|
+
expect(onNext).toHaveBeenCalledTimes(1)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('treats activeStep > stepCount - 1 as the last step', () => {
|
|
134
|
+
render(<RcSesStepCardFooter activeStep={99} stepCount={STEP_COUNT} />)
|
|
135
|
+
|
|
136
|
+
expect(
|
|
137
|
+
screen.getByRole('button', { name: /Pridėti į krepšelį/ }),
|
|
138
|
+
).toBeInTheDocument()
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
describe('Edge cases', () => {
|
|
143
|
+
it('does not throw when handlers are omitted and buttons are clicked', () => {
|
|
144
|
+
render(<RcSesStepCardFooter activeStep={0} stepCount={STEP_COUNT} />)
|
|
145
|
+
|
|
146
|
+
expect(() => {
|
|
147
|
+
fireEvent.click(screen.getByRole('button', { name: 'Atšaukti' }))
|
|
148
|
+
fireEvent.click(screen.getByRole('button', { name: 'Tęsti' }))
|
|
149
|
+
}).not.toThrow()
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('treats a single-step wizard as both first AND last (Atšaukti + Pridėti į krepšelį)', () => {
|
|
153
|
+
render(<RcSesStepCardFooter activeStep={0} stepCount={1} totalPrice='4,01 €' />)
|
|
154
|
+
|
|
155
|
+
expect(screen.getByRole('button', { name: 'Atšaukti' })).toBeInTheDocument()
|
|
156
|
+
expect(
|
|
157
|
+
screen.getByRole('button', { name: /Pridėti į krepšelį/ }),
|
|
158
|
+
).toBeInTheDocument()
|
|
159
|
+
expect(screen.getByText('4,01 €')).toBeInTheDocument()
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
})
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Box, Button, Typography } from '@mui/material'
|
|
2
|
+
import { useTranslation } from 'react-i18next'
|
|
3
|
+
|
|
4
|
+
import ArrowLeftIcon from '@/assets/icons/ArrowLeftIcon'
|
|
5
|
+
import ArrowRightIcon from '@/assets/icons/ArrowRightIcon'
|
|
6
|
+
import ShoppingCartIcon from '@/assets/icons/ShoppingCartIcon'
|
|
7
|
+
import RcSesCardFooter from '@/components/common/CardShell/CardFooter'
|
|
8
|
+
import { typography } from '@/theme/light/MuiTypography'
|
|
9
|
+
|
|
10
|
+
export interface RcSesStepCardFooterProps {
|
|
11
|
+
activeStep: number
|
|
12
|
+
stepCount: number
|
|
13
|
+
onNext?: () => void
|
|
14
|
+
onBack?: () => void
|
|
15
|
+
onCancel?: () => void
|
|
16
|
+
totalPrice?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const responsiveWidthSx = { width: { xs: '100%', sm: 'auto' } } as const
|
|
20
|
+
|
|
21
|
+
export const stepCardFooterLeadingSx = {
|
|
22
|
+
mt: { xs: 0.5, sm: 0 },
|
|
23
|
+
order: { xs: 1, sm: 0 },
|
|
24
|
+
...responsiveWidthSx,
|
|
25
|
+
} as const
|
|
26
|
+
|
|
27
|
+
export const stepCardFooterTrailingSx = {
|
|
28
|
+
order: { xs: 0, sm: 1 },
|
|
29
|
+
...responsiveWidthSx,
|
|
30
|
+
} as const
|
|
31
|
+
|
|
32
|
+
function PriceSummary({ label, price }: { label: string; price: string }) {
|
|
33
|
+
return (
|
|
34
|
+
<Box
|
|
35
|
+
sx={{
|
|
36
|
+
alignItems: { xs: 'baseline', sm: 'flex-end' },
|
|
37
|
+
display: 'flex',
|
|
38
|
+
flexDirection: { xs: 'row', sm: 'column' },
|
|
39
|
+
gap: { xs: 1, sm: 0.25 },
|
|
40
|
+
justifyContent: 'center',
|
|
41
|
+
textAlign: { xs: 'center', sm: 'right' },
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
<Typography variant='caption' sx={{ color: 'grey.500' }}>
|
|
45
|
+
{label}:
|
|
46
|
+
</Typography>
|
|
47
|
+
<Typography variant='h5' sx={typography.priceEmphasis}>
|
|
48
|
+
{price}
|
|
49
|
+
</Typography>
|
|
50
|
+
</Box>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function RcSesStepCardFooter({
|
|
55
|
+
activeStep,
|
|
56
|
+
stepCount,
|
|
57
|
+
onNext,
|
|
58
|
+
onBack,
|
|
59
|
+
onCancel,
|
|
60
|
+
totalPrice,
|
|
61
|
+
}: RcSesStepCardFooterProps) {
|
|
62
|
+
const { t } = useTranslation('common')
|
|
63
|
+
|
|
64
|
+
const isFirstStep = activeStep <= 0
|
|
65
|
+
const isLastStep = activeStep >= stepCount - 1
|
|
66
|
+
|
|
67
|
+
const leadingLabel = t(
|
|
68
|
+
isFirstStep ? 'components.StepCard.cancel' : 'components.StepCard.back',
|
|
69
|
+
)
|
|
70
|
+
const trailingLabel = t(
|
|
71
|
+
isLastStep ? 'components.StepCard.addToCart' : 'components.StepCard.continue',
|
|
72
|
+
)
|
|
73
|
+
const handleLeadingClick = isFirstStep ? onCancel : onBack
|
|
74
|
+
const showPriceSummary = isLastStep && Boolean(totalPrice)
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<RcSesCardFooter align='between'>
|
|
78
|
+
<Box sx={stepCardFooterLeadingSx}>
|
|
79
|
+
<Button
|
|
80
|
+
color='grey'
|
|
81
|
+
variant='outlined'
|
|
82
|
+
onClick={handleLeadingClick}
|
|
83
|
+
fullWidth
|
|
84
|
+
sx={responsiveWidthSx}
|
|
85
|
+
startIcon={isFirstStep ? undefined : <ArrowLeftIcon size={24} />}
|
|
86
|
+
>
|
|
87
|
+
{leadingLabel}
|
|
88
|
+
</Button>
|
|
89
|
+
</Box>
|
|
90
|
+
<Box
|
|
91
|
+
sx={{
|
|
92
|
+
alignItems: 'center',
|
|
93
|
+
display: 'flex',
|
|
94
|
+
flexDirection: { xs: 'column', sm: 'row' },
|
|
95
|
+
gap: 2,
|
|
96
|
+
...stepCardFooterTrailingSx,
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
{showPriceSummary ? (
|
|
100
|
+
<PriceSummary
|
|
101
|
+
label={t('components.StepCard.totalWithoutVat')}
|
|
102
|
+
price={totalPrice as string}
|
|
103
|
+
/>
|
|
104
|
+
) : null}
|
|
105
|
+
<Button
|
|
106
|
+
variant='contained'
|
|
107
|
+
onClick={onNext}
|
|
108
|
+
sx={responsiveWidthSx}
|
|
109
|
+
endIcon={
|
|
110
|
+
isLastStep ? <ShoppingCartIcon size={24} /> : <ArrowRightIcon size={24} />
|
|
111
|
+
}
|
|
112
|
+
>
|
|
113
|
+
{trailingLabel}
|
|
114
|
+
</Button>
|
|
115
|
+
</Box>
|
|
116
|
+
</RcSesCardFooter>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export default RcSesStepCardFooter
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import RcSesStepCard from '.'
|
|
5
|
+
|
|
6
|
+
const STEP_COUNT = 3
|
|
7
|
+
|
|
8
|
+
describe('RcSesStepCard', () => {
|
|
9
|
+
it('renders the title block header + body children + default footer', () => {
|
|
10
|
+
render(
|
|
11
|
+
<RcSesStepCard
|
|
12
|
+
activeStep={0}
|
|
13
|
+
stepCount={STEP_COUNT}
|
|
14
|
+
title='Pasirinkite paslaugą'
|
|
15
|
+
description='Trumpas paaiškinimas'
|
|
16
|
+
>
|
|
17
|
+
<div data-testid='body'>Kūnas</div>
|
|
18
|
+
</RcSesStepCard>,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
expect(screen.getByText('Pasirinkite paslaugą')).toBeInTheDocument()
|
|
22
|
+
expect(screen.getByText('Trumpas paaiškinimas')).toBeInTheDocument()
|
|
23
|
+
expect(screen.getByTestId('body')).toBeInTheDocument()
|
|
24
|
+
// default footer (first step)
|
|
25
|
+
expect(screen.getByRole('button', { name: 'Atšaukti' })).toBeInTheDocument()
|
|
26
|
+
expect(screen.getByRole('button', { name: 'Tęsti' })).toBeInTheDocument()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('renders the middle-step footer variant', () => {
|
|
30
|
+
render(<RcSesStepCard activeStep={1} stepCount={STEP_COUNT} title='Vidurinis' />)
|
|
31
|
+
|
|
32
|
+
expect(screen.getByRole('button', { name: /Atgal/ })).toBeInTheDocument()
|
|
33
|
+
expect(screen.getByRole('button', { name: 'Tęsti' })).toBeInTheDocument()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('renders the last-step footer variant with total price', () => {
|
|
37
|
+
render(
|
|
38
|
+
<RcSesStepCard
|
|
39
|
+
activeStep={2}
|
|
40
|
+
stepCount={STEP_COUNT}
|
|
41
|
+
title='Suvestinė'
|
|
42
|
+
totalPrice='4,01 €'
|
|
43
|
+
/>,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
expect(screen.getByRole('button', { name: /Pridėti į krepšelį/ })).toBeInTheDocument()
|
|
47
|
+
expect(screen.getByText('Suma be PVM:')).toBeInTheDocument()
|
|
48
|
+
expect(screen.getByText('4,01 €')).toBeInTheDocument()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('forwards step handlers to the default footer', () => {
|
|
52
|
+
const onNext = vi.fn()
|
|
53
|
+
const onBack = vi.fn()
|
|
54
|
+
const onCancel = vi.fn()
|
|
55
|
+
|
|
56
|
+
render(
|
|
57
|
+
<RcSesStepCard
|
|
58
|
+
activeStep={0}
|
|
59
|
+
stepCount={STEP_COUNT}
|
|
60
|
+
title='Pirmas'
|
|
61
|
+
onNext={onNext}
|
|
62
|
+
onBack={onBack}
|
|
63
|
+
onCancel={onCancel}
|
|
64
|
+
/>,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
screen.getByRole('button', { name: 'Atšaukti' }).click()
|
|
68
|
+
screen.getByRole('button', { name: 'Tęsti' }).click()
|
|
69
|
+
|
|
70
|
+
expect(onCancel).toHaveBeenCalledTimes(1)
|
|
71
|
+
expect(onNext).toHaveBeenCalledTimes(1)
|
|
72
|
+
expect(onBack).not.toHaveBeenCalled()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('replaces the default footer when `footer` prop is provided', () => {
|
|
76
|
+
render(
|
|
77
|
+
<RcSesStepCard
|
|
78
|
+
activeStep={0}
|
|
79
|
+
stepCount={STEP_COUNT}
|
|
80
|
+
title='Pirmas'
|
|
81
|
+
footer={<div data-testid='custom-footer'>Custom</div>}
|
|
82
|
+
/>,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
expect(screen.getByTestId('custom-footer')).toBeInTheDocument()
|
|
86
|
+
// default footer buttons must be absent
|
|
87
|
+
expect(screen.queryByRole('button', { name: 'Atšaukti' })).not.toBeInTheDocument()
|
|
88
|
+
expect(screen.queryByRole('button', { name: 'Tęsti' })).not.toBeInTheDocument()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('wires testIds through to the shell slots', () => {
|
|
92
|
+
render(
|
|
93
|
+
<RcSesStepCard
|
|
94
|
+
activeStep={0}
|
|
95
|
+
stepCount={STEP_COUNT}
|
|
96
|
+
title='T'
|
|
97
|
+
testIds={{
|
|
98
|
+
root: 'sc-root',
|
|
99
|
+
header: 'sc-header',
|
|
100
|
+
content: 'sc-content',
|
|
101
|
+
footer: 'sc-footer',
|
|
102
|
+
}}
|
|
103
|
+
>
|
|
104
|
+
<div>body</div>
|
|
105
|
+
</RcSesStepCard>,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
expect(screen.getByTestId('sc-root')).toBeInTheDocument()
|
|
109
|
+
expect(screen.getByTestId('sc-header')).toBeInTheDocument()
|
|
110
|
+
expect(screen.getByTestId('sc-content')).toBeInTheDocument()
|
|
111
|
+
expect(screen.getByTestId('sc-footer')).toBeInTheDocument()
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('renders without children (body slot is optional)', () => {
|
|
115
|
+
render(<RcSesStepCard activeStep={0} stepCount={STEP_COUNT} title='Tik antraštė' />)
|
|
116
|
+
|
|
117
|
+
expect(screen.getByText('Tik antraštė')).toBeInTheDocument()
|
|
118
|
+
expect(screen.getByRole('button', { name: 'Tęsti' })).toBeInTheDocument()
|
|
119
|
+
})
|
|
120
|
+
})
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Box, Typography } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
import RcSesCardShell from '@/components/common/CardShell'
|
|
4
|
+
import RcSesTitleBlock from '@/components/common/TitleBlock'
|
|
5
|
+
import { typography } from '@/theme/light/MuiTypography'
|
|
6
|
+
import { spacing } from '@/theme/spacing'
|
|
7
|
+
|
|
8
|
+
import RcSesStepCardFooter, {
|
|
9
|
+
stepCardFooterLeadingSx,
|
|
10
|
+
stepCardFooterTrailingSx,
|
|
11
|
+
} from './StepCardFooter'
|
|
12
|
+
import { RcSesStepCardProps } from './types'
|
|
13
|
+
|
|
14
|
+
function RcSesStepCard({
|
|
15
|
+
activeStep,
|
|
16
|
+
stepCount,
|
|
17
|
+
onNext,
|
|
18
|
+
onBack,
|
|
19
|
+
onCancel,
|
|
20
|
+
totalPrice,
|
|
21
|
+
title,
|
|
22
|
+
description,
|
|
23
|
+
footer,
|
|
24
|
+
children,
|
|
25
|
+
testIds,
|
|
26
|
+
}: RcSesStepCardProps) {
|
|
27
|
+
const resolvedFooter = footer ? (
|
|
28
|
+
<Box
|
|
29
|
+
sx={{
|
|
30
|
+
width: '100%',
|
|
31
|
+
'& > * > :first-of-type': stepCardFooterLeadingSx,
|
|
32
|
+
'& > * > :last-child': stepCardFooterTrailingSx,
|
|
33
|
+
}}
|
|
34
|
+
>
|
|
35
|
+
{footer}
|
|
36
|
+
</Box>
|
|
37
|
+
) : (
|
|
38
|
+
<RcSesStepCardFooter
|
|
39
|
+
activeStep={activeStep}
|
|
40
|
+
stepCount={stepCount}
|
|
41
|
+
onNext={onNext}
|
|
42
|
+
onBack={onBack}
|
|
43
|
+
onCancel={onCancel}
|
|
44
|
+
totalPrice={totalPrice}
|
|
45
|
+
/>
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
const resolvedDescription =
|
|
49
|
+
description !== undefined && description !== null ? (
|
|
50
|
+
<Typography component='span' sx={typography.bodyRegularMuted}>
|
|
51
|
+
{description}
|
|
52
|
+
</Typography>
|
|
53
|
+
) : undefined
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<RcSesCardShell
|
|
57
|
+
testIds={testIds}
|
|
58
|
+
contentGap={spacing.sectionGap}
|
|
59
|
+
footerGap={spacing.sectionGap}
|
|
60
|
+
header={
|
|
61
|
+
<RcSesTitleBlock
|
|
62
|
+
title={title}
|
|
63
|
+
description={resolvedDescription}
|
|
64
|
+
titleVariant='h4'
|
|
65
|
+
/>
|
|
66
|
+
}
|
|
67
|
+
footer={resolvedFooter}
|
|
68
|
+
>
|
|
69
|
+
{children}
|
|
70
|
+
</RcSesCardShell>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default RcSesStepCard
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
import { RcSesTitleBlockBaseProps } from '@/components/common/TitleBlock/types'
|
|
4
|
+
|
|
5
|
+
export interface RcSesStepCardTestIds {
|
|
6
|
+
root?: string
|
|
7
|
+
header?: string
|
|
8
|
+
content?: string
|
|
9
|
+
footer?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RcSesStepCardProps extends Pick<
|
|
13
|
+
RcSesTitleBlockBaseProps,
|
|
14
|
+
'title' | 'description'
|
|
15
|
+
> {
|
|
16
|
+
/**
|
|
17
|
+
* Zero-based index of the currently active step. Drives the step-position
|
|
18
|
+
* variant of the default footer (first / middle / last).
|
|
19
|
+
*/
|
|
20
|
+
activeStep: number
|
|
21
|
+
/** Total number of steps in the wizard. Drives last-step detection. */
|
|
22
|
+
stepCount: number
|
|
23
|
+
/**
|
|
24
|
+
* Fired when the trailing CTA is clicked ("Tęsti" on first / middle,
|
|
25
|
+
* "Į krepšelį" on the last step). The parent decides what "next" means.
|
|
26
|
+
*/
|
|
27
|
+
onNext?: () => void
|
|
28
|
+
/** Fired when the leading "Atgal" button is clicked (middle + last step). */
|
|
29
|
+
onBack?: () => void
|
|
30
|
+
/** Fired when the leading "Atšaukti" button is clicked (first step). */
|
|
31
|
+
onCancel?: () => void
|
|
32
|
+
/**
|
|
33
|
+
* Total price shown next to the trailing CTA on the last step, rendered as
|
|
34
|
+
* `Suma be PVM: {totalPrice}`. Pass a preformatted string ("4,01 €") so
|
|
35
|
+
* locale + currency stay a consumer concern.
|
|
36
|
+
*/
|
|
37
|
+
totalPrice?: string
|
|
38
|
+
/**
|
|
39
|
+
* Replaces the whole default footer, including the step-position variants.
|
|
40
|
+
* Use when a step needs an entirely custom action row.
|
|
41
|
+
*/
|
|
42
|
+
footer?: ReactNode
|
|
43
|
+
children?: ReactNode
|
|
44
|
+
testIds?: RcSesStepCardTestIds
|
|
45
|
+
}
|
|
@@ -36,7 +36,7 @@ export interface RcSesTitleBlockBaseProps {
|
|
|
36
36
|
*/
|
|
37
37
|
titleTone?: 'default' | 'brand'
|
|
38
38
|
/**
|
|
39
|
-
* Decorative leading visual, `Icon-tile` once
|
|
39
|
+
* Decorative leading visual, `Icon-tile` once that component lands. Rendered
|
|
40
40
|
* `aria-hidden`, so it never contributes to the heading's accessible name.
|
|
41
41
|
*/
|
|
42
42
|
icon?: ReactNode
|
|
@@ -18,7 +18,7 @@ vi.mock('react-i18next', () => ({
|
|
|
18
18
|
}))
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Added ahead of the inputProps -> slotProps migration
|
|
21
|
+
* Added ahead of the inputProps -> slotProps migration.
|
|
22
22
|
* This component had no tests, and its "click the field to open the modal"
|
|
23
23
|
* behaviour is wired through the input slot - the same API that silently stopped
|
|
24
24
|
* forwarding event handlers on Switch in MUI 6, where types keep passing and only
|
|
@@ -15,6 +15,9 @@ export interface RcSesCardFormContainerProps extends RcSesCardProps {
|
|
|
15
15
|
isLoading?: boolean
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `RcSesStepCard` instead. Will be removed in a future major release.
|
|
20
|
+
*/
|
|
18
21
|
const RcSesCardFormContainer = ({
|
|
19
22
|
steps,
|
|
20
23
|
onStepClick,
|