@registrucentras/rc-ses-react-components 1.11.0 → 1.13.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.
Files changed (79) 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/SelectableCardList/components/SelectableCardListItem.d.ts +4 -1
  17. package/dist/components/common/SelectableCardList/index.d.ts +4 -1
  18. package/dist/components/common/Tooltip/index.d.ts +20 -0
  19. package/dist/components/form/inputs/Select/index.d.ts +1 -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 +10 -10
  24. package/dist/registrucentras-rc-ses-react-components.js +4218 -3377
  25. package/dist/stories/components/display/AdvancedList.stories.d.ts +33 -0
  26. package/dist/stories/components/display/AdvancedListItem.stories.d.ts +33 -0
  27. package/dist/stories/components/display/SelectableCardList.stories.d.ts +8 -1
  28. package/dist/stories/components/display/Tooltip.stories.d.ts +48 -0
  29. package/dist/stories/components/loaders/LoadingSpinner.stories.d.ts +3 -3
  30. package/dist/theme/light/MuiTooltip.d.ts +3 -0
  31. package/dist/theme/motion.d.ts +16 -0
  32. package/package.json +1 -1
  33. package/src/assets/icons/CaretUpBoldIcon.tsx +17 -0
  34. package/src/assets/icons/CaretUpIcon.tsx +9 -0
  35. package/src/assets/icons/ListIcon.tsx +17 -0
  36. package/src/assets/icons/MinusIcon.tsx +9 -0
  37. package/src/assets/icons/NotePencilIcon.tsx +9 -0
  38. package/src/assets/icons/PlusIcon.tsx +9 -0
  39. package/src/assets/icons/TrashIcon.tsx +23 -0
  40. package/src/assets/icons/UserIcon.tsx +17 -0
  41. package/src/components/common/AdvancedList/components/AdvancedListItem/AdvancedListItem.types.ts +100 -0
  42. package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.tsx +214 -0
  43. package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.tsx +241 -0
  44. package/src/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion.test.ts +80 -0
  45. package/src/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion.ts +28 -0
  46. package/src/components/common/AdvancedList/components/AdvancedListItem/index.test.tsx +631 -0
  47. package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +329 -0
  48. package/src/components/common/AdvancedList/index.test.tsx +97 -0
  49. package/src/components/common/AdvancedList/index.tsx +52 -0
  50. package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +7 -5
  51. package/src/components/common/SelectableCardList/components/SelectableCardListItem.test.tsx +50 -0
  52. package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +34 -0
  53. package/src/components/common/SelectableCardList/index.test.tsx +56 -2
  54. package/src/components/common/SelectableCardList/index.tsx +29 -10
  55. package/src/components/common/Tooltip/index.test.tsx +85 -0
  56. package/src/components/common/Tooltip/index.tsx +167 -0
  57. package/src/components/form/inputs/FileDropzone.tsx +1 -0
  58. package/src/components/form/inputs/FileUpload.tsx +1 -0
  59. package/src/components/form/inputs/NumberStepper.tsx +1 -0
  60. package/src/components/form/inputs/RadioButtonGroup.test.tsx +71 -0
  61. package/src/components/form/inputs/RadioButtonGroup.tsx +1 -0
  62. package/src/components/form/inputs/Select/index.test.tsx +159 -0
  63. package/src/components/form/inputs/Select/index.tsx +109 -53
  64. package/src/i18n/namespaces/common/en.json +14 -0
  65. package/src/i18n/namespaces/common/lt.json +14 -0
  66. package/src/library/icons.ts +16 -0
  67. package/src/library/index.ts +5 -0
  68. package/src/library/types.ts +2 -0
  69. package/src/setupTests.ts +7 -1
  70. package/src/stories/components/display/AdvancedList.stories.tsx +660 -0
  71. package/src/stories/components/display/AdvancedListItem.stories.tsx +593 -0
  72. package/src/stories/components/display/SelectableCardList.stories.tsx +19 -0
  73. package/src/stories/components/display/Tooltip.stories.tsx +67 -0
  74. package/src/stories/components/inputs/Select.stories.tsx +38 -2
  75. package/src/theme/light/MuiAutocomplete.ts +3 -1
  76. package/src/theme/light/MuiInputBase.ts +4 -0
  77. package/src/theme/light/MuiTooltip.ts +40 -0
  78. package/src/theme/light/index.tsx +2 -0
  79. package/src/theme/motion.tsx +10 -0
