Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ConnectionSheetButton.tsx

99 lines2.8 KB

1import { SymbolView } from "../../components/AppSymbol";
2import { Platform, Pressable } from "react-native";
3import { useThemeColor } from "../../lib/useThemeColor";
4​
5import { AppText as Text } from "../../components/AppText";
6import { cn } from "../../lib/cn";
7​
8const CARD_SHADOW = Platform.select({
9 ios: {
10 shadowColor: "rgba(23,23,23,0.08)",
11 shadowOffset: { width: 0, height: 4 },
12 shadowOpacity: 1,
13 shadowRadius: 16,
14 },
15 android: { elevation: 3 },
16});
17​
18const CARD_SHADOW_DARK = Platform.select({
19 ios: {
20 shadowColor: "#000",
21 shadowOffset: { width: 0, height: 2 },
22 shadowOpacity: 0.18,
23 shadowRadius: 8,
24 },
25 android: { elevation: 4 },
26});
27​
28export { CARD_SHADOW, CARD_SHADOW_DARK };
29​
30export function ConnectionSheetButton(props: {
31 readonly icon: React.ComponentProps<typeof SymbolView>["name"];
32 readonly label: string;
33 readonly disabled?: boolean;
34 readonly tone?: "primary" | "secondary" | "danger";
35 readonly compact?: boolean;
36 readonly onPress: () => void;
37}) {
38 const tone = props.tone ?? "secondary";
39​
40 const primaryFg = useThemeColor("--color-primary-foreground");
41 const dangerFg = useThemeColor("--color-danger-foreground");
42 const secondaryFg = useThemeColor("--color-secondary-foreground");
43​
44 const textColor = tone === "primary" ? primaryFg : tone === "danger" ? dangerFg : secondaryFg;
45​
46 const primaryShadow =
47 tone === "primary"
48 ? Platform.select({
49 ios: {
50 shadowColor: "#000",
51 shadowOffset: { width: 0, height: 3 },
52 shadowOpacity: 0.14,
53 shadowRadius: 6,
54 },
55 android: { elevation: 3 },
56 })
57 : undefined;
58​
59 return (
60 <Pressable
61 accessibilityLabel={props.label}
62 accessibilityRole="button"
63 accessibilityState={{ disabled: props.disabled ?? false }}
64 className={cn(
65 props.compact
66 ? "min-h-[42px] flex-row items-center justify-center gap-1.5 rounded-[14px] px-3.5 py-2.5"
67 : "min-h-[48px] flex-row items-center justify-center gap-2 rounded-[16px] px-4 py-3",
68 "disabled:opacity-50",
69 tone === "primary"
70 ? "bg-primary"
71 : tone === "danger"
72 ? "border border-danger-border bg-danger"
73 : "border border-border bg-secondary",
74 )}
75 disabled={props.disabled}
76 onPress={props.onPress}
77 style={primaryShadow}
78 >
79 <SymbolView
80 name={props.icon}
81 size={props.compact ? 13 : 14}
82 tintColor={textColor}
83 type="monochrome"
84 />
85 <Text
86 className={cn(
87 "text-xs font-t3-bold tracking-[0.8px] uppercase",
88 tone === "primary"
89 ? "text-primary-foreground"
90 : tone === "danger"
91 ? "text-danger-foreground"
92 : "text-secondary-foreground",
93 )}
94 >
95 {props.label}
96 </Text>
97 </Pressable>
98 );