diff --git a/libs/components/editor-core/src/block-pendant/BlockPendantProvider.tsx b/libs/components/editor-core/src/block-pendant/BlockPendantProvider.tsx index bda4e2d2bb..877c4e451a 100644 --- a/libs/components/editor-core/src/block-pendant/BlockPendantProvider.tsx +++ b/libs/components/editor-core/src/block-pendant/BlockPendantProvider.tsx @@ -1,6 +1,6 @@ import type { FC, PropsWithChildren } from 'react'; -import React, { useState, useRef } from 'react'; -import { styled, Popover } from '@toeverything/components/ui'; +import React, { useState } from 'react'; +import { styled } from '@toeverything/components/ui'; import type { AsyncBlock } from '../editor'; import { PendantPopover } from './pendant-popover'; import { PendantRender } from './pendant-render'; @@ -19,12 +19,22 @@ export const BlockPendantProvider: FC> = ({ children, }) => { const [container, setContainer] = useState(null); + const [isHover, setIsHover] = useState(false); return ( setContainer(dom)}> {children} {container && ( - - + { + setIsHover(visible); + }} + > + )} @@ -35,27 +45,40 @@ export const BlockPendantProvider: FC> = ({ const Container = styled('div')({ position: 'relative', padding: '4px', - '&:hover .triggerLine::after': { + '&:hover .triggerLine::before': { display: 'flex', }, }); -const TriggerLine = styled('div')` - padding: 4px 0; - width: 100px; - cursor: default; - display: flex; - align-items: flex-end; - position: relative; - //background: red; - ::after { - content: ''; - width: 100%; - height: 2px; - background: #d9d9d9; - display: none; - position: absolute; - left: 0; - top: 4px; - } -`; +const StyledTriggerLine = styled('div')<{ isHover: boolean }>(({ isHover }) => { + return { + padding: '4px 0', + width: '100px', + cursor: 'default', + display: 'flex', + alignItems: 'flex-end', + position: 'relative', + + '::before': { + content: "''", + width: '100%', + height: '2px', + background: '#dadada', + display: 'none', + position: 'absolute', + left: '0', + top: '4px', + }, + '::after': { + content: "''", + width: isHover ? '100%' : '0', + height: '2px', + background: '#aac4d5', + display: 'block', + position: 'absolute', + left: '0', + top: '4px', + transition: 'width .3s', + }, + }; +}); diff --git a/libs/components/editor-core/src/block-pendant/pendant-popover/PendantPopover.tsx b/libs/components/editor-core/src/block-pendant/pendant-popover/PendantPopover.tsx index f10310c5e2..13a0ccbfb6 100644 --- a/libs/components/editor-core/src/block-pendant/pendant-popover/PendantPopover.tsx +++ b/libs/components/editor-core/src/block-pendant/pendant-popover/PendantPopover.tsx @@ -1,15 +1,19 @@ import React, { FC, useRef } from 'react'; import { AsyncBlock } from '../../editor'; import { PendantHistoryPanel } from '../pendant-history-panel'; -import { Popover, type PopperHandler } from '@toeverything/components/ui'; +import { + Popover, + type PopperHandler, + PopperProps, +} from '@toeverything/components/ui'; import { AddPendantPopover } from '../AddPendantPopover'; -export const PendantPopover: FC<{ - block: AsyncBlock; - container: HTMLElement; - children?: React.ReactElement; -}> = props => { - const { block, children, container } = props; +export const PendantPopover: FC< + { + block: AsyncBlock; + } & Omit +> = props => { + const { block, ...popoverProps } = props; const popoverHandlerRef = useRef(); return ( - {children} - + {...popoverProps} + /> ); }; diff --git a/libs/components/ui/src/popper/Popper.tsx b/libs/components/ui/src/popper/Popper.tsx index b0ca996864..f74cf89980 100644 --- a/libs/components/ui/src/popper/Popper.tsx +++ b/libs/components/ui/src/popper/Popper.tsx @@ -6,8 +6,6 @@ import React, { useRef, useState, } from 'react'; -import type { PropsWithChildren } from 'react'; - import { MuiPopper, MuiClickAwayListener as ClickAwayListener, @@ -18,7 +16,7 @@ import { styled } from '../styled'; import { PopperProps, PopperHandler, VirtualElement } from './interface'; import { useTheme } from '../theme'; import { PopperArrow } from './PopoverArrow'; -export const Popper = forwardRef>( +export const Popper = forwardRef( ( { children, diff --git a/libs/components/ui/src/popper/interface.ts b/libs/components/ui/src/popper/interface.ts index 6c41b70369..9f52cf551f 100644 --- a/libs/components/ui/src/popper/interface.ts +++ b/libs/components/ui/src/popper/interface.ts @@ -17,6 +17,10 @@ export type PopperArrowProps = { export type PopperProps = { // Popover content content: ReactNode; + + // Popover trigger + children?: ReactNode; + // Position of Popover placement?: PopperPlacementType;