@sybilion/uilib 1.4.13 → 1.4.15

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.
Files changed (136) hide show
  1. package/dist/agent-glossary/content-prompt.generated.ts +28 -23
  2. package/dist/agent-glossary/content.generated.ts +28 -23
  3. package/dist/agent-glossary/content.index.md +1 -1
  4. package/dist/agent-glossary/content.md +28 -23
  5. package/dist/agent-glossary/content.prompt.md +28 -23
  6. package/dist/agent-glossary/workspace.generated.ts +1 -1
  7. package/dist/agent-glossary/workspace.index.md +1 -1
  8. package/dist/agent-glossary/workspace.md +1 -1
  9. package/dist/esm/components/ui/Chat/ChatChrome/ChatChrome.js +28 -3
  10. package/dist/esm/components/ui/Chat/ChatSheet/useChatPanelChromeModel.js +31 -1
  11. package/dist/esm/components/ui/DropdownMenu/DropdownMenu.styl.js +2 -2
  12. package/dist/esm/components/ui/Page/Breadcrumbs/Breadcrumbs.js +28 -1
  13. package/dist/esm/components/ui/PanelResizeHandle/PanelResizeHandle.js +50 -0
  14. package/dist/esm/components/ui/Sidebar/Sidebar.styl.js +3 -3
  15. package/dist/esm/components/ui/Sidebar/SidebarAside.js +36 -0
  16. package/dist/esm/components/ui/Sidebar/SidebarContent/SidebarContent.js +13 -0
  17. package/dist/esm/components/ui/Sidebar/SidebarContent/SidebarContent.styl.js +7 -0
  18. package/dist/esm/components/ui/Sidebar/SidebarFooter/SidebarFooter.js +9 -0
  19. package/dist/esm/components/ui/Sidebar/SidebarFooter/SidebarFooter.styl.js +7 -0
  20. package/dist/esm/components/ui/Sidebar/SidebarGroup/SidebarGroup.js +9 -0
  21. package/dist/esm/components/ui/Sidebar/SidebarGroup/SidebarGroup.styl.js +7 -0
  22. package/dist/esm/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.js +11 -0
  23. package/dist/esm/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.styl.js +7 -0
  24. package/dist/esm/components/ui/Sidebar/SidebarMenu/SidebarMenu.js +15 -0
  25. package/dist/esm/components/ui/Sidebar/SidebarMenu/SidebarMenu.styl.js +7 -0
  26. package/dist/esm/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.js +11 -0
  27. package/dist/esm/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.styl.js +7 -0
  28. package/dist/esm/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.js +16 -0
  29. package/dist/esm/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.styl.js +7 -0
  30. package/dist/esm/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.js +12 -0
  31. package/dist/esm/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.styl.js +7 -0
  32. package/dist/esm/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.js +32 -0
  33. package/dist/esm/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.styl.js +7 -0
  34. package/dist/esm/components/ui/Sidebar/SidebarProvider/SidebarProvider.js +314 -0
  35. package/dist/esm/components/ui/Sidebar/SidebarProvider/SidebarProvider.styl.js +7 -0
  36. package/dist/esm/components/ui/Sidebar/SidebarRail/SidebarRail.js +11 -0
  37. package/dist/esm/components/ui/Sidebar/SidebarRail/SidebarRail.styl.js +7 -0
  38. package/dist/esm/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.js +26 -0
  39. package/dist/esm/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.styl.js +7 -0
  40. package/dist/esm/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.js +10 -0
  41. package/dist/esm/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.styl.js +7 -0
  42. package/dist/esm/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.js +16 -0
  43. package/dist/esm/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.styl.js +7 -0
  44. package/dist/esm/components/ui/Sidebar/sidebarConstants.js +7 -0
  45. package/dist/esm/components/ui/Sidebar/sidebarContext.js +28 -0
  46. package/dist/esm/components/ui/Sidebar/sidebarUtils.js +41 -0
  47. package/dist/esm/components/widgets/DriversComparisonChart/DriversComparisonChart.js +26 -5
  48. package/dist/esm/components/widgets/PerformanceChart/PerformanceTable.js +26 -4
  49. package/dist/esm/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.js +28 -1
  50. package/dist/esm/index.js +18 -1
  51. package/dist/esm/types/src/components/ui/PanelResizeHandle/PanelResizeHandle.d.ts +9 -0
  52. package/dist/esm/types/src/components/ui/Sidebar/Sidebar.d.ts +19 -106
  53. package/dist/esm/types/src/components/ui/Sidebar/Sidebar.types.d.ts +41 -0
  54. package/dist/esm/types/src/components/ui/Sidebar/SidebarAside.d.ts +2 -0
  55. package/dist/esm/types/src/components/ui/Sidebar/SidebarContent/SidebarContent.d.ts +3 -0
  56. package/dist/esm/types/src/components/ui/Sidebar/SidebarFooter/SidebarFooter.d.ts +2 -0
  57. package/dist/esm/types/src/components/ui/Sidebar/SidebarGroup/SidebarGroup.d.ts +2 -0
  58. package/dist/esm/types/src/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.d.ts +4 -0
  59. package/dist/esm/types/src/components/ui/Sidebar/SidebarMenu/SidebarMenu.d.ts +4 -0
  60. package/dist/esm/types/src/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.d.ts +5 -0
  61. package/dist/esm/types/src/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.d.ts +10 -0
  62. package/dist/esm/types/src/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.d.ts +3 -0
  63. package/dist/esm/types/src/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.d.ts +9 -0
  64. package/dist/esm/types/src/components/ui/Sidebar/SidebarProvider/SidebarProvider.d.ts +11 -0
  65. package/dist/esm/types/src/components/ui/Sidebar/SidebarRail/SidebarRail.d.ts +2 -0
  66. package/dist/esm/types/src/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.d.ts +4 -0
  67. package/dist/esm/types/src/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.d.ts +3 -0
  68. package/dist/esm/types/src/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.d.ts +3 -0
  69. package/dist/esm/types/src/components/ui/Sidebar/sidebarConstants.d.ts +5 -0
  70. package/dist/esm/types/src/components/ui/Sidebar/sidebarContext.d.ts +7 -0
  71. package/dist/esm/types/src/components/ui/Sidebar/sidebarUtils.d.ts +3 -0
  72. package/package.json +1 -1
  73. package/src/components/ui/ChartAreaInteractive/AGENT.md +0 -4
  74. package/src/components/ui/Chat/ChatChrome/ChatChrome.tsx +5 -2
  75. package/src/components/ui/DropdownMenu/DropdownMenu.styl +4 -1
  76. package/src/components/ui/PanelResizeHandle/PanelResizeHandle.tsx +89 -0
  77. package/src/components/ui/Sidebar/Sidebar.styl +23 -621
  78. package/src/components/ui/Sidebar/Sidebar.styl.d.ts +0 -33
  79. package/src/components/ui/Sidebar/Sidebar.tsx +25 -1145
  80. package/src/components/ui/Sidebar/Sidebar.types.ts +46 -0
  81. package/src/components/ui/Sidebar/SidebarAside.tsx +92 -0
  82. package/src/components/ui/Sidebar/SidebarContent/SidebarContent.styl +27 -0
  83. package/src/components/ui/Sidebar/SidebarContent/SidebarContent.styl.d.ts +7 -0
  84. package/src/components/ui/Sidebar/SidebarContent/SidebarContent.tsx +29 -0
  85. package/src/components/ui/Sidebar/SidebarFooter/SidebarFooter.styl +7 -0
  86. package/src/components/ui/Sidebar/SidebarFooter/SidebarFooter.styl.d.ts +7 -0
  87. package/src/components/ui/Sidebar/SidebarFooter/SidebarFooter.tsx +15 -0
  88. package/src/components/ui/Sidebar/SidebarGroup/SidebarGroup.styl +10 -0
  89. package/src/components/ui/Sidebar/SidebarGroup/SidebarGroup.styl.d.ts +7 -0
  90. package/src/components/ui/Sidebar/SidebarGroup/SidebarGroup.tsx +15 -0
  91. package/src/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.styl +34 -0
  92. package/src/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.styl.d.ts +7 -0
  93. package/src/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.tsx +23 -0
  94. package/src/components/ui/Sidebar/SidebarMenu/SidebarMenu.styl +60 -0
  95. package/src/components/ui/Sidebar/SidebarMenu/SidebarMenu.styl.d.ts +12 -0
  96. package/src/components/ui/Sidebar/SidebarMenu/SidebarMenu.tsx +40 -0
  97. package/src/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.styl +73 -0
  98. package/src/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.styl.d.ts +8 -0
  99. package/src/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.tsx +31 -0
  100. package/src/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.styl +107 -0
  101. package/src/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.styl.d.ts +15 -0
  102. package/src/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.tsx +82 -0
  103. package/src/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.styl +39 -0
  104. package/src/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.styl.d.ts +8 -0
  105. package/src/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.tsx +29 -0
  106. package/src/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.styl +71 -0
  107. package/src/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.styl.d.ts +8 -0
  108. package/src/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.tsx +80 -0
  109. package/src/components/ui/Sidebar/SidebarProvider/SidebarProvider.styl +45 -0
  110. package/src/components/ui/Sidebar/SidebarProvider/SidebarProvider.styl.d.ts +9 -0
  111. package/src/components/ui/Sidebar/SidebarProvider/SidebarProvider.tsx +447 -0
  112. package/src/components/ui/Sidebar/SidebarRail/SidebarRail.styl +42 -0
  113. package/src/components/ui/Sidebar/SidebarRail/SidebarRail.styl.d.ts +7 -0
  114. package/src/components/ui/Sidebar/SidebarRail/SidebarRail.tsx +22 -0
  115. package/src/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.styl +37 -0
  116. package/src/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.styl.d.ts +7 -0
  117. package/src/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.tsx +54 -0
  118. package/src/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.styl +7 -0
  119. package/src/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.styl.d.ts +7 -0
  120. package/src/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.tsx +20 -0
  121. package/src/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.styl +11 -0
  122. package/src/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.styl.d.ts +7 -0
  123. package/src/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.tsx +34 -0
  124. package/src/components/ui/Sidebar/sidebarConstants.ts +6 -0
  125. package/src/components/ui/Sidebar/sidebarContext.tsx +46 -0
  126. package/src/components/ui/Sidebar/sidebarUtils.ts +47 -0
  127. package/src/components/widgets/DriverMap/AGENT.md +0 -4
  128. package/src/components/widgets/DriversComparisonChart/AGENT.md +0 -4
  129. package/src/components/widgets/PerformanceChart/AGENT.md +0 -4
  130. package/src/components/widgets/SidebarDatasetsItemsGrouped/AGENT.md +28 -11
  131. package/src/docs/components/DocsGuidance/DocsGuidance.styl +1 -0
  132. package/src/docs/components/DocsSidebar/DocsSidebar.tsx +14 -8
  133. package/src/docs/pages/SmartTextTruncatePage.styl +2 -14
  134. package/src/docs/pages/SmartTextTruncatePage.styl.d.ts +0 -1
  135. package/src/docs/pages/SmartTextTruncatePage.tsx +0 -6
  136. package/dist/esm/components/ui/Sidebar/Sidebar.js +0 -541
