@laser-ui/components 2.5.0 → 2.6.1
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/CHANGELOG.md +12 -0
- package/date-picker/DatePicker.js +176 -168
- package/dropdown/Dropdown.js +1 -5
- package/hooks/useNestedPopup.d.ts +3 -4
- package/hooks/useNestedPopup.js +7 -12
- package/image/Image.js +14 -20
- package/input/InputNumber.js +52 -38
- package/menu/Menu.js +1 -2
- package/package.json +2 -2
- package/spinner/Spinner.js +8 -10
- package/time-picker/TimePicker.js +173 -149
- package/transition/Transition.js +7 -9
package/input/InputNumber.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useAsync, useEvent,
|
|
3
|
+
import { useAsync, useEvent, useRefExtra } from '@laser-ui/hooks';
|
|
4
4
|
import { checkNodeExist, setRef } from '@laser-ui/utils';
|
|
5
5
|
import CancelFilled from '@material-design-icons/svg/filled/cancel.svg?react';
|
|
6
6
|
import KeyboardArrowDownOutlined from '@material-design-icons/svg/outlined/keyboard_arrow_down.svg?react';
|
|
7
7
|
import KeyboardArrowUpOutlined from '@material-design-icons/svg/outlined/keyboard_arrow_up.svg?react';
|
|
8
8
|
import { isNull, isUndefined } from 'lodash';
|
|
9
|
-
import { useRef } from 'react';
|
|
9
|
+
import { useRef, useState } from 'react';
|
|
10
10
|
import { CLASSES } from './vars';
|
|
11
11
|
import { BaseInput } from '../base-input';
|
|
12
12
|
import { useComponentProps, useControlled, useDesign, useScopedProps, useStyled, useTranslation } from '../hooks';
|
|
@@ -17,30 +17,39 @@ export function InputNumber(props) {
|
|
|
17
17
|
const styled = useStyled(CLASSES, { input: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.input }, styleOverrides);
|
|
18
18
|
const async = useAsync();
|
|
19
19
|
const { t } = useTranslation();
|
|
20
|
-
const
|
|
21
|
-
const dataRef = useRef({
|
|
22
|
-
inputFocused: false,
|
|
23
|
-
});
|
|
20
|
+
const dataRef = useRef({});
|
|
24
21
|
const windowRef = useRefExtra(() => window);
|
|
25
22
|
const inputRef = useRef(null);
|
|
23
|
+
const [focused, setFocused] = useState(false);
|
|
26
24
|
const [value, _changeValue] = useControlled(defaultModel !== null && defaultModel !== void 0 ? defaultModel : null, model, onModelChange, undefined, formControl === null || formControl === void 0 ? void 0 : formControl.control);
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
const [placeholderValue, setPlaceholderValue] = useState(() => (isNull(value) ? '' : value.toString()));
|
|
26
|
+
const newPlaceholderValue = (() => {
|
|
27
|
+
if (focused) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (isNull(value)) {
|
|
31
|
+
if (placeholderValue) {
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (value !== Number(placeholderValue)) {
|
|
37
|
+
return value.toString();
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
|
-
|
|
40
|
+
})();
|
|
41
|
+
if (!isUndefined(newPlaceholderValue)) {
|
|
42
|
+
setPlaceholderValue(newPlaceholderValue);
|
|
43
|
+
}
|
|
44
|
+
const changeValue = (val) => {
|
|
37
45
|
_changeValue(val);
|
|
46
|
+
setPlaceholderValue(isNull(val) ? '' : val.toString());
|
|
38
47
|
};
|
|
39
48
|
const { size, disabled } = useScopedProps({ size: sizeProp, disabled: disabledProp || (formControl === null || formControl === void 0 ? void 0 : formControl.control.disabled) });
|
|
40
49
|
const getValue = (val) => { var _a, _b; return Number(Math.max(min !== null && min !== void 0 ? min : -Infinity, Math.min(max !== null && max !== void 0 ? max : Infinity, val)).toFixed((_b = (_a = step.toString().split('.')[1]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0)); };
|
|
41
50
|
const handleNumberButtonMouseDown = (increase = true) => {
|
|
42
|
-
|
|
43
|
-
let val =
|
|
51
|
+
const val = getValue((() => {
|
|
52
|
+
let val = placeholderValue.length > 0 ? Number(placeholderValue) : null;
|
|
44
53
|
if (isNull(val)) {
|
|
45
54
|
return 0;
|
|
46
55
|
}
|
|
@@ -48,13 +57,14 @@ export function InputNumber(props) {
|
|
|
48
57
|
val = Math.round(val);
|
|
49
58
|
}
|
|
50
59
|
return increase ? val + step : val - step;
|
|
51
|
-
})())
|
|
60
|
+
})());
|
|
61
|
+
changeValue(val);
|
|
52
62
|
const loop = (prev) => {
|
|
53
63
|
const val = getValue(increase ? prev + step : prev - step);
|
|
54
64
|
changeValue(val);
|
|
55
65
|
dataRef.current.clearLoop = async.setTimeout(() => loop(val), 50);
|
|
56
66
|
};
|
|
57
|
-
dataRef.current.clearTid = async.setTimeout(() => loop(Number(
|
|
67
|
+
dataRef.current.clearTid = async.setTimeout(() => loop(Number(placeholderValue)), 400);
|
|
58
68
|
};
|
|
59
69
|
const handleNumberButtonMouseUp = () => {
|
|
60
70
|
var _a, _b, _c, _d;
|
|
@@ -95,44 +105,48 @@ export function InputNumber(props) {
|
|
|
95
105
|
inputRef.current = null;
|
|
96
106
|
ret();
|
|
97
107
|
};
|
|
98
|
-
}, value:
|
|
99
|
-
|
|
100
|
-
dataRef.current.inputValue = val;
|
|
108
|
+
}, value: placeholderValue, max: max, min: min, step: step, type: "number", placeholder: placeholder, disabled: disabled, onValueChange: (val) => {
|
|
109
|
+
setPlaceholderValue(val);
|
|
101
110
|
if (val.length === 0) {
|
|
102
|
-
|
|
111
|
+
_changeValue(null);
|
|
103
112
|
}
|
|
104
113
|
else {
|
|
105
114
|
const num = Number(val);
|
|
106
115
|
if ((isUndefined(max) || num <= max) && (isUndefined(min) || num >= min) && (!integer || Number.isInteger(num))) {
|
|
107
|
-
|
|
116
|
+
_changeValue(num);
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
119
|
}, onFocus: (e) => {
|
|
111
120
|
var _a;
|
|
112
121
|
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
113
|
-
|
|
114
|
-
dataRef.current.inputValue = undefined;
|
|
122
|
+
setFocused(true);
|
|
115
123
|
}, onBlur: (e) => {
|
|
116
124
|
var _a;
|
|
117
125
|
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
126
|
+
setFocused(false);
|
|
127
|
+
let realValue = null;
|
|
128
|
+
if (placeholderValue.length === 0) {
|
|
129
|
+
realValue = null;
|
|
121
130
|
}
|
|
122
131
|
else {
|
|
123
|
-
|
|
124
|
-
if (!isUndefined(max) &&
|
|
125
|
-
|
|
132
|
+
realValue = Number(placeholderValue);
|
|
133
|
+
if (!isUndefined(max) && realValue > max) {
|
|
134
|
+
realValue = max;
|
|
126
135
|
}
|
|
127
|
-
if (!isUndefined(min) &&
|
|
128
|
-
|
|
136
|
+
if (!isUndefined(min) && realValue < min) {
|
|
137
|
+
realValue = min;
|
|
129
138
|
}
|
|
130
|
-
if (integer && !Number.isInteger(
|
|
131
|
-
|
|
139
|
+
if (integer && !Number.isInteger(realValue)) {
|
|
140
|
+
realValue = Math.round(realValue);
|
|
132
141
|
}
|
|
133
|
-
changeValue(num);
|
|
134
142
|
}
|
|
135
|
-
|
|
143
|
+
if (realValue !== value) {
|
|
144
|
+
changeValue(realValue);
|
|
145
|
+
}
|
|
146
|
+
else if (realValue !== (placeholderValue.length === 0 ? null : Number(placeholderValue))) {
|
|
147
|
+
setPlaceholderValue(realValue === null ? '' : realValue.toString());
|
|
148
|
+
}
|
|
149
|
+
} })), clearable && !disabled && (_jsx("div", Object.assign({}, mergeCS(styled('input__clear'), { style: { opacity: placeholderValue.length > 0 ? 1 : 0 } }), { role: "button", "aria-label": t('Clear'), onClick: () => {
|
|
136
150
|
changeValue(null);
|
|
137
151
|
onClear === null || onClear === void 0 ? void 0 : onClear();
|
|
138
152
|
}, children: _jsx(Icon, { children: _jsx(CancelFilled, {}) }) }))), numberButton && !disabled && (_jsxs("div", Object.assign({}, styled('input__number-container'), { children: [_jsx("div", Object.assign({}, styled('input__number'), { role: "button", "aria-label": t('Input', 'Increase number'), onMouseDown: (e) => {
|
package/menu/Menu.js
CHANGED
|
@@ -73,8 +73,7 @@ export function Menu(props) {
|
|
|
73
73
|
onExpandsChange(ids, items);
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
|
-
const {
|
|
77
|
-
const popupIds = popupIdsRef.current;
|
|
76
|
+
const { popupIds, setPopupIds, addPopupId, removePopupId } = useNestedPopup();
|
|
78
77
|
const [focusIds, setFocusIds] = useState([]);
|
|
79
78
|
const focusId = (() => {
|
|
80
79
|
var _a;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laser-ui/components",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "React components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"access": "public",
|
|
38
38
|
"directory": "../../dist/libs/components"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "57a261d870b76433cf5365dde0fe7ffe9b486452"
|
|
41
41
|
}
|
package/spinner/Spinner.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useAsync
|
|
3
|
+
import { useAsync } from '@laser-ui/hooks';
|
|
4
4
|
import { checkNodeExist } from '@laser-ui/utils';
|
|
5
5
|
import { isNumber, isUndefined } from 'lodash';
|
|
6
|
-
import { useEffect, useRef } from 'react';
|
|
6
|
+
import { useEffect, useRef, useState } from 'react';
|
|
7
7
|
import { CLASSES } from './vars';
|
|
8
8
|
import { CircularProgress } from '../circular-progress';
|
|
9
9
|
import { useComponentProps, useNamespace, useStyled } from '../hooks';
|
|
@@ -16,24 +16,22 @@ export function Spinner(props) {
|
|
|
16
16
|
const namespace = useNamespace();
|
|
17
17
|
const styled = useStyled(CLASSES, { spinner: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.spinner }, styleOverrides);
|
|
18
18
|
const async = useAsync();
|
|
19
|
-
const forceUpdate = useForceUpdate();
|
|
20
19
|
const spinnerRef = useRef(null);
|
|
21
|
-
const
|
|
22
|
-
if (visibleProp
|
|
23
|
-
|
|
20
|
+
const [delayTimeout, setDelayTimeout] = useState(false);
|
|
21
|
+
if (!visibleProp && delayTimeout) {
|
|
22
|
+
setDelayTimeout(false);
|
|
24
23
|
}
|
|
25
|
-
const visible = isUndefined(delay) ? visibleProp :
|
|
24
|
+
const visible = isUndefined(delay) ? visibleProp : delayTimeout;
|
|
26
25
|
useEffect(() => {
|
|
27
26
|
if (isNumber(delay) && visibleProp) {
|
|
28
27
|
const clearTid = async.setTimeout(() => {
|
|
29
|
-
|
|
30
|
-
forceUpdate();
|
|
28
|
+
setDelayTimeout(true);
|
|
31
29
|
}, delay);
|
|
32
30
|
return () => {
|
|
33
31
|
clearTid();
|
|
34
32
|
};
|
|
35
33
|
}
|
|
36
|
-
}, [async, delay,
|
|
34
|
+
}, [async, delay, visibleProp]);
|
|
37
35
|
return (_jsx(Transition, { enter: visible, name: `${namespace}-fade`, duration: TTANSITION_DURING_BASE, onSkipEnter: () => {
|
|
38
36
|
if (spinnerRef.current) {
|
|
39
37
|
spinnerRef.current.style.setProperty('--spinner-container-height', `${spinnerRef.current.offsetHeight}px`);
|