-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
On hold - V3 splitview followup #37
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6dce1d1
Change aria-valuenow to accurately reflect aria standards, addressed …
snowystinger f55abb3
Merge branch 'master' into splitview-followup
snowystinger 7654ce7
Add RTL support
snowystinger 1ab8e10
add comment
snowystinger faf1b0f
add in the focus ring
snowystinger 31cc3f3
move types around, fix linting
snowystinger 75e5910
one more lint
snowystinger b4a37b4
Allow useControlledState to accept a callback for it's `setValue` fun…
snowystinger 4c91d18
Add a few more tests because the behavior is a little strange compare…
snowystinger fb38f2d
Merge branch 'master' into splitview-followup
snowystinger ef99449
remove unused dependency
snowystinger d2a303b
Code review changes!
snowystinger 15834b0
Merge branch 'master' into splitview-followup
snowystinger b70c569
Merge branch 'master' into splitview-followup
snowystinger e0deb1c
fix linter
snowystinger 7493eae
Merge branch 'master' into splitview-followup
snowystinger 5a10ab7
Merge branch 'splitview-followup' of github.com:adobe/react-spectrum …
snowystinger 63d6e11
Fix missing deps
snowystinger 0fffc8a
Merge branch 'master' into v3-splitview-followup
snowystinger 73d39b6
brutal merging
snowystinger d86781d
Merge commit 'ee7cbcbd355ca27f93c76de29ac0588d9a75b282' into v3-split…
snowystinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import {AllHTMLAttributes, MutableRefObject, useRef} from 'react'; | ||
import {flipAxis, orientation, point} from '@react-types/shared'; | ||
|
||
interface UseMoveableProps { | ||
containerRef: MutableRefObject<HTMLElement>, | ||
flipAxis?: flipAxis, | ||
onHover?: (hovered: boolean) => void, | ||
onDrag?: (dragging: boolean) => void, | ||
onPositionChange?: (relativePosition: point) => void, | ||
onIncrement?: (axis: orientation) => void, | ||
onDecrement?: (axis: orientation) => void, | ||
onIncrementToMax?: () => void, | ||
onDecrementToMin?: () => void, | ||
onCollapseToggle?: () => void | ||
} | ||
|
||
// handles movement in x and y either as | ||
// relative position of cursor to a container | ||
// or as keyboard events | ||
|
||
export function useMoveable({containerRef, flipAxis, onHover, onDrag, onPositionChange, onIncrement, onDecrement, onIncrementToMax, onDecrementToMin, onCollapseToggle}: UseMoveableProps): AllHTMLAttributes<HTMLElement> { | ||
let getPosition = (e):point => ({x: e.clientX, y: e.clientY}); | ||
let calculateCoordinateDistances = (element, position:point):point => { | ||
let rect = element.getBoundingClientRect(); | ||
switch (flipAxis) { | ||
case 'x': | ||
return {x: position.x - rect.left, y: rect.bottom - position.y}; | ||
case 'y': | ||
return {x: rect.right - position.x, y: position.y - rect.top}; | ||
case 'xy': | ||
return {x: rect.right - position.x, y: rect.bottom - position.y}; | ||
default: | ||
return {x: position.x - rect.left, y: position.y - rect.top}; | ||
} | ||
}; | ||
let getNextDistance = (e):point => { | ||
let mousePosition = getPosition(e); | ||
let nextOffset = calculateCoordinateDistances(containerRef.current, mousePosition); | ||
return nextOffset; | ||
}; | ||
let dragging = useRef<boolean>(false); | ||
let prevPosition = useRef<point>({x: 0, y: 0}); | ||
|
||
let onMouseDragged = (e) => { | ||
e.preventDefault(); | ||
let nextOffset = getNextDistance(e); | ||
if (!dragging.current) { | ||
dragging.current = true; | ||
if (onDrag) { | ||
onDrag(true); | ||
} | ||
if (onPositionChange) { | ||
onPositionChange(nextOffset); | ||
} | ||
} | ||
if (prevPosition.current === nextOffset) { | ||
return; | ||
} | ||
prevPosition.current = nextOffset; | ||
if (onPositionChange) { | ||
onPositionChange(nextOffset); | ||
} | ||
}; | ||
|
||
let onMouseUp = (e) => { | ||
dragging.current = false; | ||
let nextOffset = getNextDistance(e); | ||
if (onDrag) { | ||
onDrag(false); | ||
} | ||
if (onPositionChange) { | ||
onPositionChange(nextOffset); | ||
} | ||
window.removeEventListener('mouseup', onMouseUp, false); | ||
window.removeEventListener('mousemove', onMouseDragged, false); | ||
}; | ||
|
||
let onMouseDown = () => { | ||
window.addEventListener('mousemove', onMouseDragged, false); | ||
window.addEventListener('mouseup', onMouseUp, false); | ||
}; | ||
|
||
let onMouseEnter = () => { | ||
if (onHover) { | ||
onHover(true); | ||
} | ||
}; | ||
|
||
let onMouseOut = () => { | ||
if (onHover) { | ||
onHover(false); | ||
} | ||
}; | ||
|
||
let onKeyDown = (e) => { | ||
switch (e.key) { | ||
case 'Left': | ||
case 'ArrowLeft': | ||
if (onDecrement && (!flipAxis || !flipAxis.includes('y'))) { | ||
onDecrement('horizontal'); | ||
} else if (onIncrement && (flipAxis && flipAxis.includes('y'))) { | ||
onIncrement('horizontal'); | ||
} | ||
break; | ||
case 'Up': | ||
case 'ArrowUp': | ||
if (onDecrement && (!flipAxis || !flipAxis.includes('x'))) { | ||
onDecrement('vertical'); | ||
} else if (onIncrement && (flipAxis && flipAxis.includes('x'))) { | ||
onIncrement('vertical'); | ||
} | ||
break; | ||
case 'Right': | ||
case 'ArrowRight': | ||
if (onIncrement && (!flipAxis || !flipAxis.includes('y'))) { | ||
onIncrement('horizontal'); | ||
} else if (onDecrement && (flipAxis && flipAxis.includes('y'))) { | ||
onDecrement('horizontal'); | ||
} | ||
break; | ||
case 'Down': | ||
case 'ArrowDown': | ||
if (onIncrement && (!flipAxis || !flipAxis.includes('x'))) { | ||
onIncrement('vertical'); | ||
} else if (onDecrement && (flipAxis && flipAxis.includes('x'))) { | ||
onDecrement('vertical'); | ||
} | ||
break; | ||
case 'Home': | ||
if (onDecrementToMin) { | ||
onDecrementToMin(); | ||
} | ||
e.preventDefault(); | ||
break; | ||
case 'End': | ||
if (onIncrementToMax) { | ||
onIncrementToMax(); | ||
} | ||
e.preventDefault(); | ||
break; | ||
case 'Enter': | ||
if (onCollapseToggle) { | ||
onCollapseToggle(); | ||
} | ||
e.preventDefault(); | ||
break; | ||
} | ||
}; | ||
|
||
return {onMouseDown, onMouseEnter, onMouseOut, onKeyDown}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Shouldn't you deconstruct the props as below?