The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { ReactNode } from "react"; |
| 2 | |
| 3 | import { T, useGT } from "gt-react"; |
| 4 | import { Spinner } from "~/components/ui/spinner"; |
| 5 | import { Button } from "~/components/ui/button"; |
| 6 | import { Toggle } from "~/components/ui/toggle"; |
| 7 | import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip"; |
| 8 | import { DIFF_SURFACE_THEME_UNSAFE_CSS } from "~/lib/diffRendering"; |
| 9 | import { cn } from "~/lib/utils"; |
| 10 | |
| 11 | export const FILE_SURFACE_SUBHEADER_CLASS = |
| 12 | "flex h-10 min-h-10 shrink-0 items-center gap-2 border-b border-border/60 bg-background px-3 in-data-[preview-panel-mode=inline]:mb-3 in-data-[preview-panel-mode=inline]:h-7 in-data-[preview-panel-mode=inline]:min-h-7 in-data-[preview-panel-mode=inline]:border-b-transparent"; |
| 13 | |
| 14 | export const FILE_LINK_REVEAL_ATTRIBUTE = "data-file-link-reveal"; |
| 15 | |
| 16 | export const FILE_LINK_REVEAL_UNSAFE_CSS = ` |
| 17 | ${DIFF_SURFACE_THEME_UNSAFE_CSS} |
| 18 | |
| 19 | diffs-container { |
| 20 | --diffs-bg: var(--code-background, var(--background)) !important; |
| 21 | --diffs-light-bg: var(--code-background, var(--background)) !important; |
| 22 | --diffs-dark-bg: var(--code-background, var(--background)) !important; |
| 23 | background-color: var(--code-background, var(--background)) !important; |
| 24 | color: var(--code-foreground, var(--foreground)) !important; |
| 25 | } |
| 26 | |
| 27 | /* Tint through --diffs-line-bg, not background-color. The editor paints row |
| 28 | tints on a layer below its text selection; a background on the row itself |
| 29 | covers the selection and makes selected text on this line invisible. */ |
| 30 | [${FILE_LINK_REVEAL_ATTRIBUTE}][data-line] { |
| 31 | --diffs-line-bg: light-dark( |
| 32 | color-mix( |
| 33 | in lab, |
| 34 | var(--diffs-computed-diff-line-bg) 82%, |
| 35 | var(--diffs-bg-selection-override, var(--diffs-selection-base)) |
| 36 | ), |
| 37 | color-mix( |
| 38 | in lab, |
| 39 | var(--diffs-computed-diff-line-bg) 75%, |
| 40 | var(--diffs-bg-selection-override, var(--diffs-selection-base)) |
| 41 | ) |
| 42 | ) !important; |
| 43 | } |
| 44 | |
| 45 | [${FILE_LINK_REVEAL_ATTRIBUTE}][data-column-number] { |
| 46 | background-color: light-dark( |
| 47 | color-mix( |
| 48 | in lab, |
| 49 | var(--diffs-computed-diff-line-bg) 75%, |
| 50 | var(--diffs-bg-selection-number-override, var(--diffs-selection-base)) |
| 51 | ), |
| 52 | color-mix( |
| 53 | in lab, |
| 54 | var(--diffs-computed-diff-line-bg) 60%, |
| 55 | var(--diffs-bg-selection-number-override, var(--diffs-selection-base)) |
| 56 | ) |
| 57 | ) !important; |
| 58 | color: var(--diffs-selection-number-fg) !important; |
| 59 | } |
| 60 | `; |
| 61 | |
| 62 | export function FileSurfaceAction(props: { |
| 63 | readonly label: string; |
| 64 | readonly pressed?: boolean; |
| 65 | readonly disabled?: boolean; |
| 66 | readonly onPress: () => void; |
| 67 | readonly children: ReactNode; |
| 68 | }) { |
| 69 | const pressed = props.pressed; |
| 70 | return ( |
| 71 | <Tooltip> |
| 72 | <TooltipTrigger |
| 73 | render={ |
| 74 | pressed === undefined ? ( |
| 75 | <Button |
| 76 | type="button" |
| 77 | className="shrink-0" |
| 78 | disabled={props.disabled ?? false} |
| 79 | onClick={props.onPress} |
| 80 | aria-label={props.label} |
| 81 | variant="ghost" |
| 82 | size="icon-sm" |
| 83 | > |
| 84 | {props.children} |
| 85 | </Button> |
| 86 | ) : ( |
| 87 | <Toggle |
| 88 | className="shrink-0" |
| 89 | pressed={pressed} |
| 90 | disabled={props.disabled ?? false} |
| 91 | onPressedChange={props.onPress} |
| 92 | aria-label={props.label} |
| 93 | variant="ghost" |
| 94 | size="sm" |
| 95 | > |
| 96 | {props.children} |
| 97 | </Toggle> |
| 98 | ) |
| 99 | } |
| 100 | /> |
| 101 | <TooltipPopup>{props.label}</TooltipPopup> |
| 102 | </Tooltip> |
| 103 | ); |
| 104 | } |
| 105 | |
| 106 | export function FileSurfaceNotice(props: { readonly children: ReactNode }) { |
| 107 | return ( |
| 108 | <div |
| 109 | role="status" |
| 110 | className="shrink-0 border-b border-warning/20 bg-warning-surface px-3 py-1.5 text-2xs text-warning-foreground" |
| 111 | > |
| 112 | {props.children} |
| 113 | </div> |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | export function FileSurfaceLoading(props: { readonly className?: string }) { |
| 118 | const gt = useGT(); |
| 119 | return ( |
| 120 | <div |
| 121 | role="status" |
| 122 | aria-label={gt("Loading file")} |
| 123 | className={cn( |
| 124 | "flex min-h-0 flex-1 items-center justify-center text-muted-foreground", |
| 125 | props.className, |
| 126 | )} |
| 127 | > |
| 128 | <Spinner size="lg" /> |
| 129 | </div> |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | export function FileSurfaceFailure(props: { |
| 134 | readonly message: string; |
| 135 | readonly onRetry?: () => void; |
| 136 | }) { |
| 137 | return ( |
| 138 | <div |
| 139 | role="alert" |
| 140 | className="flex min-h-0 flex-1 flex-col items-center justify-center gap-3 px-6 text-center text-xs leading-relaxed" |
| 141 | > |
| 142 | <p className="text-destructive">{props.message}</p> |
| 143 | {props.onRetry ? ( |
| 144 | <button |
| 145 | type="button" |
| 146 | onClick={props.onRetry} |
| 147 | className="rounded-md border border-input px-2.5 py-1 text-xs text-foreground hover:bg-accent focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring" |
| 148 | > |
| 149 | <T>Try again</T> |
| 150 | </button> |
| 151 | ) : null} |
| 152 | </div> |
| 153 | ); |
| 154 | } |