@canlooks/can-ui 0.0.75 → 0.0.77
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/cjs/components/curd/curdResizable.js +1 -1
- package/dist/cjs/components/dataGrid/dataGrid.js +1 -1
- package/dist/cjs/components/dateTimePicker/dateTimePicker.d.ts +4 -4
- package/dist/cjs/components/dateTimePicker/dateTimePicker.js +14 -190
- package/dist/cjs/components/dateTimePicker/dateTimePicker.style.d.ts +2 -12
- package/dist/cjs/components/dateTimePicker/dateTimePicker.style.js +20 -17
- package/dist/cjs/components/descriptions/descriptions.js +1 -5
- package/dist/cjs/components/dialog/dialog.js +1 -1
- package/dist/cjs/components/inputBase/inputBase.js +10 -1
- package/dist/cjs/components/popper/popper.js +21 -20
- package/dist/cjs/components/table/table.d.ts +1 -1
- package/dist/cjs/components/table/table.js +3 -1
- package/dist/cjs/components/table/table.style.js +21 -6
- package/dist/cjs/components/table/tableSticky.js +19 -16
- package/dist/cjs/components/table/tableSticky.style.js +0 -8
- package/dist/cjs/utils/utils.d.ts +5 -3
- package/dist/cjs/utils/utils.js +22 -7
- package/dist/esm/components/curd/curdResizable.js +1 -1
- package/dist/esm/components/dataGrid/dataGrid.js +1 -1
- package/dist/esm/components/dateTimePicker/dateTimePicker.d.ts +4 -4
- package/dist/esm/components/dateTimePicker/dateTimePicker.js +15 -191
- package/dist/esm/components/dateTimePicker/dateTimePicker.style.d.ts +2 -12
- package/dist/esm/components/dateTimePicker/dateTimePicker.style.js +20 -17
- package/dist/esm/components/descriptions/descriptions.js +1 -5
- package/dist/esm/components/dialog/dialog.js +1 -1
- package/dist/esm/components/inputBase/inputBase.js +11 -2
- package/dist/esm/components/popper/popper.js +22 -21
- package/dist/esm/components/table/table.d.ts +1 -1
- package/dist/esm/components/table/table.js +4 -2
- package/dist/esm/components/table/table.style.js +21 -6
- package/dist/esm/components/table/tableSticky.js +20 -17
- package/dist/esm/components/table/tableSticky.style.js +0 -8
- package/dist/esm/utils/utils.d.ts +5 -3
- package/dist/esm/utils/utils.js +21 -6
- package/package.json +1 -1
|
@@ -9,22 +9,29 @@ const utils_1 = require("../../utils");
|
|
|
9
9
|
const table_style_1 = require("./table.style");
|
|
10
10
|
const tableSticky_style_1 = require("./tableSticky.style");
|
|
11
11
|
exports.TableContainer = (({ component: Component = 'div', ...props }) => {
|
|
12
|
-
const [scrolledLeft, setScrolledLeft] = (0, react_1.useState)(false);
|
|
13
|
-
const [scrolledRight, setScrolledRight] = (0, react_1.useState)(false);
|
|
14
12
|
const innerRef = (0, react_1.useRef)(null);
|
|
15
13
|
(0, react_1.useEffect)(() => {
|
|
16
14
|
const el = innerRef.current;
|
|
17
15
|
const scroll = () => {
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
el.dataset.scrolledLeft = (el.scrollLeft > 0).toString();
|
|
17
|
+
el.dataset.scrolledRight = (el.scrollWidth - el.clientWidth > el.scrollLeft).toString();
|
|
20
18
|
};
|
|
21
19
|
scroll();
|
|
22
20
|
el.addEventListener('scroll', scroll);
|
|
21
|
+
const table = el.getElementsByTagName('table')[0];
|
|
22
|
+
const resizeObserver = new ResizeObserver(scroll);
|
|
23
|
+
resizeObserver.observe(el);
|
|
24
|
+
table && resizeObserver.observe(table);
|
|
23
25
|
return () => {
|
|
24
26
|
el.removeEventListener('scroll', scroll);
|
|
27
|
+
resizeObserver.disconnect();
|
|
25
28
|
};
|
|
26
29
|
}, []);
|
|
27
|
-
return ((0, jsx_runtime_1.jsx)(Component, { ...
|
|
30
|
+
return ((0, jsx_runtime_1.jsx)(Component, { ...(0, utils_1.mergeComponentProps)(props, {
|
|
31
|
+
ref: innerRef,
|
|
32
|
+
css: tableSticky_style_1.style,
|
|
33
|
+
className: table_style_1.classes.container
|
|
34
|
+
}) }));
|
|
28
35
|
});
|
|
29
36
|
function TdCell(props) {
|
|
30
37
|
return (0, jsx_runtime_1.jsx)("td", { ...useStickyCellProps(props) });
|
|
@@ -32,7 +39,7 @@ function TdCell(props) {
|
|
|
32
39
|
function ThCell(props) {
|
|
33
40
|
return (0, jsx_runtime_1.jsx)("th", { ...useStickyCellProps(props) });
|
|
34
41
|
}
|
|
35
|
-
function useStickyCellProps({
|
|
42
|
+
function useStickyCellProps({ sticky, ...props }) {
|
|
36
43
|
const innerRef = (0, react_1.useRef)(null);
|
|
37
44
|
const [offset, setOffset] = (0, react_1.useState)(0);
|
|
38
45
|
(0, react_1.useEffect)(() => {
|
|
@@ -62,15 +69,11 @@ function useStickyCellProps({ ref, sticky, ...props }) {
|
|
|
62
69
|
resizeObserver.disconnect();
|
|
63
70
|
};
|
|
64
71
|
});
|
|
65
|
-
return {
|
|
66
|
-
|
|
67
|
-
ref: (0, utils_1.cloneRef)(ref, innerRef),
|
|
72
|
+
return (0, utils_1.mergeComponentProps)(props, {
|
|
73
|
+
ref: innerRef,
|
|
68
74
|
css: tableSticky_style_1.style,
|
|
69
|
-
className:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
...props.style
|
|
74
|
-
}
|
|
75
|
-
};
|
|
75
|
+
className: table_style_1.classes.cell,
|
|
76
|
+
style: sticky && { [sticky]: offset },
|
|
77
|
+
'data-sticky': sticky
|
|
78
|
+
});
|
|
76
79
|
}
|
|
@@ -6,14 +6,6 @@ const react_1 = require("@emotion/react");
|
|
|
6
6
|
exports.style = (0, utils_1.defineCss)(({ background, easing }) => (0, react_1.css) `
|
|
7
7
|
overflow: auto;
|
|
8
8
|
|
|
9
|
-
tbody tr {
|
|
10
|
-
&:not(:hover):not([data-selected=true]) {
|
|
11
|
-
th, td {
|
|
12
|
-
background-color: ${background.content};
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
9
|
th, td {
|
|
18
10
|
&[data-sticky=left], &[data-sticky=right] {
|
|
19
11
|
overflow: visible;
|
|
@@ -47,12 +47,14 @@ export declare function mergeDeep<T extends {}, U, V, W, X>(target: T, source: U
|
|
|
47
47
|
export declare function mergeDeep<T extends {}, U, V, W, X, Y>(target: T, source: U, source2: V, source3: W, source4: X, source5: Y): T & U & V & W & X & Y;
|
|
48
48
|
export declare function mergeDeep<T extends {}, U, V, W, X, Y, Z>(target: T, source: U, source2: V, source3: W, source4: X, source5: Y, source6: Z): T & U & V & W & X & Y & Z;
|
|
49
49
|
export declare function mergeDeep(target: object, ...sources: any[]): any;
|
|
50
|
+
export type OverflowEdge = 'top' | 'bottom' | 'left' | 'right';
|
|
50
51
|
/**
|
|
51
52
|
* 判断元素是否完全在目标容器内,用于Popper组件
|
|
52
|
-
* @param target
|
|
53
|
-
* @param container
|
|
53
|
+
* @param target 目标元素
|
|
54
|
+
* @param container 容器
|
|
55
|
+
* @returns 'top' | 'bottom' | 'left' | 'right' | false
|
|
54
56
|
*/
|
|
55
|
-
export declare function
|
|
57
|
+
export declare function isElementOverflowed(target: Element, container?: Element): OverflowEdge | false;
|
|
56
58
|
/**
|
|
57
59
|
* 下一个事件循环
|
|
58
60
|
* @param callback
|
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.toArray = toArray;
|
|
|
8
8
|
exports.isSelected = isSelected;
|
|
9
9
|
exports.cloneDeep = cloneDeep;
|
|
10
10
|
exports.mergeDeep = mergeDeep;
|
|
11
|
-
exports.
|
|
11
|
+
exports.isElementOverflowed = isElementOverflowed;
|
|
12
12
|
exports.nextTick = nextTick;
|
|
13
13
|
exports.cloneRef = cloneRef;
|
|
14
14
|
exports.isUnset = isUnset;
|
|
@@ -138,18 +138,33 @@ function mergeDeep(target, ...sources) {
|
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
140
|
* 判断元素是否完全在目标容器内,用于Popper组件
|
|
141
|
-
* @param target
|
|
142
|
-
* @param container
|
|
141
|
+
* @param target 目标元素
|
|
142
|
+
* @param container 容器
|
|
143
|
+
* @returns 'top' | 'bottom' | 'left' | 'right' | false
|
|
143
144
|
*/
|
|
144
|
-
function
|
|
145
|
+
function isElementOverflowed(target, container) {
|
|
145
146
|
const { left, top, right, bottom } = target.getBoundingClientRect();
|
|
147
|
+
const judge = (containerBounding) => {
|
|
148
|
+
if (left < containerBounding.left) {
|
|
149
|
+
return 'left';
|
|
150
|
+
}
|
|
151
|
+
if (top < containerBounding.top) {
|
|
152
|
+
return 'top';
|
|
153
|
+
}
|
|
154
|
+
if (right > containerBounding.right) {
|
|
155
|
+
return 'right';
|
|
156
|
+
}
|
|
157
|
+
if (bottom > containerBounding.bottom) {
|
|
158
|
+
return 'bottom';
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
};
|
|
146
162
|
if (container) {
|
|
147
|
-
|
|
148
|
-
return left >= containerLeft && top >= containerTop && right <= containerRight && bottom <= containerBottom;
|
|
163
|
+
return judge(container.getBoundingClientRect());
|
|
149
164
|
}
|
|
150
165
|
const vWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
151
166
|
const vHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
152
|
-
return left
|
|
167
|
+
return judge({ left: 0, top: 0, right: vWidth, bottom: vHeight });
|
|
153
168
|
}
|
|
154
169
|
/**
|
|
155
170
|
* 下一个事件循环
|
|
@@ -7,5 +7,5 @@ import { Button } from '../button';
|
|
|
7
7
|
import { Icon } from '../icon';
|
|
8
8
|
import { faArrowsUpDown } from '@fortawesome/free-solid-svg-icons/faArrowsUpDown';
|
|
9
9
|
export const CurdResizable = memo(({ innerSize, setInnerSize }) => {
|
|
10
|
-
return (_jsx(Tooltip, { title: "\u8868\u683C\u5C3A\u5BF8", children: _jsx(Bubble, { placement: "bottom", content: _jsxs(_Fragment, { children: [_jsx(MenuItem, { value: "small", label: "\u5C0F", selected: innerSize === 'small', onClick: () => setInnerSize('small') }), _jsx(MenuItem, { value: "medium", label: "\u4E2D", selected: innerSize === 'medium', onClick: () => setInnerSize('medium') }), _jsx(MenuItem, { value: "large", label: "\u5927", selected: innerSize === 'large', onClick: () => setInnerSize('large') })] }), children: _jsx(Button, { shape: "circular", variant: "text", color: "text.secondary", children: _jsx(Icon, { icon: faArrowsUpDown }) }) }) }));
|
|
10
|
+
return (_jsx(Tooltip, { title: "\u8868\u683C\u5C3A\u5BF8", clickToClose: true, children: _jsx(Bubble, { placement: "bottom", trigger: "click", content: _jsxs(_Fragment, { children: [_jsx(MenuItem, { value: "small", label: "\u5C0F", selected: innerSize === 'small', onClick: () => setInnerSize('small') }), _jsx(MenuItem, { value: "medium", label: "\u4E2D", selected: innerSize === 'medium', onClick: () => setInnerSize('medium') }), _jsx(MenuItem, { value: "large", label: "\u5927", selected: innerSize === 'large', onClick: () => setInnerSize('large') })] }), children: _jsx(Button, { shape: "circular", variant: "text", color: "text.secondary", children: _jsx(Icon, { icon: faArrowsUpDown }) }) }) }));
|
|
11
11
|
});
|
|
@@ -117,7 +117,7 @@ export const DataGrid = memo(({ columns, rows, rowProps, primaryKey = 'id', chil
|
|
|
117
117
|
const renderPaginationFn = () => {
|
|
118
118
|
return renderPagination
|
|
119
119
|
? renderPagination(_paginationProps)
|
|
120
|
-
: _jsx(Pagination, { ..._paginationProps });
|
|
120
|
+
: paginatable && _jsx(Pagination, { ..._paginationProps });
|
|
121
121
|
};
|
|
122
122
|
const paginatedRows = useMemo(() => {
|
|
123
123
|
if (!paginatable) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PopperProps } from '../popper';
|
|
3
|
-
import { InputBaseProps } from '../inputBase';
|
|
1
|
+
import { ComponentProps } from 'react';
|
|
4
2
|
import { Dayjs } from 'dayjs';
|
|
3
|
+
import { InputBaseProps } from '../inputBase';
|
|
4
|
+
import { PopperProps } from '../popper';
|
|
5
5
|
export type DatePickerSharedProps = {
|
|
6
6
|
min?: Dayjs;
|
|
7
7
|
max?: Dayjs;
|
|
@@ -23,4 +23,4 @@ export interface DateTimePickerProps extends DatePickerSharedProps, Omit<InputBa
|
|
|
23
23
|
disabledDates?: (date: Dayjs) => any;
|
|
24
24
|
}
|
|
25
25
|
export declare function useDateTimePickerContext(): DatePickerSharedProps;
|
|
26
|
-
export declare const DateTimePicker:
|
|
26
|
+
export declare const DateTimePicker: import("react").MemoExoticComponent<({ inputProps, popperProps, min, max, disabledDates, disabledHours, disabledMinutes, disabledSeconds, format, defaultValue, value, onChange, defaultOpen, open, onOpenChange, autoClose, ...props }: DateTimePickerProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
|
|
@@ -1,205 +1,31 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import { createContext, memo, useContext,
|
|
3
|
-
import { Popper } from '../popper';
|
|
4
|
-
import { InputBase } from '../inputBase';
|
|
5
|
-
import { useControlled, mergeComponentProps } from '../../utils';
|
|
2
|
+
import { createContext, memo, useContext, useMemo, useRef } from 'react';
|
|
6
3
|
import { classes, datePickerPopperStyle, style } from './dateTimePicker.style';
|
|
7
4
|
import dayjs from 'dayjs';
|
|
8
|
-
import
|
|
5
|
+
import { InputBase } from '../inputBase';
|
|
6
|
+
import { mergeComponentProps, useControlled } from '../../utils';
|
|
7
|
+
import { Popper } from '../popper';
|
|
9
8
|
import { Calendar } from '../calendar';
|
|
10
|
-
import { Timer } from './timer';
|
|
11
9
|
import { Icon } from '../icon';
|
|
12
10
|
import { faCalendar } from '@fortawesome/free-regular-svg-icons/faCalendar';
|
|
13
11
|
import { faClock } from '@fortawesome/free-regular-svg-icons/faClock';
|
|
14
|
-
|
|
15
|
-
const availableFormatTokens = ['Y', 'M', 'D', 'H', 'm', 's'];
|
|
12
|
+
import { Timer } from './timer';
|
|
16
13
|
const DateTimePickerContext = createContext({});
|
|
17
14
|
export function useDateTimePickerContext() {
|
|
18
15
|
return useContext(DateTimePickerContext);
|
|
19
16
|
}
|
|
20
17
|
export const DateTimePicker = memo(({ inputProps, popperProps, min, max, disabledDates, disabledHours, disabledMinutes, disabledSeconds, format = 'YYYY-MM-DD', defaultValue = null, value, onChange, defaultOpen = false, open, onOpenChange, autoClose = !/[Hms]/.test(format), ...props }) => {
|
|
21
|
-
const innerInputRef = useRef(null);
|
|
22
18
|
const focused = useRef(false);
|
|
23
19
|
const [innerOpen, _setInnerOpen] = useControlled(defaultOpen, open, onOpenChange);
|
|
24
20
|
const setInnerOpen = (open) => {
|
|
25
21
|
// 如果仍聚焦在输入框,则不用关闭弹框
|
|
26
22
|
(open || !focused.current) && _setInnerOpen(open);
|
|
27
23
|
};
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (!innerOpen.current && !dateValue.current) {
|
|
30
|
-
// 弹框关闭时没有选中日期,清空输入框
|
|
31
|
-
innerInputRef.current.value = format;
|
|
32
|
-
}
|
|
33
|
-
}, [innerOpen.current]);
|
|
34
24
|
const [dateValue, _setDateValue] = useControlled(defaultValue, value, onChange);
|
|
35
25
|
const setDateValue = (date) => {
|
|
36
26
|
_setDateValue(date);
|
|
37
27
|
autoClose && _setInnerOpen(false);
|
|
38
28
|
};
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
innerInputRef.current.value = dateValue.current?.format(format) ?? format;
|
|
41
|
-
}, [dateValue.current]);
|
|
42
|
-
const clearHandler = () => {
|
|
43
|
-
setDateValue(null);
|
|
44
|
-
selectFn();
|
|
45
|
-
};
|
|
46
|
-
const ranges = useMemo(() => {
|
|
47
|
-
const range = [];
|
|
48
|
-
format.length && availableFormatTokens.forEach(token => {
|
|
49
|
-
const matched = format.match(new RegExp(`${token}+`));
|
|
50
|
-
if (matched && typeof matched.index === 'number') {
|
|
51
|
-
range.push({
|
|
52
|
-
token,
|
|
53
|
-
start: matched.index,
|
|
54
|
-
end: matched.index + matched[0].length
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return range;
|
|
59
|
-
}, [format]);
|
|
60
|
-
const currentRange = useRef(null);
|
|
61
|
-
const selectFn = () => {
|
|
62
|
-
const input = innerInputRef.current;
|
|
63
|
-
const { selectionStart } = input;
|
|
64
|
-
const range = ranges.find(({ end }) => (selectionStart || 0) <= end) || ranges[ranges.length - 1];
|
|
65
|
-
if (range) {
|
|
66
|
-
currentRange.current = range;
|
|
67
|
-
input.value ||= format;
|
|
68
|
-
input.setSelectionRange(range.start, range.end);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const selectHandler = (e) => {
|
|
72
|
-
if (e.nativeEvent.type === 'selectionchange' || !ranges.length) {
|
|
73
|
-
// setSelectionRange()方法也会触发该回调,通过nativeEvent.type排除
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
selectFn();
|
|
77
|
-
};
|
|
78
|
-
const focusHandler = () => {
|
|
79
|
-
focused.current = true;
|
|
80
|
-
selectFn();
|
|
81
|
-
};
|
|
82
|
-
const blurHandler = () => {
|
|
83
|
-
resetContinue();
|
|
84
|
-
focused.current = false;
|
|
85
|
-
_setInnerOpen(false);
|
|
86
|
-
};
|
|
87
|
-
const valueContinueHelper = useRef({ token: '', value: '' });
|
|
88
|
-
const resetContinue = () => {
|
|
89
|
-
valueContinueHelper.current = { token: '', value: '' };
|
|
90
|
-
};
|
|
91
|
-
const keydownHandler = (e) => {
|
|
92
|
-
if (!currentRange.current) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const { key } = e;
|
|
96
|
-
const input = e.target;
|
|
97
|
-
const { token, start, end } = currentRange.current;
|
|
98
|
-
if (/^\d$/.test(e.key)) {
|
|
99
|
-
// 数字键
|
|
100
|
-
e.preventDefault();
|
|
101
|
-
let continuedValue;
|
|
102
|
-
if (valueContinueHelper.current.token === token) {
|
|
103
|
-
continuedValue = valueContinueHelper.current.value += key;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
valueContinueHelper.current = { token, value: key };
|
|
107
|
-
continuedValue = key;
|
|
108
|
-
}
|
|
109
|
-
input.value = `${input.value.slice(0, start)}${continuedValue.padStart(end - start, '0')}${input.value.slice(end)}`;
|
|
110
|
-
input.setSelectionRange(start, end);
|
|
111
|
-
const d = dayjs(input.value, format);
|
|
112
|
-
d.isValid() && _setDateValue(d);
|
|
113
|
-
// 当长度达到,或者数值超过,将会跳转下一个range
|
|
114
|
-
if (token === 'Y') {
|
|
115
|
-
if (continuedValue.length === 4) {
|
|
116
|
-
return selectNext(input);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
else if (continuedValue.length === 2) {
|
|
120
|
-
return selectNext(input);
|
|
121
|
-
}
|
|
122
|
-
switch (token) {
|
|
123
|
-
case 'M':
|
|
124
|
-
if (+key > 1) {
|
|
125
|
-
return selectNext(input);
|
|
126
|
-
}
|
|
127
|
-
break;
|
|
128
|
-
case 'D':
|
|
129
|
-
if (+key > 3) {
|
|
130
|
-
return selectNext(input);
|
|
131
|
-
}
|
|
132
|
-
break;
|
|
133
|
-
default:
|
|
134
|
-
// 'H' | 'm' | 's'
|
|
135
|
-
if (+key > 5) {
|
|
136
|
-
return selectNext(input);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
switch (key) {
|
|
141
|
-
case 'Backspace':
|
|
142
|
-
case 'Delete':
|
|
143
|
-
case 'ArrowLeft':
|
|
144
|
-
case 'ArrowRight':
|
|
145
|
-
case 'ArrowUp':
|
|
146
|
-
case 'ArrowDown':
|
|
147
|
-
case 'Escape':
|
|
148
|
-
e.preventDefault();
|
|
149
|
-
resetContinue();
|
|
150
|
-
}
|
|
151
|
-
switch (key) {
|
|
152
|
-
case 'Backspace':
|
|
153
|
-
case 'Delete':
|
|
154
|
-
input.value = `${input.value.slice(0, start)}${format.slice(start, end)}${input.value.slice(end)}`;
|
|
155
|
-
input.setSelectionRange(start, end);
|
|
156
|
-
_setDateValue(null);
|
|
157
|
-
break;
|
|
158
|
-
case 'ArrowLeft':
|
|
159
|
-
const prevRange = ranges[ranges.indexOf(currentRange.current) - 1] || ranges[0];
|
|
160
|
-
currentRange.current = prevRange;
|
|
161
|
-
input.setSelectionRange(prevRange.start, prevRange.end);
|
|
162
|
-
break;
|
|
163
|
-
case 'ArrowRight':
|
|
164
|
-
selectNext(input);
|
|
165
|
-
break;
|
|
166
|
-
case 'ArrowUp':
|
|
167
|
-
case 'ArrowDown':
|
|
168
|
-
let valueFragment = +input.value.slice(start, end);
|
|
169
|
-
if (isNaN(valueFragment)) {
|
|
170
|
-
valueFragment = 0;
|
|
171
|
-
}
|
|
172
|
-
key === 'ArrowUp' ? valueFragment++ : valueFragment--;
|
|
173
|
-
switch (token) {
|
|
174
|
-
case 'Y':
|
|
175
|
-
break;
|
|
176
|
-
case 'M':
|
|
177
|
-
valueFragment >= 13 ? valueFragment = 1
|
|
178
|
-
: valueFragment <= 0 && (valueFragment = 12);
|
|
179
|
-
break;
|
|
180
|
-
case 'D':
|
|
181
|
-
valueFragment >= 32 ? valueFragment = 1
|
|
182
|
-
: valueFragment <= 0 && (valueFragment = 31);
|
|
183
|
-
break;
|
|
184
|
-
default:
|
|
185
|
-
valueFragment >= 60 ? valueFragment = 1
|
|
186
|
-
: valueFragment <= 0 && (valueFragment = 59);
|
|
187
|
-
}
|
|
188
|
-
input.value = `${input.value.slice(0, start)}${valueFragment.toString().padStart(end - start, '0')}${input.value.slice(end)}`;
|
|
189
|
-
input.setSelectionRange(start, end);
|
|
190
|
-
const d = dayjs(input.value, format);
|
|
191
|
-
d.isValid() && _setDateValue(d);
|
|
192
|
-
break;
|
|
193
|
-
case 'Escape':
|
|
194
|
-
_setInnerOpen(false);
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
const selectNext = (input) => {
|
|
198
|
-
resetContinue();
|
|
199
|
-
const nextRange = ranges[ranges.indexOf(currentRange.current) + 1] || ranges[ranges.length - 1];
|
|
200
|
-
currentRange.current = nextRange;
|
|
201
|
-
input.setSelectionRange(nextRange.start, nextRange.end);
|
|
202
|
-
};
|
|
203
29
|
const contextValue = useMemo(() => ({
|
|
204
30
|
min, max, disabledHours, disabledMinutes, disabledSeconds
|
|
205
31
|
}), [
|
|
@@ -207,7 +33,8 @@ export const DateTimePicker = memo(({ inputProps, popperProps, min, max, disable
|
|
|
207
33
|
]);
|
|
208
34
|
const showCalendar = /[YMD]/.test(format);
|
|
209
35
|
const showTimer = /[Hms]/.test(format);
|
|
210
|
-
|
|
36
|
+
// 若外部没有值,内部需要“现在”作为默认值
|
|
37
|
+
const innerValue = dateValue.current || dayjs();
|
|
211
38
|
return (_jsx(Popper, { ...mergeComponentProps({
|
|
212
39
|
css: datePickerPopperStyle,
|
|
213
40
|
open: innerOpen.current,
|
|
@@ -217,8 +44,8 @@ export const DateTimePicker = memo(({ inputProps, popperProps, min, max, disable
|
|
|
217
44
|
content: (_jsxs(_Fragment, { children: [showCalendar &&
|
|
218
45
|
_jsx(Calendar, { viewLevel: format.includes('D') ? 'date'
|
|
219
46
|
: format.includes('M') ? 'month'
|
|
220
|
-
: 'year', _defaultNull: !dateValue.current, value:
|
|
221
|
-
_jsx(DateTimePickerContext, { value: contextValue, children: _jsx(Timer, { showHours: format.includes('H'), showMinutes: format.includes('m'), showSeconds: format.includes('s'), value:
|
|
47
|
+
: 'year', _defaultNull: !dateValue.current, value: innerValue, onChange: setDateValue, min: min, max: max, disabledDates: disabledDates }), showTimer &&
|
|
48
|
+
_jsx(DateTimePickerContext, { value: contextValue, children: _jsx(Timer, { showHours: format.includes('H'), showMinutes: format.includes('m'), showSeconds: format.includes('s'), value: innerValue, onChange: setDateValue }) })] }))
|
|
222
49
|
}, popperProps, {
|
|
223
50
|
onOpenChange: setInnerOpen,
|
|
224
51
|
onPointerDown: e => e.preventDefault()
|
|
@@ -226,15 +53,12 @@ export const DateTimePicker = memo(({ inputProps, popperProps, min, max, disable
|
|
|
226
53
|
css: style,
|
|
227
54
|
className: classes.root,
|
|
228
55
|
value: dateValue.current,
|
|
229
|
-
onClear
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
ref: innerInputRef,
|
|
236
|
-
className: classes.input
|
|
237
|
-
}) }), _jsx("div", { className: classes.dateTimeIcon, children: showTimer && !showCalendar
|
|
56
|
+
onClear() {
|
|
57
|
+
setDateValue(null);
|
|
58
|
+
}
|
|
59
|
+
}), "data-focused": innerOpen.current, children: inputBaseProps => _jsxs("div", { className: classes.container, children: [!dateValue.current
|
|
60
|
+
? _jsx("div", { className: classes.placeholder, children: props.placeholder ?? '请选择' })
|
|
61
|
+
: _jsx("div", { className: classes.backfill, children: dateValue.current.format(format) }), _jsx("input", { size: 1, ...mergeComponentProps(inputBaseProps, inputProps), "data-hidden": "true" }), _jsx("div", { className: classes.dateTimeIcon, children: showTimer && !showCalendar
|
|
238
62
|
? _jsx(Icon, { icon: faClock })
|
|
239
63
|
: _jsx(Icon, { icon: faCalendar }) })] }) }) }));
|
|
240
64
|
});
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
export declare const classes: {
|
|
2
|
-
|
|
3
|
-
calendar: string;
|
|
2
|
+
placeholder: string;
|
|
4
3
|
container: string;
|
|
5
|
-
|
|
6
|
-
inputGroup: string;
|
|
7
|
-
inputUnit: string;
|
|
4
|
+
backfill: string;
|
|
8
5
|
dateTimeIcon: string;
|
|
9
|
-
calendarHead: string;
|
|
10
|
-
calendarHeadSide: string;
|
|
11
|
-
calendarHeadControl: string;
|
|
12
|
-
calendarHeadCenter: string;
|
|
13
|
-
calendarHeadButton: string;
|
|
14
|
-
calendarBody: string;
|
|
15
|
-
calendarDays: string;
|
|
16
6
|
} & {
|
|
17
7
|
root: string;
|
|
18
8
|
};
|
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
import { css } from '@emotion/react';
|
|
2
2
|
import { defineInnerClasses, defineCss } from '../../utils';
|
|
3
|
-
import { commonNativeInputStyle } from '../input/input.style';
|
|
4
3
|
import { classes as calendarClasses } from '../calendar/calendar.style';
|
|
5
4
|
import { classes as timerClasses } from './timer.style';
|
|
6
5
|
import { popperStyleCallback } from '../popper/popper.style';
|
|
7
6
|
export const classes = defineInnerClasses('date-time-picker', [
|
|
8
|
-
'input',
|
|
9
7
|
'container',
|
|
10
|
-
'inputGroup',
|
|
11
|
-
'inputUnit',
|
|
12
8
|
'dateTimeIcon',
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'calendarHeadSide',
|
|
16
|
-
'calendarHeadControl',
|
|
17
|
-
'calendarHeadCenter',
|
|
18
|
-
'calendarHeadButton',
|
|
19
|
-
'calendarBody',
|
|
20
|
-
'calendarDays',
|
|
21
|
-
'dateItem'
|
|
9
|
+
'placeholder',
|
|
10
|
+
'backfill'
|
|
22
11
|
]);
|
|
23
|
-
export const style = defineCss(({ text }) => css `
|
|
12
|
+
export const style = defineCss(({ text, spacing }) => css `
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
|
|
24
15
|
.${classes.container} {
|
|
25
16
|
display: flex;
|
|
26
17
|
align-items: center;
|
|
27
18
|
|
|
28
|
-
.${classes.
|
|
29
|
-
|
|
19
|
+
.${classes.placeholder} {
|
|
20
|
+
flex: 1;
|
|
21
|
+
color: ${text.placeholder};
|
|
22
|
+
white-space: nowrap;
|
|
23
|
+
text-overflow: ellipsis;
|
|
24
|
+
overflow: hidden;
|
|
30
25
|
}
|
|
31
|
-
|
|
26
|
+
|
|
27
|
+
.${classes.backfill} {
|
|
28
|
+
flex: 1;
|
|
29
|
+
min-width: 0;
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-wrap: wrap;
|
|
32
|
+
gap: ${spacing[1]}px;
|
|
33
|
+
}
|
|
34
|
+
|
|
32
35
|
.${classes.dateTimeIcon} {
|
|
33
36
|
color: ${text.secondary};
|
|
34
37
|
}
|
|
@@ -19,11 +19,7 @@ export const Descriptions = memo(({ size, labelWidth, colon = ':', labelPlacemen
|
|
|
19
19
|
size, labelWidth, colon, labelPlacement, disableMargin, disablePadding, variant
|
|
20
20
|
]);
|
|
21
21
|
const renderGridItems = () => {
|
|
22
|
-
return items?.map((itemProps, i) => _createElement(ItemComponent
|
|
23
|
-
// 最后一项沾满剩余行空间
|
|
24
|
-
, {
|
|
25
|
-
// 最后一项沾满剩余行空间
|
|
26
|
-
flex: i === items.length - 1 ? 1 : void 0, ...itemProps, key: itemProps.key ?? i })) || props.children;
|
|
22
|
+
return items?.map((itemProps, i) => _createElement(ItemComponent, { ...itemProps, key: itemProps.key ?? i })) || props.children;
|
|
27
23
|
};
|
|
28
24
|
const columnCountNum = useResponsiveValue(columnCount, variant === 'grid');
|
|
29
25
|
const renderTableItems = () => {
|
|
@@ -59,12 +59,12 @@ export function Dialog({ icon, title, footer, prefix, suffix, width = 420, minWi
|
|
|
59
59
|
useEffect(() => {
|
|
60
60
|
if (innerOpen.current) {
|
|
61
61
|
const resizeObserver = new ResizeObserver(onScroll);
|
|
62
|
+
resizeObserver.observe(bodyRef.current);
|
|
62
63
|
resizeObserver.observe(bodyWrapRef.current);
|
|
63
64
|
return () => {
|
|
64
65
|
resizeObserver.disconnect();
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
|
-
return;
|
|
68
68
|
}, [innerOpen.current]);
|
|
69
69
|
/**
|
|
70
70
|
* ---------------------------------------------------------------------
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { useImperativeHandle, useRef } from 'react';
|
|
3
3
|
import { classes, useStyle } from './inputBase.style';
|
|
4
|
-
import { fixInputNumber, mergeComponentProps, useControlled } from '../../utils';
|
|
4
|
+
import { fixInputNumber, isUnset, mergeComponentProps, useControlled } from '../../utils';
|
|
5
5
|
import { useTheme } from '../theme';
|
|
6
6
|
import { Button } from '../button';
|
|
7
7
|
import { LoadingIndicator } from '../loadingIndicator';
|
|
@@ -53,6 +53,15 @@ min, max, step, precision, placeholder, disabled, readOnly, autoFocus, defaultVa
|
|
|
53
53
|
changeHandler(e);
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
+
const shouldRenderClearButton = () => {
|
|
57
|
+
if (!clearable || disabled || readOnly || isUnset(innerValue.current)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(innerValue.current) || typeof innerValue.current === 'string') {
|
|
61
|
+
return !!innerValue.current.length;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
56
65
|
return (_jsxs("div", { ...mergeComponentProps(props, {
|
|
57
66
|
ref: innerRef,
|
|
58
67
|
className: classes.root,
|
|
@@ -83,7 +92,7 @@ min, max, step, precision, placeholder, disabled, readOnly, autoFocus, defaultVa
|
|
|
83
92
|
onBlur: blurHandler,
|
|
84
93
|
onKeyDown: (e) => e.key === 'Enter' && blurHandler(e)
|
|
85
94
|
}) }), loading &&
|
|
86
|
-
_jsx(LoadingIndicator, {}),
|
|
95
|
+
_jsx(LoadingIndicator, {}), shouldRenderClearButton() &&
|
|
87
96
|
_jsx(Button, { className: classes.clear, variant: "plain", color: "text.disabled", onClick: clear, tabIndex: -1, children: _jsx(Icon, { icon: faCircleXmark }) }), !!suffix &&
|
|
88
97
|
_jsx("div", { className: classes.suffix, children: suffix })] }));
|
|
89
98
|
});
|