tharaday 0.5.11 → 0.6.1
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/components/List/List.d.ts +5 -0
- package/dist/components/List/List.stories.d.ts +25 -0
- package/dist/components/List/List.types.d.ts +42 -0
- package/dist/components/List/ListItem.d.ts +2 -0
- package/dist/components/List/ListItem.types.d.ts +9 -0
- package/dist/components/Slider/Slider.d.ts +1 -1
- package/dist/components/Slider/Slider.stories.d.ts +2 -1
- package/dist/components/Slider/Slider.types.d.ts +1 -0
- package/dist/components/Tree/Tree.d.ts +5 -0
- package/dist/components/Tree/Tree.stories.d.ts +20 -0
- package/dist/components/Tree/Tree.types.d.ts +14 -0
- package/dist/components/Tree/TreeItem.d.ts +2 -0
- package/dist/components/Tree/TreeItem.types.d.ts +15 -0
- package/dist/ds.css +1 -1
- package/dist/ds.js +1557 -1254
- package/dist/ds.umd.cjs +1 -1
- package/dist/index.d.ts +8 -0
- package/package.json +5 -5
- package/src/components/List/List.module.css +85 -0
- package/src/components/List/List.stories.tsx +92 -0
- package/src/components/List/List.tsx +93 -0
- package/src/components/List/List.types.ts +45 -0
- package/src/components/List/ListItem.module.css +12 -0
- package/src/components/List/ListItem.tsx +12 -0
- package/src/components/List/ListItem.types.ts +10 -0
- package/src/components/Slider/Slider.module.css +19 -0
- package/src/components/Slider/Slider.stories.tsx +19 -0
- package/src/components/Slider/Slider.tsx +101 -2
- package/src/components/Slider/Slider.types.ts +1 -0
- package/src/components/Tree/Tree.module.css +5 -0
- package/src/components/Tree/Tree.stories.tsx +113 -0
- package/src/components/Tree/Tree.tsx +27 -0
- package/src/components/Tree/Tree.types.ts +16 -0
- package/src/components/Tree/TreeItem.module.css +63 -0
- package/src/components/Tree/TreeItem.tsx +146 -0
- package/src/components/Tree/TreeItem.types.ts +16 -0
- package/src/index.ts +8 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import type { TreeItemProps } from './TreeItem.types';
|
|
4
|
+
import styles from './TreeItem.module.css';
|
|
5
|
+
|
|
6
|
+
export const TreeItem = ({
|
|
7
|
+
data,
|
|
8
|
+
label,
|
|
9
|
+
defaultExpanded,
|
|
10
|
+
expandIcon,
|
|
11
|
+
collapseIcon,
|
|
12
|
+
isRoot,
|
|
13
|
+
}: TreeItemProps) => {
|
|
14
|
+
const [isExpanded, setIsExpanded] = useState(isRoot ? true : (defaultExpanded ?? false));
|
|
15
|
+
|
|
16
|
+
const isObject = data !== null && typeof data === 'object';
|
|
17
|
+
const hasChildren =
|
|
18
|
+
isObject && (Array.isArray(data) ? data.length > 0 : Object.keys(data).length > 0);
|
|
19
|
+
|
|
20
|
+
const toggle = () => setIsExpanded(!isExpanded);
|
|
21
|
+
|
|
22
|
+
const defaultExpandIcon = (
|
|
23
|
+
<svg
|
|
24
|
+
width="10"
|
|
25
|
+
height="10"
|
|
26
|
+
viewBox="0 0 24 24"
|
|
27
|
+
fill="none"
|
|
28
|
+
stroke="currentColor"
|
|
29
|
+
strokeWidth="3"
|
|
30
|
+
strokeLinecap="round"
|
|
31
|
+
strokeLinejoin="round"
|
|
32
|
+
>
|
|
33
|
+
<polyline points="9 18 15 12 9 6" />
|
|
34
|
+
</svg>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const defaultCollapseIcon = (
|
|
38
|
+
<svg
|
|
39
|
+
width="10"
|
|
40
|
+
height="10"
|
|
41
|
+
viewBox="0 0 24 24"
|
|
42
|
+
fill="none"
|
|
43
|
+
stroke="currentColor"
|
|
44
|
+
strokeWidth="3"
|
|
45
|
+
strokeLinecap="round"
|
|
46
|
+
strokeLinejoin="round"
|
|
47
|
+
>
|
|
48
|
+
<polyline points="6 9 12 15 18 9" />
|
|
49
|
+
</svg>
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const renderContent = () => {
|
|
53
|
+
if (data === undefined) {
|
|
54
|
+
return <span className={styles.empty}>undefined</span>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (data === null) {
|
|
58
|
+
return <span className={styles.empty}>null</span>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (typeof data !== 'object') {
|
|
62
|
+
return <span className={styles.value}>{String(data)}</span>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (Array.isArray(data)) {
|
|
66
|
+
if (data.length === 0) {
|
|
67
|
+
return <span className={styles.empty}>[]</span>;
|
|
68
|
+
}
|
|
69
|
+
return (
|
|
70
|
+
<ul
|
|
71
|
+
className={clsx(
|
|
72
|
+
styles.list,
|
|
73
|
+
styles.collapsibleContent,
|
|
74
|
+
isExpanded && styles.expanded,
|
|
75
|
+
isRoot && styles.rootList
|
|
76
|
+
)}
|
|
77
|
+
>
|
|
78
|
+
{data.map((item, index) => (
|
|
79
|
+
<li key={index} className={styles.item}>
|
|
80
|
+
<TreeItem
|
|
81
|
+
data={item}
|
|
82
|
+
defaultExpanded={defaultExpanded}
|
|
83
|
+
expandIcon={expandIcon}
|
|
84
|
+
collapseIcon={collapseIcon}
|
|
85
|
+
/>
|
|
86
|
+
</li>
|
|
87
|
+
))}
|
|
88
|
+
</ul>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (Object.keys(data).length === 0) {
|
|
93
|
+
return <span className={styles.empty}>{}</span>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<ul
|
|
98
|
+
className={clsx(
|
|
99
|
+
styles.list,
|
|
100
|
+
styles.collapsibleContent,
|
|
101
|
+
isExpanded && styles.expanded,
|
|
102
|
+
isRoot && styles.rootList
|
|
103
|
+
)}
|
|
104
|
+
>
|
|
105
|
+
{Object.entries(data).map(([key, value]) => (
|
|
106
|
+
<li key={key} className={styles.item}>
|
|
107
|
+
<TreeItem
|
|
108
|
+
label={key}
|
|
109
|
+
data={value}
|
|
110
|
+
defaultExpanded={defaultExpanded}
|
|
111
|
+
expandIcon={expandIcon}
|
|
112
|
+
collapseIcon={collapseIcon}
|
|
113
|
+
/>
|
|
114
|
+
</li>
|
|
115
|
+
))}
|
|
116
|
+
</ul>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<div>
|
|
122
|
+
{!isRoot && (
|
|
123
|
+
<div className={styles.itemHeader}>
|
|
124
|
+
{hasChildren ? (
|
|
125
|
+
<button
|
|
126
|
+
type="button"
|
|
127
|
+
className={styles.toggleButton}
|
|
128
|
+
onClick={toggle}
|
|
129
|
+
aria-expanded={isExpanded}
|
|
130
|
+
>
|
|
131
|
+
{isExpanded
|
|
132
|
+
? (collapseIcon ?? defaultCollapseIcon)
|
|
133
|
+
: (expandIcon ?? defaultExpandIcon)}
|
|
134
|
+
</button>
|
|
135
|
+
) : (
|
|
136
|
+
<div className={styles.toggleButton} aria-hidden="true" />
|
|
137
|
+
)}
|
|
138
|
+
{label && <span className={styles.key}>{label}:</span>}
|
|
139
|
+
{!hasChildren && renderContent()}
|
|
140
|
+
</div>
|
|
141
|
+
)}
|
|
142
|
+
{hasChildren && renderContent()}
|
|
143
|
+
{isRoot && !hasChildren && <div className={styles.itemHeader}>{renderContent()}</div>}
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface TreeItemProps {
|
|
4
|
+
/** The data to be displayed in the tree item */
|
|
5
|
+
data: unknown;
|
|
6
|
+
/** Label for the tree item (e.g., object key) */
|
|
7
|
+
label?: string;
|
|
8
|
+
/** Whether the tree items should be expanded by default */
|
|
9
|
+
defaultExpanded?: boolean;
|
|
10
|
+
/** Custom icon for expanded state */
|
|
11
|
+
expandIcon?: ReactNode;
|
|
12
|
+
/** Custom icon for collapsed state */
|
|
13
|
+
collapseIcon?: ReactNode;
|
|
14
|
+
/** Whether the tree item is a root element */
|
|
15
|
+
isRoot?: boolean;
|
|
16
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -60,6 +60,10 @@ export { Input } from './components/Input/Input.tsx';
|
|
|
60
60
|
export type { InputProps } from './components/Input/Input.types.ts';
|
|
61
61
|
export { Loader } from './components/Loader/Loader.tsx';
|
|
62
62
|
export type { LoaderProps, LoaderSize } from './components/Loader/Loader.types.ts';
|
|
63
|
+
export { List } from './components/List/List.tsx';
|
|
64
|
+
export { ListItem } from './components/List/ListItem.tsx';
|
|
65
|
+
export type { ListProps, ListVariant } from './components/List/List.types.ts';
|
|
66
|
+
export type { ListItemProps } from './components/List/ListItem.types.ts';
|
|
63
67
|
export { Modal } from './components/Modal/Modal.tsx';
|
|
64
68
|
export type { ModalProps } from './components/Modal/Modal.types.ts';
|
|
65
69
|
export { Notification } from './components/Notification/Notification.tsx';
|
|
@@ -124,6 +128,10 @@ export { Textarea } from './components/Textarea/Textarea.tsx';
|
|
|
124
128
|
export type { TextareaProps, TextareaSize } from './components/Textarea/Textarea.types.ts';
|
|
125
129
|
export { Tooltip } from './components/Tooltip/Tooltip.tsx';
|
|
126
130
|
export type { TooltipProps, TooltipPosition } from './components/Tooltip/Tooltip.types.ts';
|
|
131
|
+
export { Tree } from './components/Tree/Tree.tsx';
|
|
132
|
+
export { TreeItem } from './components/Tree/TreeItem.tsx';
|
|
133
|
+
export type { TreeProps } from './components/Tree/Tree.types.ts';
|
|
134
|
+
export type { TreeItemProps } from './components/Tree/TreeItem.types.ts';
|
|
127
135
|
|
|
128
136
|
// layouts
|
|
129
137
|
export { AppLayout } from './layouts/AppLayout/AppLayout.tsx';
|