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 { SymbolView, type AppSymbolName } from "./AppSymbol"; |
| 2 | import { Pressable } from "react-native"; |
| 3 | import { AppActivityIndicator } from "./AppActivityIndicator"; |
| 4 | import { AppText } from "./AppText"; |
| 5 | import { cn } from "../../lib/cn"; |
| 6 | |
| 7 | export interface ButtonProps { |
| 8 | readonly label: string; |
| 9 | readonly accessibilityLabel?: string; |
| 10 | readonly icon?: AppSymbolName; |
| 11 | readonly onPress: () => void; |
| 12 | readonly disabled?: boolean; |
| 13 | readonly accessibilityHint?: string; |
| 14 | readonly loading?: boolean; |
| 15 | readonly tone?: "primary" | "secondary" | "danger" | "text" | "contrast"; |
| 16 | readonly fullWidth?: boolean; |
| 17 | readonly size?: "default" | "compact"; |
| 18 | } |
| 19 | |
| 20 | const TONE_CLASS_NAMES = { |
| 21 | contrast: ["bg-foreground", "text-screen"], |
| 22 | primary: ["bg-primary", "text-primary-foreground"], |
| 23 | secondary: ["bg-secondary", "text-secondary-foreground"], |
| 24 | danger: ["bg-danger", "text-danger-foreground"], |
| 25 | text: ["bg-transparent", "text-primary-text"], |
| 26 | } as const; |
| 27 | |
| 28 | export function Button(props: ButtonProps) { |
| 29 | const [containerClassName, labelClassName] = TONE_CLASS_NAMES[props.tone ?? "secondary"]; |
| 30 | const disabled = Boolean(props.disabled || props.loading); |
| 31 | return ( |
| 32 | <Pressable |
| 33 | accessibilityRole="button" |
| 34 | accessibilityLabel={props.accessibilityLabel ?? props.label} |
| 35 | accessibilityHint={props.accessibilityHint} |
| 36 | accessibilityState={{ disabled, busy: Boolean(props.loading) }} |
| 37 | disabled={disabled} |
| 38 | onPress={props.onPress} |
| 39 | className={cn( |
| 40 | "flex-row items-center justify-center gap-2 rounded-full active:opacity-70", |
| 41 | props.size === "compact" ? "min-h-10 px-5" : "min-h-12 px-6", |
| 42 | props.fullWidth ? "w-full" : "self-start", |
| 43 | disabled ? "bg-subtle-strong" : containerClassName, |
| 44 | )} |
| 45 | > |
| 46 | {props.loading ? ( |
| 47 | <AppActivityIndicator colorClassName="accent-foreground-muted" /> |
| 48 | ) : props.icon ? ( |
| 49 | <SymbolView |
| 50 | name={props.icon} |
| 51 | size={18} |
| 52 | tintColorClassName={ |
| 53 | disabled ? "accent-foreground-muted" : labelClassName.replace("text-", "accent-") |
| 54 | } |
| 55 | /> |
| 56 | ) : null} |
| 57 | <AppText |
| 58 | className={cn( |
| 59 | "min-w-0 shrink text-center font-t3-medium", |
| 60 | disabled ? "text-foreground-muted" : labelClassName, |
| 61 | )} |
| 62 | > |
| 63 | {props.label} |
| 64 | </AppText> |
| 65 | </Pressable> |
| 66 | ); |
| 67 | } |