@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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.fadeStyle = exports.classes = void 0;
|
|
4
4
|
exports.useTransitionBaseStyle = useTransitionBaseStyle;
|
|
5
|
+
exports.useSweepingStyle = useSweepingStyle;
|
|
5
6
|
exports.useGrowAndCollapseStyle = useGrowAndCollapseStyle;
|
|
6
7
|
exports.useSlideStyle = useSlideStyle;
|
|
7
8
|
const react_1 = require("@emotion/react");
|
|
@@ -12,6 +13,7 @@ function useTransitionBaseStyle({ timeout }) {
|
|
|
12
13
|
return (0, utils_1.useCss)(() => (0, react_1.css) `
|
|
13
14
|
@layer reset {
|
|
14
15
|
${timeoutIsNumber ? `transition-duration: ${timeout}ms;` : ''}
|
|
16
|
+
|
|
15
17
|
&.appear-active {
|
|
16
18
|
${!timeoutIsNumber ? `transition-duration: ${timeout.appear}ms;` : ''}
|
|
17
19
|
}
|
|
@@ -28,126 +30,107 @@ function useTransitionBaseStyle({ timeout }) {
|
|
|
28
30
|
}
|
|
29
31
|
exports.fadeStyle = (0, utils_1.defineCss)(({ easing }) => (0, react_1.css) `
|
|
30
32
|
@layer reset {
|
|
31
|
-
transition-property: opacity;
|
|
32
|
-
transition-timing-function: ${easing.easeOut};
|
|
33
|
-
|
|
34
|
-
&,
|
|
35
33
|
&.appear,
|
|
36
|
-
&.
|
|
34
|
+
&.exit,
|
|
35
|
+
&.exit-done {
|
|
37
36
|
opacity: 0;
|
|
38
37
|
}
|
|
39
|
-
|
|
38
|
+
|
|
40
39
|
&.appear-active,
|
|
41
|
-
&.enter
|
|
42
|
-
&.enter-done
|
|
43
|
-
&.exit {
|
|
40
|
+
&.enter,
|
|
41
|
+
&.enter-done {
|
|
44
42
|
opacity: 1;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
&.exit-active,
|
|
48
|
-
&.exit-done {
|
|
49
|
-
opacity: 0;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
`);
|
|
53
|
-
exports.sweepingStyle = (0, utils_1.defineCss)(({ easing }) => (0, react_1.css) `
|
|
54
|
-
@layer reset {
|
|
55
|
-
transition-property: opacity, width, height;
|
|
56
|
-
|
|
57
45
|
&.appear-active,
|
|
58
46
|
&.enter-active,
|
|
59
|
-
&.
|
|
60
|
-
transition-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
&.exit-active,
|
|
64
|
-
&.exit-done {
|
|
47
|
+
&.exit-active {
|
|
48
|
+
transition-property: opacity;
|
|
65
49
|
transition-timing-function: ${easing.easeOut};
|
|
66
50
|
}
|
|
67
51
|
}
|
|
68
52
|
`);
|
|
53
|
+
function useSweepingStyle({ orientation }) {
|
|
54
|
+
return (0, utils_1.useCss)(() => (0, react_1.css) `
|
|
55
|
+
@layer reset {
|
|
56
|
+
&.appear,
|
|
57
|
+
&.appear-active,
|
|
58
|
+
&.enter-active,
|
|
59
|
+
&.exit,
|
|
60
|
+
&.exit-active,
|
|
61
|
+
&.exit-done {
|
|
62
|
+
overflow: hidden;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&.appear-active,
|
|
66
|
+
&.enter-active,
|
|
67
|
+
&.exit-active {
|
|
68
|
+
transition-property: opacity, width, height;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
`, [orientation]);
|
|
72
|
+
}
|
|
69
73
|
function useGrowAndCollapseStyle({ orientation, _mode }) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
transition-property: opacity, transform;
|
|
79
|
-
${_mode === 'collapse' ? `transform-origin: ${orientation === 'vertical' ? 'top' : 'left'};` : ''}
|
|
80
|
-
&,
|
|
81
|
-
&.appear,
|
|
82
|
-
&.enter {
|
|
83
|
-
transform: ${transformMethod}(0);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
&.appear-active,
|
|
87
|
-
&.enter-active,
|
|
88
|
-
&.enter-done,
|
|
89
|
-
&.exit {
|
|
90
|
-
transform: scale(1);
|
|
91
|
-
}
|
|
74
|
+
let transformMethod = _mode === 'grow'
|
|
75
|
+
? 'scale'
|
|
76
|
+
: orientation === 'vertical'
|
|
77
|
+
? 'scaleY'
|
|
78
|
+
: 'scaleX';
|
|
79
|
+
return (0, utils_1.useCss)(() => (0, react_1.css) `
|
|
80
|
+
@layer reset {
|
|
81
|
+
${_mode === 'collapse' ? `transform-origin: ${orientation === 'vertical' ? 'top' : 'left'};` : ''}
|
|
92
82
|
|
|
93
|
-
|
|
94
|
-
&.exit-done {
|
|
95
|
-
transform: ${transformMethod}(0);
|
|
96
|
-
}
|
|
83
|
+
transition-property: opacity, transform;
|
|
97
84
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
85
|
+
&.appear,
|
|
86
|
+
&.exit,
|
|
87
|
+
&.exit-done {
|
|
88
|
+
transform: ${transformMethod}(0);
|
|
89
|
+
}
|
|
102
90
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
91
|
+
&.appear-active,
|
|
92
|
+
&.enter,
|
|
93
|
+
&.enter-done {
|
|
94
|
+
transform: scale(1);
|
|
106
95
|
}
|
|
107
|
-
|
|
108
|
-
|
|
96
|
+
|
|
97
|
+
&.appear-active,
|
|
98
|
+
&.enter-active,
|
|
99
|
+
&.exit-active {
|
|
100
|
+
transition-property: opacity, transform;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
`, [orientation, _mode]);
|
|
109
104
|
}
|
|
110
105
|
function useSlideStyle({ direction, offset }) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
transition-property: opacity, transform;
|
|
120
|
-
|
|
121
|
-
&,
|
|
122
|
-
&.appear,
|
|
123
|
-
&.enter {
|
|
124
|
-
pointer-events: none;
|
|
125
|
-
transform: ${transformMethod}(${offsetValue});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
&.appear-active,
|
|
129
|
-
&.enter-active,
|
|
130
|
-
&.enter-done,
|
|
131
|
-
&.exit {
|
|
132
|
-
pointer-events: inherit;
|
|
133
|
-
transform: translate(0);
|
|
134
|
-
}
|
|
106
|
+
const transformMethod = direction === 'up' || direction === 'down' ? 'translateY' : 'translateX';
|
|
107
|
+
let offsetValue = typeof offset === 'number' ? `${offset}px` : offset;
|
|
108
|
+
if (direction === 'down' || direction === 'right') {
|
|
109
|
+
offsetValue = '-' + offsetValue;
|
|
110
|
+
}
|
|
111
|
+
return (0, utils_1.useCss)(() => (0, react_1.css) `
|
|
112
|
+
@layer reset {
|
|
113
|
+
transition-property: opacity, transform;
|
|
135
114
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
115
|
+
&.appear,
|
|
116
|
+
&.exit,
|
|
117
|
+
&.exit-done {
|
|
118
|
+
pointer-events: none;
|
|
119
|
+
transform: ${transformMethod}(${offsetValue});
|
|
120
|
+
}
|
|
141
121
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
122
|
+
&.appear-active,
|
|
123
|
+
&.enter,
|
|
124
|
+
&.enter-done {
|
|
125
|
+
pointer-events: inherit;
|
|
126
|
+
transform: translate(0);
|
|
127
|
+
}
|
|
146
128
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
129
|
+
&.appear-active,
|
|
130
|
+
&.enter-active,
|
|
131
|
+
&.exit-active {
|
|
132
|
+
transition-property: opacity, transform;
|
|
150
133
|
}
|
|
151
|
-
|
|
152
|
-
|
|
134
|
+
}
|
|
135
|
+
`, [direction, offset]);
|
|
153
136
|
}
|
package/dist/cjs/utils/curd.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare const CONTROL_COLUMN_KEY = "$control";
|
|
|
21
21
|
export declare function useCurdColumns<R extends RowType, V extends Id = Id>({ columns, columnConfigurable }: Pick<CurdProps<R, FormValue, V>, 'columns' | 'columnConfigurable'>): {
|
|
22
22
|
orderedColumns: any[];
|
|
23
23
|
actualColumns: (symbol | ColumnType<R>)[];
|
|
24
|
-
innerVisible: import("react").RefObject<Id[]>;
|
|
25
|
-
setInnerVisible: import("react").Dispatch<import("react").SetStateAction<Id[]>>;
|
|
26
|
-
setInnerOrder: import("react").Dispatch<import("react").SetStateAction<Id[]>>;
|
|
24
|
+
innerVisible: import("react").RefObject<Id[] | undefined>;
|
|
25
|
+
setInnerVisible: import("react").Dispatch<import("react").SetStateAction<Id[] | undefined>>;
|
|
26
|
+
setInnerOrder: import("react").Dispatch<import("react").SetStateAction<Id[] | undefined>>;
|
|
27
27
|
};
|
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,6 +1,6 @@
|
|
|
1
1
|
import { Id } from '../../types.js';
|
|
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,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
2
|
+
import { memo, useEffect, useState } from 'react';
|
|
3
3
|
import { classes, indicatorWidth } from './tabs.style.js';
|
|
4
4
|
import { colorTransfer } from '../../utils/index.js';
|
|
5
5
|
import { useTheme } from '../theme/index.js';
|
|
6
6
|
import { useTabsContext } from './tabs.js';
|
|
7
|
-
export
|
|
7
|
+
export const LineIndicator = memo(({ value, position, getActiveTab }) => {
|
|
8
8
|
const context = useTabsContext();
|
|
9
9
|
const [color, setColor] = useState(context.color);
|
|
10
10
|
const [boundingRect, setBoundingRect] = useState();
|
|
@@ -37,9 +37,12 @@ export function LineIndicator({ value, position, getActiveTab, }) {
|
|
|
37
37
|
}
|
|
38
38
|
activeTab.dataset.color && setColor(activeTab.dataset.color);
|
|
39
39
|
}, [value]);
|
|
40
|
+
const onTransitionEnd = () => {
|
|
41
|
+
setAnimating(false);
|
|
42
|
+
};
|
|
40
43
|
const theme = useTheme();
|
|
41
|
-
return (_jsx("div", { className: classes.indicator, onTransitionEnd:
|
|
44
|
+
return (_jsx("div", { className: classes.indicator, onTransitionEnd: onTransitionEnd, style: {
|
|
42
45
|
...boundingRect,
|
|
43
46
|
backgroundColor: colorTransfer(color, theme)
|
|
44
47
|
} }));
|
|
45
|
-
}
|
|
48
|
+
});
|
|
@@ -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>;
|
|
@@ -1,30 +1,39 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { memo } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { mergeComponentProps, useColor } from '../../utils/index.js';
|
|
4
4
|
import { classes } from './tabs.style.js';
|
|
5
5
|
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 {
|
|
9
|
+
import { useSortable } from '@dnd-kit/react/sortable';
|
|
10
10
|
import { Collapse } from '../transitionBase/index.js';
|
|
11
|
-
export const Tab = memo(({ prefix, suffix, color, orientation, label, value, disabled, closable, onClose, sortable, _active, _index, ...props }) => {
|
|
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;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
const showBorder = context.variant === 'line' && !context.animating && _active;
|
|
22
|
+
const { ref } = useSortable({
|
|
23
|
+
id: value,
|
|
24
|
+
index: _index,
|
|
25
|
+
disabled: !_sortable
|
|
26
|
+
});
|
|
27
|
+
return (_jsx(Collapse, { ...mergeComponentProps(props, {
|
|
28
|
+
ref,
|
|
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 }) })] }) }) }));
|
|
30
39
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { createElement as _createElement } from "@emotion/react";
|
|
3
|
-
import { Children, cloneElement, createContext, isValidElement, memo, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
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,26 +18,25 @@ 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);
|
|
24
|
+
variant === 'line' && setAnimating(true);
|
|
23
25
|
}
|
|
24
26
|
};
|
|
25
|
-
const [animating, setAnimating] =
|
|
27
|
+
const [animating, setAnimating] = useState(false);
|
|
26
28
|
const setValueInEllipsis = (value) => {
|
|
27
29
|
shouldScroll.current = true;
|
|
28
30
|
setInnerValue(value);
|
|
29
31
|
};
|
|
30
32
|
const tabRefs = useRef(new Map());
|
|
31
|
-
const getActiveTab = () => {
|
|
32
|
-
return isUnset(innerValue.current) ? void 0 : tabRefs.current.get(innerValue.current);
|
|
33
|
-
};
|
|
34
33
|
const eventName = changeEvent === 'click' ? 'onClick' : 'onPointerDown';
|
|
35
34
|
const renderTabs = () => {
|
|
36
35
|
if (tabs) {
|
|
37
36
|
return tabs.map((p, i) => {
|
|
38
37
|
const value = p[primaryKey];
|
|
39
38
|
const active = !isUnset(value) && value === innerValue.current;
|
|
40
|
-
return (_createElement(Tab, { ...p, key: p.key ?? value ?? i,
|
|
39
|
+
return (_createElement(Tab, { ...p, key: p.key ?? value ?? i, _tabRef: el => {
|
|
41
40
|
el
|
|
42
41
|
? tabRefs.current.set(value, el)
|
|
43
42
|
: tabRefs.current.delete(value);
|
|
@@ -110,6 +109,9 @@ export const Tabs = memo(({ tabs, labelKey = 'label', primaryKey = 'value', size
|
|
|
110
109
|
resizeObserver.disconnect();
|
|
111
110
|
};
|
|
112
111
|
}, [position]);
|
|
112
|
+
const getActiveTab = useCallback(() => {
|
|
113
|
+
return tabRefs.current.get(innerValue.current);
|
|
114
|
+
}, []);
|
|
113
115
|
const shouldScroll = useRef(true);
|
|
114
116
|
useEffect(() => {
|
|
115
117
|
if (shouldScroll.current) {
|
|
@@ -129,13 +131,13 @@ export const Tabs = memo(({ tabs, labelKey = 'label', primaryKey = 'value', size
|
|
|
129
131
|
newTabs && props.onSort(e, newTabs);
|
|
130
132
|
}
|
|
131
133
|
};
|
|
132
|
-
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 &&
|
|
133
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(() => ({
|
|
134
136
|
color, variant, closable, onClose, sortable,
|
|
135
|
-
animating
|
|
137
|
+
animating, setAnimating
|
|
136
138
|
}), [
|
|
137
139
|
color, variant, closable, onClose, sortable,
|
|
138
|
-
animating
|
|
140
|
+
animating
|
|
139
141
|
]), children: [_jsx(DragDropProvider, { sensors: defaultSensors, onDragEnd: dragEndHandler, children: _jsx(TransitionGroup, { component: null, children: renderTabs() }) }), variant === 'line' &&
|
|
140
142
|
_jsx(LineIndicator, { value: innerValue.current, position: position, getActiveTab: getActiveTab })] }) }) }), _jsx("div", { className: classes.end, "data-show": shadowEnd, children: !!(suffix || shadowStart || shadowEnd) &&
|
|
141
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;
|
|
@@ -122,7 +124,11 @@ export function useStyle({ color, variant }) {
|
|
|
122
124
|
background-color: ${divider};
|
|
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,9 +138,8 @@ 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
|
-
transition:
|
|
142
|
+
transition: background-color, color .25s ${easing.easeOut};
|
|
138
143
|
|
|
139
144
|
&[data-orientation=vertical] {
|
|
140
145
|
flex-direction: column;
|
|
@@ -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
|
}
|