@registrucentras/rc-ses-react-components 1.6.4 → 1.6.6
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/assets/IconProps.d.ts +2 -0
- package/dist/assets/icons/ArrowsClockwiseIcon.d.ts +3 -0
- package/dist/assets/icons/CheckIcon.d.ts +3 -0
- package/dist/assets/icons/PencilSimpleLineIcon.d.ts +3 -0
- package/dist/components/common/Card/index.d.ts +4 -1
- package/dist/components/form/inputs/SearchInput/index.d.ts +27 -0
- package/dist/components/form/inputs/Select/Select.types.d.ts +5 -0
- package/dist/components/form/inputs/Select/hooks/useFilteredOptions.d.ts +3 -0
- package/dist/components/form/inputs/Select/hooks/useSelectAllLogic.d.ts +7 -0
- package/dist/components/form/inputs/{Select.d.ts → Select/index.d.ts} +12 -12
- package/dist/library/icons.d.ts +3 -1
- package/dist/library/index.d.ts +2 -0
- package/dist/registrucentras-rc-ses-react-components.cjs +11 -11
- package/dist/registrucentras-rc-ses-react-components.js +3346 -2752
- package/dist/stories/components/display/Card.stories.d.ts +6 -47
- package/dist/stories/components/display/ImageCard.stories.d.ts +6 -6
- package/dist/stories/components/feedback/Alert.stories.d.ts +7 -16
- package/dist/stories/components/form/CardFormContainer.stories.d.ts +5 -5
- package/dist/stories/components/form/CheckboxFormControl.stories.d.ts +3 -23
- package/dist/stories/components/form/ServiceFormActions.stories.d.ts +3 -9
- package/dist/stories/components/icons/Icons.stories.d.ts +3 -2
- package/dist/stories/components/inputs/FileDropzone.stories.d.ts +3 -29
- package/dist/stories/components/inputs/NumberStepper.stories.d.ts +3 -31
- package/dist/stories/components/inputs/RadioButtonGroup.stories.d.ts +4 -32
- package/dist/stories/components/inputs/SearchInput.stories.d.ts +11 -0
- package/dist/stories/components/inputs/SearchableField.stories.d.ts +3 -332
- package/dist/stories/components/inputs/Select.stories.d.ts +4 -871
- package/dist/stories/components/inputs/TextField.stories.d.ts +3 -610
- package/dist/stories/components/layout/Footer.stories.d.ts +3 -5
- package/dist/stories/components/navigation/Breadcrumbs.stories.d.ts +4 -6
- package/dist/stories/components/navigation/ServiceWizardStepper.stories.d.ts +5 -5
- package/dist/theme/light/MuiOutlinedInput.d.ts +3 -0
- package/package.json +1 -1
- package/src/assets/IconProps.ts +2 -0
- package/src/assets/icons/ArrowsClockwiseIcon.tsx +16 -0
- package/src/assets/icons/CheckIcon.tsx +23 -0
- package/src/assets/icons/PencilSimpleLineIcon.tsx +17 -0
- package/src/components/common/Card/index.test.tsx +8 -0
- package/src/components/common/Card/index.tsx +64 -25
- package/src/components/common/SelectableCardList/index.tsx +2 -1
- package/src/components/form/components/FormControlWrapper/index.tsx +6 -1
- package/src/components/form/inputs/PhoneInputFormControl/index.tsx +11 -3
- package/src/components/form/inputs/SearchInput/index.test.tsx +203 -0
- package/src/components/form/inputs/SearchInput/index.tsx +282 -0
- package/src/components/form/inputs/Select/Select.types.ts +5 -0
- package/src/components/form/inputs/Select/hooks/useFilteredOptions.ts +18 -0
- package/src/components/form/inputs/Select/hooks/useSelectAllLogic.ts +22 -0
- package/src/components/form/inputs/Select/index.tsx +494 -0
- package/src/i18n/namespaces/input/en.json +5 -0
- package/src/i18n/namespaces/input/lt.json +5 -0
- package/src/library/icons.ts +4 -0
- package/src/library/index.ts +2 -0
- package/src/stories/components/display/Card.stories.tsx +64 -47
- package/src/stories/components/display/ImageCard.stories.tsx +29 -27
- package/src/stories/components/feedback/Alert.stories.tsx +59 -50
- package/src/stories/components/form/CardFormContainer.stories.tsx +77 -63
- package/src/stories/components/form/CheckboxFormControl.stories.tsx +29 -71
- package/src/stories/components/form/ServiceFormActions.stories.tsx +18 -21
- package/src/stories/components/form/ServiceFormContainer.stories.tsx +1 -1
- package/src/stories/components/icons/Icons.stories.tsx +6 -2
- package/src/stories/components/inputs/FileDropzone.stories.tsx +17 -34
- package/src/stories/components/inputs/NumberStepper.stories.tsx +32 -60
- package/src/stories/components/inputs/RadioButtonGroup.stories.tsx +22 -20
- package/src/stories/components/inputs/SearchInput.stories.tsx +134 -0
- package/src/stories/components/inputs/SearchableField.stories.tsx +16 -14
- package/src/stories/components/inputs/Select.stories.tsx +245 -13
- package/src/stories/components/inputs/TextField.stories.tsx +47 -47
- package/src/stories/components/layout/Footer.stories.tsx +6 -6
- package/src/stories/components/navigation/Breadcrumbs.stories.tsx +6 -8
- package/src/stories/components/navigation/ServiceWizardStepper.stories.tsx +29 -22
- package/src/theme/light/MuiAutocomplete.ts +52 -3
- package/src/theme/light/MuiOutlinedInput.ts +15 -0
- package/src/theme/light/index.tsx +2 -0
- package/src/components/form/inputs/Select.tsx +0 -152
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { Box, IconButton, useMediaQuery, useTheme } from '@mui/material'
|
|
2
|
+
import InputAdornment from '@mui/material/InputAdornment'
|
|
3
|
+
import type { OutlinedTextFieldProps } from '@mui/material/TextField'
|
|
4
|
+
import TextField from '@mui/material/TextField'
|
|
5
|
+
import React, { useCallback, useMemo, useRef } from 'react'
|
|
6
|
+
import type { UseControllerProps } from 'react-hook-form'
|
|
7
|
+
import { useController } from 'react-hook-form'
|
|
8
|
+
import { useTranslation } from 'react-i18next'
|
|
9
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
10
|
+
|
|
11
|
+
import MagnifyingGlassIcon from '@/assets/icons/MagnifyingGlassIcon'
|
|
12
|
+
import XCircleFillIcon from '@/assets/icons/XCircleFillIcon'
|
|
13
|
+
import RcSesButton from '@/components/common/Button'
|
|
14
|
+
import RcSesFormControlWrapper, {
|
|
15
|
+
RcSesFormControlWrapperProps,
|
|
16
|
+
} from '@/components/form/components/FormControlWrapper'
|
|
17
|
+
import type { ButtonProps } from '@/types/buttons/ButtonProps'
|
|
18
|
+
|
|
19
|
+
type TControllerProps = UseControllerProps<any, any>
|
|
20
|
+
type ImmediateControllerProps = 'control' | 'rules' | 'disabled' | 'name'
|
|
21
|
+
|
|
22
|
+
type TFieldProps = Omit<OutlinedTextFieldProps, 'variant' | 'value' | 'defaultValue'>
|
|
23
|
+
|
|
24
|
+
type TWrapperProps = RcSesFormControlWrapperProps
|
|
25
|
+
type ImmediateWrapperProps = 'id' | 'label' | 'errors' | 'labelSubtitle'
|
|
26
|
+
type TSearchButtonProps = Partial<ButtonProps>
|
|
27
|
+
|
|
28
|
+
type Props = Pick<TControllerProps, ImmediateControllerProps> &
|
|
29
|
+
Pick<TWrapperProps, ImmediateWrapperProps> & {
|
|
30
|
+
onSearch: (value: string) => void
|
|
31
|
+
required?: boolean
|
|
32
|
+
onlyNumbers?: boolean
|
|
33
|
+
placeholder?: TFieldProps['placeholder']
|
|
34
|
+
sideLabel?: boolean
|
|
35
|
+
showSearchButton?: boolean
|
|
36
|
+
searchButtonLabel?: string
|
|
37
|
+
slotProps?: {
|
|
38
|
+
controller?: Partial<Omit<TControllerProps, ImmediateControllerProps>>
|
|
39
|
+
field?: Partial<TFieldProps>
|
|
40
|
+
searchButton?: TSearchButtonProps
|
|
41
|
+
wrapper?: Partial<Omit<TWrapperProps, ImmediateWrapperProps>>
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const RcSesSearchInput = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
|
|
46
|
+
const [hasSearchAttempted, setHasSearchAttempted] = React.useState(false)
|
|
47
|
+
const internalInputRef = useRef<HTMLInputElement>(null)
|
|
48
|
+
|
|
49
|
+
const setInputRef = useCallback(
|
|
50
|
+
(el: HTMLInputElement | null) => {
|
|
51
|
+
;(internalInputRef as React.MutableRefObject<HTMLInputElement | null>).current = el
|
|
52
|
+
if (typeof ref === 'function') {
|
|
53
|
+
ref(el)
|
|
54
|
+
} else if (ref) {
|
|
55
|
+
;(ref as React.MutableRefObject<HTMLInputElement | null>).current = el
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
[ref],
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const { t } = useTranslation('input', { keyPrefix: 'components.RcSesSearchInput' })
|
|
62
|
+
|
|
63
|
+
const {
|
|
64
|
+
control,
|
|
65
|
+
labelSubtitle,
|
|
66
|
+
errors,
|
|
67
|
+
label,
|
|
68
|
+
onSearch,
|
|
69
|
+
required,
|
|
70
|
+
onlyNumbers = false,
|
|
71
|
+
placeholder,
|
|
72
|
+
rules,
|
|
73
|
+
sideLabel = false,
|
|
74
|
+
showSearchButton = true,
|
|
75
|
+
searchButtonLabel,
|
|
76
|
+
slotProps,
|
|
77
|
+
disabled,
|
|
78
|
+
name,
|
|
79
|
+
id: providedId,
|
|
80
|
+
} = props
|
|
81
|
+
const {
|
|
82
|
+
InputProps: slotFieldInputProps,
|
|
83
|
+
inputProps: slotFieldNativeInputProps,
|
|
84
|
+
...restFieldProps
|
|
85
|
+
} = slotProps?.field ?? {}
|
|
86
|
+
const id = useMemo(() => providedId ?? uuidv4(), [providedId])
|
|
87
|
+
|
|
88
|
+
const hasRequiredRule = rules?.required !== undefined
|
|
89
|
+
const isRequired = hasRequiredRule ? !!rules?.required : required === true
|
|
90
|
+
const controllerRules =
|
|
91
|
+
hasRequiredRule || !isRequired ? rules : { ...(rules ?? {}), required: true }
|
|
92
|
+
|
|
93
|
+
const {
|
|
94
|
+
field: { onBlur, onChange, value },
|
|
95
|
+
} = useController({
|
|
96
|
+
control,
|
|
97
|
+
name,
|
|
98
|
+
rules: controllerRules,
|
|
99
|
+
disabled,
|
|
100
|
+
shouldUnregister: true,
|
|
101
|
+
...slotProps?.controller,
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
const currentTheme = useTheme()
|
|
105
|
+
const upMd = useMediaQuery(currentTheme.breakpoints.up('md'))
|
|
106
|
+
|
|
107
|
+
const mergedSearchButtonProps = slotProps?.searchButton ?? {}
|
|
108
|
+
|
|
109
|
+
const shouldRenderSearchButton = showSearchButton !== false && upMd
|
|
110
|
+
|
|
111
|
+
const mergedWrapperProps = {
|
|
112
|
+
...slotProps?.wrapper,
|
|
113
|
+
labelSubtitle,
|
|
114
|
+
hideLabel: slotProps?.wrapper?.hideLabel ?? !label,
|
|
115
|
+
labelOnTop: slotProps?.wrapper?.labelOnTop ?? !sideLabel,
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const shouldSearchOnEnter =
|
|
119
|
+
!shouldRenderSearchButton || !!mergedSearchButtonProps.disabled
|
|
120
|
+
|
|
121
|
+
const hasSearchValue = `${value ?? ''}`.trim().length > 0
|
|
122
|
+
const visibleErrors = hasSearchAttempted ? errors : undefined
|
|
123
|
+
|
|
124
|
+
const handleSearchClick: NonNullable<ButtonProps['onClick']> = (event) => {
|
|
125
|
+
setHasSearchAttempted(true)
|
|
126
|
+
mergedSearchButtonProps.onClick?.(event)
|
|
127
|
+
|
|
128
|
+
if (!event.defaultPrevented && hasSearchValue) {
|
|
129
|
+
onSearch(value ?? '')
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const handleFieldKeyDown: NonNullable<TFieldProps['onKeyDown']> = (event) => {
|
|
134
|
+
slotProps?.field?.onKeyDown?.(event)
|
|
135
|
+
|
|
136
|
+
if (!event.defaultPrevented && shouldSearchOnEnter && event.key === 'Enter') {
|
|
137
|
+
setHasSearchAttempted(true)
|
|
138
|
+
event.preventDefault()
|
|
139
|
+
|
|
140
|
+
if (hasSearchValue) {
|
|
141
|
+
onSearch(value ?? '')
|
|
142
|
+
} else {
|
|
143
|
+
onBlur()
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const handleFieldChange: NonNullable<TFieldProps['onChange']> = (event) => {
|
|
149
|
+
slotProps?.field?.onChange?.(event)
|
|
150
|
+
|
|
151
|
+
if (event.defaultPrevented) {
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const nextValue = event.target.value ?? ''
|
|
156
|
+
const parsedValue = onlyNumbers ? nextValue.replace(/\D+/g, '') : nextValue
|
|
157
|
+
|
|
158
|
+
onChange(parsedValue)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const mergedNativeInputProps: NonNullable<
|
|
162
|
+
NonNullable<TFieldProps['InputProps']>['inputProps']
|
|
163
|
+
> = {
|
|
164
|
+
...(slotFieldInputProps?.inputProps ?? {}),
|
|
165
|
+
...(slotFieldNativeInputProps ?? {}),
|
|
166
|
+
...(onlyNumbers
|
|
167
|
+
? {
|
|
168
|
+
inputMode: 'numeric',
|
|
169
|
+
pattern: '[0-9]*',
|
|
170
|
+
}
|
|
171
|
+
: {}),
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const mergedTextFieldInputProps: TFieldProps['InputProps'] = {
|
|
175
|
+
...slotFieldInputProps,
|
|
176
|
+
inputProps: mergedNativeInputProps,
|
|
177
|
+
startAdornment: (
|
|
178
|
+
<InputAdornment position='start' onClick={() => internalInputRef.current?.focus()}>
|
|
179
|
+
<Box
|
|
180
|
+
sx={{
|
|
181
|
+
alignItems: 'center',
|
|
182
|
+
cursor: 'text',
|
|
183
|
+
display: 'flex',
|
|
184
|
+
height: '2.5rem',
|
|
185
|
+
justifyContent: 'center',
|
|
186
|
+
p: 1,
|
|
187
|
+
width: '2.5rem',
|
|
188
|
+
}}
|
|
189
|
+
>
|
|
190
|
+
<MagnifyingGlassIcon />
|
|
191
|
+
</Box>
|
|
192
|
+
</InputAdornment>
|
|
193
|
+
),
|
|
194
|
+
endAdornment: !!value && (
|
|
195
|
+
<InputAdornment position='end'>
|
|
196
|
+
<IconButton
|
|
197
|
+
aria-label={t('clearValueAriaLabel')}
|
|
198
|
+
disabled={disabled}
|
|
199
|
+
onClick={() => onChange('')}
|
|
200
|
+
>
|
|
201
|
+
<XCircleFillIcon />
|
|
202
|
+
</IconButton>
|
|
203
|
+
</InputAdornment>
|
|
204
|
+
),
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<RcSesFormControlWrapper
|
|
209
|
+
id={id}
|
|
210
|
+
errors={visibleErrors}
|
|
211
|
+
label={label}
|
|
212
|
+
required={isRequired}
|
|
213
|
+
{...mergedWrapperProps}
|
|
214
|
+
>
|
|
215
|
+
<Box
|
|
216
|
+
sx={{
|
|
217
|
+
alignItems: 'stretch',
|
|
218
|
+
display: 'flex',
|
|
219
|
+
gap: 2,
|
|
220
|
+
width: '100%',
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
<TextField
|
|
224
|
+
id={id}
|
|
225
|
+
inputRef={setInputRef}
|
|
226
|
+
InputProps={mergedTextFieldInputProps}
|
|
227
|
+
error={!!visibleErrors}
|
|
228
|
+
fullWidth
|
|
229
|
+
{...restFieldProps}
|
|
230
|
+
disabled={disabled}
|
|
231
|
+
label={undefined}
|
|
232
|
+
name={name}
|
|
233
|
+
onBlur={onBlur}
|
|
234
|
+
onChange={handleFieldChange}
|
|
235
|
+
onKeyDown={handleFieldKeyDown}
|
|
236
|
+
placeholder={restFieldProps.placeholder ?? placeholder}
|
|
237
|
+
sx={[
|
|
238
|
+
{
|
|
239
|
+
flex: '1 1 auto',
|
|
240
|
+
'& input:-webkit-autofill, & input:-webkit-autofill:hover, & input:-webkit-autofill:focus':
|
|
241
|
+
{
|
|
242
|
+
WebkitBoxShadow: `0 0 0 1000px ${currentTheme.palette.background.paper} inset`,
|
|
243
|
+
},
|
|
244
|
+
'& .MuiOutlinedInput-root:has(input:-webkit-autofill)': {
|
|
245
|
+
backgroundColor: currentTheme.palette.background.paper,
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
...(Array.isArray(restFieldProps.sx)
|
|
249
|
+
? restFieldProps.sx
|
|
250
|
+
: [restFieldProps.sx]),
|
|
251
|
+
]}
|
|
252
|
+
value={value ?? ''}
|
|
253
|
+
/>
|
|
254
|
+
|
|
255
|
+
{shouldRenderSearchButton && (
|
|
256
|
+
<RcSesButton
|
|
257
|
+
disabled={disabled || mergedSearchButtonProps.disabled || !hasSearchValue}
|
|
258
|
+
onClick={handleSearchClick}
|
|
259
|
+
sx={[
|
|
260
|
+
{
|
|
261
|
+
flexShrink: 0,
|
|
262
|
+
minWidth: '6.75rem',
|
|
263
|
+
px: 3,
|
|
264
|
+
whiteSpace: 'nowrap',
|
|
265
|
+
},
|
|
266
|
+
...(Array.isArray(mergedSearchButtonProps.sx)
|
|
267
|
+
? mergedSearchButtonProps.sx
|
|
268
|
+
: [mergedSearchButtonProps.sx]),
|
|
269
|
+
]}
|
|
270
|
+
{...mergedSearchButtonProps}
|
|
271
|
+
>
|
|
272
|
+
{searchButtonLabel ??
|
|
273
|
+
mergedSearchButtonProps.children ??
|
|
274
|
+
t('searchButtonLabel')}
|
|
275
|
+
</RcSesButton>
|
|
276
|
+
)}
|
|
277
|
+
</Box>
|
|
278
|
+
</RcSesFormControlWrapper>
|
|
279
|
+
)
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
export default RcSesSearchInput
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
|
|
3
|
+
import { Option } from '../Select.types'
|
|
4
|
+
|
|
5
|
+
function useFilteredOptions(options: Option[], search: string) {
|
|
6
|
+
return useMemo(() => {
|
|
7
|
+
const normalized = search.trim().toLowerCase()
|
|
8
|
+
if (!normalized) return options
|
|
9
|
+
|
|
10
|
+
return options.filter((opt) => {
|
|
11
|
+
const label = opt.label?.toLowerCase() ?? ''
|
|
12
|
+
const desc = opt.description?.toLowerCase() ?? ''
|
|
13
|
+
return label.includes(normalized) || desc.includes(normalized)
|
|
14
|
+
})
|
|
15
|
+
}, [options, search])
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default useFilteredOptions
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Option } from '../Select.types'
|
|
2
|
+
|
|
3
|
+
type OnChange = (values: string[]) => void
|
|
4
|
+
|
|
5
|
+
function useSelectAll(options: Option[], selectedValues: string[], onChange: OnChange) {
|
|
6
|
+
const allSelected =
|
|
7
|
+
options.length > 0 && options.every((o) => selectedValues.includes(o.value))
|
|
8
|
+
|
|
9
|
+
const toggle = () => {
|
|
10
|
+
const values = options.map((o) => o.value)
|
|
11
|
+
|
|
12
|
+
if (allSelected) {
|
|
13
|
+
onChange(selectedValues.filter((v) => !values.includes(v)))
|
|
14
|
+
} else {
|
|
15
|
+
onChange(Array.from(new Set([...selectedValues, ...values])))
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return { allSelected, toggle }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default useSelectAll
|