Expose more props from button (#4953)

zio/stable
Eric Bailey 2024-08-19 13:27:04 -05:00 committed by GitHub
parent 3976d6738b
commit f235be9819
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 55 additions and 25 deletions

View File

@ -1,6 +1,8 @@
import React from 'react' import React from 'react'
import { import {
AccessibilityProps, AccessibilityProps,
GestureResponderEvent,
MouseEvent,
Pressable, Pressable,
PressableProps, PressableProps,
StyleProp, StyleProp,
@ -65,7 +67,15 @@ type NonTextElements =
export type ButtonProps = Pick< export type ButtonProps = Pick<
PressableProps, PressableProps,
'disabled' | 'onPress' | 'testID' | 'onLongPress' | 'hitSlop' | 'disabled'
| 'onPress'
| 'testID'
| 'onLongPress'
| 'hitSlop'
| 'onHoverIn'
| 'onHoverOut'
| 'onPressIn'
| 'onPressOut'
> & > &
AccessibilityProps & AccessibilityProps &
VariantProps & { VariantProps & {
@ -115,30 +125,50 @@ export const Button = React.forwardRef<View, ButtonProps>(
focused: false, focused: false,
}) })
const onPressIn = React.useCallback(() => { const onPressInOuter = rest.onPressIn
const onPressIn = React.useCallback(
(e: GestureResponderEvent) => {
setState(s => ({ setState(s => ({
...s, ...s,
pressed: true, pressed: true,
})) }))
}, [setState]) onPressInOuter?.(e)
const onPressOut = React.useCallback(() => { },
[setState, onPressInOuter],
)
const onPressOutOuter = rest.onPressOut
const onPressOut = React.useCallback(
(e: GestureResponderEvent) => {
setState(s => ({ setState(s => ({
...s, ...s,
pressed: false, pressed: false,
})) }))
}, [setState]) onPressOutOuter?.(e)
const onHoverIn = React.useCallback(() => { },
[setState, onPressOutOuter],
)
const onHoverInOuter = rest.onHoverIn
const onHoverIn = React.useCallback(
(e: MouseEvent) => {
setState(s => ({ setState(s => ({
...s, ...s,
hovered: true, hovered: true,
})) }))
}, [setState]) onHoverInOuter?.(e)
const onHoverOut = React.useCallback(() => { },
[setState, onHoverInOuter],
)
const onHoverOutOuter = rest.onHoverOut
const onHoverOut = React.useCallback(
(e: MouseEvent) => {
setState(s => ({ setState(s => ({
...s, ...s,
hovered: false, hovered: false,
})) }))
}, [setState]) onHoverOutOuter?.(e)
},
[setState, onHoverOutOuter],
)
const onFocus = React.useCallback(() => { const onFocus = React.useCallback(() => {
setState(s => ({ setState(s => ({
...s, ...s,