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,253 +1,301 @@
1
- import { jsxs as T, jsx as r } from "react/jsx-runtime";
2
- import { useState as E, useRef as L, useCallback as Q, useLayoutEffect as $, useEffect as U } from "react";
3
- import { createPortal as Z } from "react-dom";
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { useState, useRef, useCallback, useLayoutEffect, useEffect } from "react";
3
+ import { createPortal } from "react-dom";
4
4
  /* empty css */
5
5
  /* empty css */
6
- import X from "../Tooltip/ContentTooltip.mjs";
7
- import Y from "../Tooltip/TooltipWrapper.mjs";
8
- function A({
9
- text: a,
10
- spanClassName: p,
11
- wrapperStyle: d,
12
- placement: h = "top",
13
- getPopupContainer: f,
14
- trailing: u
6
+ import BTooltip from "../Tooltip/ContentTooltip.mjs";
7
+ import TooltipWrapper from "../Tooltip/TooltipWrapper.mjs";
8
+ function TruncatedTooltip({
9
+ text,
10
+ spanClassName,
11
+ wrapperStyle,
12
+ placement = "top",
13
+ getPopupContainer,
14
+ trailing
15
15
  }) {
16
- const [i, m] = E(!1), N = L(null), x = L(null), [o, w] = E(null);
17
- function b() {
18
- var g;
19
- const y = x.current;
20
- y && y.scrollWidth > y.offsetWidth && (w(((g = N.current) == null ? void 0 : g.getBoundingClientRect()) ?? null), m(!0));
16
+ const [visible, setVisible] = useState(false);
17
+ const wrapperRef = useRef(null);
18
+ const spanRef = useRef(null);
19
+ const [anchorRect, setAnchorRect] = useState(null);
20
+ function handleMouseEnter() {
21
+ var _a;
22
+ const el = spanRef.current;
23
+ if (el && el.scrollWidth > el.offsetWidth) {
24
+ setAnchorRect(((_a = wrapperRef.current) == null ? void 0 : _a.getBoundingClientRect()) ?? null);
25
+ setVisible(true);
26
+ }
21
27
  }
22
- return /* @__PURE__ */ T(Y, { ref: N, style: d, children: [
23
- /* @__PURE__ */ r(
28
+ return /* @__PURE__ */ jsxs(TooltipWrapper, { ref: wrapperRef, style: wrapperStyle, children: [
29
+ /* @__PURE__ */ jsx(
24
30
  "span",
25
31
  {
26
- ref: x,
27
- className: p,
28
- onMouseEnter: b,
29
- onMouseLeave: () => m(!1),
30
- children: a
32
+ ref: spanRef,
33
+ className: spanClassName,
34
+ onMouseEnter: handleMouseEnter,
35
+ onMouseLeave: () => setVisible(false),
36
+ children: text
31
37
  }
32
38
  ),
33
- u,
34
- i && o && Z(
35
- /* @__PURE__ */ r(
39
+ trailing,
40
+ visible && anchorRect && createPortal(
41
+ /* @__PURE__ */ jsx(
36
42
  "span",
37
43
  {
38
44
  style: {
39
45
  position: "fixed",
40
- top: o.top,
41
- left: o.left,
42
- width: o.width,
43
- height: o.height,
46
+ top: anchorRect.top,
47
+ left: anchorRect.left,
48
+ width: anchorRect.width,
49
+ height: anchorRect.height,
44
50
  display: "block",
45
51
  pointerEvents: "none",
46
52
  zIndex: 9999999999
47
53
  },
48
- children: /* @__PURE__ */ r(X, { content: a, placement: h, className: "bu-category-dropdown__tooltip" })
54
+ children: /* @__PURE__ */ jsx(BTooltip, { content: text, placement, className: "bu-category-dropdown__tooltip" })
49
55
  }
50
56
  ),
51
- (f == null ? void 0 : f()) ?? document.body
57
+ (getPopupContainer == null ? void 0 : getPopupContainer()) ?? document.body
52
58
  )
53
59
  ] });
54
60
  }
55
- function P() {
56
- return /* @__PURE__ */ r("svg", { viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ r("path", { d: "M5.57345 8.828C5.41074 8.66528 5.41074 8.40152 5.57345 8.2388C5.73617 8.07608 5.99993 8.07608 6.16265 8.2388L10.0323 12.1084L13.8349 8.24124C13.9963 8.0772 14.26 8.07503 14.4241 8.23636C14.5881 8.39771 14.5903 8.66149 14.429 8.82555L10.5282 12.7924C10.2576 13.0675 9.81477 13.0694 9.54196 12.7966L5.57345 8.828Z", fill: "#333333" }) });
61
+ function ChevronDown() {
62
+ return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M5.57345 8.828C5.41074 8.66528 5.41074 8.40152 5.57345 8.2388C5.73617 8.07608 5.99993 8.07608 6.16265 8.2388L10.0323 12.1084L13.8349 8.24124C13.9963 8.0772 14.26 8.07503 14.4241 8.23636C14.5881 8.39771 14.5903 8.66149 14.429 8.82555L10.5282 12.7924C10.2576 13.0675 9.81477 13.0694 9.54196 12.7966L5.57345 8.828Z", fill: "#333333" }) });
57
63
  }
58
- function ee() {
64
+ function ChevronRight() {
59
65
  return (
60
66
  // <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
61
67
  // <path d="M6 3.5L10.5 8L6 12.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
62
68
  // </svg>
63
- /* @__PURE__ */ r("svg", { class: "icon", viewBox: "0 0 1024 1024", version: "1.1", xmlns: "http://www.w3.org/2000/svg", "p-id": "55697", children: /* @__PURE__ */ r("path", { d: "M451.854222 285.361778A21.333333 21.333333 0 1 0 421.688889 315.52l198.115555 198.122667-197.994666 194.702222a21.333333 21.333333 0 0 0 29.916444 30.414222l203.107556-199.722667a35.555556 35.555556 0 0 0 0.213333-50.488888L451.854222 285.354667z", "p-id": "55698" }) })
69
+ /* @__PURE__ */ jsx("svg", { class: "icon", viewBox: "0 0 1024 1024", version: "1.1", xmlns: "http://www.w3.org/2000/svg", "p-id": "55697", children: /* @__PURE__ */ jsx("path", { d: "M451.854222 285.361778A21.333333 21.333333 0 1 0 421.688889 315.52l198.115555 198.122667-197.994666 194.702222a21.333333 21.333333 0 0 0 29.916444 30.414222l203.107556-199.722667a35.555556 35.555556 0 0 0 0.213333-50.488888L451.854222 285.354667z", "p-id": "55698" }) })
64
70
  );
65
71
  }
66
- function te(a, p) {
67
- var f;
68
- const d = [a];
69
- let h = a;
70
- for (let u = 0; u < p.length; u++) {
71
- const i = h.find((m) => m.value === p[u]);
72
- if ((f = i == null ? void 0 : i.children) != null && f.length)
73
- d.push(i.children), h = i.children;
74
- else
72
+ function buildColumns(data, value) {
73
+ var _a;
74
+ const cols = [data];
75
+ let current = data;
76
+ for (let i = 0; i < value.length; i++) {
77
+ const selected = current.find((item) => item.value === value[i]);
78
+ if ((_a = selected == null ? void 0 : selected.children) == null ? void 0 : _a.length) {
79
+ cols.push(selected.children);
80
+ current = selected.children;
81
+ } else {
75
82
  break;
83
+ }
76
84
  }
77
- return d;
85
+ return cols;
78
86
  }
79
- function H(a, p) {
80
- const d = [];
81
- let h = a;
82
- for (const f of p) {
83
- const u = h.find((i) => i.value === f);
84
- if (!u) break;
85
- d.push(u), h = u.children ?? [];
87
+ function buildPath(data, value) {
88
+ const path = [];
89
+ let items = data;
90
+ for (const v of value) {
91
+ const found = items.find((x) => x.value === v);
92
+ if (!found) break;
93
+ path.push(found);
94
+ items = found.children ?? [];
86
95
  }
87
- return d;
96
+ return path;
88
97
  }
89
- function ae({
90
- data: a,
91
- value: p = [],
92
- onChange: d,
93
- placeholder: h = "请选择分类",
94
- disabled: f = !1,
95
- maxVisible: u = 6,
96
- className: i,
97
- style: m,
98
- getPopupContainer: N,
99
- dropdownStyle: x
98
+ function BuCategoryDropdown({
99
+ data,
100
+ value = [],
101
+ onChange,
102
+ placeholder = "请选择分类",
103
+ disabled = false,
104
+ maxVisible = 6,
105
+ className,
106
+ style,
107
+ getPopupContainer,
108
+ dropdownStyle: customDropdownStyle
100
109
  }) {
101
- const [o, w] = E(!1), [b, y] = E(p), g = L(null), j = L(null), S = L(null), z = L(!1), [D, q] = E({}), [B, F] = E(), C = Q(() => {
102
- var _;
103
- if (!g.current) return;
104
- const n = g.current.getBoundingClientRect();
105
- let e = 0, t = g.current.parentElement;
106
- for (; t && t !== document.documentElement; ) {
107
- const R = parseInt(window.getComputedStyle(t).zIndex, 10);
108
- if (!isNaN(R) && R > e && (e = R), t.parentElement)
109
- for (const v of t.parentElement.children) {
110
- if (v === t || !(v instanceof HTMLElement)) continue;
111
- const k = parseInt(window.getComputedStyle(v).zIndex, 10);
112
- !isNaN(k) && k > e && (e = k);
110
+ const [open, setOpen] = useState(false);
111
+ const [navValue, setNavValue] = useState(value);
112
+ const rootRef = useRef(null);
113
+ const dropdownRef = useRef(null);
114
+ const panelRef = useRef(null);
115
+ const wasOpenRef = useRef(false);
116
+ const [dropdownStyle, setDropdownStyle] = useState({});
117
+ const [colWidth, setColWidth] = useState();
118
+ const updatePosition = useCallback(() => {
119
+ var _a;
120
+ if (!rootRef.current) return;
121
+ const rect = rootRef.current.getBoundingClientRect();
122
+ let maxZ = 0;
123
+ let el = rootRef.current.parentElement;
124
+ while (el && el !== document.documentElement) {
125
+ const selfZ = parseInt(window.getComputedStyle(el).zIndex, 10);
126
+ if (!isNaN(selfZ) && selfZ > maxZ) maxZ = selfZ;
127
+ if (el.parentElement) {
128
+ for (const sibling of el.parentElement.children) {
129
+ if (sibling === el || !(sibling instanceof HTMLElement)) continue;
130
+ const sibZ = parseInt(window.getComputedStyle(sibling).zIndex, 10);
131
+ if (!isNaN(sibZ) && sibZ > maxZ) maxZ = sibZ;
113
132
  }
114
- t = t.parentElement;
133
+ }
134
+ el = el.parentElement;
115
135
  }
116
- const l = ((_ = S.current) == null ? void 0 : _.offsetHeight) ?? 0, s = window.innerHeight - n.bottom, c = n.top, M = l > 0 && s < l + 4 && c > s;
117
- q({
136
+ const panelHeight = ((_a = panelRef.current) == null ? void 0 : _a.offsetHeight) ?? 0;
137
+ const spaceBelow = window.innerHeight - rect.bottom;
138
+ const spaceAbove = rect.top;
139
+ const flipToTop = panelHeight > 0 && spaceBelow < panelHeight + 4 && spaceAbove > spaceBelow;
140
+ setDropdownStyle({
118
141
  position: "fixed",
119
- top: M ? n.top - l - 4 : n.bottom + 4,
120
- left: n.left,
121
- zIndex: e > 0 ? e + 10 : 1100,
122
- ...x
142
+ top: flipToTop ? rect.top - panelHeight - 4 : rect.bottom + 4,
143
+ left: rect.left,
144
+ zIndex: maxZ > 0 ? maxZ + 10 : 1100,
145
+ ...customDropdownStyle
123
146
  });
124
- }, [x]);
125
- $(() => {
126
- o && C();
127
- }, [o, b, C]), $(() => {
128
- const n = o && !z.current;
129
- if (z.current = o, !o || !S.current) return;
130
- const e = S.current.querySelectorAll(".bu-category-dropdown__col");
131
- e.forEach((s) => {
132
- s.style.width = "";
147
+ }, [customDropdownStyle]);
148
+ useLayoutEffect(() => {
149
+ if (open) {
150
+ updatePosition();
151
+ }
152
+ }, [open, navValue, updatePosition]);
153
+ useLayoutEffect(() => {
154
+ const justOpened = open && !wasOpenRef.current;
155
+ wasOpenRef.current = open;
156
+ if (!open || !panelRef.current) return;
157
+ const cols = panelRef.current.querySelectorAll(".bu-category-dropdown__col");
158
+ cols.forEach((col) => {
159
+ col.style.width = "";
160
+ });
161
+ let max = 0;
162
+ cols.forEach((col) => {
163
+ if (col.offsetWidth > max) max = col.offsetWidth;
133
164
  });
134
- let t = 0;
135
- e.forEach((s) => {
136
- s.offsetWidth > t && (t = s.offsetWidth);
165
+ const next = justOpened ? max : Math.max(colWidth ?? 0, max);
166
+ cols.forEach((col) => {
167
+ col.style.width = next ? `${next}px` : "";
137
168
  });
138
- const l = n ? t : Math.max(B ?? 0, t);
139
- e.forEach((s) => {
140
- s.style.width = l ? `${l}px` : "";
141
- }), l !== B && F(l || void 0);
142
- }, [o, b]), U(() => {
143
- if (!o) return;
144
- function n(t) {
145
- var s, c;
146
- const l = t.target;
147
- (s = g.current) != null && s.contains(l) || (c = j.current) != null && c.contains(l) || w(!1);
169
+ if (next !== colWidth) setColWidth(next || void 0);
170
+ }, [open, navValue]);
171
+ useEffect(() => {
172
+ if (!open) return;
173
+ function handleClickOutside(e) {
174
+ var _a, _b;
175
+ const target = e.target;
176
+ if (((_a = rootRef.current) == null ? void 0 : _a.contains(target)) || ((_b = dropdownRef.current) == null ? void 0 : _b.contains(target))) {
177
+ return;
178
+ }
179
+ setOpen(false);
148
180
  }
149
- function e() {
150
- w(!1);
181
+ function handleScroll() {
182
+ setOpen(false);
151
183
  }
152
- return document.addEventListener("mousedown", n), document.addEventListener("scroll", e, !0), window.addEventListener("resize", C), () => {
153
- document.removeEventListener("mousedown", n), document.removeEventListener("scroll", e, !0), window.removeEventListener("resize", C);
184
+ document.addEventListener("mousedown", handleClickOutside);
185
+ document.addEventListener("scroll", handleScroll, true);
186
+ window.addEventListener("resize", updatePosition);
187
+ return () => {
188
+ document.removeEventListener("mousedown", handleClickOutside);
189
+ document.removeEventListener("scroll", handleScroll, true);
190
+ window.removeEventListener("resize", updatePosition);
154
191
  };
155
- }, [o, C]);
156
- const O = H(a, p), W = O.length > 0, G = W ? O.map((n) => n.label).join(" / ") : null, V = te(a, b);
157
- function I(n, e) {
158
- var l;
159
- if (e.disabled) return;
160
- const t = b.slice(0, n + 1);
161
- if (t[n] = e.value, y(t), !((l = e.children) != null && l.length)) {
162
- const s = H(a, t);
163
- d == null || d(t, s), w(!1);
192
+ }, [open, updatePosition]);
193
+ const path = buildPath(data, value);
194
+ const hasValue = path.length > 0;
195
+ const triggerLabel = hasValue ? path.map((item) => item.label).join(" / ") : null;
196
+ const columns = buildColumns(data, navValue);
197
+ function handleSelect(colIndex, item) {
198
+ var _a;
199
+ if (item.disabled) return;
200
+ const newNavValue = navValue.slice(0, colIndex + 1);
201
+ newNavValue[colIndex] = item.value;
202
+ setNavValue(newNavValue);
203
+ if (!((_a = item.children) == null ? void 0 : _a.length)) {
204
+ const newPath = buildPath(data, newNavValue);
205
+ onChange == null ? void 0 : onChange(newNavValue, newPath);
206
+ setOpen(false);
164
207
  }
165
208
  }
166
- function J() {
167
- y(p), w(!0);
209
+ function handleOpen() {
210
+ setNavValue(value);
211
+ setOpen(true);
168
212
  }
169
- const K = [
213
+ const triggerClass = [
170
214
  "bu-category-dropdown__trigger",
171
- o ? "bu-category-dropdown__trigger--open" : "",
172
- W ? "bu-category-dropdown__trigger--has-value" : ""
215
+ open ? "bu-category-dropdown__trigger--open" : "",
216
+ hasValue ? "bu-category-dropdown__trigger--has-value" : ""
173
217
  ].filter(Boolean).join(" ");
174
- return /* @__PURE__ */ T(
218
+ return /* @__PURE__ */ jsxs(
175
219
  "div",
176
220
  {
177
- ref: g,
178
- className: `bu-category-dropdown${i ? ` ${i}` : ""}`,
179
- style: m,
221
+ ref: rootRef,
222
+ className: `bu-category-dropdown${className ? ` ${className}` : ""}`,
223
+ style,
180
224
  children: [
181
- /* @__PURE__ */ r(
225
+ /* @__PURE__ */ jsx(
182
226
  "button",
183
227
  {
184
228
  type: "button",
185
- className: K,
186
- disabled: f,
187
- onClick: () => o ? w(!1) : J(),
188
- children: /* @__PURE__ */ r(
189
- A,
229
+ className: triggerClass,
230
+ disabled,
231
+ onClick: () => open ? setOpen(false) : handleOpen(),
232
+ children: /* @__PURE__ */ jsx(
233
+ TruncatedTooltip,
190
234
  {
191
- text: G ?? h,
192
- spanClassName: `bu-category-dropdown__trigger-label${W ? "" : " bu-category-dropdown__trigger-label--placeholder"}`,
235
+ text: triggerLabel ?? placeholder,
236
+ spanClassName: `bu-category-dropdown__trigger-label${!hasValue ? " bu-category-dropdown__trigger-label--placeholder" : ""}`,
193
237
  wrapperStyle: { flex: 1, minWidth: 0, display: "flex", alignItems: "center", gap: 8 },
194
- getPopupContainer: N,
195
- trailing: /* @__PURE__ */ r("span", { className: `bu-category-dropdown__trigger-chevron${o ? " bu-category-dropdown__trigger-chevron--open" : ""}`, children: /* @__PURE__ */ r(P, {}) })
238
+ getPopupContainer,
239
+ trailing: /* @__PURE__ */ jsx("span", { className: `bu-category-dropdown__trigger-chevron${open ? " bu-category-dropdown__trigger-chevron--open" : ""}`, children: /* @__PURE__ */ jsx(ChevronDown, {}) })
196
240
  }
197
241
  )
198
242
  }
199
243
  ),
200
- o && Z(
201
- /* @__PURE__ */ r("div", { ref: j, style: D, className: "bu-category-dropdown__portal", children: /* @__PURE__ */ r("div", { className: "bu-category-dropdown__panel", ref: S, children: V.map((n, e) => {
202
- const t = n.length > u, l = e === V.length - 1, s = [
244
+ open && createPortal(
245
+ /* @__PURE__ */ jsx("div", { ref: dropdownRef, style: dropdownStyle, className: "bu-category-dropdown__portal", children: /* @__PURE__ */ jsx("div", { className: "bu-category-dropdown__panel", ref: panelRef, children: columns.map((col, colIndex) => {
246
+ const isScrollable = col.length > maxVisible;
247
+ const isLast = colIndex === columns.length - 1;
248
+ const colClass = [
203
249
  "bu-category-dropdown__col",
204
- e > 0 ? "bu-category-dropdown__col--indent" : "",
205
- t ? "bu-category-dropdown__col--scrollable" : "",
206
- l && e > 0 ? "bu-category-dropdown__col--last" : ""
250
+ colIndex > 0 ? "bu-category-dropdown__col--indent" : "",
251
+ isScrollable ? "bu-category-dropdown__col--scrollable" : "",
252
+ isLast && colIndex > 0 ? "bu-category-dropdown__col--last" : ""
207
253
  ].filter(Boolean).join(" ");
208
- return /* @__PURE__ */ T("div", { style: { display: "contents" }, children: [
209
- e > 0 && /* @__PURE__ */ r("div", { className: "bu-category-dropdown__divider" }),
210
- /* @__PURE__ */ r(
254
+ return /* @__PURE__ */ jsxs("div", { style: { display: "contents" }, children: [
255
+ colIndex > 0 && /* @__PURE__ */ jsx("div", { className: "bu-category-dropdown__divider" }),
256
+ /* @__PURE__ */ jsx(
211
257
  "div",
212
258
  {
213
- className: s,
214
- style: B ? { width: B } : void 0,
215
- onMouseEnter: t ? (c) => c.currentTarget.classList.add("bu-category-dropdown__col--scrollbar-visible") : void 0,
216
- onMouseLeave: t ? (c) => c.currentTarget.classList.remove("bu-category-dropdown__col--scrollbar-visible") : void 0,
217
- children: n.map((c) => {
218
- var v;
219
- const M = b[e] === c.value, _ = !!((v = c.children) != null && v.length), R = [
259
+ className: colClass,
260
+ style: colWidth ? { width: colWidth } : void 0,
261
+ onMouseEnter: isScrollable ? (e) => e.currentTarget.classList.add("bu-category-dropdown__col--scrollbar-visible") : void 0,
262
+ onMouseLeave: isScrollable ? (e) => e.currentTarget.classList.remove("bu-category-dropdown__col--scrollbar-visible") : void 0,
263
+ children: col.map((item) => {
264
+ var _a;
265
+ const isSelected = navValue[colIndex] === item.value;
266
+ const hasBranch = !!((_a = item.children) == null ? void 0 : _a.length);
267
+ const itemClass = [
220
268
  "bu-category-dropdown__item",
221
- M && _ ? "bu-category-dropdown__item--selected-branch" : "",
222
- M && !_ ? "bu-category-dropdown__item--selected-leaf" : "",
223
- c.disabled ? "bu-category-dropdown__item--disabled" : ""
269
+ isSelected && hasBranch ? "bu-category-dropdown__item--selected-branch" : "",
270
+ isSelected && !hasBranch ? "bu-category-dropdown__item--selected-leaf" : "",
271
+ item.disabled ? "bu-category-dropdown__item--disabled" : ""
224
272
  ].filter(Boolean).join(" ");
225
- return /* @__PURE__ */ T(
273
+ return /* @__PURE__ */ jsxs(
226
274
  "button",
227
275
  {
228
276
  type: "button",
229
- className: R,
230
- disabled: c.disabled,
231
- onClick: () => I(e, c),
277
+ className: itemClass,
278
+ disabled: item.disabled,
279
+ onClick: () => handleSelect(colIndex, item),
232
280
  children: [
233
- /* @__PURE__ */ r(
234
- A,
281
+ /* @__PURE__ */ jsx(
282
+ TruncatedTooltip,
235
283
  {
236
- text: c.label,
284
+ text: item.label,
237
285
  spanClassName: "bu-category-dropdown__item-label",
238
286
  wrapperStyle: { flex: 1, minWidth: 0, display: "block" },
239
- getPopupContainer: N
287
+ getPopupContainer
240
288
  }
241
289
  ),
242
- _ && /* @__PURE__ */ r("span", { className: "bu-category-dropdown__item-arrow", children: /* @__PURE__ */ r(ee, {}) })
290
+ hasBranch && /* @__PURE__ */ jsx("span", { className: "bu-category-dropdown__item-arrow", children: /* @__PURE__ */ jsx(ChevronRight, {}) })
243
291
  ]
244
292
  },
245
- c.value
293
+ item.value
246
294
  );
247
295
  })
248
296
  }
249
297
  )
250
- ] }, e);
298
+ ] }, colIndex);
251
299
  }) }) }),
252
300
  document.body
253
301
  )
@@ -256,5 +304,5 @@ function ae({
256
304
  );
257
305
  }
258
306
  export {
259
- ae as default
307
+ BuCategoryDropdown as default
260
308
  };
@@ -1 +1,116 @@
1
- "use strict";const n=require("react/jsx-runtime"),t=require("react"),M=require("../Icon/Icon.js"),S=require("./context.js");;/* empty css */function f(...i){return i.filter(Boolean).join(" ")}const m=t.forwardRef((i,j)=>{const{checked:k,defaultChecked:v=!1,disabled:p,indeterminate:o=!1,children:h,className:C,style:N,onChange:l,onMouseEnter:_,onMouseLeave:B,value:c,skipGroup:E=!1,direction:V="ltr",name:q,variant:x="dark",...w}=i,e=t.useContext(S.CheckBoxGroupContext),[y,D]=t.useState(v),d=t.useRef(c),a=!!(e&&!E),s=a?e.value.includes(c):k??y,r=(e==null?void 0:e.disabled)||p,G=a?e==null?void 0:e.name:q,P=a?(e==null?void 0:e.variant)??x:x;t.useEffect(()=>{if(!(!a||c===void 0))return e==null||e.registerValue(c),()=>e==null?void 0:e.cancelValue(c)},[e,a,c]),t.useEffect(()=>{!a||d.current===c||(d.current!==void 0&&(e==null||e.cancelValue(d.current)),c!==void 0&&(e==null||e.registerValue(c)),d.current=c)},[e,a,c]);const R=b=>{if(r)return;const u=b.target.checked;!a&&k===void 0&&D(u);const I={target:{...i,checked:u},stopPropagation:()=>b.stopPropagation(),preventDefault:()=>b.preventDefault(),nativeEvent:b.nativeEvent};l==null||l(I),a&&c!==void 0&&(e==null||e.toggleOption({label:h,value:c,disabled:r,onChange:l}))};return n.jsxs("label",{className:f("bj-checkbox-wrapper",s&&"bj-checkbox-wrapper--checked",r&&"bj-checkbox-wrapper--disabled",V==="rtl"&&"bj-checkbox-wrapper--rtl",C),onMouseEnter:_,onMouseLeave:B,style:N,children:[n.jsxs("span",{className:f("bj-checkbox",s&&"bj-checkbox--checked",r&&"bj-checkbox--disabled",o&&"bj-checkbox--indeterminate",`bj-checkbox--${P}`),children:[n.jsx("input",{...w,"aria-checked":o?"mixed":s,checked:s,className:"bj-checkbox__input",disabled:r,name:G,onChange:R,ref:j,type:"checkbox",value:typeof c=="boolean"?String(c):c}),n.jsxs("span",{className:"bj-checkbox__inner",children:[s&&!o&&n.jsx(M,{className:"bj-checkbox__check-icon",type:"icon-a-dagouxi"}),o&&n.jsx("span",{className:"bj-checkbox__indeterminate-mark"})]})]}),h!==void 0&&n.jsx("span",{className:"bj-checkbox__label",children:h})]})});m.displayName="BCheckBox";module.exports=m;
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const react = require("react");
4
+ const Icon = require("../Icon/Icon.js");
5
+ const context = require("./context.js");
6
+ ;/* empty css */
7
+ function classNames(...values) {
8
+ return values.filter(Boolean).join(" ");
9
+ }
10
+ const BCheckBox = react.forwardRef((props, forwardedRef) => {
11
+ const {
12
+ checked: controlledChecked,
13
+ defaultChecked = false,
14
+ disabled,
15
+ indeterminate = false,
16
+ children,
17
+ className,
18
+ style,
19
+ onChange,
20
+ onMouseEnter,
21
+ onMouseLeave,
22
+ value,
23
+ skipGroup = false,
24
+ direction = "ltr",
25
+ name,
26
+ variant = "dark",
27
+ ...inputProps
28
+ } = props;
29
+ const group = react.useContext(context.CheckBoxGroupContext);
30
+ const [internalChecked, setInternalChecked] = react.useState(defaultChecked);
31
+ const previousValue = react.useRef(value);
32
+ const inGroup = Boolean(group && !skipGroup);
33
+ const mergedChecked = inGroup ? group.value.includes(value) : controlledChecked ?? internalChecked;
34
+ const mergedDisabled = (group == null ? void 0 : group.disabled) || disabled;
35
+ const mergedName = inGroup ? group == null ? void 0 : group.name : name;
36
+ const mergedVariant = inGroup ? (group == null ? void 0 : group.variant) ?? variant : variant;
37
+ react.useEffect(() => {
38
+ if (!inGroup || value === void 0) return;
39
+ group == null ? void 0 : group.registerValue(value);
40
+ return () => group == null ? void 0 : group.cancelValue(value);
41
+ }, [group, inGroup, value]);
42
+ react.useEffect(() => {
43
+ if (!inGroup || previousValue.current === value) return;
44
+ if (previousValue.current !== void 0) group == null ? void 0 : group.cancelValue(previousValue.current);
45
+ if (value !== void 0) group == null ? void 0 : group.registerValue(value);
46
+ previousValue.current = value;
47
+ }, [group, inGroup, value]);
48
+ const handleChange = (event) => {
49
+ if (mergedDisabled) return;
50
+ const nextChecked = event.target.checked;
51
+ if (!inGroup && controlledChecked === void 0) setInternalChecked(nextChecked);
52
+ const changeEvent = {
53
+ target: { ...props, checked: nextChecked },
54
+ stopPropagation: () => event.stopPropagation(),
55
+ preventDefault: () => event.preventDefault(),
56
+ nativeEvent: event.nativeEvent
57
+ };
58
+ onChange == null ? void 0 : onChange(changeEvent);
59
+ if (inGroup && value !== void 0) {
60
+ group == null ? void 0 : group.toggleOption({ label: children, value, disabled: mergedDisabled, onChange });
61
+ }
62
+ };
63
+ return /* @__PURE__ */ jsxRuntime.jsxs(
64
+ "label",
65
+ {
66
+ className: classNames(
67
+ "bj-checkbox-wrapper",
68
+ mergedChecked && "bj-checkbox-wrapper--checked",
69
+ mergedDisabled && "bj-checkbox-wrapper--disabled",
70
+ direction === "rtl" && "bj-checkbox-wrapper--rtl",
71
+ className
72
+ ),
73
+ onMouseEnter,
74
+ onMouseLeave,
75
+ style,
76
+ children: [
77
+ /* @__PURE__ */ jsxRuntime.jsxs(
78
+ "span",
79
+ {
80
+ className: classNames(
81
+ "bj-checkbox",
82
+ mergedChecked && "bj-checkbox--checked",
83
+ mergedDisabled && "bj-checkbox--disabled",
84
+ indeterminate && "bj-checkbox--indeterminate",
85
+ `bj-checkbox--${mergedVariant}`
86
+ ),
87
+ children: [
88
+ /* @__PURE__ */ jsxRuntime.jsx(
89
+ "input",
90
+ {
91
+ ...inputProps,
92
+ "aria-checked": indeterminate ? "mixed" : mergedChecked,
93
+ checked: mergedChecked,
94
+ className: "bj-checkbox__input",
95
+ disabled: mergedDisabled,
96
+ name: mergedName,
97
+ onChange: handleChange,
98
+ ref: forwardedRef,
99
+ type: "checkbox",
100
+ value: typeof value === "boolean" ? String(value) : value
101
+ }
102
+ ),
103
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "bj-checkbox__inner", children: [
104
+ mergedChecked && !indeterminate && /* @__PURE__ */ jsxRuntime.jsx(Icon, { className: "bj-checkbox__check-icon", type: "icon-a-dagouxi" }),
105
+ indeterminate && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bj-checkbox__indeterminate-mark" })
106
+ ] })
107
+ ]
108
+ }
109
+ ),
110
+ children !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bj-checkbox__label", children })
111
+ ]
112
+ }
113
+ );
114
+ });
115
+ BCheckBox.displayName = "BCheckBox";
116
+ module.exports = BCheckBox;