GeezerVison is showing github.com — [react-events] Rename hook exports (#16533) · react/react@474b650
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +54Lines changed: 54 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# ContextMenu | | 2 | + | | 3 | +The `useContextMenu` hooks responds to context-menu events. | | 4 | + | | 5 | +```js | | 6 | +// Example | | 7 | +const Button = (props) => { | | 8 | + const contextmenu = useContextMenu({ | | 9 | + disabled, | | 10 | + onContextMenu, | | 11 | + preventDefault | | 12 | + }); | | 13 | + | | 14 | + return ( | | 15 | + <div listeners={contextmenu}> | | 16 | + {props.children} | | 17 | + </div> | | 18 | + ); | | 19 | +}; | | 20 | +``` | | 21 | + | | 22 | +## Types | | 23 | + | | 24 | +```js | | 25 | +type ContextMenuEvent = { | | 26 | + altKey: boolean, | | 27 | + buttons: 0 | 1 | 2, | | 28 | + ctrlKey: boolean, | | 29 | + metaKey: boolean, | | 30 | + pageX: number, | | 31 | + pageY: number, | | 32 | + pointerType: PointerType, | | 33 | + shiftKey: boolean, | | 34 | + target: Element, | | 35 | + timeStamp: number, | | 36 | + type: 'contextmenu', | | 37 | + x: number, | | 38 | + y: number, | | 39 | +} | | 40 | +``` | | 41 | + | | 42 | +## Props | | 43 | + | | 44 | +### disabled: boolean = false | | 45 | + | | 46 | +Disables the responder. | | 47 | + | | 48 | +### onContextMenu: (e: ContextMenuEvent) => void | | 49 | + | | 50 | +Called when the user performs a gesture to display a context menu. | | 51 | + | | 52 | +### preventDefault: boolean = true | | 53 | + | | 54 | +Prevents the native behavior (i.e., context menu). |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/docs/Focus.md +17-15Lines changed: 17 additions & 15 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | # Focus | 2 | 2 |
| 3 | | -The `Focus` module responds to focus and blur events on its child. Focus events | | 3 | +The `useFocus` hook responds to focus and blur events on its child. Focus events | 4 | 4 | are dispatched for all input types, with the exception of `onFocusVisibleChange` | 5 | 5 | which is only dispatched when focusing with a keyboard. | 6 | 6 |
| 7 | | -Focus events do not propagate between `Focus` event responders. | | 7 | +Focus events do not propagate between `useFocus` event responders. | 8 | 8 |
| 9 | 9 | ```js | 10 | 10 | // Example | 11 | 11 | const Button = (props) => { | 12 | | - const [ focusVisible, setFocusVisible ] = useState(false); | | 12 | + const [ isFocusVisible, setFocusVisible ] = useState(false); | | 13 | + const focus = useFocus({ | | 14 | + onBlur={props.onBlur} | | 15 | + onFocus={props.onFocus} | | 16 | + onFocusVisibleChange={setFocusVisible} | | 17 | + }); | 13 | 18 |
| 14 | 19 | return ( | 15 | | - <Focus | 16 | | - onBlur={props.onBlur} | 17 | | - onFocus={props.onFocus} | 18 | | - onFocusVisibleChange={setFocusVisible} | | 20 | + <button | | 21 | + children={props.children} | | 22 | + listeners={focus} | | 23 | + style={{ | | 24 | + ...(isFocusVisible && focusVisibleStyles) | | 25 | + }} | 19 | 26 | > | 20 | | - <button | 21 | | - children={props.children} | 22 | | - style={{ | 23 | | - ...(focusVisible && focusVisibleStyles) | 24 | | - }} | 25 | | - > | 26 | | - </Focus> | 27 | 27 | ); | 28 | 28 | }; | 29 | 29 | ``` | @@ -33,6 +33,8 @@ const Button = (props) => { | 33 | 33 | ```js | 34 | 34 | type FocusEvent = { | 35 | 35 | target: Element, | | 36 | + pointerType: 'mouse' | 'touch' | 'pen' | 'keyboard', | | 37 | + timeStamp: number, | 36 | 38 | type: 'blur' | 'focus' | 'focuschange' | 'focusvisiblechange' | 37 | 39 | } | 38 | 40 | ``` | @@ -41,7 +43,7 @@ type FocusEvent = { | 41 | 43 |
| 42 | 44 | ### disabled: boolean = false | 43 | 45 |
| 44 | | -Disables all `Focus` events. | | 46 | +Disables the responder. | 45 | 47 |
| 46 | 48 | ### onBlur: (e: FocusEvent) => void | 47 | 49 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/docs/FocusWithin.md +16-25Lines changed: 16 additions & 25 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | # FocusWithin | 2 | 2 |
| 3 | | -The `FocusWithin` module responds to focus and blur events on its child. Focus events | | 3 | +The `useFocusWithin` hooks responds to focus and blur events on its child. Focus events | 4 | 4 | are dispatched for all input types, with the exception of `onFocusVisibleChange` | 5 | 5 | which is only dispatched when focusing with a keyboard. | 6 | 6 |
| 7 | | -Focus events do not propagate between `FocusWithin` event responders. | | 7 | +Focus events do not propagate between `useFocusWithin` event responders. | 8 | 8 |
| 9 | 9 | ```js | 10 | 10 | // Example | 11 | 11 | const Button = (props) => { | 12 | | - const [ focusWithin, updateFocusWithin ] = useState(false); | 13 | | - const [ focusWithinVisible, updateFocusWithinVisible ] = useState(false); | | 12 | + const [ isFocusWithin, updateFocusWithin ] = useState(false); | | 13 | + const [ isFocusWithinVisible, updateFocusWithinVisible ] = useState(false); | | 14 | + const focusWithin = useFocusWithin({ | | 15 | + onFocusWithinChange={updateFocusWithin} | | 16 | + onFocusWithinVisibleChange={updateFocusWithinVisible} | | 17 | + }); | 14 | 18 |
| 15 | 19 | return ( | 16 | | - <FocusWithin | 17 | | - onFocusWithinChange={updateFocusWithin} | 18 | | - onFocusWithinVisibleChange={updateFocusWithinVisible} | | 20 | + <button | | 21 | + children={props.children} | | 22 | + listeners={focusWithin} | | 23 | + style={{ | | 24 | + ...(isFocusWithin && focusWithinStyles), | | 25 | + ...(isFocusWithinVisible && focusWithinVisibleStyles) | | 26 | + }} | 19 | 27 | > | 20 | | - <button | 21 | | - children={props.children} | 22 | | - style={{ | 23 | | - ...(focusWithin && focusWithinStyles), | 24 | | - ...(focusWithinVisible && focusWithinVisibleStyles) | 25 | | - }} | 26 | | - > | 27 | | - </FocusWithin> | 28 | 28 | ); | 29 | 29 | }; | 30 | 30 | ``` | 31 | 31 |
| 32 | | -## Types | 33 | | - | 34 | | -```js | 35 | | -type FocusEvent = { | 36 | | - target: Element, | 37 | | - type: 'focuswithinchange' | 'focuswithinvisiblechange' | 38 | | -} | 39 | | -``` | 40 | | - | 41 | 32 | ## Props | 42 | 33 |
| 43 | 34 | ### disabled: boolean = false | 44 | 35 |
| 45 | | -Disables all `FocusWithin` events. | | 36 | +Disables the responder. | 46 | 37 |
| 47 | 38 | ### onFocusWithinChange: boolean => void | 48 | 39 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/docs/Hover.md +30-18Lines changed: 30 additions & 18 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | # Hover | 2 | 2 |
| 3 | | -The `Hover` module responds to hover events on the element it wraps. Hover | | 3 | +The `useHover` hook responds to hover events on the element it wraps. Hover | 4 | 4 | events are only dispatched for `mouse` and `pen` pointer types. Hover begins | 5 | 5 | when the pointer enters the element's bounds and ends when the pointer leaves. | 6 | 6 |
| 7 | | -Hover events do not propagate between `Hover` event responders. | | 7 | +Hover events do not propagate between `useHover` event responders. | 8 | 8 |
| 9 | 9 | ```js | 10 | 10 | // Example | 11 | 11 | const Link = (props) => ( | 12 | | - const [ hovered, setHovered ] = useState(false); | | 12 | + const [ isHovered, setHovered ] = useState(false); | | 13 | + const hover = useHover({ | | 14 | + onHoverChange: setHovered | | 15 | + }); | | 16 | + | 13 | 17 | return ( | 14 | | - <Hover onHoverChange={setHovered}> | 15 | | - <a | 16 | | - {...props} | 17 | | - href={props.href} | 18 | | - style={{ | 19 | | - ...props.style, | 20 | | - textDecoration: hovered ? 'underline': 'none' | 21 | | - }} | 22 | | - /> | 23 | | - </Hover> | | 18 | + <a | | 19 | + {...props} | | 20 | + href={props.href} | | 21 | + listeners={hover} | | 22 | + style={{ | | 23 | + ...props.style, | | 24 | + textDecoration: isHovered ? 'underline': 'none' | | 25 | + }} | | 26 | + /> | 24 | 27 | ); | 25 | 28 | ); | 26 | 29 | ``` | 27 | 30 |
| 28 | 31 | ## Types | 29 | 32 |
| 30 | 33 | ```js | 31 | | -type HoverEvent = { | 32 | | - pointerType: 'mouse' | 'pen', | | 34 | +type HoverEventType = 'hoverstart' | 'hoverend' | 'hoverchange' | 'hovermove'; | | 35 | + | | 36 | +type HoverEvent = {| | | 37 | + clientX: number, | | 38 | + clientY: number, | | 39 | + pageX: number, | | 40 | + pageY: number, | | 41 | + pointerType: PointerType, | 33 | 42 | target: Element, | 34 | | - type: 'hoverstart' | 'hoverend' | 'hovermove' | 'hoverchange' | 35 | | -} | | 43 | + timeStamp: number, | | 44 | + type: HoverEventType, | | 45 | + x: number, | | 46 | + y: number, | | 47 | +|}; | 36 | 48 | ``` | 37 | 49 |
| 38 | 50 | ## Props | 39 | 51 |
| 40 | 52 | ### disabled: boolean | 41 | 53 |
| 42 | | -Disables all `Hover` events. | | 54 | +Disables the responder. | 43 | 55 |
| 44 | 56 | ### onHoverChange: boolean => void | 45 | 57 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/docs/Press.md +20-18Lines changed: 20 additions & 18 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | # Press | 2 | 2 |
| 3 | | -The `Press` module responds to press events on the element it wraps. Press | | 3 | +The `usePress` hook responds to press events on the element it wraps. Press | 4 | 4 | events are dispatched for `mouse`, `pen`, `touch`, `trackpad`, and `keyboard` | 5 | 5 | pointer types. Press events are only dispatched for keyboards when pressing the | 6 | 6 | Enter or Spacebar keys. If `onPress` is not called, this signifies that the | 7 | 7 | press ended outside of the element hit bounds (i.e., the user aborted the | 8 | 8 | press). | 9 | 9 |
| 10 | | -Press events do not propagate between `Press` event responders. | | 10 | +Press events do not propagate between `usePress` event responders. | 11 | 11 |
| 12 | 12 | ```js | 13 | 13 | // Example | 14 | 14 | const Button = (props) => ( | 15 | | - const [ pressed, setPressed ] = useState(false); | | 15 | + const [ isPressed, setPressed ] = useState(false); | | 16 | + const press = usePress({ | | 17 | + onPress={props.onPress} | | 18 | + onPressChange={setPressed} | | 19 | + }); | | 20 | + | 16 | 21 | return ( | 17 | | - <Press | 18 | | - onPress={props.onPress} | 19 | | - onPressChange={setPressed} | 20 | | - > | 21 | | - <div | 22 | | - {...props} | 23 | | - role="button" | 24 | | - tabIndex={0} | 25 | | - style={ | 26 | | - ...buttonStyles, | 27 | | - ...(pressed && pressedStyles) | 28 | | - }} | 29 | | - /> | 30 | | - </Press> | | 22 | + <div | | 23 | + {...props} | | 24 | + listeners={press} | | 25 | + role="button" | | 26 | + tabIndex={0} | | 27 | + style={ | | 28 | + ...buttonStyles, | | 29 | + ...(isPressed && pressedStyles) | | 30 | + }} | | 31 | + /> | 31 | 32 | ); | 32 | 33 | ); | 33 | 34 | ``` | @@ -37,6 +38,7 @@ const Button = (props) => ( | 37 | 38 | ```js | 38 | 39 | type PressEvent = { | 39 | 40 | altKey: boolean, | | 41 | + buttons: 0 | 1 | 4, | 40 | 42 | ctrlKey: boolean, | 41 | 43 | defaultPrevented: boolean, | 42 | 44 | metaKey: boolean, | @@ -76,7 +78,7 @@ type PressOffset = { | 76 | 78 |
| 77 | 79 | ### disabled: boolean = false | 78 | 80 |
| 79 | | -Disables all `Press` events. | | 81 | +Disables the responder. | 80 | 82 |
| 81 | 83 | ### onPress: (e: PressEvent) => void | 82 | 84 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/src/dom/ContextMenu.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -120,7 +120,7 @@ export const ContextMenuResponder = React.unstable_createResponder( | 120 | 120 | contextMenuImpl, | 121 | 121 | ); | 122 | 122 |
| 123 | | -export function useContextMenuResponder( | | 123 | +export function useContextMenu( | 124 | 124 | props: ContextMenuProps, | 125 | 125 | ): ReactEventResponderListener<any, any> { | 126 | 126 | return React.unstable_useResponder(ContextMenuResponder, props); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/src/dom/Drag.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -244,7 +244,7 @@ export const DragResponder = React.unstable_createResponder( | 244 | 244 | dragResponderImpl, | 245 | 245 | ); | 246 | 246 |
| 247 | | -export function useDragResponder( | | 247 | +export function useDrag( | 248 | 248 | props: DragProps, | 249 | 249 | ): ReactEventResponderListener<any, any> { | 250 | 250 | return React.unstable_useResponder(DragResponder, props); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/src/dom/Focus.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -348,7 +348,7 @@ export const FocusResponder = React.unstable_createResponder( | 348 | 348 | focusResponderImpl, | 349 | 349 | ); | 350 | 350 |
| 351 | | -export function useFocusResponder( | | 351 | +export function useFocus( | 352 | 352 | props: FocusProps, | 353 | 353 | ): ReactEventResponderListener<any, any> { | 354 | 354 | return React.unstable_useResponder(FocusResponder, props); | @@ -485,7 +485,7 @@ export const FocusWithinResponder = React.unstable_createResponder( | 485 | 485 | focusWithinResponderImpl, | 486 | 486 | ); | 487 | 487 |
| 488 | | -export function useFocusWithinResponder( | | 488 | +export function useFocusWithin( | 489 | 489 | props: FocusWithinProps, | 490 | 490 | ): ReactEventResponderListener<any, any> { | 491 | 491 | return React.unstable_useResponder(FocusWithinResponder, props); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/src/dom/Hover.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -341,7 +341,7 @@ export const HoverResponder = React.unstable_createResponder( | 341 | 341 | hasPointerEvents ? hoverResponderImpl : hoverResponderFallbackImpl, | 342 | 342 | ); | 343 | 343 |
| 344 | | -export function useHoverResponder( | | 344 | +export function useHover( | 345 | 345 | props: HoverProps, | 346 | 346 | ): ReactEventResponderListener<any, any> { | 347 | 347 | return React.unstable_useResponder(HoverResponder, props); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/src/dom/Input.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -215,7 +215,7 @@ export const InputResponder = React.unstable_createResponder( | 215 | 215 | inputResponderImpl, | 216 | 216 | ); | 217 | 217 |
| 218 | | -export function useInputResponder( | | 218 | +export function useInput( | 219 | 219 | props: InputResponderProps, | 220 | 220 | ): ReactEventResponderListener<any, any> { | 221 | 221 | return React.unstable_useResponder(InputResponder, props); | |
|