@registrucentras/rc-ses-react-components 2.0.0 → 2.2.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 (78) hide show
  1. package/README.md +4 -0
  2. package/dist/assets/icons/ShoppingCartIcon.d.ts +3 -0
  3. package/dist/components/common/CardShell/index.d.ts +1 -1
  4. package/dist/components/common/CardShell/types.d.ts +10 -0
  5. package/dist/components/common/ListWithIcons/ListWithIcons.types.d.ts +4 -1
  6. package/dist/components/common/StepCard/StepCardFooter/index.d.ts +34 -0
  7. package/dist/components/common/StepCard/index.d.ts +3 -0
  8. package/dist/components/common/StepCard/types.d.ts +39 -0
  9. package/dist/components/common/TitleBlock/types.d.ts +1 -1
  10. package/dist/components/form/inputs/Select/Select.utils.d.ts +9 -0
  11. package/dist/components/form/inputs/Select/components/OptionCheckbox.d.ts +5 -0
  12. package/dist/components/form/inputs/Select/index.d.ts +18 -8
  13. package/dist/components/layout/ServiceFormContainer/CardFormContainer/index.d.ts +3 -0
  14. package/dist/components/loaders/LoadingSpinner/index.d.ts +1 -4
  15. package/dist/components/overlays/BottomSheet/index.d.ts +17 -0
  16. package/dist/components/overlays/BottomSheet/useSwipeToDismiss.d.ts +17 -0
  17. package/dist/library/icons.d.ts +2 -1
  18. package/dist/library/index.d.ts +3 -1
  19. package/dist/library/types.d.ts +6 -3
  20. package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
  21. package/dist/registrucentras-rc-ses-react-components.js +3903 -3289
  22. package/dist/theme/cards.d.ts +12 -12
  23. package/dist/theme/light/MuiTypography.d.ts +14 -0
  24. package/dist/theme/palette.d.ts +124 -124
  25. package/dist/theme/spacing.d.ts +4 -0
  26. package/package.json +2 -1
  27. package/src/assets/icons/ShoppingCartIcon.tsx +16 -0
  28. package/src/components/common/Button/index.test.tsx +20 -11
  29. package/src/components/common/Button/index.tsx +8 -44
  30. package/src/components/common/CardShell/index.tsx +6 -2
  31. package/src/components/common/CardShell/types.ts +10 -0
  32. package/src/components/common/ListWithIcons/ListWithIcons.types.ts +22 -1
  33. package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +13 -4
  34. package/src/components/common/ListWithIcons/index.test.tsx +42 -0
  35. package/src/components/common/StepCard/StepCardFooter/index.test.tsx +162 -0
  36. package/src/components/common/StepCard/StepCardFooter/index.tsx +120 -0
  37. package/src/components/common/StepCard/index.test.tsx +120 -0
  38. package/src/components/common/StepCard/index.tsx +74 -0
  39. package/src/components/common/StepCard/types.ts +45 -0
  40. package/src/components/common/TitleBlock/types.ts +1 -1
  41. package/src/components/form/inputs/SearchableField.test.tsx +1 -1
  42. package/src/components/form/inputs/Select/Select.utils.ts +24 -0
  43. package/src/components/form/inputs/Select/components/OptionCheckbox.tsx +46 -0
  44. package/src/components/form/inputs/Select/index.test.tsx +127 -0
  45. package/src/components/form/inputs/Select/index.tsx +426 -181
  46. package/src/components/layout/ServiceFormContainer/CardFormContainer/index.tsx +3 -0
  47. package/src/components/loaders/LoadingSpinner/index.tsx +3 -26
  48. package/src/components/overlays/BottomSheet/index.test.tsx +256 -0
  49. package/src/components/overlays/BottomSheet/index.tsx +242 -0
  50. package/src/components/overlays/BottomSheet/useSwipeToDismiss.test.ts +295 -0
  51. package/src/components/overlays/BottomSheet/useSwipeToDismiss.ts +138 -0
  52. package/src/examples/ListWithPagination/index.tsx +2 -1
  53. package/src/i18n/namespaces/common/en.json +7 -0
  54. package/src/i18n/namespaces/common/lt.json +7 -0
  55. package/src/i18n/namespaces/input/en.json +11 -0
  56. package/src/i18n/namespaces/input/lt.json +11 -0
  57. package/src/library/icons.ts +2 -0
  58. package/src/library/index.ts +4 -0
  59. package/src/library/types.ts +19 -2
  60. package/src/stories/atoms/Button.stories.tsx +202 -497
  61. package/src/stories/atoms/Select.stories.tsx +33 -5
  62. package/src/stories/foundations/ThemedMuiComponents.stories.tsx +2 -2
  63. package/src/stories/molecules/CardShell.stories.tsx +36 -2
  64. package/src/stories/molecules/DatePicker.stories.tsx +1 -2
  65. package/src/stories/molecules/ListWithIcons.stories.tsx +26 -0
  66. package/src/stories/molecules/Popover.stories.tsx +1 -1
  67. package/src/stories/molecules/StepCard.stories.tsx +181 -0
  68. package/src/stories/molecules/TitleBlock.stories.tsx +2 -2
  69. package/src/stories/organisms/AdvancedListItem.stories.tsx +80 -0
  70. package/src/stories/organisms/BottomSheet.stories.tsx +291 -0
  71. package/src/stories/organisms/CardFormContainer.stories.tsx +1 -1
  72. package/src/stories/organisms/Dialog.stories.tsx +1 -2
  73. package/src/theme/light/MuiAutocomplete.ts +43 -19
  74. package/src/theme/light/MuiButton.tsx +54 -0
  75. package/src/theme/light/MuiCard.tsx +9 -7
  76. package/src/theme/light/MuiTypography.tsx +17 -0
  77. package/src/theme/palette.tsx +7 -7
  78. package/src/theme/spacing.ts +5 -0
