@canlooks/can-ui 0.0.149 → 0.0.152
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/app/app.style.js +1 -0
- package/dist/cjs/components/sortableItem/sortableItem.d.ts +2 -2
- package/dist/cjs/components/sortableItem/sortableItem.js +1 -2
- package/dist/cjs/components/sortableItem/sortableItem.style.js +6 -4
- package/dist/cjs/components/tabs/lineIndicator.d.ts +1 -2
- package/dist/cjs/components/tabs/lineIndicator.js +3 -2
- package/dist/cjs/components/tabs/tab.d.ts +7 -3
- package/dist/cjs/components/tabs/tab.js +17 -6
- package/dist/cjs/components/tabs/tabs.d.ts +23 -9
- package/dist/cjs/components/tabs/tabs.js +28 -10
- package/dist/cjs/components/tabs/tabs.style.d.ts +2 -1
- package/dist/cjs/components/tabs/tabs.style.js +283 -271
- package/dist/cjs/utils/dnd.d.ts +1 -1
- package/dist/cjs/utils/utils.d.ts +2 -2
- package/dist/cjs/utils/utils.js +18 -3
- package/dist/esm/components/app/app.style.js +1 -0
- package/dist/esm/components/sortableItem/sortableItem.d.ts +2 -2
- package/dist/esm/components/sortableItem/sortableItem.js +2 -3
- package/dist/esm/components/sortableItem/sortableItem.style.js +6 -4
- package/dist/esm/components/tabs/lineIndicator.d.ts +1 -2
- package/dist/esm/components/tabs/lineIndicator.js +3 -2
- package/dist/esm/components/tabs/tab.d.ts +7 -3
- package/dist/esm/components/tabs/tab.js +17 -6
- package/dist/esm/components/tabs/tabs.d.ts +23 -9
- package/dist/esm/components/tabs/tabs.js +29 -11
- package/dist/esm/components/tabs/tabs.style.d.ts +2 -1
- package/dist/esm/components/tabs/tabs.style.js +283 -271
- package/dist/esm/utils/dnd.d.ts +1 -1
- package/dist/esm/utils/utils.d.ts +2 -2
- package/dist/esm/utils/utils.js +18 -3
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ const utils_1 = require("../../utils");
|
|
|
6
6
|
const theme_1 = require("../theme");
|
|
7
7
|
exports.classes = (0, utils_1.defineInnerClasses)('app');
|
|
8
8
|
const appStyleCallback = (theme) => (0, react_1.css) `
|
|
9
|
+
@layer reset, override;
|
|
9
10
|
@layer reset {
|
|
10
11
|
line-height: ${20 / 14};
|
|
11
12
|
font-size: ${theme.fontSize}px;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ElementType } from 'react';
|
|
2
2
|
import { Arguments } from '@dnd-kit/sortable/dist/hooks/useSortable';
|
|
3
|
-
import { OverridableComponent, OverridableProps } from '../../types';
|
|
3
|
+
import { Id, OverridableComponent, OverridableProps } from '../../types';
|
|
4
4
|
export type SortableItemOwnProps = {
|
|
5
|
-
id:
|
|
5
|
+
id: Id;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
sortableArguments?: Arguments;
|
|
8
8
|
};
|
|
@@ -7,7 +7,6 @@ const sortable_1 = require("@dnd-kit/sortable");
|
|
|
7
7
|
const utilities_1 = require("@dnd-kit/utilities");
|
|
8
8
|
const utils_1 = require("../../utils");
|
|
9
9
|
const react_2 = require("@emotion/react");
|
|
10
|
-
const treeDnd_style_1 = require("../tree/treeDnd.style");
|
|
11
10
|
const sortableItem_style_1 = require("./sortableItem.style");
|
|
12
11
|
exports.SortableItem = (({ component: Component = 'div', id, disabled, sortableArguments, ...props }) => {
|
|
13
12
|
const { attributes, isDragging, listeners, setNodeRef, transform, transition } = (0, sortable_1.useSortable)({
|
|
@@ -37,5 +36,5 @@ exports.SortableItem = (({ component: Component = 'div', id, disabled, sortableA
|
|
|
37
36
|
transform: utilities_1.CSS.Transform.toString(transform),
|
|
38
37
|
transition,
|
|
39
38
|
...props.style
|
|
40
|
-
}, onTouchStart: disabled ? void 0 : onTouchStart, "data-dragging": isDragging }), isDragging && (0, jsx_runtime_1.jsx)(react_2.Global, { styles:
|
|
39
|
+
}, onTouchStart: disabled ? void 0 : onTouchStart, "data-dragging": isDragging, "data-disabled": disabled }), isDragging && (0, jsx_runtime_1.jsx)(react_2.Global, { styles: sortableItem_style_1.globalGrabbingStyle })] }));
|
|
41
40
|
});
|
|
@@ -5,10 +5,12 @@ const react_1 = require("@emotion/react");
|
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
6
|
exports.classes = (0, utils_1.defineInnerClasses)('sortable-item');
|
|
7
7
|
exports.style = (0, react_1.css) `
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
&:not([data-dsabled=true]) {
|
|
9
|
+
cursor: grab;
|
|
10
|
+
|
|
11
|
+
&:active {
|
|
12
|
+
cursor: grabbing;
|
|
13
|
+
}
|
|
12
14
|
}
|
|
13
15
|
`;
|
|
14
16
|
exports.globalGrabbingStyle = (0, react_1.css) `
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Id } from '../../types';
|
|
2
|
-
export declare function LineIndicator({ value, position, getActiveTab,
|
|
2
|
+
export declare function LineIndicator({ value, position, getActiveTab, }: {
|
|
3
3
|
value?: Id;
|
|
4
4
|
position: 'top' | 'bottom' | 'left' | 'right';
|
|
5
5
|
getActiveTab(): HTMLDivElement | undefined;
|
|
6
|
-
onTransitionEnd(): void;
|
|
7
6
|
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -7,10 +7,11 @@ 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
|
-
function LineIndicator({ value, position, getActiveTab,
|
|
10
|
+
function LineIndicator({ 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)();
|
|
14
|
+
const { setAnimating } = (0, tabs_1.useTabsContext)();
|
|
14
15
|
(0, react_1.useEffect)(() => {
|
|
15
16
|
const activeTab = getActiveTab();
|
|
16
17
|
if (!activeTab) {
|
|
@@ -40,7 +41,7 @@ function LineIndicator({ value, position, getActiveTab, onTransitionEnd }) {
|
|
|
40
41
|
activeTab.dataset.color && setColor(activeTab.dataset.color);
|
|
41
42
|
}, [value]);
|
|
42
43
|
const theme = (0, theme_1.useTheme)();
|
|
43
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.indicator, onTransitionEnd:
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.indicator, onTransitionEnd: () => setAnimating(false), style: {
|
|
44
45
|
...boundingRect,
|
|
45
46
|
backgroundColor: (0, utils_1.colorTransfer)(color, theme)
|
|
46
47
|
} }));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
2
|
import { ColorPropsValue, DivProps, Id } from '../../types';
|
|
3
3
|
export interface TabProps extends Omit<DivProps, 'prefix'> {
|
|
4
4
|
prefix?: ReactNode;
|
|
@@ -7,9 +7,13 @@ export interface TabProps extends Omit<DivProps, 'prefix'> {
|
|
|
7
7
|
color?: ColorPropsValue;
|
|
8
8
|
orientation?: 'horizontal' | 'vertical';
|
|
9
9
|
label?: ReactNode;
|
|
10
|
-
value
|
|
10
|
+
value: Id;
|
|
11
11
|
disabled?: boolean;
|
|
12
|
+
closable?: boolean;
|
|
13
|
+
onClose?: React.MouseEventHandler<HTMLButtonElement>;
|
|
14
|
+
/** 是否允许拖拽排序,默认为`false` */
|
|
15
|
+
sortable?: boolean;
|
|
12
16
|
/** @private 内部使用,用于表示改选项卡是否为激活状态 */
|
|
13
17
|
_active?: boolean;
|
|
14
18
|
}
|
|
15
|
-
export declare const Tab:
|
|
19
|
+
export declare const Tab: React.MemoExoticComponent<({ prefix, suffix, color, orientation, label, value, disabled, closable, onClose, sortable, _active, ...props }: TabProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
|
|
@@ -6,16 +6,27 @@ const react_1 = require("react");
|
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const tabs_style_1 = require("./tabs.style");
|
|
8
8
|
const tabs_1 = require("./tabs");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const button_1 = require("../button");
|
|
10
|
+
const faXmark_1 = require("@fortawesome/free-solid-svg-icons/faXmark");
|
|
11
|
+
const icon_1 = require("../icon");
|
|
12
|
+
const sortableItem_1 = require("../sortableItem");
|
|
13
|
+
exports.Tab = (0, react_1.memo)(({ prefix, suffix, color, orientation, label, value, disabled, closable, onClose, sortable, _active, ...props }) => {
|
|
14
|
+
const context = (0, tabs_1.useTabsContext)();
|
|
15
|
+
const colorValue = (0, utils_1.useColor)(color ?? context.color);
|
|
16
|
+
const _closable = closable ?? context.closable;
|
|
17
|
+
const closeHandler = (e) => {
|
|
18
|
+
onClose?.(e);
|
|
19
|
+
context.onClose?.(value);
|
|
20
|
+
};
|
|
21
|
+
const _sortable = sortable ?? context.sortable;
|
|
22
|
+
return ((0, jsx_runtime_1.jsxs)(sortableItem_1.SortableItem, { ...props, id: value, disabled: !_sortable, className: (0, utils_1.clsx)(tabs_style_1.classes.tab, props.className), style: {
|
|
23
|
+
borderColor: context.variant === 'line' && !context.animating && _active ? colorValue : void 0,
|
|
14
24
|
color: _active ? colorValue : void 0,
|
|
15
25
|
...props.style
|
|
16
26
|
}, "data-color": colorValue, "data-disabled": disabled, "data-orientation": orientation, "data-active": _active, onClick: e => {
|
|
17
27
|
!disabled && props.onClick?.(e);
|
|
18
28
|
}, children: [!!prefix &&
|
|
19
29
|
(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 &&
|
|
20
|
-
(0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.tabSuffix, children: suffix })
|
|
30
|
+
(0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.tabSuffix, children: suffix }), _closable &&
|
|
31
|
+
(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 }) })] }));
|
|
21
32
|
});
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { CSSProperties, ReactElement, ReactNode } from 'react';
|
|
1
|
+
import { CSSProperties, ReactElement, ReactNode, SetStateAction, Dispatch } from 'react';
|
|
2
2
|
import { ColorPropsValue, DivProps, Id, Obj, Size } from '../../types';
|
|
3
3
|
import { Tab, TabProps } from './tab';
|
|
4
|
+
import { DragEndEvent } from '@dnd-kit/core';
|
|
4
5
|
export type TabType = TabProps & Obj;
|
|
5
|
-
|
|
6
|
+
type TabsSharedProps = {
|
|
7
|
+
variant?: 'line' | 'card';
|
|
8
|
+
color?: ColorPropsValue;
|
|
9
|
+
/** 是否渲染关闭按钮,默认为`false` */
|
|
10
|
+
closable?: boolean;
|
|
11
|
+
onClose?(key: Id): void;
|
|
12
|
+
/** 是否允许拖拽排序,默认为`false` */
|
|
13
|
+
sortable?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export interface TabsProps<T extends TabType = TabType> extends TabsSharedProps, Omit<DivProps, 'prefix' | 'defaultValue' | 'onChange'> {
|
|
6
16
|
tabs?: T[];
|
|
7
17
|
labelKey?: keyof T;
|
|
8
18
|
primaryKey?: keyof T;
|
|
9
|
-
variant?: 'line' | 'card';
|
|
10
|
-
color?: ColorPropsValue;
|
|
11
19
|
size?: Size;
|
|
12
20
|
/** 选项卡的位置,默认为`top` */
|
|
13
21
|
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
@@ -20,13 +28,19 @@ export interface TabsProps<T extends TabType = TabType> extends Omit<DivProps, '
|
|
|
20
28
|
onChange?(value: Id): void;
|
|
21
29
|
readOnly?: boolean;
|
|
22
30
|
disabled?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @param e
|
|
33
|
+
* @param tabs 仅{@link tabs}模式支持,使用children时,该参数为`undefined`
|
|
34
|
+
*/
|
|
35
|
+
onSort?(e: DragEndEvent, tabs?: T[]): void;
|
|
23
36
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
interface ITabsContext extends TabsSharedProps {
|
|
38
|
+
animating: boolean;
|
|
39
|
+
setAnimating: Dispatch<SetStateAction<boolean>>;
|
|
40
|
+
}
|
|
41
|
+
export declare function useTabsContext(): ITabsContext;
|
|
29
42
|
export declare const Tabs: {
|
|
30
43
|
<T extends TabType>(props: TabsProps<T>): ReactElement;
|
|
31
44
|
Tab: typeof Tab;
|
|
32
45
|
};
|
|
46
|
+
export {};
|
|
@@ -11,21 +11,22 @@ const theme_1 = require("../theme");
|
|
|
11
11
|
const tab_1 = require("./tab");
|
|
12
12
|
const tabsEllipsis_1 = require("./tabsEllipsis");
|
|
13
13
|
const lineIndicator_1 = require("./lineIndicator");
|
|
14
|
+
const core_1 = require("@dnd-kit/core");
|
|
15
|
+
const sortable_1 = require("@dnd-kit/sortable");
|
|
14
16
|
const TabsContext = (0, react_2.createContext)({});
|
|
15
17
|
function useTabsContext() {
|
|
16
18
|
return (0, react_2.useContext)(TabsContext);
|
|
17
19
|
}
|
|
18
|
-
exports.Tabs = (0, react_2.memo)(({ tabs, labelKey = 'label', primaryKey = 'value',
|
|
20
|
+
exports.Tabs = (0, react_2.memo)(({ tabs, labelKey = 'label', primaryKey = 'value', size, position = 'top', justifyContent = 'flex-start', fullWidth, prefix, suffix, defaultValue, value, onChange, readOnly, disabled, variant = 'line', color = 'primary', closable, onClose, sortable, ...props }) => {
|
|
19
21
|
const theme = (0, theme_1.useTheme)();
|
|
20
22
|
size ??= theme.size;
|
|
21
|
-
const [animating, setAnimating] = (0, react_2.useState)(false); // TODO 应当考虑value受控的情况,参考anchorList组件
|
|
22
23
|
const [innerValue, _setInnerValue] = (0, utils_1.useControlled)(defaultValue, value, onChange);
|
|
23
24
|
const setInnerValue = (value) => {
|
|
24
25
|
if (!readOnly && !disabled) {
|
|
25
|
-
setAnimating(true);
|
|
26
26
|
_setInnerValue(value);
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
+
const [animating, setAnimating] = (0, utils_1.useDerivedState)(prev => typeof prev !== 'undefined', [innerValue.current]);
|
|
29
30
|
const setValueInEllipsis = (value) => {
|
|
30
31
|
shouldScroll.current = true;
|
|
31
32
|
setInnerValue(value);
|
|
@@ -116,13 +117,30 @@ exports.Tabs = (0, react_2.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
116
117
|
shouldScroll.current = false;
|
|
117
118
|
}
|
|
118
119
|
}, [shouldScroll.current]);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
/**
|
|
121
|
+
* ----------------------------------------------------------------
|
|
122
|
+
* 拖拽
|
|
123
|
+
*/
|
|
124
|
+
const tabKeys = tabs
|
|
125
|
+
? tabs.map(tab => tab[primaryKey])
|
|
126
|
+
: react_2.Children.map(props.children, c => (0, react_2.isValidElement)(c) ? c.props.value : c);
|
|
127
|
+
const dragEndHandler = (e) => {
|
|
128
|
+
if (props.onSort) {
|
|
129
|
+
const newTabs = tabs
|
|
130
|
+
? (0, utils_1.onDndDragEnd)(e, tabs, primaryKey)
|
|
131
|
+
: void 0;
|
|
132
|
+
props.onSort(e, newTabs);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
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.current, "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 &&
|
|
136
|
+
(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.jsx)(core_1.DndContext, { sensors: (0, utils_1.useDndSensors)(), onDragEnd: dragEndHandler, children: (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, { items: tabKeys, disabled: !sortable, children: (0, jsx_runtime_1.jsxs)(TabsContext, { value: (0, react_2.useMemo)(() => ({
|
|
137
|
+
color, variant, closable, onClose, sortable,
|
|
138
|
+
animating: animating.current, setAnimating
|
|
139
|
+
}), [
|
|
140
|
+
color, variant, closable, onClose, sortable,
|
|
141
|
+
animating.current
|
|
142
|
+
]), children: [renderTabs(), variant === 'line' &&
|
|
143
|
+
(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) &&
|
|
126
144
|
(0, jsx_runtime_1.jsxs)("div", { className: tabs_style_1.classes.suffix, children: [(shadowStart || shadowEnd) &&
|
|
127
145
|
(0, jsx_runtime_1.jsx)(tabsEllipsis_1.TabsEllipsis, { tabs: tabs, labelKey: labelKey, primaryKey: primaryKey, value: innerValue.current, onToggleSelected: setValueInEllipsis, children: props.children }), suffix] }) })] }));
|
|
128
146
|
});
|
|
@@ -12,8 +12,9 @@ export declare const classes: {
|
|
|
12
12
|
scrollWrap: string;
|
|
13
13
|
tabPrefix: string;
|
|
14
14
|
tabSuffix: string;
|
|
15
|
+
tabClose: string;
|
|
15
16
|
} & {
|
|
16
17
|
root: string;
|
|
17
18
|
};
|
|
18
19
|
export declare const indicatorWidth = 2;
|
|
19
|
-
export declare function useStyle({ color, variant }: Required<Pick<TabsProps, 'color' | 'variant'>>): import("@emotion/react").SerializedStyles;
|
|
20
|
+
export declare function useStyle({ color, variant }: Required<Pick<TabsProps, 'color' | 'variant'>>): import("@emotion/react").SerializedStyles[];
|