1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-23 07:19:41 +02:00

refactor(ui/image-config): create react component [EE-5342] (#8856)

This commit is contained in:
Chaim Lev-Ari 2023-07-10 18:56:12 +03:00 committed by GitHub
parent bf51f1b6c9
commit 10014ae171
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 1464 additions and 84 deletions

View file

@ -0,0 +1,52 @@
import { AutomationTestingProps } from '@/types';
import { Option } from '@@/form-components/PortainerSelect';
import { Select } from '@@/form-components/ReactSelect';
export function InputSearch({
value,
onChange,
options,
placeholder,
'data-cy': dataCy,
inputId,
}: {
value: string;
onChange: (value: string) => void;
options: Option<string>[];
placeholder?: string;
inputId?: string;
} & AutomationTestingProps) {
const selectValue = options.find((option) => option.value === value) || {
value: '',
label: value,
};
return (
<Select
options={options}
value={selectValue}
onChange={(option) => option && onChange(option.value)}
placeholder={placeholder}
data-cy={dataCy}
inputId={inputId}
onInputChange={(value, actionMeta) => {
if (
actionMeta.action !== 'input-change' &&
actionMeta.action !== 'set-value'
) {
return;
}
onChange(value);
}}
openMenuOnClick={false}
openMenuOnFocus={false}
components={{ DropdownIndicator: () => null }}
onBlur={(e) => {
e.preventDefault();
e.stopPropagation();
}}
/>
);
}