@huibo-ui/react-antd 1.0.7 → 1.0.9
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.
|
@@ -76,5 +76,5 @@ export function ConfigProvider(props) {
|
|
|
76
76
|
React.useEffect(() => {
|
|
77
77
|
applyThemeToken(theme?.token);
|
|
78
78
|
}, [theme?.token]);
|
|
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: '
|
|
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 }) }));
|
|
80
80
|
}
|
package/lib/components/Form.js
CHANGED
|
@@ -101,7 +101,7 @@ export const Form = React.forwardRef(function Form(props, ref) {
|
|
|
101
101
|
onValuesChange({ [prop]: info?.value }, {});
|
|
102
102
|
};
|
|
103
103
|
});
|
|
104
|
-
return (_jsx(HbForm, { ref: refCallback, initialValues: initialValues, labelPosition: labelPosition, labelWidth: labelCol?.span ? `${(labelCol.span / 24) * 100}%` : '80px', style: style, className: className, children: children }));
|
|
104
|
+
return (_jsx(HbForm, { ref: refCallback, initialValues: initialValues, labelPosition: labelPosition, inline: layout === 'inline', labelWidth: labelCol?.span ? `${(labelCol.span / 24) * 100}%` : '80px', style: style, className: className, children: children }));
|
|
105
105
|
});
|
|
106
106
|
Form.useForm = function useForm() {
|
|
107
107
|
const [f] = React.useState(createFormInstance);
|
package/lib/components/Tabs.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* antd Tabs 兼容层(自包含 React 渲染)。
|
|
4
|
+
*
|
|
5
|
+
* 为什么不用 core 的 hb-tabs:hb-tabs 的 items[].content 只接受 string/HTML,
|
|
6
|
+
* 不渲染 React 节点(scrm 权益管理 Tabs items 的 children 是复杂 React 内容 → 空白);
|
|
7
|
+
* 且 items 数组 post-mount 同步不可靠(同 hb-menu 的坑)。故本层纯 React 渲染:
|
|
8
|
+
* items 的 children/label 全部原生,activeKey 受控 + 非受控,type=line/card,tabPosition。
|
|
9
|
+
*/
|
|
2
10
|
export interface TabItemType {
|
|
3
11
|
key: string;
|
|
4
|
-
label
|
|
12
|
+
label?: React.ReactNode;
|
|
5
13
|
children?: React.ReactNode;
|
|
6
14
|
disabled?: boolean;
|
|
15
|
+
[k: string]: any;
|
|
7
16
|
}
|
|
8
|
-
export
|
|
17
|
+
export interface TabsProps {
|
|
9
18
|
items?: TabItemType[];
|
|
10
19
|
activeKey?: string;
|
|
11
20
|
defaultActiveKey?: string;
|
|
@@ -13,9 +22,13 @@ export declare function Tabs(props: {
|
|
|
13
22
|
type?: 'line' | 'card';
|
|
14
23
|
size?: 'small' | 'middle' | 'large';
|
|
15
24
|
tabPosition?: 'top' | 'bottom' | 'left' | 'right';
|
|
16
|
-
|
|
25
|
+
destroyInactiveTabPane?: boolean;
|
|
17
26
|
style?: React.CSSProperties;
|
|
18
|
-
|
|
27
|
+
className?: string;
|
|
28
|
+
children?: React.ReactNode;
|
|
29
|
+
[k: string]: any;
|
|
30
|
+
}
|
|
31
|
+
export declare function Tabs(props: TabsProps): React.JSX.Element;
|
|
19
32
|
export declare namespace Tabs {
|
|
20
33
|
var TabPane: any;
|
|
21
34
|
}
|
package/lib/components/Tabs.js
CHANGED
|
@@ -1,7 +1,67 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
|
|
3
|
+
const PRIMARY = 'var(--hb-color-primary, #ff6700)';
|
|
4
4
|
export function Tabs(props) {
|
|
5
|
-
|
|
5
|
+
const { items, activeKey, defaultActiveKey, onChange, type = 'line', size = 'middle', tabPosition = 'top', destroyInactiveTabPane = false, style, className, children, } = props;
|
|
6
|
+
const list = items && items.length > 0 ? items : [];
|
|
7
|
+
const [internal, setInternal] = React.useState(activeKey ?? defaultActiveKey ?? list[0]?.key ?? '');
|
|
8
|
+
const current = activeKey !== undefined ? activeKey : internal;
|
|
9
|
+
const select = (key, disabled) => {
|
|
10
|
+
if (disabled)
|
|
11
|
+
return;
|
|
12
|
+
if (activeKey === undefined)
|
|
13
|
+
setInternal(key);
|
|
14
|
+
onChange?.(key);
|
|
15
|
+
};
|
|
16
|
+
const vertical = tabPosition === 'left' || tabPosition === 'right';
|
|
17
|
+
const card = type === 'card';
|
|
18
|
+
const fontSize = size === 'large' ? 16 : size === 'small' ? 13 : 14;
|
|
19
|
+
const tabPadding = size === 'large' ? '16px 24px' : size === 'small' ? '8px 16px' : '12px 16px';
|
|
20
|
+
const tabBar = (_jsx("div", { style: {
|
|
21
|
+
display: 'flex',
|
|
22
|
+
flexDirection: vertical ? 'column' : 'row',
|
|
23
|
+
borderBottom: vertical || card ? 'none' : '1px solid #f0f0f0',
|
|
24
|
+
[vertical ? 'borderRight' : 'borderBottom']: vertical ? '1px solid #f0f0f0' : undefined,
|
|
25
|
+
gap: vertical ? 0 : 4,
|
|
26
|
+
overflowX: vertical ? 'visible' : 'auto',
|
|
27
|
+
scrollbarWidth: 'thin',
|
|
28
|
+
}, children: list.map(it => {
|
|
29
|
+
const active = it.key === current;
|
|
30
|
+
return (_jsxs("div", { role: "tab", "aria-selected": active, onClick: () => select(it.key, it.disabled), style: {
|
|
31
|
+
padding: tabPadding,
|
|
32
|
+
cursor: it.disabled ? 'not-allowed' : 'pointer',
|
|
33
|
+
color: it.disabled ? 'rgba(0,0,0,0.25)' : active ? PRIMARY : 'rgba(0,0,0,0.88)',
|
|
34
|
+
fontWeight: active ? 500 : 400,
|
|
35
|
+
fontSize,
|
|
36
|
+
whiteSpace: 'nowrap',
|
|
37
|
+
position: 'relative',
|
|
38
|
+
background: card ? (active ? '#fff' : 'transparent') : 'transparent',
|
|
39
|
+
border: card ? '1px solid #f0f0f0' : 'none',
|
|
40
|
+
[vertical ? 'borderBottom' : 'borderBottom']: card ? (active ? '1px solid #fff' : '1px solid #f0f0f0') : 'none',
|
|
41
|
+
marginBottom: card && !vertical ? '-1px' : undefined,
|
|
42
|
+
borderRadius: card ? (vertical ? '4px 0 0 4px' : '4px 4px 0 0') : undefined,
|
|
43
|
+
transition: 'color .2s',
|
|
44
|
+
}, children: [it.label, active && !card && (_jsx("span", { style: {
|
|
45
|
+
position: 'absolute',
|
|
46
|
+
[vertical ? 'right' : 'bottom']: 0,
|
|
47
|
+
[vertical ? 'top' : 'left']: vertical ? 0 : 0,
|
|
48
|
+
[vertical ? 'width' : 'height']: '2px',
|
|
49
|
+
[vertical ? 'height' : 'width']: '100%',
|
|
50
|
+
background: PRIMARY,
|
|
51
|
+
} }))] }, it.key));
|
|
52
|
+
}) }));
|
|
53
|
+
const activeItem = list.find(it => it.key === current);
|
|
54
|
+
const panels = (_jsxs("div", { style: { flex: 1, minWidth: 0, padding: vertical ? '0 16px' : '16px 0' }, children: [destroyInactiveTabPane
|
|
55
|
+
? activeItem?.children
|
|
56
|
+
: list.map(it => (_jsx("div", { style: { display: it.key === current ? 'block' : 'none' }, children: it.children }, it.key))), !items || items.length === 0 ? children : null] }));
|
|
57
|
+
return (_jsxs("div", { className: className, style: {
|
|
58
|
+
display: 'flex',
|
|
59
|
+
flexDirection: vertical ? 'row' : 'column',
|
|
60
|
+
[tabPosition === 'bottom' ? 'flexDirection' : '']: tabPosition === 'bottom' ? 'column-reverse' : undefined,
|
|
61
|
+
...style,
|
|
62
|
+
}, children: [tabPosition === 'bottom' ? panels : tabBar, tabPosition === 'bottom' ? tabBar : panels] }));
|
|
6
63
|
}
|
|
7
|
-
Tabs.TabPane
|
|
64
|
+
/** Tabs.TabPane —— antd4 声明式占位(scrm 用 items,这里仅兜底) */
|
|
65
|
+
Tabs.TabPane = function TabPane(_props) {
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
@@ -3,11 +3,28 @@
|
|
|
3
3
|
* message.success('保存成功') → 创建 hb-message 并显示
|
|
4
4
|
*/
|
|
5
5
|
let messageCounter = 0;
|
|
6
|
+
/**
|
|
7
|
+
* 获取/创建固定定位的 message 容器(与主包 show-message.ts 的 #hb-message-container 对齐)。
|
|
8
|
+
* 命令式 message 必须脱离文档流固定在视口顶部居中,否则会被 body 内容流推到视口外,
|
|
9
|
+
* 用户看不到提示(表现为「点了没反应」)。
|
|
10
|
+
*/
|
|
11
|
+
function getMessageContainer() {
|
|
12
|
+
let container = document.getElementById('hb-message-container');
|
|
13
|
+
if (!container) {
|
|
14
|
+
container = document.createElement('div');
|
|
15
|
+
container.id = 'hb-message-container';
|
|
16
|
+
container.style.cssText =
|
|
17
|
+
'position:fixed;top:20px;left:50%;transform:translateX(-50%);z-index:1100;' +
|
|
18
|
+
'display:flex;flex-direction:column;align-items:center;gap:8px;pointer-events:none;';
|
|
19
|
+
document.body.appendChild(container);
|
|
20
|
+
}
|
|
21
|
+
return container;
|
|
22
|
+
}
|
|
6
23
|
function showMessage(type, content, duration) {
|
|
7
24
|
const id = `hb-msg-${++messageCounter}`;
|
|
8
25
|
const div = document.createElement('div');
|
|
9
26
|
div.id = id;
|
|
10
|
-
|
|
27
|
+
getMessageContainer().appendChild(div);
|
|
11
28
|
// 创建 hb-message 元素
|
|
12
29
|
const el = document.createElement('hb-message');
|
|
13
30
|
el.type = type;
|