The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { MenuAction } from "@react-native-menu/menu"; |
| 2 | import { msg, useGT, useMessages } from "gt-react-native"; |
| 3 | import { Pressable } from "react-native"; |
| 4 | |
| 5 | import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing"; |
| 6 | import { SymbolView } from "../../components/ui/AppSymbol"; |
| 7 | import { Menu } from "../../components/ui/Menu"; |
| 8 | |
| 9 | const ATTACHMENT_MENU_ACTIONS: MenuAction[] = [ |
| 10 | { id: "photos", title: msg("Photo Library"), image: "photo" }, |
| 11 | { id: "files", title: msg("Choose Files"), image: "folder" }, |
| 12 | ]; |
| 13 | |
| 14 | export function ComposerAttachmentButton(props: { |
| 15 | readonly disabled?: boolean; |
| 16 | readonly size?: "regular" | "large"; |
| 17 | readonly supportsFiles: boolean; |
| 18 | readonly onPickMedia: () => Promise<void>; |
| 19 | readonly onPickFiles: () => Promise<void>; |
| 20 | }) { |
| 21 | const gt = useGT(); |
| 22 | const m = useMessages(); |
| 23 | const { scale } = useAndroidControlSizing(); |
| 24 | const button = ( |
| 25 | <Pressable |
| 26 | accessibilityLabel={gt("Add attachment")} |
| 27 | accessibilityRole="button" |
| 28 | accessibilityState={{ disabled: props.disabled }} |
| 29 | className="size-[44px] shrink-0 items-center justify-center rounded-full active:opacity-70 disabled:opacity-50" |
| 30 | disabled={props.disabled} |
| 31 | onPress={props.supportsFiles ? undefined : () => void props.onPickMedia()} |
| 32 | > |
| 33 | <SymbolView |
| 34 | name="plus" |
| 35 | size={Math.round((props.size === "large" ? 26 : 20) * scale)} |
| 36 | weight="regular" |
| 37 | tintColorClassName="accent-icon" |
| 38 | type="monochrome" |
| 39 | /> |
| 40 | </Pressable> |
| 41 | ); |
| 42 | |
| 43 | if (props.disabled || !props.supportsFiles) { |
| 44 | return button; |
| 45 | } |
| 46 | |
| 47 | return ( |
| 48 | <Menu |
| 49 | accessible |
| 50 | accessibilityLabel={gt("Add attachment")} |
| 51 | accessibilityRole="button" |
| 52 | actions={ATTACHMENT_MENU_ACTIONS.map((action) => ({ ...action, title: m(action.title) }))} |
| 53 | onPressAction={({ nativeEvent }) => { |
| 54 | if (nativeEvent.event === "photos") { |
| 55 | void props.onPickMedia(); |
| 56 | } else if (nativeEvent.event === "files") { |
| 57 | void props.onPickFiles(); |
| 58 | } |
| 59 | }} |
| 60 | > |
| 61 | {button} |
| 62 | </Menu> |
| 63 | ); |
| 64 | } |