@@ -0,0 +1,241 @@
1
+ import { Box, IconButton, Radio, Stack, Typography } from '@mui/material'
2
+ import { useTranslation } from 'react-i18next'
3
+
4
+ import CaretRightBoldIcon from '@/assets/icons/CaretRightBoldIcon'
5
+ import MinusRegularIcon from '@/assets/icons/MinusIcon'
6
+ import PlusRegularIcon from '@/assets/icons/PlusIcon'
7
+ import TrashIcon from '@/assets/icons/TrashIcon'
8
+ import RcSesBadge, { type RcSesBadgeProps } from '@/components/common/Badge'
9
+ import RcSesButton from '@/components/common/Button'
10
+ import RcSesSwitch from '@/components/common/Switch'
11
+ import RcSesSimpleCheckbox from '@/components/form/inputs/SimpleCheckbox'
12
+ import palette from '@/theme/palette'
13
+
14
+ import {
15
+ AdvancedListItemStatusColor,
16
+ AdvancedListItemTrailing as AdvancedListItemTrailingData,
17
+ } from '../AdvancedListItem.types'
18
+
19
+ type Props = {
20
+ trailing: AdvancedListItemTrailingData
21
+ disabled?: boolean
22
+ }
23
+
24
+ const NO_SHRINK_SX = { flexShrink: 0 } as const
25
+
26
+ const STEPPER_BUTTON_SX = {
27
+ padding: '0.5rem 0.25rem',
28
+ borderRadius: '0.375rem',
29
+ } as const
30
+
31
+ const STATUS_VARIANT_MAP: Record<
32
+ AdvancedListItemStatusColor,
33
+ RcSesBadgeProps['variant']
34
+ > = {
35
+ grey: 'neutral',
36
+ warning: 'warning',
37
+ success: 'success',
38
+ error: 'error',
39
+ }
40
+
41
+ const PRICE_BLOCK_SX = {
42
+ display: 'inline-flex',
43
+ flexDirection: 'column',
44
+ justifyContent: 'center',
45
+ alignItems: 'flex-end',
46
+ gap: '0.125rem',
47
+ } as const
48
+
49
+ const ACTION_BUTTON_SX = {
50
+ height: 'auto',
51
+ padding: '0.5rem 0.25rem',
52
+ fontWeight: 500,
53
+ lineHeight: '1.25rem',
54
+ color: palette.primary[700],
55
+ '&:not(.Mui-disabled) svg path': {
56
+ fill: palette.primary[700],
57
+ },
58
+ '.MuiButton-startIcon': {
59
+ marginRight: '0.375rem',
60
+ },
61
+ } as const
62
+
63
+ const stop = (e: React.SyntheticEvent) => e.stopPropagation()
64
+
65
+ const stopAnd = (fn: () => void) => (e: React.SyntheticEvent) => {
66
+ stop(e)
67
+ fn()
68
+ }
69
+
70
+ const withStop =
71
+ <E extends React.SyntheticEvent>(handler: (e: E) => void) =>
72
+ (e: E) => {
73
+ stop(e)
74
+ handler(e)
75
+ }
76
+
77
+ const AdvancedListItemTrailing = ({ trailing, disabled }: Props) => {
78
+ const { t } = useTranslation('common', {
79
+ keyPrefix: 'components.AdvancedListItemTrailing',
80
+ })
81
+
82
+ if (trailing.type === 'actions') {
83
+ return (
84
+ <Stack direction='row' gap='0.5rem' onClick={stop} sx={NO_SHRINK_SX}>
85
+ {trailing.actions.map(
86
+ ({ label, icon: Icon, disabled: actionDisabled, onClick }) => (
87
+ <RcSesButton
88
+ key={label}
89
+ variant='link'
90
+ disabled={disabled || actionDisabled}
91
+ startIcon={Icon ? <Icon size={20} /> : undefined}
92
+ onClick={stopAnd(onClick)}
93
+ sx={ACTION_BUTTON_SX}
94
+ >
95
+ {label}
96
+ </RcSesButton>
97
+ ),
98
+ )}
99
+ </Stack>
100
+ )
101
+ }
102
+
103
+ if (trailing.type === 'toggle') {
104
+ return (
105
+ <RcSesSwitch
106
+ checked={trailing.checked}
107
+ disabled={disabled}
108
+ ariaLabel={trailing['aria-label'] ?? t('toggle')}
109
+ onClick={stop}
110
+ onChange={withStop((e) => trailing.onChange(e.target.checked))}
111
+ />
112
+ )
113
+ }
114
+
115
+ if (trailing.type === 'status') {
116
+ return (
117
+ <RcSesBadge
118
+ label={trailing.label}
119
+ variant={STATUS_VARIANT_MAP[trailing.color ?? 'grey']}
120
+ size='small'
121
+ />
122
+ )
123
+ }
124
+
125
+ if (trailing.type === 'price') {
126
+ return (
127
+ <Stack direction='row' alignItems='center' gap='0.5rem' sx={NO_SHRINK_SX}>
128
+ <Box sx={PRICE_BLOCK_SX}>
129
+ <Typography
130
+ variant='body1'
131
+ sx={{ fontSize: '1rem', fontWeight: 600, lineHeight: '1.375rem' }}
132
+ color={palette.grey[900]}
133
+ >
134
+ {trailing.amount}
135
+ </Typography>
136
+ {!!trailing.caption && (
137
+ <Typography
138
+ variant='caption'
139
+ sx={{ fontSize: '0.8125rem', lineHeight: '1.125rem' }}
140
+ color={palette.grey[600]}
141
+ >
142
+ {trailing.caption}
143
+ </Typography>
144
+ )}
145
+ </Box>
146
+ {!!trailing.onDelete && (
147
+ <IconButton
148
+ aria-label={trailing.deleteAriaLabel ?? t('delete')}
149
+ size='small'
150
+ disabled={disabled}
151
+ onClick={stopAnd(() => trailing.onDelete?.())}
152
+ sx={{ padding: '0.5rem 0.25rem' }}
153
+ >
154
+ <TrashIcon size={20} fillColor={palette.grey[700]} />
155
+ </IconButton>
156
+ )}
157
+ </Stack>
158
+ )
159
+ }
160
+
161
+ if (trailing.type === 'checkbox') {
162
+ return (
163
+ <RcSesSimpleCheckbox
164
+ checked={trailing.checked}
165
+ disabled={disabled}
166
+ inputProps={{ 'aria-label': trailing['aria-label'] }}
167
+ onClick={stop}
168
+ onChange={withStop((e) => trailing.onChange(e.target.checked))}
169
+ sx={{ padding: 0, ...NO_SHRINK_SX }}
170
+ />
171
+ )
172
+ }
173
+ // change to RcSesRadio when it is implemented
174
+ if (trailing.type === 'radio') {
175
+ return (
176
+ <Radio
177
+ checked={trailing.checked}
178
+ disabled={disabled}
179
+ name={trailing.name}
180
+ inputProps={{ 'aria-label': trailing['aria-label'] }}
181
+ onClick={stop}
182
+ onChange={withStop((e) => trailing.onChange(e.target.checked))}
183
+ sx={{ padding: 0, ...NO_SHRINK_SX }}
184
+ />
185
+ )
186
+ }
187
+
188
+ if (trailing.type === 'chevron') {
189
+ return (
190
+ <Box sx={{ display: 'flex', flexShrink: 0 }} aria-hidden>
191
+ <CaretRightBoldIcon size={16} fillColor={palette.grey[500]} />
192
+ </Box>
193
+ )
194
+ }
195
+
196
+ if (trailing.type === 'stepper') {
197
+ const { value, onChange, min, max } = trailing
198
+ const atMin = min !== undefined && value <= min
199
+ const atMax = max !== undefined && value >= max
200
+
201
+ return (
202
+ <Stack
203
+ direction='row'
204
+ alignItems='center'
205
+ gap='0.25rem'
206
+ onClick={stop}
207
+ sx={NO_SHRINK_SX}
208
+ >
209
+ <IconButton
210
+ aria-label={t('decrease')}
211
+ size='small'
212
+ disabled={disabled || atMin}
213
+ onClick={stopAnd(() => onChange(value - 1))}
214
+ sx={STEPPER_BUTTON_SX}
215
+ >
216
+ <MinusRegularIcon size={20} fillColor={palette.primary[700]} />
217
+ </IconButton>
218
+ <Typography
219
+ aria-label={trailing['aria-label']}
220
+ variant='body2'
221
+ sx={{ minWidth: '1.5rem', textAlign: 'center', fontWeight: 600 }}
222
+ >
223
+ {value}
224
+ </Typography>
225
+ <IconButton
226
+ aria-label={t('increase')}
227
+ size='small'
228
+ disabled={disabled || atMax}
229
+ onClick={stopAnd(() => onChange(value + 1))}
230
+ sx={STEPPER_BUTTON_SX}
231
+ >
232
+ <PlusRegularIcon size={20} fillColor={palette.primary[700]} />
233
+ </IconButton>
234
+ </Stack>
235
+ )
236
+ }
237
+
238
+ return null
239
+ }
240
+
241
+ export default AdvancedListItemTrailing
@@ -0,0 +1,80 @@
1
+ import { act, renderHook } from '@testing-library/react'
2
+ import { afterEach, describe, expect, test, vi } from 'vitest'
3
+
4
+ import usePrefersReducedMotion from './usePrefersReducedMotion'
5
+
6
+ const QUERY = '(prefers-reduced-motion: reduce)'
7
+
8
+ const createMatchMediaMock = (initialMatches: boolean) => {
9
+ let matches = initialMatches
10
+ const listeners = new Set<() => void>()
11
+
12
+ const mediaQueryList = {
13
+ get matches() {
14
+ return matches
15
+ },
16
+ addEventListener: vi.fn((_event: string, listener: () => void) => {
17
+ listeners.add(listener)
18
+ }),
19
+ removeEventListener: vi.fn((_event: string, listener: () => void) => {
20
+ listeners.delete(listener)
21
+ }),
22
+ }
23
+
24
+ return {
25
+ matchMedia: vi.fn(() => mediaQueryList),
26
+ mediaQueryList,
27
+ setMatches: (next: boolean) => {
28
+ matches = next
29
+ listeners.forEach((listener) => listener())
30
+ },
31
+ }
32
+ }
33
+
34
+ describe('usePrefersReducedMotion', () => {
35
+ afterEach(() => {
36
+ vi.unstubAllGlobals()
37
+ })
38
+
39
+ test('reflects the current matchMedia value on mount', () => {
40
+ const { matchMedia } = createMatchMediaMock(true)
41
+ vi.stubGlobal('matchMedia', matchMedia)
42
+
43
+ const { result } = renderHook(() => usePrefersReducedMotion())
44
+
45
+ expect(result.current).toBe(true)
46
+ expect(matchMedia).toHaveBeenCalledWith(QUERY)
47
+ })
48
+
49
+ test('updates when the OS-level preference changes', () => {
50
+ const { matchMedia, setMatches } = createMatchMediaMock(false)
51
+ vi.stubGlobal('matchMedia', matchMedia)
52
+
53
+ const { result } = renderHook(() => usePrefersReducedMotion())
54
+ expect(result.current).toBe(false)
55
+
56
+ act(() => setMatches(true))
57
+
58
+ expect(result.current).toBe(true)
59
+ })
60
+
61
+ test('unsubscribes the change listener on unmount', () => {
62
+ const { matchMedia, mediaQueryList } = createMatchMediaMock(false)
63
+ vi.stubGlobal('matchMedia', matchMedia)
64
+
65
+ const { unmount } = renderHook(() => usePrefersReducedMotion())
66
+ expect(mediaQueryList.addEventListener).toHaveBeenCalledTimes(1)
67
+
68
+ unmount()
69
+
70
+ expect(mediaQueryList.removeEventListener).toHaveBeenCalledTimes(1)
71
+ })
72
+
73
+ test('falls back to false when matchMedia is unsupported (SSR-safe)', () => {
74
+ vi.stubGlobal('matchMedia', undefined)
75
+
76
+ const { result } = renderHook(() => usePrefersReducedMotion())
77
+
78
+ expect(result.current).toBe(false)
79
+ })
80
+ })
@@ -0,0 +1,28 @@
1
+ import { useEffect, useState } from 'react'
2
+
3
+ const QUERY = '(prefers-reduced-motion: reduce)'
4
+
5
+ const supportsMatchMedia = () =>
6
+ typeof window !== 'undefined' && typeof window.matchMedia === 'function'
7
+
8
+ const usePrefersReducedMotion = () => {
9
+ const [prefersReducedMotion, setPrefersReducedMotion] = useState(
10
+ () => supportsMatchMedia() && window.matchMedia(QUERY).matches,
11
+ )
12
+
13
+ useEffect(() => {
14
+ if (!supportsMatchMedia()) {
15
+ return undefined
16
+ }
17
+
18
+ const mediaQueryList = window.matchMedia(QUERY)
19
+ const listener = () => setPrefersReducedMotion(mediaQueryList.matches)
20
+
21
+ mediaQueryList.addEventListener('change', listener)
22
+ return () => mediaQueryList.removeEventListener('change', listener)
23
+ }, [])
24
+
25
+ return prefersReducedMotion
26
+ }
27
+
28
+ export default usePrefersReducedMotion