The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { ReactNode } from "react"; |
| 2 | import { Pressable, StyleSheet, Text, View } from "react-native"; |
| 3 | |
| 4 | import { SymbolView, type AppSymbolName } from "../components/ui/AppSymbol"; |
| 5 | import { themeColorWithAlpha } from "../lib/mobileTheme"; |
| 6 | import type { NativeMarkdownTextStyle } from "./SelectableMarkdownText.types"; |
| 7 | |
| 8 | /** |
| 9 | * The native code block's border and header, for a fence drawn in React once it closes. |
| 10 | * The block slot already applies the code block's outer margins. |
| 11 | */ |
| 12 | export function CodeBlockFrame(props: { |
| 13 | readonly label: string; |
| 14 | readonly textStyle: NativeMarkdownTextStyle; |
| 15 | readonly actions: ReactNode; |
| 16 | readonly children: ReactNode; |
| 17 | }) { |
| 18 | const { textStyle } = props; |
| 19 | return ( |
| 20 | <View |
| 21 | style={[ |
| 22 | styles.block, |
| 23 | { |
| 24 | backgroundColor: textStyle.codeBlockBackgroundColor, |
| 25 | borderColor: textStyle.dividerColor, |
| 26 | }, |
| 27 | ]} |
| 28 | > |
| 29 | <View |
| 30 | style={[ |
| 31 | styles.header, |
| 32 | { borderBottomColor: themeColorWithAlpha(textStyle.codeColor, 0.2) }, |
| 33 | ]} |
| 34 | > |
| 35 | <Text |
| 36 | style={[ |
| 37 | styles.label, |
| 38 | { |
| 39 | color: themeColorWithAlpha(textStyle.codeColor, 0.6), |
| 40 | fontSize: textStyle.fontSize * 0.9 * 0.85, |
| 41 | }, |
| 42 | ]} |
| 43 | > |
| 44 | {props.label} |
| 45 | </Text> |
| 46 | <View style={styles.actions}>{props.actions}</View> |
| 47 | </View> |
| 48 | {props.children} |
| 49 | </View> |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | /** A header icon; `active` draws it at full strength, as the native wrap toggle when on. */ |
| 54 | export function CodeBlockHeaderButton(props: { |
| 55 | readonly icon: AppSymbolName; |
| 56 | readonly label: string; |
| 57 | readonly textStyle: NativeMarkdownTextStyle; |
| 58 | readonly active?: boolean; |
| 59 | readonly onPress: () => void; |
| 60 | }) { |
| 61 | return ( |
| 62 | <Pressable |
| 63 | accessibilityRole="button" |
| 64 | accessibilityLabel={props.label} |
| 65 | hitSlop={10} |
| 66 | onPress={props.onPress} |
| 67 | > |
| 68 | <SymbolView |
| 69 | name={props.icon} |
| 70 | size={14} |
| 71 | tintColor={ |
| 72 | props.active |
| 73 | ? props.textStyle.codeColor |
| 74 | : themeColorWithAlpha(props.textStyle.codeColor, 0.6) |
| 75 | } |
| 76 | type="monochrome" |
| 77 | /> |
| 78 | </Pressable> |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | const styles = StyleSheet.create({ |
| 83 | block: { |
| 84 | borderRadius: 8, |
| 85 | borderWidth: StyleSheet.hairlineWidth, |
| 86 | overflow: "hidden", |
| 87 | }, |
| 88 | header: { |
| 89 | minHeight: 32, |
| 90 | paddingHorizontal: 12, |
| 91 | flexDirection: "row", |
| 92 | alignItems: "center", |
| 93 | justifyContent: "space-between", |
| 94 | borderBottomWidth: StyleSheet.hairlineWidth, |
| 95 | }, |
| 96 | label: { fontWeight: "500" }, |
| 97 | actions: { flexDirection: "row", alignItems: "center", gap: 14 }, |
| 98 | }); |