@registrucentras/rc-ses-react-components 2.0.0-rc.0 → 2.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +5 -1
  2. package/dist/assets/icons/CaretUpBoldIcon.d.ts +3 -0
  3. package/dist/assets/icons/CaretUpIcon.d.ts +3 -0
  4. package/dist/assets/icons/ListIcon.d.ts +3 -0
  5. package/dist/assets/icons/MinusIcon.d.ts +3 -0
  6. package/dist/assets/icons/NotePencilIcon.d.ts +3 -0
  7. package/dist/assets/icons/PlusIcon.d.ts +3 -0
  8. package/dist/assets/icons/TrashIcon.d.ts +3 -0
  9. package/dist/assets/icons/UserIcon.d.ts +3 -0
  10. package/dist/components/common/AdvancedList/components/AdvancedListItem/AdvancedListItem.types.d.ts +106 -0
  11. package/dist/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.d.ts +12 -0
  12. package/dist/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.d.ts +7 -0
  13. package/dist/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion.d.ts +2 -0
  14. package/dist/components/common/AdvancedList/components/AdvancedListItem/index.d.ts +4 -0
  15. package/dist/components/common/AdvancedList/index.d.ts +11 -0
  16. package/dist/components/common/Button/index.d.ts +13 -3
  17. package/dist/components/common/SelectableCardList/components/SelectableCardListItem.d.ts +4 -1
  18. package/dist/components/common/SelectableCardList/index.d.ts +4 -1
  19. package/dist/components/common/Tooltip/index.d.ts +20 -0
  20. package/dist/library/icons.d.ts +9 -1
  21. package/dist/library/index.d.ts +5 -0
  22. package/dist/library/types.d.ts +2 -1
  23. package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
  24. package/dist/registrucentras-rc-ses-react-components.js +4107 -3246
  25. package/dist/stories/components/actions/Button.stories.d.ts +4 -3
  26. package/dist/stories/components/display/AdvancedList.stories.d.ts +32 -0
  27. package/dist/stories/components/display/AdvancedListItem.stories.d.ts +33 -0
  28. package/dist/stories/components/display/SelectableCardList.stories.d.ts +8 -1
  29. package/dist/stories/components/display/Tooltip.stories.d.ts +48 -0
  30. package/dist/stories/components/inputs/DatePicker.stories.d.ts +23 -0
  31. package/dist/stories/components/loaders/LoadingSpinner.stories.d.ts +3 -3
  32. package/dist/stories/components/overlays/Dialog.stories.d.ts +6 -0
  33. package/dist/stories/components/overlays/Popover.stories.d.ts +12 -0
  34. package/dist/stories/theme/ThemedMuiComponents.stories.d.ts +25 -0
  35. package/dist/theme/light/MuiTooltip.d.ts +3 -0
  36. package/dist/theme/motion.d.ts +16 -0
  37. package/package.json +2 -1
  38. package/src/assets/icons/CaretUpBoldIcon.tsx +17 -0
  39. package/src/assets/icons/CaretUpIcon.tsx +9 -0
  40. package/src/assets/icons/ListIcon.tsx +17 -0
  41. package/src/assets/icons/MinusIcon.tsx +9 -0
  42. package/src/assets/icons/NotePencilIcon.tsx +9 -0
  43. package/src/assets/icons/PlusIcon.tsx +9 -0
  44. package/src/assets/icons/TrashIcon.tsx +23 -0
  45. package/src/assets/icons/UserIcon.tsx +17 -0
  46. package/src/components/common/AdvancedList/components/AdvancedListItem/AdvancedListItem.types.ts +100 -0
  47. package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.tsx +224 -0
  48. package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.tsx +263 -0
  49. package/src/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion.test.ts +80 -0
  50. package/src/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion.ts +28 -0
  51. package/src/components/common/AdvancedList/components/AdvancedListItem/index.test.tsx +631 -0
  52. package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +332 -0
  53. package/src/components/common/AdvancedList/index.test.tsx +97 -0
  54. package/src/components/common/AdvancedList/index.tsx +52 -0
  55. package/src/components/common/Button/index.tsx +15 -1
  56. package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +7 -5
  57. package/src/components/common/SelectableCardList/components/SelectableCardListItem.test.tsx +50 -0
  58. package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +34 -0
  59. package/src/components/common/SelectableCardList/index.test.tsx +56 -2
  60. package/src/components/common/SelectableCardList/index.tsx +29 -10
  61. package/src/components/common/Tooltip/index.test.tsx +85 -0
  62. package/src/components/common/Tooltip/index.tsx +168 -0
  63. package/src/components/form/inputs/Select/index.test.tsx +102 -0
  64. package/src/components/form/inputs/Select/index.tsx +105 -52
  65. package/src/i18n/namespaces/common/en.json +14 -0
  66. package/src/i18n/namespaces/common/lt.json +14 -0
  67. package/src/library/icons.ts +16 -0
  68. package/src/library/index.ts +5 -0
  69. package/src/library/types.ts +2 -0
  70. package/src/setupTests.ts +7 -1
  71. package/src/stories/components/display/AdvancedList.stories.tsx +529 -0
  72. package/src/stories/components/display/AdvancedListItem.stories.tsx +653 -0
  73. package/src/stories/components/display/SelectableCardList.stories.tsx +19 -0
  74. package/src/stories/components/display/Tooltip.stories.tsx +67 -0
  75. package/src/stories/components/inputs/DatePicker.stories.tsx +36 -1
  76. package/src/stories/components/inputs/Select.stories.tsx +38 -2
  77. package/src/stories/components/overlays/Dialog.stories.tsx +34 -0
  78. package/src/stories/components/overlays/Popover.stories.tsx +65 -0
  79. package/src/stories/theme/ThemedMuiComponents.stories.tsx +177 -0
  80. package/src/theme/light/MuiAutocomplete.ts +3 -1
  81. package/src/theme/light/MuiInputBase.ts +4 -0
  82. package/src/theme/light/MuiTooltip.ts +40 -0
  83. package/src/theme/light/index.tsx +2 -0
  84. package/src/theme/motion.tsx +10 -0
