bj-web-components 0.2.27 → 0.2.28
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.
- package/dist/index.js +51 -1
- package/dist/index.mjs +49 -49
- package/dist/style.css +3744 -1
- package/dist/web/BasicInput/BInput.js +208 -1
- package/dist/web/BasicInput/BInput.mjs +164 -132
- package/dist/web/BasicInput/utils.js +47 -1
- package/dist/web/BasicInput/utils.mjs +38 -28
- package/dist/web/CategoryDropdown/CategoryDropdown.js +307 -1
- package/dist/web/CategoryDropdown/CategoryDropdown.mjs +218 -170
- package/dist/web/CheckBox/BCheckBox.js +116 -1
- package/dist/web/CheckBox/BCheckBox.mjs +86 -70
- package/dist/web/CheckBox/Group.js +73 -1
- package/dist/web/CheckBox/Group.mjs +63 -56
- package/dist/web/CheckBox/context.js +5 -1
- package/dist/web/CheckBox/context.mjs +3 -3
- package/dist/web/CheckBox/index.js +8 -1
- package/dist/web/CheckBox/index.mjs +6 -6
- package/dist/web/Dropdown/BDropdown.js +186 -1
- package/dist/web/Dropdown/BDropdown.mjs +132 -106
- package/dist/web/EmptyInputBox/EmptyInputBox.js +77 -1
- package/dist/web/EmptyInputBox/EmptyInputBox.mjs +52 -48
- package/dist/web/FileCard/FileCard.js +157 -1
- package/dist/web/FileCard/FileCard.mjs +112 -82
- package/dist/web/Icon/Icon.js +9 -1
- package/dist/web/Icon/Icon.mjs +6 -6
- package/dist/web/Input/Input.js +181 -1
- package/dist/web/Input/Input.mjs +122 -113
- package/dist/web/InputNumber/BInputNumber.js +311 -1
- package/dist/web/InputNumber/BInputNumber.mjs +275 -167
- package/dist/web/InputNumber/StepHandler.js +69 -1
- package/dist/web/InputNumber/StepHandler.mjs +38 -32
- package/dist/web/InputNumber/hooks/useCursor.js +40 -1
- package/dist/web/InputNumber/hooks/useCursor.mjs +35 -33
- package/dist/web/InputNumber/hooks/useFrame.js +12 -1
- package/dist/web/InputNumber/hooks/useFrame.mjs +9 -6
- package/dist/web/InputNumber/utils/decimal.js +147 -1
- package/dist/web/InputNumber/utils/decimal.mjs +109 -81
- package/dist/web/Modal/Modal.js +84 -1
- package/dist/web/Modal/Modal.mjs +52 -49
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.js +232 -1
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.mjs +206 -125
- package/dist/web/Pagination/Pagination.js +328 -1
- package/dist/web/Pagination/Pagination.mjs +254 -178
- package/dist/web/ProductField/ProductField.js +272 -1
- package/dist/web/ProductField/ProductField.mjs +190 -143
- package/dist/web/ProductField/arrow-up.svg.js +3 -1
- package/dist/web/ProductField/arrow-up.svg.mjs +2 -2
- package/dist/web/ProductField/checkbox-no.svg.js +3 -1
- package/dist/web/ProductField/checkbox-no.svg.mjs +2 -2
- package/dist/web/ProductField/checkbox-ok.svg.js +3 -1
- package/dist/web/ProductField/checkbox-ok.svg.mjs +2 -2
- package/dist/web/ProductField/no_data_light.svg.js +3 -1
- package/dist/web/ProductField/no_data_light.svg.mjs +2 -2
- package/dist/web/ProductField/search.svg.js +3 -1
- package/dist/web/ProductField/search.svg.mjs +2 -2
- package/dist/web/ProductField/sort.svg.js +3 -1
- package/dist/web/ProductField/sort.svg.mjs +2 -2
- package/dist/web/SkuInputCard/SkuInputCard.js +276 -1
- package/dist/web/SkuInputCard/SkuInputCard.mjs +188 -149
- package/dist/web/SkuInputCard/spin_loading_red.gif.js +3 -1
- package/dist/web/SkuInputCard/spin_loading_red.gif.mjs +2 -2
- package/dist/web/Switch/Switch.js +70 -1
- package/dist/web/Switch/Switch.mjs +47 -37
- package/dist/web/Table/BTable.js +950 -1
- package/dist/web/Table/BTable.mjs +771 -519
- package/dist/web/Table/Column.js +5 -1
- package/dist/web/Table/Column.mjs +2 -2
- package/dist/web/Table/ColumnGroup.js +5 -1
- package/dist/web/Table/ColumnGroup.mjs +2 -2
- package/dist/web/Table/utils/columns.js +48 -1
- package/dist/web/Table/utils/columns.mjs +35 -30
- package/dist/web/Table/utils/sortFilter.js +84 -1
- package/dist/web/Table/utils/sortFilter.mjs +73 -52
- package/dist/web/Tabs/BTabs.js +150 -1
- package/dist/web/Tabs/BTabs.mjs +118 -98
- package/dist/web/Tabs/TabPane.js +8 -1
- package/dist/web/Tabs/TabPane.mjs +4 -4
- package/dist/web/Tooltip/ConfirmTooltip.js +26 -1
- package/dist/web/Tooltip/ConfirmTooltip.mjs +20 -19
- package/dist/web/Tooltip/ContentTooltip.js +94 -1
- package/dist/web/Tooltip/ContentTooltip.mjs +72 -62
- package/dist/web/Tooltip/ProgressTooltip.js +36 -1
- package/dist/web/Tooltip/ProgressTooltip.mjs +22 -20
- package/dist/web/Tooltip/TooltipWrapper.js +12 -1
- package/dist/web/Tooltip/TooltipWrapper.mjs +8 -8
- package/dist/web/Tooltip/useAutoPlacement.js +41 -1
- package/dist/web/Tooltip/useAutoPlacement.mjs +34 -25
- package/dist/web.js +51 -1
- package/dist/web.mjs +49 -49
- package/package.json +1 -1
package/dist/web/Tabs/BTabs.mjs
CHANGED
|
@@ -1,130 +1,150 @@
|
|
|
1
|
-
import { jsxs
|
|
2
|
-
import { useRef
|
|
3
|
-
import { TabPane
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState, useEffect, useMemo, Children, isValidElement } from "react";
|
|
3
|
+
import { TabPane } from "./TabPane.mjs";
|
|
4
4
|
/* empty css */
|
|
5
|
-
function
|
|
6
|
-
return
|
|
5
|
+
function classNames(...values) {
|
|
6
|
+
return values.filter(Boolean).join(" ");
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
const [
|
|
10
|
-
return [
|
|
8
|
+
function useMergedState(defaultValue, value) {
|
|
9
|
+
const [innerValue, setInnerValue] = useState(defaultValue);
|
|
10
|
+
return [value === void 0 ? innerValue : value, setInnerValue];
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
return
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
function useLegacyItems(items, children) {
|
|
13
|
+
return useMemo(() => {
|
|
14
|
+
if (items) return items.filter((item) => Boolean(item && typeof item === "object" && "key" in item));
|
|
15
|
+
return Children.toArray(children).flatMap((child) => {
|
|
16
|
+
if (!isValidElement(child)) return [];
|
|
17
|
+
const { tab, tabKey, ...restProps } = child.props;
|
|
18
|
+
const key = tabKey ?? child.key;
|
|
19
|
+
return key === null ? [] : [{ ...restProps, key: String(key), label: tab }];
|
|
20
|
+
});
|
|
21
|
+
}, [children, items]);
|
|
18
22
|
}
|
|
19
|
-
function
|
|
20
|
-
active
|
|
21
|
-
id
|
|
22
|
-
item
|
|
23
|
-
onClick
|
|
24
|
-
onKeyDown
|
|
25
|
-
tabCount
|
|
26
|
-
tabIndex
|
|
23
|
+
function TabNode({
|
|
24
|
+
active,
|
|
25
|
+
id,
|
|
26
|
+
item,
|
|
27
|
+
onClick,
|
|
28
|
+
onKeyDown,
|
|
29
|
+
tabCount,
|
|
30
|
+
tabIndex
|
|
27
31
|
}) {
|
|
28
|
-
return /* @__PURE__ */
|
|
32
|
+
return /* @__PURE__ */ jsxs(
|
|
29
33
|
"button",
|
|
30
34
|
{
|
|
31
|
-
"aria-controls": `${
|
|
32
|
-
"aria-disabled":
|
|
33
|
-
"aria-selected":
|
|
34
|
-
className:
|
|
35
|
-
disabled:
|
|
36
|
-
id: `${
|
|
37
|
-
onClick
|
|
38
|
-
onKeyDown
|
|
35
|
+
"aria-controls": `${id}-panel-${item.key}`,
|
|
36
|
+
"aria-disabled": item.disabled,
|
|
37
|
+
"aria-selected": active,
|
|
38
|
+
className: classNames("bj-tabs__tab", active && "bj-tabs__tab--active", item.disabled && "bj-tabs__tab--disabled"),
|
|
39
|
+
disabled: item.disabled,
|
|
40
|
+
id: `${id}-tab-${item.key}`,
|
|
41
|
+
onClick,
|
|
42
|
+
onKeyDown,
|
|
39
43
|
role: "tab",
|
|
40
|
-
tabIndex:
|
|
44
|
+
tabIndex: item.disabled ? -1 : active ? 0 : -1,
|
|
41
45
|
type: "button",
|
|
42
46
|
children: [
|
|
43
|
-
/* @__PURE__ */
|
|
44
|
-
/* @__PURE__ */
|
|
47
|
+
/* @__PURE__ */ jsx("span", { className: "bj-tabs__tab-btn", children: item.label }),
|
|
48
|
+
/* @__PURE__ */ jsx("span", { className: "bj-tabs__sr-only", children: `Tab ${tabIndex + 1} of ${tabCount}` })
|
|
45
49
|
]
|
|
46
50
|
}
|
|
47
51
|
);
|
|
48
52
|
}
|
|
49
|
-
function
|
|
50
|
-
return /* @__PURE__ */
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
+
function TabPanelList({ activeKey, id, items }) {
|
|
54
|
+
return /* @__PURE__ */ jsx("div", { className: "bj-tabs__content-holder", children: /* @__PURE__ */ jsx("div", { className: "bj-tabs__content", children: items.map((item) => {
|
|
55
|
+
const active = item.key === activeKey;
|
|
56
|
+
if (!active && !item.forceRender) return null;
|
|
57
|
+
return /* @__PURE__ */ jsx(
|
|
53
58
|
"div",
|
|
54
59
|
{
|
|
55
|
-
"aria-hidden": !
|
|
56
|
-
"aria-labelledby": `${
|
|
57
|
-
className:
|
|
58
|
-
id: `${
|
|
60
|
+
"aria-hidden": !active,
|
|
61
|
+
"aria-labelledby": `${id}-tab-${item.key}`,
|
|
62
|
+
className: classNames("bj-tabs__tabpane", active && "bj-tabs__tabpane--active", item.className),
|
|
63
|
+
id: `${id}-panel-${item.key}`,
|
|
59
64
|
role: "tabpanel",
|
|
60
|
-
style:
|
|
61
|
-
tabIndex:
|
|
62
|
-
children:
|
|
65
|
+
style: item.style,
|
|
66
|
+
tabIndex: active ? 0 : -1,
|
|
67
|
+
children: item.children
|
|
63
68
|
},
|
|
64
|
-
|
|
69
|
+
item.key
|
|
65
70
|
);
|
|
66
71
|
}) }) });
|
|
67
72
|
}
|
|
68
|
-
function
|
|
69
|
-
activeKey
|
|
70
|
-
children
|
|
71
|
-
centered
|
|
72
|
-
className
|
|
73
|
-
defaultActiveKey
|
|
74
|
-
id
|
|
75
|
-
items
|
|
76
|
-
onChange
|
|
77
|
-
onTabClick
|
|
78
|
-
style
|
|
79
|
-
tabBarGutter
|
|
80
|
-
tabBarStyle
|
|
81
|
-
tabPosition
|
|
82
|
-
type
|
|
73
|
+
function BTabs({
|
|
74
|
+
activeKey,
|
|
75
|
+
children,
|
|
76
|
+
centered,
|
|
77
|
+
className,
|
|
78
|
+
defaultActiveKey,
|
|
79
|
+
id,
|
|
80
|
+
items,
|
|
81
|
+
onChange,
|
|
82
|
+
onTabClick,
|
|
83
|
+
style,
|
|
84
|
+
tabBarGutter,
|
|
85
|
+
tabBarStyle,
|
|
86
|
+
tabPosition = "top",
|
|
87
|
+
type = "line"
|
|
83
88
|
}) {
|
|
84
|
-
const
|
|
89
|
+
const tabs = useLegacyItems(items, children);
|
|
90
|
+
const generatedIdRef = useRef(`bj-tabs-${Math.random().toString(36).slice(2, 10)}`);
|
|
91
|
+
const mergedId = id ?? generatedIdRef.current;
|
|
92
|
+
const [mergedActiveKey, setMergedActiveKey] = useMergedState(
|
|
85
93
|
() => {
|
|
86
|
-
var
|
|
87
|
-
return
|
|
94
|
+
var _a;
|
|
95
|
+
return defaultActiveKey ?? ((_a = tabs[0]) == null ? void 0 : _a.key);
|
|
88
96
|
},
|
|
89
|
-
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
97
|
+
activeKey
|
|
98
|
+
);
|
|
99
|
+
const [activeIndex, setActiveIndex] = useState(() => tabs.findIndex((tab) => tab.key === mergedActiveKey));
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
var _a;
|
|
102
|
+
let nextActiveIndex = tabs.findIndex((tab) => tab.key === mergedActiveKey);
|
|
103
|
+
if (nextActiveIndex === -1) {
|
|
104
|
+
nextActiveIndex = Math.max(0, Math.min(activeIndex, tabs.length - 1));
|
|
105
|
+
setMergedActiveKey((_a = tabs[nextActiveIndex]) == null ? void 0 : _a.key);
|
|
106
|
+
}
|
|
107
|
+
setActiveIndex(nextActiveIndex);
|
|
108
|
+
}, [activeIndex, mergedActiveKey, setMergedActiveKey, tabs]);
|
|
109
|
+
const activateTab = (key, event) => {
|
|
110
|
+
onTabClick == null ? void 0 : onTabClick(key, event);
|
|
111
|
+
if (key === mergedActiveKey) return;
|
|
112
|
+
setMergedActiveKey(key);
|
|
113
|
+
onChange == null ? void 0 : onChange(key);
|
|
114
|
+
};
|
|
115
|
+
const moveFocus = (event, index) => {
|
|
116
|
+
var _a;
|
|
117
|
+
const isVertical = tabPosition === "left" || tabPosition === "right";
|
|
118
|
+
const nextKey = isVertical ? event.key === "ArrowDown" ? 1 : event.key === "ArrowUp" ? -1 : 0 : event.key === "ArrowRight" ? 1 : event.key === "ArrowLeft" ? -1 : 0;
|
|
119
|
+
if (!nextKey) return;
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
const enabledTabs = tabs.filter((tab) => !tab.disabled);
|
|
122
|
+
const enabledIndex = enabledTabs.findIndex((tab) => {
|
|
123
|
+
var _a2;
|
|
124
|
+
return tab.key === ((_a2 = tabs[index]) == null ? void 0 : _a2.key);
|
|
125
|
+
});
|
|
126
|
+
const nextTab = enabledTabs[(enabledIndex + nextKey + enabledTabs.length) % enabledTabs.length];
|
|
127
|
+
(_a = document.getElementById(`${mergedId}-tab-${nextTab == null ? void 0 : nextTab.key}`)) == null ? void 0 : _a.focus();
|
|
108
128
|
};
|
|
109
|
-
return /* @__PURE__ */
|
|
110
|
-
/* @__PURE__ */
|
|
111
|
-
|
|
129
|
+
return /* @__PURE__ */ jsxs("div", { className: classNames("bj-tabs", `bj-tabs--${tabPosition}`, `bj-tabs--${type}`, centered && "bj-tabs--centered", className), style, children: [
|
|
130
|
+
/* @__PURE__ */ jsx("div", { className: "bj-tabs__nav", role: "tablist", style: tabBarStyle, children: /* @__PURE__ */ jsx("div", { className: "bj-tabs__nav-wrap", children: /* @__PURE__ */ jsx("div", { className: "bj-tabs__nav-list", children: tabs.map((item, index) => /* @__PURE__ */ jsx(
|
|
131
|
+
TabNode,
|
|
112
132
|
{
|
|
113
|
-
active:
|
|
114
|
-
id:
|
|
115
|
-
item
|
|
116
|
-
onClick: (
|
|
117
|
-
onKeyDown: (
|
|
118
|
-
tabCount:
|
|
119
|
-
tabIndex:
|
|
133
|
+
active: item.key === mergedActiveKey,
|
|
134
|
+
id: mergedId,
|
|
135
|
+
item,
|
|
136
|
+
onClick: (event) => activateTab(item.key, event),
|
|
137
|
+
onKeyDown: (event) => moveFocus(event, index),
|
|
138
|
+
tabCount: tabs.length,
|
|
139
|
+
tabIndex: index
|
|
120
140
|
},
|
|
121
|
-
|
|
141
|
+
item.key
|
|
122
142
|
)) }) }) }),
|
|
123
|
-
/* @__PURE__ */
|
|
143
|
+
/* @__PURE__ */ jsx(TabPanelList, { activeKey: mergedActiveKey, id: mergedId, items: tabs })
|
|
124
144
|
] });
|
|
125
145
|
}
|
|
126
|
-
|
|
146
|
+
BTabs.TabPane = TabPane;
|
|
127
147
|
export {
|
|
128
|
-
|
|
129
|
-
|
|
148
|
+
TabPane,
|
|
149
|
+
BTabs as default
|
|
130
150
|
};
|
package/dist/web/Tabs/TabPane.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
function TabPane(_) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
TabPane.displayName = "BTabs.TabPane";
|
|
7
|
+
exports.TabPane = TabPane;
|
|
8
|
+
exports.default = TabPane;
|
|
@@ -1 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
;/* empty css */
|
|
4
|
+
const useAutoPlacement = require("./useAutoPlacement.js");
|
|
5
|
+
function ConfirmTooltip({
|
|
6
|
+
placement = "top",
|
|
7
|
+
title = "是否使用当前自动翻译的英文?",
|
|
8
|
+
okText = "使用",
|
|
9
|
+
cancelText = "我去改改",
|
|
10
|
+
onOk,
|
|
11
|
+
onCancel,
|
|
12
|
+
className,
|
|
13
|
+
style
|
|
14
|
+
}) {
|
|
15
|
+
const [activePlacement, popupRef] = useAutoPlacement.useAutoPlacement(placement);
|
|
16
|
+
const popupCls = ["tooltip-popup", `tooltip-popup--${activePlacement}`, className].filter(Boolean).join(" ");
|
|
17
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: popupRef, className: popupCls, style, children: [
|
|
18
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `tooltip-arrow tooltip-arrow--${activePlacement}` }),
|
|
19
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "tooltip-confirm__title", children: title }),
|
|
20
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tooltip-confirm__actions", children: [
|
|
21
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { className: "tooltip-confirm__cancel", onClick: onCancel, children: cancelText }),
|
|
22
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { className: "tooltip-confirm__ok", onClick: onOk, children: okText })
|
|
23
|
+
] })
|
|
24
|
+
] });
|
|
25
|
+
}
|
|
26
|
+
module.exports = ConfirmTooltip;
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import { jsxs
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
/* empty css */
|
|
3
|
-
import { useAutoPlacement
|
|
4
|
-
function
|
|
5
|
-
placement
|
|
6
|
-
title
|
|
7
|
-
okText
|
|
8
|
-
cancelText
|
|
9
|
-
onOk
|
|
10
|
-
onCancel
|
|
11
|
-
className
|
|
12
|
-
style
|
|
3
|
+
import { useAutoPlacement } from "./useAutoPlacement.mjs";
|
|
4
|
+
function ConfirmTooltip({
|
|
5
|
+
placement = "top",
|
|
6
|
+
title = "是否使用当前自动翻译的英文?",
|
|
7
|
+
okText = "使用",
|
|
8
|
+
cancelText = "我去改改",
|
|
9
|
+
onOk,
|
|
10
|
+
onCancel,
|
|
11
|
+
className,
|
|
12
|
+
style
|
|
13
13
|
}) {
|
|
14
|
-
const [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/* @__PURE__ */
|
|
18
|
-
/* @__PURE__ */
|
|
19
|
-
|
|
20
|
-
/* @__PURE__ */
|
|
14
|
+
const [activePlacement, popupRef] = useAutoPlacement(placement);
|
|
15
|
+
const popupCls = ["tooltip-popup", `tooltip-popup--${activePlacement}`, className].filter(Boolean).join(" ");
|
|
16
|
+
return /* @__PURE__ */ jsxs("div", { ref: popupRef, className: popupCls, style, children: [
|
|
17
|
+
/* @__PURE__ */ jsx("div", { className: `tooltip-arrow tooltip-arrow--${activePlacement}` }),
|
|
18
|
+
/* @__PURE__ */ jsx("p", { className: "tooltip-confirm__title", children: title }),
|
|
19
|
+
/* @__PURE__ */ jsxs("div", { className: "tooltip-confirm__actions", children: [
|
|
20
|
+
/* @__PURE__ */ jsx("button", { className: "tooltip-confirm__cancel", onClick: onCancel, children: cancelText }),
|
|
21
|
+
/* @__PURE__ */ jsx("button", { className: "tooltip-confirm__ok", onClick: onOk, children: okText })
|
|
21
22
|
] })
|
|
22
23
|
] });
|
|
23
24
|
}
|
|
24
25
|
export {
|
|
25
|
-
|
|
26
|
+
ConfirmTooltip as default
|
|
26
27
|
};
|
|
@@ -1 +1,94 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const reactDom = require("react-dom");
|
|
5
|
+
const antd = require("antd");
|
|
6
|
+
;/* empty css */
|
|
7
|
+
const useAutoPlacement = require("./useAutoPlacement.js");
|
|
8
|
+
function BTooltip({
|
|
9
|
+
children,
|
|
10
|
+
placement = "top",
|
|
11
|
+
content = "这里是提示内容,可以包含更多详细信息。",
|
|
12
|
+
variant = "default",
|
|
13
|
+
className,
|
|
14
|
+
style,
|
|
15
|
+
getPopupContainer,
|
|
16
|
+
getAnchorElement,
|
|
17
|
+
color,
|
|
18
|
+
fontColor,
|
|
19
|
+
autoAdjustOverflow = true
|
|
20
|
+
}) {
|
|
21
|
+
const [activePlacement, popupRef] = useAutoPlacement.useAutoPlacement(placement);
|
|
22
|
+
const anchorRef = react.useRef(null);
|
|
23
|
+
const [portalStyle, setPortalStyle] = react.useState();
|
|
24
|
+
const popupCls = [
|
|
25
|
+
"tooltip-popup",
|
|
26
|
+
"tooltip-popup--content",
|
|
27
|
+
`tooltip-popup--${activePlacement}`,
|
|
28
|
+
variant !== "default" ? `tooltip-popup--${variant}` : "",
|
|
29
|
+
className
|
|
30
|
+
].filter(Boolean).join(" ");
|
|
31
|
+
const arrowCls = [
|
|
32
|
+
"tooltip-arrow",
|
|
33
|
+
`tooltip-arrow--${activePlacement}`,
|
|
34
|
+
variant === "tinted" ? "tooltip-arrow--tinted-bg" : ""
|
|
35
|
+
].filter(Boolean).join(" ");
|
|
36
|
+
const mergedPopupStyle = {
|
|
37
|
+
...style,
|
|
38
|
+
...color ? { backgroundColor: color } : {},
|
|
39
|
+
...fontColor ? { color: fontColor } : {}
|
|
40
|
+
};
|
|
41
|
+
const arrowStyle = color ? { backgroundColor: color, borderColor: color } : void 0;
|
|
42
|
+
const contentStyle = fontColor ? { color: fontColor } : void 0;
|
|
43
|
+
const customContent = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `${popupCls} tooltip-popup--antd`, style: mergedPopupStyle, children: [
|
|
44
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: arrowCls, style: arrowStyle }),
|
|
45
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bu-tooltip-content__text", style: contentStyle, children: content })
|
|
46
|
+
] });
|
|
47
|
+
if (children) {
|
|
48
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
49
|
+
antd.Tooltip,
|
|
50
|
+
{
|
|
51
|
+
title: customContent,
|
|
52
|
+
placement: placement === "auto" ? "top" : placement,
|
|
53
|
+
arrowPointAtCenter: true,
|
|
54
|
+
autoAdjustOverflow,
|
|
55
|
+
getPopupContainer,
|
|
56
|
+
overlayClassName: "bu-content-tooltip",
|
|
57
|
+
children
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
const popup = /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: popupRef, className: popupCls, style: mergedPopupStyle, children: [
|
|
62
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: arrowCls, style: arrowStyle }),
|
|
63
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bu-tooltip-content__text", style: contentStyle, children: content })
|
|
64
|
+
] });
|
|
65
|
+
react.useLayoutEffect(() => {
|
|
66
|
+
if (!getPopupContainer || !anchorRef.current) return;
|
|
67
|
+
const anchor = (getAnchorElement == null ? void 0 : getAnchorElement()) ?? anchorRef.current.parentElement;
|
|
68
|
+
if (!anchor) return;
|
|
69
|
+
const rect = anchor.getBoundingClientRect();
|
|
70
|
+
setPortalStyle({
|
|
71
|
+
position: "fixed",
|
|
72
|
+
left: rect.left + rect.width / 2,
|
|
73
|
+
top: rect.top,
|
|
74
|
+
right: "auto",
|
|
75
|
+
bottom: "auto",
|
|
76
|
+
transform: "translate(-50%, calc(-100% - 16px))"
|
|
77
|
+
});
|
|
78
|
+
}, [getAnchorElement, getPopupContainer]);
|
|
79
|
+
if (getPopupContainer && typeof document !== "undefined") {
|
|
80
|
+
const container = getPopupContainer();
|
|
81
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { ref: anchorRef, className: "tooltip-portal-anchor" }),
|
|
83
|
+
portalStyle && reactDom.createPortal(
|
|
84
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { ref: popupRef, className: popupCls, style: { ...mergedPopupStyle, ...portalStyle }, children: [
|
|
85
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: arrowCls, style: arrowStyle }),
|
|
86
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bu-tooltip-content__text", style: contentStyle, children: content })
|
|
87
|
+
] }),
|
|
88
|
+
container
|
|
89
|
+
)
|
|
90
|
+
] });
|
|
91
|
+
}
|
|
92
|
+
return popup;
|
|
93
|
+
}
|
|
94
|
+
module.exports = BTooltip;
|
|
@@ -1,85 +1,95 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import { useRef
|
|
3
|
-
import { createPortal
|
|
4
|
-
import { Tooltip
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState, useLayoutEffect } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import { Tooltip } from "antd";
|
|
5
5
|
/* empty css */
|
|
6
|
-
import { useAutoPlacement
|
|
7
|
-
function
|
|
8
|
-
children
|
|
9
|
-
placement
|
|
10
|
-
content
|
|
11
|
-
variant
|
|
12
|
-
className
|
|
13
|
-
style
|
|
14
|
-
getPopupContainer
|
|
15
|
-
getAnchorElement
|
|
16
|
-
color
|
|
17
|
-
fontColor
|
|
18
|
-
autoAdjustOverflow
|
|
6
|
+
import { useAutoPlacement } from "./useAutoPlacement.mjs";
|
|
7
|
+
function BTooltip({
|
|
8
|
+
children,
|
|
9
|
+
placement = "top",
|
|
10
|
+
content = "这里是提示内容,可以包含更多详细信息。",
|
|
11
|
+
variant = "default",
|
|
12
|
+
className,
|
|
13
|
+
style,
|
|
14
|
+
getPopupContainer,
|
|
15
|
+
getAnchorElement,
|
|
16
|
+
color,
|
|
17
|
+
fontColor,
|
|
18
|
+
autoAdjustOverflow = true
|
|
19
19
|
}) {
|
|
20
|
-
const [
|
|
20
|
+
const [activePlacement, popupRef] = useAutoPlacement(placement);
|
|
21
|
+
const anchorRef = useRef(null);
|
|
22
|
+
const [portalStyle, setPortalStyle] = useState();
|
|
23
|
+
const popupCls = [
|
|
21
24
|
"tooltip-popup",
|
|
22
25
|
"tooltip-popup--content",
|
|
23
|
-
`tooltip-popup--${
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
].filter(Boolean).join(" ")
|
|
26
|
+
`tooltip-popup--${activePlacement}`,
|
|
27
|
+
variant !== "default" ? `tooltip-popup--${variant}` : "",
|
|
28
|
+
className
|
|
29
|
+
].filter(Boolean).join(" ");
|
|
30
|
+
const arrowCls = [
|
|
27
31
|
"tooltip-arrow",
|
|
28
|
-
`tooltip-arrow--${
|
|
29
|
-
|
|
30
|
-
].filter(Boolean).join(" ")
|
|
31
|
-
|
|
32
|
-
...
|
|
33
|
-
...
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
`tooltip-arrow--${activePlacement}`,
|
|
33
|
+
variant === "tinted" ? "tooltip-arrow--tinted-bg" : ""
|
|
34
|
+
].filter(Boolean).join(" ");
|
|
35
|
+
const mergedPopupStyle = {
|
|
36
|
+
...style,
|
|
37
|
+
...color ? { backgroundColor: color } : {},
|
|
38
|
+
...fontColor ? { color: fontColor } : {}
|
|
39
|
+
};
|
|
40
|
+
const arrowStyle = color ? { backgroundColor: color, borderColor: color } : void 0;
|
|
41
|
+
const contentStyle = fontColor ? { color: fontColor } : void 0;
|
|
42
|
+
const customContent = /* @__PURE__ */ jsxs("div", { className: `${popupCls} tooltip-popup--antd`, style: mergedPopupStyle, children: [
|
|
43
|
+
/* @__PURE__ */ jsx("div", { className: arrowCls, style: arrowStyle }),
|
|
44
|
+
/* @__PURE__ */ jsx("div", { className: "bu-tooltip-content__text", style: contentStyle, children: content })
|
|
37
45
|
] });
|
|
38
|
-
if (
|
|
39
|
-
return /* @__PURE__ */
|
|
40
|
-
|
|
46
|
+
if (children) {
|
|
47
|
+
return /* @__PURE__ */ jsx(
|
|
48
|
+
Tooltip,
|
|
41
49
|
{
|
|
42
|
-
title:
|
|
43
|
-
placement:
|
|
44
|
-
arrowPointAtCenter:
|
|
45
|
-
autoAdjustOverflow
|
|
46
|
-
getPopupContainer
|
|
50
|
+
title: customContent,
|
|
51
|
+
placement: placement === "auto" ? "top" : placement,
|
|
52
|
+
arrowPointAtCenter: true,
|
|
53
|
+
autoAdjustOverflow,
|
|
54
|
+
getPopupContainer,
|
|
47
55
|
overlayClassName: "bu-content-tooltip",
|
|
48
|
-
children
|
|
56
|
+
children
|
|
49
57
|
}
|
|
50
58
|
);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
/* @__PURE__ */
|
|
59
|
+
}
|
|
60
|
+
const popup = /* @__PURE__ */ jsxs("div", { ref: popupRef, className: popupCls, style: mergedPopupStyle, children: [
|
|
61
|
+
/* @__PURE__ */ jsx("div", { className: arrowCls, style: arrowStyle }),
|
|
62
|
+
/* @__PURE__ */ jsx("div", { className: "bu-tooltip-content__text", style: contentStyle, children: content })
|
|
54
63
|
] });
|
|
55
|
-
|
|
56
|
-
if (!
|
|
57
|
-
const
|
|
58
|
-
if (!
|
|
59
|
-
const
|
|
60
|
-
|
|
64
|
+
useLayoutEffect(() => {
|
|
65
|
+
if (!getPopupContainer || !anchorRef.current) return;
|
|
66
|
+
const anchor = (getAnchorElement == null ? void 0 : getAnchorElement()) ?? anchorRef.current.parentElement;
|
|
67
|
+
if (!anchor) return;
|
|
68
|
+
const rect = anchor.getBoundingClientRect();
|
|
69
|
+
setPortalStyle({
|
|
61
70
|
position: "fixed",
|
|
62
|
-
left:
|
|
63
|
-
top:
|
|
71
|
+
left: rect.left + rect.width / 2,
|
|
72
|
+
top: rect.top,
|
|
64
73
|
right: "auto",
|
|
65
74
|
bottom: "auto",
|
|
66
75
|
transform: "translate(-50%, calc(-100% - 16px))"
|
|
67
76
|
});
|
|
68
|
-
}, [
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
/* @__PURE__ */
|
|
77
|
+
}, [getAnchorElement, getPopupContainer]);
|
|
78
|
+
if (getPopupContainer && typeof document !== "undefined") {
|
|
79
|
+
const container = getPopupContainer();
|
|
80
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
81
|
+
/* @__PURE__ */ jsx("span", { ref: anchorRef, className: "tooltip-portal-anchor" }),
|
|
82
|
+
portalStyle && createPortal(
|
|
83
|
+
/* @__PURE__ */ jsxs("div", { ref: popupRef, className: popupCls, style: { ...mergedPopupStyle, ...portalStyle }, children: [
|
|
84
|
+
/* @__PURE__ */ jsx("div", { className: arrowCls, style: arrowStyle }),
|
|
85
|
+
/* @__PURE__ */ jsx("div", { className: "bu-tooltip-content__text", style: contentStyle, children: content })
|
|
76
86
|
] }),
|
|
77
|
-
|
|
87
|
+
container
|
|
78
88
|
)
|
|
79
89
|
] });
|
|
80
90
|
}
|
|
81
|
-
return
|
|
91
|
+
return popup;
|
|
82
92
|
}
|
|
83
93
|
export {
|
|
84
|
-
|
|
94
|
+
BTooltip as default
|
|
85
95
|
};
|