@huibo-ui/react-antd 1.0.5 → 1.0.6

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.
@@ -1,12 +1,20 @@
1
1
  import React from 'react';
2
- export declare function Cascader(props: {
2
+ export interface CascaderProps {
3
3
  options?: any[];
4
4
  value?: any;
5
- onChange?: (value: any) => void;
5
+ onChange?: (value: any, selectOptions?: any) => void;
6
6
  multiple?: boolean;
7
7
  placeholder?: string;
8
8
  disabled?: boolean;
9
9
  allowClear?: boolean;
10
10
  showSearch?: boolean;
11
+ /** antd fieldNames:自定义节点字段名,如 { label:'name', value:'id', children:'child' } */
12
+ fieldNames?: {
13
+ label?: string;
14
+ value?: string;
15
+ children?: string;
16
+ };
11
17
  style?: React.CSSProperties;
12
- }): React.JSX.Element;
18
+ [key: string]: any;
19
+ }
20
+ export declare function Cascader(props: CascaderProps): React.JSX.Element;
@@ -1,5 +1,25 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { HbCascader } from '@huibo-ui/react';
3
+ /**
4
+ * 按 antd fieldNames 递归把自定义节点字段映射为 hb-cascader 认的 {label,value,children},
5
+ * 保留原始字段(onChange 第二参数对齐 antd 返回原始 option)。
6
+ */
7
+ function mapCascader(nodes, fn) {
8
+ if (!nodes || nodes.length === 0)
9
+ return [];
10
+ if (!fn)
11
+ return nodes;
12
+ const ln = fn.label || 'label';
13
+ const vn = fn.value || 'value';
14
+ const cn = fn.children || 'children';
15
+ return nodes.map(n => {
16
+ const mapped = { ...n, label: n[ln], value: n[vn] };
17
+ if (Array.isArray(n[cn]))
18
+ mapped.children = mapCascader(n[cn], fn);
19
+ return mapped;
20
+ });
21
+ }
3
22
  export function Cascader(props) {
4
- return _jsx(HbCascader, { options: props.options || [], modelValue: props.value, multiple: props.multiple, placeholder: props.placeholder, disabled: props.disabled, clearable: props.allowClear, filterable: props.showSearch, onHbChange: (e) => props.onChange?.(e.detail), style: props.style });
23
+ const options = mapCascader(props.options, props.fieldNames);
24
+ return (_jsx(HbCascader, { options: options, modelValue: props.value, multiple: props.multiple, placeholder: props.placeholder, disabled: props.disabled, clearable: props.allowClear, filterable: props.showSearch, onHbChange: (e) => props.onChange?.(e.detail), style: props.style }));
5
25
  }
@@ -23,6 +23,13 @@ export interface SelectProps {
23
23
  virtual?: boolean;
24
24
  onSearch?: (value: string) => void;
25
25
  onDropdownVisibleChange?: (open: boolean) => void;
26
+ /** antd fieldNames:自定义 option 字段名映射,如 { label:'nickName', value:'id' } */
27
+ fieldNames?: {
28
+ label?: string;
29
+ value?: string;
30
+ disabled?: string;
31
+ options?: string;
32
+ };
26
33
  }
27
34
  export declare function Select(props: SelectProps): React.JSX.Element;
28
35
  export declare namespace Select {
@@ -30,8 +30,32 @@ export function Select(props) {
30
30
  const { value, onChange, options, mode, placeholder, disabled, size, allowClear, showSearch, virtual, style, children, } = props;
31
31
  // antd maxTagCount:多选时折叠超出数量的 tag。映射到 hb-select 的 collapseTags + maxCollapseTags
32
32
  const maxTagCount = props.maxTagCount;
33
- // 优先用 options prop;否则从 <Select.Option> children 提取
34
- const resolvedOptions = options && options.length > 0 ? options : optionsFromChildren(children);
33
+ // antd fieldNames:自定义 option 字段名(如 {label:'nickName', value:'id'})。
34
+ // hb-select 只认 {value,label,disabled},必须按 fieldNames 重映射,否则下拉项无文案、值 undefined。
35
+ const fieldNames = props.fieldNames;
36
+ function mapOptions(opts) {
37
+ if (!opts || opts.length === 0)
38
+ return [];
39
+ if (!fieldNames)
40
+ return opts;
41
+ const ln = fieldNames.label || 'label';
42
+ const vn = fieldNames.value || 'value';
43
+ const dn = fieldNames.disabled || 'disabled';
44
+ const on = fieldNames.options; // OptGroup 子选项字段
45
+ const out = [];
46
+ for (const o of opts) {
47
+ if (on && Array.isArray(o[on])) {
48
+ for (const c of o[on])
49
+ out.push({ ...c, value: c[vn], label: c[ln], disabled: c[dn] });
50
+ }
51
+ else {
52
+ out.push({ ...o, value: o[vn], label: o[ln], disabled: o[dn] });
53
+ }
54
+ }
55
+ return out;
56
+ }
57
+ // 优先用 options prop;否则从 <Select.Option> children 提取;再按 fieldNames 映射
58
+ const resolvedOptions = mapOptions(options && options.length > 0 ? options : optionsFromChildren(children));
35
59
  // 从 options 里查出选中项(单选返回单个 option,多选返回数组),对齐 antd onChange 第二参数
36
60
  const resolveOption = (val) => {
37
61
  if (!resolvedOptions || resolvedOptions.length === 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huibo-ui/react-antd",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "antd 兼容层 — 接收 antd 原生 props,内部转换为 huibo-ui,实现丝滑平替",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",