@rovula/ui 0.0.55 → 0.0.57
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 +1 -1
- package/dist/cjs/bundle.js.map +1 -1
- package/dist/cjs/types/components/Tabs/Tabs.d.ts +2 -0
- package/dist/cjs/types/components/Tabs/Tabs.stories.d.ts +16 -0
- package/dist/cjs/types/components/Tree/type.d.ts +1 -1
- package/dist/components/Tabs/Tabs.js +8 -3
- package/dist/components/Tabs/Tabs.stories.js +24 -0
- package/dist/components/Tree/Tree.js +1 -1
- package/dist/esm/bundle.js +2 -2
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/types/components/Tabs/Tabs.d.ts +2 -0
- package/dist/esm/types/components/Tabs/Tabs.stories.d.ts +16 -0
- package/dist/esm/types/components/Tree/type.d.ts +1 -1
- package/dist/index.d.ts +3 -1
- package/package.json +1 -1
- package/src/components/Tabs/Tabs.stories.tsx +48 -0
- package/src/components/Tabs/Tabs.tsx +12 -1
- package/src/components/Tree/Tree.tsx +1 -1
- package/src/components/Tree/type.ts +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import "./Tabs.css";
|
|
3
3
|
type Tab = {
|
|
4
|
+
id?: string;
|
|
4
5
|
label: string;
|
|
5
6
|
startTabContent?: React.ReactElement;
|
|
6
7
|
endTabContent?: React.ReactElement;
|
|
@@ -10,6 +11,7 @@ type Tab = {
|
|
|
10
11
|
};
|
|
11
12
|
type TabsProps = {
|
|
12
13
|
tabs: Tab[];
|
|
14
|
+
value?: number;
|
|
13
15
|
initialTab?: number;
|
|
14
16
|
tabBarSize?: number;
|
|
15
17
|
tabMode?: "start" | "justify";
|
|
@@ -3,6 +3,7 @@ declare const meta: {
|
|
|
3
3
|
title: string;
|
|
4
4
|
component: React.FC<{
|
|
5
5
|
tabs: {
|
|
6
|
+
id?: string | undefined;
|
|
6
7
|
label: string;
|
|
7
8
|
startTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
8
9
|
endTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
@@ -10,6 +11,7 @@ declare const meta: {
|
|
|
10
11
|
disabled?: boolean | undefined;
|
|
11
12
|
isLoading?: boolean | undefined;
|
|
12
13
|
}[];
|
|
14
|
+
value?: number | undefined;
|
|
13
15
|
initialTab?: number | undefined;
|
|
14
16
|
tabBarSize?: number | undefined;
|
|
15
17
|
tabMode?: "start" | "justify" | undefined;
|
|
@@ -37,6 +39,7 @@ declare const meta: {
|
|
|
37
39
|
};
|
|
38
40
|
decorators: ((Story: import("@storybook/types").PartialStoryFn<import("@storybook/react").ReactRenderer, {
|
|
39
41
|
tabs: {
|
|
42
|
+
id?: string | undefined;
|
|
40
43
|
label: string;
|
|
41
44
|
startTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
42
45
|
endTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
@@ -44,6 +47,7 @@ declare const meta: {
|
|
|
44
47
|
disabled?: boolean | undefined;
|
|
45
48
|
isLoading?: boolean | undefined;
|
|
46
49
|
}[];
|
|
50
|
+
value?: number | undefined;
|
|
47
51
|
initialTab?: number | undefined;
|
|
48
52
|
tabBarSize?: number | undefined;
|
|
49
53
|
tabMode?: "start" | "justify" | undefined;
|
|
@@ -144,3 +148,15 @@ export declare const Disabled: {
|
|
|
144
148
|
};
|
|
145
149
|
render: (args: {}) => import("react/jsx-runtime").JSX.Element;
|
|
146
150
|
};
|
|
151
|
+
export declare const Controller: {
|
|
152
|
+
args: {
|
|
153
|
+
initialTab: number;
|
|
154
|
+
value: number;
|
|
155
|
+
tabs: {
|
|
156
|
+
label: string;
|
|
157
|
+
content: import("react/jsx-runtime").JSX.Element;
|
|
158
|
+
}[];
|
|
159
|
+
enableAddTabButton: boolean;
|
|
160
|
+
};
|
|
161
|
+
render: (args: {}) => import("react/jsx-runtime").JSX.Element;
|
|
162
|
+
};
|
|
@@ -5,8 +5,8 @@ import "./Tabs.css";
|
|
|
5
5
|
import ActionButton from "../ActionButton/ActionButton";
|
|
6
6
|
import Icon from "../Icon/Icon";
|
|
7
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, }) => {
|
|
9
|
-
var _a;
|
|
8
|
+
const Tabs = ({ tabs = [], value, 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, }) => {
|
|
9
|
+
var _a, _b;
|
|
10
10
|
const [activeTab, setActiveTab] = useState(initialTab);
|
|
11
11
|
const [sliderStyle, setSliderStyle] = useState({
|
|
12
12
|
width: "0px",
|
|
@@ -14,6 +14,11 @@ const Tabs = ({ tabs = [], initialTab = 0, tabBarSize = 38, enableBorderLine = t
|
|
|
14
14
|
});
|
|
15
15
|
const tabRefs = useRef([]);
|
|
16
16
|
const isInitialMount = useRef(true);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (value !== undefined) {
|
|
19
|
+
setActiveTab(value);
|
|
20
|
+
}
|
|
21
|
+
}, [value]);
|
|
17
22
|
const updateSliderStyle = () => {
|
|
18
23
|
const activeTabElement = tabRefs.current[activeTab];
|
|
19
24
|
if (activeTabElement) {
|
|
@@ -72,6 +77,6 @@ const Tabs = ({ tabs = [], initialTab = 0, tabBarSize = 38, enableBorderLine = t
|
|
|
72
77
|
onTabChange === null || onTabChange === void 0 ? void 0 : onTabChange(index);
|
|
73
78
|
}, 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
79
|
"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 })] }));
|
|
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: _jsx("div", { children: (_a = tabs[activeTab]) === null || _a === void 0 ? void 0 : _a.content }, (_b = tabs[activeTab].label + tabs[activeTab].id) !== null && _b !== void 0 ? _b : Math.random()) })] }));
|
|
76
81
|
};
|
|
77
82
|
export default Tabs;
|
|
@@ -4,6 +4,7 @@ import { ChevronDownIcon, ArchiveBoxIcon } from "@heroicons/react/16/solid";
|
|
|
4
4
|
import ActionButton from "../ActionButton/ActionButton";
|
|
5
5
|
import Icon from "../Icon/Icon";
|
|
6
6
|
import { useArgs } from "@storybook/preview-api";
|
|
7
|
+
import { Button } from "@/index";
|
|
7
8
|
const meta = {
|
|
8
9
|
title: "Components/Tabs",
|
|
9
10
|
component: Tabs,
|
|
@@ -114,3 +115,26 @@ export const Disabled = {
|
|
|
114
115
|
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
|
},
|
|
116
117
|
};
|
|
118
|
+
export const Controller = {
|
|
119
|
+
args: {
|
|
120
|
+
initialTab: 1,
|
|
121
|
+
value: 0,
|
|
122
|
+
tabs,
|
|
123
|
+
enableAddTabButton: true,
|
|
124
|
+
},
|
|
125
|
+
render: (args) => {
|
|
126
|
+
const props = Object.assign({}, args);
|
|
127
|
+
const [, setArgs] = useArgs();
|
|
128
|
+
return (_jsxs("div", { className: "flex flex-col gap-4 w-[500px]", children: [_jsxs("div", { className: "flex flex-row gap-2", children: [_jsx(Button, { onClick: () => setArgs(Object.assign(Object.assign({}, props.tabs), { value: 0 })), children: "Set active tab 0" }), _jsx(Button, { onClick: () => setArgs(Object.assign(Object.assign({}, props.tabs), { value: 1 })), children: "Set active tab 1" }), _jsx(Button, { onClick: () => setArgs(Object.assign(Object.assign({}, props.tabs), { value: 2 })), children: "Set active tab 2" })] }), _jsx(Tabs, Object.assign({ tabs: tabs }, props, { tabMode: "start", onAddTab: () => {
|
|
129
|
+
setArgs({
|
|
130
|
+
tabs: [
|
|
131
|
+
...props.tabs,
|
|
132
|
+
{
|
|
133
|
+
label: "Tab" + (props.tabs.length + 1),
|
|
134
|
+
content: _jsxs("p", { children: ["Tab ", props.tabs.length + 1, " content"] }),
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
} }))] }));
|
|
139
|
+
},
|
|
140
|
+
};
|
|
@@ -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, onClickItem, onCheckedItem, defaultExpandAll = false, defaultCheckAll = false, hierarchicalCheck = false, showIcon = true, disabled, enableSeparatorLine = true, checkable = true, maxLevel, mode, autoDisabled = false, }) => {
|
|
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, mode = "checkbox", autoDisabled = false, }) => {
|
|
6
6
|
const [checkedState, setCheckedState] = useState({});
|
|
7
7
|
const [expandedState, setExpandedState] = useState({});
|
|
8
8
|
const traverseTree = (nodes, callback) => {
|