mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-03 02:20:19 +08:00
feat: add animate in trigger, resolved #529
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import type { FC, PropsWithChildren } from 'react';
|
import type { FC, PropsWithChildren } from 'react';
|
||||||
import React, { useState, useRef } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { styled, Popover } from '@toeverything/components/ui';
|
import { styled } from '@toeverything/components/ui';
|
||||||
import type { AsyncBlock } from '../editor';
|
import type { AsyncBlock } from '../editor';
|
||||||
import { PendantPopover } from './pendant-popover';
|
import { PendantPopover } from './pendant-popover';
|
||||||
import { PendantRender } from './pendant-render';
|
import { PendantRender } from './pendant-render';
|
||||||
@@ -19,12 +19,22 @@ export const BlockPendantProvider: FC<PropsWithChildren<BlockTagProps>> = ({
|
|||||||
children,
|
children,
|
||||||
}) => {
|
}) => {
|
||||||
const [container, setContainer] = useState<HTMLElement>(null);
|
const [container, setContainer] = useState<HTMLElement>(null);
|
||||||
|
const [isHover, setIsHover] = useState(false);
|
||||||
return (
|
return (
|
||||||
<Container ref={(dom: HTMLElement) => setContainer(dom)}>
|
<Container ref={(dom: HTMLElement) => setContainer(dom)}>
|
||||||
{children}
|
{children}
|
||||||
{container && (
|
{container && (
|
||||||
<PendantPopover block={block} container={container}>
|
<PendantPopover
|
||||||
<TriggerLine className="triggerLine" />
|
block={block}
|
||||||
|
container={container}
|
||||||
|
onVisibleChange={visible => {
|
||||||
|
setIsHover(visible);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<StyledTriggerLine
|
||||||
|
className="triggerLine"
|
||||||
|
isHover={isHover}
|
||||||
|
/>
|
||||||
</PendantPopover>
|
</PendantPopover>
|
||||||
)}
|
)}
|
||||||
<PendantRender block={block} />
|
<PendantRender block={block} />
|
||||||
@@ -35,27 +45,40 @@ export const BlockPendantProvider: FC<PropsWithChildren<BlockTagProps>> = ({
|
|||||||
const Container = styled('div')({
|
const Container = styled('div')({
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
padding: '4px',
|
padding: '4px',
|
||||||
'&:hover .triggerLine::after': {
|
'&:hover .triggerLine::before': {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const TriggerLine = styled('div')`
|
const StyledTriggerLine = styled('div')<{ isHover: boolean }>(({ isHover }) => {
|
||||||
padding: 4px 0;
|
return {
|
||||||
width: 100px;
|
padding: '4px 0',
|
||||||
cursor: default;
|
width: '100px',
|
||||||
display: flex;
|
cursor: 'default',
|
||||||
align-items: flex-end;
|
display: 'flex',
|
||||||
position: relative;
|
alignItems: 'flex-end',
|
||||||
//background: red;
|
position: 'relative',
|
||||||
::after {
|
|
||||||
content: '';
|
'::before': {
|
||||||
width: 100%;
|
content: "''",
|
||||||
height: 2px;
|
width: '100%',
|
||||||
background: #d9d9d9;
|
height: '2px',
|
||||||
display: none;
|
background: '#dadada',
|
||||||
position: absolute;
|
display: 'none',
|
||||||
left: 0;
|
position: 'absolute',
|
||||||
top: 4px;
|
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',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
import React, { FC, useRef } from 'react';
|
import React, { FC, useRef } from 'react';
|
||||||
import { AsyncBlock } from '../../editor';
|
import { AsyncBlock } from '../../editor';
|
||||||
import { PendantHistoryPanel } from '../pendant-history-panel';
|
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';
|
import { AddPendantPopover } from '../AddPendantPopover';
|
||||||
|
|
||||||
export const PendantPopover: FC<{
|
export const PendantPopover: FC<
|
||||||
block: AsyncBlock;
|
{
|
||||||
container: HTMLElement;
|
block: AsyncBlock;
|
||||||
children?: React.ReactElement;
|
} & Omit<PopperProps, 'content'>
|
||||||
}> = props => {
|
> = props => {
|
||||||
const { block, children, container } = props;
|
const { block, ...popoverProps } = props;
|
||||||
const popoverHandlerRef = useRef<PopperHandler>();
|
const popoverHandlerRef = useRef<PopperHandler>();
|
||||||
return (
|
return (
|
||||||
<Popover
|
<Popover
|
||||||
@@ -17,7 +21,6 @@ export const PendantPopover: FC<{
|
|||||||
pointerEnterDelay={300}
|
pointerEnterDelay={300}
|
||||||
pointerLeaveDelay={200}
|
pointerLeaveDelay={200}
|
||||||
placement="bottom-start"
|
placement="bottom-start"
|
||||||
container={container}
|
|
||||||
// visible={true}
|
// visible={true}
|
||||||
// trigger="click"
|
// trigger="click"
|
||||||
content={
|
content={
|
||||||
@@ -37,9 +40,8 @@ export const PendantPopover: FC<{
|
|||||||
}
|
}
|
||||||
offset={[0, 0]}
|
offset={[0, 0]}
|
||||||
style={popoverContainerStyle}
|
style={popoverContainerStyle}
|
||||||
>
|
{...popoverProps}
|
||||||
{children}
|
/>
|
||||||
</Popover>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import React, {
|
|||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import type { PropsWithChildren } from 'react';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MuiPopper,
|
MuiPopper,
|
||||||
MuiClickAwayListener as ClickAwayListener,
|
MuiClickAwayListener as ClickAwayListener,
|
||||||
@@ -18,7 +16,7 @@ import { styled } from '../styled';
|
|||||||
import { PopperProps, PopperHandler, VirtualElement } from './interface';
|
import { PopperProps, PopperHandler, VirtualElement } from './interface';
|
||||||
import { useTheme } from '../theme';
|
import { useTheme } from '../theme';
|
||||||
import { PopperArrow } from './PopoverArrow';
|
import { PopperArrow } from './PopoverArrow';
|
||||||
export const Popper = forwardRef<PopperHandler, PropsWithChildren<PopperProps>>(
|
export const Popper = forwardRef<PopperHandler, PopperProps>(
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
children,
|
children,
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ export type PopperArrowProps = {
|
|||||||
export type PopperProps = {
|
export type PopperProps = {
|
||||||
// Popover content
|
// Popover content
|
||||||
content: ReactNode;
|
content: ReactNode;
|
||||||
|
|
||||||
|
// Popover trigger
|
||||||
|
children?: ReactNode;
|
||||||
|
|
||||||
// Position of Popover
|
// Position of Popover
|
||||||
placement?: PopperPlacementType;
|
placement?: PopperPlacementType;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user