-
Notifications
You must be signed in to change notification settings - Fork 360
feat(dialog): add sizeDraggable to props #3875
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
base: develop
Are you sure you want to change the base?
Changes from 3 commits
fb20b7b
8b53c6f
5bfe008
67bc72b
0145f5f
c049de5
ce96eb5
dc558d6
51ad547
1b33898
de1e364
ad769b8
95de3df
11b3bbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,217 @@ | ||||||
| import React from "react"; | ||||||
| import useMouseEvent from "../../hooks/useMouseEvent"; | ||||||
| import { DialogSizeDragLimit } from "../type"; | ||||||
|
|
||||||
|
|
||||||
| const RESIZE_BORDER_WIDTH = 8; // 边框宽度,拖拽时的感应区域 | ||||||
|
|
||||||
|
|
||||||
| interface DialogResizeProps { | ||||||
| dialogCardRef: React.MutableRefObject<HTMLDivElement | null>; | ||||||
| sizeDraggableProps: boolean | DialogSizeDragLimit; | ||||||
| onDragResizeChange: (resizing: boolean) => void; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| type ResizeDirection = 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 'sw' | false; | ||||||
|
|
||||||
|
|
||||||
| function mouseOnBorder( | ||||||
| e: React.MouseEvent, | ||||||
| dialogCardRef: React.MutableRefObject<HTMLDivElement | null> | ||||||
| ): ResizeDirection { | ||||||
| const mouseX = e.clientX; | ||||||
| const mouseY = e.clientY; | ||||||
| const { left, top, width, height } = dialogCardRef.current.getBoundingClientRect(); | ||||||
|
|
||||||
| const borderWidth = RESIZE_BORDER_WIDTH; | ||||||
| const onLeftBorder = mouseX >= left - borderWidth && mouseX <= left + borderWidth; | ||||||
| const onRightBorder = mouseX >= left + width - borderWidth && mouseX <= left + width + borderWidth; | ||||||
| const onTopBorder = mouseY >= top - borderWidth && mouseY <= top + borderWidth; | ||||||
| const onBottomBorder = mouseY >= top + height - borderWidth && mouseY <= top + height + borderWidth; | ||||||
| if (onLeftBorder && onTopBorder) | ||||||
| return 'nw'; | ||||||
|
||||||
| if (onRightBorder && onBottomBorder) | ||||||
| return 'se'; | ||||||
| if (onRightBorder && onTopBorder) | ||||||
| return 'ne'; | ||||||
| if (onLeftBorder && onBottomBorder) | ||||||
| return 'sw'; | ||||||
| if (onLeftBorder) | ||||||
| return 'w'; | ||||||
| if (onRightBorder) | ||||||
| return 'e'; | ||||||
| if (onTopBorder) | ||||||
| return 'n'; | ||||||
| if (onBottomBorder) | ||||||
| return 's'; | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| const useDialogResize = (props: DialogResizeProps) => { | ||||||
| const { dialogCardRef, sizeDraggableProps } = props; | ||||||
|
|
||||||
| const validWindow = typeof window === 'object'; | ||||||
|
|
||||||
| const getWindowHeight = () => (validWindow ? window.innerHeight || document.documentElement.clientHeight : undefined); | ||||||
| const getWindowWidth = () => (validWindow ? window.innerWidth || document.documentElement.clientWidth : undefined); | ||||||
|
|
||||||
| const dialogSize = React.useRef({ x: 0, y: 0, width: 0, height: 0 }); | ||||||
|
|
||||||
| const resizingDirection = React.useRef<ResizeDirection>(false); | ||||||
|
|
||||||
| const minWidth = React.useRef(0); | ||||||
| const maxWidth = React.useRef(Number.MAX_VALUE); | ||||||
| const minHeight = React.useRef<number|undefined>(undefined); // If undefined, set to current height on first drag (lower than which causes buttons overflow). | ||||||
FlowerBlackG marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| const maxHeight = React.useRef(Number.MAX_VALUE); | ||||||
|
|
||||||
|
|
||||||
| React.useEffect(() => { | ||||||
| if (sizeDraggableProps === undefined || typeof sizeDraggableProps === 'boolean') { | ||||||
| minWidth.current = undefined; | ||||||
| maxWidth.current = Number.MAX_VALUE; | ||||||
| minHeight.current = 0; | ||||||
|
||||||
| minHeight.current = 0; | |
| minHeight.current = undefined; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来没有习惯一键格式化代码...缺少空格 const { style }
Uh oh!
There was an error while loading. Please reload this page.