@attebyte/react-tree-select 1.0.0
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/LICENSE +674 -0
- package/README.md +120 -0
- package/dist/components/ExpandIcon.d.ts +15 -0
- package/dist/components/NodeCheck.d.ts +17 -0
- package/dist/components/NodeLabel.d.ts +22 -0
- package/dist/components/TreeNode.d.ts +31 -0
- package/dist/components/TreeSelect.d.ts +36 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.js +2688 -0
- package/dist/style.css +1 -0
- package/dist/utils/ClassUtility.d.ts +2 -0
- package/dist/utils/TreeUtility.d.ts +9 -0
- package/dist/utils/TreeUtility.test.d.ts +1 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# React Tree Select <img src="https://firebasestorage.googleapis.com/v0/b/attebyte-8542f.appspot.com/o/react-tree-select%2Freact.svg?alt=media&token=a2cf555d-d091-4b45-af56-6fc97062c66d" alt="React Icon" width="30" height="30" /> <img src="https://firebasestorage.googleapis.com/v0/b/attebyte-8542f.appspot.com/o/react-tree-select%2Ftailwind.svg?alt=media&token=7655c1f4-9525-4c53-acfa-07b4d95edb22" alt="React Icon" width="30" height="30" />
|
|
2
|
+
A simple, highly customizable tree component. <br/>
|
|
3
|
+
[View Full Documentation](https://rts.attebyte.io)
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
Install using the package manager of your choice.
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npm i @attebyte/react-tree-select
|
|
10
|
+
```
|
|
11
|
+
```
|
|
12
|
+
yarn add @attebyte/react-tree-select
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Getting Started
|
|
16
|
+
|
|
17
|
+
Simply pass your tree shaped data to TreeSelect along with the required properties.
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
import TreeSelect from '@attebyte/react-tree-select';
|
|
21
|
+
import '@attebyte/react-tree-select/dist/style.css';
|
|
22
|
+
|
|
23
|
+
function App() {
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
<TreeSelect
|
|
27
|
+
defaultData={ExampleData}
|
|
28
|
+
labelProperty={'label'}
|
|
29
|
+
valueProperty={'included'}
|
|
30
|
+
childrenProperty={'children'}
|
|
31
|
+
uniqueIDProperty={'value'}
|
|
32
|
+
|
|
33
|
+
/>
|
|
34
|
+
</>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default App
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
const ExampleData: ExampleNode[] = [
|
|
43
|
+
{
|
|
44
|
+
label: 'Root 1',
|
|
45
|
+
value: 1,
|
|
46
|
+
children: [
|
|
47
|
+
{
|
|
48
|
+
label: 'Child 1',
|
|
49
|
+
value: 2,
|
|
50
|
+
children: [
|
|
51
|
+
{
|
|
52
|
+
label: 'Grandchild 1',
|
|
53
|
+
value: 3,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
label: 'Grandchild 2',
|
|
57
|
+
value: 4,
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: 'Child 2',
|
|
63
|
+
value: 5,
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
label: 'Root 2',
|
|
69
|
+
value: 6,
|
|
70
|
+
children: [
|
|
71
|
+
{
|
|
72
|
+
label: 'Child 3',
|
|
73
|
+
value: 7,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
label: 'Child 4',
|
|
77
|
+
value: 8,
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
<img src="https://firebasestorage.googleapis.com/v0/b/attebyte-8542f.appspot.com/o/react-tree-select%2Ftree-select-example.gif?alt=media&token=0fb3fbaf-95b2-40d9-a065-be2e08515272" alt="Example GIF">
|
|
85
|
+
|
|
86
|
+
## Props
|
|
87
|
+
Commonly required props for most use cases. To see a full list of available properties, see our [full documentation](https://rts.attebyte.io/#api).
|
|
88
|
+
|
|
89
|
+
| Property | Type | Required? | Description |
|
|
90
|
+
| ----------- | ----------- | ----------- | ----------- |
|
|
91
|
+
| `data` | `T[]` | yes* | The data to be rendered, if controlled |
|
|
92
|
+
| `defaultData` | `T[]` | yes* | The data to be rendered, if uncontrolled |
|
|
93
|
+
| `uniqueIDProperty` | `keyof T` | yes | The property of your tree node that uniquely identifies the node |
|
|
94
|
+
| `labelProperty` | `keyof T` | yes | The property of your node to display |
|
|
95
|
+
| `childrenProperty` | `keyof T` | yes | The property of your node that holds the node's children |
|
|
96
|
+
| `valueProperty` | `keyof T` | yes* | Required if you intend to use the tree to select nodes. If using for display purposes only, not required |
|
|
97
|
+
| `onChange` | `(data: T[]) => void` | yes* | Required if you intend to use the the tree to select nodes. Called every time a node selection is changed with the updated tree
|
|
98
|
+
|
|
99
|
+
## Customization
|
|
100
|
+
This library is built with customization in mind and contains minimal default styles using tailwind. The library consists of 4 replacable parts:
|
|
101
|
+
- `TreeNode` - The container for an individual node
|
|
102
|
+
- `NodeLabel` - The label displyed within each node
|
|
103
|
+
- `NodeCheck` - The checkbox used to select a node or indicate descendent's selections
|
|
104
|
+
- `ExpandIcon` - Icon to indicate if a node has children or is collapsed / expanded
|
|
105
|
+
For additional information and examples of customization, please see our full documentation.
|
|
106
|
+
|
|
107
|
+
<br/>
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
<br/>
|
|
112
|
+
|
|
113
|
+
<a href="https://www.buymeacoffee.com/tristan10" target="_blank">
|
|
114
|
+
<picture>
|
|
115
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://firebasestorage.googleapis.com/v0/b/attebyte-8542f.appspot.com/o/react-tree-select%2Fbmc-logo-light.svg?alt=media&token=03a8ffd4-3e98-4c8e-9e7a-b8c200c92ed6">
|
|
116
|
+
<img style="color: white;" src="https://firebasestorage.googleapis.com/v0/b/attebyte-8542f.appspot.com/o/react-tree-select%2Fbmc-logo.svg?alt=media&token=357749a8-a191-46de-88f4-b7783517b806" alt="Buy Me A Coffee Logo" title="Buy Me A Coffee" height="40" />
|
|
117
|
+
</picture>
|
|
118
|
+
</a>
|
|
119
|
+
|
|
120
|
+
This is my first open source project and feedback is always appreciated. [Twitter](https://twitter.com/tristanattebery)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { VariantProps } from 'class-variance-authority';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { StandardComponentProps } from './TreeSelect';
|
|
4
|
+
interface Props<T> {
|
|
5
|
+
standardComponentProps: StandardComponentProps<T>;
|
|
6
|
+
expanded: boolean;
|
|
7
|
+
show: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const iconVariants: (props?: ({
|
|
10
|
+
rotated?: boolean | null | undefined;
|
|
11
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
12
|
+
export interface ExpandIconProps<T> extends React.HTMLAttributes<HTMLSpanElement>, VariantProps<typeof iconVariants>, Props<T> {
|
|
13
|
+
}
|
|
14
|
+
declare const _default: <T>(props: ExpandIconProps<T>) => import("react/jsx-runtime").JSX.Element | null;
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { VariantProps } from 'class-variance-authority';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { StandardComponentProps } from './TreeSelect';
|
|
4
|
+
interface Props<T> {
|
|
5
|
+
myRef?: React.RefObject<HTMLInputElement>;
|
|
6
|
+
standardComponentProps: StandardComponentProps<T>;
|
|
7
|
+
checked?: boolean | null;
|
|
8
|
+
expanded?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const checkVariants: (props?: ({
|
|
12
|
+
mixed?: boolean | null | undefined;
|
|
13
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
14
|
+
export interface NodeCheckProps<T> extends React.HTMLAttributes<HTMLInputElement>, VariantProps<typeof checkVariants>, Props<T> {
|
|
15
|
+
}
|
|
16
|
+
declare const _default: <T>(props: NodeCheckProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { VariantProps } from 'class-variance-authority';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ExpandIconProps } from './ExpandIcon';
|
|
4
|
+
import { StandardComponentProps } from './TreeSelect';
|
|
5
|
+
interface Props<T> {
|
|
6
|
+
standardComponentProps: StandardComponentProps<T>;
|
|
7
|
+
label: string;
|
|
8
|
+
hasChildren: boolean;
|
|
9
|
+
expanded?: boolean;
|
|
10
|
+
expandDisabledNodes?: boolean;
|
|
11
|
+
iconClassName?: string;
|
|
12
|
+
iconStyle?: React.CSSProperties;
|
|
13
|
+
ExpandIconComponent: React.ComponentType<ExpandIconProps<T>>;
|
|
14
|
+
}
|
|
15
|
+
declare const labelVariants: (props?: ({
|
|
16
|
+
disabled?: boolean | null | undefined;
|
|
17
|
+
expandEnabled?: boolean | null | undefined;
|
|
18
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
19
|
+
export interface NodeLabelProps<T> extends React.HTMLAttributes<HTMLSpanElement>, VariantProps<typeof labelVariants>, Props<T> {
|
|
20
|
+
}
|
|
21
|
+
declare const _default: <T>(props: NodeLabelProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export default _default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NodeCheckProps } from './NodeCheck';
|
|
3
|
+
import { NodeLabelProps } from './NodeLabel';
|
|
4
|
+
import { ExpandIconProps } from './ExpandIcon';
|
|
5
|
+
import { VariantProps } from 'class-variance-authority';
|
|
6
|
+
import { StandardComponentProps } from './TreeSelect';
|
|
7
|
+
interface Props<T> {
|
|
8
|
+
standardComponentProps: StandardComponentProps<T>;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
level?: number;
|
|
11
|
+
defaultExpanded?: boolean;
|
|
12
|
+
expandDisabledNodes?: boolean;
|
|
13
|
+
chainedSelect?: boolean;
|
|
14
|
+
labelClassName?: string;
|
|
15
|
+
labelStyle?: React.CSSProperties;
|
|
16
|
+
iconClassName?: string;
|
|
17
|
+
iconStyle?: React.CSSProperties;
|
|
18
|
+
inputClassName?: string;
|
|
19
|
+
inputStyle?: React.CSSProperties;
|
|
20
|
+
CheckComponent: React.ComponentType<NodeCheckProps<T>>;
|
|
21
|
+
LabelComponent: React.ComponentType<NodeLabelProps<T>>;
|
|
22
|
+
ExpandIconComponent: React.ComponentType<ExpandIconProps<T>>;
|
|
23
|
+
onChange: (node: T, value: boolean | null) => void;
|
|
24
|
+
}
|
|
25
|
+
declare const nodeVariants: (props?: ({
|
|
26
|
+
nested?: boolean | null | undefined;
|
|
27
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
28
|
+
export interface TreeNodeProps<T> extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>, VariantProps<typeof nodeVariants>, Props<T> {
|
|
29
|
+
}
|
|
30
|
+
declare const _default: <T>(props: TreeNodeProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export default _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TreeNodeProps } from './TreeNode';
|
|
3
|
+
import { NodeCheckProps } from './NodeCheck';
|
|
4
|
+
import { NodeLabelProps } from './NodeLabel';
|
|
5
|
+
import { ExpandIconProps } from './ExpandIcon';
|
|
6
|
+
export interface StandardComponentProps<T> {
|
|
7
|
+
node: T;
|
|
8
|
+
expanded?: boolean;
|
|
9
|
+
uniqueIDProperty: keyof T;
|
|
10
|
+
labelProperty: keyof T;
|
|
11
|
+
valueProperty?: keyof T;
|
|
12
|
+
childrenProperty: keyof T;
|
|
13
|
+
disabledProperty?: keyof T;
|
|
14
|
+
}
|
|
15
|
+
export interface TreeSelectProps<T> extends Omit<React.HTMLProps<HTMLDivElement>, "data" | "onChange">, Omit<StandardComponentProps<T>, "node" | "expanded"> {
|
|
16
|
+
data?: T[];
|
|
17
|
+
defaultData?: T[];
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
expandDisabledNodes?: boolean;
|
|
20
|
+
defaultExpanded?: boolean;
|
|
21
|
+
chainedSelect?: boolean;
|
|
22
|
+
nodeClassName?: string;
|
|
23
|
+
nodeStyle?: React.CSSProperties;
|
|
24
|
+
labelClassName?: string;
|
|
25
|
+
labelStyle?: React.CSSProperties;
|
|
26
|
+
iconClassName?: string;
|
|
27
|
+
iconStyle?: React.CSSProperties;
|
|
28
|
+
inputClassName?: string;
|
|
29
|
+
inputStyle?: React.CSSProperties;
|
|
30
|
+
CustomNodeComponent?: React.ComponentType<TreeNodeProps<T>>;
|
|
31
|
+
CustomCheckComponent?: React.ComponentType<NodeCheckProps<T>>;
|
|
32
|
+
CustomLabelComponent?: React.ComponentType<NodeLabelProps<T>>;
|
|
33
|
+
CustomExpandIconComponent?: React.ComponentType<ExpandIconProps<T>>;
|
|
34
|
+
onChange?: (data: T[]) => void;
|
|
35
|
+
}
|
|
36
|
+
export declare const TreeSelect: <T>(props: TreeSelectProps<T>) => import("react/jsx-runtime").JSX.Element;
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TreeSelect } from './components/TreeSelect';
|
|
2
|
+
export default TreeSelect;
|
|
3
|
+
export { default as NodeLabel } from './components/NodeLabel';
|
|
4
|
+
export { default as NodeCheck } from './components/NodeCheck';
|
|
5
|
+
export { default as ExpandIcon } from './components/ExpandIcon';
|
|
6
|
+
export { default as TreeNode } from './components/TreeNode';
|
|
7
|
+
export type { NodeLabelProps } from './components/NodeLabel';
|
|
8
|
+
export type { StandardComponentProps } from './components/TreeSelect';
|
|
9
|
+
export type { ExpandIconProps } from './components/ExpandIcon';
|
|
10
|
+
export type { NodeCheckProps } from './components/NodeCheck';
|
|
11
|
+
export type { TreeNodeProps } from './components/TreeNode';
|
|
12
|
+
export type { TreeSelectProps } from './components/TreeSelect';
|