@@ -0,0 +1,46 @@
1
+ import { Box } from '@mui/material'
2
+
3
+ import CheckIcon from '@/assets/icons/CheckIcon'
4
+ import palette from '@/theme/palette'
5
+
6
+ interface Props {
7
+ checked: boolean
8
+ }
9
+
10
+ function OptionCheckbox({ checked }: Props) {
11
+ return (
12
+ <Box aria-hidden sx={{ flexShrink: 0, py: '.5rem' }}>
13
+ <Box
14
+ sx={{
15
+ alignItems: 'center',
16
+ boxSizing: 'border-box',
17
+ display: 'flex',
18
+ height: '1.5rem',
19
+ justifyContent: 'center',
20
+ padding: '.125rem',
21
+ width: '1.5rem',
22
+ }}
23
+ >
24
+ <Box
25
+ sx={{
26
+ alignItems: 'center',
27
+ backgroundColor: checked ? palette.primary.main : 'white',
28
+ border: checked
29
+ ? `1px solid ${palette.primary.main}`
30
+ : `2px solid ${palette.grey['500']}`,
31
+ borderRadius: '.25rem',
32
+ boxSizing: 'border-box',
33
+ display: 'flex',
34
+ height: '1.25rem',
35
+ justifyContent: 'center',
36
+ width: '1.25rem',
37
+ }}
38
+ >
39
+ {checked && <CheckIcon size={14} weight='bold' fillColor='white' />}
40
+ </Box>
41
+ </Box>
42
+ </Box>
43
+ )
44
+ }
45
+
46
+ export default OptionCheckbox
@@ -80,6 +80,62 @@ const TestWrapper = ({ defaultValue = null }: TestWrapperProps) => {
80
80
  )
81
81
  }
82
82
 
