@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.
- package/README.md +4 -0
- package/dist/assets/icons/ShoppingCartIcon.d.ts +3 -0
- package/dist/components/common/CardShell/index.d.ts +1 -1
- package/dist/components/common/CardShell/types.d.ts +10 -0
- package/dist/components/common/ListWithIcons/ListWithIcons.types.d.ts +4 -1
- package/dist/components/common/StepCard/StepCardFooter/index.d.ts +34 -0
- package/dist/components/common/StepCard/index.d.ts +3 -0
- package/dist/components/common/StepCard/types.d.ts +39 -0
- package/dist/components/common/TitleBlock/types.d.ts +1 -1
- 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/layout/ServiceFormContainer/CardFormContainer/index.d.ts +3 -0
- package/dist/components/loaders/LoadingSpinner/index.d.ts +1 -4
- package/dist/components/overlays/BottomSheet/index.d.ts +17 -0
- package/dist/components/overlays/BottomSheet/useSwipeToDismiss.d.ts +17 -0
- package/dist/library/icons.d.ts +2 -1
- package/dist/library/index.d.ts +3 -1
- package/dist/library/types.d.ts +6 -3
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +3903 -3289
- package/dist/theme/cards.d.ts +12 -12
- package/dist/theme/light/MuiTypography.d.ts +14 -0
- package/dist/theme/palette.d.ts +124 -124
- package/dist/theme/spacing.d.ts +4 -0
- package/package.json +2 -1
- package/src/assets/icons/ShoppingCartIcon.tsx +16 -0
- package/src/components/common/Button/index.test.tsx +20 -11
- package/src/components/common/Button/index.tsx +8 -44
- package/src/components/common/CardShell/index.tsx +6 -2
- package/src/components/common/CardShell/types.ts +10 -0
- package/src/components/common/ListWithIcons/ListWithIcons.types.ts +22 -1
- package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +13 -4
- package/src/components/common/ListWithIcons/index.test.tsx +42 -0
- package/src/components/common/StepCard/StepCardFooter/index.test.tsx +162 -0
- package/src/components/common/StepCard/StepCardFooter/index.tsx +120 -0
- package/src/components/common/StepCard/index.test.tsx +120 -0
- package/src/components/common/StepCard/index.tsx +74 -0
- package/src/components/common/StepCard/types.ts +45 -0
- package/src/components/common/TitleBlock/types.ts +1 -1
- package/src/components/form/inputs/SearchableField.test.tsx +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/layout/ServiceFormContainer/CardFormContainer/index.tsx +3 -0
- package/src/components/loaders/LoadingSpinner/index.tsx +3 -26
- 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/examples/ListWithPagination/index.tsx +2 -1
- package/src/i18n/namespaces/common/en.json +7 -0
- package/src/i18n/namespaces/common/lt.json +7 -0
- package/src/i18n/namespaces/input/en.json +11 -0
- package/src/i18n/namespaces/input/lt.json +11 -0
- package/src/library/icons.ts +2 -0
- package/src/library/index.ts +4 -0
- package/src/library/types.ts +19 -2
- package/src/stories/atoms/Button.stories.tsx +202 -497
- package/src/stories/atoms/Select.stories.tsx +33 -5
- package/src/stories/foundations/ThemedMuiComponents.stories.tsx +2 -2
- package/src/stories/molecules/CardShell.stories.tsx +36 -2
- package/src/stories/molecules/DatePicker.stories.tsx +1 -2
- package/src/stories/molecules/ListWithIcons.stories.tsx +26 -0
- package/src/stories/molecules/Popover.stories.tsx +1 -1
- package/src/stories/molecules/StepCard.stories.tsx +181 -0
- package/src/stories/molecules/TitleBlock.stories.tsx +2 -2
- package/src/stories/organisms/AdvancedListItem.stories.tsx +80 -0
- package/src/stories/organisms/BottomSheet.stories.tsx +291 -0
- package/src/stories/organisms/CardFormContainer.stories.tsx +1 -1
- package/src/stories/organisms/Dialog.stories.tsx +1 -2
- package/src/theme/light/MuiAutocomplete.ts +43 -19
- package/src/theme/light/MuiButton.tsx +54 -0
- package/src/theme/light/MuiCard.tsx +9 -7
- package/src/theme/light/MuiTypography.tsx +17 -0
- package/src/theme/palette.tsx +7 -7
- package/src/theme/spacing.ts +5 -0
|
@@ -1,48 +1,56 @@
|
|
|
1
|
-
import { Box,
|
|
1
|
+
import { Box, Chip, Paper, TextField } from '@mui/material'
|
|
2
2
|
import Autocomplete, { AutocompleteProps } from '@mui/material/Autocomplete'
|
|
3
3
|
import React, { useMemo } from 'react'
|
|
4
|
-
import { UseControllerProps, useController } from 'react-hook-form'
|
|
4
|
+
import { FieldValues, UseControllerProps, useController } from 'react-hook-form'
|
|
5
|
+
import { useTranslation } from 'react-i18next'
|
|
5
6
|
import { v4 as uuidv4 } from 'uuid'
|
|
6
7
|
|
|
7
|
-
import
|
|
8
|
+
import CaretDownIcon from '@/assets/icons/CaretDownIcon'
|
|
8
9
|
import CheckIcon from '@/assets/icons/CheckIcon'
|
|
9
|
-
import
|
|
10
|
-
import MagnifyingGlassIcon from '@/assets/icons/MagnifyingGlassIcon'
|
|
10
|
+
import RcSesBadge from '@/components/common/Badge'
|
|
11
11
|
import palette from '@/theme/palette'
|
|
12
12
|
|
|
13
13
|
import RcSesFormControlWrapper, {
|
|
14
14
|
RcSesFormControlWrapperProps,
|
|
15
15
|
} from '../../components/FormControlWrapper'
|
|
16
16
|
import { Option } from './Select.types'
|
|
17
|
+
import {
|
|
18
|
+
dropdownGroupOptionValue,
|
|
19
|
+
dropdownSearchFieldOption,
|
|
20
|
+
dropdownSearchFieldValue,
|
|
21
|
+
dropdownSelectAllValue,
|
|
22
|
+
groupNameFromOptionValue,
|
|
23
|
+
isGroupOptionValue,
|
|
24
|
+
isInternalOptionValue,
|
|
25
|
+
} from './Select.utils'
|
|
26
|
+
import OptionCheckbox from './components/OptionCheckbox'
|
|
17
27
|
import useFilteredOptions from './hooks/useFilteredOptions'
|
|
18
28
|
import useSelectAll from './hooks/useSelectAllLogic'
|
|
19
29
|
|
|
20
|
-
type TControllerProps =
|
|
30
|
+
type TControllerProps<TFieldValues extends FieldValues = FieldValues> =
|
|
31
|
+
UseControllerProps<TFieldValues>
|
|
21
32
|
type ImmediateControllerProps = 'control' | 'rules' | 'name' | 'disabled'
|
|
22
33
|
|
|
23
34
|
type TWrapperProps = RcSesFormControlWrapperProps
|
|
24
35
|
type ImmediateWrapperProps = 'id' | 'label' | 'errors'
|
|
25
|
-
type AutocompleteValue<T, Multiple extends boolean> = Multiple extends true
|
|
26
|
-
? T[]
|
|
27
|
-
: T | null
|
|
28
36
|
|
|
29
|
-
type
|
|
37
|
+
type CommonSelectProps<TFieldValues extends FieldValues = FieldValues> = Pick<
|
|
38
|
+
TControllerProps<TFieldValues>,
|
|
39
|
+
ImmediateControllerProps
|
|
40
|
+
> &
|
|
30
41
|
Pick<TWrapperProps, ImmediateWrapperProps> & {
|
|
31
|
-
multiple?: boolean
|
|
32
42
|
clearable?: boolean
|
|
33
|
-
limitTags?: number
|
|
34
43
|
loading?: boolean
|
|
35
44
|
options: Option[]
|
|
36
45
|
placeholder?: string
|
|
37
46
|
dropdownLabel?: string
|
|
38
47
|
dropdownSearch?: boolean
|
|
39
48
|
dropdownSearchPlaceholder?: string
|
|
40
|
-
selectAll?: boolean
|
|
41
49
|
|
|
42
50
|
onInputChange?: AutocompleteProps<Option, boolean, boolean, false>['onInputChange']
|
|
43
51
|
|
|
44
52
|
slotProps?: {
|
|
45
|
-
controller?: Partial<Omit<TControllerProps
|
|
53
|
+
controller?: Partial<Omit<TControllerProps<TFieldValues>, ImmediateControllerProps>>
|
|
46
54
|
field?: Partial<
|
|
47
55
|
Omit<
|
|
48
56
|
AutocompleteProps<Option, boolean, boolean, false>,
|
|
@@ -53,10 +61,60 @@ type Props = Pick<TControllerProps, ImmediateControllerProps> &
|
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
|
|
56
|
-
|
|
64
|
+
type SingleSelectProps<TFieldValues extends FieldValues = FieldValues> =
|
|
65
|
+
CommonSelectProps<TFieldValues> & {
|
|
66
|
+
multiple?: false
|
|
67
|
+
limitTags?: never
|
|
68
|
+
selectAll?: never
|
|
69
|
+
selectAllLabel?: never
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type MultiSelectProps<TFieldValues extends FieldValues = FieldValues> =
|
|
73
|
+
CommonSelectProps<TFieldValues> & {
|
|
74
|
+
multiple: true
|
|
75
|
+
limitTags?: number
|
|
76
|
+
selectAll?: boolean
|
|
77
|
+
selectAllLabel?: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type Props<TFieldValues extends FieldValues = FieldValues> =
|
|
81
|
+
SingleSelectProps<TFieldValues> | MultiSelectProps<TFieldValues>
|
|
82
|
+
|
|
83
|
+
interface DropdownPaperProps extends React.ComponentProps<typeof Paper> {
|
|
84
|
+
dropdownLabel?: string
|
|
85
|
+
ownerState?: unknown
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function DropdownPaper({
|
|
89
|
+
children,
|
|
90
|
+
dropdownLabel,
|
|
91
|
+
ownerState: _ownerState,
|
|
92
|
+
...paperProps
|
|
93
|
+
}: DropdownPaperProps) {
|
|
94
|
+
return (
|
|
95
|
+
<Paper {...paperProps}>
|
|
96
|
+
{!!dropdownLabel && (
|
|
97
|
+
<Box
|
|
98
|
+
sx={{
|
|
99
|
+
padding: '1.1875rem 1.125rem .8125rem 1.125rem',
|
|
100
|
+
fontSize: '.9375rem',
|
|
101
|
+
color: palette.grey[600],
|
|
102
|
+
}}
|
|
103
|
+
>
|
|
104
|
+
{dropdownLabel}
|
|
105
|
+
</Box>
|
|
106
|
+
)}
|
|
107
|
+
{children}
|
|
108
|
+
</Paper>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function RcSesSelect<TFieldValues extends FieldValues = FieldValues>(
|
|
113
|
+
props: Props<TFieldValues>,
|
|
114
|
+
) {
|
|
115
|
+
const { t } = useTranslation('input', { keyPrefix: 'components.RcSesSelect' })
|
|
57
116
|
const [dropdownSearchValue, setDropdownSearchValue] = React.useState('')
|
|
58
117
|
const [open, setOpen] = React.useState(false)
|
|
59
|
-
const dropdownSearchOptionValue = '__dropdown-search-option__'
|
|
60
118
|
// rem widths reserved at the end of the input for the clear and dropdown adornments
|
|
61
119
|
const reservedSingleEndAdornmentWidth = 2
|
|
62
120
|
const reservedMultipleTagsEndAdornmentWidth = 2.2
|
|
@@ -78,18 +136,23 @@ function RcSesSelect(props: Props) {
|
|
|
78
136
|
slotProps,
|
|
79
137
|
dropdownLabel,
|
|
80
138
|
dropdownSearch = false,
|
|
81
|
-
dropdownSearchPlaceholder
|
|
139
|
+
dropdownSearchPlaceholder,
|
|
82
140
|
selectAll = false,
|
|
141
|
+
selectAllLabel,
|
|
83
142
|
...fieldProps
|
|
84
143
|
} = props
|
|
85
144
|
|
|
145
|
+
const resolvedDropdownSearchPlaceholder =
|
|
146
|
+
dropdownSearchPlaceholder ?? t('searchPlaceholder')
|
|
147
|
+
const resolvedSelectAllLabel = selectAllLabel ?? t('selectAllLabel')
|
|
148
|
+
|
|
86
149
|
const { disabled, name } = fieldProps
|
|
87
150
|
|
|
88
151
|
const id = useMemo(() => fieldProps.id ?? uuidv4(), [fieldProps.id])
|
|
89
152
|
const selectedValueId = useMemo(() => `rc-ses-select-single-value-${id}`, [id])
|
|
90
153
|
|
|
91
154
|
const {
|
|
92
|
-
field: { onChange, value },
|
|
155
|
+
field: { onChange: rawOnChange, value: rawValue },
|
|
93
156
|
} = useController({
|
|
94
157
|
control,
|
|
95
158
|
name,
|
|
@@ -98,17 +161,25 @@ function RcSesSelect(props: Props) {
|
|
|
98
161
|
...slotProps?.controller,
|
|
99
162
|
})
|
|
100
163
|
|
|
164
|
+
const value = rawValue as string | string[] | null | undefined
|
|
165
|
+
const onChange = rawOnChange as (next: string | string[] | null) => void
|
|
166
|
+
|
|
101
167
|
const hasError = !!errors
|
|
102
|
-
const
|
|
168
|
+
const groupBy = slotProps?.field?.groupBy
|
|
169
|
+
const hasCustomGroupBy = typeof groupBy === 'function'
|
|
170
|
+
|
|
171
|
+
const selectedValueSet = useMemo(
|
|
172
|
+
() => new Set(Array.isArray(value) ? value : []),
|
|
173
|
+
[value],
|
|
174
|
+
)
|
|
103
175
|
|
|
104
176
|
const resolvedValue = useMemo(() => {
|
|
105
177
|
if (multiple) {
|
|
106
|
-
|
|
107
|
-
return options.filter((o) => value.includes(o.value))
|
|
178
|
+
return options.filter((o) => selectedValueSet.has(o.value))
|
|
108
179
|
}
|
|
109
180
|
|
|
110
181
|
return options.find((o) => o.value === value) ?? null
|
|
111
|
-
}, [value, options, multiple])
|
|
182
|
+
}, [value, options, multiple, selectedValueSet])
|
|
112
183
|
|
|
113
184
|
const selectedSingleLabel =
|
|
114
185
|
!multiple && resolvedValue && !Array.isArray(resolvedValue) ? resolvedValue.label : ''
|
|
@@ -123,75 +194,174 @@ function RcSesSelect(props: Props) {
|
|
|
123
194
|
|
|
124
195
|
const [inputValue, setInputValue] = React.useState('')
|
|
125
196
|
const resolvedInputValue = dropdownSearch ? '' : inputValue
|
|
197
|
+
const searchText = dropdownSearch ? dropdownSearchValue : inputValue
|
|
126
198
|
|
|
127
|
-
const
|
|
128
|
-
() => ({ label:
|
|
129
|
-
[
|
|
199
|
+
const selectAllOption = useMemo<Option>(
|
|
200
|
+
() => ({ label: resolvedSelectAllLabel, value: dropdownSelectAllValue }),
|
|
201
|
+
[resolvedSelectAllLabel],
|
|
130
202
|
)
|
|
131
203
|
|
|
132
|
-
const
|
|
133
|
-
() => (dropdownSearch && !hasCustomGroupBy ? [searchRowOption, ...options] : options),
|
|
134
|
-
[dropdownSearch, hasCustomGroupBy, options, searchRowOption],
|
|
135
|
-
)
|
|
204
|
+
const labelFilteredOptions = useFilteredOptions(options, searchText)
|
|
136
205
|
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
selected: AutocompleteValue<Option, typeof multiple>,
|
|
140
|
-
) => {
|
|
141
|
-
if (multiple) {
|
|
142
|
-
const values = (selected as Option[])
|
|
143
|
-
.filter((item) => item.value !== dropdownSearchOptionValue)
|
|
144
|
-
.map((item) => item.value)
|
|
206
|
+
const filteredOptions = useMemo(() => {
|
|
207
|
+
if (!groupBy) return labelFilteredOptions
|
|
145
208
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const val = selected as Option | null
|
|
149
|
-
if (val?.value === dropdownSearchOptionValue) return
|
|
150
|
-
onChange(val?.value ?? null)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
209
|
+
const normalized = searchText.trim().toLowerCase()
|
|
210
|
+
if (!normalized) return labelFilteredOptions
|
|
153
211
|
|
|
154
|
-
|
|
155
|
-
options
|
|
156
|
-
|
|
157
|
-
|
|
212
|
+
const matchedValues = new Set(labelFilteredOptions.map((o) => o.value))
|
|
213
|
+
options.forEach((option) => {
|
|
214
|
+
if (groupBy(option).toLowerCase().includes(normalized)) {
|
|
215
|
+
matchedValues.add(option.value)
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
return options.filter((option) => matchedValues.has(option.value))
|
|
220
|
+
}, [groupBy, labelFilteredOptions, options, searchText])
|
|
221
|
+
|
|
222
|
+
const filteredOptionsByGroup = useMemo(() => {
|
|
223
|
+
const map = new Map<string, Option[]>()
|
|
224
|
+
filteredOptions.forEach((option) => {
|
|
225
|
+
const group = groupBy?.(option) ?? ''
|
|
226
|
+
const items = map.get(group) ?? []
|
|
227
|
+
items.push(option)
|
|
228
|
+
map.set(group, items)
|
|
229
|
+
})
|
|
230
|
+
return map
|
|
231
|
+
}, [filteredOptions, groupBy])
|
|
232
|
+
|
|
233
|
+
const groupCounts = useMemo(() => {
|
|
234
|
+
const counts = new Map<string, number>()
|
|
235
|
+
filteredOptionsByGroup.forEach((items, group) => {
|
|
236
|
+
counts.set(group, items.length)
|
|
237
|
+
})
|
|
238
|
+
return counts
|
|
239
|
+
}, [filteredOptionsByGroup])
|
|
158
240
|
|
|
159
241
|
const selectedValues = Array.isArray(value) ? value : []
|
|
242
|
+
|
|
243
|
+
// A group header doubles as a "select all in this group" checkbox: it's
|
|
244
|
+
// checked exactly when every one of its items is selected, and toggling it
|
|
245
|
+
// selects/deselects every item in the group together - so unchecking any
|
|
246
|
+
// single item also un-checks the group, with no separate state to track.
|
|
247
|
+
const isGroupFullySelected = (groupValue: string) => {
|
|
248
|
+
const memberValues = filteredOptionsByGroup.get(groupValue) ?? []
|
|
249
|
+
return (
|
|
250
|
+
memberValues.length > 0 && memberValues.every((o) => selectedValueSet.has(o.value))
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const toggleGroupValue = (groupValue: string) => {
|
|
255
|
+
const memberValues = (filteredOptionsByGroup.get(groupValue) ?? []).map(
|
|
256
|
+
(o) => o.value,
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
const next = isGroupFullySelected(groupValue)
|
|
260
|
+
? selectedValues.filter((v) => !memberValues.includes(v))
|
|
261
|
+
: Array.from(new Set([...selectedValues, ...memberValues]))
|
|
262
|
+
|
|
263
|
+
onChange(next)
|
|
264
|
+
}
|
|
265
|
+
|
|
160
266
|
const { allSelected: allFilteredSelected, toggle: handleSelectAll } = useSelectAll(
|
|
161
267
|
filteredOptions,
|
|
162
268
|
selectedValues,
|
|
163
269
|
onChange,
|
|
164
270
|
)
|
|
165
271
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
272
|
+
// Multi-select group headers are rendered as their own selectable option
|
|
273
|
+
// (see the isGroupOptionValue branch in renderOption) instead of living
|
|
274
|
+
// outside the listbox as a separate Tab-only element - that's what lets
|
|
275
|
+
// the header fully participate in the listbox's native keyboard
|
|
276
|
+
// navigation (arrows, Enter) and pick up the same focus ring as every
|
|
277
|
+
// other row, both of which a plain non-option DOM node can't get for free
|
|
278
|
+
// since MUI's Autocomplete manages highlighting via aria-activedescendant
|
|
279
|
+
// on the input, not real per-item DOM focus.
|
|
280
|
+
const optionsWithGroupMarkers = useMemo(() => {
|
|
281
|
+
if (!(multiple && groupBy)) return options
|
|
282
|
+
|
|
283
|
+
const seenGroups = new Set<string>()
|
|
284
|
+
const result: Option[] = []
|
|
285
|
+
options.forEach((option) => {
|
|
286
|
+
const group = groupBy(option)
|
|
287
|
+
if (group && !seenGroups.has(group)) {
|
|
288
|
+
seenGroups.add(group)
|
|
289
|
+
result.push({ label: group, value: dropdownGroupOptionValue(group) })
|
|
290
|
+
}
|
|
291
|
+
result.push(option)
|
|
292
|
+
})
|
|
293
|
+
return result
|
|
294
|
+
}, [multiple, groupBy, options])
|
|
295
|
+
|
|
296
|
+
const resolvedOptions = useMemo(() => {
|
|
297
|
+
if (!dropdownSearch) return optionsWithGroupMarkers
|
|
298
|
+
|
|
299
|
+
const rows: Option[] = [dropdownSearchFieldOption]
|
|
300
|
+
if (multiple && selectAll) rows.push(selectAllOption)
|
|
301
|
+
return [...rows, ...optionsWithGroupMarkers]
|
|
302
|
+
}, [dropdownSearch, multiple, selectAll, optionsWithGroupMarkers, selectAllOption])
|
|
303
|
+
|
|
304
|
+
const handleChange = (_: React.SyntheticEvent, selected: Option | Option[] | null) => {
|
|
305
|
+
if (Array.isArray(selected)) {
|
|
306
|
+
const groupItem = selected.find((item) => isGroupOptionValue(item.value))
|
|
307
|
+
if (groupItem) {
|
|
308
|
+
toggleGroupValue(groupNameFromOptionValue(groupItem.value))
|
|
309
|
+
return
|
|
310
|
+
}
|
|
170
311
|
|
|
171
|
-
|
|
172
|
-
|
|
312
|
+
if (selected.some((item) => item.value === dropdownSelectAllValue)) {
|
|
313
|
+
handleSelectAll()
|
|
314
|
+
return
|
|
315
|
+
}
|
|
173
316
|
|
|
174
|
-
|
|
317
|
+
const values = selected
|
|
318
|
+
.filter((item) => !isInternalOptionValue(item.value))
|
|
319
|
+
.map((item) => item.value)
|
|
320
|
+
|
|
321
|
+
onChange(values)
|
|
322
|
+
} else {
|
|
323
|
+
if (selected && isInternalOptionValue(selected.value)) return
|
|
324
|
+
onChange(selected?.value ?? null)
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const filterOptions = (opts: Option[]) => {
|
|
329
|
+
const filteredValues = new Set(filteredOptions.map((o) => o.value))
|
|
330
|
+
const isVisibleAfterFilter = (opt: Option) => {
|
|
331
|
+
if (isGroupOptionValue(opt.value)) {
|
|
332
|
+
const groupValue = groupNameFromOptionValue(opt.value)
|
|
333
|
+
return (filteredOptionsByGroup.get(groupValue)?.length ?? 0) > 0
|
|
334
|
+
}
|
|
335
|
+
return filteredValues.has(opt.value)
|
|
175
336
|
}
|
|
176
337
|
|
|
177
|
-
if (dropdownSearch
|
|
338
|
+
if (dropdownSearch) {
|
|
339
|
+
if (!dropdownSearchValue.trim()) return opts
|
|
178
340
|
|
|
179
|
-
|
|
341
|
+
return opts.filter((opt) => {
|
|
342
|
+
// Search field / select-all rows always stay visible; group markers
|
|
343
|
+
// are conditionally visible (only when the group still has filtered
|
|
344
|
+
// members) via isVisibleAfterFilter below - isInternalOptionValue
|
|
345
|
+
// covers both cases, so it can't be used as a blanket always-show.
|
|
346
|
+
if (
|
|
347
|
+
opt.value === dropdownSearchFieldValue ||
|
|
348
|
+
opt.value === dropdownSelectAllValue
|
|
349
|
+
) {
|
|
350
|
+
return true
|
|
351
|
+
}
|
|
352
|
+
return isVisibleAfterFilter(opt)
|
|
353
|
+
})
|
|
354
|
+
}
|
|
180
355
|
|
|
181
|
-
|
|
182
|
-
return opts.filter((opt) => filteredValues.has(opt.value))
|
|
183
|
-
}
|
|
356
|
+
if (!inputValue.trim() || inputValue === selectedSingleLabel) return opts
|
|
184
357
|
|
|
185
|
-
|
|
186
|
-
setOpen(false)
|
|
187
|
-
setDropdownSearchValue('')
|
|
358
|
+
return opts.filter((opt) => isVisibleAfterFilter(opt))
|
|
188
359
|
}
|
|
189
360
|
|
|
190
|
-
|
|
191
|
-
const closeDropdownWithClear = () => {
|
|
361
|
+
const closeDropdown = ({ clearInput = false } = {}) => {
|
|
192
362
|
setOpen(false)
|
|
193
363
|
setDropdownSearchValue('')
|
|
194
|
-
setInputValue('')
|
|
364
|
+
if (clearInput) setInputValue('')
|
|
195
365
|
}
|
|
196
366
|
|
|
197
367
|
const shouldKeepDropdownOpen = () => {
|
|
@@ -209,6 +379,7 @@ function RcSesSelect(props: Props) {
|
|
|
209
379
|
}
|
|
210
380
|
})
|
|
211
381
|
}
|
|
382
|
+
|
|
212
383
|
return (
|
|
213
384
|
<RcSesFormControlWrapper
|
|
214
385
|
id={id}
|
|
@@ -234,6 +405,7 @@ function RcSesSelect(props: Props) {
|
|
|
234
405
|
clearOnBlur={false}
|
|
235
406
|
handleHomeEndKeys={false}
|
|
236
407
|
loading={loading}
|
|
408
|
+
popupIcon={<CaretDownIcon size={20} fillColor={palette.grey['600']} />}
|
|
237
409
|
value={resolvedValue}
|
|
238
410
|
inputValue={resolvedInputValue}
|
|
239
411
|
onChange={handleChange}
|
|
@@ -247,33 +419,41 @@ function RcSesSelect(props: Props) {
|
|
|
247
419
|
deferCloseCheck()
|
|
248
420
|
return
|
|
249
421
|
}
|
|
250
|
-
|
|
422
|
+
closeDropdown({ clearInput: true })
|
|
251
423
|
}}
|
|
252
424
|
isOptionEqualToValue={(option, val) => option.value === val.value}
|
|
253
425
|
getOptionLabel={(option) => option.label}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
renderGroup={(params) => (
|
|
257
|
-
<React.Fragment key={params.key}>
|
|
258
|
-
{!!params.group && (
|
|
259
|
-
<Box className='MuiAutocomplete-groupLabel'>{params.group}</Box>
|
|
260
|
-
)}
|
|
261
|
-
|
|
262
|
-
{!params.group && !!dropdownLabel && (
|
|
263
|
-
<Box
|
|
264
|
-
sx={{
|
|
265
|
-
padding: '1.1875rem 1.125rem .8125rem 1.125rem',
|
|
266
|
-
fontSize: '.9375rem',
|
|
267
|
-
color: palette.grey[600],
|
|
268
|
-
}}
|
|
269
|
-
>
|
|
270
|
-
{dropdownLabel}
|
|
271
|
-
</Box>
|
|
272
|
-
)}
|
|
426
|
+
renderGroup={(params) => {
|
|
427
|
+
const groupValue = params.group
|
|
273
428
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
429
|
+
return (
|
|
430
|
+
<React.Fragment key={params.key}>
|
|
431
|
+
{/* For multi-select this plain header is skipped: the group's
|
|
432
|
+
own selectable row (rendered by renderOption's
|
|
433
|
+
isGroupOptionValue branch, injected as the first item of
|
|
434
|
+
each group) supplies the header visual instead, so it can
|
|
435
|
+
fully participate in the listbox's native keyboard nav. */}
|
|
436
|
+
{!multiple && !!groupValue && (
|
|
437
|
+
<Box
|
|
438
|
+
className='MuiAutocomplete-groupLabel'
|
|
439
|
+
sx={{ alignItems: 'center', display: 'flex', gap: '.5rem' }}
|
|
440
|
+
>
|
|
441
|
+
{groupValue}
|
|
442
|
+
{groupCounts.has(groupValue) && (
|
|
443
|
+
<RcSesBadge
|
|
444
|
+
label={String(groupCounts.get(groupValue))}
|
|
445
|
+
variant='neutral'
|
|
446
|
+
size='small'
|
|
447
|
+
showIcon={false}
|
|
448
|
+
/>
|
|
449
|
+
)}
|
|
450
|
+
</Box>
|
|
451
|
+
)}
|
|
452
|
+
|
|
453
|
+
{params.children}
|
|
454
|
+
</React.Fragment>
|
|
455
|
+
)
|
|
456
|
+
}}
|
|
277
457
|
renderInput={(params) => (
|
|
278
458
|
<TextField
|
|
279
459
|
{...params}
|
|
@@ -310,8 +490,6 @@ function RcSesSelect(props: Props) {
|
|
|
310
490
|
}),
|
|
311
491
|
}}
|
|
312
492
|
slotProps={{
|
|
313
|
-
// Spreading params.slotProps keeps `input`, which carries the ref
|
|
314
|
-
// and classes Autocomplete relies on.
|
|
315
493
|
...params.slotProps,
|
|
316
494
|
input: {
|
|
317
495
|
...params.slotProps.input,
|
|
@@ -338,14 +516,15 @@ function RcSesSelect(props: Props) {
|
|
|
338
516
|
/>
|
|
339
517
|
)}
|
|
340
518
|
renderOption={(optionProps, option, { selected }) => {
|
|
341
|
-
const { key, ...rest } = optionProps
|
|
519
|
+
const { key, className, ...rest } = optionProps
|
|
342
520
|
|
|
343
|
-
if (option.value ===
|
|
521
|
+
if (option.value === dropdownSearchFieldValue) {
|
|
344
522
|
return (
|
|
345
523
|
<Box
|
|
346
524
|
key={key}
|
|
347
525
|
component='li'
|
|
348
526
|
{...rest}
|
|
527
|
+
className={className}
|
|
349
528
|
onMouseDown={(event: React.MouseEvent) => {
|
|
350
529
|
event.preventDefault()
|
|
351
530
|
}}
|
|
@@ -354,50 +533,17 @@ function RcSesSelect(props: Props) {
|
|
|
354
533
|
}}
|
|
355
534
|
sx={{
|
|
356
535
|
'&:hover': { backgroundColor: 'transparent !important' },
|
|
357
|
-
alignItems: 'center',
|
|
358
|
-
borderBottom: `1px solid ${palette.grey['200']}`,
|
|
359
536
|
display: 'flex',
|
|
360
537
|
flexDirection: 'row !important',
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
pb: '.5rem',
|
|
364
|
-
pt: 0,
|
|
365
|
-
px: '.75rem',
|
|
538
|
+
px: '1rem',
|
|
539
|
+
py: '.5rem',
|
|
366
540
|
}}
|
|
367
541
|
>
|
|
368
|
-
{multiple && selectAll && (
|
|
369
|
-
<Checkbox
|
|
370
|
-
checked={allFilteredSelected}
|
|
371
|
-
checkedIcon={
|
|
372
|
-
<CheckBoldIcon fillColor={palette.primary.main} size={24} />
|
|
373
|
-
}
|
|
374
|
-
icon={
|
|
375
|
-
<CheckUncheckedBoldIcon fillColor={palette.grey['500']} size={24} />
|
|
376
|
-
}
|
|
377
|
-
disableRipple
|
|
378
|
-
onMouseDown={(e) => {
|
|
379
|
-
e.preventDefault()
|
|
380
|
-
e.stopPropagation()
|
|
381
|
-
}}
|
|
382
|
-
onClick={(e) => {
|
|
383
|
-
e.stopPropagation()
|
|
384
|
-
handleSelectAll()
|
|
385
|
-
}}
|
|
386
|
-
sx={{
|
|
387
|
-
flexShrink: 0,
|
|
388
|
-
alignSelf: 'center',
|
|
389
|
-
height: '1.5rem',
|
|
390
|
-
m: 0,
|
|
391
|
-
p: 0,
|
|
392
|
-
width: '1.5rem',
|
|
393
|
-
}}
|
|
394
|
-
/>
|
|
395
|
-
)}
|
|
396
542
|
<TextField
|
|
397
543
|
fullWidth
|
|
398
544
|
value={dropdownSearchValue}
|
|
399
545
|
onChange={(event) => setDropdownSearchValue(event.target.value)}
|
|
400
|
-
placeholder={
|
|
546
|
+
placeholder={resolvedDropdownSearchPlaceholder}
|
|
401
547
|
size='small'
|
|
402
548
|
onMouseDown={(e) => {
|
|
403
549
|
e.stopPropagation()
|
|
@@ -413,26 +559,18 @@ function RcSesSelect(props: Props) {
|
|
|
413
559
|
event.stopPropagation()
|
|
414
560
|
}}
|
|
415
561
|
sx={{
|
|
562
|
+
'& .MuiOutlinedInput-notchedOutline': {
|
|
563
|
+
borderColor: palette.grey['200'],
|
|
564
|
+
},
|
|
565
|
+
'& .MuiInputBase-input': {
|
|
566
|
+
padding: '.625rem .75rem',
|
|
567
|
+
},
|
|
416
568
|
'& .MuiInputBase-input::placeholder': {
|
|
417
569
|
color: palette.grey.main,
|
|
418
570
|
opacity: 1,
|
|
419
571
|
},
|
|
420
572
|
}}
|
|
421
573
|
slotProps={{
|
|
422
|
-
input: {
|
|
423
|
-
startAdornment: (
|
|
424
|
-
<Box sx={{ display: 'flex', m: '.625rem' }}>
|
|
425
|
-
<MagnifyingGlassIcon
|
|
426
|
-
size={20}
|
|
427
|
-
fillColor={palette.grey['900']}
|
|
428
|
-
/>
|
|
429
|
-
</Box>
|
|
430
|
-
),
|
|
431
|
-
},
|
|
432
|
-
// Keeps typing in the dropdown's search box from reaching
|
|
433
|
-
// Autocomplete's own keyboard navigation. The parameter needs
|
|
434
|
-
// annotating: inside slotProps it no longer gets a contextual
|
|
435
|
-
// type the way it did on InputProps.
|
|
436
574
|
htmlInput: {
|
|
437
575
|
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) =>
|
|
438
576
|
event.stopPropagation(),
|
|
@@ -443,44 +581,112 @@ function RcSesSelect(props: Props) {
|
|
|
443
581
|
)
|
|
444
582
|
}
|
|
445
583
|
|
|
584
|
+
if (option.value === dropdownSelectAllValue) {
|
|
585
|
+
return (
|
|
586
|
+
<Box
|
|
587
|
+
key={key}
|
|
588
|
+
component='li'
|
|
589
|
+
{...rest}
|
|
590
|
+
aria-selected={allFilteredSelected}
|
|
591
|
+
className={className}
|
|
592
|
+
onMouseDown={(event: React.MouseEvent) => {
|
|
593
|
+
event.preventDefault()
|
|
594
|
+
}}
|
|
595
|
+
onClick={(event: React.MouseEvent) => {
|
|
596
|
+
event.stopPropagation()
|
|
597
|
+
handleSelectAll()
|
|
598
|
+
}}
|
|
599
|
+
sx={{
|
|
600
|
+
display: 'flex',
|
|
601
|
+
flexDirection: 'row !important',
|
|
602
|
+
gap: '.75rem',
|
|
603
|
+
}}
|
|
604
|
+
>
|
|
605
|
+
<OptionCheckbox checked={allFilteredSelected} />
|
|
606
|
+
<span className='rc-ses-select-option-label'>
|
|
607
|
+
{resolvedSelectAllLabel}
|
|
608
|
+
</span>
|
|
609
|
+
</Box>
|
|
610
|
+
)
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
if (isGroupOptionValue(option.value)) {
|
|
614
|
+
const groupValue = groupNameFromOptionValue(option.value)
|
|
615
|
+
const isGroupSelected = isGroupFullySelected(groupValue)
|
|
616
|
+
|
|
617
|
+
return (
|
|
618
|
+
<Box
|
|
619
|
+
key={key}
|
|
620
|
+
component='li'
|
|
621
|
+
{...rest}
|
|
622
|
+
aria-selected={isGroupSelected}
|
|
623
|
+
className={className}
|
|
624
|
+
onMouseDown={(event: React.MouseEvent) => {
|
|
625
|
+
event.preventDefault()
|
|
626
|
+
}}
|
|
627
|
+
onClick={(event: React.MouseEvent) => {
|
|
628
|
+
event.stopPropagation()
|
|
629
|
+
toggleGroupValue(groupValue)
|
|
630
|
+
}}
|
|
631
|
+
sx={{
|
|
632
|
+
alignItems: 'center',
|
|
633
|
+
backgroundColor: isGroupSelected
|
|
634
|
+
? palette.primary['50']
|
|
635
|
+
: 'transparent',
|
|
636
|
+
display: 'flex',
|
|
637
|
+
flexDirection: 'row !important',
|
|
638
|
+
gap: '.5rem',
|
|
639
|
+
}}
|
|
640
|
+
>
|
|
641
|
+
<OptionCheckbox checked={isGroupSelected} />
|
|
642
|
+
<Box
|
|
643
|
+
component='span'
|
|
644
|
+
sx={{
|
|
645
|
+
color: isGroupSelected ? palette.primary['700'] : palette.grey['900'],
|
|
646
|
+
flex: 1,
|
|
647
|
+
fontFamily: '"Public Sans", sans-serif',
|
|
648
|
+
fontSize: '.875rem',
|
|
649
|
+
fontWeight: 600,
|
|
650
|
+
lineHeight: '1.25rem',
|
|
651
|
+
overflowWrap: 'anywhere',
|
|
652
|
+
}}
|
|
653
|
+
>
|
|
654
|
+
{groupValue}
|
|
655
|
+
</Box>
|
|
656
|
+
{groupCounts.has(groupValue) && (
|
|
657
|
+
<RcSesBadge
|
|
658
|
+
label={String(groupCounts.get(groupValue))}
|
|
659
|
+
variant='neutral'
|
|
660
|
+
size='small'
|
|
661
|
+
showIcon={false}
|
|
662
|
+
/>
|
|
663
|
+
)}
|
|
664
|
+
</Box>
|
|
665
|
+
)
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
let indentClassName = ''
|
|
669
|
+
if (hasCustomGroupBy) {
|
|
670
|
+
indentClassName = multiple
|
|
671
|
+
? 'rc-ses-select-option--indent-multi'
|
|
672
|
+
: 'rc-ses-select-option--indent-single'
|
|
673
|
+
}
|
|
674
|
+
|
|
446
675
|
return (
|
|
447
676
|
<Box
|
|
448
677
|
key={key}
|
|
449
678
|
component='li'
|
|
450
679
|
{...rest}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
},
|
|
460
|
-
...(Array.isArray(rest.sx) ? rest.sx : [rest.sx]),
|
|
461
|
-
]}
|
|
680
|
+
className={[className, indentClassName].filter(Boolean).join(' ')}
|
|
681
|
+
sx={{
|
|
682
|
+
display: 'flex',
|
|
683
|
+
gap: multiple ? '.75rem' : '.5rem',
|
|
684
|
+
flexDirection: 'row !important',
|
|
685
|
+
justifyContent: 'space-between',
|
|
686
|
+
minWidth: 0,
|
|
687
|
+
}}
|
|
462
688
|
>
|
|
463
|
-
{multiple &&
|
|
464
|
-
<Checkbox
|
|
465
|
-
checked={selected}
|
|
466
|
-
checkedIcon={
|
|
467
|
-
<CheckBoldIcon fillColor={palette.primary.main} size={24} />
|
|
468
|
-
}
|
|
469
|
-
icon={
|
|
470
|
-
<CheckUncheckedBoldIcon fillColor={palette.grey['500']} size={24} />
|
|
471
|
-
}
|
|
472
|
-
tabIndex={-1}
|
|
473
|
-
disableRipple
|
|
474
|
-
sx={{
|
|
475
|
-
alignSelf: 'center',
|
|
476
|
-
height: '1.5rem',
|
|
477
|
-
m: 0,
|
|
478
|
-
p: 0,
|
|
479
|
-
pointerEvents: 'none',
|
|
480
|
-
width: '1.5rem',
|
|
481
|
-
}}
|
|
482
|
-
/>
|
|
483
|
-
)}
|
|
689
|
+
{multiple && <OptionCheckbox checked={selected} />}
|
|
484
690
|
<Box
|
|
485
691
|
sx={{
|
|
486
692
|
flex: 1,
|
|
@@ -495,7 +701,12 @@ function RcSesSelect(props: Props) {
|
|
|
495
701
|
: {}),
|
|
496
702
|
}}
|
|
497
703
|
>
|
|
498
|
-
<span
|
|
704
|
+
<span
|
|
705
|
+
className='rc-ses-select-option-label'
|
|
706
|
+
style={selected ? { color: palette.primary['700'] } : undefined}
|
|
707
|
+
>
|
|
708
|
+
{option.label}
|
|
709
|
+
</span>
|
|
499
710
|
|
|
500
711
|
{option.description && (
|
|
501
712
|
<span className='rc-ses-select-option-description'>
|
|
@@ -505,7 +716,7 @@ function RcSesSelect(props: Props) {
|
|
|
505
716
|
</Box>
|
|
506
717
|
{!multiple && selected && (
|
|
507
718
|
<CheckIcon
|
|
508
|
-
size={
|
|
719
|
+
size={20}
|
|
509
720
|
fillColor={palette.primary.main}
|
|
510
721
|
aria-hidden
|
|
511
722
|
weight='bold'
|
|
@@ -565,11 +776,45 @@ function RcSesSelect(props: Props) {
|
|
|
565
776
|
)
|
|
566
777
|
}}
|
|
567
778
|
{...slotProps?.field}
|
|
779
|
+
groupBy={(option) => {
|
|
780
|
+
if (isGroupOptionValue(option.value)) {
|
|
781
|
+
return groupNameFromOptionValue(option.value)
|
|
782
|
+
}
|
|
783
|
+
if (isInternalOptionValue(option.value)) return ''
|
|
784
|
+
return groupBy ? groupBy(option) : ''
|
|
785
|
+
}}
|
|
786
|
+
slots={{
|
|
787
|
+
...slotProps?.field?.slots,
|
|
788
|
+
paper: DropdownPaper,
|
|
789
|
+
}}
|
|
568
790
|
slotProps={{
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
791
|
+
...slotProps?.field?.slotProps,
|
|
792
|
+
paper: (ownerState) => {
|
|
793
|
+
const consumerPaperSlotProps = slotProps?.field?.slotProps?.paper
|
|
794
|
+
const resolved =
|
|
795
|
+
typeof consumerPaperSlotProps === 'function'
|
|
796
|
+
? consumerPaperSlotProps(ownerState)
|
|
797
|
+
: consumerPaperSlotProps
|
|
798
|
+
|
|
799
|
+
return {
|
|
800
|
+
...resolved,
|
|
801
|
+
dropdownLabel,
|
|
802
|
+
}
|
|
803
|
+
},
|
|
804
|
+
listbox: (ownerState) => {
|
|
805
|
+
const consumerListboxSlotProps = slotProps?.field?.slotProps?.listbox
|
|
806
|
+
const resolved =
|
|
807
|
+
typeof consumerListboxSlotProps === 'function'
|
|
808
|
+
? consumerListboxSlotProps(ownerState)
|
|
809
|
+
: consumerListboxSlotProps
|
|
810
|
+
|
|
811
|
+
return {
|
|
812
|
+
...resolved,
|
|
813
|
+
onMouseDown: (e: React.MouseEvent<HTMLUListElement>) => {
|
|
814
|
+
resolved?.onMouseDown?.(e)
|
|
815
|
+
e.preventDefault()
|
|
816
|
+
},
|
|
817
|
+
}
|
|
573
818
|
},
|
|
574
819
|
}}
|
|
575
820
|
/>
|