zy-react-library 1.3.29 → 1.3.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,6 +21,10 @@ export interface BasicSelectProps extends SelectProps {
|
|
|
21
21
|
onGetData?: (data: Record<string, any>[]) => void;
|
|
22
22
|
/** 自定义 label 的渲染函数 */
|
|
23
23
|
labelRender?: (item: Record<string, any>) => ReactNode;
|
|
24
|
+
/** 排除的项 */
|
|
25
|
+
exclude?: string[];
|
|
26
|
+
/** 包含的项 */
|
|
27
|
+
include?: string[];
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Select as e}from"antd";import{useEffect as n}from"react";import{
|
|
1
|
+
import{Select as e}from"antd";import{useMemo as t,useEffect as n}from"react";import{getUnmatchedItems as r,getMatchedItems as l}from"../../../utils/index.js";import{jsx as i}from"react/jsx-runtime";function a(a){const{onGetData:o,onChange:s,onGetLabel:c,onGetOption:d,placeholder:h="",data:p=[],nameKey:u="name",idKey:f="id",labelRender:m,exclude:y=[],include:g=[],...x}=a,K=t(()=>{let e=p;return y.length>0&&(e=r({list:e,value:y,idKey:f})),g.length>0&&(e=l({list:e,value:g,idKey:f})),e},[p,y,g,f]);return n(()=>{o?.(K)},[K]),i(e,{placeholder:`请选择${h}`,showSearch:!0,allowClear:!0,optionFilterProp:"children",onChange:(e,t)=>{if(c||d)if(Array.isArray(e))if(e.length>0){const t=[],n=[];e.forEach(e=>{const r=K.find(t=>t[f]===e);r&&(t.push(r),n.push(r[u]))}),c?.(n),d?.(t)}else c?.([]),d?.([]);else if(e){const t=K.find(t=>t[f]===e);c?.(t[u]),d?.(t)}else c?.(""),d?.({});s?.(e,t)},...x,children:K.map(t=>{const n=t[f],r=m?m(t):t[u];return i(e.Option,{value:n,children:r},n)})})}a.displayName="BasicSelect";export{a as default};
|