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,204 +1,312 @@
1
- import { jsxs as pe, jsx as o } from "react/jsx-runtime";
2
- import { forwardRef as Se, useRef as g, useState as z, useCallback as B, useMemo as U } from "react";
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useRef, useState, useCallback, useMemo } from "react";
3
3
  /* empty css */
4
- import We from "./hooks/useCursor.mjs";
5
- import Ye from "./hooks/useFrame.mjs";
6
- import Ge from "./StepHandler.mjs";
7
- import { getDecimal as i, getNumberPrecision as de, validateNumber as Je, toFixed as O, getDecupleSteps as ge } from "./utils/decimal.mjs";
8
- function je(I) {
9
- if (I == null) return null;
10
- const u = i(I);
11
- return u.isInvalidate() ? null : u;
4
+ import useCursor from "./hooks/useCursor.mjs";
5
+ import useFrame from "./hooks/useFrame.mjs";
6
+ import StepHandler from "./StepHandler.mjs";
7
+ import { getDecimal, getNumberPrecision, validateNumber, toFixed, getDecupleSteps } from "./utils/decimal.mjs";
8
+ function getDecimalIfValid(value) {
9
+ if (value === void 0 || value === null) return null;
10
+ const decimal = getDecimal(value);
11
+ return decimal.isInvalidate() ? null : decimal;
12
12
  }
13
- const Ae = Se(function({
14
- value: u,
15
- defaultValue: A,
16
- onChange: x,
17
- min: C,
18
- max: K,
19
- step: c = 1,
20
- precision: N,
21
- disabled: F = !1,
22
- readOnly: $ = !1,
23
- placeholder: Ie,
24
- autoFocus: Ne,
25
- size: T = "middle",
26
- status: ee,
27
- bordered: ve = !0,
28
- controls: k = !0,
29
- keyboard: Ve = !0,
30
- changeOnWheel: De = !1,
31
- changeOnBlur: Re = !0,
32
- addonBefore: a,
33
- addonAfter: f,
34
- prefix: v,
35
- suffix: V,
36
- formatter: D,
37
- parser: R,
38
- decimalSeparator: m,
39
- onStep: M,
40
- onPressEnter: P,
41
- onFocus: H,
42
- onBlur: S,
43
- id: _e,
44
- name: he,
45
- className: te,
46
- style: ne
47
- }, _) {
48
- const W = g(null), [Y, re] = z(!1), s = g(!1), j = g(!1), h = g(!1), G = g(""), [r, ue] = z(() => i(u ?? A)), we = (e) => {
49
- u === void 0 && ue(e);
50
- }, J = B(
51
- (e, t) => {
52
- if (!t)
53
- return N !== void 0 && N >= 0 ? N : Math.max(de(e), de(c));
13
+ const BInputNumber = forwardRef(function BInputNumber2({
14
+ value,
15
+ defaultValue,
16
+ onChange,
17
+ min,
18
+ max,
19
+ step = 1,
20
+ precision,
21
+ disabled = false,
22
+ readOnly = false,
23
+ placeholder,
24
+ autoFocus,
25
+ size = "middle",
26
+ status,
27
+ bordered = true,
28
+ controls = true,
29
+ keyboard = true,
30
+ changeOnWheel = false,
31
+ changeOnBlur = true,
32
+ addonBefore,
33
+ addonAfter,
34
+ prefix,
35
+ suffix,
36
+ formatter,
37
+ parser,
38
+ decimalSeparator,
39
+ onStep,
40
+ onPressEnter,
41
+ onFocus,
42
+ onBlur,
43
+ id,
44
+ name,
45
+ className,
46
+ style
47
+ }, ref) {
48
+ const inputRef = useRef(null);
49
+ const [focused, setFocused] = useState(false);
50
+ const userTypingRef = useRef(false);
51
+ const compositionRef = useRef(false);
52
+ const shiftKeyRef = useRef(false);
53
+ const inputValueRef = useRef("");
54
+ const [decimalValue, setDecimalValue] = useState(() => getDecimal(value ?? defaultValue));
55
+ const setUncontrolledDecimalValue = (next) => {
56
+ if (value === void 0) setDecimalValue(next);
57
+ };
58
+ const getPrecision = useCallback(
59
+ (numStr, userTyping) => {
60
+ if (userTyping) return void 0;
61
+ if (precision !== void 0 && precision >= 0) return precision;
62
+ return Math.max(getNumberPrecision(numStr), getNumberPrecision(step));
54
63
  },
55
- [N, c]
56
- ), L = B(
57
- (e) => {
58
- if (R) return R(e);
59
- let t = e;
60
- return m && (t = t.replace(m, ".")), t.replace(/[^\w.-]+/g, "");
64
+ [precision, step]
65
+ );
66
+ const mergedParser = useCallback(
67
+ (num) => {
68
+ if (parser) return parser(num);
69
+ let parsedStr = num;
70
+ if (decimalSeparator) parsedStr = parsedStr.replace(decimalSeparator, ".");
71
+ return parsedStr.replace(/[^\w.-]+/g, "");
61
72
  },
62
- [R, m]
63
- ), ie = B(
64
- (e, t) => {
65
- if (D) return D(e, { userTyping: !!t, input: G.current });
66
- let n = e;
67
- if (!t) {
68
- const l = J(n, t);
69
- Je(n) && (m || (l ?? -1) >= 0) && (n = O(n, m || ".", l));
73
+ [parser, decimalSeparator]
74
+ );
75
+ const mergedFormatter = useCallback(
76
+ (number, userTyping) => {
77
+ if (formatter) return formatter(number, { userTyping: !!userTyping, input: inputValueRef.current });
78
+ let str = number;
79
+ if (!userTyping) {
80
+ const mergedPrecision = getPrecision(str, userTyping);
81
+ if (validateNumber(str) && (decimalSeparator || (mergedPrecision ?? -1) >= 0)) {
82
+ str = toFixed(str, decimalSeparator || ".", mergedPrecision);
83
+ }
70
84
  }
71
- return n;
85
+ return str;
72
86
  },
73
- [D, J, m]
74
- ), [w, se] = z(() => {
75
- const e = A ?? u;
76
- return r.isInvalidate() && ["string", "number"].includes(typeof e) ? e == null || Number.isNaN(e) ? "" : String(e) : ie(r.toString(), !1);
87
+ [formatter, getPrecision, decimalSeparator]
88
+ );
89
+ const [inputValue, setInternalInputValue] = useState(() => {
90
+ const initValue = defaultValue ?? value;
91
+ if (decimalValue.isInvalidate() && ["string", "number"].includes(typeof initValue)) {
92
+ return initValue === void 0 || initValue === null || Number.isNaN(initValue) ? "" : String(initValue);
93
+ }
94
+ return mergedFormatter(decimalValue.toString(), false);
77
95
  });
78
- G.current = w;
79
- const q = (e, t) => {
80
- se(
81
- ie(e.isInvalidate() ? e.toString(!1) : e.toString(!t), t)
96
+ inputValueRef.current = inputValue;
97
+ const setInputValue = (newValue, userTyping) => {
98
+ setInternalInputValue(
99
+ mergedFormatter(newValue.isInvalidate() ? newValue.toString(false) : newValue.toString(!userTyping), userTyping)
82
100
  );
83
- }, b = U(() => je(K), [K]), p = U(() => je(C), [C]), le = U(() => !b || r.isInvalidate() ? !1 : b.lessEquals(r), [b, r]), oe = U(() => !p || r.isInvalidate() ? !1 : r.lessEquals(p), [p, r]), [qe] = We(W.current, Y), ce = (e) => b && !e.lessEquals(b) ? b : p && !p.lessEquals(e) ? p : null, Q = (e) => !ce(e), y = (e, t) => {
84
- let n = e, l = Q(n) || n.isEmpty();
85
- if (!n.isEmpty() && !t && (n = ce(n) || n, l = !0), !$ && !F && l) {
86
- const d = n.toString(), E = J(d, t);
87
- return E !== void 0 && E >= 0 && (n = i(O(d, ".", E)), Q(n) || (n = i(O(d, ".", E, !0)))), n.equals(r) || (we(n), x == null || x(n.isEmpty() ? null : n.toNumber()), u === void 0 && q(n, t)), n;
101
+ };
102
+ const maxDecimal = useMemo(() => getDecimalIfValid(max), [max]);
103
+ const minDecimal = useMemo(() => getDecimalIfValid(min), [min]);
104
+ const upDisabled = useMemo(() => {
105
+ if (!maxDecimal || decimalValue.isInvalidate()) return false;
106
+ return maxDecimal.lessEquals(decimalValue);
107
+ }, [maxDecimal, decimalValue]);
108
+ const downDisabled = useMemo(() => {
109
+ if (!minDecimal || decimalValue.isInvalidate()) return false;
110
+ return decimalValue.lessEquals(minDecimal);
111
+ }, [minDecimal, decimalValue]);
112
+ const [recordCursor] = useCursor(inputRef.current, focused);
113
+ const getRangeValue = (target) => {
114
+ if (maxDecimal && !target.lessEquals(maxDecimal)) return maxDecimal;
115
+ if (minDecimal && !minDecimal.lessEquals(target)) return minDecimal;
116
+ return null;
117
+ };
118
+ const isInRange = (target) => !getRangeValue(target);
119
+ const triggerValueUpdate = (newValue, userTyping) => {
120
+ let updateValue = newValue;
121
+ let isRangeValidate = isInRange(updateValue) || updateValue.isEmpty();
122
+ if (!updateValue.isEmpty() && !userTyping) {
123
+ updateValue = getRangeValue(updateValue) || updateValue;
124
+ isRangeValidate = true;
125
+ }
126
+ if (!readOnly && !disabled && isRangeValidate) {
127
+ const numStr = updateValue.toString();
128
+ const mergedPrecision = getPrecision(numStr, userTyping);
129
+ if (mergedPrecision !== void 0 && mergedPrecision >= 0) {
130
+ updateValue = getDecimal(toFixed(numStr, ".", mergedPrecision));
131
+ if (!isInRange(updateValue)) {
132
+ updateValue = getDecimal(toFixed(numStr, ".", mergedPrecision, true));
133
+ }
134
+ }
135
+ if (!updateValue.equals(decimalValue)) {
136
+ setUncontrolledDecimalValue(updateValue);
137
+ onChange == null ? void 0 : onChange(updateValue.isEmpty() ? null : updateValue.toNumber());
138
+ if (value === void 0) setInputValue(updateValue, userTyping);
139
+ }
140
+ return updateValue;
88
141
  }
89
- return r;
90
- }, ye = Ye(), X = (e) => {
91
- if (qe(), G.current = e, se(e), !j.current) {
92
- const t = L(e), n = i(t);
93
- n.isNaN() || y(n, !0);
142
+ return decimalValue;
143
+ };
144
+ const onNextFrame = useFrame();
145
+ const collectInputValue = (inputStr) => {
146
+ recordCursor();
147
+ inputValueRef.current = inputStr;
148
+ setInternalInputValue(inputStr);
149
+ if (!compositionRef.current) {
150
+ const finalValue = mergedParser(inputStr);
151
+ const finalDecimal = getDecimal(finalValue);
152
+ if (!finalDecimal.isNaN()) triggerValueUpdate(finalDecimal, true);
94
153
  }
95
- ye(() => {
96
- const t = R ? e : e.replace(/。/g, ".");
97
- t !== e && X(t);
154
+ onNextFrame(() => {
155
+ const nextInputStr = parser ? inputStr : inputStr.replace(/。/g, ".");
156
+ if (nextInputStr !== inputStr) collectInputValue(nextInputStr);
98
157
  });
99
- }, Ee = () => {
100
- j.current = !0;
101
- }, Ue = (e) => {
102
- j.current = !1, X(e.target.value);
103
- }, xe = (e) => X(e.target.value), Z = (e) => {
104
- var d;
105
- if (e && le || !e && oe) return;
106
- s.current = !1;
107
- let t = i(h.current ? ge(c) : c);
108
- e || (t = t.negate());
109
- const n = (r.isInvalidate() ? i(0) : r).add(t.toString()), l = y(n, !1);
110
- M == null || M(l.toNumber(), { offset: h.current ? ge(c) : c, type: e ? "up" : "down" }), (d = W.current) == null || d.focus();
111
- }, ae = (e) => {
112
- const t = i(L(w));
113
- let n;
114
- t.isNaN() ? n = y(r, e) : n = y(t, e), u !== void 0 ? q(r, !1) : n.isNaN() || q(n, !1);
115
- }, Ce = (e) => {
116
- const { key: t, shiftKey: n } = e;
117
- s.current = !0, h.current = n, t === "Enter" && (j.current || (s.current = !1), ae(!1), P == null || P(e)), Ve && !j.current && (t === "ArrowUp" || t === "ArrowDown") && (Z(t === "ArrowUp"), e.preventDefault());
118
- }, Ke = () => {
119
- s.current = !1, h.current = !1;
120
- }, Fe = (e) => {
121
- re(!0), H == null || H(e);
122
- }, $e = (e) => {
123
- Re && ae(!1), re(!1), s.current = !1, S == null || S(e);
124
- }, fe = g(u);
125
- if (fe.current !== u) {
126
- fe.current = u;
127
- const e = i(u);
128
- if (!e.equals(r)) {
129
- ue(e);
130
- const t = i(L(w));
131
- (!e.equals(t) || !s.current || D) && q(e, s.current);
158
+ };
159
+ const onCompositionStart = () => {
160
+ compositionRef.current = true;
161
+ };
162
+ const onCompositionEnd = (e) => {
163
+ compositionRef.current = false;
164
+ collectInputValue(e.target.value);
165
+ };
166
+ const onInternalInput = (e) => collectInputValue(e.target.value);
167
+ const onInternalStep = (up) => {
168
+ var _a;
169
+ if (up && upDisabled || !up && downDisabled) return;
170
+ userTypingRef.current = false;
171
+ let stepDecimal = getDecimal(shiftKeyRef.current ? getDecupleSteps(step) : step);
172
+ if (!up) stepDecimal = stepDecimal.negate();
173
+ const target = (decimalValue.isInvalidate() ? getDecimal(0) : decimalValue).add(stepDecimal.toString());
174
+ const updatedValue = triggerValueUpdate(target, false);
175
+ onStep == null ? void 0 : onStep(updatedValue.toNumber(), { offset: shiftKeyRef.current ? getDecupleSteps(step) : step, type: up ? "up" : "down" });
176
+ (_a = inputRef.current) == null ? void 0 : _a.focus();
177
+ };
178
+ const flushInputValue = (userTyping) => {
179
+ const parsedValue = getDecimal(mergedParser(inputValue));
180
+ let formatValue;
181
+ if (!parsedValue.isNaN()) {
182
+ formatValue = triggerValueUpdate(parsedValue, userTyping);
183
+ } else {
184
+ formatValue = triggerValueUpdate(decimalValue, userTyping);
185
+ }
186
+ if (value !== void 0) {
187
+ setInputValue(decimalValue, false);
188
+ } else if (!formatValue.isNaN()) {
189
+ setInputValue(formatValue, false);
190
+ }
191
+ };
192
+ const onKeyDown = (event) => {
193
+ const { key, shiftKey } = event;
194
+ userTypingRef.current = true;
195
+ shiftKeyRef.current = shiftKey;
196
+ if (key === "Enter") {
197
+ if (!compositionRef.current) userTypingRef.current = false;
198
+ flushInputValue(false);
199
+ onPressEnter == null ? void 0 : onPressEnter(event);
200
+ }
201
+ if (!keyboard) return;
202
+ if (!compositionRef.current && (key === "ArrowUp" || key === "ArrowDown")) {
203
+ onInternalStep(key === "ArrowUp");
204
+ event.preventDefault();
205
+ }
206
+ };
207
+ const onKeyUp = () => {
208
+ userTypingRef.current = false;
209
+ shiftKeyRef.current = false;
210
+ };
211
+ const onInternalFocus = (e) => {
212
+ setFocused(true);
213
+ onFocus == null ? void 0 : onFocus(e);
214
+ };
215
+ const onInternalBlur = (e) => {
216
+ if (changeOnBlur) flushInputValue(false);
217
+ setFocused(false);
218
+ userTypingRef.current = false;
219
+ onBlur == null ? void 0 : onBlur(e);
220
+ };
221
+ const prevValueRef = useRef(value);
222
+ if (prevValueRef.current !== value) {
223
+ prevValueRef.current = value;
224
+ const newValue = getDecimal(value);
225
+ if (!newValue.equals(decimalValue)) {
226
+ setDecimalValue(newValue);
227
+ const currentParsedValue = getDecimal(mergedParser(inputValue));
228
+ if (!newValue.equals(currentParsedValue) || !userTypingRef.current || formatter) {
229
+ setInputValue(newValue, userTypingRef.current);
230
+ }
132
231
  }
133
232
  }
134
- const ke = (e) => {
135
- W.current = e, typeof _ == "function" ? _(e) : _ && (_.current = e);
136
- }, me = !!k, Me = typeof k == "object" ? k.icon : void 0, Pe = !r.isInvalidate() && !Q(r), He = [
233
+ const setRefs = (node) => {
234
+ inputRef.current = node;
235
+ if (typeof ref === "function") ref(node);
236
+ else if (ref) ref.current = node;
237
+ };
238
+ const controlsEnabled = !!controls;
239
+ const controlsIcon = typeof controls === "object" ? controls.icon : void 0;
240
+ const outOfRange = !decimalValue.isInvalidate() && !isInRange(decimalValue);
241
+ const rootCls = [
137
242
  "bj-input-number",
138
- `bj-input-number--${T}`,
139
- Y && "bj-input-number--focused",
140
- F && "bj-input-number--disabled",
141
- $ && "bj-input-number--readonly",
142
- !ve && "bj-input-number--borderless",
143
- ee && `bj-input-number--${ee}`,
144
- Pe && "bj-input-number--out-of-range",
145
- me && "bj-input-number--with-controls",
146
- a && "bj-input-number--group-left",
147
- f && "bj-input-number--group-right"
148
- ].filter(Boolean).join(" "), be = /* @__PURE__ */ pe(
243
+ `bj-input-number--${size}`,
244
+ focused && "bj-input-number--focused",
245
+ disabled && "bj-input-number--disabled",
246
+ readOnly && "bj-input-number--readonly",
247
+ !bordered && "bj-input-number--borderless",
248
+ status && `bj-input-number--${status}`,
249
+ outOfRange && "bj-input-number--out-of-range",
250
+ controlsEnabled && "bj-input-number--with-controls",
251
+ addonBefore && "bj-input-number--group-left",
252
+ addonAfter && "bj-input-number--group-right"
253
+ ].filter(Boolean).join(" ");
254
+ const numberBox = /* @__PURE__ */ jsxs(
149
255
  "div",
150
256
  {
151
- className: [He, !(a || f || v || V) && te].filter(Boolean).join(" "),
152
- style: a || f || v || V ? void 0 : ne,
153
- onKeyDown: Ce,
154
- onKeyUp: Ke,
257
+ className: [rootCls, !(addonBefore || addonAfter || prefix || suffix) && className].filter(Boolean).join(" "),
258
+ style: !(addonBefore || addonAfter || prefix || suffix) ? style : void 0,
259
+ onKeyDown,
260
+ onKeyUp,
155
261
  children: [
156
- v && /* @__PURE__ */ o("span", { className: "bj-input-number__prefix", children: v }),
157
- /* @__PURE__ */ o("div", { className: "bj-input-number__input-wrap", children: /* @__PURE__ */ o(
262
+ prefix && /* @__PURE__ */ jsx("span", { className: "bj-input-number__prefix", children: prefix }),
263
+ /* @__PURE__ */ jsx("div", { className: "bj-input-number__input-wrap", children: /* @__PURE__ */ jsx(
158
264
  "input",
159
265
  {
160
- ref: ke,
161
- id: _e,
162
- name: he,
266
+ ref: setRefs,
267
+ id,
268
+ name,
163
269
  className: "bj-input-number__input",
164
270
  autoComplete: "off",
165
271
  role: "spinbutton",
166
- "aria-valuemin": C,
167
- "aria-valuemax": K,
168
- "aria-valuenow": r.isInvalidate() ? void 0 : r.toNumber(),
169
- value: w,
170
- placeholder: Ie,
171
- disabled: F,
172
- readOnly: $,
173
- autoFocus: Ne,
174
- onChange: xe,
175
- onFocus: Fe,
176
- onBlur: $e,
177
- onCompositionStart: Ee,
178
- onCompositionEnd: Ue,
179
- onWheel: De ? (e) => {
180
- Y && Z(e.deltaY < 0);
272
+ "aria-valuemin": min,
273
+ "aria-valuemax": max,
274
+ "aria-valuenow": decimalValue.isInvalidate() ? void 0 : decimalValue.toNumber(),
275
+ value: inputValue,
276
+ placeholder,
277
+ disabled,
278
+ readOnly,
279
+ autoFocus,
280
+ onChange: onInternalInput,
281
+ onFocus: onInternalFocus,
282
+ onBlur: onInternalBlur,
283
+ onCompositionStart,
284
+ onCompositionEnd,
285
+ onWheel: changeOnWheel ? (e) => {
286
+ if (!focused) return;
287
+ onInternalStep(e.deltaY < 0);
181
288
  } : void 0
182
289
  }
183
290
  ) }),
184
- V && /* @__PURE__ */ o("span", { className: "bj-input-number__suffix", children: V }),
185
- me && /* @__PURE__ */ o(Ge, { icon: Me, upDisabled: le, downDisabled: oe, onStep: Z })
291
+ suffix && /* @__PURE__ */ jsx("span", { className: "bj-input-number__suffix", children: suffix }),
292
+ controlsEnabled && /* @__PURE__ */ jsx(StepHandler, { icon: controlsIcon, upDisabled, downDisabled, onStep: onInternalStep })
186
293
  ]
187
294
  }
188
295
  );
189
- return !a && !f ? be : /* @__PURE__ */ pe(
296
+ if (!addonBefore && !addonAfter) return numberBox;
297
+ return /* @__PURE__ */ jsxs(
190
298
  "div",
191
299
  {
192
- className: ["bj-input-number-group", `bj-input-number-group--${T}`, te].filter(Boolean).join(" "),
193
- style: ne,
300
+ className: ["bj-input-number-group", `bj-input-number-group--${size}`, className].filter(Boolean).join(" "),
301
+ style,
194
302
  children: [
195
- a && /* @__PURE__ */ o("div", { className: "bj-input-number-group__addon", children: a }),
196
- be,
197
- f && /* @__PURE__ */ o("div", { className: "bj-input-number-group__addon", children: f })
303
+ addonBefore && /* @__PURE__ */ jsx("div", { className: "bj-input-number-group__addon", children: addonBefore }),
304
+ numberBox,
305
+ addonAfter && /* @__PURE__ */ jsx("div", { className: "bj-input-number-group__addon", children: addonAfter })
198
306
  ]
199
307
  }
200
308
  );
201
309
  });
202
310
  export {
203
- Ae as default
311
+ BInputNumber as default
204
312
  };
@@ -1 +1,69 @@
1
- "use strict";const e=require("react/jsx-runtime"),a=require("react"),m=600,h=200;function _({className:t}){return e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:t,children:e.jsx("path",{d:"M15.4573 13.6501C15.9047 13.6504 16.129 14.192 15.8128 14.5085L12.3352 17.9851C12.139 18.1811 11.8214 18.1811 11.6253 17.9851L8.14772 14.5085C7.83144 14.192 8.0558 13.6504 8.50319 13.6501H15.4573ZM11.6643 5.98311C11.8606 5.78688 12.179 5.78688 12.3753 5.98311L15.8518 9.45967C16.1683 9.77623 15.944 10.3171 15.4964 10.3171H8.54323C8.09567 10.3171 7.87154 9.77625 8.18776 9.45967L11.6643 5.98311Z",fill:"currentColor"})})}function j({icon:t,upDisabled:o,downDisabled:i,onStep:l}){const u=a.useRef(void 0),s=a.useRef(l);s.current=l;const r=()=>clearTimeout(u.current),c=(n,p)=>{n.preventDefault(),r(),s.current(p);function d(){s.current(p),u.current=setTimeout(d,h)}u.current=setTimeout(d,m)};a.useEffect(()=>r,[]);const b={unselectable:"on",role:"button",onMouseUp:r,onMouseLeave:r};return e.jsxs("div",{className:"bj-input-number__handler-wrap",children:[e.jsx("span",{...b,"aria-label":"Increase Value","aria-disabled":o,className:o?"bj-input-number__handler bj-input-number__handler--up bj-input-number__handler--disabled":"bj-input-number__handler bj-input-number__handler--up",onMouseDown:n=>c(n,!0)}),e.jsx("span",{...b,"aria-label":"Decrease Value","aria-disabled":i,className:i?"bj-input-number__handler bj-input-number__handler--down bj-input-number__handler--disabled":"bj-input-number__handler bj-input-number__handler--down",onMouseDown:n=>c(n,!1)}),t||e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"bj-input-number__handler-icon bj-input-number__handler-icon--up"}),e.jsx(_,{className:"bj-input-number__handler-icon bj-input-number__handler-icon--down"})]})]})}module.exports=j;
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const react = require("react");
4
+ const STEP_DELAY = 600;
5
+ const STEP_INTERVAL = 200;
6
+ function SpinnerIcon({ className }) {
7
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", className, children: /* @__PURE__ */ jsxRuntime.jsx(
8
+ "path",
9
+ {
10
+ d: "M15.4573 13.6501C15.9047 13.6504 16.129 14.192 15.8128 14.5085L12.3352 17.9851C12.139 18.1811 11.8214 18.1811 11.6253 17.9851L8.14772 14.5085C7.83144 14.192 8.0558 13.6504 8.50319 13.6501H15.4573ZM11.6643 5.98311C11.8606 5.78688 12.179 5.78688 12.3753 5.98311L15.8518 9.45967C16.1683 9.77623 15.944 10.3171 15.4964 10.3171H8.54323C8.09567 10.3171 7.87154 9.77625 8.18776 9.45967L11.6643 5.98311Z",
11
+ fill: "currentColor"
12
+ }
13
+ ) });
14
+ }
15
+ function StepHandler({ icon, upDisabled, downDisabled, onStep }) {
16
+ const stepTimeoutRef = react.useRef(void 0);
17
+ const onStepRef = react.useRef(onStep);
18
+ onStepRef.current = onStep;
19
+ const onStopStep = () => clearTimeout(stepTimeoutRef.current);
20
+ const onStepMouseDown = (e, up) => {
21
+ e.preventDefault();
22
+ onStopStep();
23
+ onStepRef.current(up);
24
+ function loopStep() {
25
+ onStepRef.current(up);
26
+ stepTimeoutRef.current = setTimeout(loopStep, STEP_INTERVAL);
27
+ }
28
+ stepTimeoutRef.current = setTimeout(loopStep, STEP_DELAY);
29
+ };
30
+ react.useEffect(() => onStopStep, []);
31
+ const sharedProps = {
32
+ unselectable: "on",
33
+ role: "button",
34
+ onMouseUp: onStopStep,
35
+ onMouseLeave: onStopStep
36
+ };
37
+ return (
38
+ // Click zones come before the icon(s) in DOM order so the icon halves
39
+ // can be dimmed via a `:hover ~`/`:active ~` sibling selector in CSS —
40
+ // the icon itself stays `pointer-events: none` and purely visual.
41
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bj-input-number__handler-wrap", children: [
42
+ /* @__PURE__ */ jsxRuntime.jsx(
43
+ "span",
44
+ {
45
+ ...sharedProps,
46
+ "aria-label": "Increase Value",
47
+ "aria-disabled": upDisabled,
48
+ className: upDisabled ? "bj-input-number__handler bj-input-number__handler--up bj-input-number__handler--disabled" : "bj-input-number__handler bj-input-number__handler--up",
49
+ onMouseDown: (e) => onStepMouseDown(e, true)
50
+ }
51
+ ),
52
+ /* @__PURE__ */ jsxRuntime.jsx(
53
+ "span",
54
+ {
55
+ ...sharedProps,
56
+ "aria-label": "Decrease Value",
57
+ "aria-disabled": downDisabled,
58
+ className: downDisabled ? "bj-input-number__handler bj-input-number__handler--down bj-input-number__handler--disabled" : "bj-input-number__handler bj-input-number__handler--down",
59
+ onMouseDown: (e) => onStepMouseDown(e, false)
60
+ }
61
+ ),
62
+ icon || /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
63
+ /* @__PURE__ */ jsxRuntime.jsx(SpinnerIcon, { className: "bj-input-number__handler-icon bj-input-number__handler-icon--up" }),
64
+ /* @__PURE__ */ jsxRuntime.jsx(SpinnerIcon, { className: "bj-input-number__handler-icon bj-input-number__handler-icon--down" })
65
+ ] })
66
+ ] })
67
+ );
68
+ }
69
+ module.exports = StepHandler;