fix: inline menu position (#433)

This commit is contained in:
DiamondThree
2022-09-16 16:28:43 +08:00
committed by GitHub
parent 6ce3a7f705
commit d2bd896367
2 changed files with 15 additions and 11 deletions
@@ -1,12 +1,7 @@
import { useState, useEffect } from 'react'; import { MuiGrow as Grow, styled } from '@toeverything/components/ui';
import { Protocol } from '@toeverything/datasource/db-service'; import { Protocol } from '@toeverything/datasource/db-service';
import { import { SelectionInfo, Virgo } from '@toeverything/framework/virgo';
MuiClickAwayListener as ClickAwayListener, import { useEffect, useState } from 'react';
MuiGrow as Grow,
styled,
} from '@toeverything/components/ui';
import { Virgo, SelectionInfo } from '@toeverything/framework/virgo';
import { InlineMenuToolbar } from './Toolbar'; import { InlineMenuToolbar } from './Toolbar';
export type InlineMenuContainerProps = { export type InlineMenuContainerProps = {
@@ -47,11 +42,18 @@ export const InlineMenuContainer = ({ editor }: InlineMenuContainerProps) => {
// This is relative to window // This is relative to window
const rect = browserSelection.getRangeAt(0).getBoundingClientRect(); const rect = browserSelection.getRangeAt(0).getBoundingClientRect();
const { top, left } = editor.container.getBoundingClientRect();
const { top, left, right } =
editor.container.getBoundingClientRect();
let menuLeft = rect.left - left;
if (right - rect.right < 500) {
// If the inline-menu is further away from the right than the button itself, a scroll bar will appear
menuLeft -= 500;
}
setSelectionInfo(info); setSelectionInfo(info);
setShowMenu(true); setShowMenu(true);
setContainerStyle({ setContainerStyle({
left: rect.left - left, left: menuLeft,
top: rect.top - top - 64, top: rect.top - top - 64,
}); });
}); });
@@ -89,6 +91,6 @@ const ToolbarContainer = styled('div')(({ theme }) => ({
alignItems: 'center', alignItems: 'center',
padding: '0 12px', padding: '0 12px',
borderRadius: '10px', borderRadius: '10px',
boxShadow: theme.affine.shadows.shadow1, boxShadow: theme.affine.shadows.shadow3,
backgroundColor: '#fff', backgroundColor: '#fff',
})); }));
+2
View File
@@ -237,6 +237,8 @@ export const Theme = {
'0px 1px 10px -6px rgba(24, 39, 75, 0.08), 0px 3px 16px -6px rgba(24, 39, 75, 0.04)', '0px 1px 10px -6px rgba(24, 39, 75, 0.08), 0px 3px 16px -6px rgba(24, 39, 75, 0.04)',
shadow2: shadow2:
'0px 6px 16px -8px rgba(0,0,0,0.08), 0px 9px 14px 0px rgba(0,0,0,0.05), 0px 12px 24px 16px rgba(0,0,0,0.03)', '0px 6px 16px -8px rgba(0,0,0,0.08), 0px 9px 14px 0px rgba(0,0,0,0.05), 0px 12px 24px 16px rgba(0,0,0,0.03)',
shadow3:
'0px 1px 10px -6px rgb(24 39 75 / 50%), 0px 3px 16px -6px rgb(24 39 75 / 30%)',
}, },
border: ['none'], border: ['none'],
spacing: { spacing: {