From 866408015e409664b4cb29444eccfd3eaef44a65 Mon Sep 17 00:00:00 2001 From: danielchim Date: Thu, 17 Aug 2023 01:48:13 +0800 Subject: [PATCH] fix: tooltip arrow (#3769) Co-authored-by: Alex Yang --- .../src/components/pure/help-island/index.tsx | 25 +++- .../src/components/workspace/index.css.ts | 3 + packages/component/src/ui/popper/popper.tsx | 113 ++++++++++++++++-- packages/component/src/ui/tooltip/tooltip.tsx | 15 +-- plugins/image-preview/src/component/index.tsx | 28 ++--- plugins/image-preview/src/component/toast.ts | 2 +- 6 files changed, 153 insertions(+), 33 deletions(-) diff --git a/apps/core/src/components/pure/help-island/index.tsx b/apps/core/src/components/pure/help-island/index.tsx index d5ecce0ae2..81196a3675 100644 --- a/apps/core/src/components/pure/help-island/index.tsx +++ b/apps/core/src/components/pure/help-island/index.tsx @@ -60,7 +60,11 @@ export const HelpIsland = ({ style={{ height: spread ? `${showList.length * 40 + 4}px` : 0 }} > {showList.includes('whatNew') && ( - + { @@ -72,7 +76,11 @@ export const HelpIsland = ({ )} {showList.includes('contact') && ( - + )} {showList.includes('shortcuts') && ( - + { @@ -98,6 +110,7 @@ export const HelpIsland = ({ - + diff --git a/packages/component/src/components/workspace/index.css.ts b/packages/component/src/components/workspace/index.css.ts index 8dc699da2c..98d382658c 100644 --- a/packages/component/src/components/workspace/index.css.ts +++ b/packages/component/src/components/workspace/index.css.ts @@ -103,6 +103,9 @@ export const toolStyle = style({ right: '30px', bottom: '30px', zIndex: 'var(--affine-z-index-popover)', + display: 'flex', + flexDirection: 'column', + gap: '12px', '@media': { [breakpoints.down('md', true)]: { right: 'calc((100vw - 640px) * 3 / 19 + 14px)', diff --git a/packages/component/src/ui/popper/popper.tsx b/packages/component/src/ui/popper/popper.tsx index bf53272dc8..04088b37c0 100644 --- a/packages/component/src/ui/popper/popper.tsx +++ b/packages/component/src/ui/popper/popper.tsx @@ -13,7 +13,6 @@ import { import { styled } from '../../styles'; import type { PopperProps, VirtualElement } from './interface'; -import { PopperArrow } from './popover-arrow'; export const Popper = ({ children, content, @@ -41,7 +40,8 @@ export const Popper = ({ }: PopperProps) => { const [anchorEl, setAnchorEl] = useState(); const [visible, setVisible] = useState(defaultVisible); - const [arrowRef, setArrowRef] = useState(); + //const [arrowRef, setArrowRef] = useState(); + const arrowRef = null; const pointerLeaveTimer = useRef(); const pointerEnterTimer = useRef(); @@ -170,12 +170,111 @@ export const Popper = ({ } }} > - {showArrow && ( - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - + {showArrow ? ( + <> + {placement.indexOf('bottom') === 0 ? ( +
+ + + + {content} +
+ ) : placement.indexOf('top') === 0 ? ( +
+ {content} + + + +
+ ) : placement.indexOf('left') === 0 ? ( + <> + {content} + + + + + ) : placement.indexOf('right') === 0 ? ( + <> + + + + {content} + + ) : ( +
+ {content} + + + +
+ )} + + ) : ( + <>{content} )} - {content} )} diff --git a/packages/component/src/ui/tooltip/tooltip.tsx b/packages/component/src/ui/tooltip/tooltip.tsx index 3b5e43b32a..c2a94a5d9e 100644 --- a/packages/component/src/ui/tooltip/tooltip.tsx +++ b/packages/component/src/ui/tooltip/tooltip.tsx @@ -7,15 +7,16 @@ import StyledPopperContainer from '../shared/container'; const StyledTooltip = styled(StyledPopperContainer)(() => { return { - maxWidth: '320px', - boxShadow: 'var(--affine-float-button-shadow)', - padding: '4px 12px', + display: 'inline-flex', + height: '38px', + flexDirection: 'column', + justifyContent: 'center', + alignItems: 'center', + flexShrink: 0, backgroundColor: 'var(--affine-tooltip)', + borderRadius: '4px', color: 'var(--affine-white)', - fontSize: 'var(--affine-font-sm)', - borderRadius: '8px', - marginBottom: '12px', - overflowWrap: 'break-word', + padding: '5px 12px', }; }); diff --git a/plugins/image-preview/src/component/index.tsx b/plugins/image-preview/src/component/index.tsx index 33dc34cf34..6d89f9359c 100644 --- a/plugins/image-preview/src/component/index.tsx +++ b/plugins/image-preview/src/component/index.tsx @@ -336,7 +336,7 @@ const ImagePreviewModalImpl = ( ) : null}
- + } @@ -348,7 +348,7 @@ const ImagePreviewModalImpl = ( }} /> - + } @@ -362,11 +362,7 @@ const ImagePreviewModalImpl = (
- + } @@ -375,7 +371,7 @@ const ImagePreviewModalImpl = ( onClick={() => resetZoom()} /> - + } @@ -384,7 +380,7 @@ const ImagePreviewModalImpl = ( onClick={zoomOut} /> - +