@huibo-ui/react-antd 1.0.15 → 1.0.17

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,5 +1,6 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import React from 'react';
3
+ import { HbConfigProvider } from '@huibo-ui/react';
3
4
  /**
4
5
  * 把 antd 的 ThemeConfig.token 映射到 huibo-ui 的 --hb-* 设计令牌。
5
6
  * 写在 document.documentElement(:root) 上,custom property 会穿透 shadow DOM,
@@ -75,22 +76,5 @@ export function ConfigProvider(props) {
75
76
  React.useEffect(() => {
76
77
  applyThemeToken(theme?.token);
77
78
  }, [theme?.token]);
78
- // 设置 data-size / data-locale / data-theme documentElement
79
- // (原 hb-config-provider 的 applyConfig 逻辑,改为直接写 :root,避免额外 DOM 层)
80
- React.useEffect(() => {
81
- const root = document.documentElement;
82
- root.setAttribute('data-size', props.componentSize === 'middle' ? 'default' : (props.componentSize || 'default'));
83
- root.setAttribute('data-locale', props.locale ? 'zh-CN' : 'en-US');
84
- if (theme?.dark) {
85
- root.setAttribute('data-theme', 'dark');
86
- }
87
- else {
88
- root.removeAttribute('data-theme');
89
- }
90
- }, [theme?.dark, props.componentSize, props.locale]);
91
- // 直接返回 children,不包裹任何 DOM 元素 —— 对齐 antd ConfigProvider
92
- // (antd 用 React Context + CSS-in-JS,零 DOM 层)。
93
- // 之前渲染 hb-config-provider(display:contents)会改变 #root 子元素结构,
94
- // 导致 #root { height:100% } 在某些高度链下解析失效(全屏背景图场景)。
95
- return _jsx(_Fragment, { children: children });
79
+ return (_jsx(HbConfigProvider, { theme: theme?.dark ? 'dark' : 'light', size: props.componentSize === 'middle' ? 'default' : props.componentSize, locale: props.locale ? 'zh-CN' : 'en-US', children: _jsx("div", { style: { display: 'contents' }, children: children }) }));
96
80
  }
@@ -262,7 +262,13 @@ export function FormItem(props) {
262
262
  const [localErrors, setLocalErrors] = React.useState([]);
263
263
  const errors = (ctx?.errors[propName] ?? localErrors) || [];
264
264
  const isRequired = required || rules?.some((r) => r.required);
265
- const child = React.Children.only(children);
265
+ // 对齐 antd FormItem 的容错:antd 不会因 children 为空/数组而崩溃。
266
+ // React.Children.only 在 children 为 undefined/null/数组时会抛错,
267
+ // 业务代码(尤其条件渲染场景)可能传入 0 个或多个子元素,这里做兼容:
268
+ // - undefined/null/0 元素 → child 为 undefined(渲染空 FormItem)
269
+ // - 多个元素 → 取第一个(与 antd 单控件包裹语义一致)
270
+ const childArr = React.Children.toArray(children);
271
+ const child = (childArr.length > 0 ? childArr[0] : undefined);
266
272
  const labelColSpan = labelCol?.span ?? ctx?.labelColSpan;
267
273
  // wrapperCol 支持 { span, offset }:offset 在 wrapper 左侧留出与 labelCol 等比的空间。
268
274
  // 注意:|| 与 ?? 不可直接混用(babel parser 报错),用显式括号 + 层级判断。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huibo-ui/react-antd",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "antd 兼容层 — 接收 antd 原生 props,内部转换为 huibo-ui,实现丝滑平替",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",