mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat: add button only show on hover, resolved #526
This commit is contained in:
@@ -1,30 +1,38 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
import React, {useRef, useState} from 'react';
|
||||||
import { AsyncBlock } from '../../editor';
|
import {AsyncBlock} from '../../editor';
|
||||||
import {
|
import {
|
||||||
getRecastItemValue,
|
getRecastItemValue,
|
||||||
PropertyType,
|
|
||||||
RecastBlockValue,
|
RecastBlockValue,
|
||||||
RecastMetaProperty,
|
RecastMetaProperty,
|
||||||
useRecastBlockMeta,
|
useRecastBlockMeta,
|
||||||
} from '../../recast-block';
|
} from '../../recast-block';
|
||||||
import { Popover, PopperHandler, styled } from '@toeverything/components/ui';
|
import {
|
||||||
import { PendantTag } from '../PendantTag';
|
MuiZoom,
|
||||||
|
Popover,
|
||||||
|
PopperHandler,
|
||||||
|
styled,
|
||||||
|
} from '@toeverything/components/ui';
|
||||||
|
import {PendantTag} from '../PendantTag';
|
||||||
|
import {
|
||||||
|
UpdatePendantPanel
|
||||||
|
} from '../pendant-operation-panel';
|
||||||
|
import {AddPendantPopover} from '../AddPendantPopover';
|
||||||
|
|
||||||
import { defaultPendantColors } from '../config';
|
export const PendantRender = ({block}: { block: AsyncBlock }) => {
|
||||||
import { UpdatePendantPanel } from '../pendant-operation-panel';
|
|
||||||
import { AddPendantPopover } from '../AddPendantPopover';
|
|
||||||
import { PendantTypes } from '../types';
|
|
||||||
|
|
||||||
export const PendantRender = ({ block }: { block: AsyncBlock }) => {
|
|
||||||
const [propertyWithValue, setPropertyWithValue] = useState<{
|
const [propertyWithValue, setPropertyWithValue] = useState<{
|
||||||
value: RecastBlockValue;
|
value: RecastBlockValue;
|
||||||
property: RecastMetaProperty;
|
property: RecastMetaProperty;
|
||||||
}>();
|
}>();
|
||||||
const popoverHandlerRef = useRef<{ [key: string]: PopperHandler }>({});
|
const popoverHandlerRef = useRef<{ [key: string]: PopperHandler }>({});
|
||||||
|
const blockRenderContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
const [showAddBtn, setShowAddBtn] = useState(false);
|
||||||
|
|
||||||
const { getProperties } = useRecastBlockMeta();
|
const {getProperties} = useRecastBlockMeta();
|
||||||
|
|
||||||
const { getValue, removeValue } = getRecastItemValue(block);
|
const {
|
||||||
|
getValue,
|
||||||
|
removeValue
|
||||||
|
} = getRecastItemValue(block);
|
||||||
|
|
||||||
const properties = getProperties();
|
const properties = getProperties();
|
||||||
|
|
||||||
@@ -38,9 +46,17 @@ export const PendantRender = ({ block }: { block: AsyncBlock }) => {
|
|||||||
.filter(v => v.value);
|
.filter(v => v.value);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BlockPendantContainer>
|
<BlockPendantContainer
|
||||||
|
ref={blockRenderContainerRef}
|
||||||
|
onPointerEnter={() => {
|
||||||
|
setShowAddBtn(true);
|
||||||
|
}}
|
||||||
|
onPointerLeave={() => {
|
||||||
|
setShowAddBtn(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
{propertyWithValues.map(pWithV => {
|
{propertyWithValues.map(pWithV => {
|
||||||
const { id, type } = pWithV.value;
|
const {id, type} = pWithV.value;
|
||||||
|
|
||||||
/* (暂时关闭,HOOK中需要加入Scene的判断)Remove duplicate label(tag) */
|
/* (暂时关闭,HOOK中需要加入Scene的判断)Remove duplicate label(tag) */
|
||||||
// if (groupBy?.id === id) {
|
// if (groupBy?.id === id) {
|
||||||
@@ -52,6 +68,7 @@ export const PendantRender = ({ block }: { block: AsyncBlock }) => {
|
|||||||
ref={ref => {
|
ref={ref => {
|
||||||
popoverHandlerRef.current[id] = ref;
|
popoverHandlerRef.current[id] = ref;
|
||||||
}}
|
}}
|
||||||
|
container={blockRenderContainerRef.current}
|
||||||
key={id}
|
key={id}
|
||||||
trigger="click"
|
trigger="click"
|
||||||
placement="bottom-start"
|
placement="bottom-start"
|
||||||
@@ -96,7 +113,15 @@ export const PendantRender = ({ block }: { block: AsyncBlock }) => {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
{propertyWithValues.length ? (
|
{propertyWithValues.length ? (
|
||||||
<AddPendantPopover block={block} iconStyle={{ marginTop: 5 }} />
|
<MuiZoom in={showAddBtn}>
|
||||||
|
<div>
|
||||||
|
<AddPendantPopover
|
||||||
|
block={block}
|
||||||
|
iconStyle={{marginTop: 4}}
|
||||||
|
container={blockRenderContainerRef.current}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</MuiZoom>
|
||||||
) : null}
|
) : null}
|
||||||
</BlockPendantContainer>
|
</BlockPendantContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,55 +4,54 @@
|
|||||||
|
|
||||||
/* eslint-disable no-restricted-imports */
|
/* eslint-disable no-restricted-imports */
|
||||||
|
|
||||||
import {
|
|
||||||
Box,
|
|
||||||
Collapse,
|
|
||||||
IconButton,
|
|
||||||
CircularProgress,
|
|
||||||
Divider,
|
|
||||||
Typography,
|
|
||||||
Menu,
|
|
||||||
MenuItem,
|
|
||||||
Avatar,
|
|
||||||
Popover,
|
|
||||||
TextField,
|
|
||||||
Modal,
|
|
||||||
Button,
|
|
||||||
List,
|
|
||||||
ListItem,
|
|
||||||
ListItemText,
|
|
||||||
Tooltip,
|
|
||||||
tooltipClasses,
|
|
||||||
Tabs,
|
|
||||||
Tab,
|
|
||||||
OutlinedInput,
|
|
||||||
InputAdornment,
|
|
||||||
Grow,
|
|
||||||
Paper,
|
|
||||||
MenuList,
|
|
||||||
ClickAwayListener,
|
|
||||||
Popper,
|
|
||||||
Select,
|
|
||||||
Switch,
|
|
||||||
Grid,
|
|
||||||
Container,
|
|
||||||
Snackbar,
|
|
||||||
InputBase,
|
|
||||||
FormControlLabel,
|
|
||||||
Checkbox,
|
|
||||||
Input,
|
|
||||||
Radio,
|
|
||||||
Zoom,
|
|
||||||
} from '@mui/material';
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
DividerProps,
|
||||||
PopoverProps,
|
PopoverProps,
|
||||||
PopperPlacementType,
|
PopperPlacementType,
|
||||||
SelectChangeEvent,
|
SelectChangeEvent,
|
||||||
TooltipProps,
|
TooltipProps,
|
||||||
DividerProps,
|
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { ListItemButton } from '@mui/material';
|
import {
|
||||||
|
Avatar,
|
||||||
|
Box,
|
||||||
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
CircularProgress,
|
||||||
|
ClickAwayListener,
|
||||||
|
Collapse,
|
||||||
|
Container,
|
||||||
|
Divider,
|
||||||
|
FormControlLabel,
|
||||||
|
Grid,
|
||||||
|
Grow,
|
||||||
|
IconButton,
|
||||||
|
Input,
|
||||||
|
InputAdornment,
|
||||||
|
InputBase,
|
||||||
|
List,
|
||||||
|
ListItem,
|
||||||
|
ListItemButton,
|
||||||
|
ListItemText,
|
||||||
|
Menu,
|
||||||
|
MenuItem,
|
||||||
|
MenuList,
|
||||||
|
Modal,
|
||||||
|
OutlinedInput,
|
||||||
|
Paper,
|
||||||
|
Popover,
|
||||||
|
Popper,
|
||||||
|
Radio,
|
||||||
|
Select,
|
||||||
|
Snackbar,
|
||||||
|
Switch,
|
||||||
|
Tab,
|
||||||
|
Tabs,
|
||||||
|
TextField,
|
||||||
|
Tooltip,
|
||||||
|
tooltipClasses,
|
||||||
|
Typography,
|
||||||
|
Zoom,
|
||||||
|
} from '@mui/material';
|
||||||
|
|
||||||
export { alpha } from '@mui/system';
|
export { alpha } from '@mui/system';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user