@registrucentras/rc-ses-react-components 2.0.0-rc.0 → 2.0.0-rc.2
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 +5 -1
- package/dist/assets/icons/CaretUpBoldIcon.d.ts +3 -0
- package/dist/assets/icons/CaretUpIcon.d.ts +3 -0
- package/dist/assets/icons/ListIcon.d.ts +3 -0
- package/dist/assets/icons/MinusIcon.d.ts +3 -0
- package/dist/assets/icons/NotePencilIcon.d.ts +3 -0
- package/dist/assets/icons/PlusIcon.d.ts +3 -0
- package/dist/assets/icons/TrashIcon.d.ts +3 -0
- package/dist/assets/icons/UserIcon.d.ts +3 -0
- package/dist/components/common/AdvancedList/components/AdvancedListItem/AdvancedListItem.types.d.ts +106 -0
- package/dist/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.d.ts +12 -0
- package/dist/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.d.ts +7 -0
- package/dist/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion.d.ts +2 -0
- package/dist/components/common/AdvancedList/components/AdvancedListItem/index.d.ts +4 -0
- package/dist/components/common/AdvancedList/index.d.ts +11 -0
- package/dist/components/common/Button/index.d.ts +13 -3
- package/dist/components/common/SelectableCardList/components/SelectableCardListItem.d.ts +4 -1
- package/dist/components/common/SelectableCardList/index.d.ts +4 -1
- package/dist/components/common/Tooltip/index.d.ts +20 -0
- package/dist/components/form/inputs/Select/index.d.ts +1 -0
- package/dist/library/icons.d.ts +9 -1
- package/dist/library/index.d.ts +5 -0
- package/dist/library/types.d.ts +2 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +4137 -3249
- package/dist/stories/components/actions/Button.stories.d.ts +4 -3
- package/dist/stories/components/display/AdvancedList.stories.d.ts +33 -0
- package/dist/stories/components/display/AdvancedListItem.stories.d.ts +33 -0
- package/dist/stories/components/display/SelectableCardList.stories.d.ts +8 -1
- package/dist/stories/components/display/Tooltip.stories.d.ts +48 -0
- package/dist/stories/components/inputs/DatePicker.stories.d.ts +23 -0
- package/dist/stories/components/loaders/LoadingSpinner.stories.d.ts +3 -3
- package/dist/stories/components/overlays/Dialog.stories.d.ts +6 -0
- package/dist/stories/components/overlays/Popover.stories.d.ts +12 -0
- package/dist/stories/theme/ThemedMuiComponents.stories.d.ts +25 -0
- package/dist/theme/light/MuiTooltip.d.ts +3 -0
- package/dist/theme/motion.d.ts +16 -0
- package/package.json +2 -1
- package/src/assets/icons/CaretUpBoldIcon.tsx +17 -0
- package/src/assets/icons/CaretUpIcon.tsx +9 -0
- package/src/assets/icons/ListIcon.tsx +17 -0
- package/src/assets/icons/MinusIcon.tsx +9 -0
- package/src/assets/icons/NotePencilIcon.tsx +9 -0
- package/src/assets/icons/PlusIcon.tsx +9 -0
- package/src/assets/icons/TrashIcon.tsx +23 -0
- package/src/assets/icons/UserIcon.tsx +17 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/AdvancedListItem.types.ts +100 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.tsx +228 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.tsx +270 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion.test.ts +80 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion.ts +28 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.test.tsx +631 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +340 -0
- package/src/components/common/AdvancedList/index.test.tsx +97 -0
- package/src/components/common/AdvancedList/index.tsx +52 -0
- package/src/components/common/Button/index.tsx +15 -1
- package/src/components/common/Card/index.tsx +2 -2
- package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +7 -5
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.test.tsx +50 -0
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +34 -0
- package/src/components/common/SelectableCardList/index.test.tsx +56 -2
- package/src/components/common/SelectableCardList/index.tsx +29 -10
- package/src/components/common/Tooltip/index.test.tsx +85 -0
- package/src/components/common/Tooltip/index.tsx +168 -0
- package/src/components/form/inputs/FileDropzone.tsx +1 -0
- package/src/components/form/inputs/FileUpload.tsx +1 -0
- package/src/components/form/inputs/NumberStepper.tsx +1 -0
- package/src/components/form/inputs/PhoneInputFormControl/index.tsx +1 -1
- package/src/components/form/inputs/RadioButtonGroup.test.tsx +71 -0
- package/src/components/form/inputs/RadioButtonGroup.tsx +1 -0
- package/src/components/form/inputs/Select/index.test.tsx +159 -0
- package/src/components/form/inputs/Select/index.tsx +107 -52
- package/src/components/layout/Footer/index.test.tsx +13 -0
- package/src/components/layout/Footer/index.tsx +5 -2
- package/src/i18n/namespaces/common/en.json +14 -0
- package/src/i18n/namespaces/common/lt.json +14 -0
- package/src/library/icons.ts +16 -0
- package/src/library/index.ts +5 -0
- package/src/library/types.ts +2 -0
- package/src/setupTests.ts +7 -1
- package/src/stories/components/display/AdvancedList.stories.tsx +660 -0
- package/src/stories/components/display/AdvancedListItem.stories.tsx +653 -0
- package/src/stories/components/display/SelectableCardList.stories.tsx +19 -0
- package/src/stories/components/display/Tooltip.stories.tsx +67 -0
- package/src/stories/components/inputs/DatePicker.stories.tsx +36 -1
- package/src/stories/components/inputs/Select.stories.tsx +38 -2
- package/src/stories/components/overlays/Dialog.stories.tsx +34 -0
- package/src/stories/components/overlays/Popover.stories.tsx +65 -0
- package/src/stories/theme/ThemedMuiComponents.stories.tsx +177 -0
- package/src/theme/light/MuiAutocomplete.ts +3 -1
- package/src/theme/light/MuiInputBase.ts +4 -0
- package/src/theme/light/MuiTooltip.ts +40 -0
- package/src/theme/light/index.tsx +2 -0
- package/src/theme/motion.tsx +10 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { Box, Collapse, Stack, Typography } from '@mui/material'
|
|
2
|
+
import { useCallback, useEffect, useId, useMemo, useRef } from 'react'
|
|
3
|
+
|
|
4
|
+
import RcSesBadge from '@/components/common/Badge'
|
|
5
|
+
import ListWithIcons from '@/components/common/ListWithIcons'
|
|
6
|
+
import motion from '@/theme/motion'
|
|
7
|
+
import palette from '@/theme/palette'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
AdvancedListItemLeading as AdvancedListItemLeadingData,
|
|
11
|
+
AdvancedListItemProps,
|
|
12
|
+
AdvancedListItemState,
|
|
13
|
+
} from './AdvancedListItem.types'
|
|
14
|
+
import AdvancedListItemLeading from './components/AdvancedListItemLeading'
|
|
15
|
+
import AdvancedListItemTrailing from './components/AdvancedListItemTrailing'
|
|
16
|
+
import usePrefersReducedMotion from './hooks/usePrefersReducedMotion'
|
|
17
|
+
|
|
18
|
+
const BORDER_RADIUS = '0.5rem'
|
|
19
|
+
const BORDER_WIDTH = '0.0625rem'
|
|
20
|
+
const FOCUS_RING_WIDTH = '0.0625rem'
|
|
21
|
+
|
|
22
|
+
const STATE_BORDER_COLOR: Record<AdvancedListItemState, string> = {
|
|
23
|
+
rest: palette.grey[300],
|
|
24
|
+
selected: palette.primary.main,
|
|
25
|
+
disabled: palette.grey[200],
|
|
26
|
+
error: palette.error.main,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const LEADING_MEDIA_SX = {
|
|
30
|
+
width: '2rem',
|
|
31
|
+
height: '2rem',
|
|
32
|
+
flexShrink: 0,
|
|
33
|
+
display: 'flex',
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
} as const
|
|
37
|
+
|
|
38
|
+
const INTERACTIVE_LEADING_TYPES = new Set(['reorder', 'checkbox', 'radio'])
|
|
39
|
+
const INTERACTIVE_TRAILING_TYPES = new Set([
|
|
40
|
+
'actions',
|
|
41
|
+
'toggle',
|
|
42
|
+
'checkbox',
|
|
43
|
+
'radio',
|
|
44
|
+
'stepper',
|
|
45
|
+
])
|
|
46
|
+
|
|
47
|
+
const AdvancedListItem = ({
|
|
48
|
+
title,
|
|
49
|
+
label,
|
|
50
|
+
subtitle,
|
|
51
|
+
metaItems,
|
|
52
|
+
leadingMedia,
|
|
53
|
+
expandedContent,
|
|
54
|
+
expanded = false,
|
|
55
|
+
onExpandedChange,
|
|
56
|
+
leading = { type: 'none' },
|
|
57
|
+
trailing = { type: 'none' },
|
|
58
|
+
state = 'rest',
|
|
59
|
+
onClick,
|
|
60
|
+
}: AdvancedListItemProps) => {
|
|
61
|
+
const isDisabled = state === 'disabled'
|
|
62
|
+
const isSelectable = leading.type === 'checkbox' || leading.type === 'radio'
|
|
63
|
+
const isClickable = (!!onClick || isSelectable) && !isDisabled
|
|
64
|
+
|
|
65
|
+
const hasInteractiveChild =
|
|
66
|
+
INTERACTIVE_LEADING_TYPES.has(leading.type) ||
|
|
67
|
+
INTERACTIVE_TRAILING_TYPES.has(trailing.type) ||
|
|
68
|
+
(trailing.type === 'price' && !!trailing.onDelete)
|
|
69
|
+
|
|
70
|
+
const isRootFocusable = isClickable && !hasInteractiveChild
|
|
71
|
+
const isExpandable = !!expandedContent
|
|
72
|
+
const canAttachExpandToLeading =
|
|
73
|
+
isExpandable && (leading.type === 'radio' || leading.type === 'checkbox')
|
|
74
|
+
const needsRootFocusFallback =
|
|
75
|
+
isExpandable && !canAttachExpandToLeading && !isRootFocusable
|
|
76
|
+
|
|
77
|
+
let rootTabIndex: number | undefined
|
|
78
|
+
if (isRootFocusable) {
|
|
79
|
+
rootTabIndex = 0
|
|
80
|
+
} else if (needsRootFocusFallback) {
|
|
81
|
+
rootTabIndex = -1
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const contentId = useId()
|
|
85
|
+
const titleId = useId()
|
|
86
|
+
const selectorRef = useRef<HTMLInputElement>(null)
|
|
87
|
+
const rootRef = useRef<HTMLDivElement>(null)
|
|
88
|
+
const contentRef = useRef<HTMLDivElement>(null)
|
|
89
|
+
const prefersReducedMotion = usePrefersReducedMotion()
|
|
90
|
+
|
|
91
|
+
const borderColor = STATE_BORDER_COLOR[state]
|
|
92
|
+
const backgroundColor = state === 'selected' ? palette.primary[50] : undefined
|
|
93
|
+
const focusRingShadow = `0 0 0 ${FOCUS_RING_WIDTH} ${palette.primary.main}`
|
|
94
|
+
const transitionTiming = `${motion.duration.standard}ms ${motion.easing.standard}`
|
|
95
|
+
|
|
96
|
+
const leadingWithExpandNotify: AdvancedListItemLeadingData = useMemo(() => {
|
|
97
|
+
if (
|
|
98
|
+
!canAttachExpandToLeading ||
|
|
99
|
+
(leading.type !== 'radio' && leading.type !== 'checkbox')
|
|
100
|
+
) {
|
|
101
|
+
return leading
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
...leading,
|
|
105
|
+
onChange: (checked: boolean) => {
|
|
106
|
+
leading.onChange(checked)
|
|
107
|
+
onExpandedChange?.(checked)
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
}, [canAttachExpandToLeading, leading, onExpandedChange])
|
|
111
|
+
|
|
112
|
+
// Runs for every collapse, not just ones driven by the leading control's own onChange —
|
|
113
|
+
// an external trigger (e.g. a parent-level "collapse" action) sets `expanded` directly,
|
|
114
|
+
// bypassing that onChange entirely. Without this, focus is left stranded inside content
|
|
115
|
+
// that's about to become inert.
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (!expanded && contentRef.current?.contains(document.activeElement)) {
|
|
118
|
+
if (selectorRef.current) {
|
|
119
|
+
selectorRef.current.focus()
|
|
120
|
+
} else {
|
|
121
|
+
rootRef.current?.focus()
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}, [expanded])
|
|
125
|
+
|
|
126
|
+
const isInsideExpandedContent = useCallback(
|
|
127
|
+
(target: EventTarget | null) => !!contentRef.current?.contains(target as Node),
|
|
128
|
+
[],
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
const activate = useCallback(
|
|
132
|
+
(event: React.SyntheticEvent) => {
|
|
133
|
+
if (isInsideExpandedContent(event.target)) {
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const clickedInputDirectly =
|
|
138
|
+
isSelectable && selectorRef.current?.contains(event.target as Node)
|
|
139
|
+
|
|
140
|
+
if (isSelectable && !clickedInputDirectly) {
|
|
141
|
+
if (
|
|
142
|
+
leadingWithExpandNotify.type === 'checkbox' ||
|
|
143
|
+
leadingWithExpandNotify.type === 'radio'
|
|
144
|
+
) {
|
|
145
|
+
const nextChecked =
|
|
146
|
+
leadingWithExpandNotify.type === 'radio'
|
|
147
|
+
? true
|
|
148
|
+
: !leadingWithExpandNotify.checked
|
|
149
|
+
leadingWithExpandNotify.onChange(nextChecked)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
onClick?.()
|
|
153
|
+
},
|
|
154
|
+
[isInsideExpandedContent, isSelectable, leadingWithExpandNotify, onClick],
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
const handleRootClick = useCallback(
|
|
158
|
+
(event: React.MouseEvent) => activate(event),
|
|
159
|
+
[activate],
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
const handleRootKeyDown = useCallback(
|
|
163
|
+
(event: React.KeyboardEvent) => {
|
|
164
|
+
if (isInsideExpandedContent(event.target)) {
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
169
|
+
event.preventDefault()
|
|
170
|
+
activate(event)
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
[activate, isInsideExpandedContent],
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<Box
|
|
178
|
+
ref={rootRef}
|
|
179
|
+
role={isRootFocusable ? 'button' : undefined}
|
|
180
|
+
tabIndex={rootTabIndex}
|
|
181
|
+
onClick={isClickable ? handleRootClick : undefined}
|
|
182
|
+
onKeyDown={isRootFocusable ? handleRootKeyDown : undefined}
|
|
183
|
+
aria-disabled={isDisabled || undefined}
|
|
184
|
+
sx={{
|
|
185
|
+
display: 'flex',
|
|
186
|
+
flexDirection: 'column',
|
|
187
|
+
gap: '0.75rem',
|
|
188
|
+
width: '100%',
|
|
189
|
+
boxSizing: 'border-box',
|
|
190
|
+
border: `${BORDER_WIDTH} solid`,
|
|
191
|
+
borderColor,
|
|
192
|
+
backgroundColor,
|
|
193
|
+
borderRadius: BORDER_RADIUS,
|
|
194
|
+
padding: '0.5rem 0.75rem',
|
|
195
|
+
opacity: isDisabled ? 0.6 : 1,
|
|
196
|
+
pointerEvents: isDisabled ? 'none' : 'auto',
|
|
197
|
+
cursor: isClickable ? 'pointer' : 'default',
|
|
198
|
+
boxShadow: state === 'selected' ? focusRingShadow : 'none',
|
|
199
|
+
transition: prefersReducedMotion
|
|
200
|
+
? 'none'
|
|
201
|
+
: `border-color ${transitionTiming}, box-shadow ${transitionTiming}`,
|
|
202
|
+
'&:hover': isClickable
|
|
203
|
+
? { borderColor: state === 'rest' ? palette.grey[400] : borderColor }
|
|
204
|
+
: undefined,
|
|
205
|
+
'&:focus-visible, &:focus-within': !isDisabled
|
|
206
|
+
? { borderColor: palette.primary.main, boxShadow: focusRingShadow }
|
|
207
|
+
: undefined,
|
|
208
|
+
}}
|
|
209
|
+
>
|
|
210
|
+
<Stack
|
|
211
|
+
direction='row'
|
|
212
|
+
sx={{
|
|
213
|
+
alignItems: 'flex-start',
|
|
214
|
+
flexWrap: { xs: 'wrap', md: 'nowrap' },
|
|
215
|
+
gap: '0.75rem',
|
|
216
|
+
}}
|
|
217
|
+
>
|
|
218
|
+
{leading.type !== 'none' && (
|
|
219
|
+
<Box sx={{ alignSelf: 'center', order: { xs: -1, md: 0 } }}>
|
|
220
|
+
<AdvancedListItemLeading
|
|
221
|
+
leading={leadingWithExpandNotify}
|
|
222
|
+
disabled={isDisabled}
|
|
223
|
+
inputRef={canAttachExpandToLeading ? selectorRef : undefined}
|
|
224
|
+
expandableId={canAttachExpandToLeading ? contentId : undefined}
|
|
225
|
+
expanded={canAttachExpandToLeading ? expanded : undefined}
|
|
226
|
+
titleId={titleId}
|
|
227
|
+
/>
|
|
228
|
+
</Box>
|
|
229
|
+
)}
|
|
230
|
+
|
|
231
|
+
<Box
|
|
232
|
+
sx={{
|
|
233
|
+
display: 'flex',
|
|
234
|
+
flexDirection: 'row',
|
|
235
|
+
alignItems: 'flex-start',
|
|
236
|
+
gap: '0.75rem',
|
|
237
|
+
minWidth: 0,
|
|
238
|
+
flex: {
|
|
239
|
+
xs: trailing.type !== 'none' ? '1 1 100%' : '1 1 0%',
|
|
240
|
+
md: '1 1 0%',
|
|
241
|
+
},
|
|
242
|
+
alignSelf: subtitle ? undefined : 'center',
|
|
243
|
+
}}
|
|
244
|
+
>
|
|
245
|
+
{!!leadingMedia && <Box sx={LEADING_MEDIA_SX}>{leadingMedia}</Box>}
|
|
246
|
+
|
|
247
|
+
<Box
|
|
248
|
+
sx={{
|
|
249
|
+
flex: 1,
|
|
250
|
+
minWidth: 0,
|
|
251
|
+
display: 'flex',
|
|
252
|
+
flexDirection: 'column',
|
|
253
|
+
gap: '0.25rem',
|
|
254
|
+
}}
|
|
255
|
+
>
|
|
256
|
+
<Stack
|
|
257
|
+
direction='row'
|
|
258
|
+
sx={{
|
|
259
|
+
alignItems: 'center',
|
|
260
|
+
flexWrap: 'wrap',
|
|
261
|
+
gap: '0.5rem',
|
|
262
|
+
alignSelf: 'stretch',
|
|
263
|
+
}}
|
|
264
|
+
>
|
|
265
|
+
<Typography
|
|
266
|
+
id={titleId}
|
|
267
|
+
variant='h3'
|
|
268
|
+
sx={{
|
|
269
|
+
color: palette.grey[900],
|
|
270
|
+
fontSize: '1rem',
|
|
271
|
+
fontWeight: 600,
|
|
272
|
+
lineHeight: '1.375rem',
|
|
273
|
+
}}
|
|
274
|
+
>
|
|
275
|
+
{title}
|
|
276
|
+
</Typography>
|
|
277
|
+
{!!label && <RcSesBadge label={label} variant='neutral' size='small' />}
|
|
278
|
+
</Stack>
|
|
279
|
+
|
|
280
|
+
{!!subtitle && (
|
|
281
|
+
<Typography
|
|
282
|
+
variant='body2'
|
|
283
|
+
sx={{
|
|
284
|
+
color: palette.grey[600],
|
|
285
|
+
fontSize: '0.875rem',
|
|
286
|
+
fontWeight: 400,
|
|
287
|
+
lineHeight: '1.25rem',
|
|
288
|
+
}}
|
|
289
|
+
>
|
|
290
|
+
{subtitle}
|
|
291
|
+
</Typography>
|
|
292
|
+
)}
|
|
293
|
+
|
|
294
|
+
{!!metaItems?.length && (
|
|
295
|
+
<ListWithIcons items={metaItems} layout='horizontal' />
|
|
296
|
+
)}
|
|
297
|
+
</Box>
|
|
298
|
+
</Box>
|
|
299
|
+
|
|
300
|
+
{trailing.type !== 'none' && (
|
|
301
|
+
<Box
|
|
302
|
+
sx={{
|
|
303
|
+
alignSelf: 'center',
|
|
304
|
+
order: leading.type !== 'none' ? { xs: -1, md: 0 } : 0,
|
|
305
|
+
marginLeft: leading.type !== 'none' ? { xs: 'auto', md: 0 } : 0,
|
|
306
|
+
}}
|
|
307
|
+
>
|
|
308
|
+
<AdvancedListItemTrailing trailing={trailing} disabled={isDisabled} />
|
|
309
|
+
</Box>
|
|
310
|
+
)}
|
|
311
|
+
</Stack>
|
|
312
|
+
{isExpandable && (
|
|
313
|
+
<Collapse
|
|
314
|
+
in={expanded}
|
|
315
|
+
timeout={prefersReducedMotion ? 0 : motion.duration.standard}
|
|
316
|
+
easing={motion.easing.standard}
|
|
317
|
+
>
|
|
318
|
+
<Box
|
|
319
|
+
ref={contentRef}
|
|
320
|
+
id={contentId}
|
|
321
|
+
sx={{
|
|
322
|
+
marginLeft: leading.type !== 'none' ? { xs: 0, md: '2rem' } : 0,
|
|
323
|
+
backgroundColor: palette.grey[50],
|
|
324
|
+
borderRadius: BORDER_RADIUS,
|
|
325
|
+
padding: '0.75rem 1rem',
|
|
326
|
+
}}
|
|
327
|
+
{...({
|
|
328
|
+
inert: expanded ? undefined : '',
|
|
329
|
+
} as React.HTMLAttributes<HTMLDivElement>)}
|
|
330
|
+
>
|
|
331
|
+
{expandedContent}
|
|
332
|
+
</Box>
|
|
333
|
+
</Collapse>
|
|
334
|
+
)}
|
|
335
|
+
</Box>
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export default AdvancedListItem
|
|
340
|
+
export type { AdvancedListItemProps }
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { useMediaQuery } from '@mui/material'
|
|
2
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
3
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
4
|
+
import { type ReactElement } from 'react'
|
|
5
|
+
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
|
6
|
+
|
|
7
|
+
import theme from '@/theme/light'
|
|
8
|
+
|
|
9
|
+
import AdvancedList, { type AdvancedListItemData } from '.'
|
|
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 mockedUseMediaQuery = vi.mocked(useMediaQuery)
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
mockedUseMediaQuery.mockReturnValue(false)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const renderList = (ui: ReactElement) =>
|
|
27
|
+
render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
|
|
28
|
+
|
|
29
|
+
const makeItems = (count: number): AdvancedListItemData[] =>
|
|
30
|
+
Array.from({ length: count }, (_, i) => ({
|
|
31
|
+
id: `item-${i + 1}`,
|
|
32
|
+
title: `Item ${i + 1}`,
|
|
33
|
+
subtitle: `Subtitle ${i + 1}`,
|
|
34
|
+
}))
|
|
35
|
+
|
|
36
|
+
describe('AdvancedList', () => {
|
|
37
|
+
test('renders all items on the first page when count <= page size', () => {
|
|
38
|
+
renderList(<AdvancedList items={makeItems(3)} />)
|
|
39
|
+
|
|
40
|
+
expect(screen.getByText('Item 1')).toBeInTheDocument()
|
|
41
|
+
expect(screen.getByText('Item 2')).toBeInTheDocument()
|
|
42
|
+
expect(screen.getByText('Item 3')).toBeInTheDocument()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('shows only 5 items per page', () => {
|
|
46
|
+
renderList(<AdvancedList items={makeItems(8)} />)
|
|
47
|
+
|
|
48
|
+
expect(screen.getByText('Item 1')).toBeInTheDocument()
|
|
49
|
+
expect(screen.getByText('Item 5')).toBeInTheDocument()
|
|
50
|
+
expect(screen.queryByText('Item 6')).not.toBeInTheDocument()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('navigating to next page shows the next set of items', () => {
|
|
54
|
+
renderList(<AdvancedList items={makeItems(8)} />)
|
|
55
|
+
|
|
56
|
+
fireEvent.click(screen.getByRole('button', { name: 'Kitas' }))
|
|
57
|
+
|
|
58
|
+
expect(screen.getByText('Item 6')).toBeInTheDocument()
|
|
59
|
+
expect(screen.getByText('Item 7')).toBeInTheDocument()
|
|
60
|
+
expect(screen.getByText('Item 8')).toBeInTheDocument()
|
|
61
|
+
expect(screen.queryByText('Item 1')).not.toBeInTheDocument()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test("passes each item's own leading/trailing/expanded config through to AdvancedListItem", () => {
|
|
65
|
+
const onChange = vi.fn()
|
|
66
|
+
|
|
67
|
+
renderList(
|
|
68
|
+
<AdvancedList
|
|
69
|
+
items={[
|
|
70
|
+
{
|
|
71
|
+
id: 'radio-item',
|
|
72
|
+
title: 'Savininkas juridinis asmuo',
|
|
73
|
+
leading: { type: 'radio', checked: true, onChange },
|
|
74
|
+
expanded: true,
|
|
75
|
+
expandedContent: <input aria-label='Įmonės kodas' />,
|
|
76
|
+
},
|
|
77
|
+
]}
|
|
78
|
+
/>,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
expect(screen.getByRole('radio')).toBeChecked()
|
|
82
|
+
expect(screen.getByLabelText('Įmonės kodas')).toBeInTheDocument()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('renders error node and hides the list when error is provided', () => {
|
|
86
|
+
renderList(<AdvancedList items={makeItems(3)} error={<p>Something went wrong</p>} />)
|
|
87
|
+
|
|
88
|
+
expect(screen.getByText('Something went wrong')).toBeInTheDocument()
|
|
89
|
+
expect(screen.queryByText('Item 1')).not.toBeInTheDocument()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('does not render pagination controls when everything fits on one page', () => {
|
|
93
|
+
renderList(<AdvancedList items={makeItems(2)} />)
|
|
94
|
+
|
|
95
|
+
expect(screen.queryByRole('button', { name: 'Kitas' })).not.toBeInTheDocument()
|
|
96
|
+
})
|
|
97
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Box, Container } from '@mui/material'
|
|
2
|
+
import { ReactNode, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import DataPagination from '@/components/common/DataPagination'
|
|
5
|
+
|
|
6
|
+
import AdvancedListItem, {
|
|
7
|
+
type AdvancedListItemProps,
|
|
8
|
+
} from './components/AdvancedListItem'
|
|
9
|
+
|
|
10
|
+
export type AdvancedListItemData = AdvancedListItemProps & { id: string }
|
|
11
|
+
|
|
12
|
+
export interface AdvancedListProps {
|
|
13
|
+
items: AdvancedListItemData[]
|
|
14
|
+
error?: ReactNode
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const PAGE_SIZE = 5
|
|
18
|
+
|
|
19
|
+
const AdvancedList = ({ items, error }: AdvancedListProps) => {
|
|
20
|
+
const [page, setPage] = useState(1)
|
|
21
|
+
|
|
22
|
+
if (error != null) {
|
|
23
|
+
return (
|
|
24
|
+
<Container disableGutters sx={{ display: 'flex', justifyContent: 'center' }}>
|
|
25
|
+
{error}
|
|
26
|
+
</Container>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const totalPages = Math.ceil(items.length / PAGE_SIZE)
|
|
31
|
+
const currentPage = totalPages > 0 ? Math.min(page, totalPages) : 1
|
|
32
|
+
const startIndex = (currentPage - 1) * PAGE_SIZE
|
|
33
|
+
const pagedItems = items.slice(startIndex, startIndex + PAGE_SIZE)
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<Container
|
|
37
|
+
disableGutters
|
|
38
|
+
sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '1rem' }}
|
|
39
|
+
>
|
|
40
|
+
<Box
|
|
41
|
+
sx={{ display: 'flex', flexDirection: 'column', gap: '0.625rem', width: '100%' }}
|
|
42
|
+
>
|
|
43
|
+
{pagedItems.map(({ id, ...itemProps }) => (
|
|
44
|
+
<AdvancedListItem key={id} {...itemProps} />
|
|
45
|
+
))}
|
|
46
|
+
</Box>
|
|
47
|
+
<DataPagination count={totalPages} page={currentPage} onChange={setPage} />
|
|
48
|
+
</Container>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default AdvancedList
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Button as MuiButton, ButtonProps as MuiButtonProps } from '@mui/material'
|
|
2
|
+
import type { ButtonTypeMap } from '@mui/material/Button'
|
|
3
|
+
import type { ExtendButtonBase } from '@mui/material/ButtonBase'
|
|
2
4
|
import { useTranslation } from 'react-i18next'
|
|
3
5
|
|
|
4
6
|
import RcSesLoadingSpinner, { getSpinnerColor } from '@/components/loaders/LoadingSpinner'
|
|
@@ -27,7 +29,7 @@ const ICON_ONLY_SIZE_MAP = {
|
|
|
27
29
|
// breaking change, tracked as SAV-5916.
|
|
28
30
|
type Props = ButtonProps
|
|
29
31
|
|
|
30
|
-
function
|
|
32
|
+
function RcSesButtonComponent(props: Props) {
|
|
31
33
|
const { t } = useTranslation('common')
|
|
32
34
|
const {
|
|
33
35
|
children,
|
|
@@ -97,4 +99,16 @@ function RcSesButton(props: Props) {
|
|
|
97
99
|
)
|
|
98
100
|
}
|
|
99
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Declared the way MUI declares its own `Button`, rather than as a plain
|
|
104
|
+
* function component. `component={Link}` has to bring the target component's
|
|
105
|
+
* props with it - without this, `<RcSesButton component={Link} to='/x' />` fails
|
|
106
|
+
* with "Property 'to' does not exist", which is how ~38 call sites in `ses-ui`
|
|
107
|
+
* were compiling against 1.x (it declared a bare `to?: string`, which allowed
|
|
108
|
+
* `to` even when no `component` was given).
|
|
109
|
+
*/
|
|
110
|
+
const RcSesButton = RcSesButtonComponent as ExtendButtonBase<
|
|
111
|
+
ButtonTypeMap<{ iconOnly?: boolean }>
|
|
112
|
+
>
|
|
113
|
+
|
|
100
114
|
export default RcSesButton
|
|
@@ -162,12 +162,12 @@ function RcSesCard({
|
|
|
162
162
|
]}
|
|
163
163
|
>
|
|
164
164
|
<Typography
|
|
165
|
-
color={palette.grey[900]}
|
|
166
165
|
data-testid={testIds?.title}
|
|
167
166
|
variant='h5'
|
|
168
167
|
{...titleProps}
|
|
169
168
|
sx={[
|
|
170
169
|
{
|
|
170
|
+
color: palette.grey[900],
|
|
171
171
|
lineHeight: '1.75rem',
|
|
172
172
|
...(centered ? { textAlign: 'center' } : {}),
|
|
173
173
|
},
|
|
@@ -179,12 +179,12 @@ function RcSesCard({
|
|
|
179
179
|
|
|
180
180
|
{!!description && (
|
|
181
181
|
<Typography
|
|
182
|
-
color={palette.grey[800]}
|
|
183
182
|
data-testid={testIds?.description}
|
|
184
183
|
variant='body2'
|
|
185
184
|
{...descriptionProps}
|
|
186
185
|
sx={[
|
|
187
186
|
{
|
|
187
|
+
color: palette.grey[800],
|
|
188
188
|
fontWeight: 300,
|
|
189
189
|
lineHeight: '1.25rem',
|
|
190
190
|
...(centered ? { textAlign: 'center' } : {}),
|
|
@@ -21,14 +21,14 @@ const ListWithIconsItem = ({
|
|
|
21
21
|
const content = (
|
|
22
22
|
<Box
|
|
23
23
|
sx={{
|
|
24
|
-
display: '
|
|
25
|
-
alignItems: '
|
|
24
|
+
display: 'flex',
|
|
25
|
+
alignItems: 'flex-start',
|
|
26
26
|
gap: 0.5,
|
|
27
|
-
maxWidth:
|
|
27
|
+
maxWidth: '100%',
|
|
28
28
|
}}
|
|
29
29
|
>
|
|
30
30
|
{Icon && (
|
|
31
|
-
<Box sx={{ display: 'flex', alignItems: 'center' }}>
|
|
31
|
+
<Box sx={{ display: 'flex', alignItems: 'center', height: 20 }}>
|
|
32
32
|
<Icon fillColor={textColor ?? palette.grey[600]} size={16} />
|
|
33
33
|
</Box>
|
|
34
34
|
)}
|
|
@@ -38,7 +38,8 @@ const ListWithIconsItem = ({
|
|
|
38
38
|
fontSize: '14px',
|
|
39
39
|
lineHeight: '20px',
|
|
40
40
|
fontWeight: 300,
|
|
41
|
-
whiteSpace: '
|
|
41
|
+
whiteSpace: 'normal',
|
|
42
|
+
wordBreak: 'break-word',
|
|
42
43
|
color: textColor,
|
|
43
44
|
}}
|
|
44
45
|
>
|
|
@@ -81,6 +82,7 @@ const ListWithIconsItem = ({
|
|
|
81
82
|
display: 'flex',
|
|
82
83
|
alignItems: 'center',
|
|
83
84
|
width: { xs: '100%', md: isLoading ? '120px' : 'auto' },
|
|
85
|
+
maxWidth: '100%',
|
|
84
86
|
gap: 0.5,
|
|
85
87
|
minHeight: 20,
|
|
86
88
|
opacity: disabled ? 0.5 : 1,
|
|
@@ -148,6 +148,56 @@ describe('SelectableCardListItem', () => {
|
|
|
148
148
|
expect(onSelect).toHaveBeenCalledTimes(1)
|
|
149
149
|
})
|
|
150
150
|
|
|
151
|
+
test('renders action button with label when hasActionButton is true', () => {
|
|
152
|
+
renderItem(
|
|
153
|
+
<SelectableCardListItem
|
|
154
|
+
title='With action'
|
|
155
|
+
selected={false}
|
|
156
|
+
onSelect={vi.fn()}
|
|
157
|
+
listItems={[]}
|
|
158
|
+
hasActionButton
|
|
159
|
+
actionButtonLabel='Veiksmas'
|
|
160
|
+
/>,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
expect(screen.getByRole('button', { name: 'Veiksmas' })).toBeInTheDocument()
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
test('omits action button when hasActionButton is false', () => {
|
|
167
|
+
renderItem(
|
|
168
|
+
<SelectableCardListItem
|
|
169
|
+
title='No action'
|
|
170
|
+
selected={false}
|
|
171
|
+
onSelect={vi.fn()}
|
|
172
|
+
listItems={[]}
|
|
173
|
+
actionButtonLabel='Veiksmas'
|
|
174
|
+
/>,
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
expect(screen.queryByRole('button', { name: 'Veiksmas' })).not.toBeInTheDocument()
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
test('clicking action button calls onActionButtonClick and not onSelect', () => {
|
|
181
|
+
const onSelect = vi.fn()
|
|
182
|
+
const onActionButtonClick = vi.fn()
|
|
183
|
+
renderItem(
|
|
184
|
+
<SelectableCardListItem
|
|
185
|
+
title='With action'
|
|
186
|
+
selected={false}
|
|
187
|
+
onSelect={onSelect}
|
|
188
|
+
listItems={[]}
|
|
189
|
+
hasActionButton
|
|
190
|
+
actionButtonLabel='Veiksmas'
|
|
191
|
+
onActionButtonClick={onActionButtonClick}
|
|
192
|
+
/>,
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
fireEvent.click(screen.getByRole('button', { name: 'Veiksmas' }))
|
|
196
|
+
|
|
197
|
+
expect(onActionButtonClick).toHaveBeenCalledTimes(1)
|
|
198
|
+
expect(onSelect).not.toHaveBeenCalled()
|
|
199
|
+
})
|
|
200
|
+
|
|
151
201
|
test('loading card is not selectable', () => {
|
|
152
202
|
const onSelect = vi.fn()
|
|
153
203
|
const { container } = renderItem(
|