zy-react-library/components/Select/Basic/index.js

44 lines
1008 B
JavaScript

import { Select } from "antd";
import { getLabelName } from "../../../utils";
/**
* 基础下拉组件(不建议直接使用此组件,二次继承使用)
*/
function BasicSelect(props) {
const {
onChange,
onGetLabel,
placeholder = "",
data = [],
nameKey = "name",
idKey = "id",
...restProps
} = props;
const handleChange = (event, option) => {
if (event)
onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey }));
else
onGetLabel?.("");
onChange?.(event, option);
};
return (
<Select placeholder={`请选择${placeholder}`} showSearch allowClear onChange={handleChange} {...restProps}>
{data.map((item) => {
const value = item[idKey];
const label = item[nameKey];
return (
<Select.Option key={value} value={value}>
{label}
</Select.Option>
);
})}
</Select>
);
}
BasicSelect.displayName = "BasicSelect";
export default BasicSelect;