vchikalkin 7b9dbdaeb5 add turborepo
move ./Elements to packages/elements
2022-12-19 19:08:32 +03:00

47 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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