@rovula/ui 0.0.52 → 0.0.54
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/bundle.css +50 -10
- package/dist/cjs/bundle.js +2 -2
- package/dist/cjs/bundle.js.map +1 -1
- package/dist/cjs/types/components/Tabs/Tabs.d.ts +14 -1
- package/dist/cjs/types/components/Tabs/Tabs.stories.d.ts +81 -2
- package/dist/cjs/types/components/Tree/Tree.stories.d.ts +3 -0
- package/dist/cjs/types/components/Tree/example-data.d.ts +5 -0
- package/dist/cjs/types/components/Tree/type.d.ts +13 -4
- package/dist/components/Tabs/Tabs.js +35 -18
- package/dist/components/Tabs/Tabs.stories.js +70 -3
- package/dist/components/Tree/Tree.js +5 -5
- package/dist/components/Tree/Tree.stories.js +35 -2091
- package/dist/components/Tree/TreeItem.js +16 -8
- package/dist/components/Tree/example-data.js +2125 -0
- package/dist/esm/bundle.css +50 -10
- package/dist/esm/bundle.js +2 -2
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/types/components/Tabs/Tabs.d.ts +14 -1
- package/dist/esm/types/components/Tabs/Tabs.stories.d.ts +81 -2
- package/dist/esm/types/components/Tree/Tree.stories.d.ts +3 -0
- package/dist/esm/types/components/Tree/example-data.d.ts +5 -0
- package/dist/esm/types/components/Tree/type.d.ts +13 -4
- package/dist/index.d.ts +26 -5
- package/dist/src/theme/global.css +36 -13
- package/package.json +6 -1
- package/src/components/Tabs/Tabs.css +21 -0
- package/src/components/Tabs/Tabs.stories.tsx +140 -4
- package/src/components/Tabs/Tabs.tsx +134 -50
- package/src/components/Tree/Tree.stories.tsx +61 -2133
- package/src/components/Tree/Tree.tsx +11 -3
- package/src/components/Tree/TreeItem.tsx +47 -17
- package/src/components/Tree/example-data.ts +2162 -0
- package/src/components/Tree/type.ts +13 -4
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import "./Tabs.css";
|
|
2
3
|
type Tab = {
|
|
3
4
|
label: string;
|
|
4
5
|
startTabContent?: React.ReactElement;
|
|
5
6
|
endTabContent?: React.ReactElement;
|
|
6
7
|
content: React.ReactNode;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
isLoading?: boolean;
|
|
7
10
|
};
|
|
8
11
|
type TabsProps = {
|
|
9
12
|
tabs: Tab[];
|
|
@@ -11,12 +14,22 @@ type TabsProps = {
|
|
|
11
14
|
tabBarSize?: number;
|
|
12
15
|
tabMode?: "start" | "justify";
|
|
13
16
|
enableBorderLine?: boolean;
|
|
17
|
+
enableAddTabButton?: boolean;
|
|
18
|
+
keepIconSpace?: boolean;
|
|
14
19
|
className?: string;
|
|
15
20
|
tabBarClassName?: string;
|
|
21
|
+
tabBarContainerClassName?: string;
|
|
22
|
+
tabBarWrapperClassName?: string;
|
|
16
23
|
tabButtonClassName?: string;
|
|
17
24
|
tabButtonActiveClassName?: string;
|
|
18
25
|
tabContentClassName?: string;
|
|
19
|
-
|
|
26
|
+
addTabButtonWrapperClassName?: string;
|
|
27
|
+
borderSliderClassName?: string;
|
|
28
|
+
leftAction?: React.ReactNode;
|
|
29
|
+
rightAction?: React.ReactNode;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
onAddTab?: () => void;
|
|
32
|
+
onTabChange?: (tabIndex: number) => void;
|
|
20
33
|
};
|
|
21
34
|
declare const Tabs: React.FC<TabsProps>;
|
|
22
35
|
export default Tabs;
|
|
@@ -7,17 +7,29 @@ declare const meta: {
|
|
|
7
7
|
startTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
8
8
|
endTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
9
9
|
content: React.ReactNode;
|
|
10
|
+
disabled?: boolean | undefined;
|
|
11
|
+
isLoading?: boolean | undefined;
|
|
10
12
|
}[];
|
|
11
13
|
initialTab?: number | undefined;
|
|
12
14
|
tabBarSize?: number | undefined;
|
|
13
15
|
tabMode?: "start" | "justify" | undefined;
|
|
14
16
|
enableBorderLine?: boolean | undefined;
|
|
17
|
+
enableAddTabButton?: boolean | undefined;
|
|
18
|
+
keepIconSpace?: boolean | undefined;
|
|
15
19
|
className?: string | undefined;
|
|
16
20
|
tabBarClassName?: string | undefined;
|
|
21
|
+
tabBarContainerClassName?: string | undefined;
|
|
22
|
+
tabBarWrapperClassName?: string | undefined;
|
|
17
23
|
tabButtonClassName?: string | undefined;
|
|
18
24
|
tabButtonActiveClassName?: string | undefined;
|
|
19
25
|
tabContentClassName?: string | undefined;
|
|
20
|
-
|
|
26
|
+
addTabButtonWrapperClassName?: string | undefined;
|
|
27
|
+
borderSliderClassName?: string | undefined;
|
|
28
|
+
leftAction?: React.ReactNode;
|
|
29
|
+
rightAction?: React.ReactNode;
|
|
30
|
+
disabled?: boolean | undefined;
|
|
31
|
+
onAddTab?: (() => void) | undefined;
|
|
32
|
+
onTabChange?: ((tabIndex: number) => void) | undefined;
|
|
21
33
|
}>;
|
|
22
34
|
tags: string[];
|
|
23
35
|
parameters: {
|
|
@@ -29,17 +41,29 @@ declare const meta: {
|
|
|
29
41
|
startTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
30
42
|
endTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
31
43
|
content: React.ReactNode;
|
|
44
|
+
disabled?: boolean | undefined;
|
|
45
|
+
isLoading?: boolean | undefined;
|
|
32
46
|
}[];
|
|
33
47
|
initialTab?: number | undefined;
|
|
34
48
|
tabBarSize?: number | undefined;
|
|
35
49
|
tabMode?: "start" | "justify" | undefined;
|
|
36
50
|
enableBorderLine?: boolean | undefined;
|
|
51
|
+
enableAddTabButton?: boolean | undefined;
|
|
52
|
+
keepIconSpace?: boolean | undefined;
|
|
37
53
|
className?: string | undefined;
|
|
38
54
|
tabBarClassName?: string | undefined;
|
|
55
|
+
tabBarContainerClassName?: string | undefined;
|
|
56
|
+
tabBarWrapperClassName?: string | undefined;
|
|
39
57
|
tabButtonClassName?: string | undefined;
|
|
40
58
|
tabButtonActiveClassName?: string | undefined;
|
|
41
59
|
tabContentClassName?: string | undefined;
|
|
42
|
-
|
|
60
|
+
addTabButtonWrapperClassName?: string | undefined;
|
|
61
|
+
borderSliderClassName?: string | undefined;
|
|
62
|
+
leftAction?: React.ReactNode;
|
|
63
|
+
rightAction?: React.ReactNode;
|
|
64
|
+
disabled?: boolean | undefined;
|
|
65
|
+
onAddTab?: (() => void) | undefined;
|
|
66
|
+
onTabChange?: ((tabIndex: number) => void) | undefined;
|
|
43
67
|
}>) => import("react/jsx-runtime").JSX.Element)[];
|
|
44
68
|
};
|
|
45
69
|
export default meta;
|
|
@@ -65,3 +89,58 @@ export declare const CustomTab: {
|
|
|
65
89
|
};
|
|
66
90
|
render: (args: {}) => import("react/jsx-runtime").JSX.Element;
|
|
67
91
|
};
|
|
92
|
+
export declare const TabWithLeftRightAction: {
|
|
93
|
+
args: {
|
|
94
|
+
initialTab: number;
|
|
95
|
+
tabs: {
|
|
96
|
+
label: string;
|
|
97
|
+
content: import("react/jsx-runtime").JSX.Element;
|
|
98
|
+
}[];
|
|
99
|
+
};
|
|
100
|
+
render: (args: {}) => import("react/jsx-runtime").JSX.Element;
|
|
101
|
+
};
|
|
102
|
+
export declare const AddTabWithScrolling: {
|
|
103
|
+
args: {
|
|
104
|
+
initialTab: number;
|
|
105
|
+
tabs: {
|
|
106
|
+
label: string;
|
|
107
|
+
content: import("react/jsx-runtime").JSX.Element;
|
|
108
|
+
}[];
|
|
109
|
+
enableAddTabButton: boolean;
|
|
110
|
+
};
|
|
111
|
+
render: (args: {}) => import("react/jsx-runtime").JSX.Element;
|
|
112
|
+
};
|
|
113
|
+
export declare const KeepIconSpacing: {
|
|
114
|
+
args: {
|
|
115
|
+
initialTab: number;
|
|
116
|
+
tabs: {
|
|
117
|
+
label: string;
|
|
118
|
+
content: import("react/jsx-runtime").JSX.Element;
|
|
119
|
+
}[];
|
|
120
|
+
keepIconSpace: boolean;
|
|
121
|
+
};
|
|
122
|
+
render: (args: {}) => import("react/jsx-runtime").JSX.Element;
|
|
123
|
+
};
|
|
124
|
+
export declare const Loading: {
|
|
125
|
+
args: {
|
|
126
|
+
initialTab: number;
|
|
127
|
+
tabs: {
|
|
128
|
+
isLoading: boolean;
|
|
129
|
+
startTabContent: import("react/jsx-runtime").JSX.Element;
|
|
130
|
+
label: string;
|
|
131
|
+
content: import("react/jsx-runtime").JSX.Element;
|
|
132
|
+
}[];
|
|
133
|
+
};
|
|
134
|
+
render: (args: {}) => import("react/jsx-runtime").JSX.Element;
|
|
135
|
+
};
|
|
136
|
+
export declare const Disabled: {
|
|
137
|
+
args: {
|
|
138
|
+
initialTab: number;
|
|
139
|
+
tabs: {
|
|
140
|
+
disabled: boolean;
|
|
141
|
+
label: string;
|
|
142
|
+
content: import("react/jsx-runtime").JSX.Element;
|
|
143
|
+
}[];
|
|
144
|
+
};
|
|
145
|
+
render: (args: {}) => import("react/jsx-runtime").JSX.Element;
|
|
146
|
+
};
|
|
@@ -11,3 +11,6 @@ export declare const ControlShowExpandButton: StoryObj<typeof Tree>;
|
|
|
11
11
|
export declare const Diabled: StoryObj<typeof Tree>;
|
|
12
12
|
export declare const DiabledEachItem: StoryObj<typeof Tree>;
|
|
13
13
|
export declare const ExpandLoadData: StoryObj<typeof Tree>;
|
|
14
|
+
export declare const MaximumLevel: StoryObj<typeof Tree>;
|
|
15
|
+
export declare const Leaf: StoryObj<typeof Tree>;
|
|
16
|
+
export declare const HideCheckboxMode: StoryObj<typeof Tree>;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { CSSProperties, ReactNode } from "react";
|
|
2
|
-
export type TreeData = {
|
|
2
|
+
export type TreeData<T = {}> = {
|
|
3
3
|
id: string;
|
|
4
4
|
title: string;
|
|
5
5
|
icon?: ReactNode;
|
|
6
6
|
disabled?: boolean;
|
|
7
|
+
isLeaf?: boolean;
|
|
7
8
|
onClickItem?: (id: string) => void;
|
|
8
|
-
children?: TreeData[];
|
|
9
|
+
children?: TreeData<T>[];
|
|
9
10
|
renderIcon?: (params: {
|
|
10
11
|
id: string;
|
|
11
12
|
expanded: boolean;
|
|
12
13
|
selected: boolean;
|
|
13
14
|
}) => ReactNode;
|
|
14
|
-
};
|
|
15
|
+
} & T;
|
|
15
16
|
export interface TreeItemProps extends TreeData {
|
|
17
|
+
checkable?: boolean;
|
|
16
18
|
isFirstLevel?: boolean;
|
|
17
19
|
isLastItem: boolean;
|
|
18
20
|
disabled?: boolean;
|
|
@@ -23,11 +25,14 @@ export interface TreeItemProps extends TreeData {
|
|
|
23
25
|
horizontalLineWidth?: number;
|
|
24
26
|
expandButtonSize?: number;
|
|
25
27
|
spacing?: number;
|
|
28
|
+
currentLevel: number;
|
|
29
|
+
maxLevel?: number;
|
|
26
30
|
checkIsExpanded: (id: string) => boolean;
|
|
27
31
|
checkIsChecked: (id: string) => boolean;
|
|
28
32
|
checkIsLoading?: (id: string) => void;
|
|
29
33
|
onExpandChange?: (id: string, expanded: boolean) => void;
|
|
30
34
|
onCheckedChange?: (id: string, checked: boolean) => void;
|
|
35
|
+
notifyClickItem?: (id: string) => void;
|
|
31
36
|
renderRightSection?: (params: {
|
|
32
37
|
id: string;
|
|
33
38
|
expanded: boolean;
|
|
@@ -77,8 +82,12 @@ export interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRig
|
|
|
77
82
|
checkedId?: string[];
|
|
78
83
|
loadingId?: string[];
|
|
79
84
|
onExpandChange?: (id: string, expanded: boolean) => void;
|
|
80
|
-
onCheckedChange?: (
|
|
85
|
+
onCheckedChange?: (checkedState: Record<string, boolean>) => void;
|
|
86
|
+
onClickItem?: (id: string) => void;
|
|
87
|
+
onCheckedItem?: (id: string, checked: boolean) => void;
|
|
81
88
|
defaultExpandAll?: boolean;
|
|
82
89
|
defaultCheckAll?: boolean;
|
|
83
90
|
hierarchicalCheck?: boolean;
|
|
91
|
+
checkable?: boolean;
|
|
92
|
+
maxLevel?: number;
|
|
84
93
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useRef, useEffect } from "react";
|
|
3
3
|
import { cn } from "@/utils/cn";
|
|
4
|
-
|
|
4
|
+
import "./Tabs.css";
|
|
5
|
+
import ActionButton from "../ActionButton/ActionButton";
|
|
6
|
+
import Icon from "../Icon/Icon";
|
|
7
|
+
import { Loading } from "@/index";
|
|
8
|
+
const Tabs = ({ tabs = [], initialTab = 0, tabBarSize = 38, enableBorderLine = true, enableAddTabButton = false, keepIconSpace = true, disabled = false, tabMode = "start", className, tabBarClassName, tabBarContainerClassName, tabBarWrapperClassName, tabButtonClassName, tabButtonActiveClassName, tabContentClassName, addTabButtonWrapperClassName, borderSliderClassName, leftAction, rightAction, onAddTab, onTabChange, }) => {
|
|
5
9
|
var _a;
|
|
6
10
|
const [activeTab, setActiveTab] = useState(initialTab);
|
|
7
11
|
const [sliderStyle, setSliderStyle] = useState({
|
|
@@ -38,23 +42,36 @@ const Tabs = ({ tabs = [], initialTab = 0, tabBarSize = 38, enableBorderLine = t
|
|
|
38
42
|
else {
|
|
39
43
|
updateSliderStyle();
|
|
40
44
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}, [activeTab, tabs, tabMode]);
|
|
47
|
-
return (_jsxs("div", { className: cn("w-full", className), children: [_jsxs("div", { className: cn(
|
|
45
|
+
const handleResize = () => {
|
|
46
|
+
updateSliderStyle();
|
|
47
|
+
};
|
|
48
|
+
window.addEventListener("resize", handleResize);
|
|
49
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
50
|
+
}, [activeTab, tabs, tabMode, keepIconSpace]);
|
|
51
|
+
return (_jsxs("div", { className: cn("w-full", className), children: [_jsxs("div", { className: cn(" relative flex flex-row w-full", {
|
|
48
52
|
[`border-b-[1px] border-base-stroke`]: enableBorderLine,
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
},
|
|
53
|
-
"typography-small3 text-text-dark": index === activeTab,
|
|
54
|
-
"typography-small1 text-text-grey-light hover:text-text-grey-dark active:text-text-dark": index !== activeTab,
|
|
55
|
-
[tabButtonClassName !== null && tabButtonClassName !== void 0 ? tabButtonClassName : ""]: true,
|
|
56
|
-
[tabButtonActiveClassName !== null && tabButtonActiveClassName !== void 0 ? tabButtonActiveClassName : ""]: index === activeTab,
|
|
53
|
+
"border-state-disable-outline": disabled,
|
|
54
|
+
"flex-1": tabMode === "justify",
|
|
55
|
+
tabBarContainerClassName,
|
|
56
|
+
}), children: [leftAction, _jsx("div", { className: cn("relative flex flex-row overflow-x-auto", {
|
|
57
57
|
"flex-1": tabMode === "justify",
|
|
58
|
-
}
|
|
58
|
+
}, tabBarWrapperClassName), children: _jsxs("div", { className: cn("tabs-scrollbar overflow-x-auto w-full", `relative flex gap-3 h-[${tabBarSize}px] box-border`, {
|
|
59
|
+
"gap-0": tabMode === "justify",
|
|
60
|
+
}, tabBarClassName), style: {
|
|
61
|
+
justifyContent: tabMode === "justify" ? "stretch" : tabMode,
|
|
62
|
+
}, role: "tablist", children: [tabs.map((tab, index) => (_jsxs("button", { ref: (el) => (tabRefs.current[index] = el), role: "tab", "aria-selected": index === activeTab, "aria-controls": `tab-content-${index}`, disabled: disabled || tab.disabled, id: `tab-${index}`, className: cn("flex justify-center flex-row items-center py-3 cursor-pointer transition-colors duration-300 box-border gap-1 flex-shrink-0 typography-subtitile6", {
|
|
63
|
+
"text-foreground": index === activeTab,
|
|
64
|
+
"text-text-grey-medium hover:text-text-grey-dark active:text-text-dark": index !== activeTab,
|
|
65
|
+
"text-state-disable-solid pointer-events-none": disabled || tab.disabled,
|
|
66
|
+
"text-state-disable-outline": (index === activeTab && disabled) || tab.disabled,
|
|
67
|
+
[tabButtonClassName !== null && tabButtonClassName !== void 0 ? tabButtonClassName : ""]: true,
|
|
68
|
+
[tabButtonActiveClassName !== null && tabButtonActiveClassName !== void 0 ? tabButtonActiveClassName : ""]: index === activeTab,
|
|
69
|
+
"flex-1": tabMode === "justify",
|
|
70
|
+
}), onClick: () => {
|
|
71
|
+
setActiveTab(index);
|
|
72
|
+
onTabChange === null || onTabChange === void 0 ? void 0 : onTabChange(index);
|
|
73
|
+
}, children: [(keepIconSpace || tab.startTabContent) && (_jsx("div", { className: "h-full w-3 flex items-center justify-center", children: tab.isLoading ? _jsx(Loading, {}) : tab.startTabContent })), tab.label, (keepIconSpace || tab.endTabContent) && (_jsx("div", { className: "h-full w-3 flex items-center justify-center", children: tab.endTabContent }))] }, index))), _jsx("div", { className: cn(`absolute left-0 bottom-0 h-[2px] rounded-full bg-foreground transition-all duration-300 ease-in-out`, {
|
|
74
|
+
"bg-state-disable-solid": disabled,
|
|
75
|
+
}, borderSliderClassName), style: sliderStyle })] }) }), enableAddTabButton && (_jsx("div", { className: cn("sticky right-0 flex content-center items-center mx-4", addTabButtonWrapperClassName), children: _jsx(ActionButton, { variant: "outline", size: "sm", onClick: () => onAddTab === null || onAddTab === void 0 ? void 0 : onAddTab(), disabled: disabled, children: _jsx(Icon, { name: "plus" }) }) })), rightAction] }), _jsx("div", { className: cn("mt-4 text-foreground", tabContentClassName), role: "tabpanel", id: `tab-content-${activeTab}`, "aria-labelledby": `tab-${activeTab}`, children: (_a = tabs[activeTab]) === null || _a === void 0 ? void 0 : _a.content })] }));
|
|
59
76
|
};
|
|
60
77
|
export default Tabs;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import Tabs from "./Tabs";
|
|
3
3
|
import { ChevronDownIcon, ArchiveBoxIcon } from "@heroicons/react/16/solid";
|
|
4
|
+
import ActionButton from "../ActionButton/ActionButton";
|
|
5
|
+
import Icon from "../Icon/Icon";
|
|
6
|
+
import { useArgs } from "@storybook/preview-api";
|
|
4
7
|
const meta = {
|
|
5
8
|
title: "Components/Tabs",
|
|
6
9
|
component: Tabs,
|
|
@@ -9,7 +12,7 @@ const meta = {
|
|
|
9
12
|
layout: "fullscreen",
|
|
10
13
|
},
|
|
11
14
|
decorators: [
|
|
12
|
-
(Story) => (_jsx("div", { className: "p-5 flex w-full", children: _jsx(Story, {}) })),
|
|
15
|
+
(Story) => (_jsx("div", { className: "p-5 flex w-full bg-base-bg2", children: _jsx(Story, {}) })),
|
|
13
16
|
],
|
|
14
17
|
};
|
|
15
18
|
export default meta;
|
|
@@ -40,10 +43,74 @@ export const Default = {
|
|
|
40
43
|
export const CustomTab = {
|
|
41
44
|
args: {
|
|
42
45
|
initialTab: 0,
|
|
43
|
-
tabs: tabs.map((tab) => (Object.assign(Object.assign({}, tab), { startTabContent: _jsx(ArchiveBoxIcon, {
|
|
46
|
+
tabs: tabs.map((tab) => (Object.assign(Object.assign({}, tab), { startTabContent: _jsx(ArchiveBoxIcon, {}), endTabContent: _jsx(ChevronDownIcon, {}) }))),
|
|
44
47
|
},
|
|
45
48
|
render: (args) => {
|
|
46
49
|
const props = Object.assign({}, args);
|
|
47
50
|
return (_jsx("div", { className: "flex flex-row gap-4 w-full", children: _jsx(Tabs, Object.assign({ tabs: tabs }, props)) }));
|
|
48
51
|
},
|
|
49
52
|
};
|
|
53
|
+
// variant="scrollable"
|
|
54
|
+
export const TabWithLeftRightAction = {
|
|
55
|
+
args: {
|
|
56
|
+
initialTab: 0,
|
|
57
|
+
tabs: tabs.map((tab) => (Object.assign({}, tab))),
|
|
58
|
+
},
|
|
59
|
+
render: (args) => {
|
|
60
|
+
const props = Object.assign({}, args);
|
|
61
|
+
return (_jsx("div", { className: "flex flex-row gap-4 w-full", children: _jsx(Tabs, Object.assign({ tabs: tabs }, props, { tabMode: "start", leftAction: _jsx(ActionButton, { onClick: () => alert("left action"), className: "mr-4", children: _jsx(Icon, { name: "academic-cap" }) }), rightAction: _jsx(ActionButton, { onClick: () => alert("right action"), className: "ml-4", children: _jsx(Icon, { name: "arrow-down-tray" }) }) })) }));
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
export const AddTabWithScrolling = {
|
|
65
|
+
args: {
|
|
66
|
+
initialTab: 0,
|
|
67
|
+
tabs,
|
|
68
|
+
enableAddTabButton: true,
|
|
69
|
+
},
|
|
70
|
+
render: (args) => {
|
|
71
|
+
const props = Object.assign({}, args);
|
|
72
|
+
const [, setArgs] = useArgs();
|
|
73
|
+
return (_jsx("div", { className: "flex flex-row gap-4 w-[500px]", children: _jsx(Tabs, Object.assign({ tabs: tabs }, props, { tabMode: "start", onAddTab: () => {
|
|
74
|
+
setArgs({
|
|
75
|
+
tabs: [
|
|
76
|
+
...props.tabs,
|
|
77
|
+
{
|
|
78
|
+
label: "Tab" + (props.tabs.length + 1),
|
|
79
|
+
content: _jsxs("p", { children: ["Tab ", props.tabs.length + 1, " content"] }),
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
} })) }));
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
export const KeepIconSpacing = {
|
|
87
|
+
args: {
|
|
88
|
+
initialTab: 0,
|
|
89
|
+
tabs,
|
|
90
|
+
keepIconSpace: true,
|
|
91
|
+
},
|
|
92
|
+
render: (args) => {
|
|
93
|
+
const props = Object.assign({}, args);
|
|
94
|
+
return (_jsx("div", { className: "flex flex-row gap-4 w-[500px]", children: _jsx(Tabs, Object.assign({ tabs: tabs }, props, { tabMode: "start" })) }));
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
export const Loading = {
|
|
98
|
+
args: {
|
|
99
|
+
initialTab: 0,
|
|
100
|
+
tabs: tabs.map((tab, i) => (Object.assign(Object.assign({}, tab), { isLoading: i !== 0, startTabContent: _jsx(Icon, { name: "rocket-launch" }) }))),
|
|
101
|
+
},
|
|
102
|
+
render: (args) => {
|
|
103
|
+
const props = Object.assign({}, args);
|
|
104
|
+
return (_jsx("div", { className: "flex flex-row gap-4 w-[500px]", children: _jsx(Tabs, Object.assign({ tabs: tabs }, props, { tabMode: "start" })) }));
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
export const Disabled = {
|
|
108
|
+
args: {
|
|
109
|
+
initialTab: 0,
|
|
110
|
+
tabs: tabs.map((tab, i) => (Object.assign(Object.assign({}, tab), { disabled: i !== 0 }))),
|
|
111
|
+
},
|
|
112
|
+
render: (args) => {
|
|
113
|
+
const props = Object.assign({}, args);
|
|
114
|
+
return (_jsxs("div", { className: "flex flex-row gap-4", children: [_jsx(Tabs, Object.assign({ tabs: tabs }, props)), _jsx(Tabs, Object.assign({ tabs: tabs }, props, { disabled: true }))] }));
|
|
115
|
+
},
|
|
116
|
+
};
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useCallback, useEffect, useState } from "react";
|
|
3
3
|
import TreeItem from "./TreeItem";
|
|
4
4
|
import { cn } from "@/utils/cn";
|
|
5
|
-
const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, loadingId, lineSize, horizontalLineWidth, expandButtonSize, spacing, renderIcon, renderRightSection, renderElement, renderTitle, onExpandChange, onCheckedChange, defaultExpandAll = false, defaultCheckAll = false, hierarchicalCheck = false, showIcon = true, disabled, enableSeparatorLine = true, }) => {
|
|
5
|
+
const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, loadingId, lineSize, horizontalLineWidth, expandButtonSize, spacing, renderIcon, renderRightSection, renderElement, renderTitle, onExpandChange, onCheckedChange, onClickItem, onCheckedItem, defaultExpandAll = false, defaultCheckAll = false, hierarchicalCheck = false, showIcon = true, disabled, enableSeparatorLine = true, checkable = true, maxLevel, }) => {
|
|
6
6
|
const [checkedState, setCheckedState] = useState({});
|
|
7
7
|
const [expandedState, setExpandedState] = useState({});
|
|
8
8
|
const traverseTree = (nodes, callback) => {
|
|
@@ -52,6 +52,7 @@ const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, l
|
|
|
52
52
|
setExpandedState((prev) => (Object.assign(Object.assign({}, prev), { [id]: expanded })));
|
|
53
53
|
}, [onExpandChange]);
|
|
54
54
|
const handleCheckedChange = useCallback((id, checked) => {
|
|
55
|
+
onCheckedItem === null || onCheckedItem === void 0 ? void 0 : onCheckedItem(id, checked);
|
|
55
56
|
let newState = Object.assign(Object.assign({}, checkedState), { [id]: checked });
|
|
56
57
|
if (hierarchicalCheck) {
|
|
57
58
|
const updateCheckedState = (nodeId, isChecked, state) => {
|
|
@@ -86,10 +87,9 @@ const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, l
|
|
|
86
87
|
}
|
|
87
88
|
setCheckedState(newState);
|
|
88
89
|
if (onCheckedChange) {
|
|
89
|
-
|
|
90
|
-
onCheckedChange(checkedIds);
|
|
90
|
+
onCheckedChange === null || onCheckedChange === void 0 ? void 0 : onCheckedChange(newState);
|
|
91
91
|
}
|
|
92
|
-
}, [checkedState, data, onCheckedChange, hierarchicalCheck]);
|
|
92
|
+
}, [checkedState, data, onCheckedChange, hierarchicalCheck, onCheckedItem]);
|
|
93
93
|
const checkIsExpanded = useCallback((id) => !!expandedState[id], [expandedState]);
|
|
94
94
|
const checkIsChecked = useCallback((id) => {
|
|
95
95
|
if (checkedId) {
|
|
@@ -102,6 +102,6 @@ const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, l
|
|
|
102
102
|
return loadingId.includes(id);
|
|
103
103
|
}
|
|
104
104
|
}, [loadingId]);
|
|
105
|
-
return (_jsx("div", { className: cn("w-full", classes === null || classes === void 0 ? void 0 : classes.container), children: data.map((item, idx) => (_jsx(TreeItem, Object.assign({ classes: classes, isFirstLevel: true, isLastItem: idx === data.length - 1, checkIsExpanded: checkIsExpanded, checkIsChecked: checkIsChecked, onExpandChange: handleExpandChange, onCheckedChange: handleCheckedChange, checkIsLoading: checkIsLoading, renderIcon: renderIcon, renderElement: renderElement, renderTitle: renderTitle, renderRightSection: renderRightSection, enableSeparatorLine: enableSeparatorLine, disabled: disabled, showIcon: showIcon, lineSize: lineSize, horizontalLineWidth: horizontalLineWidth, expandButtonSize: expandButtonSize, spacing: spacing }, item), item.id))) }));
|
|
105
|
+
return (_jsx("div", { className: cn("w-full", classes === null || classes === void 0 ? void 0 : classes.container), children: data.map((item, idx) => (_jsx(TreeItem, Object.assign({ classes: classes, isFirstLevel: true, isLastItem: idx === data.length - 1, checkIsExpanded: checkIsExpanded, checkIsChecked: checkIsChecked, onExpandChange: handleExpandChange, onCheckedChange: handleCheckedChange, checkIsLoading: checkIsLoading, renderIcon: renderIcon, renderElement: renderElement, renderTitle: renderTitle, renderRightSection: renderRightSection, enableSeparatorLine: enableSeparatorLine, disabled: disabled, showIcon: showIcon, lineSize: lineSize, horizontalLineWidth: horizontalLineWidth, expandButtonSize: expandButtonSize, spacing: spacing, notifyClickItem: onClickItem, maxLevel: maxLevel, currentLevel: 1, checkable: checkable }, item), item.id))) }));
|
|
106
106
|
};
|
|
107
107
|
export default Tree;
|