@registrucentras/rc-ses-react-components 2.5.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/common/FilterChip/index.d.ts +8 -0
- package/dist/components/common/StepCard/StepCardFooter/index.d.ts +4 -1
- package/dist/components/common/StepCard/index.d.ts +1 -1
- package/dist/components/common/StepCard/types.d.ts +31 -0
- package/dist/library/index.d.ts +2 -1
- package/dist/library/types.d.ts +3 -2
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +1287 -1203
- package/package.json +1 -1
- package/src/components/common/FilterChip/index.test.tsx +71 -0
- package/src/components/common/FilterChip/index.tsx +89 -0
- package/src/components/common/StepCard/StepCardFooter/index.test.tsx +187 -0
- package/src/components/common/StepCard/StepCardFooter/index.tsx +59 -24
- package/src/components/common/StepCard/index.test.tsx +31 -0
- package/src/components/common/StepCard/index.tsx +4 -0
- package/src/components/common/StepCard/types.ts +33 -0
- package/src/components/form/inputs/Select/index.tsx +3 -1
- package/src/i18n/namespaces/input/en.json +6 -0
- package/src/i18n/namespaces/input/lt.json +6 -0
- package/src/library/index.ts +3 -1
- package/src/library/types.ts +6 -0
- package/src/stories/atoms/FilterChip.stories.tsx +104 -0
- package/src/stories/foundations/ThemedMuiComponents.stories.tsx +31 -0
- package/src/stories/molecules/StepCard.stories.tsx +86 -2
- package/src/theme/light/MuiAutocomplete.ts +5 -1
package/package.json
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import i18n from '@/i18n/i18n'
|
|
5
|
+
|
|
6
|
+
import RcSesFilterChip from '.'
|
|
7
|
+
|
|
8
|
+
// Mock ResizeObserver
|
|
9
|
+
class ResizeObserverMock {
|
|
10
|
+
observe = vi.fn()
|
|
11
|
+
|
|
12
|
+
unobserve = vi.fn()
|
|
13
|
+
|
|
14
|
+
disconnect = vi.fn()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
global.ResizeObserver = ResizeObserverMock
|
|
18
|
+
|
|
19
|
+
describe('RcSesFilterChip', () => {
|
|
20
|
+
const mockOnRemove = vi.fn()
|
|
21
|
+
|
|
22
|
+
beforeEach(async () => {
|
|
23
|
+
vi.clearAllMocks()
|
|
24
|
+
await i18n.changeLanguage('en')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('renders with label', () => {
|
|
28
|
+
render(<RcSesFilterChip label='Test Filter' onRemove={mockOnRemove} />)
|
|
29
|
+
|
|
30
|
+
expect(screen.getByText('Test Filter')).toBeInTheDocument()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('calls onRemove when clicked', () => {
|
|
34
|
+
render(<RcSesFilterChip label='Test Filter' onRemove={mockOnRemove} />)
|
|
35
|
+
|
|
36
|
+
const chip = screen.getByRole('button', {
|
|
37
|
+
name: 'Remove filter: Test Filter',
|
|
38
|
+
})
|
|
39
|
+
fireEvent.click(chip)
|
|
40
|
+
|
|
41
|
+
expect(mockOnRemove).toHaveBeenCalledOnce()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('has proper accessibility attributes', () => {
|
|
45
|
+
render(<RcSesFilterChip label='Test Filter' onRemove={mockOnRemove} />)
|
|
46
|
+
|
|
47
|
+
const chip = screen.getByRole('button', {
|
|
48
|
+
name: 'Remove filter: Test Filter',
|
|
49
|
+
})
|
|
50
|
+
expect(chip).toHaveAttribute('aria-label', 'Remove filter: Test Filter')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('supports custom testId', () => {
|
|
54
|
+
render(
|
|
55
|
+
<RcSesFilterChip
|
|
56
|
+
label='Test Filter'
|
|
57
|
+
onRemove={mockOnRemove}
|
|
58
|
+
testId='custom-chip-id'
|
|
59
|
+
/>,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
expect(screen.getByTestId('custom-chip-id')).toBeInTheDocument()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('is keyboard accessible with Tab', () => {
|
|
66
|
+
render(<RcSesFilterChip label='Test Filter' onRemove={mockOnRemove} />)
|
|
67
|
+
|
|
68
|
+
const chip = screen.getByRole('button')
|
|
69
|
+
expect(chip).toHaveAttribute('tabIndex', '0')
|
|
70
|
+
})
|
|
71
|
+
})
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Chip, Tooltip, useForkRef } from '@mui/material'
|
|
2
|
+
import { forwardRef, useLayoutEffect, useRef, useState } from 'react'
|
|
3
|
+
import { useTranslation } from 'react-i18next'
|
|
4
|
+
|
|
5
|
+
import { CloseIcon } from '@/assets/icons/phosphorIcons'
|
|
6
|
+
import { common, grey, primary } from '@/theme/palette'
|
|
7
|
+
|
|
8
|
+
export interface RcSesFilterChipProps {
|
|
9
|
+
label: string
|
|
10
|
+
onRemove: () => void
|
|
11
|
+
testId?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const RcSesFilterChip = forwardRef<HTMLDivElement, RcSesFilterChipProps>((props, ref) => {
|
|
15
|
+
const { label, onRemove, testId } = props
|
|
16
|
+
const { t } = useTranslation('input', { keyPrefix: 'components.RcSesFilterChip' })
|
|
17
|
+
|
|
18
|
+
const [isTruncated, setIsTruncated] = useState(false)
|
|
19
|
+
const chipRef = useRef<HTMLDivElement>(null)
|
|
20
|
+
const forkRef = useForkRef(chipRef, ref)
|
|
21
|
+
|
|
22
|
+
useLayoutEffect(() => {
|
|
23
|
+
const checkTruncation = () => {
|
|
24
|
+
const labelElement = chipRef.current?.querySelector('.MuiChip-label') as HTMLElement
|
|
25
|
+
if (labelElement) {
|
|
26
|
+
setIsTruncated(labelElement.scrollWidth > labelElement.clientWidth)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
checkTruncation()
|
|
31
|
+
|
|
32
|
+
const observer = new ResizeObserver(checkTruncation)
|
|
33
|
+
if (chipRef.current) {
|
|
34
|
+
observer.observe(chipRef.current)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return () => observer.disconnect()
|
|
38
|
+
}, [label])
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Tooltip title={isTruncated ? label : ''} placement='top' arrow>
|
|
42
|
+
<Chip
|
|
43
|
+
ref={forkRef}
|
|
44
|
+
label={label}
|
|
45
|
+
onClick={onRemove}
|
|
46
|
+
onDelete={onRemove}
|
|
47
|
+
deleteIcon={<CloseIcon size={16} aria-hidden focusable={false} />}
|
|
48
|
+
aria-label={t('aria.label', { label })}
|
|
49
|
+
data-testid={testId}
|
|
50
|
+
sx={{
|
|
51
|
+
maxWidth: '100%',
|
|
52
|
+
borderColor: grey['300'],
|
|
53
|
+
backgroundColor: common.white,
|
|
54
|
+
color: grey['900'],
|
|
55
|
+
'& .MuiChip-label': {
|
|
56
|
+
fontSize: '0.875rem',
|
|
57
|
+
fontWeight: 400,
|
|
58
|
+
lineHeight: '1.25rem',
|
|
59
|
+
minWidth: 0,
|
|
60
|
+
pl: '0.75rem',
|
|
61
|
+
pr: 0,
|
|
62
|
+
},
|
|
63
|
+
'& .MuiChip-deleteIcon': {
|
|
64
|
+
color: grey['900'],
|
|
65
|
+
margin: '0 0.5rem 0 0.25rem',
|
|
66
|
+
flexShrink: 0,
|
|
67
|
+
},
|
|
68
|
+
'&.MuiChip-clickable:hover': {
|
|
69
|
+
borderColor: grey['400'],
|
|
70
|
+
backgroundColor: grey['100'],
|
|
71
|
+
},
|
|
72
|
+
'&:hover .MuiChip-deleteIcon': {
|
|
73
|
+
color: grey['900'],
|
|
74
|
+
},
|
|
75
|
+
'&.Mui-focusVisible': {
|
|
76
|
+
outline: `2px solid ${primary['500']}`,
|
|
77
|
+
outlineOffset: '-2px',
|
|
78
|
+
backgroundColor: common.white,
|
|
79
|
+
},
|
|
80
|
+
}}
|
|
81
|
+
variant='outlined'
|
|
82
|
+
/>
|
|
83
|
+
</Tooltip>
|
|
84
|
+
)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
RcSesFilterChip.displayName = 'RcSesFilterChip'
|
|
88
|
+
|
|
89
|
+
export default RcSesFilterChip
|
|
@@ -108,6 +108,20 @@ describe('RcSesStepCardFooter', () => {
|
|
|
108
108
|
expect(screen.getByText('4,01 €')).toBeInTheDocument()
|
|
109
109
|
})
|
|
110
110
|
|
|
111
|
+
it('replaces the price caption with totalPriceLabel', () => {
|
|
112
|
+
render(
|
|
113
|
+
<RcSesStepCardFooter
|
|
114
|
+
activeStep={2}
|
|
115
|
+
stepCount={STEP_COUNT}
|
|
116
|
+
totalPrice='4,01 €'
|
|
117
|
+
totalPriceLabel='Mokėtina suma'
|
|
118
|
+
/>,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
expect(screen.getByText('Mokėtina suma:')).toBeInTheDocument()
|
|
122
|
+
expect(screen.queryByText(/Suma be PVM/i)).not.toBeInTheDocument()
|
|
123
|
+
})
|
|
124
|
+
|
|
111
125
|
it('omits the price summary when totalPrice is missing', () => {
|
|
112
126
|
render(<RcSesStepCardFooter activeStep={2} stepCount={STEP_COUNT} />)
|
|
113
127
|
|
|
@@ -139,6 +153,179 @@ describe('RcSesStepCardFooter', () => {
|
|
|
139
153
|
})
|
|
140
154
|
})
|
|
141
155
|
|
|
156
|
+
describe('actions', () => {
|
|
157
|
+
it('makes the CTA the submit button of the form named by `form`', () => {
|
|
158
|
+
const onSubmit = vi.fn((event: React.FormEvent) => event.preventDefault())
|
|
159
|
+
|
|
160
|
+
render(
|
|
161
|
+
<>
|
|
162
|
+
<form id='step-form' onSubmit={onSubmit} />
|
|
163
|
+
<RcSesStepCardFooter
|
|
164
|
+
activeStep={0}
|
|
165
|
+
stepCount={STEP_COUNT}
|
|
166
|
+
actions={{ next: { form: 'step-form' } }}
|
|
167
|
+
/>
|
|
168
|
+
</>,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
const next = screen.getByRole('button', { name: 'Tęsti' })
|
|
172
|
+
expect(next).toHaveAttribute('type', 'submit')
|
|
173
|
+
expect(next).toHaveAttribute('form', 'step-form')
|
|
174
|
+
|
|
175
|
+
fireEvent.click(next)
|
|
176
|
+
expect(onSubmit).toHaveBeenCalledTimes(1)
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('keeps the CTA a plain button without `form`', () => {
|
|
180
|
+
render(<RcSesStepCardFooter activeStep={0} stepCount={STEP_COUNT} />)
|
|
181
|
+
|
|
182
|
+
const next = screen.getByRole('button', { name: 'Tęsti' })
|
|
183
|
+
expect(next).toHaveAttribute('type', 'button')
|
|
184
|
+
expect(next).not.toHaveAttribute('form')
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('disables the CTA and shows a spinner while loading', () => {
|
|
188
|
+
render(
|
|
189
|
+
<RcSesStepCardFooter
|
|
190
|
+
activeStep={1}
|
|
191
|
+
stepCount={STEP_COUNT}
|
|
192
|
+
actions={{ next: { loading: true } }}
|
|
193
|
+
/>,
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
expect(screen.getByRole('button', { name: /Tęsti/ })).toBeDisabled()
|
|
197
|
+
expect(screen.getByRole('progressbar')).toBeInTheDocument()
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
it('puts the spinner in the icon slot when the button has an icon', () => {
|
|
201
|
+
render(
|
|
202
|
+
<RcSesStepCardFooter
|
|
203
|
+
activeStep={1}
|
|
204
|
+
stepCount={STEP_COUNT}
|
|
205
|
+
actions={{ next: { loading: true }, back: { loading: true } }}
|
|
206
|
+
/>,
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
expect(screen.getByRole('button', { name: /Tęsti/ })).toHaveClass(
|
|
210
|
+
'MuiButton-loadingPositionEnd',
|
|
211
|
+
)
|
|
212
|
+
expect(screen.getByRole('button', { name: /Atgal/ })).toHaveClass(
|
|
213
|
+
'MuiButton-loadingPositionStart',
|
|
214
|
+
)
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
it('centres the spinner when the button has no icon', () => {
|
|
218
|
+
render(
|
|
219
|
+
<RcSesStepCardFooter
|
|
220
|
+
activeStep={2}
|
|
221
|
+
stepCount={STEP_COUNT}
|
|
222
|
+
actions={{ next: { label: 'Pateikti', icon: null, loading: true } }}
|
|
223
|
+
/>,
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
expect(screen.getByRole('button', { name: /Pateikti/ })).toHaveClass(
|
|
227
|
+
'MuiButton-loadingPositionCenter',
|
|
228
|
+
)
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
it('disables next and back independently', () => {
|
|
232
|
+
render(
|
|
233
|
+
<RcSesStepCardFooter
|
|
234
|
+
activeStep={1}
|
|
235
|
+
stepCount={STEP_COUNT}
|
|
236
|
+
actions={{ next: { disabled: true }, back: { disabled: true } }}
|
|
237
|
+
/>,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
expect(screen.getByRole('button', { name: 'Tęsti' })).toBeDisabled()
|
|
241
|
+
expect(screen.getByRole('button', { name: /Atgal/ })).toBeDisabled()
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
it('overrides the i18n labels', () => {
|
|
245
|
+
render(
|
|
246
|
+
<RcSesStepCardFooter
|
|
247
|
+
activeStep={1}
|
|
248
|
+
stepCount={STEP_COUNT}
|
|
249
|
+
actions={{ next: { label: 'Toliau' }, back: { label: 'Grįžti' } }}
|
|
250
|
+
/>,
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
expect(screen.getByRole('button', { name: 'Toliau' })).toBeInTheDocument()
|
|
254
|
+
expect(screen.getByRole('button', { name: /Grįžti/ })).toBeInTheDocument()
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it('hides the leading button on the first step with `cancel: false`', () => {
|
|
258
|
+
render(
|
|
259
|
+
<RcSesStepCardFooter
|
|
260
|
+
activeStep={0}
|
|
261
|
+
stepCount={STEP_COUNT}
|
|
262
|
+
actions={{ cancel: false }}
|
|
263
|
+
/>,
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
expect(screen.queryByRole('button', { name: 'Atšaukti' })).not.toBeInTheDocument()
|
|
267
|
+
expect(screen.getAllByRole('button')).toHaveLength(1)
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
it('keeps Atgal on later steps with `cancel: false`', () => {
|
|
271
|
+
render(
|
|
272
|
+
<RcSesStepCardFooter
|
|
273
|
+
activeStep={1}
|
|
274
|
+
stepCount={STEP_COUNT}
|
|
275
|
+
actions={{ cancel: false }}
|
|
276
|
+
/>,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
expect(screen.getByRole('button', { name: /Atgal/ })).toBeInTheDocument()
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
it('renders a custom last-step CTA: own label, no cart icon', () => {
|
|
283
|
+
render(
|
|
284
|
+
<RcSesStepCardFooter
|
|
285
|
+
activeStep={2}
|
|
286
|
+
stepCount={STEP_COUNT}
|
|
287
|
+
totalPrice='4,01 €'
|
|
288
|
+
actions={{ next: { label: 'Pateikti', icon: null } }}
|
|
289
|
+
/>,
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
const next = screen.getByRole('button', { name: 'Pateikti' })
|
|
293
|
+
expect(next.querySelector('svg')).toBeNull()
|
|
294
|
+
expect(screen.getByText('4,01 €')).toBeInTheDocument()
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
it('keeps the default icons when `icon` is undefined', () => {
|
|
298
|
+
render(
|
|
299
|
+
<RcSesStepCardFooter
|
|
300
|
+
activeStep={2}
|
|
301
|
+
stepCount={STEP_COUNT}
|
|
302
|
+
actions={{ next: { label: 'Pateikti' }, back: {} }}
|
|
303
|
+
/>,
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
expect(
|
|
307
|
+
screen.getByRole('button', { name: 'Pateikti' }).querySelector('svg'),
|
|
308
|
+
).not.toBeNull()
|
|
309
|
+
expect(
|
|
310
|
+
screen.getByRole('button', { name: /Atgal/ }).querySelector('svg'),
|
|
311
|
+
).not.toBeNull()
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
it('replaces the icon with a custom node', () => {
|
|
315
|
+
render(
|
|
316
|
+
<RcSesStepCardFooter
|
|
317
|
+
activeStep={1}
|
|
318
|
+
stepCount={STEP_COUNT}
|
|
319
|
+
actions={{ next: { icon: <span data-testid='custom-icon' /> } }}
|
|
320
|
+
/>,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
const next = screen.getByRole('button', { name: 'Tęsti' })
|
|
324
|
+
expect(next).toContainElement(screen.getByTestId('custom-icon'))
|
|
325
|
+
expect(next.querySelector('svg')).toBeNull()
|
|
326
|
+
})
|
|
327
|
+
})
|
|
328
|
+
|
|
142
329
|
describe('Edge cases', () => {
|
|
143
330
|
it('does not throw when handlers are omitted and buttons are clicked', () => {
|
|
144
331
|
render(<RcSesStepCardFooter activeStep={0} stepCount={STEP_COUNT} />)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Box, Button, Typography } from '@mui/material'
|
|
1
|
+
import { Box, Button, ButtonProps, Typography } from '@mui/material'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
2
3
|
import { useTranslation } from 'react-i18next'
|
|
3
4
|
|
|
4
5
|
import {
|
|
@@ -9,6 +10,8 @@ import {
|
|
|
9
10
|
import RcSesCardFooter from '@/components/common/CardShell/CardFooter'
|
|
10
11
|
import { typography } from '@/theme/light/MuiTypography'
|
|
11
12
|
|
|
13
|
+
import { RcSesStepCardAction, RcSesStepCardActions } from '../types'
|
|
14
|
+
|
|
12
15
|
export interface RcSesStepCardFooterProps {
|
|
13
16
|
activeStep: number
|
|
14
17
|
stepCount: number
|
|
@@ -16,6 +19,8 @@ export interface RcSesStepCardFooterProps {
|
|
|
16
19
|
onBack?: () => void
|
|
17
20
|
onCancel?: () => void
|
|
18
21
|
totalPrice?: string
|
|
22
|
+
totalPriceLabel?: string
|
|
23
|
+
actions?: RcSesStepCardActions
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
const responsiveWidthSx = { width: { xs: '100%', sm: 'auto' } } as const
|
|
@@ -53,6 +58,23 @@ function PriceSummary({ label, price }: { label: string; price: string }) {
|
|
|
53
58
|
)
|
|
54
59
|
}
|
|
55
60
|
|
|
61
|
+
function createActionButtonProps(
|
|
62
|
+
action: RcSesStepCardAction | undefined,
|
|
63
|
+
defaultIcon: ReactNode,
|
|
64
|
+
side: 'start' | 'end',
|
|
65
|
+
): ButtonProps {
|
|
66
|
+
const icon = action?.icon === undefined ? defaultIcon : action.icon
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
type: action?.form ? 'submit' : 'button',
|
|
70
|
+
form: action?.form,
|
|
71
|
+
loading: action?.loading,
|
|
72
|
+
disabled: action?.disabled,
|
|
73
|
+
loadingPosition: icon ? side : 'center',
|
|
74
|
+
[side === 'start' ? 'startIcon' : 'endIcon']: icon,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
56
78
|
function RcSesStepCardFooter({
|
|
57
79
|
activeStep,
|
|
58
80
|
stepCount,
|
|
@@ -60,35 +82,46 @@ function RcSesStepCardFooter({
|
|
|
60
82
|
onBack,
|
|
61
83
|
onCancel,
|
|
62
84
|
totalPrice,
|
|
85
|
+
totalPriceLabel,
|
|
86
|
+
actions,
|
|
63
87
|
}: RcSesStepCardFooterProps) {
|
|
64
88
|
const { t } = useTranslation('common')
|
|
65
89
|
|
|
66
90
|
const isFirstStep = activeStep <= 0
|
|
67
91
|
const isLastStep = activeStep >= stepCount - 1
|
|
68
92
|
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
93
|
+
const leadingAction = isFirstStep ? actions?.cancel : actions?.back
|
|
94
|
+
const showLeading = leadingAction !== false
|
|
95
|
+
const leading = leadingAction || undefined
|
|
96
|
+
const leadingLabel =
|
|
97
|
+
leading?.label ??
|
|
98
|
+
t(isFirstStep ? 'components.StepCard.cancel' : 'components.StepCard.back')
|
|
99
|
+
const trailingLabel =
|
|
100
|
+
actions?.next?.label ??
|
|
101
|
+
t(isLastStep ? 'components.StepCard.addToCart' : 'components.StepCard.continue')
|
|
75
102
|
const handleLeadingClick = isFirstStep ? onCancel : onBack
|
|
76
103
|
const showPriceSummary = isLastStep && Boolean(totalPrice)
|
|
77
104
|
|
|
78
105
|
return (
|
|
79
|
-
<RcSesCardFooter align='between'>
|
|
80
|
-
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
106
|
+
<RcSesCardFooter align={showLeading ? 'between' : 'end'}>
|
|
107
|
+
{showLeading ? (
|
|
108
|
+
<Box sx={stepCardFooterLeadingSx}>
|
|
109
|
+
<Button
|
|
110
|
+
color='grey'
|
|
111
|
+
variant='outlined'
|
|
112
|
+
onClick={handleLeadingClick}
|
|
113
|
+
fullWidth
|
|
114
|
+
sx={responsiveWidthSx}
|
|
115
|
+
{...createActionButtonProps(
|
|
116
|
+
leading,
|
|
117
|
+
isFirstStep ? undefined : <ArrowLeftIcon size={24} />,
|
|
118
|
+
'start',
|
|
119
|
+
)}
|
|
120
|
+
>
|
|
121
|
+
{leadingLabel}
|
|
122
|
+
</Button>
|
|
123
|
+
</Box>
|
|
124
|
+
) : null}
|
|
92
125
|
<Box
|
|
93
126
|
sx={{
|
|
94
127
|
alignItems: 'center',
|
|
@@ -100,7 +133,7 @@ function RcSesStepCardFooter({
|
|
|
100
133
|
>
|
|
101
134
|
{showPriceSummary ? (
|
|
102
135
|
<PriceSummary
|
|
103
|
-
label={t('components.StepCard.totalWithoutVat')}
|
|
136
|
+
label={totalPriceLabel ?? t('components.StepCard.totalWithoutVat')}
|
|
104
137
|
price={totalPrice as string}
|
|
105
138
|
/>
|
|
106
139
|
) : null}
|
|
@@ -108,9 +141,11 @@ function RcSesStepCardFooter({
|
|
|
108
141
|
variant='contained'
|
|
109
142
|
onClick={onNext}
|
|
110
143
|
sx={responsiveWidthSx}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
144
|
+
{...createActionButtonProps(
|
|
145
|
+
actions?.next,
|
|
146
|
+
isLastStep ? <ShoppingCartIcon size={24} /> : <ArrowRightIcon size={24} />,
|
|
147
|
+
'end',
|
|
148
|
+
)}
|
|
114
149
|
>
|
|
115
150
|
{trailingLabel}
|
|
116
151
|
</Button>
|
|
@@ -48,6 +48,20 @@ describe('RcSesStepCard', () => {
|
|
|
48
48
|
expect(screen.getByText('4,01 €')).toBeInTheDocument()
|
|
49
49
|
})
|
|
50
50
|
|
|
51
|
+
it('forwards totalPriceLabel to the default footer', () => {
|
|
52
|
+
render(
|
|
53
|
+
<RcSesStepCard
|
|
54
|
+
activeStep={2}
|
|
55
|
+
stepCount={STEP_COUNT}
|
|
56
|
+
title='Suvestinė'
|
|
57
|
+
totalPrice='4,01 €'
|
|
58
|
+
totalPriceLabel='Mokėtina suma'
|
|
59
|
+
/>,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
expect(screen.getByText('Mokėtina suma:')).toBeInTheDocument()
|
|
63
|
+
})
|
|
64
|
+
|
|
51
65
|
it('forwards step handlers to the default footer', () => {
|
|
52
66
|
const onNext = vi.fn()
|
|
53
67
|
const onBack = vi.fn()
|
|
@@ -72,6 +86,23 @@ describe('RcSesStepCard', () => {
|
|
|
72
86
|
expect(onBack).not.toHaveBeenCalled()
|
|
73
87
|
})
|
|
74
88
|
|
|
89
|
+
it('forwards `actions` to the default footer', () => {
|
|
90
|
+
render(
|
|
91
|
+
<RcSesStepCard
|
|
92
|
+
activeStep={0}
|
|
93
|
+
stepCount={STEP_COUNT}
|
|
94
|
+
title='Pirmas'
|
|
95
|
+
actions={{ next: { form: 'step-form', label: 'Toliau' }, cancel: false }}
|
|
96
|
+
/>,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
expect(screen.getByRole('button', { name: 'Toliau' })).toHaveAttribute(
|
|
100
|
+
'form',
|
|
101
|
+
'step-form',
|
|
102
|
+
)
|
|
103
|
+
expect(screen.queryByRole('button', { name: 'Atšaukti' })).not.toBeInTheDocument()
|
|
104
|
+
})
|
|
105
|
+
|
|
75
106
|
it('replaces the default footer when `footer` prop is provided', () => {
|
|
76
107
|
render(
|
|
77
108
|
<RcSesStepCard
|
|
@@ -18,6 +18,8 @@ function RcSesStepCard({
|
|
|
18
18
|
onBack,
|
|
19
19
|
onCancel,
|
|
20
20
|
totalPrice,
|
|
21
|
+
totalPriceLabel,
|
|
22
|
+
actions,
|
|
21
23
|
title,
|
|
22
24
|
description,
|
|
23
25
|
footer,
|
|
@@ -42,6 +44,8 @@ function RcSesStepCard({
|
|
|
42
44
|
onBack={onBack}
|
|
43
45
|
onCancel={onCancel}
|
|
44
46
|
totalPrice={totalPrice}
|
|
47
|
+
totalPriceLabel={totalPriceLabel}
|
|
48
|
+
actions={actions}
|
|
45
49
|
/>
|
|
46
50
|
)
|
|
47
51
|
|
|
@@ -9,6 +9,32 @@ export interface RcSesStepCardTestIds {
|
|
|
9
9
|
footer?: string
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export interface RcSesStepCardAction {
|
|
13
|
+
label?: string
|
|
14
|
+
/**
|
|
15
|
+
* `undefined` keeps the default icon (arrows, or the cart on the last step),
|
|
16
|
+
* `null` renders none, a node replaces the icon.
|
|
17
|
+
*/
|
|
18
|
+
icon?: ReactNode
|
|
19
|
+
/**
|
|
20
|
+
* Id of a `<form>` rendered elsewhere. The button becomes that form's submit
|
|
21
|
+
* button (`type="submit" form={id}`). The click handler still fires.
|
|
22
|
+
*/
|
|
23
|
+
form?: string
|
|
24
|
+
/** Shows a spinner in the icon's place and disables the button. */
|
|
25
|
+
loading?: boolean
|
|
26
|
+
disabled?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface RcSesStepCardActions {
|
|
30
|
+
/** The trailing CTA on every step, including the last. */
|
|
31
|
+
next?: RcSesStepCardAction
|
|
32
|
+
/** The leading "Atgal" button (middle + last step). */
|
|
33
|
+
back?: RcSesStepCardAction
|
|
34
|
+
/** The leading "Atšaukti" button (first step). `false` removes it. */
|
|
35
|
+
cancel?: RcSesStepCardAction | false
|
|
36
|
+
}
|
|
37
|
+
|
|
12
38
|
export interface RcSesStepCardProps extends Pick<
|
|
13
39
|
RcSesTitleBlockBaseProps,
|
|
14
40
|
'title' | 'description'
|
|
@@ -35,6 +61,13 @@ export interface RcSesStepCardProps extends Pick<
|
|
|
35
61
|
* locale + currency stay a consumer concern.
|
|
36
62
|
*/
|
|
37
63
|
totalPrice?: string
|
|
64
|
+
/** Replaces the default caption of `totalPrice`. */
|
|
65
|
+
totalPriceLabel?: string
|
|
66
|
+
/**
|
|
67
|
+
* Overrides for the default footer: label, icon, form submit,
|
|
68
|
+
* loading and disabled. Ignored when `footer` is set.
|
|
69
|
+
*/
|
|
70
|
+
actions?: RcSesStepCardActions
|
|
38
71
|
/**
|
|
39
72
|
* Replaces the whole default footer, including the step-position variants.
|
|
40
73
|
* Use when a step needs an entirely custom action row.
|
|
@@ -596,6 +596,7 @@ function RcSesSelect<TFieldValues extends FieldValues = FieldValues>(
|
|
|
596
596
|
handleSelectAll()
|
|
597
597
|
}}
|
|
598
598
|
sx={{
|
|
599
|
+
alignItems: 'center !important',
|
|
599
600
|
display: 'flex',
|
|
600
601
|
flexDirection: 'row !important',
|
|
601
602
|
gap: '.75rem',
|
|
@@ -628,7 +629,7 @@ function RcSesSelect<TFieldValues extends FieldValues = FieldValues>(
|
|
|
628
629
|
toggleGroupValue(groupValue)
|
|
629
630
|
}}
|
|
630
631
|
sx={{
|
|
631
|
-
alignItems: 'center',
|
|
632
|
+
alignItems: 'center !important',
|
|
632
633
|
backgroundColor: isGroupSelected
|
|
633
634
|
? palette.primary['50']
|
|
634
635
|
: 'transparent',
|
|
@@ -678,6 +679,7 @@ function RcSesSelect<TFieldValues extends FieldValues = FieldValues>(
|
|
|
678
679
|
{...rest}
|
|
679
680
|
className={[className, indentClassName].filter(Boolean).join(' ')}
|
|
680
681
|
sx={{
|
|
682
|
+
alignItems: 'center !important',
|
|
681
683
|
display: 'flex',
|
|
682
684
|
gap: multiple ? '.75rem' : '.5rem',
|
|
683
685
|
flexDirection: 'row !important',
|