@rovula/ui 0.0.48 → 0.0.49
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.css +9 -0
- package/dist/cjs/bundle.js +3 -3
- package/dist/cjs/bundle.js.map +1 -1
- package/dist/cjs/types/components/Tree/Tree.d.ts +4 -45
- package/dist/cjs/types/components/Tree/Tree.stories.d.ts +8 -1
- package/dist/cjs/types/components/Tree/TreeItem.d.ts +4 -0
- package/dist/cjs/types/components/Tree/index.d.ts +4 -0
- package/dist/cjs/types/components/Tree/type.d.ts +76 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/components/Tree/Tree.js +15 -49
- package/dist/components/Tree/Tree.stories.js +117 -8
- package/dist/components/Tree/TreeItem.js +81 -0
- package/dist/components/Tree/index.js +4 -0
- package/dist/components/Tree/type.js +1 -0
- package/dist/esm/bundle.css +9 -0
- package/dist/esm/bundle.js +1 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/types/components/Tree/Tree.d.ts +4 -45
- package/dist/esm/types/components/Tree/Tree.stories.d.ts +8 -1
- package/dist/esm/types/components/Tree/TreeItem.d.ts +4 -0
- package/dist/esm/types/components/Tree/index.d.ts +4 -0
- package/dist/esm/types/components/Tree/type.d.ts +76 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/index.d.ts +82 -2
- package/dist/index.js +1 -0
- package/dist/src/theme/global.css +12 -0
- package/package.json +1 -1
- package/src/components/Tree/Tree.stories.tsx +230 -8
- package/src/components/Tree/Tree.tsx +44 -183
- package/src/components/Tree/TreeItem.tsx +231 -0
- package/src/components/Tree/index.ts +5 -0
- package/src/components/Tree/type.ts +90 -0
- package/src/index.ts +1 -0
|
@@ -1,45 +1,4 @@
|
|
|
1
|
-
import { FC
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
icon?: ReactNode;
|
|
6
|
-
children?: TreeData[];
|
|
7
|
-
};
|
|
8
|
-
export interface TreeItemProps extends TreeData {
|
|
9
|
-
isFirstLevel?: boolean;
|
|
10
|
-
isLastItem: boolean;
|
|
11
|
-
checkIsExpanded: (id: string) => boolean;
|
|
12
|
-
checkIsChecked: (id: string) => boolean;
|
|
13
|
-
onExpandChange?: (id: string, expanded: boolean) => void;
|
|
14
|
-
onCheckedChange?: (id: string, checked: boolean) => void;
|
|
15
|
-
}
|
|
16
|
-
export type TreeProps = {
|
|
17
|
-
data: TreeData[];
|
|
18
|
-
defaultExpandedId?: string[];
|
|
19
|
-
defaultCheckedId?: string[];
|
|
20
|
-
checkedId?: string[];
|
|
21
|
-
onCheckedChange?: (checkedId: string[]) => void;
|
|
22
|
-
defaultExpandAll?: boolean;
|
|
23
|
-
defaultCheckAll?: boolean;
|
|
24
|
-
hierarchicalCheck?: boolean;
|
|
25
|
-
};
|
|
26
|
-
export declare const Tree: FC<TreeProps>;
|
|
27
|
-
/**
|
|
28
|
-
* TODO
|
|
29
|
-
* -----
|
|
30
|
-
* - Custom style
|
|
31
|
-
* - Custom icon, elm and render props -> callback with selected*expanded
|
|
32
|
-
* - OnClick item
|
|
33
|
-
* - OnClick expandButton
|
|
34
|
-
* - disabled props
|
|
35
|
-
* - right section icon
|
|
36
|
-
* - props for show icon, line
|
|
37
|
-
* - props for render item
|
|
38
|
-
* - OnLoad mode
|
|
39
|
-
* -----
|
|
40
|
-
* - props onLoad item
|
|
41
|
-
* - props for hasChildren * for check to trigger on load
|
|
42
|
-
* - animate expand
|
|
43
|
-
* - check duplicate reversive on updateChildren
|
|
44
|
-
* - write storybook
|
|
45
|
-
*/
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { TreeProps } from "./type";
|
|
3
|
+
declare const Tree: FC<TreeProps>;
|
|
4
|
+
export default Tree;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
-
import
|
|
2
|
+
import Tree from "./Tree";
|
|
3
3
|
declare const meta: Meta<typeof Tree>;
|
|
4
4
|
export default meta;
|
|
5
5
|
export declare const Default: StoryObj<typeof Tree>;
|
|
6
|
+
export declare const onClick: StoryObj<typeof Tree>;
|
|
7
|
+
export declare const CustomIcon: StoryObj<typeof Tree>;
|
|
8
|
+
export declare const renderRightSection: StoryObj<typeof Tree>;
|
|
9
|
+
export declare const ControlShowExpandButton: StoryObj<typeof Tree>;
|
|
10
|
+
export declare const Diabled: StoryObj<typeof Tree>;
|
|
11
|
+
export declare const DiabledEachItem: StoryObj<typeof Tree>;
|
|
12
|
+
export declare const ExpandLoadData: StoryObj<typeof Tree>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CSSProperties, ReactNode } from "react";
|
|
2
|
+
export type TreeData = {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
icon?: ReactNode;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
onClickItem?: (id: string) => void;
|
|
8
|
+
children?: TreeData[];
|
|
9
|
+
renderIcon?: (params: {
|
|
10
|
+
id: string;
|
|
11
|
+
expanded: boolean;
|
|
12
|
+
selected: boolean;
|
|
13
|
+
}) => ReactNode;
|
|
14
|
+
};
|
|
15
|
+
export interface TreeItemProps extends TreeData {
|
|
16
|
+
isFirstLevel?: boolean;
|
|
17
|
+
isLastItem: boolean;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
showIcon?: boolean;
|
|
20
|
+
showExpandButton?: boolean;
|
|
21
|
+
enableSeparatorLine?: boolean;
|
|
22
|
+
checkIsExpanded: (id: string) => boolean;
|
|
23
|
+
checkIsChecked: (id: string) => boolean;
|
|
24
|
+
checkIsLoading?: (id: string) => void;
|
|
25
|
+
onExpandChange?: (id: string, expanded: boolean) => void;
|
|
26
|
+
onCheckedChange?: (id: string, checked: boolean) => void;
|
|
27
|
+
renderRightSection?: (params: {
|
|
28
|
+
id: string;
|
|
29
|
+
expanded: boolean;
|
|
30
|
+
selected: boolean;
|
|
31
|
+
}) => ReactNode;
|
|
32
|
+
renderElement?: (params: {
|
|
33
|
+
id: string;
|
|
34
|
+
expanded: boolean;
|
|
35
|
+
selected: boolean;
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
styles: {
|
|
38
|
+
branch: CSSProperties;
|
|
39
|
+
horizontalLine: CSSProperties;
|
|
40
|
+
expandButton: CSSProperties;
|
|
41
|
+
childPadding: CSSProperties;
|
|
42
|
+
};
|
|
43
|
+
onClick?: TreeItemProps["onClickItem"];
|
|
44
|
+
}) => ReactNode;
|
|
45
|
+
renderTitle?: (params: {
|
|
46
|
+
id: string;
|
|
47
|
+
title: string;
|
|
48
|
+
expanded: boolean;
|
|
49
|
+
selected: boolean;
|
|
50
|
+
}) => ReactNode;
|
|
51
|
+
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;
|
|
63
|
+
}>;
|
|
64
|
+
}
|
|
65
|
+
export interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRightSection" | "renderElement" | "renderTitle" | "showIcon" | "disabled" | "enableSeparatorLine" | "classes"> {
|
|
66
|
+
data: TreeData[];
|
|
67
|
+
defaultExpandedId?: string[];
|
|
68
|
+
defaultCheckedId?: string[];
|
|
69
|
+
checkedId?: string[];
|
|
70
|
+
loadingId?: string[];
|
|
71
|
+
onExpandChange?: (id: string, expanded: boolean) => void;
|
|
72
|
+
onCheckedChange?: (checkedId: string[]) => void;
|
|
73
|
+
defaultExpandAll?: boolean;
|
|
74
|
+
defaultCheckAll?: boolean;
|
|
75
|
+
hierarchicalCheck?: boolean;
|
|
76
|
+
}
|
|
@@ -32,6 +32,7 @@ export * from "./components/Tooltip/TooltipSimple";
|
|
|
32
32
|
export * from "./components/Toast/Toast";
|
|
33
33
|
export * from "./components/Toast/Toaster";
|
|
34
34
|
export * from "./components/Toast/useToast";
|
|
35
|
+
export * from "./components/Tree";
|
|
35
36
|
export type { ButtonProps } from "./components/Button/Button";
|
|
36
37
|
export type { InputProps } from "./components/TextInput/TextInput";
|
|
37
38
|
export type { DropdownProps, Options } from "./components/Dropdown/Dropdown";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import React__default, { ReactElement, ReactNode, FC, ComponentPropsWithoutRef } from 'react';
|
|
2
|
+
import React__default, { ReactElement, ReactNode, FC, ComponentPropsWithoutRef, CSSProperties } from 'react';
|
|
3
3
|
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
4
4
|
import * as class_variance_authority_dist_types from 'class-variance-authority/dist/types';
|
|
5
5
|
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
@@ -601,6 +601,86 @@ declare function useToast(options?: ToastOptions): {
|
|
|
601
601
|
position?: ToasterPosition;
|
|
602
602
|
};
|
|
603
603
|
|
|
604
|
+
type TreeData = {
|
|
605
|
+
id: string;
|
|
606
|
+
title: string;
|
|
607
|
+
icon?: ReactNode;
|
|
608
|
+
disabled?: boolean;
|
|
609
|
+
onClickItem?: (id: string) => void;
|
|
610
|
+
children?: TreeData[];
|
|
611
|
+
renderIcon?: (params: {
|
|
612
|
+
id: string;
|
|
613
|
+
expanded: boolean;
|
|
614
|
+
selected: boolean;
|
|
615
|
+
}) => ReactNode;
|
|
616
|
+
};
|
|
617
|
+
interface TreeItemProps extends TreeData {
|
|
618
|
+
isFirstLevel?: boolean;
|
|
619
|
+
isLastItem: boolean;
|
|
620
|
+
disabled?: boolean;
|
|
621
|
+
showIcon?: boolean;
|
|
622
|
+
showExpandButton?: boolean;
|
|
623
|
+
enableSeparatorLine?: boolean;
|
|
624
|
+
checkIsExpanded: (id: string) => boolean;
|
|
625
|
+
checkIsChecked: (id: string) => boolean;
|
|
626
|
+
checkIsLoading?: (id: string) => void;
|
|
627
|
+
onExpandChange?: (id: string, expanded: boolean) => void;
|
|
628
|
+
onCheckedChange?: (id: string, checked: boolean) => void;
|
|
629
|
+
renderRightSection?: (params: {
|
|
630
|
+
id: string;
|
|
631
|
+
expanded: boolean;
|
|
632
|
+
selected: boolean;
|
|
633
|
+
}) => ReactNode;
|
|
634
|
+
renderElement?: (params: {
|
|
635
|
+
id: string;
|
|
636
|
+
expanded: boolean;
|
|
637
|
+
selected: boolean;
|
|
638
|
+
children: ReactNode;
|
|
639
|
+
styles: {
|
|
640
|
+
branch: CSSProperties;
|
|
641
|
+
horizontalLine: CSSProperties;
|
|
642
|
+
expandButton: CSSProperties;
|
|
643
|
+
childPadding: CSSProperties;
|
|
644
|
+
};
|
|
645
|
+
onClick?: TreeItemProps["onClickItem"];
|
|
646
|
+
}) => ReactNode;
|
|
647
|
+
renderTitle?: (params: {
|
|
648
|
+
id: string;
|
|
649
|
+
title: string;
|
|
650
|
+
expanded: boolean;
|
|
651
|
+
selected: boolean;
|
|
652
|
+
}) => ReactNode;
|
|
653
|
+
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;
|
|
665
|
+
}>;
|
|
666
|
+
}
|
|
667
|
+
interface TreeProps extends Pick<TreeItemProps, "renderIcon" | "renderRightSection" | "renderElement" | "renderTitle" | "showIcon" | "disabled" | "enableSeparatorLine" | "classes"> {
|
|
668
|
+
data: TreeData[];
|
|
669
|
+
defaultExpandedId?: string[];
|
|
670
|
+
defaultCheckedId?: string[];
|
|
671
|
+
checkedId?: string[];
|
|
672
|
+
loadingId?: string[];
|
|
673
|
+
onExpandChange?: (id: string, expanded: boolean) => void;
|
|
674
|
+
onCheckedChange?: (checkedId: string[]) => void;
|
|
675
|
+
defaultExpandAll?: boolean;
|
|
676
|
+
defaultCheckAll?: boolean;
|
|
677
|
+
hierarchicalCheck?: boolean;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
declare const Tree: FC<TreeProps>;
|
|
681
|
+
|
|
682
|
+
declare const TreeItem: FC<TreeItemProps>;
|
|
683
|
+
|
|
604
684
|
declare const resloveTimestamp: (timestamp: number) => number;
|
|
605
685
|
declare const getStartDateOfDay: (date: Date) => Date;
|
|
606
686
|
declare const getEndDateOfDay: (date: Date) => Date;
|
|
@@ -612,4 +692,4 @@ declare const getTimestampUTC: (date: Date) => number;
|
|
|
612
692
|
|
|
613
693
|
declare function cn(...inputs: ClassValue[]): string;
|
|
614
694
|
|
|
615
|
-
export { ActionButton, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps, Button, type ButtonProps, Calendar, Checkbox, Collapsible, DataTable, type DataTableProps, DatePicker, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Dropdown, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, type DropdownProps, Icon, Input, InputFilter, type InputFilterProps, type InputProps, Label, Loading, Navbar, type NavbarProps, type Options$1 as Options, Popover, PopoverContent, PopoverTrigger, ProgressBar, Search, type SearchProps, Slider, type SliderProps, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, Text, TextInput, Toast$1 as Toast, ToastAction, type ToastActionElement, ToastClose, ToastDescription, type ToastProps, ToastProvider, ToastTitle, ToastViewport, Toaster, Tooltip, TooltipArrow, TooltipContent, TooltipProvider, TooltipSimple, TooltipTrigger, cn, getEndDateOfDay, getStartDateOfDay, getStartEndTimestampOfDay, getTimestampUTC, reducer, resloveTimestamp, toast, useToast };
|
|
695
|
+
export { ActionButton, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps, Button, type ButtonProps, Calendar, Checkbox, Collapsible, DataTable, type DataTableProps, DatePicker, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Dropdown, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, type DropdownProps, Icon, Input, InputFilter, type InputFilterProps, type InputProps, Label, Loading, Navbar, type NavbarProps, type Options$1 as Options, Popover, PopoverContent, PopoverTrigger, ProgressBar, Search, type SearchProps, Slider, type SliderProps, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, Text, TextInput, Toast$1 as Toast, ToastAction, type ToastActionElement, ToastClose, ToastDescription, type ToastProps, ToastProvider, ToastTitle, ToastViewport, Toaster, Tooltip, TooltipArrow, TooltipContent, TooltipProvider, TooltipSimple, TooltipTrigger, Tree, type TreeData, TreeItem, type TreeItemProps, type TreeProps, cn, getEndDateOfDay, getStartDateOfDay, getStartEndTimestampOfDay, getTimestampUTC, reducer, resloveTimestamp, toast, useToast };
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ export * from "./components/Tooltip/TooltipSimple";
|
|
|
34
34
|
export * from "./components/Toast/Toast";
|
|
35
35
|
export * from "./components/Toast/Toaster";
|
|
36
36
|
export * from "./components/Toast/useToast";
|
|
37
|
+
export * from "./components/Tree";
|
|
37
38
|
// UTILS
|
|
38
39
|
export { resloveTimestamp, getStartDateOfDay, getEndDateOfDay, getStartEndTimestampOfDay, getTimestampUTC, } from "./utils/datetime";
|
|
39
40
|
export { cn } from "./utils/cn";
|
|
@@ -3711,6 +3711,10 @@ input[type=number] {
|
|
|
3711
3711
|
height: 24px;
|
|
3712
3712
|
}
|
|
3713
3713
|
|
|
3714
|
+
.h-\[2px\] {
|
|
3715
|
+
height: 2px;
|
|
3716
|
+
}
|
|
3717
|
+
|
|
3714
3718
|
.h-\[32px\] {
|
|
3715
3719
|
height: 32px;
|
|
3716
3720
|
}
|
|
@@ -6104,6 +6108,10 @@ input[type=number] {
|
|
|
6104
6108
|
fill: color-mix(in srgb, var(--state-color-error-default) calc(100% * 1), transparent);
|
|
6105
6109
|
}
|
|
6106
6110
|
|
|
6111
|
+
.fill-info {
|
|
6112
|
+
fill: color-mix(in srgb, var(--state-color-info-default) calc(100% * 1), transparent);
|
|
6113
|
+
}
|
|
6114
|
+
|
|
6107
6115
|
.fill-inherit {
|
|
6108
6116
|
fill: inherit;
|
|
6109
6117
|
}
|
|
@@ -6128,6 +6136,10 @@ input[type=number] {
|
|
|
6128
6136
|
fill: color-mix(in srgb, var(--state-color-primary-default) calc(100% * 1), transparent);
|
|
6129
6137
|
}
|
|
6130
6138
|
|
|
6139
|
+
.fill-secondary {
|
|
6140
|
+
fill: color-mix(in srgb, var(--state-color-secondary-default) calc(100% * 1), transparent);
|
|
6141
|
+
}
|
|
6142
|
+
|
|
6131
6143
|
.fill-warning {
|
|
6132
6144
|
fill: color-mix(in srgb, var(--state-color-warning-default) calc(100% * 1), transparent);
|
|
6133
6145
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
|
-
import
|
|
3
|
+
import Tree from "./Tree";
|
|
4
|
+
import { ActionButton, Icon } from "@/index";
|
|
4
5
|
|
|
5
|
-
// Example data for testing the Tree component (as plain objects)
|
|
6
6
|
const exampleData = [
|
|
7
7
|
{
|
|
8
8
|
id: "1",
|
|
@@ -27,6 +27,16 @@ const exampleData = [
|
|
|
27
27
|
{ id: "3", title: "Parent Folder 3" },
|
|
28
28
|
];
|
|
29
29
|
|
|
30
|
+
const commonProps = {
|
|
31
|
+
defaultExpandedId: ["1", "1.1"],
|
|
32
|
+
defaultCheckedId: ["1.1"],
|
|
33
|
+
defaultExpandAll: true,
|
|
34
|
+
defaultCheckAll: true,
|
|
35
|
+
hierarchicalCheck: true,
|
|
36
|
+
disabled: false,
|
|
37
|
+
showIcon: true,
|
|
38
|
+
};
|
|
39
|
+
|
|
30
40
|
// Storybook metadata
|
|
31
41
|
const meta: Meta<typeof Tree> = {
|
|
32
42
|
title: "Components/Tree",
|
|
@@ -50,11 +60,25 @@ export default meta;
|
|
|
50
60
|
export const Default: StoryObj<typeof Tree> = {
|
|
51
61
|
args: {
|
|
52
62
|
data: exampleData,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
...commonProps,
|
|
64
|
+
showIcon: true,
|
|
65
|
+
},
|
|
66
|
+
render: (args) => {
|
|
67
|
+
return (
|
|
68
|
+
<div className="flex flex-row gap-4 w-full">
|
|
69
|
+
<Tree {...args} />
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const onClick: StoryObj<typeof Tree> = {
|
|
76
|
+
args: {
|
|
77
|
+
data: exampleData.map((item) => ({
|
|
78
|
+
...item,
|
|
79
|
+
onClickItem: (id: string) => alert("Click item " + id),
|
|
80
|
+
})),
|
|
81
|
+
...commonProps,
|
|
58
82
|
},
|
|
59
83
|
render: (args) => {
|
|
60
84
|
return (
|
|
@@ -64,3 +88,201 @@ export const Default: StoryObj<typeof Tree> = {
|
|
|
64
88
|
);
|
|
65
89
|
},
|
|
66
90
|
};
|
|
91
|
+
|
|
92
|
+
export const CustomIcon: StoryObj<typeof Tree> = {
|
|
93
|
+
args: {
|
|
94
|
+
data: exampleData.map((item, idx) => ({
|
|
95
|
+
...item,
|
|
96
|
+
...(idx === 0 && {
|
|
97
|
+
icon: <Icon name="home" />,
|
|
98
|
+
}),
|
|
99
|
+
...(idx === 1 && {
|
|
100
|
+
renderIcon: ({ expanded, selected }) => (
|
|
101
|
+
<Icon
|
|
102
|
+
name={expanded ? "home" : "home-modern"}
|
|
103
|
+
className={selected ? "fill-info" : "fill-error"}
|
|
104
|
+
/>
|
|
105
|
+
),
|
|
106
|
+
}),
|
|
107
|
+
})),
|
|
108
|
+
...commonProps,
|
|
109
|
+
},
|
|
110
|
+
render: (args) => {
|
|
111
|
+
return (
|
|
112
|
+
<div className="flex flex-row gap-4 w-full">
|
|
113
|
+
<Tree
|
|
114
|
+
{...args}
|
|
115
|
+
renderIcon={({ expanded, selected }) => (
|
|
116
|
+
<Icon
|
|
117
|
+
name={expanded ? "bell" : "bell-slash"}
|
|
118
|
+
className={selected ? "fill-primary" : "fill-secondary"}
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
121
|
+
/>
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const renderRightSection: StoryObj<typeof Tree> = {
|
|
128
|
+
args: {
|
|
129
|
+
data: exampleData,
|
|
130
|
+
...commonProps,
|
|
131
|
+
},
|
|
132
|
+
render: (args) => {
|
|
133
|
+
return (
|
|
134
|
+
<div className="flex flex-row gap-4 w-full">
|
|
135
|
+
<Tree
|
|
136
|
+
{...args}
|
|
137
|
+
renderRightSection={() => (
|
|
138
|
+
<ActionButton variant="icon" onClick={() => alert("Say hi!")}>
|
|
139
|
+
<Icon name="ellipsis-vertical" />
|
|
140
|
+
</ActionButton>
|
|
141
|
+
)}
|
|
142
|
+
/>
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const ControlShowExpandButton: StoryObj<typeof Tree> = {
|
|
149
|
+
args: {
|
|
150
|
+
data: exampleData.map((item) => ({
|
|
151
|
+
...item,
|
|
152
|
+
showExpandButton: true,
|
|
153
|
+
})),
|
|
154
|
+
},
|
|
155
|
+
render: (args) => {
|
|
156
|
+
return (
|
|
157
|
+
<div className="flex flex-row gap-4 w-full">
|
|
158
|
+
<Tree {...args} />
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const Diabled: StoryObj<typeof Tree> = {
|
|
165
|
+
args: {
|
|
166
|
+
data: exampleData,
|
|
167
|
+
...commonProps,
|
|
168
|
+
disabled: true,
|
|
169
|
+
},
|
|
170
|
+
render: (args) => {
|
|
171
|
+
return (
|
|
172
|
+
<div className="flex flex-row gap-4 w-full">
|
|
173
|
+
<Tree
|
|
174
|
+
{...args}
|
|
175
|
+
renderRightSection={() => (
|
|
176
|
+
<ActionButton variant="icon" onClick={() => alert("Say hi!")}>
|
|
177
|
+
<Icon name="ellipsis-vertical" />
|
|
178
|
+
</ActionButton>
|
|
179
|
+
)}
|
|
180
|
+
/>
|
|
181
|
+
</div>
|
|
182
|
+
);
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const DiabledEachItem: StoryObj<typeof Tree> = {
|
|
187
|
+
args: {
|
|
188
|
+
data: exampleData.map((item, i) => ({ ...item, disabled: i === 0 })),
|
|
189
|
+
...commonProps,
|
|
190
|
+
disabled: undefined,
|
|
191
|
+
},
|
|
192
|
+
render: (args) => {
|
|
193
|
+
return (
|
|
194
|
+
<div className="flex flex-row gap-4 w-full">
|
|
195
|
+
<Tree
|
|
196
|
+
{...args}
|
|
197
|
+
renderRightSection={() => (
|
|
198
|
+
<ActionButton variant="icon" onClick={() => alert("Say hi!")}>
|
|
199
|
+
<Icon name="ellipsis-vertical" />
|
|
200
|
+
</ActionButton>
|
|
201
|
+
)}
|
|
202
|
+
/>
|
|
203
|
+
</div>
|
|
204
|
+
);
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export const ExpandLoadData: StoryObj<typeof Tree> = {
|
|
209
|
+
args: {},
|
|
210
|
+
render: (args) => {
|
|
211
|
+
const [data, setData] = useState([
|
|
212
|
+
{
|
|
213
|
+
id: "1",
|
|
214
|
+
title: "Parent Folder 1",
|
|
215
|
+
showExpandButton: true,
|
|
216
|
+
children: [],
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: "2",
|
|
220
|
+
title: "Parent Folder 2",
|
|
221
|
+
showExpandButton: true,
|
|
222
|
+
children: [],
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
id: "3",
|
|
226
|
+
title: "Parent Folder 3",
|
|
227
|
+
showExpandButton: true,
|
|
228
|
+
children: [],
|
|
229
|
+
},
|
|
230
|
+
]);
|
|
231
|
+
const [loadingId, setLoadingId] = useState<string[]>([]);
|
|
232
|
+
const [loadedId, setLoadedId] = useState<string[]>([]);
|
|
233
|
+
|
|
234
|
+
const updateNode = (nodes: any[], id: string, newChildren: any[]): any[] =>
|
|
235
|
+
nodes.map((node) => {
|
|
236
|
+
if (node.id === id) {
|
|
237
|
+
return { ...node, children: newChildren };
|
|
238
|
+
}
|
|
239
|
+
if (node.children?.length) {
|
|
240
|
+
return {
|
|
241
|
+
...node,
|
|
242
|
+
children: updateNode(node.children, id, newChildren),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
return node;
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const handleOnExpandChange = (id: string, isExpand: boolean) => {
|
|
249
|
+
// *Note can you other way for improve should load if need with other way without loadedId
|
|
250
|
+
|
|
251
|
+
if (isExpand && !loadingId.includes(id) && !loadedId.includes(id)) {
|
|
252
|
+
setLoadingId((prev) => [...prev, id]);
|
|
253
|
+
setTimeout(() => {
|
|
254
|
+
// Mock child data
|
|
255
|
+
const newChildren = [
|
|
256
|
+
{
|
|
257
|
+
id: Date.now() + "1",
|
|
258
|
+
title: `Child of ${id} - 1`,
|
|
259
|
+
children: [],
|
|
260
|
+
showExpandButton: true,
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: Date.now() + "2",
|
|
264
|
+
title: `Child of ${id} - 2`,
|
|
265
|
+
children: [],
|
|
266
|
+
showExpandButton: true,
|
|
267
|
+
},
|
|
268
|
+
];
|
|
269
|
+
|
|
270
|
+
setData((prevData) => updateNode(prevData, id, newChildren));
|
|
271
|
+
setLoadingId((prev) => prev.filter((val) => val !== id));
|
|
272
|
+
setLoadedId((prev) => [...prev, id]);
|
|
273
|
+
}, 1500);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
return (
|
|
278
|
+
<div className="flex flex-row gap-4 w-full">
|
|
279
|
+
<Tree
|
|
280
|
+
{...args}
|
|
281
|
+
data={data}
|
|
282
|
+
loadingId={loadingId}
|
|
283
|
+
onExpandChange={handleOnExpandChange}
|
|
284
|
+
/>
|
|
285
|
+
</div>
|
|
286
|
+
);
|
|
287
|
+
},
|
|
288
|
+
};
|