@rovula/ui 0.0.50 → 0.0.51

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.
@@ -19,6 +19,10 @@ export interface TreeItemProps extends TreeData {
19
19
  showIcon?: boolean;
20
20
  showExpandButton?: boolean;
21
21
  enableSeparatorLine?: boolean;
22
+ lineSize?: number;
23
+ horizontalLineWidth?: number;
24
+ expandButtonSize?: number;
25
+ spacing?: number;
22
26
  checkIsExpanded: (id: string) => boolean;
23
27
  checkIsChecked: (id: string) => boolean;
24
28
  checkIsLoading?: (id: string) => void;
@@ -49,20 +53,23 @@ export interface TreeItemProps extends TreeData {
49
53
  selected: boolean;
50
54
  }) => ReactNode;
51
55
  classes?: Partial<{
52
- elementWrapper: string;
53
- branch: string;
54
- itemWrapper: string;
55
- itemContainer: string;
56
- horizontalLine: string;
57
- expandButton: string;
58
- separatorLine: string;
59
- checkbox: string;
60
- item: string;
61
- title: string;
62
- childrenWrapper: string;
56
+ elementWrapper?: string;
57
+ branch?: string;
58
+ itemWrapper?: string;
59
+ itemContainer?: string;
60
+ horizontalLine?: string;
61
+ expandButton?: string;
62
+ separatorLine?: string;
63
+ checkbox?: string;
64
+ item?: string;
65
+ title?: string;
66
+ expandedChildrenWrapper?: string;
67
+ expandedChildrenWrapperInner?: string;
68
+ rowWrapperClasses?: string;
69
+ columnWrapperClasses?: string;
63
70
  }>;
64
71
  }
65
- export interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRightSection" | "renderElement" | "renderTitle" | "showIcon" | "disabled" | "enableSeparatorLine" | "classes"> {
72
+ export interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRightSection" | "renderElement" | "renderTitle" | "showIcon" | "disabled" | "enableSeparatorLine" | "classes" | "lineSize" | "horizontalLineWidth" | "expandButtonSize" | "spacing"> {
66
73
  data: TreeData[];
67
74
  defaultExpandedId?: string[];
68
75
  defaultCheckedId?: string[];
package/dist/index.d.ts CHANGED
@@ -621,6 +621,10 @@ interface TreeItemProps extends TreeData {
621
621
  showIcon?: boolean;
622
622
  showExpandButton?: boolean;
623
623
  enableSeparatorLine?: boolean;
624
+ lineSize?: number;
625
+ horizontalLineWidth?: number;
626
+ expandButtonSize?: number;
627
+ spacing?: number;
624
628
  checkIsExpanded: (id: string) => boolean;
625
629
  checkIsChecked: (id: string) => boolean;
626
630
  checkIsLoading?: (id: string) => void;
@@ -651,20 +655,23 @@ interface TreeItemProps extends TreeData {
651
655
  selected: boolean;
652
656
  }) => ReactNode;
653
657
  classes?: Partial<{
654
- elementWrapper: string;
655
- branch: string;
656
- itemWrapper: string;
657
- itemContainer: string;
658
- horizontalLine: string;
659
- expandButton: string;
660
- separatorLine: string;
661
- checkbox: string;
662
- item: string;
663
- title: string;
664
- childrenWrapper: string;
658
+ elementWrapper?: string;
659
+ branch?: string;
660
+ itemWrapper?: string;
661
+ itemContainer?: string;
662
+ horizontalLine?: string;
663
+ expandButton?: string;
664
+ separatorLine?: string;
665
+ checkbox?: string;
666
+ item?: string;
667
+ title?: string;
668
+ expandedChildrenWrapper?: string;
669
+ expandedChildrenWrapperInner?: string;
670
+ rowWrapperClasses?: string;
671
+ columnWrapperClasses?: string;
665
672
  }>;
666
673
  }
