@kopexa/sidebar 17.1.74 → 17.2.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.
@@ -0,0 +1,329 @@
1
+ "use client";
2
+ import {
3
+ panelItemHasChildren,
4
+ panelItemIsSection
5
+ } from "./chunk-SDMGFB6V.mjs";
6
+ import {
7
+ useSidebarV2
8
+ } from "./chunk-AIRHHM7Z.mjs";
9
+
10
+ // src/v2/components.tsx
11
+ import { IconButton } from "@kopexa/button";
12
+ import {
13
+ ChevronDownIcon,
14
+ ChevronRightIcon,
15
+ PanelLeftIcon
16
+ } from "@kopexa/icons";
17
+ import { cn } from "@kopexa/shared-utils";
18
+ import { sidebarMenuButton } from "@kopexa/theme";
19
+ import { Tooltip } from "@kopexa/tooltip";
20
+ import { forwardRef } from "react";
21
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
22
+ function SidebarV2Inset({
23
+ className,
24
+ ...props
25
+ }) {
26
+ const { styles } = useSidebarV2();
27
+ return /* @__PURE__ */ jsx(
28
+ "main",
29
+ {
30
+ "data-slot": "sidebar-v2-inset",
31
+ className: styles.inset({ className }),
32
+ ...props
33
+ }
34
+ );
35
+ }
36
+ function SidebarV2Rail({ className, ...props }) {
37
+ const { styles } = useSidebarV2();
38
+ return /* @__PURE__ */ jsx(
39
+ "nav",
40
+ {
41
+ "data-slot": "sidebar-v2-rail",
42
+ className: styles.rail({ className }),
43
+ ...props
44
+ }
45
+ );
46
+ }
47
+ function SidebarV2RailSpacer() {
48
+ return /* @__PURE__ */ jsx("div", { "aria-hidden": true, className: "flex-1" });
49
+ }
50
+ var SidebarV2Workspace = forwardRef(({ name, role, logo, className, appearance = "rail", ...props }, ref) => {
51
+ const { styles } = useSidebarV2();
52
+ if (appearance === "bar") {
53
+ return /* @__PURE__ */ jsxs(
54
+ "button",
55
+ {
56
+ ref,
57
+ type: "button",
58
+ "data-slot": "sidebar-v2-workspace",
59
+ "aria-label": role ? `${name} \u2013 ${role}` : name,
60
+ className: styles.workspaceBar({ className }),
61
+ ...props,
62
+ children: [
63
+ /* @__PURE__ */ jsx("span", { className: styles.workspaceBarLogo(), children: logo != null ? logo : name.charAt(0).toUpperCase() }),
64
+ /* @__PURE__ */ jsxs("span", { className: styles.workspaceBarText(), children: [
65
+ /* @__PURE__ */ jsx("span", { className: styles.workspaceBarName(), children: name }),
66
+ role && /* @__PURE__ */ jsx("span", { className: styles.workspaceBarRole(), children: role })
67
+ ] }),
68
+ /* @__PURE__ */ jsx(ChevronDownIcon, { className: styles.workspaceBarChevron() })
69
+ ]
70
+ }
71
+ );
72
+ }
73
+ return /* @__PURE__ */ jsx(
74
+ "button",
75
+ {
76
+ ref,
77
+ type: "button",
78
+ "data-slot": "sidebar-v2-workspace",
79
+ "aria-label": role ? `${name} \u2013 ${role}` : name,
80
+ className: styles.workspaceRail({ className }),
81
+ ...props,
82
+ children: /* @__PURE__ */ jsxs("span", { className: styles.workspaceRailLogo(), children: [
83
+ logo != null ? logo : name.charAt(0).toUpperCase(),
84
+ /* @__PURE__ */ jsx(ChevronDownIcon, { className: styles.workspaceRailChevron() })
85
+ ] })
86
+ }
87
+ );
88
+ });
89
+ SidebarV2Workspace.displayName = "SidebarV2Workspace";
90
+ function RailInner({
91
+ icon: Icon,
92
+ badge
93
+ }) {
94
+ const { styles } = useSidebarV2();
95
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
96
+ /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: styles.railIndicator() }),
97
+ /* @__PURE__ */ jsx(Icon, { className: styles.railIcon() }),
98
+ badge != null && /* @__PURE__ */ jsx("span", { className: styles.railBadge(), children: badge })
99
+ ] });
100
+ }
101
+ function SidebarV2RailLink({
102
+ icon,
103
+ label,
104
+ href,
105
+ badge
106
+ }) {
107
+ const { renderLink, isActive, resetPanelSelection, styles } = useSidebarV2();
108
+ const active = isActive(href);
109
+ return /* @__PURE__ */ jsx(Tooltip, { content: label, side: "right", children: renderLink({
110
+ href,
111
+ className: styles.railButton(),
112
+ "data-active": active,
113
+ "aria-current": active ? "page" : void 0,
114
+ "aria-label": label,
115
+ // Navigating to a destination link clears any open panel preview,
116
+ // even when the route doesn't change (e.g. already on it).
117
+ onClick: resetPanelSelection,
118
+ children: /* @__PURE__ */ jsx(RailInner, { icon, badge })
119
+ }) });
120
+ }
121
+ function SidebarV2RailItem({
122
+ icon,
123
+ label,
124
+ active,
125
+ hasPanel,
126
+ onClick,
127
+ onMouseEnter,
128
+ onMouseLeave,
129
+ badge
130
+ }) {
131
+ const { styles } = useSidebarV2();
132
+ return /* @__PURE__ */ jsx(Tooltip, { content: label, side: "right", children: /* @__PURE__ */ jsx(
133
+ "button",
134
+ {
135
+ type: "button",
136
+ "data-active": active,
137
+ "aria-label": label,
138
+ "aria-expanded": hasPanel ? active : void 0,
139
+ onClick,
140
+ onMouseEnter,
141
+ onMouseLeave,
142
+ className: styles.railButton(),
143
+ children: /* @__PURE__ */ jsx(RailInner, { icon, badge })
144
+ }
145
+ ) });
146
+ }
147
+ function SidebarV2Panel({
148
+ title,
149
+ subtitle,
150
+ floating,
151
+ hidePin,
152
+ action,
153
+ children,
154
+ className
155
+ }) {
156
+ const { togglePin, pinned, styles } = useSidebarV2();
157
+ return /* @__PURE__ */ jsxs(
158
+ "div",
159
+ {
160
+ "data-slot": "sidebar-v2-panel",
161
+ "data-floating": floating ? "true" : "false",
162
+ className: styles.panel({ className }),
163
+ children: [
164
+ /* @__PURE__ */ jsxs("div", { className: styles.panelHeader(), children: [
165
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
166
+ title && /* @__PURE__ */ jsx("div", { className: styles.panelTitle(), children: title }),
167
+ subtitle && /* @__PURE__ */ jsx("div", { className: styles.panelSubtitle(), children: subtitle })
168
+ ] }),
169
+ action != null ? action : !hidePin && /* @__PURE__ */ jsx(
170
+ Tooltip,
171
+ {
172
+ content: pinned ? "Panel l\xF6sen" : "Panel anheften",
173
+ side: "bottom",
174
+ children: /* @__PURE__ */ jsx(
175
+ IconButton,
176
+ {
177
+ variant: "ghost",
178
+ size: "sm",
179
+ "aria-label": pinned ? "Panel l\xF6sen" : "Panel anheften",
180
+ onClick: togglePin,
181
+ className: styles.panelPin(),
182
+ children: /* @__PURE__ */ jsx(PanelLeftIcon, { className: "size-4" })
183
+ }
184
+ )
185
+ }
186
+ )
187
+ ] }),
188
+ /* @__PURE__ */ jsx("div", { className: styles.panelBody(), children })
189
+ ]
190
+ }
191
+ );
192
+ }
193
+ function SidebarV2PanelLabel({
194
+ className,
195
+ ...props
196
+ }) {
197
+ const { styles } = useSidebarV2();
198
+ return /* @__PURE__ */ jsx(
199
+ "div",
200
+ {
201
+ "data-slot": "sidebar-v2-panel-label",
202
+ className: styles.panelLabel({ className }),
203
+ ...props
204
+ }
205
+ );
206
+ }
207
+ function SidebarV2PanelLeaf({
208
+ item,
209
+ active: activeProp
210
+ }) {
211
+ const { renderLink, isActive, tone, styles } = useSidebarV2();
212
+ const light = tone === "light";
213
+ const Icon = item.icon;
214
+ const active = activeProp != null ? activeProp : isActive(item.href);
215
+ return /* @__PURE__ */ jsx(Fragment, { children: renderLink({
216
+ href: item.href,
217
+ "data-active": active,
218
+ "aria-current": active ? "page" : void 0,
219
+ // Light tone uses the recipe's leaf slot (group/leaf + data-active);
220
+ // dark tone reuses the existing sidebarMenuButton recipe.
221
+ className: light ? styles.panelLeaf() : sidebarMenuButton({ size: "md" }),
222
+ children: /* @__PURE__ */ jsxs(Fragment, { children: [
223
+ Icon && /* @__PURE__ */ jsx(Icon, { className: styles.panelLeafIcon() }),
224
+ /* @__PURE__ */ jsx("span", { className: styles.panelLeafLabel(), children: item.label }),
225
+ item.badge != null && /* @__PURE__ */ jsx("span", { className: styles.panelLeafBadge(), children: item.badge })
226
+ ] })
227
+ }) });
228
+ }
229
+ function SidebarV2PanelGroup({
230
+ item
231
+ }) {
232
+ var _a;
233
+ const { openGroup, toggleGroup, activeHref, renderLink, tone, styles } = useSidebarV2();
234
+ const light = tone === "light";
235
+ const Icon = item.icon;
236
+ const key = (_a = item.value) != null ? _a : item.label;
237
+ let bestChildHref = null;
238
+ let bestLen = -1;
239
+ for (const c of item.children) {
240
+ if (activeHref === c.href) {
241
+ bestChildHref = c.href;
242
+ break;
243
+ }
244
+ if (activeHref.startsWith(`${c.href}/`) && c.href.length > bestLen) {
245
+ bestChildHref = c.href;
246
+ bestLen = c.href.length;
247
+ }
248
+ }
249
+ const containsActive = bestChildHref !== null;
250
+ const open = openGroup === key || openGroup === null && containsActive;
251
+ return /* @__PURE__ */ jsxs("div", { children: [
252
+ /* @__PURE__ */ jsxs(
253
+ "button",
254
+ {
255
+ type: "button",
256
+ "data-state": open ? "open" : "closed",
257
+ "data-contains-active": containsActive,
258
+ "aria-expanded": open,
259
+ onClick: () => toggleGroup(key),
260
+ className: cn(
261
+ light ? styles.panelLeaf() : sidebarMenuButton({ size: "md" }),
262
+ styles.panelGroupButton()
263
+ ),
264
+ children: [
265
+ Icon && /* @__PURE__ */ jsx(Icon, { className: styles.panelGroupIcon() }),
266
+ /* @__PURE__ */ jsx("span", { className: styles.panelGroupLabel(), children: item.label }),
267
+ /* @__PURE__ */ jsx(ChevronRightIcon, { className: styles.panelGroupChevron() })
268
+ ]
269
+ }
270
+ ),
271
+ open && /* @__PURE__ */ jsx("div", { className: styles.panelTree(), children: item.children.map((child) => {
272
+ const active = child.href === bestChildHref;
273
+ return /* @__PURE__ */ jsx("span", { children: renderLink({
274
+ href: child.href,
275
+ "data-active": active,
276
+ "aria-current": active ? "page" : void 0,
277
+ className: styles.subItem(),
278
+ children: child.label
279
+ }) }, child.href);
280
+ }) })
281
+ ] });
282
+ }
283
+ function SidebarV2PanelItems({
284
+ items
285
+ }) {
286
+ return /* @__PURE__ */ jsx(Fragment, { children: items.map((item, idx) => {
287
+ var _a;
288
+ if (panelItemIsSection(item)) {
289
+ return /* @__PURE__ */ jsx(SidebarV2PanelLabel, { children: item.section }, `section-${item.section}-${idx}`);
290
+ }
291
+ if (panelItemHasChildren(item)) {
292
+ return /* @__PURE__ */ jsx(SidebarV2PanelGroup, { item }, (_a = item.value) != null ? _a : item.label);
293
+ }
294
+ return /* @__PURE__ */ jsx(SidebarV2PanelLeaf, { item }, item.href);
295
+ }) });
296
+ }
297
+ function SidebarV2Trigger({
298
+ className,
299
+ ...props
300
+ }) {
301
+ const { setDrawerOpen, drawerOpen } = useSidebarV2();
302
+ return /* @__PURE__ */ jsx(
303
+ IconButton,
304
+ {
305
+ variant: "ghost",
306
+ size: "md",
307
+ "aria-label": "Navigation \xF6ffnen",
308
+ onClick: () => setDrawerOpen(!drawerOpen),
309
+ className,
310
+ ...props,
311
+ children: /* @__PURE__ */ jsx(PanelLeftIcon, { className: "size-5" })
312
+ }
313
+ );
314
+ }
315
+
316
+ export {
317
+ SidebarV2Inset,
318
+ SidebarV2Rail,
319
+ SidebarV2RailSpacer,
320
+ SidebarV2Workspace,
321
+ SidebarV2RailLink,
322
+ SidebarV2RailItem,
323
+ SidebarV2Panel,
324
+ SidebarV2PanelLabel,
325
+ SidebarV2PanelLeaf,
326
+ SidebarV2PanelGroup,
327
+ SidebarV2PanelItems,
328
+ SidebarV2Trigger
329
+ };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,10 @@
1
1
  export { Sidebar, SidebarContent, SidebarContentProps, SidebarFooter, SidebarFooterProps, SidebarGroup, SidebarGroupAction, SidebarGroupActionProps, SidebarGroupContent, SidebarGroupContentProps, SidebarGroupLabel, SidebarGroupLabelProps, SidebarGroupProps, SidebarHeader, SidebarHeaderProps, SidebarInput, SidebarInputProps, SidebarInset, SidebarInsetProps, SidebarMenu, SidebarMenuAction, SidebarMenuActionProps, SidebarMenuButton, SidebarMenuButtonProps, SidebarMenuItem, SidebarMenuItemProps, SidebarMenuProps, SidebarProps, SidebarProvider, SidebarProviderProps, SidebarRail, SidebarRailProps, SidebarRoot, SidebarSeparator, SidebarSeparatorProps, SidebarTrigger, SidebarTriggerProps, useSidebar } from './sidebar.mjs';
