diff --git a/apps/ligo-virgo/src/pages/workspace/docs/collapsible-page-tree.tsx b/apps/ligo-virgo/src/pages/workspace/docs/collapsible-page-tree.tsx index ab903ab3ca..913f4024c9 100644 --- a/apps/ligo-virgo/src/pages/workspace/docs/collapsible-page-tree.tsx +++ b/apps/ligo-virgo/src/pages/workspace/docs/collapsible-page-tree.tsx @@ -1,34 +1,32 @@ -import React, { useCallback, useState } from 'react'; -import { useNavigate, useParams } from 'react-router-dom'; -import { - MuiBox as Box, - MuiButton as Button, - MuiCollapse as Collapse, - MuiIconButton as IconButton, - styled, -} from '@toeverything/components/ui'; import { + AddIcon, ArrowDropDownIcon, ArrowRightIcon, } from '@toeverything/components/icons'; -import { services } from '@toeverything/datasource/db-service'; import { - usePageTree, useCalendarHeatmap, + usePageTree, } from '@toeverything/components/layout'; -import { AddIcon } from '@toeverything/components/icons'; +import { + MuiBox as Box, + MuiCollapse as Collapse, + styled, +} from '@toeverything/components/ui'; +import { services } from '@toeverything/datasource/db-service'; +import React, { useCallback, useState } from 'react'; +import { useNavigate, useParams } from 'react-router-dom'; -const StyledContainer = styled('div')({ +const StyledBtn = styled('div')({ height: '32px', display: 'flex', alignItems: 'center', -}); - -const StyledBtn = styled('div')({ color: '#98ACBD', textTransform: 'none', fontSize: '12px', fontWeight: '600', + cursor: 'pointer', + userSelect: 'none', + flex: 1, }); export type CollapsiblePageTreeProps = { @@ -81,16 +79,14 @@ export function CollapsiblePageTree(props: CollapsiblePageTreeProps) { onMouseEnter={() => setNewPageBtnVisible(true)} onMouseLeave={() => setNewPageBtnVisible(false)} > - + setOpen(prev => !prev)}> {open ? ( ) : ( )} - setOpen(prev => !prev)}> - {title} - - + {title} + {newPageBtnVisible && ( ) => { + if (anchorEl) { + setAnchorEl(null); + return; + } setAnchorEl(event.currentTarget); }; const handleClose = () => { @@ -246,10 +248,11 @@ function DndTreeItemMoreActions(props: ActionsProps) { return ( handleClose()}> - + @@ -262,14 +265,15 @@ function DndTreeItemMoreActions(props: ActionsProps) { - + + + /> ( 'BooleanPageTreeItemMoreActions', true ); - const theme = useTheme(); return ( - - - + + {childCount !== 0 && (collapsed ? ( ) : ( ))} - + - - + {value} - + {BooleanPageTreeItemMoreActions && ( ( {/*{!clone && onRemove && }*/} {clone && childCount && childCount > 1 ? ( - - {childCount} - + {childCount} ) : null} - - - + + + ); } ); - -export interface ActionProps extends React.HTMLAttributes { - active?: { - fill: string; - background: string; - }; - // cursor?: CSSProperties['cursor']; - cursor?: 'pointer' | 'grab'; -} - -/** Customizable buttons */ -export function Action({ - active, - className, - cursor, - style, - ...props -}: ActionProps) { - return ( - - ); -} - -export function Handle(props: ActionProps) { - return ( - - - - ); -} - -export function Remove(props: ActionProps) { - return ( - - - {/* - - */} - - ); -} diff --git a/libs/components/layout/src/workspace-sidebar/page-tree/tree-item/tree-item.module.scss b/libs/components/layout/src/workspace-sidebar/page-tree/tree-item/styles.ts old mode 100755 new mode 100644 similarity index 63% rename from libs/components/layout/src/workspace-sidebar/page-tree/tree-item/tree-item.module.scss rename to libs/components/layout/src/workspace-sidebar/page-tree/tree-item/styles.ts index 59cc3cfa69..a615a497eb --- a/libs/components/layout/src/workspace-sidebar/page-tree/tree-item/tree-item.module.scss +++ b/libs/components/layout/src/workspace-sidebar/page-tree/tree-item/styles.ts @@ -1,10 +1,46 @@ -.Wrapper { +import { styled } from '@toeverything/components/ui'; +import { Link } from 'react-router-dom'; + +export const TreeItemContainer = styled('div')` box-sizing: border-box; - padding-left: var(--spacing); + display: flex; + align-items: center; + color: #4c6275; +`; + +export const Wrapper = styled('li')<{ + spacing: string; + clone?: boolean; + ghost?: boolean; + indicator?: boolean; + disableSelection?: boolean; + disableInteraction?: boolean; +}>` + box-sizing: border-box; + padding-left: ${({ spacing }) => spacing}; list-style: none; - padding-top: 6px; - padding-bottom: 6px; font-size: 14px; + + ${({ clone, disableSelection }) => + (clone || disableSelection) && + `width: 100%; + .Text, + .Count { + user-select: none; + -webkit-user-select: none; + }`} + + ${({ indicator }) => + indicator && + `width: 100%; + .Text, + .Count { + user-select: none; + -webkit-user-select: none; + }`} + + ${({ disableInteraction }) => disableInteraction && `pointer-events: none;`} + &:hover { background: #f5f7f8; border-radius: 5px; @@ -17,7 +53,7 @@ margin-top: 5px; pointer-events: none; - .TreeItem { + ${TreeItemContainer} { padding-right: 20px; border-radius: 4px; box-shadow: 0px 15px 15px 0 rgba(34, 33, 81, 0.1); @@ -31,7 +67,7 @@ z-index: 1; margin-bottom: -1px; - .TreeItem { + ${TreeItemContainer} { position: relative; padding: 0; height: 8px; @@ -62,56 +98,14 @@ opacity: 0.5; } - .TreeItem > * { + ${TreeItemContainer} > * { box-shadow: none; background-color: transparent; } } -} +`; -.TreeItem { - box-sizing: border-box; - display: flex; - align-items: center; - color: #4c6275; -} - -.ItemContent { - box-sizing: border-box; - width: 100%; - height: 32px; - position: relative; - display: flex; - align-items: center; - justify-content: space-around; - color: #4c6275; - padding-right: 0.5rem; - overflow: hidden; - - .TreeItemMoreActions { - visibility: hidden; - cursor: pointer; - } - &:hover { - .TreeItemMoreActions { - visibility: visible; - display: block; - } - } -} - -.Text { - flex-grow: 1; - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; - cursor: pointer; - appearance: none; - color: unset; - text-decoration: none; -} - -.Count { +export const Counter = styled('span')` position: absolute; top: 8px; right: 0; @@ -125,33 +119,12 @@ font-size: 0.9rem; font-weight: 500; color: #fff; -} +`; -.disableInteraction { - pointer-events: none; -} - -.disableSelection, -.clone { - width: 100%; - .Text, - .Count { - user-select: none; - -webkit-user-select: none; - } -} - -.Collapse { - svg { - transition: transform 250ms ease; - } - - &.collapsed svg { - transform: rotate(-90deg); - } -} - -.Action { +export const ActionButton = styled('button')<{ + background?: string; + fill?: string; +}>` display: flex; width: 12px; padding: 0 15px; @@ -176,10 +149,11 @@ } &:active { - background-color: var(--background, rgba(0, 0, 0, 0.05)); + background-color: ${({ background }) => + background ?? 'rgba(0, 0, 0, 0.05)'}; svg { - fill: var(--fill, #788491); + fill: ${({ fill }) => fill ?? '#788491'}; } } @@ -187,4 +161,45 @@ outline: none; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0), 0 0px 0px 2px #4c9ffe; } -} +`; + +export const TreeItemMoreActions = styled('div')` + display: block; + visibility: hidden; +`; + +export const TextLink = styled(Link)<{ active?: boolean }>` + display: flex; + align-items: center; + flex-grow: 1; + height: 100%; + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + cursor: pointer; + appearance: none; + text-decoration: none; + user-select: none; + color: ${({ theme, active }) => + active ? theme.affine.palette.primary : 'unset'}; +`; + +export const TreeItemContent = styled('div')` + box-sizing: border-box; + width: 100%; + height: 32px; + position: relative; + display: flex; + align-items: center; + justify-content: space-around; + color: #4c6275; + padding-right: 0.5rem; + overflow: hidden; + + &:hover { + ${TreeItemMoreActions} { + visibility: visible; + cursor: pointer; + } + } +`;