@@ -0,0 +1,332 @@
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={{ fontSize: '1rem', fontWeight: 600, lineHeight: '1.375rem' }}
269
+ color={palette.grey[900]}
270
+ >
271
+ {title}
272
+ </Typography>
273
+ {!!label && <RcSesBadge label={label} variant='neutral' size='small' />}
274
+ </Stack>
275
+
276
+ {!!subtitle && (
277
+ <Typography
278
+ variant='body2'
279
+ sx={{ fontSize: '0.875rem', fontWeight: 400, lineHeight: '1.25rem' }}
280
+ color={palette.grey[600]}
281
+ >
282
+ {subtitle}
283
+ </Typography>
284
+ )}
285
+
286
+ {!!metaItems?.length && (
287
+ <ListWithIcons items={metaItems} layout='horizontal' />
288
+ )}
289
+ </Box>
290
+ </Box>
291
+
292
+ {trailing.type !== 'none' && (
293
+ <Box
294
+ sx={{
295
+ alignSelf: 'center',
296
+ order: leading.type !== 'none' ? { xs: -1, md: 0 } : 0,
297
+ marginLeft: leading.type !== 'none' ? { xs: 'auto', md: 0 } : 0,
298
+ }}
299
+ >
300
+ <AdvancedListItemTrailing trailing={trailing} disabled={isDisabled} />
301
+ </Box>
302
+ )}
303
+ </Stack>
304
+ {isExpandable && (
305
+ <Collapse
306
+ in={expanded}
307
+ timeout={prefersReducedMotion ? 0 : motion.duration.standard}
308
+ easing={motion.easing.standard}
309
+ >
310
+ <Box
311
+ ref={contentRef}
312
+ id={contentId}
313
+ sx={{
314
+ marginLeft: leading.type !== 'none' ? { xs: 0, md: '2rem' } : 0,
315
+ backgroundColor: palette.grey[50],
316
+ borderRadius: BORDER_RADIUS,
317
+ padding: '0.75rem 1rem',
318
+ }}
319
+ {...({
320
+ inert: expanded ? undefined : '',
321
+ } as React.HTMLAttributes<HTMLDivElement>)}
322
+ >
323
+ {expandedContent}
324
+ </Box>
325
+ </Collapse>
326
+ )}
327
+ </Box>
328
+ )
329
+ }
330
+
331
+ export default AdvancedListItem
332
+ 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 RcSesButton(props: Props) {
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
@@ -21,14 +21,14 @@ const ListWithIconsItem = ({
21
21
  const content = (
22
22
  <Box
23
23
  sx={{
24
- display: 'inline-flex',
25
- alignItems: 'center',
24
+ display: 'flex',
25
+ alignItems: 'flex-start',
26
26
  gap: 0.5,
27
- maxWidth: { xs: '100%', md: 'none' },
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: 'nowrap',
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(
@@ -1,5 +1,6 @@
1
1
  import { Box, Radio, Skeleton, Stack, Typography } from '@mui/material'
2
2
 
3
+ import RcSesButton from '@/components/common/Button'
3
4
  import RcSesCard from '@/components/common/Card'
4
5
  import ListWithIcons from '@/components/common/ListWithIcons'
5
6
  import palette from '@/theme/palette'
@@ -13,6 +14,9 @@ type Props = {
13
14
  selected: boolean
14
15
  onSelect: () => void
15
16
  isLoading?: boolean
17
+ hasActionButton?: boolean
18
+ actionButtonLabel?: string
19
+ onActionButtonClick?: () => void
16
20
  }
17
21
 
18
22
  const SelectableCardListItem = ({
@@ -22,6 +26,9 @@ const SelectableCardListItem = ({
22
26
  selected,
23
27
  onSelect,
24
28
  isLoading = false,
29
+ hasActionButton = false,
30
+ actionButtonLabel,
31
+ onActionButtonClick,
25
32
  }: Props) => {
26
33
  const titleTemplate = isLoading ? (
27
34
  <Stack
@@ -109,6 +116,33 @@ const SelectableCardListItem = ({
109
116
  },
110
117
  }}
111
118
  title={titleTemplate}
119
+ headerAction={
120
+ isLoading ? (
121
+ <Skeleton variant='rounded' width={100} height={38} />
122
+ ) : (
123
+ hasActionButton && (
124
+ <RcSesButton
125
+ color='grey'
126
+ sx={{
127
+ height: 'auto',
128
+ padding: '0.5rem 1rem',
129
+ fontSize: '0.875rem',
130
+ lineHeight: '1.25rem',
131
+ '&.MuiButton-colorGrey': {
132
+ color: palette.grey[800],
133
+ },
134
+ }}
135
+ onClick={(e) => {
136
+ e.stopPropagation()
137
+ onActionButtonClick?.()
138
+ }}
139
+ variant='outlined'
140
+ >
141
+ {actionButtonLabel}
142
+ </RcSesButton>
143
+ )
144
+ )
145
+ }
112
146
  slotProps={{
113
147
  title: {
114
148
  sx: {