Skip to content

Commit 474b650

Browse files
authored
[react-events] Rename hook exports (#16533)
For example, 'useHoverResponder' becomes 'useHover'
1 parent 2f03aa6 commit 474b650

24 files changed

+259
-200
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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).

packages/react-events/docs/Focus.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
# Focus
22

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
44
are dispatched for all input types, with the exception of `onFocusVisibleChange`
55
which is only dispatched when focusing with a keyboard.
66

7-
Focus events do not propagate between `Focus` event responders.
7+
Focus events do not propagate between `useFocus` event responders.
88

99
```js
1010
// Example
1111
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+
});
1318

1419
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+
}}
1926
>
20-
<button
21-
children={props.children}
22-
style={{
23-
...(focusVisible && focusVisibleStyles)
24-
}}
25-
>
26-
</Focus>
2727
);
2828
};
2929
```
@@ -33,6 +33,8 @@ const Button = (props) => {
3333
```js
3434
type FocusEvent = {
3535
target: Element,
36+
pointerType: 'mouse' | 'touch' | 'pen' | 'keyboard',
37+
timeStamp: number,
3638
type: 'blur' | 'focus' | 'focuschange' | 'focusvisiblechange'
3739
}
3840
```
@@ -41,7 +43,7 @@ type FocusEvent = {
4143

4244
### disabled: boolean = false
4345

44-
Disables all `Focus` events.
46+
Disables the responder.
4547

4648
### onBlur: (e: FocusEvent) => void
4749

packages/react-events/docs/FocusWithin.md

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
11
# FocusWithin
22

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
44
are dispatched for all input types, with the exception of `onFocusVisibleChange`
55
which is only dispatched when focusing with a keyboard.
66

7-
Focus events do not propagate between `FocusWithin` event responders.
7+
Focus events do not propagate between `useFocusWithin` event responders.
88

99
```js
1010
// Example
1111
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+
});
1418

1519
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+
}}
1927
>
20-
<button
21-
children={props.children}
22-
style={{
23-
...(focusWithin && focusWithinStyles),
24-
...(focusWithinVisible && focusWithinVisibleStyles)
25-
}}
26-
>
27-
</FocusWithin>
2828
);
2929
};
3030
```
3131

32-
## Types
33-
34-
```js
35-
type FocusEvent = {
36-
target: Element,
37-
type: 'focuswithinchange' | 'focuswithinvisiblechange'
38-
}
39-
```
40-
4132
## Props
4233

4334
### disabled: boolean = false
4435

45-
Disables all `FocusWithin` events.
36+
Disables the responder.
4637

4738
### onFocusWithinChange: boolean => void
4839

packages/react-events/docs/Hover.md

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,57 @@
11
# Hover
22

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
44
events are only dispatched for `mouse` and `pen` pointer types. Hover begins
55
when the pointer enters the element's bounds and ends when the pointer leaves.
66

7-
Hover events do not propagate between `Hover` event responders.
7+
Hover events do not propagate between `useHover` event responders.
88

99
```js
1010
// Example
1111
const Link = (props) => (
12-
const [ hovered, setHovered ] = useState(false);
12+
const [ isHovered, setHovered ] = useState(false);
13+
const hover = useHover({
14+
onHoverChange: setHovered
15+
});
16+
1317
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+
/>
2427
);
2528
);
2629
```
2730

2831
## Types
2932

3033
```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,
3342
target: Element,
34-
type: 'hoverstart' | 'hoverend' | 'hovermove' | 'hoverchange'
35-
}
43+
timeStamp: number,
44+
type: HoverEventType,
45+
x: number,
46+
y: number,
47+
|};
3648
```
3749

3850
## Props
3951

4052
### disabled: boolean
4153

42-
Disables all `Hover` events.
54+
Disables the responder.
4355

4456
### onHoverChange: boolean => void
4557

packages/react-events/docs/Press.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
# Press
22

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
44
events are dispatched for `mouse`, `pen`, `touch`, `trackpad`, and `keyboard`
55
pointer types. Press events are only dispatched for keyboards when pressing the
66
Enter or Spacebar keys. If `onPress` is not called, this signifies that the
77
press ended outside of the element hit bounds (i.e., the user aborted the
88
press).
99

10-
Press events do not propagate between `Press` event responders.
10+
Press events do not propagate between `usePress` event responders.
1111

1212
```js
1313
// Example
1414
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+
1621
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+
/>
3132
);
3233
);
3334
```
@@ -37,6 +38,7 @@ const Button = (props) => (
3738
```js
3839
type PressEvent = {
3940
altKey: boolean,
41+
buttons: 0 | 1 | 4,
4042
ctrlKey: boolean,
4143
defaultPrevented: boolean,
4244
metaKey: boolean,
@@ -76,7 +78,7 @@ type PressOffset = {
7678

7779
### disabled: boolean = false
7880

79-
Disables all `Press` events.
81+
Disables the responder.
8082

8183
### onPress: (e: PressEvent) => void
8284

packages/react-events/src/dom/ContextMenu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const ContextMenuResponder = React.unstable_createResponder(
120120
contextMenuImpl,
121121
);
122122

123-
export function useContextMenuResponder(
123+
export function useContextMenu(
124124
props: ContextMenuProps,
125125
): ReactEventResponderListener<any, any> {
126126
return React.unstable_useResponder(ContextMenuResponder, props);

packages/react-events/src/dom/Drag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export const DragResponder = React.unstable_createResponder(
244244
dragResponderImpl,
245245
);
246246

247-
export function useDragResponder(
247+
export function useDrag(
248248
props: DragProps,
249249
): ReactEventResponderListener<any, any> {
250250
return React.unstable_useResponder(DragResponder, props);

packages/react-events/src/dom/Focus.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ export const FocusResponder = React.unstable_createResponder(
348348
focusResponderImpl,
349349
);
350350

351-
export function useFocusResponder(
351+
export function useFocus(
352352
props: FocusProps,
353353
): ReactEventResponderListener<any, any> {
354354
return React.unstable_useResponder(FocusResponder, props);
@@ -485,7 +485,7 @@ export const FocusWithinResponder = React.unstable_createResponder(
485485
focusWithinResponderImpl,
486486
);
487487

488-
export function useFocusWithinResponder(
488+
export function useFocusWithin(
489489
props: FocusWithinProps,
490490
): ReactEventResponderListener<any, any> {
491491
return React.unstable_useResponder(FocusWithinResponder, props);

packages/react-events/src/dom/Hover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export const HoverResponder = React.unstable_createResponder(
341341
hasPointerEvents ? hoverResponderImpl : hoverResponderFallbackImpl,
342342
);
343343

344-
export function useHoverResponder(
344+
export function useHover(
345345
props: HoverProps,
346346
): ReactEventResponderListener<any, any> {
347347
return React.unstable_useResponder(HoverResponder, props);

packages/react-events/src/dom/Input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export const InputResponder = React.unstable_createResponder(
215215
inputResponderImpl,
216216
);
217217

218-
export function useInputResponder(
218+
export function useInput(
219219
props: InputResponderProps,
220220
): ReactEventResponderListener<any, any> {
221221
return React.unstable_useResponder(InputResponder, props);

packages/react-events/src/dom/Keyboard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export const KeyboardResponder = React.unstable_createResponder(
209209
keyboardResponderImpl,
210210
);
211211

212-
export function useKeyboardResponder(
212+
export function useKeyboard(
213213
props: KeyboardProps,
214214
): ReactEventResponderListener<any, any> {
215215
return React.unstable_useResponder(KeyboardResponder, props);

packages/react-events/src/dom/Press.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ export const PressResponder = React.unstable_createResponder(
850850
pressResponderImpl,
851851
);
852852

853-
export function usePressResponder(
853+
export function usePress(
854854
props: PressProps,
855855
): ReactEventResponderListener<any, any> {
856856
return React.unstable_useResponder(PressResponder, props);

0 commit comments

Comments
 (0)