From f8433bc65e781d8da85b2208909f5f8f86ade397 Mon Sep 17 00:00:00 2001 From: Hemachandar <132386067+hmacr@users.noreply.github.com> Date: Sun, 27 Oct 2024 20:10:15 +0530 Subject: [PATCH] fix: add sidebar toggle for public docs (#7842) --- app/components/SearchPopover.tsx | 4 +- app/components/Sidebar/Shared.tsx | 94 ++++++++++++++++++++++++++----- 2 files changed, 84 insertions(+), 14 deletions(-) diff --git a/app/components/SearchPopover.tsx b/app/components/SearchPopover.tsx index 0548b91bd1..2708021537 100644 --- a/app/components/SearchPopover.tsx +++ b/app/components/SearchPopover.tsx @@ -19,9 +19,10 @@ import SearchListItem from "./SearchListItem"; interface Props extends React.HTMLAttributes { shareId: string; + className?: string; } -function SearchPopover({ shareId }: Props) { +function SearchPopover({ shareId, className }: Props) { const { t } = useTranslation(); const { documents } = useStores(); const focusRef = React.useRef(null); @@ -186,6 +187,7 @@ function SearchPopover({ shareId }: Props) { onChange={handleSearchInputChange} onFocus={handleSearchInputFocus} onKeyDown={handleKeyDown} + className={className} /> )} diff --git a/app/components/Sidebar/Shared.tsx b/app/components/Sidebar/Shared.tsx index 129cd3060a..3eb7d1a652 100644 --- a/app/components/Sidebar/Shared.tsx +++ b/app/components/Sidebar/Shared.tsx @@ -1,13 +1,18 @@ import { observer } from "mobx-react"; +import { SidebarIcon } from "outline-icons"; import * as React from "react"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; import { NavigationNode } from "@shared/types"; +import Flex from "~/components/Flex"; import Scrollable from "~/components/Scrollable"; import SearchPopover from "~/components/SearchPopover"; +import Tooltip from "~/components/Tooltip"; import useCurrentUser from "~/hooks/useCurrentUser"; import useStores from "~/hooks/useStores"; +import { hover } from "~/styles"; import history from "~/utils/history"; +import { metaDisplay } from "~/utils/keyboard"; import { homePath, sharedDocumentPath } from "~/utils/routeHelpers"; import { useTeamContext } from "../TeamContext"; import TeamLogo from "../TeamLogo"; @@ -15,6 +20,7 @@ import Sidebar from "./Sidebar"; import Section from "./components/Section"; import DocumentLink from "./components/SharedDocumentLink"; import SidebarButton from "./components/SidebarButton"; +import ToggleButton from "./components/ToggleButton"; type Props = { rootNode: NavigationNode; @@ -27,9 +33,11 @@ function SharedSidebar({ rootNode, shareId }: Props) { const { ui, documents } = useStores(); const { t } = useTranslation(); + const teamAvailable = !!team?.name; + return ( - - {team?.name && ( + + {teamAvailable && ( } @@ -38,11 +46,20 @@ function SharedSidebar({ rootNode, shareId }: Props) { user ? homePath() : sharedDocumentPath(shareId, rootNode.url) ) } - /> + > + + )} - + + + + {!teamAvailable && ( + + + + )}
-
+ ); } +const ToggleSidebar = () => { + const { t } = useTranslation(); + const { ui } = useStores(); + + return ( + + } + onClick={() => { + ui.toggleCollapsedSidebar(); + (document.activeElement as HTMLElement)?.blur(); + }} + /> + + ); +}; + const ScrollContainer = styled(Scrollable)` padding-bottom: 16px; `; -const TopSection = styled(Section)` - // this weird looking && increases the specificity of the style rule - &&:first-child { - margin-top: 16px; - } +const TopSection = styled(Flex)` + position: relative; + padding: 8px; +`; - && { - margin-bottom: 16px; - } +const SearchWrapper = styled.div` + width: 100%; +`; + +const StyledSearchPopover = styled(SearchPopover)` + width: 100%; + transition: width 100ms ease-out; + margin: 8px 0; +`; + +const ToggleWrapper = styled.div` + position: absolute; + right: 0; + opacity: 0; + transform: translateX(10px); + transition: opacity 100ms ease-out, transform 100ms ease-out; +`; + +const StyledSidebar = styled(Sidebar)<{ $hoverTransition: boolean }>` + ${({ $hoverTransition }) => + $hoverTransition && + ` + &: ${hover} { + ${StyledSearchPopover} { + width: 85%; + } + + ${ToggleWrapper} { + opacity: 1; + transform: translateX(0); + } + } + `} `; export default observer(SharedSidebar);