@rovula/ui 0.0.56 → 0.0.58

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;
@@ -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;
@@ -38,6 +39,7 @@ declare const meta: {
38
39
  };
39
40
  decorators: ((Story: import("@storybook/types").PartialStoryFn<import("@storybook/react").ReactRenderer, {
40
41
  tabs: {
42
+ id?: string | undefined;
41
43
  label: string;
42
44
  startTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
43
45
  endTabContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
@@ -83,7 +83,7 @@ export interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRig
83
83
  checkedId?: string[];
84
84
  loadingId?: string[];
85
85
  onExpandChange?: (id: string, expanded: boolean) => void;
86
- onCheckedChange?: (checkedState: Record<string, boolean>) => void;
86
+ onCheckedChange?: (checkedState: Record<string, boolean>, id?: string) => void;
87
87
  onClickItem?: (id: string) => void;
88
88
  onCheckedItem?: (id: string, checked: boolean) => void;
89
89
  defaultExpandAll?: boolean;
@@ -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;
@@ -698,7 +699,7 @@ interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRightSecti
698
699
  checkedId?: string[];
699
700
  loadingId?: string[];
700
701
  onExpandChange?: (id: string, expanded: boolean) => void;
701
- onCheckedChange?: (checkedState: Record<string, boolean>) => void;
702
+ onCheckedChange?: (checkedState: Record<string, boolean>, id?: string) => void;
702
703
  onClickItem?: (id: string) => void;
703
704
  onCheckedItem?: (id: string, checked: boolean) => void;
704
705
  defaultExpandAll?: boolean;
@@ -706,7 +707,7 @@ interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRightSecti
706
707
  hierarchicalCheck?: boolean;
707
708
  checkable?: boolean;
708
709
  maxLevel?: number;
709
- mode: "checkbox" | "radio";
710
+ mode?: "checkbox" | "radio";
710
711
  autoDisabled?: boolean;
711
712
  }
712
713
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rovula/ui",
3
- "version": "0.0.56",
3
+ "version": "0.0.58",
4
4
  "main": "dist/cjs/bundle.js",
5
5
  "module": "dist/esm/bundle.js",
6
6
  "types": "dist/index.d.ts",
@@ -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;
@@ -232,7 +233,9 @@ const Tabs: React.FC<TabsProps> = ({
232
233
  id={`tab-content-${activeTab}`}
233
234
  aria-labelledby={`tab-${activeTab}`}
234
235
  >
235
- {tabs[activeTab]?.content}
236
+ <div key={tabs[activeTab].label + tabs[activeTab].id}>
237
+ {tabs[activeTab]?.content}
238
+ </div>
236
239
  </div>
237
240
  </div>
238
241
  );
@@ -335,6 +335,7 @@ export const ExpandLoadData: StoryObj<typeof Tree> = {
335
335
  {...args}
336
336
  data={data}
337
337
  loadingId={loadingId}
338
+ hierarchicalCheck
338
339
  onExpandChange={handleOnExpandChange}
339
340
  />
340
341
  </div>
@@ -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>>({});
@@ -93,6 +93,37 @@ const Tree: FC<TreeProps> = ({
93
93
  }
94
94
  }, [checkedId]);
95
95
 
96
+ useEffect(() => {
97
+ if (!hierarchicalCheck) {
98
+ return;
99
+ }
100
+
101
+ const state: Record<string, boolean> = {};
102
+ const updateChildren = (parentId: string, isChecked: boolean) => {
103
+ traverseTree(data, (node) => {
104
+ if (node.id === parentId && node.children) {
105
+ node.children.forEach((child) => {
106
+ state[child.id] = isChecked;
107
+ updateChildren(child.id, isChecked);
108
+ });
109
+ }
110
+ });
111
+ };
112
+
113
+ setCheckedState((prev) => {
114
+ Object.keys(prev)
115
+ .filter((key) => prev[key])
116
+ .map((id) => {
117
+ updateChildren(id, true);
118
+ });
119
+
120
+ return {
121
+ ...prev,
122
+ ...state,
123
+ };
124
+ });
125
+ }, [data, hierarchicalCheck]);
126
+
96
127
  const handleExpandChange = useCallback(
97
128
  (id: string, expanded: boolean) => {
98
129
  onExpandChange?.(id, expanded);
@@ -108,7 +139,7 @@ const Tree: FC<TreeProps> = ({
108
139
 
109
140
  onCheckedItem?.(id, checked);
110
141
  setCheckedState(newState);
111
- onCheckedChange?.(newState);
142
+ onCheckedChange?.(newState, id);
112
143
 
113
144
  return;
114
145
  }
@@ -163,7 +194,7 @@ const Tree: FC<TreeProps> = ({
163
194
  setCheckedState(newState);
164
195
 
165
196
  if (onCheckedChange) {
166
- onCheckedChange?.(newState);
197
+ onCheckedChange?.(newState, id);
167
198
  }
168
199
  },
169
200
  [
@@ -254,7 +254,7 @@ const TreeItem: FC<TreeItemProps> = ({
254
254
  {isExpanded && hasChildren && currentLevel < (maxLevel || Infinity) && (
255
255
  <div
256
256
  className={cn(
257
- "flex flex-row overflow-hidden max-h-screen",
257
+ "flex flex-row overflow-hidden",
258
258
  classes?.expandedChildrenWrapper
259
259
  )}
260
260
  >
@@ -269,7 +269,7 @@ const TreeItem: FC<TreeItemProps> = ({
269
269
  )}
270
270
  <div
271
271
  className={cn(
272
- "flex flex-col overflow-hidden max-h-screen",
272
+ "flex flex-col overflow-hidden",
273
273
  classes?.expandedChildrenWrapperInner
274
274
  )}
275
275
  style={styles.childPadding}
@@ -101,7 +101,10 @@ export interface TreeProps
101
101
  checkedId?: string[];
102
102
  loadingId?: string[];
103
103
  onExpandChange?: (id: string, expanded: boolean) => void;
104
- onCheckedChange?: (checkedState: Record<string, boolean>) => void;
104
+ onCheckedChange?: (
105
+ checkedState: Record<string, boolean>,
106
+ id?: string
107
+ ) => void;
105
108
  onClickItem?: (id: string) => void;
106
109
  onCheckedItem?: (id: string, checked: boolean) => void;
107
110
  defaultExpandAll?: boolean;
@@ -109,7 +112,7 @@ export interface TreeProps
109
112
  hierarchicalCheck?: boolean;
110
113
  checkable?: boolean;
111
114
  maxLevel?: number;
112
- mode: "checkbox" | "radio";
115
+ mode?: "checkbox" | "radio";
113
116
  // Only radio mode
114
117
  autoDisabled?: boolean;
115
118
  }