39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
import { Select as AntSelect } from 'antd';
|
|
import { useStatus } from 'client/hooks/useStatus';
|
|
import { useStoreValue } from 'client/hooks/useStoreValue';
|
|
import { Status } from 'core/types/elements';
|
|
import { observer } from 'mobx-react';
|
|
import React from 'react';
|
|
import { useOptions } from 'client/hooks/useOptions';
|
|
|
|
const Select = ({ disabled, name, showSearch, computedValue, valueName }) => {
|
|
const { value, setCurrentValue } = useStoreValue({
|
|
computedValue,
|
|
valueName,
|
|
});
|
|
const { status } = useStatus(name);
|
|
const { options, filter } = useOptions(name);
|
|
|
|
return (
|
|
<AntSelect
|
|
disabled={status === Status.Disabled}
|
|
showSearch={showSearch}
|
|
optionFilterProp="children"
|
|
filterOption={filter}
|
|
value={value}
|
|
onChange={val => setCurrentValue(val)}
|
|
>
|
|
{options.map((option, i) => {
|
|
if (option)
|
|
return (
|
|
<AntSelect.Option key={i} value={option.value}>
|
|
{option.name}
|
|
</AntSelect.Option>
|
|
);
|
|
})}
|
|
</AntSelect>
|
|
);
|
|
};
|
|
|
|
export default observer(Select);
|