@ttoss/components 2.5.1 → 2.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/README.md +64 -0
- package/dist/JsonEditor/index.d.ts +0 -1
- package/dist/NavList/index.d.ts +55 -0
- package/dist/esm/Menu/index.js +2188 -16
- package/dist/esm/NavList/index.js +246 -0
- package/package.json +11 -7
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
import { Icon } from "../chunk-2R7AUPJL.js";
|
|
3
|
+
import { __name } from "../chunk-V4MHYKRI.js";
|
|
4
|
+
|
|
5
|
+
// src/components/NavList/NavList.tsx
|
|
6
|
+
import { Divider, Flex, Link, Text } from "@ttoss/ui";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
var getVariantStyles = /* @__PURE__ */__name(variant => {
|
|
9
|
+
switch (variant) {
|
|
10
|
+
case "sidebar":
|
|
11
|
+
return {
|
|
12
|
+
container: {
|
|
13
|
+
flexDirection: "column",
|
|
14
|
+
gap: "1",
|
|
15
|
+
width: "full"
|
|
16
|
+
},
|
|
17
|
+
item: {
|
|
18
|
+
backgroundColor: "transparent",
|
|
19
|
+
padding: "3",
|
|
20
|
+
borderRadius: "none",
|
|
21
|
+
fontSize: "md",
|
|
22
|
+
transition: "background-color 0.15s ease",
|
|
23
|
+
"&:hover": {
|
|
24
|
+
backgroundColor: "navigation.background.muted.hover",
|
|
25
|
+
textDecoration: "none"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
activeItem: {
|
|
29
|
+
backgroundColor: "navigation.background.muted.default",
|
|
30
|
+
borderLeft: "4px solid",
|
|
31
|
+
borderColor: "navigation.border.primary.default",
|
|
32
|
+
paddingLeft: "calc(0.75rem - 4px)"
|
|
33
|
+
},
|
|
34
|
+
icon: {
|
|
35
|
+
size: 20
|
|
36
|
+
},
|
|
37
|
+
groupLabel: {
|
|
38
|
+
fontSize: "xs",
|
|
39
|
+
fontWeight: "bold",
|
|
40
|
+
color: "navigation.text.muted.default",
|
|
41
|
+
textTransform: "uppercase",
|
|
42
|
+
marginBottom: "2",
|
|
43
|
+
marginTop: "4"
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
case "menu":
|
|
47
|
+
return {
|
|
48
|
+
container: {
|
|
49
|
+
flexDirection: "column",
|
|
50
|
+
gap: "1",
|
|
51
|
+
width: "full"
|
|
52
|
+
},
|
|
53
|
+
item: {
|
|
54
|
+
backgroundColor: "transparent",
|
|
55
|
+
borderRadius: "md",
|
|
56
|
+
padding: "2",
|
|
57
|
+
fontSize: "md",
|
|
58
|
+
transition: "all 0.2s ease",
|
|
59
|
+
"&:hover": {
|
|
60
|
+
backgroundColor: "navigation.background.muted.hover",
|
|
61
|
+
transform: "translateX(4px)",
|
|
62
|
+
textDecoration: "none"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
activeItem: {
|
|
66
|
+
backgroundColor: "navigation.background.muted.default",
|
|
67
|
+
fontWeight: "bold"
|
|
68
|
+
},
|
|
69
|
+
icon: {
|
|
70
|
+
size: 18
|
|
71
|
+
},
|
|
72
|
+
groupLabel: {
|
|
73
|
+
fontSize: "sm",
|
|
74
|
+
fontWeight: "semibold",
|
|
75
|
+
color: "display.text.secondary.default",
|
|
76
|
+
marginBottom: "2",
|
|
77
|
+
marginTop: "3"
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
case "dropdown":
|
|
81
|
+
return {
|
|
82
|
+
container: {
|
|
83
|
+
flexDirection: "column",
|
|
84
|
+
gap: "1",
|
|
85
|
+
width: "full"
|
|
86
|
+
},
|
|
87
|
+
item: {
|
|
88
|
+
backgroundColor: "transparent",
|
|
89
|
+
padding: "2",
|
|
90
|
+
fontSize: "sm",
|
|
91
|
+
borderBottom: "sm",
|
|
92
|
+
borderColor: "display.border.muted.default",
|
|
93
|
+
transition: "background-color 0.1s ease",
|
|
94
|
+
"&:hover": {
|
|
95
|
+
backgroundColor: "navigation.background.muted.hover",
|
|
96
|
+
textDecoration: "none"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
activeItem: {
|
|
100
|
+
backgroundColor: "navigation.background.muted.default",
|
|
101
|
+
fontWeight: "semibold"
|
|
102
|
+
},
|
|
103
|
+
icon: {
|
|
104
|
+
size: 16
|
|
105
|
+
},
|
|
106
|
+
groupLabel: {
|
|
107
|
+
fontSize: "xs",
|
|
108
|
+
fontWeight: "medium",
|
|
109
|
+
color: "display.text.secondary.default",
|
|
110
|
+
marginBottom: "1",
|
|
111
|
+
marginTop: "2",
|
|
112
|
+
paddingX: "2"
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
default:
|
|
116
|
+
return getVariantStyles("menu");
|
|
117
|
+
}
|
|
118
|
+
}, "getVariantStyles");
|
|
119
|
+
var NavListItemComponent = /* @__PURE__ */__name(({
|
|
120
|
+
item,
|
|
121
|
+
onItemClick,
|
|
122
|
+
variantStyles,
|
|
123
|
+
iconSize,
|
|
124
|
+
LinkComponent = Link,
|
|
125
|
+
showDivider = false
|
|
126
|
+
}) => {
|
|
127
|
+
const handleClick = /* @__PURE__ */__name(event => {
|
|
128
|
+
if (item.disabled) {
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
item.onClick?.(event);
|
|
133
|
+
onItemClick?.(item);
|
|
134
|
+
}, "handleClick");
|
|
135
|
+
const itemStyles = {
|
|
136
|
+
...variantStyles.item,
|
|
137
|
+
...(item.active ? variantStyles.activeItem : {}),
|
|
138
|
+
...(item.disabled ? {
|
|
139
|
+
opacity: 0.5,
|
|
140
|
+
cursor: "not-allowed",
|
|
141
|
+
pointerEvents: "none"
|
|
142
|
+
} : {})
|
|
143
|
+
};
|
|
144
|
+
const isDefaultLink = LinkComponent === Link;
|
|
145
|
+
const linkContent = /* @__PURE__ */React.createElement(Flex, {
|
|
146
|
+
sx: {
|
|
147
|
+
alignItems: "center",
|
|
148
|
+
gap: "2",
|
|
149
|
+
color: "navigation.text.primary.default"
|
|
150
|
+
}
|
|
151
|
+
}, item.icon && /* @__PURE__ */React.createElement(Icon, {
|
|
152
|
+
icon: item.icon,
|
|
153
|
+
width: iconSize ?? variantStyles.icon.size,
|
|
154
|
+
height: iconSize ?? variantStyles.icon.size
|
|
155
|
+
}), /* @__PURE__ */React.createElement(Text, null, item.label));
|
|
156
|
+
return /* @__PURE__ */React.createElement(React.Fragment, null, isDefaultLink ? /* @__PURE__ */React.createElement(LinkComponent, {
|
|
157
|
+
href: item.href,
|
|
158
|
+
onClick: handleClick,
|
|
159
|
+
sx: itemStyles,
|
|
160
|
+
"aria-disabled": item.disabled,
|
|
161
|
+
"aria-current": item.active ? "page" : void 0,
|
|
162
|
+
quiet: true
|
|
163
|
+
}, linkContent) : /* @__PURE__ */React.createElement(Link, {
|
|
164
|
+
as: LinkComponent,
|
|
165
|
+
href: item.href,
|
|
166
|
+
onClick: handleClick,
|
|
167
|
+
sx: itemStyles,
|
|
168
|
+
"aria-disabled": item.disabled,
|
|
169
|
+
"aria-current": item.active ? "page" : void 0,
|
|
170
|
+
quiet: true
|
|
171
|
+
}, linkContent), showDivider && /* @__PURE__ */React.createElement(Divider, {
|
|
172
|
+
sx: {
|
|
173
|
+
marginY: "2"
|
|
174
|
+
}
|
|
175
|
+
}));
|
|
176
|
+
}, "NavListItemComponent");
|
|
177
|
+
var NavList = /* @__PURE__ */__name(({
|
|
178
|
+
items = [],
|
|
179
|
+
groups = [],
|
|
180
|
+
variant = "menu",
|
|
181
|
+
onItemClick,
|
|
182
|
+
sx,
|
|
183
|
+
iconSize,
|
|
184
|
+
LinkComponent
|
|
185
|
+
}) => {
|
|
186
|
+
const variantStyles = getVariantStyles(variant);
|
|
187
|
+
const processedGroups = React.useMemo(() => {
|
|
188
|
+
if (groups.length > 0) {
|
|
189
|
+
return groups;
|
|
190
|
+
}
|
|
191
|
+
if (items.length > 0) {
|
|
192
|
+
const groupedItems = items.reduce((acc, item) => {
|
|
193
|
+
const groupKey = item.group || "__ungrouped__";
|
|
194
|
+
if (!acc[groupKey]) {
|
|
195
|
+
acc[groupKey] = [];
|
|
196
|
+
}
|
|
197
|
+
acc[groupKey].push(item);
|
|
198
|
+
return acc;
|
|
199
|
+
}, {});
|
|
200
|
+
return Object.entries(groupedItems).map(([key, groupItems]) => {
|
|
201
|
+
return {
|
|
202
|
+
id: key,
|
|
203
|
+
label: key === "__ungrouped__" ? void 0 : key,
|
|
204
|
+
items: groupItems,
|
|
205
|
+
divider: false
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return [];
|
|
210
|
+
}, [items, groups]);
|
|
211
|
+
return /* @__PURE__ */React.createElement(Flex, {
|
|
212
|
+
as: "nav",
|
|
213
|
+
sx: {
|
|
214
|
+
...variantStyles.container,
|
|
215
|
+
...sx
|
|
216
|
+
},
|
|
217
|
+
role: "navigation"
|
|
218
|
+
}, processedGroups.map((group, groupIndex) => {
|
|
219
|
+
return /* @__PURE__ */React.createElement(React.Fragment, {
|
|
220
|
+
key: group.id || `group-${groupIndex}`
|
|
221
|
+
}, group.label && /* @__PURE__ */React.createElement(Text, {
|
|
222
|
+
sx: variantStyles.groupLabel,
|
|
223
|
+
as: "div",
|
|
224
|
+
role: "heading"
|
|
225
|
+
}, group.label), /* @__PURE__ */React.createElement(Flex, {
|
|
226
|
+
sx: {
|
|
227
|
+
flexDirection: "column",
|
|
228
|
+
gap: variantStyles.container.gap
|
|
229
|
+
}
|
|
230
|
+
}, group.items.map((item, itemIndex) => {
|
|
231
|
+
const isLastItem = itemIndex === group.items.length - 1;
|
|
232
|
+
const showDivider = item.divider || isLastItem && group.divider;
|
|
233
|
+
return /* @__PURE__ */React.createElement(NavListItemComponent, {
|
|
234
|
+
key: item.id || `${group.id}-item-${itemIndex}`,
|
|
235
|
+
item,
|
|
236
|
+
onItemClick,
|
|
237
|
+
variantStyles,
|
|
238
|
+
iconSize,
|
|
239
|
+
LinkComponent,
|
|
240
|
+
showDivider
|
|
241
|
+
});
|
|
242
|
+
})));
|
|
243
|
+
}));
|
|
244
|
+
}, "NavList");
|
|
245
|
+
NavList.displayName = "NavList";
|
|
246
|
+
export { NavList };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/components",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "React components for ttoss ecosystem.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -54,6 +54,10 @@
|
|
|
54
54
|
"types": "./dist/Modal/index.d.ts",
|
|
55
55
|
"default": "./dist/esm/Modal/index.js"
|
|
56
56
|
},
|
|
57
|
+
"./NavList": {
|
|
58
|
+
"types": "./dist/NavList/index.d.ts",
|
|
59
|
+
"default": "./dist/esm/NavList/index.js"
|
|
60
|
+
},
|
|
57
61
|
"./NotificationCard": {
|
|
58
62
|
"types": "./dist/NotificationCard/index.d.ts",
|
|
59
63
|
"default": "./dist/esm/NotificationCard/index.js"
|
|
@@ -102,8 +106,8 @@
|
|
|
102
106
|
"peerDependencies": {
|
|
103
107
|
"react": ">=16.8.0",
|
|
104
108
|
"@ttoss/react-hooks": "^2.1.5",
|
|
105
|
-
"@ttoss/
|
|
106
|
-
"@ttoss/
|
|
109
|
+
"@ttoss/react-i18n": "^2.0.19",
|
|
110
|
+
"@ttoss/ui": "^5.10.4"
|
|
107
111
|
},
|
|
108
112
|
"devDependencies": {
|
|
109
113
|
"@types/jest": "^30.0.0",
|
|
@@ -112,13 +116,13 @@
|
|
|
112
116
|
"react": "^19.2.0",
|
|
113
117
|
"tsup": "^8.5.0",
|
|
114
118
|
"tsx": "^4.19.2",
|
|
119
|
+
"@ttoss/react-hooks": "^2.1.5",
|
|
115
120
|
"@ttoss/config": "^1.35.9",
|
|
116
121
|
"@ttoss/i18n-cli": "^0.7.35",
|
|
117
|
-
"@ttoss/react-
|
|
122
|
+
"@ttoss/react-icons": "^0.5.0",
|
|
118
123
|
"@ttoss/react-i18n": "^2.0.19",
|
|
119
|
-
"@ttoss/
|
|
120
|
-
"@ttoss/ui": "^5.10.
|
|
121
|
-
"@ttoss/test-utils": "^3.0.1"
|
|
124
|
+
"@ttoss/test-utils": "^3.0.1",
|
|
125
|
+
"@ttoss/ui": "^5.10.4"
|
|
122
126
|
},
|
|
123
127
|
"keywords": [
|
|
124
128
|
"React",
|