@registrucentras/rc-ses-react-components 1.6.5 → 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/icons/ArrowsClockwiseIcon.d.ts +3 -0
- package/dist/components/form/inputs/SearchInput/index.d.ts +27 -0
- package/dist/library/icons.d.ts +2 -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 +2010 -1823
- package/dist/stories/components/inputs/SearchInput.stories.d.ts +11 -0
- package/dist/theme/light/MuiOutlinedInput.d.ts +3 -0
- package/package.json +1 -1
- package/src/assets/icons/ArrowsClockwiseIcon.tsx +16 -0
- package/src/components/form/inputs/SearchInput/index.test.tsx +203 -0
- package/src/components/form/inputs/SearchInput/index.tsx +282 -0
- package/src/i18n/namespaces/input/en.json +5 -0
- package/src/i18n/namespaces/input/lt.json +5 -0
- package/src/library/icons.ts +2 -0
- package/src/library/index.ts +2 -0
- package/src/stories/components/inputs/SearchInput.stories.tsx +134 -0
- package/src/theme/light/MuiOutlinedInput.ts +15 -0
- package/src/theme/light/index.tsx +2 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as RcSesSearchInput } from '../../../components/form/inputs/SearchInput';
|
|
3
|
+
declare const meta: Meta<typeof RcSesSearchInput>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof RcSesSearchInput>;
|
|
6
|
+
export declare const Main: Story;
|
|
7
|
+
export declare const OnlyRequired: Story;
|
|
8
|
+
export declare const WithoutButton: Story;
|
|
9
|
+
export declare const WithoutLabel: Story;
|
|
10
|
+
export declare const SideLabel: Story;
|
|
11
|
+
export declare const OnlyNumbers: Story;
|
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ArrowsClockwiseIcon as PhosphorArrowClockwiseIcon } from '@phosphor-icons/react'
|
|
2
|
+
|
|
3
|
+
import IconProps from '../IconProps'
|
|
4
|
+
|
|
5
|
+
function ArrowsClockwiseIcon({ className, size = 24, fillColor, ...rest }: IconProps) {
|
|
6
|
+
return (
|
|
7
|
+
<PhosphorArrowClockwiseIcon
|
|
8
|
+
{...rest}
|
|
9
|
+
className={className}
|
|
10
|
+
size={size}
|
|
11
|
+
color={fillColor}
|
|
12
|
+
/>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default ArrowsClockwiseIcon
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
3
|
+
import { useForm } from 'react-hook-form'
|
|
4
|
+
import { vi } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import theme from '@/theme/light'
|
|
7
|
+
|
|
8
|
+
import RcSesSearchInput from './index'
|
|
9
|
+
|
|
10
|
+
vi.mock('react-i18next', () => ({
|
|
11
|
+
useTranslation: () => ({
|
|
12
|
+
t: (key: string) => key,
|
|
13
|
+
}),
|
|
14
|
+
initReactI18next: {
|
|
15
|
+
type: '3rdParty',
|
|
16
|
+
init: () => {},
|
|
17
|
+
},
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
// Fake md breakpoint so the search button is always rendered
|
|
21
|
+
vi.mock('@mui/material', async (importOriginal) => {
|
|
22
|
+
const actual = await importOriginal<typeof import('@mui/material')>()
|
|
23
|
+
return {
|
|
24
|
+
...actual,
|
|
25
|
+
useMediaQuery: () => true,
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
type WrapperProps = Partial<React.ComponentProps<typeof RcSesSearchInput>> & {
|
|
30
|
+
onSearch?: (value: string) => void
|
|
31
|
+
defaultValue?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const TestWrapper = ({
|
|
35
|
+
defaultValue = '',
|
|
36
|
+
onSearch = vi.fn(),
|
|
37
|
+
...props
|
|
38
|
+
}: WrapperProps) => {
|
|
39
|
+
const { control } = useForm({ defaultValues: { search: defaultValue } })
|
|
40
|
+
return (
|
|
41
|
+
<ThemeProvider theme={theme}>
|
|
42
|
+
<RcSesSearchInput
|
|
43
|
+
id='search'
|
|
44
|
+
name='search'
|
|
45
|
+
control={control}
|
|
46
|
+
label='Search'
|
|
47
|
+
errors={undefined}
|
|
48
|
+
onSearch={onSearch}
|
|
49
|
+
{...props}
|
|
50
|
+
/>
|
|
51
|
+
</ThemeProvider>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
describe('RcSesSearchInput', () => {
|
|
56
|
+
test('renders the text input', () => {
|
|
57
|
+
render(<TestWrapper />)
|
|
58
|
+
expect(screen.getByRole('textbox')).toBeInTheDocument()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('renders label', () => {
|
|
62
|
+
render(<TestWrapper label='My label' />)
|
|
63
|
+
expect(screen.getByText('My label')).toBeInTheDocument()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('does not show clear button when value is empty', () => {
|
|
67
|
+
render(<TestWrapper />)
|
|
68
|
+
expect(
|
|
69
|
+
screen.queryByRole('button', { name: /clearValueAriaLabel/i }),
|
|
70
|
+
).not.toBeInTheDocument()
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('search button is disabled when input is empty', () => {
|
|
74
|
+
render(<TestWrapper />)
|
|
75
|
+
const btn = screen.getByRole('button', { name: /search/i })
|
|
76
|
+
expect(btn).toBeDisabled()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('search button is not rendered when showSearchButton=false', () => {
|
|
80
|
+
render(<TestWrapper showSearchButton={false} />)
|
|
81
|
+
expect(screen.queryByRole('button', { name: /search/i })).not.toBeInTheDocument()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
describe('handleSearchClick', () => {
|
|
85
|
+
test('calls onSearch with current value when button is clicked', () => {
|
|
86
|
+
const onSearch = vi.fn()
|
|
87
|
+
render(<TestWrapper onSearch={onSearch} defaultValue='hello' />)
|
|
88
|
+
|
|
89
|
+
fireEvent.click(screen.getByRole('button', { name: /search/i }))
|
|
90
|
+
|
|
91
|
+
expect(onSearch).toHaveBeenCalledWith('hello')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('does not call onSearch when slotProps.searchButton.onClick calls preventDefault', () => {
|
|
95
|
+
const onSearch = vi.fn()
|
|
96
|
+
|
|
97
|
+
render(
|
|
98
|
+
<TestWrapper
|
|
99
|
+
onSearch={onSearch}
|
|
100
|
+
defaultValue='test'
|
|
101
|
+
slotProps={{
|
|
102
|
+
searchButton: {
|
|
103
|
+
onClick: (e) => e.preventDefault(),
|
|
104
|
+
},
|
|
105
|
+
}}
|
|
106
|
+
/>,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
fireEvent.click(screen.getByRole('button', { name: /search/i }))
|
|
110
|
+
|
|
111
|
+
expect(onSearch).not.toHaveBeenCalled()
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
describe('handleFieldKeyDown', () => {
|
|
116
|
+
test('calls onSearch on Enter when search button is hidden', () => {
|
|
117
|
+
const onSearch = vi.fn()
|
|
118
|
+
render(<TestWrapper onSearch={onSearch} showSearchButton={false} />)
|
|
119
|
+
|
|
120
|
+
const input = screen.getByRole('textbox')
|
|
121
|
+
fireEvent.change(input, { target: { value: 'query' } })
|
|
122
|
+
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter', charCode: 13 })
|
|
123
|
+
|
|
124
|
+
expect(onSearch).toHaveBeenCalledWith('query')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('does not call onSearch on Enter when value is empty', () => {
|
|
128
|
+
const onSearch = vi.fn()
|
|
129
|
+
render(<TestWrapper onSearch={onSearch} showSearchButton={false} />)
|
|
130
|
+
|
|
131
|
+
const input = screen.getByRole('textbox')
|
|
132
|
+
fireEvent.click(input)
|
|
133
|
+
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter', charCode: 13 })
|
|
134
|
+
|
|
135
|
+
expect(onSearch).not.toHaveBeenCalled()
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('does not call onSearch on Enter when search button is enabled (shouldSearchOnEnter=false)', () => {
|
|
139
|
+
const onSearch = vi.fn()
|
|
140
|
+
render(<TestWrapper onSearch={onSearch} defaultValue='hello' />)
|
|
141
|
+
|
|
142
|
+
const input = screen.getByRole('textbox')
|
|
143
|
+
fireEvent.click(input)
|
|
144
|
+
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter', charCode: 13 })
|
|
145
|
+
|
|
146
|
+
expect(onSearch).not.toHaveBeenCalled()
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
test('does not call onSearch when slotProps.field.onKeyDown calls preventDefault', () => {
|
|
150
|
+
const onSearch = vi.fn()
|
|
151
|
+
|
|
152
|
+
render(
|
|
153
|
+
<TestWrapper
|
|
154
|
+
onSearch={onSearch}
|
|
155
|
+
showSearchButton={false}
|
|
156
|
+
slotProps={{
|
|
157
|
+
field: {
|
|
158
|
+
onKeyDown: (e) => {
|
|
159
|
+
if (e.key === 'Enter') e.preventDefault()
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
}}
|
|
163
|
+
/>,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
const input = screen.getByRole('textbox')
|
|
167
|
+
fireEvent.change(input, { target: { value: 'hi' } })
|
|
168
|
+
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter', charCode: 13 })
|
|
169
|
+
|
|
170
|
+
expect(onSearch).not.toHaveBeenCalled()
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
describe('handleFieldChange', () => {
|
|
175
|
+
test('updates field value as user types', () => {
|
|
176
|
+
render(<TestWrapper />)
|
|
177
|
+
|
|
178
|
+
const input = screen.getByRole('textbox')
|
|
179
|
+
fireEvent.change(input, { target: { value: 'hello' } })
|
|
180
|
+
|
|
181
|
+
expect(input).toHaveValue('hello')
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
test('strips non-numeric characters when onlyNumbers=true', () => {
|
|
185
|
+
render(<TestWrapper onlyNumbers />)
|
|
186
|
+
|
|
187
|
+
const input = screen.getByRole('textbox')
|
|
188
|
+
fireEvent.change(input, { target: { value: 'ab12cd3' } })
|
|
189
|
+
|
|
190
|
+
expect(input).toHaveValue('123')
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
test('calls slotProps.field.onChange before updating value', () => {
|
|
194
|
+
const fieldOnChange = vi.fn()
|
|
195
|
+
|
|
196
|
+
render(<TestWrapper slotProps={{ field: { onChange: fieldOnChange } }} />)
|
|
197
|
+
|
|
198
|
+
fireEvent.change(screen.getByRole('textbox'), { target: { value: 'x' } })
|
|
199
|
+
|
|
200
|
+
expect(fieldOnChange).toHaveBeenCalled()
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
})
|
|
@@ -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
|
|
@@ -48,6 +48,11 @@
|
|
|
48
48
|
"RcSesSearchableField": {
|
|
49
49
|
"clearValueAriaLabel": "Išvalyti paieškos reikšmę",
|
|
50
50
|
"searchAriaLabel": "Ieškoti"
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
"RcSesSearchInput": {
|
|
54
|
+
"clearValueAriaLabel": "Išvalyti paieškos reikšmę",
|
|
55
|
+
"searchButtonLabel": "Ieškoti"
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
}
|
package/src/library/icons.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import RcSesLogo from '@/assets/Logo'
|
|
2
2
|
import ArrowLeftIcon from '@/assets/icons/ArrowLeftIcon'
|
|
3
3
|
import ArrowRightIcon from '@/assets/icons/ArrowRightIcon'
|
|
4
|
+
import ArrowsClockwiseIcon from '@/assets/icons/ArrowsClockwiseIcon'
|
|
4
5
|
import BarcodeIcon from '@/assets/icons/BarcodeIcon'
|
|
5
6
|
import CalendarBlankIcon from '@/assets/icons/CalendarBlankIcon'
|
|
6
7
|
import CaretDoubleLeftBoldIcon from '@/assets/icons/CaretDoubleLeftBoldIcon'
|
|
@@ -40,6 +41,7 @@ export {
|
|
|
40
41
|
RcSesLogo,
|
|
41
42
|
ArrowLeftIcon,
|
|
42
43
|
ArrowRightIcon,
|
|
44
|
+
ArrowsClockwiseIcon,
|
|
43
45
|
BarcodeIcon,
|
|
44
46
|
CalendarBlankIcon,
|
|
45
47
|
CaretDoubleLeftBoldIcon,
|
package/src/library/index.ts
CHANGED
|
@@ -28,6 +28,7 @@ import RcSesNumberStepper from '@/components/form/inputs/NumberStepper'
|
|
|
28
28
|
import RcSesPhoneInput from '@/components/form/inputs/PhoneInput'
|
|
29
29
|
import RcSesPhoneInputFormControl from '@/components/form/inputs/PhoneInputFormControl'
|
|
30
30
|
import RcSesRadioButtonGroup from '@/components/form/inputs/RadioButtonGroup'
|
|
31
|
+
import RcSesSearchInput from '@/components/form/inputs/SearchInput'
|
|
31
32
|
import RcSesSearchableField from '@/components/form/inputs/SearchableField'
|
|
32
33
|
import RcSesSelect from '@/components/form/inputs/Select'
|
|
33
34
|
import RcSesTextField from '@/components/form/inputs/TextField'
|
|
@@ -67,6 +68,7 @@ export { RcSesFileDropzone }
|
|
|
67
68
|
export { RcSesNumberStepper }
|
|
68
69
|
export { RcSesPhoneInput, RcSesPhoneInputFormControl }
|
|
69
70
|
export { RcSesRadioButtonGroup }
|
|
71
|
+
export { RcSesSearchInput }
|
|
70
72
|
export { RcSesSearchableField }
|
|
71
73
|
export { RcSesSelect }
|
|
72
74
|
export { RcSesTab, RcSesTabPanel, RcSesTabs, RcSesTabsWrapper }
|