41 lines
911 B
TypeScript
41 lines
911 B
TypeScript
import type { SelectProps } from 'antd';
|
||
import { Form, Select } from 'antd';
|
||
import type { BaseElementProps, BaseOption } from './types';
|
||
|
||
const { Item: FormItem } = Form;
|
||
|
||
type ElementProps = BaseElementProps<string | null> & {
|
||
options: BaseOption[];
|
||
};
|
||
|
||
export default function Element({
|
||
value = null,
|
||
setValue,
|
||
options,
|
||
status,
|
||
isValid,
|
||
help,
|
||
...props
|
||
}: ElementProps) {
|
||
return (
|
||
<FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
|
||
<Select
|
||
defaultValue={value}
|
||
onChange={(val) => setValue(val)}
|
||
disabled={status === 'Disabled'}
|
||
loading={status === 'Loading'}
|
||
optionFilterProp="children"
|
||
options={[
|
||
{
|
||
label: 'Не выбрано',
|
||
value: null,
|
||
},
|
||
].concat(options)}
|
||
{...props}
|
||
/>
|
||
</FormItem>
|
||
);
|
||
}
|
||
|
||
export type { SelectProps };
|