2
+ export { SidebarV2 } from './v2/index.mjs';
3
+ export { AppShell, AppShellAside, AppShellHeader, AppShellMain, AppShellPanelContent, AppShellPanelContentProps, AppShellRoot } from './v2/app-shell.mjs';
4
+ export { SidebarV2ContextValue, SidebarV2Provider, SidebarV2ProviderProps, SidebarV2Tone, useSidebarV2 } from './v2/context.mjs';
5
+ export { SidebarV2FromConfig, SidebarV2FromConfigProps } from './v2/from-config.mjs';
6
+ export { SidebarV2Icon, SidebarV2LinkProps, SidebarV2Nav, SidebarV2PanelItem, SidebarV2RailEntry, SidebarV2SubItem } from './v2/types.mjs';
7
+ export { SidebarV2Inset, SidebarV2Panel, SidebarV2PanelGroup, SidebarV2PanelItems, SidebarV2PanelLabel, SidebarV2PanelLeaf, SidebarV2Rail, SidebarV2RailItem, SidebarV2RailLink, SidebarV2RailSpacer, SidebarV2Trigger, SidebarV2Workspace } from './v2/components.mjs';
2
8
  import 'react/jsx-runtime';
3
9
  import '@kopexa/button';
4
10
  import '@kopexa/input';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,10 @@
