@rovula/ui 0.0.58 → 0.0.59
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.js +3 -3
- package/dist/cjs/bundle.js.map +1 -1
- package/dist/cjs/types/components/Tree/type.d.ts +6 -5
- package/dist/components/Tabs/Tabs.js +42 -35
- package/dist/components/Tabs/Tabs.stories.js +38 -2
- package/dist/components/Tree/Tree.js +2 -2
- package/dist/components/Tree/TreeItem.js +6 -6
- package/dist/esm/bundle.js +2 -2
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/types/components/Tree/type.d.ts +6 -5
- package/dist/index.d.ts +6 -5
- package/package.json +1 -1
- package/src/components/Tabs/Tabs.stories.tsx +60 -3
- package/src/components/Tabs/Tabs.tsx +43 -38
- package/src/components/Tree/Tree.tsx +2 -2
- package/src/components/Tree/TreeItem.tsx +6 -5
- package/src/components/Tree/type.ts +6 -5
|
@@ -5,7 +5,8 @@ export type TreeData<T = {}> = {
|
|
|
5
5
|
icon?: ReactNode;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
isLeaf?: boolean;
|
|
8
|
-
|
|
8
|
+
itemData?: any;
|
|
9
|
+
onClickItem?: (id: string, itemData?: any) => void;
|
|
9
10
|
children?: TreeData<T>[];
|
|
10
11
|
renderIcon?: (params: {
|
|
11
12
|
id: string;
|
|
@@ -31,9 +32,9 @@ export interface TreeItemProps extends TreeData {
|
|
|
31
32
|
checkIsChecked: (id: string) => boolean;
|
|
32
33
|
checkAutoDisabled: (id: string) => boolean;
|
|
33
34
|
checkIsLoading?: (id: string) => void;
|
|
34
|
-
onExpandChange?: (id: string, expanded: boolean) => void;
|
|
35
|
+
onExpandChange?: (id: string, expanded: boolean, itemData: any) => void;
|
|
35
36
|
onCheckedChange?: (id: string, checked: boolean) => void;
|
|
36
|
-
notifyClickItem?: (id: string) => void;
|
|
37
|
+
notifyClickItem?: (id: string, itemData: any) => void;
|
|
37
38
|
renderRightSection?: (params: {
|
|
38
39
|
id: string;
|
|
39
40
|
expanded: boolean;
|
|
@@ -82,9 +83,9 @@ export interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRig
|
|
|
82
83
|
defaultCheckedId?: string[];
|
|
83
84
|
checkedId?: string[];
|
|
84
85
|
loadingId?: string[];
|
|
85
|
-
onExpandChange?: (id: string, expanded: boolean) => void;
|
|
86
|
+
onExpandChange?: (id: string, expanded: boolean, itemData: any) => void;
|
|
86
87
|
onCheckedChange?: (checkedState: Record<string, boolean>, id?: string) => void;
|
|
87
|
-
onClickItem?: (id: string) => void;
|
|
88
|
+
onClickItem?: (id: string, itemData: any) => void;
|
|
88
89
|
onCheckedItem?: (id: string, checked: boolean) => void;
|
|
89
90
|
defaultExpandAll?: boolean;
|
|
90
91
|
defaultCheckAll?: boolean;
|
|
@@ -19,40 +19,47 @@ const Tabs = ({ tabs = [], value, initialTab = 0, tabBarSize = 38, enableBorderL
|
|
|
19
19
|
setActiveTab(value);
|
|
20
20
|
}
|
|
21
21
|
}, [value]);
|
|
22
|
-
const updateSliderStyle = () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
22
|
+
// const updateSliderStyle = () => {
|
|
23
|
+
// const activeTabElement = tabRefs.current[activeTab];
|
|
24
|
+
// if (activeTabElement) {
|
|
25
|
+
// setSliderStyle({
|
|
26
|
+
// width: `${activeTabElement.offsetWidth}px`,
|
|
27
|
+
// transform: `translateX(${activeTabElement.offsetLeft}px)`,
|
|
28
|
+
// });
|
|
29
|
+
// }
|
|
30
|
+
// };
|
|
31
|
+
// useEffect(() => {
|
|
32
|
+
// let timer: NodeJS.Timeout;
|
|
33
|
+
// if (isInitialMount.current) {
|
|
34
|
+
// isInitialMount.current = false;
|
|
35
|
+
// // Set initial position without animation
|
|
36
|
+
// const activeTabElement = tabRefs.current[activeTab];
|
|
37
|
+
// if (activeTabElement) {
|
|
38
|
+
// setSliderStyle({
|
|
39
|
+
// width: "0px",
|
|
40
|
+
// transform: `translateX(${
|
|
41
|
+
// activeTabElement.offsetLeft + activeTabElement.offsetWidth / 2
|
|
42
|
+
// }px)`,
|
|
43
|
+
// });
|
|
44
|
+
// // Trigger reflow
|
|
45
|
+
// timer = setTimeout(() => {
|
|
46
|
+
// updateSliderStyle();
|
|
47
|
+
// }, 50);
|
|
48
|
+
// }
|
|
49
|
+
// } else {
|
|
50
|
+
// updateSliderStyle();
|
|
51
|
+
// }
|
|
52
|
+
// const handleResize = () => {
|
|
53
|
+
// updateSliderStyle();
|
|
54
|
+
// };
|
|
55
|
+
// window.addEventListener("resize", handleResize);
|
|
56
|
+
// return () => {
|
|
57
|
+
// window.removeEventListener("resize", handleResize);
|
|
58
|
+
// if (timer) {
|
|
59
|
+
// clearTimeout(timer);
|
|
60
|
+
// }
|
|
61
|
+
// };
|
|
62
|
+
// }, [activeTab, tabs, tabMode, keepIconSpace]);
|
|
56
63
|
return (_jsxs("div", { className: cn("w-full", className), children: [_jsxs("div", { className: cn(" relative flex flex-row w-full", {
|
|
57
64
|
[`border-b-[1px] border-base-stroke`]: enableBorderLine,
|
|
58
65
|
"border-state-disable-outline": disabled,
|
|
@@ -77,6 +84,6 @@ const Tabs = ({ tabs = [], value, initialTab = 0, tabBarSize = 38, enableBorderL
|
|
|
77
84
|
onTabChange === null || onTabChange === void 0 ? void 0 : onTabChange(index);
|
|
78
85
|
}, 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`, {
|
|
79
86
|
"bg-state-disable-solid": disabled,
|
|
80
|
-
}, 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:
|
|
87
|
+
}, 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 })] }));
|
|
81
88
|
};
|
|
82
89
|
export default Tabs;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from "react";
|
|
2
3
|
import Tabs from "./Tabs";
|
|
3
4
|
import { ChevronDownIcon, ArchiveBoxIcon } from "@heroicons/react/16/solid";
|
|
4
5
|
import ActionButton from "../ActionButton/ActionButton";
|
|
5
6
|
import Icon from "../Icon/Icon";
|
|
6
7
|
import { useArgs } from "@storybook/preview-api";
|
|
7
|
-
import { Button } from "@/index";
|
|
8
|
+
import { Button, Tree } from "@/index";
|
|
9
|
+
import { exampleData } from "../Tree/example-data";
|
|
8
10
|
const meta = {
|
|
9
11
|
title: "Components/Tabs",
|
|
10
12
|
component: Tabs,
|
|
@@ -115,11 +117,45 @@ export const Disabled = {
|
|
|
115
117
|
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 }))] }));
|
|
116
118
|
},
|
|
117
119
|
};
|
|
120
|
+
const TabContent = ({ tab }) => {
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
console.log("tab ", tab, " Mount");
|
|
123
|
+
return () => {
|
|
124
|
+
console.log("tab ", tab, " DidMount");
|
|
125
|
+
};
|
|
126
|
+
}, [tab]);
|
|
127
|
+
return (_jsxs("div", { children: [_jsxs("p", { children: ["Tab ", tab, " content"] }), _jsx("input", {}), _jsx(Tree, { data: exampleData })] }));
|
|
128
|
+
};
|
|
118
129
|
export const Controller = {
|
|
119
130
|
args: {
|
|
120
131
|
initialTab: 1,
|
|
121
132
|
value: 0,
|
|
122
|
-
tabs
|
|
133
|
+
tabs: [
|
|
134
|
+
// {
|
|
135
|
+
// label: "Tab1",
|
|
136
|
+
// content: <TabContent tab={1} />,
|
|
137
|
+
// },
|
|
138
|
+
// {
|
|
139
|
+
// label: "Tab2",
|
|
140
|
+
// content: <TabContent tab={2} />,
|
|
141
|
+
// },
|
|
142
|
+
// {
|
|
143
|
+
// label: "Tab3",
|
|
144
|
+
// content: <TabContent tab={3} />,
|
|
145
|
+
// },
|
|
146
|
+
{
|
|
147
|
+
label: "Tab1",
|
|
148
|
+
content: (_jsxs("div", { children: ["fdfsdfdsfsdf ", _jsx("input", {})] }, `tab-content-key-1`)),
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
label: "Tab2",
|
|
152
|
+
content: (_jsxs("div", { children: ["fdfsdfdsfsdf ", _jsx("input", {})] }, `tab-content-key-2`)),
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
label: "Tab3",
|
|
156
|
+
content: (_jsxs("div", { children: ["fdfsdfdsfsdf ", _jsx("input", {})] }, `tab-content-key-3`)),
|
|
157
|
+
},
|
|
158
|
+
],
|
|
123
159
|
enableAddTabButton: true,
|
|
124
160
|
},
|
|
125
161
|
render: (args) => {
|
|
@@ -76,8 +76,8 @@ const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, l
|
|
|
76
76
|
return Object.assign(Object.assign({}, prev), state);
|
|
77
77
|
});
|
|
78
78
|
}, [data, hierarchicalCheck]);
|
|
79
|
-
const handleExpandChange = useCallback((id, expanded) => {
|
|
80
|
-
onExpandChange === null || onExpandChange === void 0 ? void 0 : onExpandChange(id, expanded);
|
|
79
|
+
const handleExpandChange = useCallback((id, expanded, itemData) => {
|
|
80
|
+
onExpandChange === null || onExpandChange === void 0 ? void 0 : onExpandChange(id, expanded, itemData);
|
|
81
81
|
setExpandedState((prev) => (Object.assign(Object.assign({}, prev), { [id]: expanded })));
|
|
82
82
|
}, [onExpandChange]);
|
|
83
83
|
const handleCheckedChange = useCallback((id, checked) => {
|
|
@@ -3,7 +3,7 @@ import { ActionButton, Checkbox, Loading } from "@/index";
|
|
|
3
3
|
import { cn } from "@/utils/cn";
|
|
4
4
|
import { useCallback, useEffect, useMemo } from "react";
|
|
5
5
|
import Icon from "../Icon/Icon";
|
|
6
|
-
const TreeItem = ({ id, title, classes, children, isFirstLevel = false, isLeaf = false, disabled, icon, showIcon, showExpandButton, enableSeparatorLine = true, isLastItem, checkable, checkIsExpanded, checkIsChecked, checkAutoDisabled, checkIsLoading, onExpandChange, onCheckedChange, onClickItem, renderIcon, renderElement, renderTitle, renderRightSection, lineSize = 2, horizontalLineWidth = 4, expandButtonSize = 30, spacing = 2, currentLevel = 1, maxLevel = 10, notifyClickItem, }) => {
|
|
6
|
+
const TreeItem = ({ id, title, classes, children, isFirstLevel = false, isLeaf = false, disabled, icon, showIcon, showExpandButton, enableSeparatorLine = true, isLastItem, checkable, checkIsExpanded, checkIsChecked, checkAutoDisabled, checkIsLoading, onExpandChange, onCheckedChange, onClickItem, renderIcon, renderElement, renderTitle, renderRightSection, lineSize = 2, horizontalLineWidth = 4, expandButtonSize = 30, spacing = 2, currentLevel = 1, maxLevel = 10, notifyClickItem, itemData, }) => {
|
|
7
7
|
const isLoading = useMemo(() => checkIsLoading === null || checkIsLoading === void 0 ? void 0 : checkIsLoading(id), [checkIsLoading, id]);
|
|
8
8
|
const isChecked = useMemo(() => checkIsChecked(id), [checkIsChecked, id]);
|
|
9
9
|
const isExpanded = useMemo(() => checkIsExpanded(id), [checkIsExpanded, id]);
|
|
@@ -46,17 +46,17 @@ const TreeItem = ({ id, title, classes, children, isFirstLevel = false, isLeaf =
|
|
|
46
46
|
checkboxSpace,
|
|
47
47
|
]);
|
|
48
48
|
const handleExpandToggle = useCallback(() => {
|
|
49
|
-
onExpandChange === null || onExpandChange === void 0 ? void 0 : onExpandChange(id, !isExpanded);
|
|
50
|
-
}, [id, isExpanded, onExpandChange]);
|
|
49
|
+
onExpandChange === null || onExpandChange === void 0 ? void 0 : onExpandChange(id, !isExpanded, itemData);
|
|
50
|
+
}, [id, isExpanded, onExpandChange, itemData]);
|
|
51
51
|
useEffect(() => {
|
|
52
52
|
if (isExpanded && !isLoading && !hasChildren) {
|
|
53
53
|
handleExpandToggle();
|
|
54
54
|
}
|
|
55
55
|
}, [isLoading, handleExpandToggle]);
|
|
56
56
|
const handleOnClickItem = useCallback(() => {
|
|
57
|
-
onClickItem === null || onClickItem === void 0 ? void 0 : onClickItem(id);
|
|
58
|
-
notifyClickItem === null || notifyClickItem === void 0 ? void 0 : notifyClickItem(id);
|
|
59
|
-
}, [onClickItem, notifyClickItem,
|
|
57
|
+
onClickItem === null || onClickItem === void 0 ? void 0 : onClickItem(id, itemData);
|
|
58
|
+
notifyClickItem === null || notifyClickItem === void 0 ? void 0 : notifyClickItem(id, itemData);
|
|
59
|
+
}, [id, isExpanded, onClickItem, notifyClickItem, itemData]);
|
|
60
60
|
const defaultIcon = (_jsx(Icon, { name: isExpanded ? "folder-open" : "folder", className: "fill-warning size-[18px]" }));
|
|
61
61
|
const customIcon = icon !== null && icon !== void 0 ? icon : renderIcon === null || renderIcon === void 0 ? void 0 : renderIcon({
|
|
62
62
|
id,
|