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