@registrucentras/rc-ses-react-components 2.1.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.
- package/dist/components/form/inputs/Select/Select.utils.d.ts +9 -0
- package/dist/components/form/inputs/Select/components/OptionCheckbox.d.ts +5 -0
- package/dist/components/form/inputs/Select/index.d.ts +18 -8
- package/dist/components/overlays/BottomSheet/index.d.ts +17 -0
- package/dist/components/overlays/BottomSheet/useSwipeToDismiss.d.ts +17 -0
- package/dist/library/index.d.ts +2 -1
- package/dist/library/types.d.ts +2 -0
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +3492 -3081
- package/package.json +1 -1
- package/src/components/form/inputs/Select/Select.utils.ts +24 -0
- package/src/components/form/inputs/Select/components/OptionCheckbox.tsx +46 -0
- package/src/components/form/inputs/Select/index.test.tsx +127 -0
- package/src/components/form/inputs/Select/index.tsx +426 -181
- package/src/components/overlays/BottomSheet/index.test.tsx +256 -0
- package/src/components/overlays/BottomSheet/index.tsx +242 -0
- package/src/components/overlays/BottomSheet/useSwipeToDismiss.test.ts +295 -0
- package/src/components/overlays/BottomSheet/useSwipeToDismiss.ts +138 -0
- package/src/i18n/namespaces/input/en.json +11 -0
- package/src/i18n/namespaces/input/lt.json +11 -0
- package/src/library/index.ts +2 -0
- package/src/library/types.ts +2 -0
- package/src/stories/atoms/Select.stories.tsx +33 -5
- package/src/stories/organisms/BottomSheet.stories.tsx +291 -0
- package/src/theme/light/MuiAutocomplete.ts +43 -19
package/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Option } from './Select.types'
|
|
2
|
+
|
|
3
|
+
export const dropdownSearchFieldValue = '__dropdown-search-field__'
|
|
4
|
+
export const dropdownSelectAllValue = '__dropdown-select-all__'
|
|
5
|
+
export const dropdownGroupOptionPrefix = '__dropdown-group__:'
|
|
6
|
+
|
|
7
|
+
export const isGroupOptionValue = (value: string) =>
|
|
8
|
+
value.startsWith(dropdownGroupOptionPrefix)
|
|
9
|
+
|
|
10
|
+
export const groupNameFromOptionValue = (value: string) =>
|
|
11
|
+
value.slice(dropdownGroupOptionPrefix.length)
|
|
12
|
+
|
|
13
|
+
export const dropdownGroupOptionValue = (groupName: string) =>
|
|
14
|
+
`${dropdownGroupOptionPrefix}${groupName}`
|
|
15
|
+
|
|
16
|
+
export const isInternalOptionValue = (value: string) =>
|
|
17
|
+
value === dropdownSearchFieldValue ||
|
|
18
|
+
value === dropdownSelectAllValue ||
|
|
19
|
+
isGroupOptionValue(value)
|
|
20
|
+
|
|
21
|
+
export const dropdownSearchFieldOption: Option = {
|
|
22
|
+
label: '',
|
|
23
|
+
value: dropdownSearchFieldValue,
|
|
24
|
+
}
|
|
@@ -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
|
})
|