Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: add animate in trigger, resolved #529

qishaoxuana7c76c0bce28
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<PropsWithChildren<BlockTagProps>> = ({
children,
}) => {
const [container, setContainer] = useState<HTMLElement>(null);
+ const [isHover, setIsHover] = useState(false);
return (
<Container ref={(dom: HTMLElement) => setContainer(dom)}>
{children}
{container && (
- <PendantPopover block={block} container={container}>
- <TriggerLine className="triggerLine" />
+ <PendantPopover
+ block={block}
+ container={container}
+ onVisibleChange={visible => {
+ setIsHover(visible);
+ }}
+ >
+ <StyledTriggerLine
+ className="triggerLine"
+ isHover={isHover}
+ />
</PendantPopover>
)}
<PendantRender block={block} />
@@ -35,27 +45,40 @@ export const BlockPendantProvider: FC<PropsWithChildren<BlockTagProps>> = ({
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<PopperProps, 'content'>
+> = props => {
+ const { block, ...popoverProps } = props;
const popoverHandlerRef = useRef<PopperHandler>();
return (
<Popover
@@ -17,7 +21,6 @@ export const PendantPopover: FC<{
pointerEnterDelay={300}
pointerLeaveDelay={200}
placement="bottom-start"
- container={container}
// visible={true}
// trigger="click"
content={
@@ -37,9 +40,8 @@ export const PendantPopover: FC<{
}
offset={[0, 0]}
style={popoverContainerStyle}
- >
- {children}
- </Popover>
+ {...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<PopperHandler, PropsWithChildren<PopperProps>>(
+export const Popper = forwardRef<PopperHandler, PopperProps>(
(
{
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;