@canlooks/can-ui 0.0.168 → 0.0.170
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/curdColumnConfig.d.ts +4 -4
- package/dist/cjs/components/curd/curdColumnConfig.js +3 -3
- package/dist/cjs/components/tabs/tab.d.ts +4 -2
- package/dist/cjs/components/tabs/tab.js +15 -15
- package/dist/cjs/components/tabs/tabs.js +7 -6
- package/dist/cjs/components/tabs/tabs.style.d.ts +1 -0
- package/dist/cjs/components/tabs/tabs.style.js +16 -7
- package/dist/cjs/components/transitionBase/collapse.d.ts +1 -1
- package/dist/cjs/components/transitionBase/collapse.js +41 -30
- package/dist/cjs/components/transitionBase/transitionBase.js +7 -2
- package/dist/cjs/components/transitionBase/transitionBase.style.d.ts +3 -3
- package/dist/cjs/components/transitionBase/transitionBase.style.js +82 -99
- package/dist/cjs/utils/curd.d.ts +3 -3
- package/dist/cjs/utils/curd.js +3 -21
- package/dist/esm/components/curd/curdColumnConfig.d.ts +4 -4
- package/dist/esm/components/curd/curdColumnConfig.js +3 -3
- package/dist/esm/components/tabs/tab.d.ts +4 -2
- package/dist/esm/components/tabs/tab.js +15 -15
- package/dist/esm/components/tabs/tabs.js +8 -7
- package/dist/esm/components/tabs/tabs.style.d.ts +1 -0
- package/dist/esm/components/tabs/tabs.style.js +16 -7
- package/dist/esm/components/transitionBase/collapse.d.ts +1 -1
- package/dist/esm/components/transitionBase/collapse.js +43 -32
- package/dist/esm/components/transitionBase/transitionBase.js +9 -4
- package/dist/esm/components/transitionBase/transitionBase.style.d.ts +3 -3
- package/dist/esm/components/transitionBase/transitionBase.style.js +80 -98
- package/dist/esm/utils/curd.d.ts +3 -3
- package/dist/esm/utils/curd.js +3 -21
- package/package.json +1 -1
package/dist/cjs/utils/curd.js
CHANGED
|
@@ -69,24 +69,6 @@ function useCurdColumns({ columns, columnConfigurable }) {
|
|
|
69
69
|
columnConfigurable = {};
|
|
70
70
|
}
|
|
71
71
|
let { defaultVisible, visible, onVisibleChange, defaultOrder, order, onOrderChange } = columnConfigurable;
|
|
72
|
-
if (!defaultVisible || !defaultOrder) {
|
|
73
|
-
let hasControlColumn = false;
|
|
74
|
-
const defaultKeys = columns?.flatMap((col) => {
|
|
75
|
-
if (col.hideInTable) {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
if (col._key) {
|
|
79
|
-
if (col._key === exports.CONTROL_COLUMN_KEY) {
|
|
80
|
-
hasControlColumn = true;
|
|
81
|
-
}
|
|
82
|
-
return col._key;
|
|
83
|
-
}
|
|
84
|
-
return [];
|
|
85
|
-
}) || [];
|
|
86
|
-
!hasControlColumn && defaultKeys.push(exports.CONTROL_COLUMN_KEY);
|
|
87
|
-
defaultVisible ||= defaultKeys;
|
|
88
|
-
defaultOrder ||= defaultKeys;
|
|
89
|
-
}
|
|
90
72
|
const [innerOrder, setInnerOrder] = (0, hooks_1.useControlled)(defaultOrder, order, onOrderChange);
|
|
91
73
|
const [innerVisible, setInnerVisible] = (0, hooks_1.useControlled)(defaultVisible, visible, onVisibleChange);
|
|
92
74
|
const symbolBoundToNext = (0, react_1.useRef)(new WeakMap());
|
|
@@ -112,7 +94,7 @@ function useCurdColumns({ columns, columnConfigurable }) {
|
|
|
112
94
|
}, [columns]);
|
|
113
95
|
// 只排序不筛选,用于设置项
|
|
114
96
|
const orderedColumns = (0, react_1.useMemo)(() => {
|
|
115
|
-
if (!innerOrder.current
|
|
97
|
+
if (!innerOrder.current?.length) {
|
|
116
98
|
return pureColumns;
|
|
117
99
|
}
|
|
118
100
|
const set = new Set(pureColumns);
|
|
@@ -129,12 +111,12 @@ function useCurdColumns({ columns, columnConfigurable }) {
|
|
|
129
111
|
];
|
|
130
112
|
}, [innerOrder.current, pureColumns]);
|
|
131
113
|
const visibleSet = (0, react_1.useMemo)(() => {
|
|
132
|
-
return new Set(innerVisible.current);
|
|
114
|
+
return innerVisible.current && new Set(innerVisible.current);
|
|
133
115
|
}, [innerVisible.current]);
|
|
134
116
|
// 筛选表格上可见的列,并将symbol回填
|
|
135
117
|
const actualColumns = (0, react_1.useMemo)(() => {
|
|
136
118
|
return orderedColumns.flatMap(col => {
|
|
137
|
-
if (!(0, utils_1.isUnset)(col._key) && visibleSet.has(col._key)) {
|
|
119
|
+
if (!(0, utils_1.isUnset)(col._key) && (!visibleSet || visibleSet.has(col._key))) {
|
|
138
120
|
const symbolArr = symbolBoundToNext.current.get(col) || [];
|
|
139
121
|
// 移除DataGrid不需要的属性
|
|
140
122
|
const { filterInline, filter, form, ...c } = col;
|
|
@@ -3,9 +3,9 @@ import { CurdColumn } from './curd.js';
|
|
|
3
3
|
import { RowType } from '../dataGrid/index.js';
|
|
4
4
|
import { Id } from '../../types.js';
|
|
5
5
|
export type CurdColumnConfigProps<R extends RowType> = {
|
|
6
|
-
columns
|
|
7
|
-
innerVisible: Id[];
|
|
8
|
-
setInnerVisible: Dispatch<SetStateAction<Id[]>>;
|
|
9
|
-
setInnerOrder: Dispatch<SetStateAction<Id[]>>;
|
|
6
|
+
columns: CurdColumn<R>[] | undefined;
|
|
7
|
+
innerVisible: Id[] | undefined;
|
|
8
|
+
setInnerVisible: Dispatch<SetStateAction<Id[] | undefined>>;
|
|
9
|
+
setInnerOrder: Dispatch<SetStateAction<Id[] | undefined>>;
|
|
10
10
|
};
|
|
11
11
|
export declare const CurdColumnConfig: <R extends RowType>(props: CurdColumnConfigProps<R>) => ReactElement;
|
|
@@ -30,16 +30,16 @@ const CurdColumnConfigContent = memo(({ columns, innerVisible, setInnerVisible }
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
const visibleSet = useMemo(() => {
|
|
33
|
-
return new Set(innerVisible);
|
|
33
|
+
return innerVisible && new Set(innerVisible);
|
|
34
34
|
}, [innerVisible]);
|
|
35
35
|
const toggleVisible = (key, checked) => {
|
|
36
|
-
!isUnset(key) && setInnerVisible(o => checked
|
|
36
|
+
!isUnset(key) && setInnerVisible((o = []) => checked
|
|
37
37
|
? [...o, key]
|
|
38
38
|
: o.filter(k => k !== key));
|
|
39
39
|
};
|
|
40
40
|
return (_jsx(Bubble, { css: style, open: open, onOpenChange: openChangeHandler, placement: "bottomRight", trigger: ['hover', 'click'], content: _jsxs("div", { className: classes.content, children: [_jsxs("div", { className: classes.title, children: [_jsx("div", { className: classes.titleText, children: "\u5217\u8BBE\u7F6E" }), _jsx("div", { className: classes.description, children: "\u62D6\u62FD\u8C03\u6574\u987A\u5E8F" })] }), columns?.map((col, i) => {
|
|
41
41
|
const id = col._key;
|
|
42
|
-
const checked = !isUnset(id) && visibleSet.has(id);
|
|
42
|
+
const checked = !isUnset(id) && (!visibleSet || visibleSet.has(id));
|
|
43
43
|
return (_jsx(SortableItem, { id: id ?? i, index: i, component: MenuItem, className: classes.item, prefix: _jsx(Checkbox, { className: classes.checkbox, checked: checked, onChange: e => {
|
|
44
44
|
e.stopPropagation();
|
|
45
45
|
toggleVisible(id, e.target.checked);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
1
|
+
import React, { ReactNode, Ref } from 'react';
|
|
2
2
|
import { ColorPropsValue, DivProps, Id } from '../../types.js';
|
|
3
3
|
export interface TabProps extends Omit<DivProps, 'prefix'> {
|
|
4
4
|
prefix?: ReactNode;
|
|
@@ -17,5 +17,7 @@ export interface TabProps extends Omit<DivProps, 'prefix'> {
|
|
|
17
17
|
_active?: boolean;
|
|
18
18
|
/** @private */
|
|
19
19
|
_index?: number;
|
|
20
|
+
/** @private */
|
|
21
|
+
_tabRef?: Ref<HTMLDivElement>;
|
|
20
22
|
}
|
|
21
|
-
export declare const Tab: React.MemoExoticComponent<({ prefix, suffix, color, orientation, label, value, disabled, closable, onClose, sortable, _active, _index, ...props }: TabProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
|
|
23
|
+
export declare const Tab: React.MemoExoticComponent<({ prefix, suffix, color, orientation, label, value, disabled, closable, onClose, sortable, _active, _index, _tabRef, ...props }: TabProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
|
|
@@ -6,34 +6,34 @@ import { useTabsContext } from './tabs.js';
|
|
|
6
6
|
import { Button } from '../button/index.js';
|
|
7
7
|
import { faXmark } from '@fortawesome/free-solid-svg-icons/faXmark';
|
|
8
8
|
import { Icon } from '../icon/index.js';
|
|
9
|
-
import { Collapse } from '../transitionBase/index.js';
|
|
10
9
|
import { useSortable } from '@dnd-kit/react/sortable';
|
|
11
|
-
|
|
10
|
+
import { Collapse } from '../transitionBase/index.js';
|
|
11
|
+
export const Tab = memo(({ prefix, suffix, color, orientation, label, value, disabled, closable, onClose, sortable, _active, _index, _tabRef, ...props }) => {
|
|
12
12
|
const context = useTabsContext();
|
|
13
13
|
const colorValue = useColor(color ?? context.color);
|
|
14
14
|
const _closable = closable ?? context.closable;
|
|
15
15
|
const closeHandler = (e) => {
|
|
16
|
+
e.stopPropagation();
|
|
16
17
|
onClose?.(e);
|
|
17
18
|
context.onClose?.(value);
|
|
18
19
|
};
|
|
19
20
|
const _sortable = sortable ?? context.sortable;
|
|
21
|
+
const showBorder = context.variant === 'line' && !context.animating && _active;
|
|
20
22
|
const { ref } = useSortable({
|
|
21
23
|
id: value,
|
|
22
24
|
index: _index,
|
|
23
25
|
disabled: !_sortable
|
|
24
26
|
});
|
|
25
|
-
return (
|
|
27
|
+
return (_jsx(Collapse, { ...mergeComponentProps(props, {
|
|
26
28
|
ref,
|
|
27
|
-
className: classes.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
_jsx("div", { className: classes.tabSuffix, children: suffix }), _closable &&
|
|
38
|
-
_jsx(Button, { className: classes.tabClose, variant: "text", color: "text.secondary", onClick: closeHandler, children: _jsx(Icon, { icon: faXmark }) })] }));
|
|
29
|
+
className: classes.tabTransition
|
|
30
|
+
}), orientation: "horizontal", className: classes.tabTransition, children: _jsx("div", { className: classes.tabWrapper, children: _jsxs("div", { ref: _tabRef, className: classes.tab, style: {
|
|
31
|
+
borderColor: showBorder ? colorValue : void 0,
|
|
32
|
+
color: _active ? colorValue : void 0
|
|
33
|
+
}, onClick: e => {
|
|
34
|
+
!disabled && props.onClick?.(e);
|
|
35
|
+
}, "data-color": colorValue, "data-disabled": disabled, "data-orientation": orientation, "data-active": _active, children: [!!prefix &&
|
|
36
|
+
_jsx("div", { className: classes.tabPrefix, children: prefix }), _jsx("div", { className: classes.label, children: label }), !!suffix &&
|
|
37
|
+
_jsx("div", { className: classes.tabSuffix, children: suffix }), _closable &&
|
|
38
|
+
_jsx(Button, { className: classes.tabClose, variant: "text", color: "text.secondary", onClick: closeHandler, children: _jsx(Icon, { icon: faXmark }) })] }) }) }));
|
|
39
39
|
});
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
|
2
2
|
import { createElement as _createElement } from "@emotion/react";
|
|
3
3
|
import { Children, cloneElement, createContext, isValidElement, memo, useContext, useEffect, useMemo, useRef, useState, useCallback } from 'react';
|
|
4
4
|
import { classes, useStyle } from './tabs.style.js';
|
|
5
|
-
import { clsx, cloneRef, isUnset, useControlled,
|
|
5
|
+
import { clsx, cloneRef, isUnset, useControlled, defaultSensors, onDndDragEnd } from '../../utils/index.js';
|
|
6
6
|
import { useTheme } from '../theme/index.js';
|
|
7
7
|
import { Tab } from './tab.js';
|
|
8
8
|
import { TabsEllipsis } from './tabsEllipsis.js';
|
|
@@ -18,12 +18,13 @@ export const Tabs = memo(({ tabs, labelKey = 'label', primaryKey = 'value', size
|
|
|
18
18
|
size ??= theme.size;
|
|
19
19
|
const [innerValue, _setInnerValue] = useControlled(defaultValue, value, onChange);
|
|
20
20
|
const setInnerValue = (value) => {
|
|
21
|
-
if (!readOnly && !disabled) {
|
|
21
|
+
if (!readOnly && !disabled && value !== innerValue.current) {
|
|
22
22
|
_setInnerValue(value);
|
|
23
|
+
console.log(96, value);
|
|
23
24
|
variant === 'line' && setAnimating(true);
|
|
24
25
|
}
|
|
25
26
|
};
|
|
26
|
-
const [animating, setAnimating] =
|
|
27
|
+
const [animating, setAnimating] = useState(false);
|
|
27
28
|
const setValueInEllipsis = (value) => {
|
|
28
29
|
shouldScroll.current = true;
|
|
29
30
|
setInnerValue(value);
|
|
@@ -35,7 +36,7 @@ export const Tabs = memo(({ tabs, labelKey = 'label', primaryKey = 'value', size
|
|
|
35
36
|
return tabs.map((p, i) => {
|
|
36
37
|
const value = p[primaryKey];
|
|
37
38
|
const active = !isUnset(value) && value === innerValue.current;
|
|
38
|
-
return (_createElement(Tab, { ...p, key: p.key ?? value ?? i,
|
|
39
|
+
return (_createElement(Tab, { ...p, key: p.key ?? value ?? i, _tabRef: el => {
|
|
39
40
|
el
|
|
40
41
|
? tabRefs.current.set(value, el)
|
|
41
42
|
: tabRefs.current.delete(value);
|
|
@@ -130,13 +131,13 @@ export const Tabs = memo(({ tabs, labelKey = 'label', primaryKey = 'value', size
|
|
|
130
131
|
newTabs && props.onSort(e, newTabs);
|
|
131
132
|
}
|
|
132
133
|
};
|
|
133
|
-
return (_jsxs("div", { ...props, css: useStyle({ color, variant }), className: clsx(classes.root, props.className), "data-size": size, "data-position": position, "data-animating": animating
|
|
134
|
+
return (_jsxs("div", { ...props, css: useStyle({ color, variant }), className: clsx(classes.root, props.className), "data-size": size, "data-position": position, "data-animating": animating, "data-full-width": fullWidth, "data-read-only": readOnly, "data-disabled": disabled, children: [_jsx("div", { className: classes.start, "data-show": shadowStart, children: !!prefix &&
|
|
134
135
|
_jsx("div", { className: classes.prefix, children: prefix }) }), _jsx("div", { ref: scrollRef, className: classes.scroll, onScroll: setShadow, children: _jsx("div", { className: classes.scrollWrap, style: { justifyContent }, children: _jsxs(TabsContext, { value: useMemo(() => ({
|
|
135
136
|
color, variant, closable, onClose, sortable,
|
|
136
|
-
animating
|
|
137
|
+
animating, setAnimating
|
|
137
138
|
}), [
|
|
138
139
|
color, variant, closable, onClose, sortable,
|
|
139
|
-
animating
|
|
140
|
+
animating
|
|
140
141
|
]), children: [_jsx(DragDropProvider, { sensors: defaultSensors, onDragEnd: dragEndHandler, children: _jsx(TransitionGroup, { component: null, children: renderTabs() }) }), variant === 'line' &&
|
|
141
142
|
_jsx(LineIndicator, { value: innerValue.current, position: position, getActiveTab: getActiveTab })] }) }) }), _jsx("div", { className: classes.end, "data-show": shadowEnd, children: !!(suffix || shadowStart || shadowEnd) &&
|
|
142
143
|
_jsxs("div", { className: classes.suffix, children: [(shadowStart || shadowEnd) &&
|
|
@@ -8,6 +8,7 @@ export const classes = defineInnerClasses('tabs', [
|
|
|
8
8
|
'ellipsis',
|
|
9
9
|
'prefix',
|
|
10
10
|
'suffix',
|
|
11
|
+
'tabTransition',
|
|
11
12
|
'tabWrapper',
|
|
12
13
|
'tab',
|
|
13
14
|
'label',
|
|
@@ -32,6 +33,7 @@ export function useStyle({ color, variant }) {
|
|
|
32
33
|
display: flex;
|
|
33
34
|
scrollbar-width: none;
|
|
34
35
|
position: relative;
|
|
36
|
+
overflow: auto;
|
|
35
37
|
|
|
36
38
|
&::-webkit-scrollbar {
|
|
37
39
|
display: none;
|
|
@@ -123,6 +125,10 @@ export function useStyle({ color, variant }) {
|
|
|
123
125
|
position: absolute;
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
.${classes.tabTransition} { {
|
|
129
|
+
z-index: 1;
|
|
130
|
+
}}
|
|
131
|
+
|
|
126
132
|
.${classes.tab} {
|
|
127
133
|
display: flex;
|
|
128
134
|
align-items: center;
|
|
@@ -132,7 +138,6 @@ export function useStyle({ color, variant }) {
|
|
|
132
138
|
white-space: nowrap;
|
|
133
139
|
text-overflow: ellipsis;
|
|
134
140
|
overflow: hidden;
|
|
135
|
-
z-index: 1;
|
|
136
141
|
-webkit-tap-highlight-color: transparent;
|
|
137
142
|
transition: background-color, color .25s ${easing.easeOut};
|
|
138
143
|
|
|
@@ -225,8 +230,8 @@ export function useStyle({ color, variant }) {
|
|
|
225
230
|
variant === 'line'
|
|
226
231
|
? css `
|
|
227
232
|
@layer reset {
|
|
228
|
-
.${classes.
|
|
229
|
-
|
|
233
|
+
.${classes.tabWrapper} {
|
|
234
|
+
padding: 0 ${spacing[5]}px;
|
|
230
235
|
}
|
|
231
236
|
|
|
232
237
|
&[data-position=top],
|
|
@@ -309,10 +314,6 @@ export function useStyle({ color, variant }) {
|
|
|
309
314
|
// variant === 'card'
|
|
310
315
|
: css `
|
|
311
316
|
@layer reset {
|
|
312
|
-
.${classes.scrollWrap} {
|
|
313
|
-
gap: ${spacing[1]}px;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
317
|
.${classes.tab} {
|
|
317
318
|
border: 1px solid ${gray(.1)};
|
|
318
319
|
background-color: ${background.body};
|
|
@@ -324,6 +325,10 @@ export function useStyle({ color, variant }) {
|
|
|
324
325
|
|
|
325
326
|
&[data-position=top],
|
|
326
327
|
&[data-position=bottom] {
|
|
328
|
+
.${classes.tabWrapper} {
|
|
329
|
+
padding: 0 2px;
|
|
330
|
+
}
|
|
331
|
+
|
|
327
332
|
.${classes.tab} {
|
|
328
333
|
padding: 10px 15px;
|
|
329
334
|
}
|
|
@@ -363,6 +368,10 @@ export function useStyle({ color, variant }) {
|
|
|
363
368
|
|
|
364
369
|
&[data-position=left],
|
|
365
370
|
&[data-position=right] {
|
|
371
|
+
.${classes.tabWrapper} {
|
|
372
|
+
padding: 2px 0;
|
|
373
|
+
}
|
|
374
|
+
|
|
366
375
|
.${classes.tab} {
|
|
367
376
|
padding: 9px 18px;
|
|
368
377
|
}
|
|
@@ -1,60 +1,71 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import { useRef, useState } from 'react';
|
|
2
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
3
3
|
import { TransitionBase } from './transitionBase.js';
|
|
4
|
-
import { cloneRef,
|
|
4
|
+
import { cloneRef, useUpdateEffect } from '../../utils/index.js';
|
|
5
5
|
export const Collapse = ({ transitionType = 'sweeping', ...props }) => {
|
|
6
6
|
const Component = transitionType === 'sweeping' ? Sweeping : TransitionBase;
|
|
7
7
|
return (_jsx(Component, { ...props, _mode: transitionType === 'sweeping' ? '_sweeping' : 'collapse' }));
|
|
8
8
|
};
|
|
9
|
-
const Sweeping = ({ ref, in: _in = false,
|
|
9
|
+
const Sweeping = ({ ref, in: _in = false, orientation = 'vertical', collapsedSize = 0, appear = true, ...props }) => {
|
|
10
10
|
const innerRef = useRef(null);
|
|
11
|
+
const styleProperty = orientation === 'vertical' ? 'height' : 'width';
|
|
11
12
|
const getCollapsedSize = () => {
|
|
12
13
|
return typeof collapsedSize === 'function' ? collapsedSize() : collapsedSize;
|
|
13
14
|
};
|
|
14
|
-
const [size, setSize] = useState(() =>
|
|
15
|
-
|
|
16
|
-
return 'auto';
|
|
17
|
-
}
|
|
18
|
-
return getCollapsedSize();
|
|
19
|
-
});
|
|
20
|
-
const [isEntered, setIsEntered] = useState(_in && !appear);
|
|
21
|
-
const styleProperty = orientation === 'vertical' ? 'height' : 'width';
|
|
22
|
-
const expand = () => {
|
|
15
|
+
const [size, setSize] = useState(() => !_in ? getCollapsedSize() : 'auto');
|
|
16
|
+
const getFullSize = () => {
|
|
23
17
|
const el = innerRef.current;
|
|
18
|
+
let size;
|
|
24
19
|
if (el) {
|
|
25
20
|
el.style.transition = 'none';
|
|
21
|
+
const originalSize = el.style[styleProperty];
|
|
26
22
|
el.style[styleProperty] = 'auto';
|
|
27
|
-
|
|
28
|
-
el.style[styleProperty] =
|
|
23
|
+
size = el[orientation === 'vertical' ? 'offsetHeight' : 'offsetWidth'];
|
|
24
|
+
el.style[styleProperty] = originalSize;
|
|
29
25
|
el.style.transition = '';
|
|
26
|
+
}
|
|
27
|
+
return size;
|
|
28
|
+
};
|
|
29
|
+
const expand = (fromSize) => {
|
|
30
|
+
const fullSize = getFullSize();
|
|
31
|
+
if (typeof fullSize !== 'undefined') {
|
|
32
|
+
if (typeof fromSize !== 'undefined') {
|
|
33
|
+
const el = innerRef.current;
|
|
34
|
+
el.style[styleProperty] = fromSize + 'px';
|
|
35
|
+
}
|
|
30
36
|
requestAnimationFrame(() => {
|
|
31
|
-
setSize(
|
|
37
|
+
setSize(fullSize);
|
|
32
38
|
});
|
|
33
39
|
}
|
|
34
40
|
};
|
|
41
|
+
const getCurrentSize = () => {
|
|
42
|
+
const el = innerRef.current;
|
|
43
|
+
if (el) {
|
|
44
|
+
return el[orientation === 'vertical' ? 'offsetHeight' : 'offsetWidth'];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
35
47
|
const collapse = () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
const currentSize = getCurrentSize();
|
|
49
|
+
if (typeof currentSize !== 'undefined') {
|
|
50
|
+
const el = innerRef.current;
|
|
51
|
+
el.style[styleProperty] = currentSize + 'px';
|
|
52
|
+
requestAnimationFrame(() => {
|
|
53
|
+
setSize(getCollapsedSize());
|
|
54
|
+
});
|
|
55
|
+
}
|
|
40
56
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// 首次渲染
|
|
45
|
-
mounted.current = true;
|
|
46
|
-
if (!appear) {
|
|
47
|
-
// 若appear为false,则跳过首次动画
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
57
|
+
useLayoutEffect(() => {
|
|
58
|
+
if (_in && appear) {
|
|
59
|
+
expand(getCollapsedSize());
|
|
50
60
|
}
|
|
61
|
+
}, []);
|
|
62
|
+
useUpdateEffect(() => {
|
|
51
63
|
_in
|
|
52
64
|
? expand()
|
|
53
65
|
: collapse();
|
|
54
66
|
}, [_in]);
|
|
55
|
-
return (_jsx(TransitionBase, { ...props,
|
|
56
|
-
[styleProperty]:
|
|
57
|
-
...!isEntered && { overflow: 'hidden' },
|
|
67
|
+
return (_jsx(TransitionBase, { ...props, ref: cloneRef(ref, innerRef), in: _in, orientation: orientation, appear: appear, style: {
|
|
68
|
+
[styleProperty]: size,
|
|
58
69
|
...props.style
|
|
59
|
-
}
|
|
70
|
+
} }));
|
|
60
71
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { useRef } from 'react';
|
|
3
3
|
import { CSSTransition } from 'react-transition-group';
|
|
4
|
-
import { classes, fadeStyle,
|
|
5
|
-
import { clsx, cloneRef } from '../../utils/index.js';
|
|
4
|
+
import { classes, fadeStyle, useGrowAndCollapseStyle, useSlideStyle, useSweepingStyle, useTransitionBaseStyle } from './transitionBase.style.js';
|
|
5
|
+
import { clsx, cloneRef, useUpdateEffect } from '../../utils/index.js';
|
|
6
6
|
export const TransitionBase = (({ ref, component: Component = 'div', orientation = 'vertical', direction = 'down', offset = '100%', timeout = 300, appear = true, _mode, ...props }) => {
|
|
7
7
|
const cssArr = [
|
|
8
8
|
useTransitionBaseStyle({ timeout })
|
|
@@ -11,7 +11,7 @@ export const TransitionBase = (({ ref, component: Component = 'div', orientation
|
|
|
11
11
|
cssArr.push(fadeStyle);
|
|
12
12
|
switch (_mode) {
|
|
13
13
|
case '_sweeping':
|
|
14
|
-
cssArr.push(
|
|
14
|
+
cssArr.push(useSweepingStyle({ orientation }));
|
|
15
15
|
break;
|
|
16
16
|
case 'collapse':
|
|
17
17
|
case 'grow':
|
|
@@ -22,5 +22,10 @@ export const TransitionBase = (({ ref, component: Component = 'div', orientation
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
const innerRef = useRef(null);
|
|
25
|
-
|
|
25
|
+
const firstOpenChanged = useRef(false);
|
|
26
|
+
useUpdateEffect(() => {
|
|
27
|
+
firstOpenChanged.current = true;
|
|
28
|
+
}, [props.in]);
|
|
29
|
+
const unInitClass = !firstOpenChanged.current && !props.in && 'exit-done';
|
|
30
|
+
return (_jsx(CSSTransition, { ...props, css: cssArr, nodeRef: innerRef, className: clsx(classes.root, props.className, unInitClass), timeout: timeout, appear: appear, children: _jsx(Component, { ref: cloneRef(ref, innerRef), children: props.children }) }));
|
|
26
31
|
});
|
|
@@ -4,6 +4,6 @@ export declare const classes: {
|
|
|
4
4
|
};
|
|
5
5
|
export declare function useTransitionBaseStyle({ timeout }: Required<Pick<TransitionBaseProps<any>, 'timeout'>>): import("@emotion/utils").SerializedStyles;
|
|
6
6
|
export declare const fadeStyle: () => import("@emotion/utils").SerializedStyles;
|
|
7
|
-
export declare
|
|
8
|
-
export declare function useGrowAndCollapseStyle({ orientation, _mode }: Required<Pick<TransitionBaseProps
|
|
9
|
-
export declare function useSlideStyle({ direction, offset }: Required<Pick<TransitionBaseProps
|
|
7
|
+
export declare function useSweepingStyle({ orientation }: Required<Pick<TransitionBaseProps, 'orientation'>>): import("@emotion/utils").SerializedStyles;
|
|
8
|
+
export declare function useGrowAndCollapseStyle({ orientation, _mode }: Required<Pick<TransitionBaseProps, 'orientation' | '_mode'>>): import("@emotion/utils").SerializedStyles;
|
|
9
|
+
export declare function useSlideStyle({ direction, offset }: Required<Pick<TransitionBaseProps, 'direction' | 'offset'>>): import("@emotion/utils").SerializedStyles;
|