@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.
@@ -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
+ };
@@ -91,6 +91,6 @@ export interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRig
91
91
  hierarchicalCheck?: boolean;
92
92
  checkable?: boolean;
93
93
  maxLevel?: number;
94
- mode: "checkbox" | "radio";
94
+ mode?: "checkbox" | "radio";
95
95
  autoDisabled?: boolean;
96
96
  }
package/dist/index.d.ts CHANGED
@@ -106,6 +106,7 @@ type TextProps = {
106
106
  declare const Text: React__default.ForwardRefExoticComponent<TextProps & React__default.RefAttributes<unknown>>;
107
107
 
108
108
  type Tab = {
109
+ id?: string;
109
110
  label: string;
110
111
  startTabContent?: React__default.ReactElement;
111
112
  endTabContent?: React__default.ReactElement;
@@ -115,6 +116,7 @@ type Tab = {
115
116
  };
116
117
  type TabsProps = {
117
118
  tabs: Tab[];
119
+ value?: number;
118
120
  initialTab?: number;
119
121
  tabBarSize?: number;
120
122
  tabMode?: "start" | "justify";
@@ -705,7 +707,7 @@ interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRightSecti
705
707
  hierarchicalCheck?: boolean;
706
708
  checkable?: boolean;
707
709
  maxLevel?: number;
708
- mode: "checkbox" | "radio";
710
+ mode?: "checkbox" | "radio";
709
711
  autoDisabled?: boolean;
710
712
  }
711
713
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rovula/ui",
3
- "version": "0.0.55",
3
+ "version": "0.0.57",
4
4
  "main": "dist/cjs/bundle.js",
5
5
  "module": "dist/esm/bundle.js",
6
6
  "types": "dist/index.d.ts",
@@ -5,6 +5,7 @@ import { ChevronDownIcon, ArchiveBoxIcon } from "@heroicons/react/16/solid";
5
5
  import ActionButton from "../ActionButton/ActionButton";
6
6
  import Icon from "../Icon/Icon";
7
7
  import { useArgs } from "@storybook/preview-api";
8
+ import { Button } from "@/index";
8
9
 
9
10
  const meta = {
10
11
  title: "Components/Tabs",
@@ -209,3 +210,50 @@ export const Disabled = {
209
210
  );
210
211
  },
211
212
  } satisfies StoryObj;
213
+
214
+ export const Controller = {
215
+ args: {
216
+ initialTab: 1,
217
+ value: 0,
218
+ tabs,
219
+ enableAddTabButton: true,
220
+ },
221
+ render: (args) => {
222
+ const props: any = {
223
+ ...args,
224
+ };
225
+
226
+ const [, setArgs] = useArgs();
227
+ return (
228
+ <div className="flex flex-col gap-4 w-[500px]">
229
+ <div className="flex flex-row gap-2">
230
+ <Button onClick={() => setArgs({ ...props.tabs, value: 0 })}>
231
+ Set active tab 0
232
+ </Button>
233
+ <Button onClick={() => setArgs({ ...props.tabs, value: 1 })}>
234
+ Set active tab 1
235
+ </Button>
236
+ <Button onClick={() => setArgs({ ...props.tabs, value: 2 })}>
237
+ Set active tab 2
238
+ </Button>
239
+ </div>
240
+ <Tabs
241
+ tabs={tabs}
242
+ {...props}
243
+ tabMode="start"
244
+ onAddTab={() => {
245
+ setArgs({
246
+ tabs: [
247
+ ...props.tabs,
248
+ {
249
+ label: "Tab" + (props.tabs.length + 1),
250
+ content: <p>Tab {props.tabs.length + 1} content</p>,
251
+ },
252
+ ],
253
+ });
254
+ }}
255
+ />
256
+ </div>
257
+ );
258
+ },
259
+ } satisfies StoryObj;
@@ -6,6 +6,7 @@ import Icon from "../Icon/Icon";
6
6
  import { Loading } from "@/index";
7
7
 
8
8
  type Tab = {
9
+ id?: string;
9
10
  label: string;
10
11
  startTabContent?: React.ReactElement;
11
12
  endTabContent?: React.ReactElement;
@@ -16,6 +17,7 @@ type Tab = {
16
17
 
17
18
  type TabsProps = {
18
19
  tabs: Tab[];
20
+ value?: number;
19
21
  initialTab?: number;
20
22
  tabBarSize?: number;
21
23
  tabMode?: "start" | "justify";
@@ -40,6 +42,7 @@ type TabsProps = {
40
42
 
41
43
  const Tabs: React.FC<TabsProps> = ({
42
44
  tabs = [],
45
+ value,
43
46
  initialTab = 0,
44
47
  tabBarSize = 38,
45
48
  enableBorderLine = true,
@@ -69,6 +72,12 @@ const Tabs: React.FC<TabsProps> = ({
69
72
  const tabRefs = useRef<(HTMLButtonElement | null)[]>([]);
70
73
  const isInitialMount = useRef(true);
71
74
 
75
+ useEffect(() => {
76
+ if (value !== undefined) {
77
+ setActiveTab(value);
78
+ }
79
+ }, [value]);
80
+
72
81
  const updateSliderStyle = () => {
73
82
  const activeTabElement = tabRefs.current[activeTab];
74
83
  if (activeTabElement) {
@@ -224,7 +233,9 @@ const Tabs: React.FC<TabsProps> = ({
224
233
  id={`tab-content-${activeTab}`}
225
234
  aria-labelledby={`tab-${activeTab}`}
226
235
  >
227
- {tabs[activeTab]?.content}
236
+ <div key={tabs[activeTab].label + tabs[activeTab].id ?? Math.random()}>
237
+ {tabs[activeTab]?.content}
238
+ </div>
228
239
  </div>
229
240
  </div>
230
241
  );
@@ -30,7 +30,7 @@ const Tree: FC<TreeProps> = ({
30
30
  enableSeparatorLine = true,
31
31
  checkable = true,
32
32
  maxLevel,
33
- mode,
33
+ mode = "checkbox",
34
34
  autoDisabled = false,
35
35
  }) => {
36
36
  const [checkedState, setCheckedState] = useState<Record<string, boolean>>({});
@@ -109,7 +109,7 @@ export interface TreeProps
109
109
  hierarchicalCheck?: boolean;
110
110
  checkable?: boolean;
111
111
  maxLevel?: number;
112
- mode: "checkbox" | "radio";
112
+ mode?: "checkbox" | "radio";
113
113
  // Only radio mode
114
114
  autoDisabled?: boolean;
115
115
  }