Bluesky app fork with some witchin' additions 💫 witchsky.app
bluesky fork client

Add optional props to Prompt.Action (#9887)

authored by

DS Boyce and committed by
GitHub
29bc0f13 82f42e73

+30 -5
+30 -5
src/components/Prompt.tsx
··· 4 4 import {useLingui} from '@lingui/react' 5 5 6 6 import {atoms as a, useTheme, type ViewStyleProp, web} from '#/alf' 7 - import {Button, type ButtonColor, ButtonText} from '#/components/Button' 7 + import { 8 + Button, 9 + type ButtonColor, 10 + ButtonIcon, 11 + ButtonText, 12 + } from '#/components/Button' 8 13 import * as Dialog from '#/components/Dialog' 14 + import {type Props as SVGIconProps} from '#/components/icons/common' 9 15 import {Text} from '#/components/Typography' 10 16 import {type BottomSheetViewProps} from '../../modules/bottom-sheet' 11 17 ··· 126 132 <Button 127 133 variant="solid" 128 134 color="secondary" 129 - size={'large'} 135 + size="large" 130 136 label={cta || _(msg`Cancel`)} 131 137 onPress={onPress}> 132 138 <ButtonText>{cta || _(msg`Cancel`)}</ButtonText> ··· 138 144 onPress, 139 145 color = 'primary', 140 146 cta, 147 + disabled = false, 148 + icon, 149 + shouldCloseOnPress, 141 150 testID, 142 151 }: { 143 152 /** ··· 153 162 * Optional i18n string. If undefined, it will default to "Confirm". 154 163 */ 155 164 cta?: string 165 + /** 166 + * If undefined, it will default to false. 167 + */ 168 + disabled?: boolean 169 + icon?: React.ComponentType<SVGIconProps> 170 + /** 171 + * Optionally close dialog automatically on press. If undefined, it will 172 + * default to true. 173 + */ 174 + shouldCloseOnPress?: boolean 156 175 testID?: string 157 176 }) { 158 177 const {_} = useLingui() 159 178 const {close} = Dialog.useDialogContext() 160 179 const handleOnPress = useCallback( 161 180 (e: GestureResponderEvent) => { 162 - close(() => onPress?.(e)) 181 + if (shouldCloseOnPress) { 182 + close(() => onPress?.(e)) 183 + } else { 184 + onPress?.(e) 185 + } 163 186 }, 164 - [close, onPress], 187 + [close, onPress, shouldCloseOnPress], 165 188 ) 166 189 167 190 return ( 168 191 <Button 169 192 color={color} 170 - size={'large'} 193 + disabled={disabled} 194 + size="large" 171 195 label={cta || _(msg`Confirm`)} 172 196 onPress={handleOnPress} 173 197 testID={testID}> 174 198 <ButtonText>{cta || _(msg`Confirm`)}</ButtonText> 199 + {icon && <ButtonIcon icon={icon} />} 175 200 </Button> 176 201 ) 177 202 }