@laser-ui/components 0.0.5 → 0.1.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 +10 -0
- package/README.md +23 -24
- package/affix/Affix.js +35 -25
- package/anchor/Anchor.js +14 -21
- package/cascader/Cascader.js +12 -11
- package/date-picker/DatePicker.js +13 -12
- package/dropdown/Dropdown.js +19 -16
- package/dropdown/internal/DropdownSub.d.ts +0 -1
- package/dropdown/internal/DropdownSub.js +26 -17
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useJSS.d.ts +1 -0
- package/hooks/useJSS.js +15 -0
- package/menu/Menu.js +4 -4
- package/menu/internal/MenuSub.d.ts +0 -1
- package/menu/internal/MenuSub.js +26 -17
- package/package.json +8 -6
- package/popover/Popover.js +20 -17
- package/select/Select.js +18 -13
- package/textarea/Textarea.js +12 -5
- package/time-picker/TimePicker.js +13 -12
- package/tooltip/Tooltip.js +24 -21
- package/tree-select/TreeSelect.js +12 -11
|
@@ -5,13 +5,13 @@ import { ReactComponent as CancelFilled } from '@material-design-icons/svg/fille
|
|
|
5
5
|
import { ReactComponent as AccessTimeOutlined } from '@material-design-icons/svg/outlined/access_time.svg';
|
|
6
6
|
import { ReactComponent as SwapHorizOutlined } from '@material-design-icons/svg/outlined/swap_horiz.svg';
|
|
7
7
|
import { isNull, isUndefined } from 'lodash';
|
|
8
|
-
import { forwardRef, useEffect, useImperativeHandle, useRef
|
|
8
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
|
9
9
|
import { TimePickerPanel } from './internal/TimePickerPanel';
|
|
10
10
|
import { deepCompareDate, orderTime } from './utils';
|
|
11
11
|
import { CLASSES } from './vars';
|
|
12
12
|
import { Button } from '../button';
|
|
13
13
|
import dayjs from '../dayjs';
|
|
14
|
-
import { useComponentProps, useControlled, useDesign, useLayout, useListenGlobalScrolling, useMaxIndex, useNamespace, useScopedProps, useStyled, useTranslation, } from '../hooks';
|
|
14
|
+
import { useComponentProps, useControlled, useDesign, useJSS, useLayout, useListenGlobalScrolling, useMaxIndex, useNamespace, useScopedProps, useStyled, useTranslation, } from '../hooks';
|
|
15
15
|
import { Icon } from '../icon';
|
|
16
16
|
import { Portal } from '../internal/portal';
|
|
17
17
|
import { Transition } from '../internal/transition';
|
|
@@ -23,6 +23,7 @@ export const TimePicker = forwardRef((props, ref) => {
|
|
|
23
23
|
const _c = useComponentProps('TimePicker', props), { styleOverrides, styleProvider, formControl, model, defaultModel, visible: visibleProp, defaultVisible, placeholder, range = false, format = 'HH:mm:ss', order: orderProp = 'ascend', clearable: clearableProp = false, size: sizeProp, disabled: disabledProp = false, config, escClosable = true, inputRef, inputRender, onModelChange, onVisibleChange, onClear, afterVisibleChange } = _c, restProps = __rest(_c, ["styleOverrides", "styleProvider", "formControl", "model", "defaultModel", "visible", "defaultVisible", "placeholder", "range", "format", "order", "clearable", "size", "disabled", "config", "escClosable", "inputRef", "inputRender", "onModelChange", "onVisibleChange", "onClear", "afterVisibleChange"]);
|
|
24
24
|
const namespace = useNamespace();
|
|
25
25
|
const styled = useStyled(CLASSES, { 'time-picker': styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider['time-picker'], 'time-picker-popup': styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider['time-picker-popup'] }, styleOverrides);
|
|
26
|
+
const sheet = useJSS();
|
|
26
27
|
const { t } = useTranslation();
|
|
27
28
|
const forceUpdate = useForceUpdate();
|
|
28
29
|
const async = useAsync();
|
|
@@ -104,11 +105,7 @@ export const TimePicker = forwardRef((props, ref) => {
|
|
|
104
105
|
const { size, disabled } = useScopedProps({ size: sizeProp, disabled: disabledProp || (formControl === null || formControl === void 0 ? void 0 : formControl.control.disabled) });
|
|
105
106
|
const maxZIndex = useMaxIndex(visible);
|
|
106
107
|
const zIndex = `calc(var(--${namespace}-zindex-fixed) + ${maxZIndex})`;
|
|
107
|
-
const
|
|
108
|
-
const [popupPositionStyle, setPopupPositionStyle] = useState({
|
|
109
|
-
top: '-200vh',
|
|
110
|
-
left: '-200vw',
|
|
111
|
-
});
|
|
108
|
+
const transformOrigin = useRef();
|
|
112
109
|
const updatePosition = useEventCallback(() => {
|
|
113
110
|
if (visible && boxRef.current && popupRef.current) {
|
|
114
111
|
const height = popupRef.current.offsetHeight;
|
|
@@ -118,12 +115,16 @@ export const TimePicker = forwardRef((props, ref) => {
|
|
|
118
115
|
placement: 'bottom-left',
|
|
119
116
|
inWindow: WINDOW_SPACE,
|
|
120
117
|
});
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
transformOrigin.current = position.transformOrigin;
|
|
119
|
+
if (sheet.classes.position) {
|
|
120
|
+
popupRef.current.classList.toggle(sheet.classes.position, false);
|
|
121
|
+
}
|
|
122
|
+
sheet.replaceRule('position', {
|
|
123
123
|
top: position.top,
|
|
124
124
|
left: position.left,
|
|
125
125
|
maxWidth,
|
|
126
126
|
});
|
|
127
|
+
popupRef.current.classList.toggle(sheet.classes.position, true);
|
|
127
128
|
}
|
|
128
129
|
});
|
|
129
130
|
const listenGlobalScrolling = useListenGlobalScrolling(updatePosition, !visible);
|
|
@@ -304,7 +305,7 @@ export const TimePicker = forwardRef((props, ref) => {
|
|
|
304
305
|
case 'entering':
|
|
305
306
|
transitionStyle = {
|
|
306
307
|
transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_POPUP}ms ease-out`).join(', '),
|
|
307
|
-
transformOrigin,
|
|
308
|
+
transformOrigin: transformOrigin.current,
|
|
308
309
|
};
|
|
309
310
|
break;
|
|
310
311
|
case 'leaving':
|
|
@@ -312,7 +313,7 @@ export const TimePicker = forwardRef((props, ref) => {
|
|
|
312
313
|
transform: 'scaleY(0.7)',
|
|
313
314
|
opacity: 0,
|
|
314
315
|
transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_POPUP}ms ease-in`).join(', '),
|
|
315
|
-
transformOrigin,
|
|
316
|
+
transformOrigin: transformOrigin.current,
|
|
316
317
|
};
|
|
317
318
|
break;
|
|
318
319
|
case 'leaved':
|
|
@@ -322,7 +323,7 @@ export const TimePicker = forwardRef((props, ref) => {
|
|
|
322
323
|
break;
|
|
323
324
|
}
|
|
324
325
|
return (_jsxs("div", Object.assign({}, mergeCS(styled('time-picker-popup'), {
|
|
325
|
-
style: Object.assign(
|
|
326
|
+
style: Object.assign({ zIndex }, transitionStyle),
|
|
326
327
|
}), { ref: popupRef, onMouseDown: (e) => {
|
|
327
328
|
preventBlur(e);
|
|
328
329
|
}, onMouseUp: (e) => {
|
package/tooltip/Tooltip.js
CHANGED
|
@@ -2,9 +2,9 @@ import { __rest } from "tslib";
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useEventCallback, useRefExtra } from '@laser-ui/hooks';
|
|
4
4
|
import { isFunction, isUndefined } from 'lodash';
|
|
5
|
-
import { cloneElement, forwardRef, useId, useImperativeHandle, useRef
|
|
5
|
+
import { cloneElement, forwardRef, useId, useImperativeHandle, useRef } from 'react';
|
|
6
6
|
import { CLASSES, TTANSITION_DURING } from './vars';
|
|
7
|
-
import { useComponentProps, useControlled, useMaxIndex, useNamespace, useStyled } from '../hooks';
|
|
7
|
+
import { useComponentProps, useControlled, useJSS, useMaxIndex, useNamespace, useStyled } from '../hooks';
|
|
8
8
|
import { Popup } from '../internal/popup';
|
|
9
9
|
import { Portal } from '../internal/portal';
|
|
10
10
|
import { Transition } from '../internal/transition';
|
|
@@ -14,35 +14,38 @@ export const Tooltip = forwardRef((props, ref) => {
|
|
|
14
14
|
const _b = useComponentProps('Tooltip', props), { children, styleOverrides, styleProvider, title, visible: visibleProp, defaultVisible, trigger = 'hover', placement: placementProp = 'top', placementFixed = false, arrow = true, escClosable = true, gap = 10, inWindow = false, mouseEnterDelay = 150, mouseLeaveDelay = 200, skipFirstTransition = true, destroyAfterClose = true, zIndex: zIndexProp, scrolling, onVisibleChange, afterVisibleChange } = _b, restProps = __rest(_b, ["children", "styleOverrides", "styleProvider", "title", "visible", "defaultVisible", "trigger", "placement", "placementFixed", "arrow", "escClosable", "gap", "inWindow", "mouseEnterDelay", "mouseLeaveDelay", "skipFirstTransition", "destroyAfterClose", "zIndex", "scrolling", "onVisibleChange", "afterVisibleChange"]);
|
|
15
15
|
const namespace = useNamespace();
|
|
16
16
|
const styled = useStyled(CLASSES, { tooltip: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.tooltip }, styleOverrides);
|
|
17
|
+
const sheet = useJSS();
|
|
17
18
|
const uniqueId = useId();
|
|
18
19
|
const id = (_a = restProps.id) !== null && _a !== void 0 ? _a : `${namespace}-tooltip-${uniqueId}`;
|
|
19
20
|
const triggerRef = useRefExtra(() => document.querySelector(`[aria-describedby="${id}"]`));
|
|
20
|
-
const
|
|
21
|
+
const tooltipRef = useRef(null);
|
|
21
22
|
const scrollingRef = useRefExtra(scrolling);
|
|
22
23
|
const [visible, changeVisible] = useControlled(defaultVisible !== null && defaultVisible !== void 0 ? defaultVisible : false, visibleProp, onVisibleChange);
|
|
23
24
|
const maxZIndex = useMaxIndex(visible);
|
|
24
25
|
const zIndex = !isUndefined(zIndexProp) ? zIndexProp : `calc(var(--${namespace}-zindex-fixed) + ${maxZIndex})`;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
left: '-200vw',
|
|
28
|
-
});
|
|
29
|
-
const [transformOrigin, setTransformOrigin] = useState();
|
|
30
|
-
const [placement, setPlacement] = useState(placementProp);
|
|
26
|
+
const transformOrigin = useRef();
|
|
27
|
+
const placement = useRef(placementProp);
|
|
31
28
|
const updatePosition = useEventCallback(() => {
|
|
32
|
-
if (visible && triggerRef.current &&
|
|
33
|
-
const position = getPopupPosition(triggerRef.current, { width:
|
|
29
|
+
if (visible && triggerRef.current && tooltipRef.current) {
|
|
30
|
+
const position = getPopupPosition(triggerRef.current, { width: tooltipRef.current.offsetWidth, height: tooltipRef.current.offsetHeight }, {
|
|
34
31
|
placement: placementProp,
|
|
35
|
-
placementFallback: placement,
|
|
32
|
+
placementFallback: placement.current,
|
|
36
33
|
placementFixed,
|
|
37
34
|
gap,
|
|
38
35
|
inWindow,
|
|
39
36
|
});
|
|
40
|
-
|
|
37
|
+
transformOrigin.current = position.transformOrigin;
|
|
38
|
+
tooltipRef.current.classList.toggle(`${namespace}-tooltip--${placement.current}`, false);
|
|
39
|
+
placement.current = position.placement;
|
|
40
|
+
tooltipRef.current.classList.toggle(`${namespace}-tooltip--${placement.current}`, true);
|
|
41
|
+
if (sheet.classes.position) {
|
|
42
|
+
tooltipRef.current.classList.toggle(sheet.classes.position, false);
|
|
43
|
+
}
|
|
44
|
+
sheet.replaceRule('position', {
|
|
41
45
|
top: position.top,
|
|
42
46
|
left: position.left,
|
|
43
47
|
});
|
|
44
|
-
|
|
45
|
-
setPlacement(position.placement);
|
|
48
|
+
tooltipRef.current.classList.toggle(sheet.classes.position, true);
|
|
46
49
|
}
|
|
47
50
|
});
|
|
48
51
|
useImperativeHandle(ref, () => ({
|
|
@@ -51,7 +54,7 @@ export const Tooltip = forwardRef((props, ref) => {
|
|
|
51
54
|
return (_jsx(Popup, { visible: visible, trigger: trigger, mouseEnterDelay: mouseEnterDelay, mouseLeaveDelay: mouseLeaveDelay, updatePosition: {
|
|
52
55
|
fn: updatePosition,
|
|
53
56
|
triggerRef,
|
|
54
|
-
popupRef,
|
|
57
|
+
popupRef: tooltipRef,
|
|
55
58
|
containerRefs: [scrollingRef],
|
|
56
59
|
}, onVisibleChange: changeVisible, children: ({ renderTrigger, renderPopup }) => {
|
|
57
60
|
const render = (el) => renderTrigger(cloneElement(el, {
|
|
@@ -87,7 +90,7 @@ export const Tooltip = forwardRef((props, ref) => {
|
|
|
87
90
|
case 'entering':
|
|
88
91
|
transitionStyle = {
|
|
89
92
|
transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING.enter}ms ease-out`).join(', '),
|
|
90
|
-
transformOrigin,
|
|
93
|
+
transformOrigin: transformOrigin.current,
|
|
91
94
|
};
|
|
92
95
|
break;
|
|
93
96
|
case 'leaving':
|
|
@@ -95,7 +98,7 @@ export const Tooltip = forwardRef((props, ref) => {
|
|
|
95
98
|
transform: 'scale(0.3)',
|
|
96
99
|
opacity: 0,
|
|
97
100
|
transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING.leave}ms ease-in`).join(', '),
|
|
98
|
-
transformOrigin,
|
|
101
|
+
transformOrigin: transformOrigin.current,
|
|
99
102
|
};
|
|
100
103
|
break;
|
|
101
104
|
case 'leaved':
|
|
@@ -104,10 +107,10 @@ export const Tooltip = forwardRef((props, ref) => {
|
|
|
104
107
|
default:
|
|
105
108
|
break;
|
|
106
109
|
}
|
|
107
|
-
return renderPopup(_jsxs("div", Object.assign({}, restProps, mergeCS(styled('tooltip'
|
|
110
|
+
return renderPopup(_jsxs("div", Object.assign({}, restProps, mergeCS(styled('tooltip'), {
|
|
108
111
|
className: restProps.className,
|
|
109
|
-
style: Object.assign(Object.assign(Object.assign(
|
|
110
|
-
}), { ref:
|
|
112
|
+
style: Object.assign(Object.assign(Object.assign({}, restProps.style), { zIndex }), transitionStyle),
|
|
113
|
+
}), { ref: tooltipRef, id: id, role: "tooltip", children: [arrow && _jsx("div", Object.assign({}, styled('tooltip__arrow'))), title] })));
|
|
111
114
|
} }) })] }));
|
|
112
115
|
} }));
|
|
113
116
|
});
|
|
@@ -11,7 +11,7 @@ import { createElement, forwardRef, useId, useImperativeHandle, useMemo, useRef,
|
|
|
11
11
|
import { TreeSelectSearchPanel } from './internal/TreeSelectSearchPanel';
|
|
12
12
|
import { CLASSES } from './vars';
|
|
13
13
|
import { Dropdown } from '../dropdown';
|
|
14
|
-
import { useComponentProps, useControlled, useDesign, useFocusVisible, useLayout, useListenGlobalScrolling, useMaxIndex, useNamespace, useScopedProps, useStyled, useTranslation, } from '../hooks';
|
|
14
|
+
import { useComponentProps, useControlled, useDesign, useFocusVisible, useJSS, useLayout, useListenGlobalScrolling, useMaxIndex, useNamespace, useScopedProps, useStyled, useTranslation, } from '../hooks';
|
|
15
15
|
import { Icon } from '../icon';
|
|
16
16
|
import { CircularProgress } from '../internal/circular-progress';
|
|
17
17
|
import { Portal } from '../internal/portal';
|
|
@@ -33,6 +33,7 @@ function TreeSelectFC(props, ref) {
|
|
|
33
33
|
tree: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.tree,
|
|
34
34
|
'tree-select-popup': styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider['tree-select-popup'],
|
|
35
35
|
}, styleOverrides);
|
|
36
|
+
const sheet = useJSS();
|
|
36
37
|
const dataRef = useRef({
|
|
37
38
|
expands: new Set(),
|
|
38
39
|
});
|
|
@@ -179,11 +180,7 @@ function TreeSelectFC(props, ref) {
|
|
|
179
180
|
})();
|
|
180
181
|
const maxZIndex = useMaxIndex(visible);
|
|
181
182
|
const zIndex = `calc(var(--${namespace}-zindex-fixed) + ${maxZIndex})`;
|
|
182
|
-
const
|
|
183
|
-
const [popupPositionStyle, setPopupPositionStyle] = useState({
|
|
184
|
-
top: '-200vh',
|
|
185
|
-
left: '-200vw',
|
|
186
|
-
});
|
|
183
|
+
const transformOrigin = useRef();
|
|
187
184
|
const updatePosition = useEventCallback(() => {
|
|
188
185
|
if (visible && boxRef.current && popupRef.current) {
|
|
189
186
|
const boxWidth = boxRef.current.offsetWidth;
|
|
@@ -194,13 +191,17 @@ function TreeSelectFC(props, ref) {
|
|
|
194
191
|
placement: 'bottom-left',
|
|
195
192
|
inWindow: WINDOW_SPACE,
|
|
196
193
|
});
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
transformOrigin.current = position.transformOrigin;
|
|
195
|
+
if (sheet.classes.position) {
|
|
196
|
+
popupRef.current.classList.toggle(sheet.classes.position, false);
|
|
197
|
+
}
|
|
198
|
+
sheet.replaceRule('position', {
|
|
199
199
|
top: position.top,
|
|
200
200
|
left: position.left,
|
|
201
201
|
minWidth: Math.min(boxWidth, maxWidth),
|
|
202
202
|
maxWidth,
|
|
203
203
|
});
|
|
204
|
+
popupRef.current.classList.toggle(sheet.classes.position, true);
|
|
204
205
|
}
|
|
205
206
|
});
|
|
206
207
|
const listenGlobalScrolling = useListenGlobalScrolling(updatePosition, !visible);
|
|
@@ -475,7 +476,7 @@ function TreeSelectFC(props, ref) {
|
|
|
475
476
|
case 'entering':
|
|
476
477
|
transitionStyle = {
|
|
477
478
|
transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_POPUP}ms ease-out`).join(', '),
|
|
478
|
-
transformOrigin,
|
|
479
|
+
transformOrigin: transformOrigin.current,
|
|
479
480
|
};
|
|
480
481
|
break;
|
|
481
482
|
case 'leaving':
|
|
@@ -483,7 +484,7 @@ function TreeSelectFC(props, ref) {
|
|
|
483
484
|
transform: 'scaleY(0.7)',
|
|
484
485
|
opacity: 0,
|
|
485
486
|
transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_POPUP}ms ease-in`).join(', '),
|
|
486
|
-
transformOrigin,
|
|
487
|
+
transformOrigin: transformOrigin.current,
|
|
487
488
|
};
|
|
488
489
|
break;
|
|
489
490
|
case 'leaved':
|
|
@@ -493,7 +494,7 @@ function TreeSelectFC(props, ref) {
|
|
|
493
494
|
break;
|
|
494
495
|
}
|
|
495
496
|
return (_jsxs("div", Object.assign({}, mergeCS(styled('tree-select-popup'), {
|
|
496
|
-
style: Object.assign(
|
|
497
|
+
style: Object.assign({ zIndex }, transitionStyle),
|
|
497
498
|
}), { ref: popupRef, onMouseDown: (e) => {
|
|
498
499
|
preventBlur(e);
|
|
499
500
|
}, onMouseUp: (e) => {
|