-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Configure expanded sidebar items (#592)
- Loading branch information
1 parent
4bb4349
commit b748fcb
Showing
7 changed files
with
212 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { type MouseEvent } from 'react' | ||
|
||
import { HamburgerMenuCollapseIcon, HamburgerMenuIcon } from '../icons' | ||
|
||
import { useSidebar } from './Sidebar' | ||
import SidebarItem from './SidebarItem' | ||
|
||
function SidebarExpandButton() { | ||
const { setIsExpanded, isExpanded } = useSidebar() | ||
|
||
return ( | ||
<SidebarItem | ||
tooltip="Expand" | ||
className="sidebar-expand" | ||
clickable | ||
expandedLabel="Collapse" | ||
onClick={(e: MouseEvent) => { | ||
e.stopPropagation() | ||
setIsExpanded((x: boolean) => !x) | ||
}} | ||
> | ||
{isExpanded ? <HamburgerMenuCollapseIcon /> : <HamburgerMenuIcon />} | ||
</SidebarItem> | ||
) | ||
} | ||
|
||
export default SidebarExpandButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useOutsideClick } from 'honorable' | ||
import { type ReactNode, useEffect, useRef } from 'react' | ||
|
||
import styled from 'styled-components' | ||
|
||
import { SIDEBAR_WIDTH, useSidebar } from './Sidebar' | ||
|
||
export const SIDEBAR_EXPANDED_WIDTH = 180 | ||
|
||
function SidebarExpandWrapper({ | ||
pathname, | ||
...props | ||
}: { | ||
pathname?: string | ||
children: ReactNode[] | ||
}) { | ||
const { layout, isExpanded, setIsExpanded } = useSidebar() | ||
const isHorizontal = layout === 'horizontal' | ||
const ref = useRef(null) | ||
|
||
useOutsideClick(ref, () => { | ||
setIsExpanded(false) | ||
}) | ||
|
||
useEffect(() => { | ||
setIsExpanded(false) | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [pathname]) | ||
|
||
return ( | ||
<Animated | ||
$isExpanded={isExpanded} | ||
$isHorizontal={isHorizontal} | ||
ref={ref} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
export default SidebarExpandWrapper | ||
|
||
const Animated = styled.div<{ | ||
$isExpanded: boolean | ||
$isHorizontal: boolean | ||
}>(({ theme, $isExpanded, $isHorizontal }) => ({ | ||
display: 'flex', | ||
flexDirection: $isHorizontal ? 'row' : 'column', | ||
position: 'relative', | ||
alignItems: 'center', | ||
borderBottom: $isHorizontal ? '' : `1px solid ${theme.colors.border}`, | ||
gap: $isHorizontal ? theme.spacing.medium : theme.spacing.xsmall, | ||
borderRight: $isHorizontal ? undefined : `1px solid ${theme.colors.border}`, | ||
width: $isExpanded ? SIDEBAR_EXPANDED_WIDTH : SIDEBAR_WIDTH, | ||
minWidth: $isExpanded ? SIDEBAR_EXPANDED_WIDTH : SIDEBAR_WIDTH, | ||
maxWidth: $isExpanded ? SIDEBAR_EXPANDED_WIDTH : SIDEBAR_WIDTH, | ||
height: '100%', | ||
backgroundColor: 'inherit', | ||
transition: 'all 0.2s ease', | ||
zIndex: 10, | ||
':last-of-type': { | ||
borderBottom: 'none', | ||
}, | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.