@@ -1,1150 +1,30 @@
1
- import cn from 'classnames';
2
- import {
3
- CSSProperties,
4
- ComponentProps,
5
- RefObject,
6
- createContext,
7
- useCallback,
8
- useContext,
9
- useEffect,
10
- useLayoutEffect,
11
- useMemo,
12
- useRef,
13
- useState,
14
- } from 'react';
15
-
16
- import { Button } from '#uilib/components/ui/Button';
17
- import type { ButtonProps } from '#uilib/components/ui/Button/Button.types';
18
- import { Logo } from '#uilib/components/ui/Logo/Logo';
19
- import { Separator } from '#uilib/components/ui/Separator';
20
- import { Sheet, SheetContent, SheetTitle } from '#uilib/components/ui/Sheet';
21
- import {
22
- SmartTextTruncate,
23
- notifyPanelWidthDragEnd,
24
- notifyPanelWidthDragStart,
25
- } from '#uilib/components/ui/SmartTextTruncate/SmartTextTruncate';
26
- import {
27
- Tooltip,
28
- TooltipContent,
29
- TooltipProvider,
30
- TooltipTrigger,
31
- } from '#uilib/components/ui/Tooltip';
32
- import {
33
- CHAT_WIDTH_DEFAULT_PX,
34
- CHAT_WIDTH_MIN_PX,
35
- CHAT_WIDTH_STORAGE_KEY,
36
- SIDEBAR_WIDTH_DEFAULT_PX,
37
- SIDEBAR_WIDTH_MIN_PX,
38
- SIDEBAR_WIDTH_STORAGE_KEY_PCT,
39
- SIDEBAR_WIDTH_STORAGE_KEY_PX,
40
- clampChatWidthPx,
41
- clampSidebarWidthPx,
42
- defaultChatWidthPx,
43
- shellFitsSidebarsLayout,
44
- } from '#uilib/hooks/panelWidth';
45
- import useElemDrag, { Delta } from '#uilib/hooks/useDragElem';
46
- import useEvent from '#uilib/hooks/useEvent';
47
- import { useIsSidebarSheetLayout } from '#uilib/hooks/useIsSidebarSheetLayout';
48
- import { useShellWidthObserver } from '#uilib/hooks/useShellWidthObserver';
49
- import { getCookie, setCookie } from '#uilib/lib/cookie';
50
- import { getCookiePreferences } from '#uilib/lib/cookie-consent/cookie-consent';
51
- import { LS, Scroll } from '@homecode/ui';
52
- import { Slot } from '@radix-ui/react-slot';
53
- import { ChevronDown, ChevronRight, PanelLeft } from 'lucide-react';
54
-
55
- import S from './Sidebar.styl';
56
-
57
- const SIDEBAR_WIDTH_MOBILE = '18rem';
58
- const SIDEBAR_WIDTH_ICON = '3rem';
59
- const SIDEBAR_KEYBOARD_SHORTCUT = 'b';
60
-
61
- /** Fired when nav open closes chat for layout; ChatSheet clears `?chat=` so URL sync does not reopen chat. */
62
- export const DISMISS_CHAT_FOR_LAYOUT_EVENT = 'sybilion:dismiss-chat-for-layout';
63
-
64
- function isEditableKeyboardTarget(el: Element | null): boolean {
65
- if (!el) return false;
66
- if (el instanceof HTMLElement && el.isContentEditable) return true;
67
- const tag = el.tagName;
68
- return tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT';
69
- }
70
-
71
- function readInitialSidebarWidthPx(storageKeyPx: string): number {
72
- if (typeof window === 'undefined') return SIDEBAR_WIDTH_DEFAULT_PX;
73
- const stored = LS.get(storageKeyPx);
74
- if (typeof stored === 'number' && stored >= SIDEBAR_WIDTH_MIN_PX) {
75
- return stored;
76
- }
77
- if (storageKeyPx === SIDEBAR_WIDTH_STORAGE_KEY_PX) {
78
- const legacyPct = LS.get(SIDEBAR_WIDTH_STORAGE_KEY_PCT);
79
- if (typeof legacyPct === 'number' && legacyPct > 0) {
80
- const w = window.innerWidth;
81
- return clampSidebarWidthPx(Math.round((legacyPct / 100) * w), w, {
82
- chatPanelOpen: false,
83
- chatWidthPx: 0,
84
- });
85
- }
86
- }
87
- return SIDEBAR_WIDTH_DEFAULT_PX;
88
- }
89
-
90
- function readInitialChatWidthPx(): number {
91
- if (typeof window === 'undefined') return CHAT_WIDTH_DEFAULT_PX;
92
- const stored = LS.get(CHAT_WIDTH_STORAGE_KEY);
93
- if (typeof stored === 'number' && stored >= CHAT_WIDTH_MIN_PX) {
94
- return stored;
95
- }
96
- return defaultChatWidthPx(window.innerWidth);
97
- }
98
-
99
- type SetPanelWidthOptions = { persist?: boolean };
100
-
101
- /** Pass `viewTransition: false` to avoid nesting `document.startViewTransition` (e.g. chat open already animating). */
102
- export type SetSidebarOpenOptions = {
103
- viewTransition?: boolean;
104
- /** Nav closed for layout (chat/width); restore when chat closes — do not persist closed cookie. */
105
- layoutAutoClose?: boolean;
106
- };
107
-
108
- type SidebarActionsContextProps = {
109
- setOpen: (open: boolean, options?: SetSidebarOpenOptions) => void;
110
- toggleSidebar: () => void;
111
- setSidebarWidthPx: (px: number, options?: SetPanelWidthOptions) => void;
112
- setChatWidthPx: (px: number, options?: SetPanelWidthOptions) => void;
113
- setChatPanelOpen: (open: boolean) => void;
114
- getShellWidth: () => number;
115
- /** Read shell chat open without subscribing to SidebarStateContext. */
116
- getChatPanelOpen: () => boolean;
117
- };
118
-
119
- type SidebarStateContextProps = {
120
- isOpen: boolean;
121
- sidebarWidthPx: number;
122
- chatWidthPx: number;
123
- chatPanelOpen: boolean;
124
- /** Portal target for the AI chat side panel (right column). */
125
- chatPanelContainer: HTMLDivElement | null;
126
- /** App shell wrapper; used to set `--chat-panel-width` (and `--chat-panel-height` on mobile only). */
127
- sidebarWrapperRef: RefObject<HTMLDivElement | null>;
128
- };
129
-
130
- type SidebarContextProps = SidebarStateContextProps &
131
- SidebarActionsContextProps;
132
-
133
- type SidebarProps = ComponentProps<'div'> & {
134
- defaultOpen?: boolean;
135
- open?: boolean;
136
- onOpenChange?: (open: boolean) => void;
137
- side?: 'left' | 'right';
138
- variant?: 'sidebar' | 'floating' | 'inset';
139
- collapsible?: 'offcanvas' | 'icon' | 'none';
140
- fullHeightResizer?: boolean;
141
- brandText?: string;
142
- };
143
-
144
- const SidebarActionsContext = createContext<SidebarActionsContextProps | null>(
145
- null,
146
- );
147
- const SidebarStateContext = createContext<SidebarStateContextProps | null>(
148
- null,
149
- );
150
-
151
- function useSidebarActions() {
152
- const context = useContext(SidebarActionsContext);
153
- if (!context) {
154
- throw new Error('useSidebarActions must be used within a SidebarProvider.');
155
- }
156
-
157
- return context;
158
- }
159
-
160
- function useSidebarState() {
161
- const context = useContext(SidebarStateContext);
162
- if (!context) {
163
- throw new Error('useSidebarState must be used within a SidebarProvider.');
164
- }
165
-
166
- return context;
167
- }
168
-
169
- function useSidebar(): SidebarContextProps {
170
- const actions = useSidebarActions();
171
- const state = useSidebarState();
172
- return useMemo(
173
- () => ({
174
- ...state,
175
- ...actions,
176
- }),
177
- [state, actions],
178
- );
179
- }
180
-
181
- function SidebarProvider({
182
- defaultOpen = (getCookie('isSidebarOpen') as unknown as boolean) ?? true,
183
- className,
184
- style,
185
- children,
186
- userId,
187
- sidebarWidthStorageKey,
188
- persistSidebarWidthWithoutConsent = false,
189
- ...props
190
- }: ComponentProps<'div'> & {
191
- defaultOpen?: boolean;
192
- open?: boolean;
193
- onOpenChange?: (open: boolean) => void;
194
- userId?: string | number | null;
195
- /** LocalStorage key for sidebar width (pixels). Defaults to `sidebarWidthPx`. */
196
- sidebarWidthStorageKey?: string;
197
- /** When true, sidebar width is saved without functional cookie consent (e.g. internal docs). */
198
- persistSidebarWidthWithoutConsent?: boolean;
199
- }) {
200
- const sidebarLsKey = sidebarWidthStorageKey ?? SIDEBAR_WIDTH_STORAGE_KEY_PX;
201
- const allowPersistSidebarWidth =
202
- persistSidebarWidthWithoutConsent ||
203
- Boolean(getCookiePreferences(userId)?.functional);
204
-
205
- const isSidebarSheetLayout = useIsSidebarSheetLayout();
206
- const [isOpen, setIsOpen] = useState(
207
- isSidebarSheetLayout ? false : defaultOpen,
208
- );
209
- const wrapperRef = useRef<HTMLDivElement | null>(null);
210
- const shellWidthRef = useRef(0);
211
- const prevShellWidthRef = useRef(0);
212
- const [shellEl, setShellEl] = useState<HTMLDivElement | null>(null);
213
- const [chatPanelContainer, setChatPanelContainer] =
214
- useState<HTMLDivElement | null>(null);
215
- const onChatPanelMount = useCallback((node: HTMLDivElement | null) => {
216
- setChatPanelContainer(node);
217
- }, []);
218
-
219
- const [sidebarWidthPx, _setSidebarWidthPx] = useState(() =>
220
- readInitialSidebarWidthPx(sidebarLsKey),
221
- );
222
- const [chatWidthPx, _setChatWidthPx] = useState(readInitialChatWidthPx);
223
- const [chatPanelOpen, _setChatPanelOpen] = useState(false);
224
- const sidebarWidthRef = useRef(sidebarWidthPx);
225
- const chatWidthRef = useRef(chatWidthPx);
226
- const isOpenRef = useRef(isOpen);
227
- const chatPanelOpenRef = useRef(chatPanelOpen);
228
- /** Left nav was auto-closed because chat opened on a narrow shell; reopen when chat closes. */
229
- const sidebarAutoClosedForChatRef = useRef(false);
230
- sidebarWidthRef.current = sidebarWidthPx;
231
- chatWidthRef.current = chatWidthPx;
232
- isOpenRef.current = isOpen;
233
- chatPanelOpenRef.current = chatPanelOpen;
234
-
235
- const mergeWrapperRef = useCallback((el: HTMLDivElement | null) => {
236
- wrapperRef.current = el;
237
- setShellEl(el);
238
- }, []);
239
-
240
- const getShellWidth = useCallback((): number => {
241
- const w = shellWidthRef.current;
242
- if (w > 0) return w;
243
- if (wrapperRef.current) {
244
- const cw = wrapperRef.current.getBoundingClientRect().width;
245
- if (cw > 0) return cw;
246
- }
247
- return typeof window !== 'undefined' ? window.innerWidth : 1200;
248
- }, []);
249
-
250
- const getChatPanelOpen = useCallback(
251
- (): boolean => chatPanelOpenRef.current,
252
- [],
253
- );
254
-
255
- const setSidebarWidthPx = useCallback(
256
- (px: number, options?: SetPanelWidthOptions) => {
257
- const persist = options?.persist !== false;
258
- const shellW = getShellWidth();
259
- const next = clampSidebarWidthPx(px, shellW, {
260
- chatPanelOpen: chatPanelOpenRef.current,
261
- chatWidthPx: chatWidthRef.current,
262
- });
263
- sidebarWidthRef.current = next;
264
-
265
- // Live drag: update CSS var only — avoid re-rendering the whole nav tree each frame.
266
- if (wrapperRef.current) {
267
- wrapperRef.current.style.setProperty('--sidebar-width', `${next}px`);
268
- }
269
-
270
- if (!persist) return;
271
-
272
- _setSidebarWidthPx(next);
273
- if (allowPersistSidebarWidth) {
274
- LS.set(sidebarLsKey, next);
275
- }
276
- },
277
- [getShellWidth, sidebarLsKey, allowPersistSidebarWidth],
278
- );
279
-
280
- const setChatWidthPx = useCallback(
281
- (px: number, options?: SetPanelWidthOptions) => {
282
- const persist = options?.persist !== false;
283
- const shellW = getShellWidth();
284
- const effectiveSidebarW = isOpenRef.current ? sidebarWidthRef.current : 0;
285
- const next = clampChatWidthPx(px, shellW, effectiveSidebarW);
286
- _setChatWidthPx(next);
287
- if (persist && getCookiePreferences(userId)?.functional) {
288
- LS.set(CHAT_WIDTH_STORAGE_KEY, next);
289
- }
290
- },
291
- [getShellWidth, userId],
292
- );
293
-
294
- const handleShellResize = useCallback(
295
- (shellW: number) => {
296
- shellWidthRef.current = shellW;
297
- const prev = prevShellWidthRef.current;
298
- if (prev > 0 && shellW > 0) {
299
- const s = sidebarWidthRef.current;
300
- const c = chatWidthRef.current;
301
- const sScaled = Math.round((s * shellW) / prev);
302
- const cScaled = Math.round((c * shellW) / prev);
303
- const effS = (navOpen: boolean, sidebarPx: number) =>
304
- navOpen ? sidebarPx : 0;
305
- let cNext = clampChatWidthPx(
306
- cScaled,
307
- shellW,
308
- effS(isOpenRef.current, sScaled),
309
- );
310
- let sNext = clampSidebarWidthPx(sScaled, shellW, {
311
- chatPanelOpen: chatPanelOpenRef.current,
312
- chatWidthPx: cNext,
313
- });
314
- cNext = clampChatWidthPx(
315
- cScaled,
316
- shellW,
317
- effS(isOpenRef.current, sNext),
318
- );
319
- sNext = clampSidebarWidthPx(sScaled, shellW, {
320
- chatPanelOpen: chatPanelOpenRef.current,
321
- chatWidthPx: cNext,
322
- });
323
- _setSidebarWidthPx(sNext);
324
- _setChatWidthPx(cNext);
325
- if (allowPersistSidebarWidth) {
326
- LS.set(sidebarLsKey, sNext);
327
- }
328
- if (getCookiePreferences(userId)?.functional) {
329
- LS.set(CHAT_WIDTH_STORAGE_KEY, cNext);
330
- }
331
- }
332
- prevShellWidthRef.current = shellW;
333
- },
334
- [userId, sidebarLsKey, allowPersistSidebarWidth],
335
- );
336
-
337
- const fitPanelWidthsToShell = useCallback(() => {
338
- const shellW = getShellWidth();
339
- if (shellW <= 0) return;
340
- const s = sidebarWidthRef.current;
341
- const c = chatWidthRef.current;
342
- const effS = isOpenRef.current ? s : 0;
343
- let cNext = clampChatWidthPx(c, shellW, effS);
344
- let sNext = clampSidebarWidthPx(s, shellW, {
345
- chatPanelOpen: chatPanelOpenRef.current,
346
- chatWidthPx: cNext,
347
- });
348
- cNext = clampChatWidthPx(c, shellW, isOpenRef.current ? sNext : 0);
349
- sNext = clampSidebarWidthPx(s, shellW, {
350
- chatPanelOpen: chatPanelOpenRef.current,
351
- chatWidthPx: cNext,
352
- });
353
- if (sNext !== s || cNext !== c) {
354
- _setSidebarWidthPx(sNext);
355
- _setChatWidthPx(cNext);
356
- if (allowPersistSidebarWidth) {
357
- LS.set(sidebarLsKey, sNext);
358
- }
359
- if (getCookiePreferences(userId)?.functional) {
360
- LS.set(CHAT_WIDTH_STORAGE_KEY, cNext);
361
- }
362
- }
363
- }, [getShellWidth, userId, sidebarLsKey, allowPersistSidebarWidth]);
364
-
365
- useLayoutEffect(() => {
366
- if (!shellEl || isSidebarSheetLayout) return;
367
- fitPanelWidthsToShell();
368
- }, [
369
- shellEl,
370
- chatPanelOpen,
371
- isSidebarSheetLayout,
372
- isOpen,
373
- fitPanelWidthsToShell,
374
- ]);
375
-
376
- useShellWidthObserver(shellEl, handleShellResize);
377
-
378
- const closeOppositeSidebarIfNoSpace = useCallback(
379
- (openingMain: boolean, openingChat: boolean) => {
380
- if (isSidebarSheetLayout) return;
381
- const shellW = getShellWidth();
382
- const layoutAfterOpen = {
383
- mainSidebarOpen: openingMain || isOpenRef.current,
384
- chatPanelOpen: openingChat || chatPanelOpenRef.current,
385
- sidebarWidthPx: sidebarWidthRef.current,
386
- chatWidthPx: chatWidthRef.current,
387
- };
388
- if (shellFitsSidebarsLayout(shellW, layoutAfterOpen)) return;
389
- if (openingMain && chatPanelOpenRef.current) {
390
- _setChatPanelOpen(false);
391
- if (typeof window !== 'undefined') {
392
- window.dispatchEvent(new CustomEvent(DISMISS_CHAT_FOR_LAYOUT_EVENT));
393
- }
394
- } else if (openingChat && isOpenRef.current) {
395
- sidebarAutoClosedForChatRef.current = true;
396
- setIsOpen(false);
397
- }
398
- },
399
- [isSidebarSheetLayout, getShellWidth],
400
- );
401
-
402
- const setChatPanelOpen = useCallback(
403
- (open: boolean) => {
404
- if (open) {
405
- closeOppositeSidebarIfNoSpace(false, true);
406
- const shellW = getShellWidth();
407
- if (shellW > 0 && !isSidebarSheetLayout) {
408
- const navOpenAfter =
409
- isOpenRef.current && !sidebarAutoClosedForChatRef.current;
410
- const effNav = navOpenAfter ? sidebarWidthRef.current : 0;
411
- const cNext = clampChatWidthPx(chatWidthRef.current, shellW, effNav);
412
- if (cNext !== chatWidthRef.current) {
413
- _setChatWidthPx(cNext);
414
- }
415
- }
416
- _setChatPanelOpen(true);
417
- return;
418
- }
419
- _setChatPanelOpen(false);
420
- if (sidebarAutoClosedForChatRef.current) {
421
- sidebarAutoClosedForChatRef.current = false;
422
- setIsOpen(true);
423
- if (getCookiePreferences(userId)?.functional) {
424
- setCookie('isSidebarOpen', 'true', 60 * 60 * 24 * 7);
425
- }
426
- }
427
- },
428
- [
429
- closeOppositeSidebarIfNoSpace,
430
- getShellWidth,
431
- isSidebarSheetLayout,
432
- userId,
433
- ],
434
- );
435
-
436
- const setOpen = useCallback(
437
- (value: boolean, options?: SetSidebarOpenOptions) => {
438
- const layoutAutoClose = options?.layoutAutoClose === true;
439
-
440
- if (value) {
441
- sidebarAutoClosedForChatRef.current = false;
442
- closeOppositeSidebarIfNoSpace(true, false);
443
- } else if (layoutAutoClose) {
444
- sidebarAutoClosedForChatRef.current = true;
445
- } else {
446
- sidebarAutoClosedForChatRef.current = false;
447
- }
448
-
449
- const useViewTransition =
450
- options?.viewTransition !== false &&
451
- !isSidebarSheetLayout &&
452
- 'startViewTransition' in document &&
453
- document.startViewTransition;
454
-
455
- if (useViewTransition) {
456
- document.startViewTransition(() => {
457
- setIsOpen(value);
458
- });
459
- } else {
460
- setIsOpen(value);
461
- }
462
-
463
- if (!layoutAutoClose && getCookiePreferences(userId)?.functional) {
464
- setCookie('isSidebarOpen', value.toString(), 60 * 60 * 24 * 7);
465
- }
466
- },
467
- [isSidebarSheetLayout, userId, closeOppositeSidebarIfNoSpace],
468
- );
469
-
470
- const toggleSidebar = useCallback(
471
- () => setOpen(!isOpenRef.current),
472
- [setOpen],
473
- );
474
-
475
- useEffect(() => {
476
- const shell = wrapperRef.current;
477
- if (!shell) return;
478
- if (chatPanelOpen) {
479
- shell.setAttribute('data-chat-open', '');
480
- if (isSidebarSheetLayout) {
481
- shell.style.setProperty('--chat-panel-width', '100%');
482
- shell.style.setProperty('--chat-panel-height', '100dvh');
483
- } else {
484
- shell.style.setProperty('--chat-panel-width', `${chatWidthPx}px`);
485
- shell.style.removeProperty('--chat-panel-height');
486
- }
487
- } else {
488
- shell.removeAttribute('data-chat-open');
489
- shell.style.setProperty('--chat-panel-width', '0px');
490
- shell.style.removeProperty('--chat-panel-height');
491
- }
492
- }, [chatPanelOpen, isSidebarSheetLayout, chatWidthPx]);
493
-
494
- useEffect(() => {
495
- return () => {
496
- const shell = wrapperRef.current;
497
- if (!shell) return;
498
- shell.removeAttribute('data-chat-open');
499
- shell.style.setProperty('--chat-panel-width', '0px');
500
- shell.style.removeProperty('--chat-panel-height');
501
- };
502
- }, []);
503
-
504
- useEvent({
505
- event: 'keydown',
506
- callback: (e: KeyboardEvent) => {
507
- const isToggleShortcut =
508
- (e.key === SIDEBAR_KEYBOARD_SHORTCUT && (e.metaKey || e.ctrlKey)) ||
509
- (e.key === '/' && !isEditableKeyboardTarget(document.activeElement));
510
-
511
- if (isToggleShortcut) {
512
- e.preventDefault();
513
- toggleSidebar();
514
- }
515
- },
516
- });
517
-
518
- const sidebarActionsValue = useMemo<SidebarActionsContextProps>(
519
- () => ({
520
- setOpen,
521
- toggleSidebar,
522
- setSidebarWidthPx,
523
- setChatWidthPx,
524
- setChatPanelOpen,
525
- getShellWidth,
526
- getChatPanelOpen,
527
- }),
528
- [
529
- setOpen,
530
- toggleSidebar,
531
- setSidebarWidthPx,
532
- setChatWidthPx,
533
- setChatPanelOpen,
534
- getShellWidth,
535
- getChatPanelOpen,
536
- ],
537
- );
538
-
539
- const sidebarStateValue = useMemo<SidebarStateContextProps>(
540
- () => ({
541
- isOpen,
542
- sidebarWidthPx,
543
- chatWidthPx,
544
- chatPanelOpen,
545
- chatPanelContainer,
546
- sidebarWrapperRef: wrapperRef,
547
- }),
548
- [isOpen, sidebarWidthPx, chatWidthPx, chatPanelOpen, chatPanelContainer],
549
- );
550
-
551
- return (
552
- <SidebarActionsContext.Provider value={sidebarActionsValue}>
553
- <SidebarStateContext.Provider value={sidebarStateValue}>
554
- <TooltipProvider delayDuration={0}>
555
- <div
556
- ref={mergeWrapperRef}
557
- data-slot="sidebar-wrapper"
558
- data-state={isOpen ? 'expanded' : 'collapsed'}
559
- style={
560
- {
561
- '--sidebar-width': `${sidebarWidthPx}px`,
562
- '--sidebar-width-icon': SIDEBAR_WIDTH_ICON,
563
- ...style,
564
- } as CSSProperties
565
- }
566
- className={cn(S.sidebarWrapper, className)}
567
- {...props}
568
- >
569
- <div
570
- className={S.sidebarMainShell}
571
- // style={{ viewTransitionName: 'sidebar-gap' }}
572
- >
573
- {children}
574
- </div>
575
- <div
576
- ref={onChatPanelMount}
577
- className={S.chatPanelMount}
578
- data-slot="chat-panel-mount"
579
- // style={{ viewTransitionName: 'sidebar-container' }}
580
- />
581
- </div>
582
- </TooltipProvider>
583
- </SidebarStateContext.Provider>
584
- </SidebarActionsContext.Provider>
585
- );
586
- }
587
-
588
- function Sidebar({
589
- defaultOpen = true,
590
- open: openProp,
591
- onOpenChange: setOpenProp,
592
- className,
593
- side = 'left',
594
- variant = 'sidebar',
595
- collapsible = 'offcanvas',
596
- children,
597
- fullHeightResizer = false,
598
- brandText = 'Sybilion',
599
- ...props
600
- }: SidebarProps) {
601
- const isSidebarSheetLayout = useIsSidebarSheetLayout();
602
- const { isOpen } = useSidebarState();
603
- const { setOpen } = useSidebarActions();
604
-
605
- const prevSheetLayoutRef = useRef(isSidebarSheetLayout);
606
-
607
- /** Narrow shell: sidebar is a sheet; collapse only when crossing into this mode. */
608
- useEffect(() => {
609
- const enteredSheetLayout =
610
- isSidebarSheetLayout && !prevSheetLayoutRef.current;
611
- prevSheetLayoutRef.current = isSidebarSheetLayout;
612
- if (enteredSheetLayout) setOpen(false);
613
- }, [isSidebarSheetLayout, setOpen]);
614
-
615
- if (collapsible === 'none') {
616
- return (
617
- <div
618
- data-slot="sidebar"
619
- className={cn(S.sidebarNone, className)}
620
- {...props}
621
- >
622
- {children}
623
- </div>
624
- );
625
- }
626
-
627
- if (isSidebarSheetLayout) {
628
- return (
629
- <Sheet open={isOpen} onOpenChange={setOpen} {...props}>
630
- <SheetContent
631
- data-sidebar="sidebar"
632
- data-slot="sidebar"
633
- className={cn(S.sheetContentSidebar, className)}
634
- style={
635
- {
636
- '--gap-top': '40px',
637
- '--sidebar-width': SIDEBAR_WIDTH_MOBILE,
638
- } as CSSProperties
639
- }
640
- side={side}
641
- >
642
- <div className={cn(S.sheetSidebarInner)}>
643
- <div className={S.sheetSidebarLogo}>
644
- <Logo size="md" brandText={brandText} />
645
- </div>
646
- {children}
647
- </div>
648
- </SheetContent>
649
- </Sheet>
650
- );
651
- }
652
-
653
- return (
654
- <aside
655
- className={cn(
656
- S.sidebar,
657
- S[`variant-${variant}`],
658
- className,
659
- fullHeightResizer && S.fullHeightResizer,
660
- )}
661
- data-state={isOpen ? 'expanded' : 'collapsed'}
662
- data-collapsible={!isOpen ? collapsible : ''}
663
- data-variant={variant}
664
- data-side={side}
665
- {...props}
666
- >
667
- {children}
668
- <SidebarResizeHandle side={side} />
669
- </aside>
670
- );
671
- }
672
-
673
- function SidebarTrigger({
674
- className,
675
- onClick,
676
- ...props
677
- }: ComponentProps<typeof Button>) {
678
- const { toggleSidebar } = useSidebarActions();
679
-
680
- return (
681
- <Button
682
- data-sidebar="trigger"
683
- data-slot="sidebar-trigger"
684
- variant="ghost"
685
- icon
686
- className={cn(S.sidebarTrigger, className)}
687
- onClick={event => {
688
- onClick?.(event);
689
- toggleSidebar();
690
- }}
691
- {...props}
692
- >
693
- <PanelLeft size={20} strokeWidth={1.5} className="text-foreground" />
694
- {/* <span className="sr-only">Toggle Sidebar</span> */}
695
- </Button>
696
- );
697
- }
698
-
699
- function SidebarRail({ className, ...props }: ComponentProps<'button'>) {
700
- const { toggleSidebar } = useSidebarActions();
701
-
702
- return (
703
- <button
704
- data-sidebar="rail"
705
- data-slot="sidebar-rail"
706
- aria-label="Toggle Sidebar"
707
- tabIndex={-1}
708
- onClick={toggleSidebar}
709
- title="Toggle Sidebar"
710
- className={cn(S.sidebarRail, className)}
711
- {...props}
712
- />
713
- );
714
- }
715
-
716
- function PanelResizeHandle({
717
- className,
718
- edge,
719
- isActive,
720
- startWidthPx,
721
- getShellWidth,
722
- onDragWidth,
723
- onDragComplete,
724
- ...props
725
- }: ComponentProps<'div'> & {
726
- edge: 'leading' | 'trailing';
727
- isActive: boolean;
728
- startWidthPx: number;
729
- getShellWidth: () => number;
730
- onDragWidth: (rawPx: number) => void;
731
- onDragComplete?: (finalRawPx: number) => void;
732
- }) {
733
- const handleRef = useRef<HTMLDivElement>(null);
734
- const startWidthRef = useRef(0);
735
- const lastRawRef = useRef(0);
736
-
737
- const handleDrag = useCallback(
738
- (delta: Delta) => {
739
- notifyPanelWidthDragStart();
740
- const shellW = getShellWidth();
741
- if (shellW <= 0) return;
742
- const raw =
743
- edge === 'trailing'
744
- ? startWidthRef.current + delta.x
745
- : startWidthRef.current - delta.x;
746
- lastRawRef.current = raw;
747
- onDragWidth(raw);
748
- },
749
- [edge, getShellWidth, onDragWidth],
750
- );
751
-
752
- const handleDragStart = useCallback(
753
- (e: PointerEvent) => {
754
- startWidthRef.current = startWidthPx;
755
- lastRawRef.current = startWidthPx;
756
- handleRef.current?.setPointerCapture(e.pointerId);
757
- },
758
- [startWidthPx],
759
- );
760
-
761
- const handleDragEnd = useCallback(
762
- (e: PointerEvent) => {
763
- onDragComplete?.(lastRawRef.current);
764
- notifyPanelWidthDragEnd();
765
- try {
766
- handleRef.current?.releasePointerCapture(e.pointerId);
767
- } catch {
768
- // Capture already released
769
- }
770
- startWidthRef.current = 0;
771
- },
772
- [onDragComplete],
773
- );
774
-
775
- useElemDrag({
776
- elem: handleRef,
777
- onDrag: handleDrag,
778
- onDragStart: handleDragStart,
779
- onDragEnd: handleDragEnd,
780
- isActive,
781
- });
782
-
783
- if (!isActive) {
784
- return null;
785
- }
786
-
787
- return (
788
- <div
789
- ref={handleRef}
790
- data-slot="panel-resize-handle"
791
- data-edge={edge}
792
- className={className}
793
- {...props}
794
- />
795
- );
796
- }
797
-
798
- function SidebarResizeHandle({
799
- className,
800
- side = 'left',
801
- ...props
802
- }: ComponentProps<'div'> & { side?: 'left' | 'right' }) {
803
- const { isOpen, sidebarWidthPx } = useSidebarState();
804
- const { setSidebarWidthPx, getShellWidth } = useSidebarActions();
805
- const isSidebarSheetLayout = useIsSidebarSheetLayout();
806
-
807
- const edge: 'leading' | 'trailing' = side === 'left' ? 'trailing' : 'leading';
808
-
809
- const onDragWidth = useCallback(
810
- (rawPx: number) => {
811
- setSidebarWidthPx(rawPx, { persist: false });
812
- },
813
- [setSidebarWidthPx],
814
- );
815
-
816
- const onDragComplete = useCallback(
817
- (finalRawPx: number) => {
818
- setSidebarWidthPx(finalRawPx, { persist: true });
819
- },
820
- [setSidebarWidthPx],
821
- );
822
-
823
- if (isSidebarSheetLayout || !isOpen) {
824
- return null;
825
- }
826
-
827
- return (
828
- <PanelResizeHandle
829
- edge={edge}
830
- isActive={isOpen && !isSidebarSheetLayout}
831
- startWidthPx={sidebarWidthPx}
832
- getShellWidth={getShellWidth}
833
- onDragWidth={onDragWidth}
834
- onDragComplete={onDragComplete}
835
- data-sidebar="resize-handle"
836
- data-slot="sidebar-resize-handle"
837
- data-side={side}
838
- className={cn(S.sidebarResizeHandle, className)}
839
- {...props}
840
- />
841
- );
842
- }
843
-
844
- function SidebarFooter({ className, ...props }: ComponentProps<'div'>) {
845
- return (
846
- <div
847
- data-slot="sidebar-footer"
848
- data-sidebar="footer"
849
- className={cn(S.sidebarFooter, className)}
850
- {...props}
851
- />
852
- );
853
- }
854
-
855
- function SidebarSeparator({
856
- className,
857
- ...props
858
- }: ComponentProps<typeof Separator>) {
859
- return (
860
- <Separator
861
- data-slot="sidebar-separator"
862
- data-sidebar="separator"
863
- className={cn(S.sidebarSeparator, className)}
864
- {...props}
865
- />
866
- );
867
- }
868
-
869
- function SidebarContent({
870
- className,
871
- innerClassName,
872
- children,
873
- }: ComponentProps<typeof Scroll>) {
874
- // const sidebarContentTransition = useViewTransition({
875
- // transitionName: 'sidebar-content',
876
- // });
877
-
878
- return (
879
- <Scroll
880
- y
881
- autoHide
882
- fadeSize="l"
883
- offset={{ y: { before: 40, after: 20 } }}
884
- className={cn(S.sidebarContent, className)}
885
- innerClassName={innerClassName}
886
- >
887
- {children}
888
- </Scroll>
889
- );
890
- }
891
-
892
- function SidebarGroup({ className, ...props }: ComponentProps<'div'>) {
893
- return (
894
- <div
895
- data-slot="sidebar-group"
896
- data-sidebar="group"
897
- className={cn(S.sidebarGroup, className)}
898
- {...props}
899
- />
900
- );
901
- }
902
-
903
- function SidebarGroupAction({
904
- className,
905
- asChild = false,
906
- ...props
907
- }: ComponentProps<'button'> & { asChild?: boolean }) {
908
- const Comp = asChild ? Slot : 'button';
909
-
910
- return (
911
- <Comp
912
- data-slot="sidebar-group-action"
913
- data-sidebar="group-action"
914
- className={cn(S.sidebarGroupAction, className)}
915
- {...props}
916
- />
917
- );
918
- }
919
-
920
- function SidebarMenu({ className, ...props }: ComponentProps<'ul'>) {
921
- return (
922
- <ul
923
- data-slot="sidebar-menu"
924
- data-sidebar="menu"
925
- className={cn(S.sidebarMenu, className)}
926
- {...props}
927
- />
928
- );
929
- }
930
-
931
- function SidebarMenuItem({ className, ...props }: ComponentProps<'li'>) {
932
- return (
933
- <li
934
- data-slot="sidebar-menu-item"
935
- data-sidebar="menu-item"
936
- className={cn(S.sidebarMenuItem, className)}
937
- {...props}
938
- />
939
- );
940
- }
941
-
942
- function SidebarMenuButton({
943
- asChild = false,
944
- isActive = false,
945
- hasSubItems = false,
946
- isExpanded = false,
947
- variant = 'ghost',
948
- size = 'sm',
949
- className,
950
- icon,
951
- children,
952
- ...props
953
- }: Omit<ButtonProps, 'icon'> & {
954
- icon?: React.ReactNode;
955
- isActive?: boolean;
956
- /** When true, renders an expand/collapse chevron (requires a non–asChild button). */
957
- hasSubItems?: boolean;
958
- /** Chevron direction when `hasSubItems` is true. */
959
- isExpanded?: boolean;
960
- }) {
961
- const effectiveAsChild = asChild && !hasSubItems;
962
-
963
- const label = (
964
- <SmartTextTruncate className={S.sidebarMenuButtonLabel}>
965
- {children}
966
- </SmartTextTruncate>
967
- );
968
-
969
- const chevron = hasSubItems ? (
970
- <span
971
- className={cn(S.sidebarMenuButtonChevron, isExpanded && S.expanded)}
972
- aria-hidden="true"
973
- >
974
- <ChevronRight size={16} />
975
- </span>
976
- ) : null;
977
-
978
- return (
979
- <Button
980
- asChild={effectiveAsChild}
981
- variant={variant}
982
- size={size}
983
- data-slot="sidebar-menu-button"
984
- data-sidebar="menu-button"
985
- data-active={isActive}
986
- aria-expanded={hasSubItems ? isExpanded : undefined}
987
- className={cn(
988
- variant === 'default' ? S.sidebarMenuButtonCta : S.sidebarMenuButton,
989
- S[`size-${size}`],
990
- className,
991
- )}
992
- {...props}
993
- >
994
- {icon}
995
- {effectiveAsChild ? (
996
- label
997
- ) : (
998
- <>
999
- {label}
1000
- {chevron}
1001
- </>
1002
- )}
1003
- </Button>
1004
- );
1005
- }
1006
-
1007
- function SidebarMenuAction({
1008
- className,
1009
- asChild = false,
1010
- showOnHover = false,
1011
- ...props
1012
- }: ComponentProps<'button'> & {
1013
- asChild?: boolean;
1014
- showOnHover?: boolean;
1015
- }) {
1016
- const Comp = asChild ? Slot : 'button';
1017
-
1018
- return (
1019
- <Comp
1020
- data-slot="sidebar-menu-action"
1021
- data-sidebar="menu-action"
1022
- className={cn(
1023
- S.sidebarMenuAction,
1024
- showOnHover && S.showOnHover,
1025
- className,
1026
- )}
1027
- {...props}
1028
- />
1029
- );
1030
- }
1031
-
1032
- function SidebarMenuBadge({ className, ...props }: ComponentProps<'div'>) {
1033
- return (
1034
- <div
1035
- data-slot="sidebar-menu-badge"
1036
- data-sidebar="menu-badge"
1037
- className={cn(S.sidebarMenuBadge, className)}
1038
- {...props}
1039
- />
1040
- );
1041
- }
1042
-
1043
- function SidebarMenuSub({ className, ...props }: ComponentProps<'ul'>) {
1044
- return (
1045
- <ul
1046
- data-slot="sidebar-menu-sub"
1047
- data-sidebar="menu-sub"
1048
- className={cn(S.sidebarMenuSub, className)}
1049
- {...props}
1050
- />
1051
- );
1052
- }
1053
-
1054
- function SidebarMenuSubItem({ className, ...props }: ComponentProps<'li'>) {
1055
- return (
1056
- <li
1057
- data-slot="sidebar-menu-sub-item"
1058
- data-sidebar="menu-sub-item"
1059
- className={cn(S.sidebarMenuSubItem, className)}
1060
- {...props}
1061
- />
1062
- );
1063
- }
1064
-
1065
- function SidebarMenuSubButton({
1066
- asChild = false,
1067
- size = 'md',
1068
- isActive = false,
1069
- tooltip,
1070
- className,
1071
- onClick,
1072
- children,
1073
- ...props
1074
- }: ComponentProps<'a'> & {
1075
- asChild?: boolean;
1076
- size?: 'sm' | 'md' | 'lg';
1077
- isActive?: boolean;
1078
- tooltip?: string | ComponentProps<typeof TooltipContent>;
1079
- }) {
1080
- const Comp = asChild ? Slot : 'a';
1081
- const { isOpen } = useSidebarState();
1082
- const { setOpen } = useSidebarActions();
1083
- const isSidebarSheetLayout = useIsSidebarSheetLayout();
1084
-
1085
- const handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => {
1086
- if (isSidebarSheetLayout && isOpen) setOpen(false);
1087
- onClick?.(event);
1088
- };
1089
-
1090
- const button = (
1091
- <Comp
1092
- data-slot="sidebar-menu-sub-button"
1093
- data-sidebar="menu-sub-button"
1094
- data-size={size}
1095
- data-active={isActive}
1096
- className={cn(S.sidebarMenuSubButton, S[`size-${size}`], className)}
1097
- onClick={handleClick}
1098
- {...props}
1099
- >
1100
- <SmartTextTruncate className={S.sidebarMenuSubButtonLabel}>
1101
- {children}
1102
- </SmartTextTruncate>
1103
- </Comp>
1104
- );
1105
-
1106
- if (!tooltip) return button;
1107
-
1108
- if (typeof tooltip === 'string') {
1109
- tooltip = {
1110
- children: tooltip,
1111
- };
1112
- }
1113
-
1114
- return (
1115
- <Tooltip>
1116
- <TooltipTrigger asChild>{button}</TooltipTrigger>
1117
- <TooltipContent
1118
- side="right"
1119
- align="center"
1120
- hidden={!isOpen || isSidebarSheetLayout}
1121
- {...tooltip}
1122
- />
1123
- </Tooltip>
1124
- );
1125
- }
1126
-
1
+ export { DISMISS_CHAT_FOR_LAYOUT_EVENT } from './sidebarConstants';
2
+ export type { SetSidebarOpenOptions } from './Sidebar.types';
3
+ export {
4
+ useSidebar,
5
+ useSidebarActions,
6
+ useSidebarState,
7
+ } from './sidebarContext';
8
+ export { SidebarProvider } from './SidebarProvider/SidebarProvider';
9
+ export { Sidebar } from './SidebarAside';
10
+ export { SidebarTrigger } from './SidebarTrigger/SidebarTrigger';
11
+ export { SidebarRail } from './SidebarRail/SidebarRail';
12
+ export { PanelResizeHandle } from '../PanelResizeHandle/PanelResizeHandle';
13
+ export { SidebarResizeHandle } from './SidebarResizeHandle/SidebarResizeHandle';
14
+ export { SidebarFooter } from './SidebarFooter/SidebarFooter';
15
+ export { SidebarSeparator } from './SidebarSeparator/SidebarSeparator';
16
+ export { SidebarContent } from './SidebarContent/SidebarContent';
17
+ export { SidebarGroup } from './SidebarGroup/SidebarGroup';
18
+ export { SidebarGroupAction } from './SidebarGroupAction/SidebarGroupAction';
1127
19
  export {
1128
- PanelResizeHandle,
1129
- Sidebar,
1130
- SidebarContent,
1131
- SidebarFooter,
1132
- SidebarGroup,
1133
- SidebarGroupAction,
1134
20
  SidebarMenu,
1135
- SidebarMenuAction,
1136
- SidebarMenuBadge,
1137
- SidebarMenuButton,
1138
21
  SidebarMenuItem,
22
+ SidebarMenuBadge,
23
+ } from './SidebarMenu/SidebarMenu';
24
+ export { SidebarMenuButton } from './SidebarMenuButton/SidebarMenuButton';
25
+ export { SidebarMenuAction } from './SidebarMenuAction/SidebarMenuAction';
26
+ export {
1139
27
  SidebarMenuSub,
1140
- SidebarMenuSubButton,
1141
28
  SidebarMenuSubItem,
1142
- SidebarProvider,
1143
- SidebarRail,
1144
- SidebarResizeHandle,
1145
- SidebarSeparator,
1146
- SidebarTrigger,
1147
- useSidebar,
1148
- useSidebarActions,
1149
- useSidebarState,
1150
- };
29
+ } from './SidebarMenuSub/SidebarMenuSub';
30
+ export { SidebarMenuSubButton } from './SidebarMenuSubButton/SidebarMenuSubButton';