667
- interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRightSection" | "renderElement" | "renderTitle" | "showIcon" | "disabled" | "enableSeparatorLine" | "classes"> {
674
+ interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRightSection" | "renderElement" | "renderTitle" | "showIcon" | "disabled" | "enableSeparatorLine" | "classes" | "lineSize" | "horizontalLineWidth" | "expandButtonSize" | "spacing"> {
668
675
  data: TreeData[];
669
676
  defaultExpandedId?: string[];
670
677
  defaultCheckedId?: string[];
@@ -3667,6 +3667,10 @@ input[type=number] {
3667
3667
  height: 100%;
3668
3668
  }
3669
3669
 
3670
+ .h-1\/2 {
3671
+ height: 50%;
3672
+ }
3673
+
3670
3674
  .h-10 {
3671
3675
  height: 2.5rem;
3672
3676
  }
@@ -3812,6 +3816,10 @@ input[type=number] {
3812
3816
  width: 24px;
3813
3817
  }
3814
3818
 
3819
+ .w-\[2px\] {
3820
+ width: 2px;
3821
+ }
3822
+
3815
3823
  .w-\[32px\] {
3816
3824
  width: 32px;
3817
3825
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rovula/ui",
3
- "version": "0.0.50",
3
+ "version": "0.0.51",
4
4
  "main": "dist/cjs/bundle.js",
5
5
  "module": "dist/esm/bundle.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,6 +9,10 @@ const Tree: FC<TreeProps> = ({
9
9
  defaultCheckedId,
10
10
  checkedId,
11
11
  loadingId,
12
+ lineSize,
13
+ horizontalLineWidth,
14
+ expandButtonSize,
15
+ spacing,
12
16
  renderIcon,
13
17
  renderRightSection,
14
18
  renderElement,
@@ -185,6 +189,10 @@ const Tree: FC<TreeProps> = ({
185
189
  enableSeparatorLine={enableSeparatorLine}
186
190
  disabled={disabled}
187
191
  showIcon={showIcon}
192
+ lineSize={lineSize}
193
+ horizontalLineWidth={horizontalLineWidth}
194
+ expandButtonSize={expandButtonSize}
195
+ spacing={spacing}
188
196
  {...item}
189
197
  />
190
198
  ))}
