Rename handlers to props
This commit is contained in:
@@ -2,7 +2,6 @@ import React from 'react'
|
|||||||
import {View, Pressable} from 'react-native'
|
import {View, Pressable} from 'react-native'
|
||||||
import flattenReactChildren from 'react-keyed-flatten-children'
|
import flattenReactChildren from 'react-keyed-flatten-children'
|
||||||
|
|
||||||
import {logger} from '#/logger'
|
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
import {useInteractionState} from '#/components/hooks/useInteractionState'
|
import {useInteractionState} from '#/components/hooks/useInteractionState'
|
||||||
@@ -50,7 +49,7 @@ export function Trigger({children, label}: TriggerProps) {
|
|||||||
onOut: onPressOut,
|
onOut: onPressOut,
|
||||||
} = useInteractionState()
|
} = useInteractionState()
|
||||||
|
|
||||||
const child = children({
|
return children({
|
||||||
isNative: true,
|
isNative: true,
|
||||||
control,
|
control,
|
||||||
state: {
|
state: {
|
||||||
@@ -58,26 +57,15 @@ export function Trigger({children, label}: TriggerProps) {
|
|||||||
focused,
|
focused,
|
||||||
pressed,
|
pressed,
|
||||||
},
|
},
|
||||||
handlers: {
|
props: {
|
||||||
onPress: control.open,
|
onPress: control.open,
|
||||||
onFocus,
|
onFocus,
|
||||||
onBlur,
|
onBlur,
|
||||||
onPressIn,
|
onPressIn,
|
||||||
onPressOut,
|
onPressOut,
|
||||||
|
accessibilityLabel: label,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!React.isValidElement(child)) {
|
|
||||||
logger.error(
|
|
||||||
'Menu.Trigger children must be a function that returns a valid element',
|
|
||||||
)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return React.cloneElement(child, {
|
|
||||||
...child.props,
|
|
||||||
accessibilityLabel: label,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Outer({children}: React.PropsWithChildren<{}>) {
|
export function Outer({children}: React.PropsWithChildren<{}>) {
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ export function Trigger({children, label, style}: TriggerProps) {
|
|||||||
focused,
|
focused,
|
||||||
pressed: false,
|
pressed: false,
|
||||||
},
|
},
|
||||||
handlers: {},
|
props: {},
|
||||||
})}
|
})}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</DropdownMenu.Trigger>
|
</DropdownMenu.Trigger>
|
||||||
|
|||||||
@@ -25,12 +25,20 @@ export type TriggerChildProps =
|
|||||||
focused: boolean
|
focused: boolean
|
||||||
pressed: boolean
|
pressed: boolean
|
||||||
}
|
}
|
||||||
handlers: {
|
/**
|
||||||
|
* We don't necessarily know what these will be spread on to, so we
|
||||||
|
* should add props one-by-one.
|
||||||
|
*
|
||||||
|
* On web, these properties are applied to a parent `Pressable`, so this
|
||||||
|
* object is empty.
|
||||||
|
*/
|
||||||
|
props: {
|
||||||
onPress: () => void
|
onPress: () => void
|
||||||
onFocus: () => void
|
onFocus: () => void
|
||||||
onBlur: () => void
|
onBlur: () => void
|
||||||
onPressIn: () => void
|
onPressIn: () => void
|
||||||
onPressOut: () => void
|
onPressOut: () => void
|
||||||
|
accessibilityLabel: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
@@ -44,7 +52,7 @@ export type TriggerChildProps =
|
|||||||
*/
|
*/
|
||||||
pressed: false
|
pressed: false
|
||||||
}
|
}
|
||||||
handlers: {}
|
props: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO test id
|
// TODO test id
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ export function Menus() {
|
|||||||
<View style={[a.flex_row, a.align_start]}>
|
<View style={[a.flex_row, a.align_start]}>
|
||||||
<Menu.Root control={menuControl}>
|
<Menu.Root control={menuControl}>
|
||||||
<Menu.Trigger label="Open basic menu" style={[a.flex_1]}>
|
<Menu.Trigger label="Open basic menu" style={[a.flex_1]}>
|
||||||
{({state, handlers}) => {
|
{({state, props}) => {
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
{...handlers}
|
{...props}
|
||||||
style={[
|
style={[
|
||||||
a.py_sm,
|
a.py_sm,
|
||||||
a.px_md,
|
a.px_md,
|
||||||
|
|||||||
Reference in New Issue
Block a user