-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathToggleSidebarButton.tsx
More file actions
36 lines (33 loc) · 1.25 KB
/
ToggleSidebarButton.tsx
File metadata and controls
36 lines (33 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react';
import { useIsMobileViewport } from '../ChannelHeader/hooks/useIsMobileViewport';
import { useChatContext, useTranslationContext } from '../../context';
import { Button, type ButtonProps } from './Button';
type ToggleSidebarButtonProps = ButtonProps & {
/** expand mode is usually assigned to button, whose task is to show the sidebar, and collapse vice versa */
mode: 'expand' | 'collapse';
/** usually can collapse if an item from sidebar was selected */
canCollapse?: boolean;
};
export const ToggleSidebarButton = ({
canCollapse,
mode,
...props
}: ToggleSidebarButtonProps) => {
const { closeMobileNav, navOpen, openMobileNav } = useChatContext('ChannelHeader');
const { t } = useTranslationContext('ChannelHeader');
const toggleNav = navOpen ? closeMobileNav : openMobileNav;
const isMobileViewport = useIsMobileViewport();
const showButton = mode === 'expand' ? isMobileViewport || !navOpen : canCollapse;
return showButton ? (
<Button
appearance='ghost'
aria-label={navOpen ? t('aria/Collapse sidebar') : t('aria/Expand sidebar')}
circular
className='str-chat__header-sidebar-toggle'
onClick={toggleNav}
size='md'
variant='secondary'
{...props}
/>
) : null;
};