@@ -26,6 +26,10 @@ const TreeItem: FC<TreeItemProps> = ({
26
26
  renderElement,
27
27
  renderTitle,
28
28
  renderRightSection,
29
+ lineSize = 2,
30
+ horizontalLineWidth = 4,
31
+ expandButtonSize = 30,
32
+ spacing = 2,
29
33
  }) => {
30
34
  const isLoading = useMemo(() => checkIsLoading?.(id), [checkIsLoading, id]);
31
35
  const isChecked = useMemo(() => checkIsChecked(id), [checkIsChecked, id]);
@@ -40,41 +44,41 @@ const TreeItem: FC<TreeItemProps> = ({
40
44
  onExpandChange?.(id, !isExpanded);
41
45
  }, [id, isExpanded, onExpandChange]);
42
46
 
43
- // TODO move to props
44
- const lineSize = 2;
45
- const horizontalLineWidth = 4;
46
- const expandButtonSize = 30;
47
- const spacing = 2;
48
-
49
- const styles = {
50
- branch: {
51
- height:
52
- isLastItem && !(isExpanded && hasChildren)
53
- ? `calc(50% + ${lineSize}px)`
54
- : `calc(100% + ${lineSize}px)`,
55
- width: lineSize,
56
- marginTop: -lineSize,
57
- borderBottomLeftRadius: lineSize / 2,
58
- },
59
- horizontalLine: {
60
- height: lineSize,
61
- width:
62
- lineSize +
63
- horizontalLineWidth +
64
- (shouldExpandButton ? 0 : expandButtonSize + spacing),
65
- marginLeft: -lineSize + 0.1,
66
- borderBottomLeftRadius: lineSize / 2,
67
- },
68
- expandButton: {
69
- width: expandButtonSize,
70
- height: expandButtonSize,
71
- },
72
- childPadding: {
73
- paddingLeft: isFirstLevel
74
- ? expandButtonSize / 2 - lineSize / 2
75
- : expandButtonSize / 2 + horizontalLineWidth - lineSize / 2,
76
- },
77
- };
47
+ const styles = useMemo(
48
+ () => ({
49
+ branch: {
50
+ width: lineSize,
51
+ borderBottomLeftRadius: isLastItem ? lineSize / 2 : 0,
52
+ },
53
+ horizontalLine: {
54
+ height: lineSize,
55
+ width:
56
+ lineSize +
57
+ horizontalLineWidth +
58
+ (shouldExpandButton ? 0 : expandButtonSize + spacing),
59
+ marginLeft: -lineSize,
60
+ borderBottomLeftRadius: lineSize / 2,
61
+ },
62
+ expandButton: {
63
+ width: expandButtonSize,
64
+ height: expandButtonSize,
65
+ },
66
+ childPadding: {
67
+ paddingLeft: isFirstLevel
68
+ ? expandButtonSize / 2 - lineSize / 2
69
+ : expandButtonSize / 2 + horizontalLineWidth - lineSize / 2,
70
+ },
71
+ }),
72
+ [
73
+ lineSize,
74
+ horizontalLineWidth,
75
+ expandButtonSize,
76
+ spacing,
77
+ isFirstLevel,
78
+ isLastItem,
79
+ shouldExpandButton,
80
+ ]
81
+ );
78
82
 
79
83
  useEffect(() => {
80
84
  if (isExpanded && !isLoading && !hasChildren) {
@@ -124,96 +128,148 @@ const TreeItem: FC<TreeItemProps> = ({
124
128
  : content;
125
129
 
126
130
  return elementWrapper(
127
- <div className={cn("flex flex-row w-full ", classes?.elementWrapper)}>
128
- <div
129
- className={cn("bg-grey-150", classes?.branch)}
130
- style={styles.branch}
131
- />
131
+ <div className={cn("flex flex-row w-full", classes?.elementWrapper)}>
132
132
  <div className={cn("flex flex-col w-full", classes?.itemWrapper)}>
133
- <div
134
- className={cn(
135
- "flex items-center py-2 min-h-10",
136
- classes?.itemContainer
137
- )}
138
- >
139
- {!isFirstLevel && (
140
- <div
141
- className={cn("bg-grey-150", classes?.horizontalLine)}
142
- style={styles.horizontalLine}
143
- />
144
- )}
145
- {isFirstLevel && !shouldExpandButton && (
146
- <div
147
- className={cn("flex mr-[2px]", classes?.expandButton)}
148
- style={styles.expandButton}
149
- />
150
- )}
151
- {shouldExpandButton && (
152
- <div
153
- className={cn("flex mr-[2px]", classes?.expandButton)}
154
- style={styles.expandButton}
155
- onClick={!isLoading && handleExpandToggle}
156
- >
157
- <ActionButton variant="icon" size="sm">
158
- {isLoading ? (
159
- <Loading />
160
- ) : (
161
- <Icon name={isExpanded ? "chevron-down" : "chevron-right"} />
133
+ <div className={cn("flex flex-row flex-1", classes?.rowWrapperClasses)}>
134
+ <div
135
+ className={cn(
136
+ "flex flex-col h-full",
137
+ classes?.columnWrapperClasses
138
+ )}
139
+ >
140
+ {!isFirstLevel && (
141
+ <div
142
+ className={cn(
143
+ "flex w-[2px] h-1/2 bg-grey-150",
144
+ classes?.branch
162
145
  )}
163
- </ActionButton>
164
- </div>
165
- )}
166
- <Checkbox
167
- id={id}
168
- className={cn("size-[16pt]", classes?.checkbox)}
169
- checked={isChecked}
170
- disabled={disabled}
171
- onCheckedChange={(newChecked) =>
172
- onCheckedChange?.(id, newChecked as boolean)
173
- }
174
- />
146
+ style={styles.branch}
147
+ />
148
+ )}
149
+ {!isFirstLevel &&
150
+ !isLastItem &&
151
+ ((isExpanded && (hasChildren || isLoading)) || !isExpanded) && (
152
+ <div
153
+ className={cn(
154
+ "flex w-[2px] h-1/2 bg-grey-150",
155
+ classes?.branch
156
+ )}
157
+ style={styles.branch}
158
+ />
159
+ )}
160
+ </div>
161
+
175
162
  <div
176
163
  className={cn(
177
- "ml-2 gap-1 flex flex-1 items-center text-foreground",
178
- classes?.item
164
+ "flex flex-1 items-center py-2 min-h-10",
165
+ classes?.itemContainer
179
166
  )}
180
- onClick={handleOnClickItem}
181
167
  >
182
- {showIcon ? customIcon || defaultIcon : null}
168
+ {!isFirstLevel && (
169
+ <div
170
+ className={cn("bg-grey-150", classes?.horizontalLine)}
171
+ style={styles.horizontalLine}
172
+ />
173
+ )}
174
+ {isFirstLevel && !shouldExpandButton && (
175
+ <div
176
+ className={cn("flex mr-[2px]", classes?.expandButton)}
177
+ style={styles.expandButton}
178
+ />
179
+ )}
180
+ {shouldExpandButton && (
181
+ <div
182
+ className={cn("flex mr-[2px]", classes?.expandButton)}
183
+ style={styles.expandButton}
184
+ onClick={!isLoading && handleExpandToggle}
185
+ >
186
+ <ActionButton variant="icon" size="sm">
187
+ {isLoading ? (
188
+ <Loading />
189
+ ) : (
190
+ <Icon
191
+ name={isExpanded ? "chevron-down" : "chevron-right"}
192
+ />
193
+ )}
194
+ </ActionButton>
195
+ </div>
196
+ )}
197
+ <Checkbox
198
+ id={id}
199
+ className={cn("size-[16pt]", classes?.checkbox)}
200
+ checked={isChecked}
201
+ disabled={disabled}
202
+ onCheckedChange={(newChecked) =>
203
+ onCheckedChange?.(id, newChecked as boolean)
204
+ }
205
+ />
183
206
  <div
184
207
  className={cn(
185
- "flex flex-1 cursor-pointer text-subtitle5 text-ellipsis",
186
- classes?.title
208
+ "ml-2 gap-1 flex flex-1 items-center text-foreground",
209
+ classes?.item
187
210
  )}
211
+ onClick={handleOnClickItem}
188
212
  >
189
- {titleContent}
213
+ {showIcon ? customIcon || defaultIcon : null}
214
+ <div
215
+ className={cn(
216
+ "flex flex-1 cursor-pointer text-subtitle5 text-ellipsis",
217
+ classes?.title
218
+ )}
219
+ >
220
+ {titleContent}
221
+ </div>
190
222
  </div>
223
+ {rightIcon}
191
224
  </div>
192
- {rightIcon}
193
225
  </div>
226
+
194
227
  {isExpanded && hasChildren && (
195
228
  <div
196
- className={cn("flex flex-col", classes?.childrenWrapper)}
197
- style={styles.childPadding}
229
+ className={cn(
230
+ "flex flex-row overflow-hidden max-h-screen",
231
+ classes?.expandedChildrenWrapper
232
+ )}
198
233
  >
199
- {children?.map((child, idx) => (
200
- <TreeItem
201
- key={child.id}
202
- classes={classes}
203
- isLastItem={idx === children.length - 1}
204
- checkIsExpanded={checkIsExpanded}
205
- checkIsChecked={checkIsChecked}
206
- checkIsLoading={checkIsLoading}
207
- onExpandChange={onExpandChange}
208
- onCheckedChange={onCheckedChange}
209
- renderIcon={renderIcon}
210
- renderElement={renderElement}
211
- renderTitle={renderTitle}
212
- disabled={disabled}
213
- showIcon={showIcon}
214
- {...child}
234
+ {!isFirstLevel && !isLastItem && (
235
+ <div
236
+ className={cn(
237
+ "flex w-[2px] h-full bg-grey-150",
238
+ classes?.branch
239
+ )}
240
+ style={styles.branch}
215
241
  />
216
- ))}
242
+ )}
243
+ <div
244
+ className={cn(
245
+ "flex flex-col overflow-hidden max-h-screen",
246
+ classes?.expandedChildrenWrapperInner
247
+ )}
248
+ style={styles.childPadding}
249
+ >
250
+ {children?.map((child, idx) => (
251
+ <TreeItem
252
+ key={child.id}
253
+ classes={classes}
254
+ isLastItem={idx === children.length - 1}
255
+ checkIsExpanded={checkIsExpanded}
256
+ checkIsChecked={checkIsChecked}
257
+ checkIsLoading={checkIsLoading}
258
+ onExpandChange={onExpandChange}
259
+ onCheckedChange={onCheckedChange}
260
+ renderIcon={renderIcon}
261
+ renderElement={renderElement}
262
+ renderTitle={renderTitle}
263
+ disabled={disabled}
264
+ showIcon={showIcon}
265
+ lineSize={lineSize}
266
+ horizontalLineWidth={horizontalLineWidth}
267
+ expandButtonSize={expandButtonSize}
268
+ spacing={spacing}
269
+ {...child}
270
+ />
271
+ ))}
272
+ </div>
217
273
  </div>
218
274
  )}
219
275
  {enableSeparatorLine && isFirstLevel && !isLastItem && (
@@ -21,6 +21,10 @@ export interface TreeItemProps extends TreeData {
21
21
  showIcon?: boolean;
22
22
  showExpandButton?: boolean;
23
23
  enableSeparatorLine?: boolean;
24
+ lineSize?: number;
25
+ horizontalLineWidth?: number;
26
+ expandButtonSize?: number;
27
+ spacing?: number;
24
28
  checkIsExpanded: (id: string) => boolean;
25
29
  checkIsChecked: (id: string) => boolean;
26
30
  checkIsLoading?: (id: string) => void;
@@ -51,17 +55,20 @@ export interface TreeItemProps extends TreeData {
51
55
  selected: boolean;
52
56
  }) => ReactNode;
53
57
  classes?: Partial<{
54
- elementWrapper: string;
55
- branch: string;
56
- itemWrapper: string;
57
- itemContainer: string;
58
- horizontalLine: string;
59
- expandButton: string;
60
- separatorLine: string;
61
- checkbox: string;
62
- item: string;
63
- title: string;
64
- childrenWrapper: string;
58
+ elementWrapper?: string;
59
+ branch?: string;
60
+ itemWrapper?: string;
61
+ itemContainer?: string;
62
+ horizontalLine?: string;
63
+ expandButton?: string;
64
+ separatorLine?: string;
65
+ checkbox?: string;
66
+ item?: string;
67
+ title?: string;
68
+ expandedChildrenWrapper?: string;
69
+ expandedChildrenWrapperInner?: string;
70
+ rowWrapperClasses?: string;
71
+ columnWrapperClasses?: string;
65
72
  }>;
66
73
  }
67
74
 
@@ -76,6 +83,10 @@ export interface TreeProps
76
83
  | "disabled"
77
84
  | "enableSeparatorLine"
78
85
  | "classes"
86
+ | "lineSize"
87
+ | "horizontalLineWidth"
88
+ | "expandButtonSize"
89
+ | "spacing"
79
90
  > {
80
91
  data: TreeData[];
81
92
  defaultExpandedId?: string[];