@canlooks/can-ui 0.0.166 → 0.0.168
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/badge/badge.d.ts +1 -0
- 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.js +18 -9
- package/dist/cjs/components/tabs/tabs.js +4 -3
- package/dist/cjs/components/tabs/tabs.style.js +2 -2
- package/dist/cjs/components/transitionBase/transitionBase.style.js +1 -0
- package/dist/esm/components/badge/badge.d.ts +1 -0
- 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.js +19 -10
- package/dist/esm/components/tabs/tabs.js +5 -4
- package/dist/esm/components/tabs/tabs.style.js +2 -2
- package/dist/esm/components/transitionBase/transitionBase.style.js +1 -0
- package/package.json +1 -1
|
@@ -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
|
+
});
|
|
@@ -9,8 +9,8 @@ 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 sortableItem_1 = require("../sortableItem");
|
|
13
12
|
const transitionBase_1 = require("../transitionBase");
|
|
13
|
+
const sortable_1 = require("@dnd-kit/react/sortable");
|
|
14
14
|
exports.Tab = (0, react_1.memo)(({ prefix, suffix, color, orientation, label, value, disabled, closable, onClose, sortable, _active, _index, ...props }) => {
|
|
15
15
|
const context = (0, tabs_1.useTabsContext)();
|
|
16
16
|
const colorValue = (0, utils_1.useColor)(color ?? context.color);
|
|
@@ -20,14 +20,23 @@ exports.Tab = (0, react_1.memo)(({ prefix, suffix, color, orientation, label, va
|
|
|
20
20
|
context.onClose?.(value);
|
|
21
21
|
};
|
|
22
22
|
const _sortable = sortable ?? context.sortable;
|
|
23
|
-
|
|
23
|
+
const { ref } = (0, sortable_1.useSortable)({
|
|
24
|
+
id: value,
|
|
25
|
+
index: _index,
|
|
26
|
+
disabled: !_sortable
|
|
27
|
+
});
|
|
28
|
+
return ((0, jsx_runtime_1.jsxs)(transitionBase_1.Collapse, { orientation: "horizontal", ...(0, utils_1.mergeComponentProps)(props, {
|
|
29
|
+
ref,
|
|
30
|
+
className: tabs_style_1.classes.tab,
|
|
31
|
+
style: {
|
|
24
32
|
borderColor: context.variant === 'line' && !context.animating && _active ? colorValue : void 0,
|
|
25
|
-
color: _active ? colorValue : void 0
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
color: _active ? colorValue : void 0
|
|
34
|
+
},
|
|
35
|
+
onClick: e => {
|
|
28
36
|
!disabled && props.onClick?.(e);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
}
|
|
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
|
});
|
|
@@ -24,6 +24,7 @@ exports.Tabs = (0, react_2.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
24
24
|
const setInnerValue = (value) => {
|
|
25
25
|
if (!readOnly && !disabled) {
|
|
26
26
|
_setInnerValue(value);
|
|
27
|
+
variant === 'line' && setAnimating(true);
|
|
27
28
|
}
|
|
28
29
|
};
|
|
29
30
|
const [animating, setAnimating] = (0, utils_1.useDerivedState)(prev => typeof prev !== 'undefined', [innerValue.current]);
|
|
@@ -32,9 +33,6 @@ exports.Tabs = (0, react_2.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
32
33
|
setInnerValue(value);
|
|
33
34
|
};
|
|
34
35
|
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
36
|
const eventName = changeEvent === 'click' ? 'onClick' : 'onPointerDown';
|
|
39
37
|
const renderTabs = () => {
|
|
40
38
|
if (tabs) {
|
|
@@ -114,6 +112,9 @@ exports.Tabs = (0, react_2.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
114
112
|
resizeObserver.disconnect();
|
|
115
113
|
};
|
|
116
114
|
}, [position]);
|
|
115
|
+
const getActiveTab = (0, react_2.useCallback)(() => {
|
|
116
|
+
return tabRefs.current.get(innerValue.current);
|
|
117
|
+
}, []);
|
|
117
118
|
const shouldScroll = (0, react_2.useRef)(true);
|
|
118
119
|
(0, react_2.useEffect)(() => {
|
|
119
120
|
if (shouldScroll.current) {
|
|
@@ -126,7 +126,7 @@ function useStyle({ color, variant }) {
|
|
|
126
126
|
background-color: ${divider};
|
|
127
127
|
position: absolute;
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
.${exports.classes.tab} {
|
|
131
131
|
display: flex;
|
|
132
132
|
align-items: center;
|
|
@@ -138,7 +138,7 @@ function useStyle({ color, variant }) {
|
|
|
138
138
|
overflow: hidden;
|
|
139
139
|
z-index: 1;
|
|
140
140
|
-webkit-tap-highlight-color: transparent;
|
|
141
|
-
transition:
|
|
141
|
+
transition: background-color, color .25s ${easing.easeOut};
|
|
142
142
|
|
|
143
143
|
&[data-orientation=vertical] {
|
|
144
144
|
flex-direction: column;
|
|
@@ -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,13 +1,13 @@
|
|
|
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 { SortableItem } from '../sortableItem/index.js';
|
|
10
9
|
import { Collapse } from '../transitionBase/index.js';
|
|
10
|
+
import { useSortable } from '@dnd-kit/react/sortable';
|
|
11
11
|
export const Tab = memo(({ prefix, suffix, color, orientation, label, value, disabled, closable, onClose, sortable, _active, _index, ...props }) => {
|
|
12
12
|
const context = useTabsContext();
|
|
13
13
|
const colorValue = useColor(color ?? context.color);
|
|
@@ -17,14 +17,23 @@ export const Tab = memo(({ prefix, suffix, color, orientation, label, value, dis
|
|
|
17
17
|
context.onClose?.(value);
|
|
18
18
|
};
|
|
19
19
|
const _sortable = sortable ?? context.sortable;
|
|
20
|
-
|
|
20
|
+
const { ref } = useSortable({
|
|
21
|
+
id: value,
|
|
22
|
+
index: _index,
|
|
23
|
+
disabled: !_sortable
|
|
24
|
+
});
|
|
25
|
+
return (_jsxs(Collapse, { orientation: "horizontal", ...mergeComponentProps(props, {
|
|
26
|
+
ref,
|
|
27
|
+
className: classes.tab,
|
|
28
|
+
style: {
|
|
21
29
|
borderColor: context.variant === 'line' && !context.animating && _active ? colorValue : void 0,
|
|
22
|
-
color: _active ? colorValue : void 0
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
color: _active ? colorValue : void 0
|
|
31
|
+
},
|
|
32
|
+
onClick: e => {
|
|
25
33
|
!disabled && props.onClick?.(e);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
}
|
|
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,6 +1,6 @@
|
|
|
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
5
|
import { clsx, cloneRef, isUnset, useControlled, useDerivedState, defaultSensors, onDndDragEnd } from '../../utils/index.js';
|
|
6
6
|
import { useTheme } from '../theme/index.js';
|
|
@@ -20,6 +20,7 @@ export const Tabs = memo(({ tabs, labelKey = 'label', primaryKey = 'value', size
|
|
|
20
20
|
const setInnerValue = (value) => {
|
|
21
21
|
if (!readOnly && !disabled) {
|
|
22
22
|
_setInnerValue(value);
|
|
23
|
+
variant === 'line' && setAnimating(true);
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
const [animating, setAnimating] = useDerivedState(prev => typeof prev !== 'undefined', [innerValue.current]);
|
|
@@ -28,9 +29,6 @@ export const Tabs = memo(({ tabs, labelKey = 'label', primaryKey = 'value', size
|
|
|
28
29
|
setInnerValue(value);
|
|
29
30
|
};
|
|
30
31
|
const tabRefs = useRef(new Map());
|
|
31
|
-
const getActiveTab = () => {
|
|
32
|
-
return isUnset(innerValue.current) ? void 0 : tabRefs.current.get(innerValue.current);
|
|
33
|
-
};
|
|
34
32
|
const eventName = changeEvent === 'click' ? 'onClick' : 'onPointerDown';
|
|
35
33
|
const renderTabs = () => {
|
|
36
34
|
if (tabs) {
|
|
@@ -110,6 +108,9 @@ export const Tabs = memo(({ tabs, labelKey = 'label', primaryKey = 'value', size
|
|
|
110
108
|
resizeObserver.disconnect();
|
|
111
109
|
};
|
|
112
110
|
}, [position]);
|
|
111
|
+
const getActiveTab = useCallback(() => {
|
|
112
|
+
return tabRefs.current.get(innerValue.current);
|
|
113
|
+
}, []);
|
|
113
114
|
const shouldScroll = useRef(true);
|
|
114
115
|
useEffect(() => {
|
|
115
116
|
if (shouldScroll.current) {
|
|
@@ -122,7 +122,7 @@ export function useStyle({ color, variant }) {
|
|
|
122
122
|
background-color: ${divider};
|
|
123
123
|
position: absolute;
|
|
124
124
|
}
|
|
125
|
-
|
|
125
|
+
|
|
126
126
|
.${classes.tab} {
|
|
127
127
|
display: flex;
|
|
128
128
|
align-items: center;
|
|
@@ -134,7 +134,7 @@ export function useStyle({ color, variant }) {
|
|
|
134
134
|
overflow: hidden;
|
|
135
135
|
z-index: 1;
|
|
136
136
|
-webkit-tap-highlight-color: transparent;
|
|
137
|
-
transition:
|
|
137
|
+
transition: background-color, color .25s ${easing.easeOut};
|
|
138
138
|
|
|
139
139
|
&[data-orientation=vertical] {
|
|
140
140
|
flex-direction: column;
|