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