From 43a55357392a76da855c28f69078546a1dae343c Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Sat, 16 Sep 2023 19:20:17 -0700 Subject: [PATCH] Refactor NavCollapse button (#1625) --- .../ui/layout/components/PageHeader.tsx | 2 +- .../ui/navbar/components/MainNavbar.tsx | 2 +- .../navbar/components/NavCollapseButton.tsx | 64 ++++++++----------- .../navbar/components/NavWorkspaceButton.tsx | 6 +- 4 files changed, 30 insertions(+), 44 deletions(-) diff --git a/front/src/modules/ui/layout/components/PageHeader.tsx b/front/src/modules/ui/layout/components/PageHeader.tsx index db94e3746..3bdac95aa 100644 --- a/front/src/modules/ui/layout/components/PageHeader.tsx +++ b/front/src/modules/ui/layout/components/PageHeader.tsx @@ -96,7 +96,7 @@ export const PageHeader = ({ {!isNavbarOpened && ( - + )} {hasBackButton && ( diff --git a/front/src/modules/ui/navbar/components/MainNavbar.tsx b/front/src/modules/ui/navbar/components/MainNavbar.tsx index 2a4ec0c46..50ad10879 100644 --- a/front/src/modules/ui/navbar/components/MainNavbar.tsx +++ b/front/src/modules/ui/navbar/components/MainNavbar.tsx @@ -32,7 +32,7 @@ const MainNavbar = ({ children }: OwnProps) => { return (
- + {children}
diff --git a/front/src/modules/ui/navbar/components/NavCollapseButton.tsx b/front/src/modules/ui/navbar/components/NavCollapseButton.tsx index 9f79d3f14..260686984 100644 --- a/front/src/modules/ui/navbar/components/NavCollapseButton.tsx +++ b/front/src/modules/ui/navbar/components/NavCollapseButton.tsx @@ -1,4 +1,6 @@ +import { useTheme } from '@emotion/react'; import styled from '@emotion/styled'; +import { motion } from 'framer-motion'; import { useRecoilState } from 'recoil'; import { IconButton } from '@/ui/button/components/IconButton'; @@ -8,11 +10,8 @@ import { } from '@/ui/icon'; import { isNavbarOpenedState } from '@/ui/layout/states/isNavbarOpenedState'; -const StyledCollapseButton = styled.div<{ - hide: boolean; -}>` +const StyledCollapseButton = styled(motion.div)` align-items: center; - animation: ${({ hide }) => (hide ? 'fadeIn 150ms' : 'none')}; background: inherit; border: 0; &:hover { @@ -30,58 +29,45 @@ const StyledCollapseButton = styled.div<{ padding: 0; user-select: none; - visibility: ${({ hide }) => (hide ? 'visible' : 'hidden')}; width: 24px; - - @keyframes fadeIn { - 0% { - opacity: 0; - } - 100% { - opacity: 1; - } - } `; type CollapseButtonProps = { direction?: 'left' | 'right'; - hide: boolean; + show?: boolean; }; const NavCollapseButton = ({ direction = 'left', - hide, + show = true, }: CollapseButtonProps) => { const [isNavbarOpened, setIsNavbarOpened] = useRecoilState(isNavbarOpenedState); const iconSize = 'small'; + const theme = useTheme(); return ( <> - {direction === 'left' ? ( - setIsNavbarOpened(!isNavbarOpened)} - > - - - ) : ( - setIsNavbarOpened(!isNavbarOpened)} - > - - - )} + setIsNavbarOpened(!isNavbarOpened)} + > + + ); }; diff --git a/front/src/modules/ui/navbar/components/NavWorkspaceButton.tsx b/front/src/modules/ui/navbar/components/NavWorkspaceButton.tsx index 60bd3addc..e10b656ff 100644 --- a/front/src/modules/ui/navbar/components/NavWorkspaceButton.tsx +++ b/front/src/modules/ui/navbar/components/NavWorkspaceButton.tsx @@ -46,10 +46,10 @@ const StyledName = styled.div` `; type OwnProps = { - hideCollapseButton: boolean; + showCollapseButton: boolean; }; -const NavWorkspaceButton = ({ hideCollapseButton }: OwnProps) => { +const NavWorkspaceButton = ({ showCollapseButton }: OwnProps) => { const currentUser = useRecoilValue(currentUserState); const currentWorkspace = currentUser?.workspaceMember?.workspace; @@ -68,7 +68,7 @@ const NavWorkspaceButton = ({ hideCollapseButton }: OwnProps) => { > {currentWorkspace?.displayName ?? 'Twenty'} - +
); };