Skip to content

Commit 95a39de

Browse files
vardanbansal-harnessHarness
authored andcommitted
feat: Updating sidebar expand-collapse interaction (#10573)
* 3d92ce Adding sidebar expand collapse icons * 673fde remove sidebar collapse icon button
1 parent 33cd88f commit 95a39de

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

packages/ui/src/components/chatV2.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRef, useState } from 'react'
22

3-
import { Button, IconV2, Layout, Text } from '@/components'
3+
import { Button, IconV2, Text } from '@/components'
44

55
export const ChatV2 = () => {
66
const [collapsed, setCollapsed] = useState(false)
@@ -33,18 +33,7 @@ export const ChatV2 = () => {
3333
</Button>
3434
</div>
3535
) : (
36-
<Layout.Vertical className="h-full justify-between">
37-
<Text>Chat</Text>
38-
<Button
39-
variant="transparent"
40-
size="sm"
41-
iconOnly
42-
tooltipProps={{ content: 'Collapse' }}
43-
onClick={handleToggle}
44-
>
45-
<IconV2 name="collapse-sidebar" skipSize />
46-
</Button>
47-
</Layout.Vertical>
36+
<Text>Chat</Text>
4837
)}
4938
</div>
5039
)

packages/ui/src/components/nav/side-nav.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,7 @@ export const SideNav: React.FC<{ routes?: RouteDefinitions }> = ({ routes }) =>
174174
))}
175175
</Sidebar.Group>
176176
</Sidebar.Content>
177-
178-
<Sidebar.Footer>
179-
<Sidebar.ToggleMenuButton onClick={noop} />
180-
</Sidebar.Footer>
181-
<Sidebar.Rail onClick={noop} />
177+
<Sidebar.Rail onClick={noop} open={!collapsed} />
182178
</Sidebar.Root>
183179

184180
<ManageNavigation

packages/ui/src/components/sidebar/sidebar-units.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
forwardRef,
77
MouseEvent,
88
useCallback,
9-
useMemo
9+
useMemo,
10+
useState
1011
} from 'react'
1112

1213
import {
@@ -91,10 +92,11 @@ export const SidebarTrigger = forwardRef<ElementRef<typeof Button>, SidebarTrigg
9192
)
9293
SidebarTrigger.displayName = 'SidebarTrigger'
9394

94-
export const SidebarRail = forwardRef<HTMLButtonElement, ComponentProps<'button'>>(
95-
({ className, onClick, ...props }, ref) => {
95+
export const SidebarRail = forwardRef<HTMLButtonElement, ComponentProps<'button'> & { open?: boolean }>(
96+
({ className, onClick, open, ...props }, ref) => {
9697
const { toggleSidebar } = useSidebar()
9798
const { t } = useTranslation()
99+
const [hovered, setHovered] = useState(false)
98100

99101
const onClickHandler = useCallback(
100102
(event: MouseEvent<HTMLButtonElement>) => {
@@ -104,16 +106,26 @@ export const SidebarRail = forwardRef<HTMLButtonElement, ComponentProps<'button'
104106
[toggleSidebar, onClick]
105107
)
106108

109+
const label = open ? t('component:sidebar.collapse', 'Collapse') : t('component:sidebar.expand', 'Expand')
110+
107111
return (
108112
<button
109113
ref={ref}
110-
aria-label={t('component:sidebar.toggle', 'Toggle sidebar')}
114+
aria-label={label}
115+
title={label}
111116
tabIndex={-1}
112117
onClick={onClickHandler}
113-
title={t('component:sidebar.toggle', 'Toggle sidebar')}
114-
className={cn('cn-sidebar-rail', className)}
118+
onMouseEnter={() => setHovered(true)}
119+
onMouseLeave={() => setHovered(false)}
120+
className={cn('cn-sidebar-rail top-1/4 translate-x-1/2', { 'translate-x-1/4': hovered }, className)}
115121
{...props}
116-
/>
122+
>
123+
{hovered ? (
124+
<IconV2 name={open ? 'nav-arrow-left' : 'nav-arrow-right'} size="lg" />
125+
) : (
126+
<Text className="cn-pl-1 pl-cn-4xs">|</Text>
127+
)}
128+
</button>
117129
)
118130
}
119131
)

0 commit comments

Comments
 (0)