1
1
  export { Sidebar, SidebarContent, SidebarContentProps, SidebarFooter, SidebarFooterProps, SidebarGroup, SidebarGroupAction, SidebarGroupActionProps, SidebarGroupContent, SidebarGroupContentProps, SidebarGroupLabel, SidebarGroupLabelProps, SidebarGroupProps, SidebarHeader, SidebarHeaderProps, SidebarInput, SidebarInputProps, SidebarInset, SidebarInsetProps, SidebarMenu, SidebarMenuAction, SidebarMenuActionProps, SidebarMenuButton, SidebarMenuButtonProps, SidebarMenuItem, SidebarMenuItemProps, SidebarMenuProps, SidebarProps, SidebarProvider, SidebarProviderProps, SidebarRail, SidebarRailProps, SidebarRoot, SidebarSeparator, SidebarSeparatorProps, SidebarTrigger, SidebarTriggerProps, useSidebar } from './sidebar.js';
2
+ export { SidebarV2 } from './v2/index.js';
3
+ export { AppShell, AppShellAside, AppShellHeader, AppShellMain, AppShellPanelContent, AppShellPanelContentProps, AppShellRoot } from './v2/app-shell.js';
4
+ export { SidebarV2ContextValue, SidebarV2Provider, SidebarV2ProviderProps, SidebarV2Tone, useSidebarV2 } from './v2/context.js';
5
+ export { SidebarV2FromConfig, SidebarV2FromConfigProps } from './v2/from-config.js';
6
+ export { SidebarV2Icon, SidebarV2LinkProps, SidebarV2Nav, SidebarV2PanelItem, SidebarV2RailEntry, SidebarV2SubItem } from './v2/types.js';
7
+ export { SidebarV2Inset, SidebarV2Panel, SidebarV2PanelGroup, SidebarV2PanelItems, SidebarV2PanelLabel, SidebarV2PanelLeaf, SidebarV2Rail, SidebarV2RailItem, SidebarV2RailLink, SidebarV2RailSpacer, SidebarV2Trigger, SidebarV2Workspace } from './v2/components.js';
2
8
  import 'react/jsx-runtime';
3
9
  import '@kopexa/button';
4
10
  import '@kopexa/input';