bj-web-components 0.2.27 → 0.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +51 -1
- package/dist/index.mjs +49 -49
- package/dist/style.css +3744 -1
- package/dist/web/BasicInput/BInput.js +208 -1
- package/dist/web/BasicInput/BInput.mjs +164 -132
- package/dist/web/BasicInput/utils.js +47 -1
- package/dist/web/BasicInput/utils.mjs +38 -28
- package/dist/web/CategoryDropdown/CategoryDropdown.js +307 -1
- package/dist/web/CategoryDropdown/CategoryDropdown.mjs +218 -170
- package/dist/web/CheckBox/BCheckBox.js +116 -1
- package/dist/web/CheckBox/BCheckBox.mjs +86 -70
- package/dist/web/CheckBox/Group.js +73 -1
- package/dist/web/CheckBox/Group.mjs +63 -56
- package/dist/web/CheckBox/context.js +5 -1
- package/dist/web/CheckBox/context.mjs +3 -3
- package/dist/web/CheckBox/index.js +8 -1
- package/dist/web/CheckBox/index.mjs +6 -6
- package/dist/web/Dropdown/BDropdown.js +186 -1
- package/dist/web/Dropdown/BDropdown.mjs +132 -106
- package/dist/web/EmptyInputBox/EmptyInputBox.js +77 -1
- package/dist/web/EmptyInputBox/EmptyInputBox.mjs +52 -48
- package/dist/web/FileCard/FileCard.js +157 -1
- package/dist/web/FileCard/FileCard.mjs +112 -82
- package/dist/web/Icon/Icon.js +9 -1
- package/dist/web/Icon/Icon.mjs +6 -6
- package/dist/web/Input/Input.js +181 -1
- package/dist/web/Input/Input.mjs +122 -113
- package/dist/web/InputNumber/BInputNumber.js +311 -1
- package/dist/web/InputNumber/BInputNumber.mjs +275 -167
- package/dist/web/InputNumber/StepHandler.js +69 -1
- package/dist/web/InputNumber/StepHandler.mjs +38 -32
- package/dist/web/InputNumber/hooks/useCursor.js +40 -1
- package/dist/web/InputNumber/hooks/useCursor.mjs +35 -33
- package/dist/web/InputNumber/hooks/useFrame.js +12 -1
- package/dist/web/InputNumber/hooks/useFrame.mjs +9 -6
- package/dist/web/InputNumber/utils/decimal.js +147 -1
- package/dist/web/InputNumber/utils/decimal.mjs +109 -81
- package/dist/web/Modal/Modal.js +84 -1
- package/dist/web/Modal/Modal.mjs +52 -49
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.js +232 -1
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.mjs +206 -125
- package/dist/web/Pagination/Pagination.js +328 -1
- package/dist/web/Pagination/Pagination.mjs +254 -178
- package/dist/web/ProductField/ProductField.js +272 -1
- package/dist/web/ProductField/ProductField.mjs +190 -143
- package/dist/web/ProductField/arrow-up.svg.js +3 -1
- package/dist/web/ProductField/arrow-up.svg.mjs +2 -2
- package/dist/web/ProductField/checkbox-no.svg.js +3 -1
- package/dist/web/ProductField/checkbox-no.svg.mjs +2 -2
- package/dist/web/ProductField/checkbox-ok.svg.js +3 -1
- package/dist/web/ProductField/checkbox-ok.svg.mjs +2 -2
- package/dist/web/ProductField/no_data_light.svg.js +3 -1
- package/dist/web/ProductField/no_data_light.svg.mjs +2 -2
- package/dist/web/ProductField/search.svg.js +3 -1
- package/dist/web/ProductField/search.svg.mjs +2 -2
- package/dist/web/ProductField/sort.svg.js +3 -1
- package/dist/web/ProductField/sort.svg.mjs +2 -2
- package/dist/web/SkuInputCard/SkuInputCard.js +276 -1
- package/dist/web/SkuInputCard/SkuInputCard.mjs +188 -149
- package/dist/web/SkuInputCard/spin_loading_red.gif.js +3 -1
- package/dist/web/SkuInputCard/spin_loading_red.gif.mjs +2 -2
- package/dist/web/Switch/Switch.js +70 -1
- package/dist/web/Switch/Switch.mjs +47 -37
- package/dist/web/Table/BTable.js +950 -1
- package/dist/web/Table/BTable.mjs +771 -519
- package/dist/web/Table/Column.js +5 -1
- package/dist/web/Table/Column.mjs +2 -2
- package/dist/web/Table/ColumnGroup.js +5 -1
- package/dist/web/Table/ColumnGroup.mjs +2 -2
- package/dist/web/Table/utils/columns.js +48 -1
- package/dist/web/Table/utils/columns.mjs +35 -30
- package/dist/web/Table/utils/sortFilter.js +84 -1
- package/dist/web/Table/utils/sortFilter.mjs +73 -52
- package/dist/web/Tabs/BTabs.js +150 -1
- package/dist/web/Tabs/BTabs.mjs +118 -98
- package/dist/web/Tabs/TabPane.js +8 -1
- package/dist/web/Tabs/TabPane.mjs +4 -4
- package/dist/web/Tooltip/ConfirmTooltip.js +26 -1
- package/dist/web/Tooltip/ConfirmTooltip.mjs +20 -19
- package/dist/web/Tooltip/ContentTooltip.js +94 -1
- package/dist/web/Tooltip/ContentTooltip.mjs +72 -62
- package/dist/web/Tooltip/ProgressTooltip.js +36 -1
- package/dist/web/Tooltip/ProgressTooltip.mjs +22 -20
- package/dist/web/Tooltip/TooltipWrapper.js +12 -1
- package/dist/web/Tooltip/TooltipWrapper.mjs +8 -8
- package/dist/web/Tooltip/useAutoPlacement.js +41 -1
- package/dist/web/Tooltip/useAutoPlacement.mjs +34 -25
- package/dist/web.js +51 -1
- package/dist/web.mjs +49 -49
- package/package.json +1 -1
|
@@ -1,204 +1,312 @@
|
|
|
1
|
-
import { jsxs
|
|
2
|
-
import { forwardRef
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useRef, useState, useCallback, useMemo } from "react";
|
|
3
3
|
/* empty css */
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { getDecimal
|
|
8
|
-
function
|
|
9
|
-
if (
|
|
10
|
-
const
|
|
11
|
-
return
|
|
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
|
|
14
|
-
value
|
|
15
|
-
defaultValue
|
|
16
|
-
onChange
|
|
17
|
-
min
|
|
18
|
-
max
|
|
19
|
-
step
|
|
20
|
-
precision
|
|
21
|
-
disabled
|
|
22
|
-
readOnly
|
|
23
|
-
placeholder
|
|
24
|
-
autoFocus
|
|
25
|
-
size
|
|
26
|
-
status
|
|
27
|
-
bordered
|
|
28
|
-
controls
|
|
29
|
-
keyboard
|
|
30
|
-
changeOnWheel
|
|
31
|
-
changeOnBlur
|
|
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
|
-
},
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
[
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
[
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
85
|
+
return str;
|
|
72
86
|
},
|
|
73
|
-
[
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
154
|
+
onNextFrame(() => {
|
|
155
|
+
const nextInputStr = parser ? inputStr : inputStr.replace(/。/g, ".");
|
|
156
|
+
if (nextInputStr !== inputStr) collectInputValue(nextInputStr);
|
|
98
157
|
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
|
135
|
-
|
|
136
|
-
|
|
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--${
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
!
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
].filter(Boolean).join(" ")
|
|
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: [
|
|
152
|
-
style:
|
|
153
|
-
onKeyDown
|
|
154
|
-
onKeyUp
|
|
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
|
-
|
|
157
|
-
/* @__PURE__ */
|
|
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:
|
|
161
|
-
id
|
|
162
|
-
name
|
|
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":
|
|
167
|
-
"aria-valuemax":
|
|
168
|
-
"aria-valuenow":
|
|
169
|
-
value:
|
|
170
|
-
placeholder
|
|
171
|
-
disabled
|
|
172
|
-
readOnly
|
|
173
|
-
autoFocus
|
|
174
|
-
onChange:
|
|
175
|
-
onFocus:
|
|
176
|
-
onBlur:
|
|
177
|
-
onCompositionStart
|
|
178
|
-
onCompositionEnd
|
|
179
|
-
onWheel:
|
|
180
|
-
|
|
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
|
-
|
|
185
|
-
|
|
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
|
-
|
|
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--${
|
|
193
|
-
style
|
|
300
|
+
className: ["bj-input-number-group", `bj-input-number-group--${size}`, className].filter(Boolean).join(" "),
|
|
301
|
+
style,
|
|
194
302
|
children: [
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
311
|
+
BInputNumber as default
|
|
204
312
|
};
|
|
@@ -1 +1,69 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|