Refactor NavCollapse button (#1625)

This commit is contained in:
Charles Bochet
2023-09-16 19:20:17 -07:00
committed by GitHub
parent 82ac84ee7c
commit 43a5535739
4 changed files with 30 additions and 44 deletions

View File

@ -96,7 +96,7 @@ export const PageHeader = ({
<StyledLeftContainer> <StyledLeftContainer>
{!isNavbarOpened && ( {!isNavbarOpened && (
<StyledTopBarButtonContainer> <StyledTopBarButtonContainer>
<NavCollapseButton direction="right" hide={true} /> <NavCollapseButton direction="right" />
</StyledTopBarButtonContainer> </StyledTopBarButtonContainer>
)} )}
{hasBackButton && ( {hasBackButton && (

View File

@ -32,7 +32,7 @@ const MainNavbar = ({ children }: OwnProps) => {
return ( return (
<StyledContainer> <StyledContainer>
<div onMouseEnter={handleHover} onMouseLeave={handleMouseLeave}> <div onMouseEnter={handleHover} onMouseLeave={handleMouseLeave}>
<NavWorkspaceButton hideCollapseButton={isHovered} /> <NavWorkspaceButton showCollapseButton={isHovered} />
<NavItemsContainer>{children}</NavItemsContainer> <NavItemsContainer>{children}</NavItemsContainer>
</div> </div>
<SupportChat /> <SupportChat />

View File

@ -1,4 +1,6 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { motion } from 'framer-motion';
import { useRecoilState } from 'recoil'; import { useRecoilState } from 'recoil';
import { IconButton } from '@/ui/button/components/IconButton'; import { IconButton } from '@/ui/button/components/IconButton';
@ -8,11 +10,8 @@ import {
} from '@/ui/icon'; } from '@/ui/icon';
import { isNavbarOpenedState } from '@/ui/layout/states/isNavbarOpenedState'; import { isNavbarOpenedState } from '@/ui/layout/states/isNavbarOpenedState';
const StyledCollapseButton = styled.div<{ const StyledCollapseButton = styled(motion.div)`
hide: boolean;
}>`
align-items: center; align-items: center;
animation: ${({ hide }) => (hide ? 'fadeIn 150ms' : 'none')};
background: inherit; background: inherit;
border: 0; border: 0;
&:hover { &:hover {
@ -30,58 +29,45 @@ const StyledCollapseButton = styled.div<{
padding: 0; padding: 0;
user-select: none; user-select: none;
visibility: ${({ hide }) => (hide ? 'visible' : 'hidden')};
width: 24px; width: 24px;
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
`; `;
type CollapseButtonProps = { type CollapseButtonProps = {
direction?: 'left' | 'right'; direction?: 'left' | 'right';
hide: boolean; show?: boolean;
}; };
const NavCollapseButton = ({ const NavCollapseButton = ({
direction = 'left', direction = 'left',
hide, show = true,
}: CollapseButtonProps) => { }: CollapseButtonProps) => {
const [isNavbarOpened, setIsNavbarOpened] = const [isNavbarOpened, setIsNavbarOpened] =
useRecoilState(isNavbarOpenedState); useRecoilState(isNavbarOpenedState);
const iconSize = 'small'; const iconSize = 'small';
const theme = useTheme();
return ( return (
<> <>
{direction === 'left' ? ( <StyledCollapseButton
<StyledCollapseButton animate={{
hide={hide} opacity: show ? 1 : 0,
onClick={() => setIsNavbarOpened(!isNavbarOpened)} }}
> transition={{
<IconButton duration: theme.animation.duration.normal,
Icon={IconLayoutSidebarLeftCollapse} }}
variant="tertiary" onClick={() => setIsNavbarOpened(!isNavbarOpened)}
size={iconSize} >
/> <IconButton
</StyledCollapseButton> Icon={
) : ( direction === 'left'
<StyledCollapseButton ? IconLayoutSidebarLeftCollapse
hide={hide} : IconLayoutSidebarRightCollapse
onClick={() => setIsNavbarOpened(!isNavbarOpened)} }
> variant="tertiary"
<IconButton size={iconSize}
Icon={IconLayoutSidebarRightCollapse} />
variant="tertiary" </StyledCollapseButton>
size={iconSize}
/>
</StyledCollapseButton>
)}
</> </>
); );
}; };

View File

@ -46,10 +46,10 @@ const StyledName = styled.div`
`; `;
type OwnProps = { type OwnProps = {
hideCollapseButton: boolean; showCollapseButton: boolean;
}; };
const NavWorkspaceButton = ({ hideCollapseButton }: OwnProps) => { const NavWorkspaceButton = ({ showCollapseButton }: OwnProps) => {
const currentUser = useRecoilValue(currentUserState); const currentUser = useRecoilValue(currentUserState);
const currentWorkspace = currentUser?.workspaceMember?.workspace; const currentWorkspace = currentUser?.workspaceMember?.workspace;
@ -68,7 +68,7 @@ const NavWorkspaceButton = ({ hideCollapseButton }: OwnProps) => {
></StyledLogo> ></StyledLogo>
<StyledName>{currentWorkspace?.displayName ?? 'Twenty'}</StyledName> <StyledName>{currentWorkspace?.displayName ?? 'Twenty'}</StyledName>
</StyledLogoAndNameContainer> </StyledLogoAndNameContainer>
<NavCollapseButton direction="left" hide={hideCollapseButton} /> <NavCollapseButton direction="left" show={showCollapseButton} />
</StyledContainer> </StyledContainer>
); );
}; };