@canlooks/can-ui 0.0.167 → 0.0.169
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/lineIndicator.d.ts +5 -5
- package/dist/cjs/components/tabs/lineIndicator.js +7 -4
- package/dist/cjs/components/tabs/tab.d.ts +4 -2
- package/dist/cjs/components/tabs/tab.js +21 -12
- package/dist/cjs/components/tabs/tabs.js +11 -9
- package/dist/cjs/components/tabs/tabs.style.d.ts +1 -0
- package/dist/cjs/components/tabs/tabs.style.js +18 -9
- 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/lineIndicator.d.ts +5 -5
- package/dist/esm/components/tabs/lineIndicator.js +7 -4
- package/dist/esm/components/tabs/tab.d.ts +4 -2
- package/dist/esm/components/tabs/tab.js +22 -13
- package/dist/esm/components/tabs/tabs.js +13 -11
- package/dist/esm/components/tabs/tabs.style.d.ts +1 -0
- package/dist/esm/components/tabs/tabs.style.js +18 -9
- 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
|
@@ -3,9 +3,9 @@ import { CurdColumn } from './curd';
|
|
|
3
3
|
import { RowType } from '../dataGrid';
|
|
4
4
|
import { Id } from '../../types';
|
|
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;
|
|
@@ -33,16 +33,16 @@ const CurdColumnConfigContent = (0, react_1.memo)(({ columns, innerVisible, setI
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
const visibleSet = (0, react_1.useMemo)(() => {
|
|
36
|
-
return new Set(innerVisible);
|
|
36
|
+
return innerVisible && new Set(innerVisible);
|
|
37
37
|
}, [innerVisible]);
|
|
38
38
|
const toggleVisible = (key, checked) => {
|
|
39
|
-
!(0, utils_1.isUnset)(key) && setInnerVisible(o => checked
|
|
39
|
+
!(0, utils_1.isUnset)(key) && setInnerVisible((o = []) => checked
|
|
40
40
|
? [...o, key]
|
|
41
41
|
: o.filter(k => k !== key));
|
|
42
42
|
};
|
|
43
43
|
return ((0, jsx_runtime_1.jsx)(bubble_1.Bubble, { css: curdColumnConfig_style_1.style, open: open, onOpenChange: openChangeHandler, placement: "bottomRight", trigger: ['hover', 'click'], content: (0, jsx_runtime_1.jsxs)("div", { className: curdColumnConfig_style_1.classes.content, children: [(0, jsx_runtime_1.jsxs)("div", { className: curdColumnConfig_style_1.classes.title, children: [(0, jsx_runtime_1.jsx)("div", { className: curdColumnConfig_style_1.classes.titleText, children: "\u5217\u8BBE\u7F6E" }), (0, jsx_runtime_1.jsx)("div", { className: curdColumnConfig_style_1.classes.description, children: "\u62D6\u62FD\u8C03\u6574\u987A\u5E8F" })] }), columns?.map((col, i) => {
|
|
44
44
|
const id = col._key;
|
|
45
|
-
const checked = !(0, utils_1.isUnset)(id) && visibleSet.has(id);
|
|
45
|
+
const checked = !(0, utils_1.isUnset)(id) && (!visibleSet || visibleSet.has(id));
|
|
46
46
|
return ((0, jsx_runtime_1.jsx)(sortableItem_1.SortableItem, { id: id ?? i, index: i, component: menuItem_1.MenuItem, className: curdColumnConfig_style_1.classes.item, prefix: (0, jsx_runtime_1.jsx)(checkbox_1.Checkbox, { className: curdColumnConfig_style_1.classes.checkbox, checked: checked, onChange: e => {
|
|
47
47
|
e.stopPropagation();
|
|
48
48
|
toggleVisible(id, e.target.checked);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Id } from '../../types';
|
|
2
|
-
export declare
|
|
3
|
-
value
|
|
4
|
-
position:
|
|
5
|
-
getActiveTab():
|
|
6
|
-
})
|
|
2
|
+
export declare const LineIndicator: import("react").MemoExoticComponent<({ value, position, getActiveTab }: {
|
|
3
|
+
value: Id | undefined;
|
|
4
|
+
position: "top" | "bottom" | "left" | "right";
|
|
5
|
+
getActiveTab(): HTMLElement | undefined;
|
|
6
|
+
}) => import("@emotion/react/jsx-runtime").JSX.Element>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LineIndicator =
|
|
3
|
+
exports.LineIndicator = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const tabs_style_1 = require("./tabs.style");
|
|
7
7
|
const utils_1 = require("../../utils");
|
|
8
8
|
const theme_1 = require("../theme");
|
|
9
9
|
const tabs_1 = require("./tabs");
|
|
10
|
-
|
|
10
|
+
exports.LineIndicator = (0, react_1.memo)(({ value, position, getActiveTab }) => {
|
|
11
11
|
const context = (0, tabs_1.useTabsContext)();
|
|
12
12
|
const [color, setColor] = (0, react_1.useState)(context.color);
|
|
13
13
|
const [boundingRect, setBoundingRect] = (0, react_1.useState)();
|
|
@@ -40,9 +40,12 @@ function LineIndicator({ value, position, getActiveTab, }) {
|
|
|
40
40
|
}
|
|
41
41
|
activeTab.dataset.color && setColor(activeTab.dataset.color);
|
|
42
42
|
}, [value]);
|
|
43
|
+
const onTransitionEnd = () => {
|
|
44
|
+
setAnimating(false);
|
|
45
|
+
};
|
|
43
46
|
const theme = (0, theme_1.useTheme)();
|
|
44
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.indicator, onTransitionEnd:
|
|
47
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.indicator, onTransitionEnd: onTransitionEnd, style: {
|
|
45
48
|
...boundingRect,
|
|
46
49
|
backgroundColor: (0, utils_1.colorTransfer)(color, theme)
|
|
47
50
|
} }));
|
|
48
|
-
}
|
|
51
|
+
});
|
|
@@ -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';
|
|
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>;
|
|
@@ -9,25 +9,34 @@ const tabs_1 = require("./tabs");
|
|
|
9
9
|
const button_1 = require("../button");
|
|
10
10
|
const faXmark_1 = require("@fortawesome/free-solid-svg-icons/faXmark");
|
|
11
11
|
const icon_1 = require("../icon");
|
|
12
|
-
const
|
|
12
|
+
const sortable_1 = require("@dnd-kit/react/sortable");
|
|
13
13
|
const transitionBase_1 = require("../transitionBase");
|
|
14
|
-
exports.Tab = (0, react_1.memo)(({ prefix, suffix, color, orientation, label, value, disabled, closable, onClose, sortable, _active, _index, ...props }) => {
|
|
14
|
+
exports.Tab = (0, react_1.memo)(({ prefix, suffix, color, orientation, label, value, disabled, closable, onClose, sortable, _active, _index, _tabRef, ...props }) => {
|
|
15
15
|
const context = (0, tabs_1.useTabsContext)();
|
|
16
16
|
const colorValue = (0, utils_1.useColor)(color ?? context.color);
|
|
17
17
|
const _closable = closable ?? context.closable;
|
|
18
18
|
const closeHandler = (e) => {
|
|
19
|
+
e.stopPropagation();
|
|
19
20
|
onClose?.(e);
|
|
20
21
|
context.onClose?.(value);
|
|
21
22
|
};
|
|
22
23
|
const _sortable = sortable ?? context.sortable;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
const showBorder = context.variant === 'line' && !context.animating && _active;
|
|
25
|
+
const { ref } = (0, sortable_1.useSortable)({
|
|
26
|
+
id: value,
|
|
27
|
+
index: _index,
|
|
28
|
+
disabled: !_sortable
|
|
29
|
+
});
|
|
30
|
+
return ((0, jsx_runtime_1.jsx)(transitionBase_1.Collapse, { ...(0, utils_1.mergeComponentProps)(props, {
|
|
31
|
+
ref,
|
|
32
|
+
className: tabs_style_1.classes.tabTransition
|
|
33
|
+
}), orientation: "horizontal", className: tabs_style_1.classes.tabTransition, children: (0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.tabWrapper, children: (0, jsx_runtime_1.jsxs)("div", { ref: _tabRef, className: tabs_style_1.classes.tab, style: {
|
|
34
|
+
borderColor: showBorder ? colorValue : void 0,
|
|
35
|
+
color: _active ? colorValue : void 0
|
|
36
|
+
}, onClick: e => {
|
|
37
|
+
!disabled && props.onClick?.(e);
|
|
38
|
+
}, "data-color": colorValue, "data-disabled": disabled, "data-orientation": orientation, "data-active": _active, children: [!!prefix &&
|
|
39
|
+
(0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.tabPrefix, children: prefix }), (0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.label, children: label }), !!suffix &&
|
|
40
|
+
(0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.tabSuffix, children: suffix }), _closable &&
|
|
41
|
+
(0, jsx_runtime_1.jsx)(button_1.Button, { className: tabs_style_1.classes.tabClose, variant: "text", color: "text.secondary", onClick: closeHandler, children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faXmark_1.faXmark }) })] }) }) }));
|
|
33
42
|
});
|
|
@@ -22,26 +22,25 @@ exports.Tabs = (0, react_2.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
22
22
|
size ??= theme.size;
|
|
23
23
|
const [innerValue, _setInnerValue] = (0, utils_1.useControlled)(defaultValue, value, onChange);
|
|
24
24
|
const setInnerValue = (value) => {
|
|
25
|
-
if (!readOnly && !disabled) {
|
|
25
|
+
if (!readOnly && !disabled && value !== innerValue.current) {
|
|
26
26
|
_setInnerValue(value);
|
|
27
|
+
console.log(96, value);
|
|
28
|
+
variant === 'line' && setAnimating(true);
|
|
27
29
|
}
|
|
28
30
|
};
|
|
29
|
-
const [animating, setAnimating] = (0,
|
|
31
|
+
const [animating, setAnimating] = (0, react_2.useState)(false);
|
|
30
32
|
const setValueInEllipsis = (value) => {
|
|
31
33
|
shouldScroll.current = true;
|
|
32
34
|
setInnerValue(value);
|
|
33
35
|
};
|
|
34
36
|
const tabRefs = (0, react_2.useRef)(new Map());
|
|
35
|
-
const getActiveTab = () => {
|
|
36
|
-
return (0, utils_1.isUnset)(innerValue.current) ? void 0 : tabRefs.current.get(innerValue.current);
|
|
37
|
-
};
|
|
38
37
|
const eventName = changeEvent === 'click' ? 'onClick' : 'onPointerDown';
|
|
39
38
|
const renderTabs = () => {
|
|
40
39
|
if (tabs) {
|
|
41
40
|
return tabs.map((p, i) => {
|
|
42
41
|
const value = p[primaryKey];
|
|
43
42
|
const active = !(0, utils_1.isUnset)(value) && value === innerValue.current;
|
|
44
|
-
return ((0, react_1.createElement)(tab_1.Tab, { ...p, key: p.key ?? value ?? i,
|
|
43
|
+
return ((0, react_1.createElement)(tab_1.Tab, { ...p, key: p.key ?? value ?? i, _tabRef: el => {
|
|
45
44
|
el
|
|
46
45
|
? tabRefs.current.set(value, el)
|
|
47
46
|
: tabRefs.current.delete(value);
|
|
@@ -114,6 +113,9 @@ exports.Tabs = (0, react_2.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
114
113
|
resizeObserver.disconnect();
|
|
115
114
|
};
|
|
116
115
|
}, [position]);
|
|
116
|
+
const getActiveTab = (0, react_2.useCallback)(() => {
|
|
117
|
+
return tabRefs.current.get(innerValue.current);
|
|
118
|
+
}, []);
|
|
117
119
|
const shouldScroll = (0, react_2.useRef)(true);
|
|
118
120
|
(0, react_2.useEffect)(() => {
|
|
119
121
|
if (shouldScroll.current) {
|
|
@@ -133,13 +135,13 @@ exports.Tabs = (0, react_2.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
133
135
|
newTabs && props.onSort(e, newTabs);
|
|
134
136
|
}
|
|
135
137
|
};
|
|
136
|
-
return ((0, jsx_runtime_1.jsxs)("div", { ...props, css: (0, tabs_style_1.useStyle)({ color, variant }), className: (0, utils_1.clsx)(tabs_style_1.classes.root, props.className), "data-size": size, "data-position": position, "data-animating": animating
|
|
138
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ...props, css: (0, tabs_style_1.useStyle)({ color, variant }), className: (0, utils_1.clsx)(tabs_style_1.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: [(0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.start, "data-show": shadowStart, children: !!prefix &&
|
|
137
139
|
(0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.prefix, children: prefix }) }), (0, jsx_runtime_1.jsx)("div", { ref: scrollRef, className: tabs_style_1.classes.scroll, onScroll: setShadow, children: (0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.scrollWrap, style: { justifyContent }, children: (0, jsx_runtime_1.jsxs)(TabsContext, { value: (0, react_2.useMemo)(() => ({
|
|
138
140
|
color, variant, closable, onClose, sortable,
|
|
139
|
-
animating
|
|
141
|
+
animating, setAnimating
|
|
140
142
|
}), [
|
|
141
143
|
color, variant, closable, onClose, sortable,
|
|
142
|
-
animating
|
|
144
|
+
animating
|
|
143
145
|
]), children: [(0, jsx_runtime_1.jsx)(react_3.DragDropProvider, { sensors: utils_1.defaultSensors, onDragEnd: dragEndHandler, children: (0, jsx_runtime_1.jsx)(react_transition_group_1.TransitionGroup, { component: null, children: renderTabs() }) }), variant === 'line' &&
|
|
144
146
|
(0, jsx_runtime_1.jsx)(lineIndicator_1.LineIndicator, { value: innerValue.current, position: position, getActiveTab: getActiveTab })] }) }) }), (0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.end, "data-show": shadowEnd, children: !!(suffix || shadowStart || shadowEnd) &&
|
|
145
147
|
(0, jsx_runtime_1.jsxs)("div", { className: tabs_style_1.classes.suffix, children: [(shadowStart || shadowEnd) &&
|
|
@@ -12,6 +12,7 @@ exports.classes = (0, utils_1.defineInnerClasses)('tabs', [
|
|
|
12
12
|
'ellipsis',
|
|
13
13
|
'prefix',
|
|
14
14
|
'suffix',
|
|
15
|
+
'tabTransition',
|
|
15
16
|
'tabWrapper',
|
|
16
17
|
'tab',
|
|
17
18
|
'label',
|
|
@@ -36,6 +37,7 @@ function useStyle({ color, variant }) {
|
|
|
36
37
|
display: flex;
|
|
37
38
|
scrollbar-width: none;
|
|
38
39
|
position: relative;
|
|
40
|
+
overflow: auto;
|
|
39
41
|
|
|
40
42
|
&::-webkit-scrollbar {
|
|
41
43
|
display: none;
|
|
@@ -126,7 +128,11 @@ function useStyle({ color, variant }) {
|
|
|
126
128
|
background-color: ${divider};
|
|
127
129
|
position: absolute;
|
|
128
130
|
}
|
|
129
|
-
|
|
131
|
+
|
|
132
|
+
.${exports.classes.tabTransition} { {
|
|
133
|
+
z-index: 1;
|
|
134
|
+
}}
|
|
135
|
+
|
|
130
136
|
.${exports.classes.tab} {
|
|
131
137
|
display: flex;
|
|
132
138
|
align-items: center;
|
|
@@ -136,9 +142,8 @@ function useStyle({ color, variant }) {
|
|
|
136
142
|
white-space: nowrap;
|
|
137
143
|
text-overflow: ellipsis;
|
|
138
144
|
overflow: hidden;
|
|
139
|
-
z-index: 1;
|
|
140
145
|
-webkit-tap-highlight-color: transparent;
|
|
141
|
-
transition:
|
|
146
|
+
transition: background-color, color .25s ${easing.easeOut};
|
|
142
147
|
|
|
143
148
|
&[data-orientation=vertical] {
|
|
144
149
|
flex-direction: column;
|
|
@@ -229,8 +234,8 @@ function useStyle({ color, variant }) {
|
|
|
229
234
|
variant === 'line'
|
|
230
235
|
? (0, react_1.css) `
|
|
231
236
|
@layer reset {
|
|
232
|
-
.${exports.classes.
|
|
233
|
-
|
|
237
|
+
.${exports.classes.tabWrapper} {
|
|
238
|
+
padding: 0 ${spacing[5]}px;
|
|
234
239
|
}
|
|
235
240
|
|
|
236
241
|
&[data-position=top],
|
|
@@ -313,10 +318,6 @@ function useStyle({ color, variant }) {
|
|
|
313
318
|
// variant === 'card'
|
|
314
319
|
: (0, react_1.css) `
|
|
315
320
|
@layer reset {
|
|
316
|
-
.${exports.classes.scrollWrap} {
|
|
317
|
-
gap: ${spacing[1]}px;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
321
|
.${exports.classes.tab} {
|
|
321
322
|
border: 1px solid ${gray(.1)};
|
|
322
323
|
background-color: ${background.body};
|
|
@@ -328,6 +329,10 @@ function useStyle({ color, variant }) {
|
|
|
328
329
|
|
|
329
330
|
&[data-position=top],
|
|
330
331
|
&[data-position=bottom] {
|
|
332
|
+
.${exports.classes.tabWrapper} {
|
|
333
|
+
padding: 0 2px;
|
|
334
|
+
}
|
|
335
|
+
|
|
331
336
|
.${exports.classes.tab} {
|
|
332
337
|
padding: 10px 15px;
|
|
333
338
|
}
|
|
@@ -367,6 +372,10 @@ function useStyle({ color, variant }) {
|
|
|
367
372
|
|
|
368
373
|
&[data-position=left],
|
|
369
374
|
&[data-position=right] {
|
|
375
|
+
.${exports.classes.tabWrapper} {
|
|
376
|
+
padding: 2px 0;
|
|
377
|
+
}
|
|
378
|
+
|
|
370
379
|
.${exports.classes.tab} {
|
|
371
380
|
padding: 9px 18px;
|
|
372
381
|
}
|
|
@@ -10,55 +10,66 @@ const Collapse = ({ transitionType = 'sweeping', ...props }) => {
|
|
|
10
10
|
return ((0, jsx_runtime_1.jsx)(Component, { ...props, _mode: transitionType === 'sweeping' ? '_sweeping' : 'collapse' }));
|
|
11
11
|
};
|
|
12
12
|
exports.Collapse = Collapse;
|
|
13
|
-
const Sweeping = ({ ref, in: _in = false,
|
|
13
|
+
const Sweeping = ({ ref, in: _in = false, orientation = 'vertical', collapsedSize = 0, appear = true, ...props }) => {
|
|
14
14
|
const innerRef = (0, react_1.useRef)(null);
|
|
15
|
+
const styleProperty = orientation === 'vertical' ? 'height' : 'width';
|
|
15
16
|
const getCollapsedSize = () => {
|
|
16
17
|
return typeof collapsedSize === 'function' ? collapsedSize() : collapsedSize;
|
|
17
18
|
};
|
|
18
|
-
const [size, setSize] = (0, react_1.useState)(() =>
|
|
19
|
-
|
|
20
|
-
return 'auto';
|
|
21
|
-
}
|
|
22
|
-
return getCollapsedSize();
|
|
23
|
-
});
|
|
24
|
-
const [isEntered, setIsEntered] = (0, react_1.useState)(_in && !appear);
|
|
25
|
-
const styleProperty = orientation === 'vertical' ? 'height' : 'width';
|
|
26
|
-
const expand = () => {
|
|
19
|
+
const [size, setSize] = (0, react_1.useState)(() => !_in ? getCollapsedSize() : 'auto');
|
|
20
|
+
const getFullSize = () => {
|
|
27
21
|
const el = innerRef.current;
|
|
22
|
+
let size;
|
|
28
23
|
if (el) {
|
|
29
24
|
el.style.transition = 'none';
|
|
25
|
+
const originalSize = el.style[styleProperty];
|
|
30
26
|
el.style[styleProperty] = 'auto';
|
|
31
|
-
|
|
32
|
-
el.style[styleProperty] =
|
|
27
|
+
size = el[orientation === 'vertical' ? 'offsetHeight' : 'offsetWidth'];
|
|
28
|
+
el.style[styleProperty] = originalSize;
|
|
33
29
|
el.style.transition = '';
|
|
30
|
+
}
|
|
31
|
+
return size;
|
|
32
|
+
};
|
|
33
|
+
const expand = (fromSize) => {
|
|
34
|
+
const fullSize = getFullSize();
|
|
35
|
+
if (typeof fullSize !== 'undefined') {
|
|
36
|
+
if (typeof fromSize !== 'undefined') {
|
|
37
|
+
const el = innerRef.current;
|
|
38
|
+
el.style[styleProperty] = fromSize + 'px';
|
|
39
|
+
}
|
|
34
40
|
requestAnimationFrame(() => {
|
|
35
|
-
setSize(
|
|
41
|
+
setSize(fullSize);
|
|
36
42
|
});
|
|
37
43
|
}
|
|
38
44
|
};
|
|
45
|
+
const getCurrentSize = () => {
|
|
46
|
+
const el = innerRef.current;
|
|
47
|
+
if (el) {
|
|
48
|
+
return el[orientation === 'vertical' ? 'offsetHeight' : 'offsetWidth'];
|
|
49
|
+
}
|
|
50
|
+
};
|
|
39
51
|
const collapse = () => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
const currentSize = getCurrentSize();
|
|
53
|
+
if (typeof currentSize !== 'undefined') {
|
|
54
|
+
const el = innerRef.current;
|
|
55
|
+
el.style[styleProperty] = currentSize + 'px';
|
|
56
|
+
requestAnimationFrame(() => {
|
|
57
|
+
setSize(getCollapsedSize());
|
|
58
|
+
});
|
|
59
|
+
}
|
|
44
60
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// 首次渲染
|
|
49
|
-
mounted.current = true;
|
|
50
|
-
if (!appear) {
|
|
51
|
-
// 若appear为false,则跳过首次动画
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
61
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
62
|
+
if (_in && appear) {
|
|
63
|
+
expand(getCollapsedSize());
|
|
54
64
|
}
|
|
65
|
+
}, []);
|
|
66
|
+
(0, utils_1.useUpdateEffect)(() => {
|
|
55
67
|
_in
|
|
56
68
|
? expand()
|
|
57
69
|
: collapse();
|
|
58
70
|
}, [_in]);
|
|
59
|
-
return ((0, jsx_runtime_1.jsx)(transitionBase_1.TransitionBase, { ...props,
|
|
60
|
-
[styleProperty]:
|
|
61
|
-
...!isEntered && { overflow: 'hidden' },
|
|
71
|
+
return ((0, jsx_runtime_1.jsx)(transitionBase_1.TransitionBase, { ...props, ref: (0, utils_1.cloneRef)(ref, innerRef), in: _in, orientation: orientation, appear: appear, style: {
|
|
72
|
+
[styleProperty]: size,
|
|
62
73
|
...props.style
|
|
63
|
-
}
|
|
74
|
+
} }));
|
|
64
75
|
};
|
|
@@ -14,7 +14,7 @@ exports.TransitionBase = (({ ref, component: Component = 'div', orientation = 'v
|
|
|
14
14
|
cssArr.push(transitionBase_style_1.fadeStyle);
|
|
15
15
|
switch (_mode) {
|
|
16
16
|
case '_sweeping':
|
|
17
|
-
cssArr.push(transitionBase_style_1.
|
|
17
|
+
cssArr.push((0, transitionBase_style_1.useSweepingStyle)({ orientation }));
|
|
18
18
|
break;
|
|
19
19
|
case 'collapse':
|
|
20
20
|
case 'grow':
|
|
@@ -25,5 +25,10 @@ exports.TransitionBase = (({ ref, component: Component = 'div', orientation = 'v
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
const innerRef = (0, react_1.useRef)(null);
|
|
28
|
-
|
|
28
|
+
const initialized = (0, react_1.useRef)(false);
|
|
29
|
+
(0, react_1.useEffect)(() => {
|
|
30
|
+
initialized.current = true;
|
|
31
|
+
}, [props.in]);
|
|
32
|
+
const unInitClass = !initialized.current && !props.in && 'exit-done';
|
|
33
|
+
return ((0, jsx_runtime_1.jsx)(react_transition_group_1.CSSTransition, { ...props, css: cssArr, nodeRef: innerRef, className: (0, utils_1.clsx)(transitionBase_style_1.classes.root, props.className, unInitClass), timeout: timeout, appear: appear, children: (0, jsx_runtime_1.jsx)(Component, { ref: (0, utils_1.cloneRef)(ref, innerRef), children: props.children }) }));
|
|
29
34
|
});
|
|
@@ -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;
|