From 382002d1e4be9d9d33a73503e1423fc9d64759fc Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 21 Feb 2022 12:55:51 -0800 Subject: [PATCH] disclosure refactor --- .../Sidebar/components/CollectionLink.tsx | 44 ++++++++----------- .../Sidebar/components/Disclosure.ts | 14 ++++-- .../Sidebar/components/DocumentLink.tsx | 32 ++++++-------- .../Sidebar/components/SidebarLink.tsx | 36 ++++++++------- .../Sidebar/components/StarredLink.tsx | 27 +++++------- 5 files changed, 71 insertions(+), 82 deletions(-) diff --git a/app/components/Sidebar/components/CollectionLink.tsx b/app/components/Sidebar/components/CollectionLink.tsx index cf8879b29c..f6a480377d 100644 --- a/app/components/Sidebar/components/CollectionLink.tsx +++ b/app/components/Sidebar/components/CollectionLink.tsx @@ -1,6 +1,5 @@ import fractionalIndex from "fractional-index"; import { observer } from "mobx-react"; -import { CollapsedIcon } from "outline-icons"; import * as React from "react"; import { useDrop, useDrag } from "react-dnd"; import { useTranslation } from "react-i18next"; @@ -17,6 +16,7 @@ import useStores from "~/hooks/useStores"; import CollectionMenu from "~/menus/CollectionMenu"; import CollectionSortMenu from "~/menus/CollectionSortMenu"; import { NavigationNode } from "~/types"; +import Disclosure from "./Disclosure"; import DocumentLink from "./DocumentLink"; import DropCursor from "./DropCursor"; import DropToImport from "./DropToImport"; @@ -227,20 +227,16 @@ function CollectionLink({ { + event.preventDefault(); + setExpanded((prev) => !prev); + }} icon={ - <> - { - event.preventDefault(); - setExpanded((prev) => !prev); - }} - /> - - + } showActions={menuOpen} isActiveDrop={isOver && canDrop} @@ -257,8 +253,8 @@ function CollectionLink({ menu={ !isEditing && ( <> - {can.update && ( - ` opacity: ${(props) => (props.$isDragging || props.$isMoving ? 0.5 : 1)}; pointer-events: ${(props) => (props.$isMoving ? "none" : "auto")}; -`; -const Disclosure = styled(CollapsedIcon)<{ expanded?: boolean }>` - transition: transform 100ms ease, fill 50ms !important; - position: absolute; - left: -6px; - ${({ expanded }) => !expanded && "transform: rotate(-90deg);"}; - display: none; -`; + ${Disclosure} { + opacity: 0; + } -const CollectionSortMenuWithMargin = styled(CollectionSortMenu)` - margin-right: 4px; + &:hover ${Disclosure} { + opacity: 1; + } `; export default observer(CollectionLink); diff --git a/app/components/Sidebar/components/Disclosure.ts b/app/components/Sidebar/components/Disclosure.ts index 4c17623a1a..69496389b1 100644 --- a/app/components/Sidebar/components/Disclosure.ts +++ b/app/components/Sidebar/components/Disclosure.ts @@ -1,12 +1,18 @@ import { CollapsedIcon } from "outline-icons"; import styled from "styled-components"; -const Disclosure = styled(CollapsedIcon)<{ expanded?: boolean }>` - transition: transform 100ms ease, fill 50ms !important; +const Disclosure = styled(CollapsedIcon).attrs(() => ({ + color: "currentColor", +}))<{ + expanded?: boolean; +}>` + transition: opacity 100ms ease, transform 100ms ease, fill 50ms !important; + color: ${(props) => props.theme.textTertiary}; + flex-shrink: 0; position: absolute; - left: -24px; + left: -20px; - ${({ expanded }) => !expanded && "transform: rotate(-90deg);"}; + ${(props) => !props.expanded && "transform: rotate(-90deg);"}; `; export default Disclosure; diff --git a/app/components/Sidebar/components/DocumentLink.tsx b/app/components/Sidebar/components/DocumentLink.tsx index 63aa5677cf..5c98d9d15f 100644 --- a/app/components/Sidebar/components/DocumentLink.tsx +++ b/app/components/Sidebar/components/DocumentLink.tsx @@ -16,7 +16,6 @@ import useStores from "~/hooks/useStores"; import DocumentMenu from "~/menus/DocumentMenu"; import { NavigationNode } from "~/types"; import { newDocumentPath } from "~/utils/routeHelpers"; -import Disclosure from "./Disclosure"; import DropCursor from "./DropCursor"; import DropToImport from "./DropToImport"; import EditableTitle from "./EditableTitle"; @@ -98,7 +97,7 @@ function DocumentLink( }, [expanded, hasChildDocuments]); const handleDisclosureClick = React.useCallback( - (ev: React.SyntheticEvent) => { + (ev) => { ev.preventDefault(); ev.stopPropagation(); setExpanded(!expanded); @@ -270,6 +269,8 @@ function DocumentLink( t("Untitled"); const can = policies.abilities(node.id); + const isExpanded = expanded && !isDragging; + const hasChildren = nodeChildren.length > 0; return ( <> @@ -283,6 +284,8 @@ function DocumentLink(
- {hasChildDocuments && ( - - )} - - + } isActive={(match, location) => !!match && location.search !== "?starred" @@ -351,8 +346,7 @@ function DocumentLink( )} - {expanded && - !isDragging && + {isExpanded && nodeChildren.map((childNode, index) => ( & { innerRef?: (arg0: HTMLElement | null | undefined) => void; onClick?: React.MouseEventHandler; onMouseEnter?: React.MouseEventHandler; + onDisclosureClick?: React.MouseEventHandler; icon?: React.ReactNode; label?: React.ReactNode; menu?: React.ReactNode; showActions?: boolean; active?: boolean; + /* If set, a disclosure will be rendered to the left of any icon */ + expanded?: boolean; isActiveDrop?: boolean; isDraft?: boolean; depth?: number; @@ -50,6 +53,8 @@ function SidebarLink( href, depth, className, + expanded, + onDisclosureClick, ...rest }: Props, ref: React.RefObject @@ -90,14 +95,25 @@ function SidebarLink( ref={ref} {...rest} > - {icon && {icon}} - + + {expanded !== undefined && ( + + )} + {icon && {icon}} + + {menu && {menu}} ); } +const Content = styled.span` + display: flex; + position: relative; + width: 100%; +`; + // accounts for whitespace around icon export const IconWrapper = styled.span` margin-left: -4px; @@ -112,6 +128,7 @@ const Actions = styled(EventBoundary)<{ showActions?: boolean }>` position: absolute; top: 4px; right: 4px; + gap: 4px; color: ${(props) => props.theme.textTertiary}; transition: opacity 50ms; @@ -162,25 +179,12 @@ const Link = styled(NavLink)<{ $isActiveDrop?: boolean; $isDraft?: boolean }>` display: inline; } - &:focus { - color: ${(props) => props.theme.text}; - background: ${(props) => - transparentize("0.25", props.theme.sidebarItemBackground)}; - } - & + ${Actions} { ${NudeButton} { background: ${(props) => props.theme.sidebarBackground}; } } - &:focus + ${Actions} { - ${NudeButton} { - background: ${(props) => - transparentize("0.25", props.theme.sidebarItemBackground)}; - } - } - &[aria-current="page"] + ${Actions} { ${NudeButton} { background: ${(props) => props.theme.sidebarItemBackground}; diff --git a/app/components/Sidebar/components/StarredLink.tsx b/app/components/Sidebar/components/StarredLink.tsx index c842bcc3f4..77b842a45f 100644 --- a/app/components/Sidebar/components/StarredLink.tsx +++ b/app/components/Sidebar/components/StarredLink.tsx @@ -12,7 +12,6 @@ import Fade from "~/components/Fade"; import useBoolean from "~/hooks/useBoolean"; import useStores from "~/hooks/useStores"; import DocumentMenu from "~/menus/DocumentMenu"; -import Disclosure from "./Disclosure"; import DropCursor from "./DropCursor"; import EditableTitle from "./EditableTitle"; import SidebarLink from "./SidebarLink"; @@ -123,27 +122,21 @@ function StarredLink({ : undefined} isActive={(match, location) => !!match && location.search === "?starred" } label={ - <> - {hasChildDocuments && ( - - )} - - + } exact={false} showActions={menuOpen} @@ -167,7 +160,7 @@ function StarredLink({ childDocuments.map((childDocument) => (