83
+ const groupedOptions = [
84
+ { value: 'rc', label: 'Registrų centras', group: 'Nekilnojamasis turtas' },
85
+ { value: 'vtpsi', label: 'VTPSI', group: 'Nekilnojamasis turtas' },
86
+ { value: 'regitra', label: 'Regitra', group: 'Transportas' },
87
+ ]
88
+
89
+ interface GroupedFormModel {
90
+ providers: string[]
91
+ }
92
+
93
+ interface GroupedMultiTestWrapperProps {
94
+ defaultValue?: string[]
95
+ dropdownSearch?: boolean
96
+ }
97
+
98
+ const GroupedMultiTestWrapper = ({
99
+ defaultValue = [],
100
+ dropdownSearch = false,
101
+ }: GroupedMultiTestWrapperProps) => {
102
+ const { control, getValues } = useForm<GroupedFormModel>({
103
+ defaultValues: { providers: defaultValue },
104
+ })
105
+ const [formValues, setFormValues] = useState('')
106
+
107
+ return (
108
+ <ThemeProvider theme={theme}>
109
+ <RcSesSelect
110
+ id='providers'
111
+ name='providers'
112
+ control={control}
113
+ label='Teikėjai'
114
+ multiple
115
+ dropdownSearch={dropdownSearch}
116
+ selectAll
117
+ options={groupedOptions}
118
+ slotProps={{
119
+ field: {
120
+ groupBy: (option) =>
121
+ groupedOptions.find((o) => o.value === option.value)?.group ?? '',
122
+ },
123
+ }}
124
+ />
125
+
126
+ <button type='button' onClick={() => setFormValues(JSON.stringify(getValues()))}>
127
+ Read
128
+ </button>
129
+ <div data-testid='form-values'>{formValues}</div>
130
+ </ThemeProvider>
131
+ )
132
+ }
133
+
134
+ const readGroupedFormValues = (): GroupedFormModel => {
135
+ fireEvent.click(screen.getByRole('button', { name: 'Read' }))
136
+ return JSON.parse(screen.getByTestId('form-values').textContent ?? '{}')
137
+ }
138
+
83
139
  describe('RcSesSelect', () => {
84
140
  test('single select rodo pilna pasirinktos reiksmes label', () => {
85
141
  render(<TestWrapper defaultValue='long-option' />)
@@ -156,4 +212,75 @@ describe('RcSesSelect', () => {
156
212
 
157
213
  expect(screen.getByTestId('form-values')).toHaveTextContent('short-option')
158
214
  })
215
+
216
+ test('clicking a group selects all of its members', async () => {
217
+ render(<GroupedMultiTestWrapper />)
218
+
219
+ fireEvent.mouseDown(screen.getByRole('combobox'))
220
+ fireEvent.click(
221
+ // The badge showing the group's member count is part of the row's
222
+ // accessible name (it's not aria-hidden - screen readers should
223
+ // announce the count), so this can't be an exact-string match.
224
+ await screen.findByRole('option', { name: /^Nekilnojamasis turtas/ }),
225
+ )
226
+
227
+ const { providers } = readGroupedFormValues()
228
+ expect([...providers].sort()).toEqual(['rc', 'vtpsi'])
229
+ })
230
+
231
+ test('unchecking one member un-checks its (previously fully-selected) group', async () => {
232
+ render(<GroupedMultiTestWrapper defaultValue={['rc', 'vtpsi']} />)
233
+
234
+ fireEvent.mouseDown(screen.getByRole('combobox'))
235
+ fireEvent.click(await screen.findByRole('option', { name: 'Registrų centras' }))
236
+
237
+ const { providers } = readGroupedFormValues()
238
+ expect(providers).toEqual(['vtpsi'])
239
+ })
240
+
241
+ test('re-clicking a fully-selected group deselects all of its members', async () => {
242
+ render(<GroupedMultiTestWrapper defaultValue={['rc', 'vtpsi']} />)
243
+
244
+ fireEvent.mouseDown(screen.getByRole('combobox'))
245
+ fireEvent.click(
246
+ // The badge showing the group's member count is part of the row's
247
+ // accessible name (it's not aria-hidden - screen readers should
248
+ // announce the count), so this can't be an exact-string match.
249
+ await screen.findByRole('option', { name: /^Nekilnojamasis turtas/ }),
250
+ )
251
+
252
+ const { providers } = readGroupedFormValues()
253
+ expect(providers).toEqual([])
254
+ })
255
+
256
+ test('the group row is reachable by keyboard and Enter toggles it', async () => {
257
+ render(<GroupedMultiTestWrapper />)
258
+
259
+ const input = screen.getByRole('combobox')
260
+ fireEvent.mouseDown(input)
261
+ await screen.findByRole('option', { name: 'Registrų centras' })
262
+
263
+ // The group marker is the first option ahead of its own members.
264
+ fireEvent.keyDown(input, { key: 'ArrowDown' })
265
+ fireEvent.keyDown(input, { key: 'Enter' })
266
+
267
+ const { providers } = readGroupedFormValues()
268
+ expect([...providers].sort()).toEqual(['rc', 'vtpsi'])
269
+ })
270
+
271
+ test('keyboard Enter on the "select all" row selects every option', async () => {
272
+ render(<GroupedMultiTestWrapper dropdownSearch />)
273
+
274
+ const input = screen.getByRole('combobox')
275
+ fireEvent.mouseDown(input)
276
+ await screen.findByRole('option', { name: 'Registrų centras' })
277
+
278
+ // The search field is the first row, "Visi" the second.
279
+ fireEvent.keyDown(input, { key: 'ArrowDown' })
280
+ fireEvent.keyDown(input, { key: 'ArrowDown' })
281
+ fireEvent.keyDown(input, { key: 'Enter' })
282
+
283
+ const { providers } = readGroupedFormValues()
284
+ expect([...providers].sort()).toEqual(['rc', 'regitra', 'vtpsi'])
285
+ })
159
286
  })