The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useGT } from "gt-react-native"; |
| 2 | import { View } from "react-native"; |
| 3 | |
| 4 | import { AppBar } from "./AppBar"; |
| 5 | import { NativeStackScreenOptions } from "../../native/StackHeader"; |
| 6 | import { Button } from "./Button"; |
| 7 | import { IconButton } from "./IconButton"; |
| 8 | import type { SheetCloseButtonProps, SheetHeaderProps } from "./SheetHeader.types"; |
| 9 | |
| 10 | export function SheetCloseButton(props: SheetCloseButtonProps) { |
| 11 | const gt = useGT(); |
| 12 | return ( |
| 13 | <IconButton |
| 14 | icon="xmark" |
| 15 | accessibilityLabel={props.accessibilityLabel ?? (props.onCancel ? gt("Cancel") : gt("Close"))} |
| 16 | disabled={props.disabled} |
| 17 | tintColorClassName="accent-header-foreground" |
| 18 | onPress={props.onCancel ?? props.onClose} |
| 19 | /> |
| 20 | ); |
| 21 | } |
| 22 | |
| 23 | export function SheetHeader(props: SheetHeaderProps) { |
| 24 | const confirmation = props.confirm; |
| 25 | const trailing = |
| 26 | props.trailing || confirmation ? ( |
| 27 | <View className="flex-row items-center gap-2"> |
| 28 | {props.trailing} |
| 29 | {confirmation ? ( |
| 30 | <Button |
| 31 | label={confirmation.label} |
| 32 | tone="text" |
| 33 | loading={confirmation.loading} |
| 34 | disabled={confirmation.disabled} |
| 35 | onPress={confirmation.onPress} |
| 36 | /> |
| 37 | ) : null} |
| 38 | </View> |
| 39 | ) : undefined; |
| 40 | |
| 41 | return ( |
| 42 | <> |
| 43 | {props.dismissDisabled === undefined ? null : ( |
| 44 | // A sheet that can't be closed with its button can't be swiped away either. |
| 45 | <NativeStackScreenOptions options={{ gestureEnabled: !props.dismissDisabled }} /> |
| 46 | )} |
| 47 | <AppBar |
| 48 | embedded |
| 49 | sheet={props.presentation === "inline"} |
| 50 | title={props.title} |
| 51 | subtitle={props.subtitle} |
| 52 | actions={props.actions} |
| 53 | menus={props.menus} |
| 54 | leading={ |
| 55 | <SheetCloseButton |
| 56 | {...(props.onCancel ? { onCancel: props.onCancel } : { onClose: props.onClose })} |
| 57 | accessibilityLabel={props.accessibilityLabel} |
| 58 | disabled={props.dismissDisabled} |
| 59 | /> |
| 60 | } |
| 61 | trailing={trailing} |
| 62 | hideBottomBorder |
| 63 | /> |
| 64 | </> |
| 65 | ); |
| 66 | } |