Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: popover re-click position bug & drag panel drag bug #165

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/playground/src/helpers/mock-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const tangoConfigJson = {
},
'@music163/antd': {
description: '云音乐低代码中后台应用基础物料',
version: '0.2.5',
version: '0.2.6',
library: 'TangoAntd',
type: 'baseDependency',
resources: [
Expand Down
43 changes: 43 additions & 0 deletions apps/storybook/src/ui/drag-panel.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { DragPanel } from '@music163/tango-ui';
import { Box, Text } from 'coral-system';
import { Button } from 'antd';

export default {
title: 'UI/DragPanel',
};

export function Basic() {
return (
<DragPanel
title="弹层标题"
extra="右上角内容"
width={350}
body={<Box p="m">内容</Box>}
footer={<Text>底部信息</Text>}
>
<Button>点击唤起浮层</Button>
</DragPanel>
);
}

export function FooterCustom() {
return (
<DragPanel
title="弹层标题"
extra="右上角内容"
width={350}
body={<Box p="m">内容</Box>}
footer={(close) => (
<Box display="flex" justifyContent="space-between">
<Text>底部信息</Text>
<Button size="small" onClick={() => close()}>
点此关闭
</Button>
</Box>
)}
>
<Button>点击唤起浮层</Button>
</DragPanel>
);
}
27 changes: 25 additions & 2 deletions packages/ui/src/drag-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ import Draggable from 'react-draggable';
import { CloseOutlined } from '@ant-design/icons';
import { noop } from '@music163/tango-helpers';

// Dragging over an iframe stops dragging when moving the mouse too fast #613
// https://github.com/react-grid-layout/react-draggable/issues/613
const injectStyleToBody = () => {
const id = 'react-draggable-transparent-selection';
if (document.getElementById(id)) {
return;
}
const style = document.createElement('style');
style.id = id;
style.innerHTML = `
/* Prevent iframes from stealing drag events */
.react-draggable-transparent-selection iframe {
pointer-events: none;
}
`;
document.head.appendChild(style);
};

const CloseIcon = styled(CloseOutlined)`
cursor: pointer;
margin-left: 10px;
Expand All @@ -17,7 +35,7 @@ const CloseIcon = styled(CloseOutlined)`
}
`;

interface DragPanelProps extends Omit<PopoverProps, 'overlay'> {
interface DragPanelProps extends Omit<PopoverProps, 'overlay' | 'open'> {
// 标题
title?: React.ReactNode | string;
// 内容
Expand Down Expand Up @@ -59,7 +77,12 @@ export function DragPanel({
onOpenChange(innerOpen);
}}
overlay={
<Draggable handle=".selection-drag-bar">
<Draggable
handle=".selection-drag-bar"
onStart={() => {
injectStyleToBody();
}}
>
<Box
bg="#FFF"
borderRadius="m"
Expand Down
7 changes: 6 additions & 1 deletion packages/ui/src/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,19 @@ export const Popover: React.FC<PopoverProps> = ({
const handleClick = useCallback(
(e: React.MouseEvent) => {
e.preventDefault();
if (visible) {
setVisible(false);
onOpenChange(false);
return;
}
const x = e.clientX;
const y = e.clientY;
setLeft(x);
setTop(y + 10);
setVisible(true);
onOpenChange(true);
},
[onOpenChange],
[visible, onOpenChange],
);

useEffect(() => {
Expand Down
Loading