diff options
author | Eric Bailey <git@esb.lol> | 2024-08-19 14:21:29 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-19 12:21:29 -0700 |
commit | e54298ec2c9a04aabe40ee7719962e2e33be23ec (patch) | |
tree | 7b042cb6cea29dbc0c1a37af6949cc5ec452dae2 /src/components/Menu/index.tsx | |
parent | f235be9819286c38e7c76142a62d39e22a7746d1 (diff) | |
download | voidsky-e54298ec2c9a04aabe40ee7719962e2e33be23ec.tar.zst |
Expose more methods, support disabled items (#4954)
Diffstat (limited to 'src/components/Menu/index.tsx')
-rw-r--r-- | src/components/Menu/index.tsx | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/components/Menu/index.tsx b/src/components/Menu/index.tsx index 3be69b348..a0a21a50f 100644 --- a/src/components/Menu/index.tsx +++ b/src/components/Menu/index.tsx @@ -9,7 +9,7 @@ import {atoms as a, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import {useInteractionState} from '#/components/hooks/useInteractionState' -import {Context} from '#/components/Menu/context' +import {Context, ItemContext} from '#/components/Menu/context' import { ContextType, GroupProps, @@ -125,8 +125,14 @@ export function Item({children, label, style, onPress, ...rest}: ItemProps) { }} onFocus={onFocus} onBlur={onBlur} - onPressIn={onPressIn} - onPressOut={onPressOut} + onPressIn={e => { + onPressIn() + rest.onPressIn?.(e) + }} + onPressOut={e => { + onPressOut() + rest.onPressOut?.(e) + }} style={[ a.flex_row, a.align_center, @@ -138,15 +144,18 @@ export function Item({children, label, style, onPress, ...rest}: ItemProps) { t.atoms.border_contrast_low, {minHeight: 44, paddingVertical: 10}, style, - (focused || pressed) && [t.atoms.bg_contrast_50], + (focused || pressed) && !rest.disabled && [t.atoms.bg_contrast_50], ]}> - {children} + <ItemContext.Provider value={{disabled: Boolean(rest.disabled)}}> + {children} + </ItemContext.Provider> </Pressable> ) } export function ItemText({children, style}: ItemTextProps) { const t = useTheme() + const {disabled} = React.useContext(ItemContext) return ( <Text numberOfLines={1} @@ -155,9 +164,10 @@ export function ItemText({children, style}: ItemTextProps) { a.flex_1, a.text_md, a.font_bold, - t.atoms.text_contrast_medium, + t.atoms.text_contrast_high, {paddingTop: 3}, style, + disabled && t.atoms.text_contrast_low, ]}> {children} </Text> @@ -166,7 +176,17 @@ export function ItemText({children, style}: ItemTextProps) { export function ItemIcon({icon: Comp}: ItemIconProps) { const t = useTheme() - return <Comp size="lg" fill={t.atoms.text_contrast_medium.color} /> + const {disabled} = React.useContext(ItemContext) + return ( + <Comp + size="lg" + fill={ + disabled + ? t.atoms.text_contrast_low.color + : t.atoms.text_contrast_medium.color + } + /> + ) } export function Group({children, style}: GroupProps) { |