Add optional props to Prompt.Action (#9887)

This commit is contained in:
DS Boyce
2026-02-16 13:29:25 -08:00
committed by GitHub
parent 82f42e734c
commit 29bc0f1372
+29 -4
View File
@@ -4,8 +4,14 @@ import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {atoms as a, useTheme, type ViewStyleProp, web} from '#/alf' import {atoms as a, useTheme, type ViewStyleProp, web} from '#/alf'
import {Button, type ButtonColor, ButtonText} from '#/components/Button' import {
Button,
type ButtonColor,
ButtonIcon,
ButtonText,
} from '#/components/Button'
import * as Dialog from '#/components/Dialog' import * as Dialog from '#/components/Dialog'
import {type Props as SVGIconProps} from '#/components/icons/common'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
import {type BottomSheetViewProps} from '../../modules/bottom-sheet' import {type BottomSheetViewProps} from '../../modules/bottom-sheet'
@@ -126,7 +132,7 @@ export function Cancel({
<Button <Button
variant="solid" variant="solid"
color="secondary" color="secondary"
size={'large'} size="large"
label={cta || _(msg`Cancel`)} label={cta || _(msg`Cancel`)}
onPress={onPress}> onPress={onPress}>
<ButtonText>{cta || _(msg`Cancel`)}</ButtonText> <ButtonText>{cta || _(msg`Cancel`)}</ButtonText>
@@ -138,6 +144,9 @@ export function Action({
onPress, onPress,
color = 'primary', color = 'primary',
cta, cta,
disabled = false,
icon,
shouldCloseOnPress,
testID, testID,
}: { }: {
/** /**
@@ -153,25 +162,41 @@ export function Action({
* Optional i18n string. If undefined, it will default to "Confirm". * Optional i18n string. If undefined, it will default to "Confirm".
*/ */
cta?: string cta?: string
/**
* If undefined, it will default to false.
*/
disabled?: boolean
icon?: React.ComponentType<SVGIconProps>
/**
* Optionally close dialog automatically on press. If undefined, it will
* default to true.
*/
shouldCloseOnPress?: boolean
testID?: string testID?: string
}) { }) {
const {_} = useLingui() const {_} = useLingui()
const {close} = Dialog.useDialogContext() const {close} = Dialog.useDialogContext()
const handleOnPress = useCallback( const handleOnPress = useCallback(
(e: GestureResponderEvent) => { (e: GestureResponderEvent) => {
if (shouldCloseOnPress) {
close(() => onPress?.(e)) close(() => onPress?.(e))
} else {
onPress?.(e)
}
}, },
[close, onPress], [close, onPress, shouldCloseOnPress],
) )
return ( return (
<Button <Button
color={color} color={color}
size={'large'} disabled={disabled}
size="large"
label={cta || _(msg`Confirm`)} label={cta || _(msg`Confirm`)}
onPress={handleOnPress} onPress={handleOnPress}
testID={testID}> testID={testID}>
<ButtonText>{cta || _(msg`Confirm`)}</ButtonText> <ButtonText>{cta || _(msg`Confirm`)}</ButtonText>
{icon && <ButtonIcon icon={icon} />}
</Button> </Button>
) )
} }