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 { mergeProps } from "@base-ui/react/merge-props"; |
| 2 | import { useRender } from "@base-ui/react/use-render"; |
| 3 | import { T, Var } from "gt-react"; |
| 4 | import type { ComponentProps } from "react"; |
| 5 | |
| 6 | import { cn } from "~/lib/utils"; |
| 7 | import { Button } from "../ui/button"; |
| 8 | import { |
| 9 | THREAD_DETAILS_PANEL_ROW_CLASS, |
| 10 | THREAD_DETAILS_PANEL_SELECT_ROW_CLASS, |
| 11 | THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS, |
| 12 | THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS, |
| 13 | THREAD_DETAILS_PANEL_ICON_ACTION_CLASS, |
| 14 | THREAD_DETAILS_PANEL_META_ACTION_CLASS, |
| 15 | THREAD_DETAILS_PANEL_CHEVRON_CLASS, |
| 16 | THREAD_DETAILS_PANEL_SELECT_LABEL_CLASS, |
| 17 | THREAD_DETAILS_PANEL_SELECT_ICON_CLASS, |
| 18 | } from "./threadDetailsPanelStyles"; |
| 19 | import { ChevronDownIcon, ChevronUpIcon } from "lucide-react"; |
| 20 | |
| 21 | const parts = { |
| 22 | row: THREAD_DETAILS_PANEL_ROW_CLASS, |
| 23 | title: cn( |
| 24 | THREAD_DETAILS_PANEL_ROW_CLASS, |
| 25 | "h-auto min-h-8 items-start pt-1.5 pb-0 disabled:opacity-100 sm:h-auto [&>svg]:mt-px", |
| 26 | ), |
| 27 | select: THREAD_DETAILS_PANEL_SELECT_ROW_CLASS, |
| 28 | primary: THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS, |
| 29 | secondary: THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS, |
| 30 | icon: THREAD_DETAILS_PANEL_ICON_ACTION_CLASS, |
| 31 | meta: THREAD_DETAILS_PANEL_META_ACTION_CLASS, |
| 32 | }; |
| 33 | |
| 34 | export function ThreadDetailsControl({ |
| 35 | panel = true, |
| 36 | part = "row", |
| 37 | multiline = false, |
| 38 | tone = "default", |
| 39 | className, |
| 40 | children, |
| 41 | size = "default", |
| 42 | variant = "default", |
| 43 | render, |
| 44 | ...props |
| 45 | }: ComponentProps<typeof Button> & { |
| 46 | panel?: boolean; |
| 47 | part?: keyof typeof parts; |
| 48 | multiline?: boolean; |
| 49 | tone?: "default" | "muted" | "primary" | "destructive"; |
| 50 | }) { |
| 51 | const control = useRender({ |
| 52 | defaultTagName: "button", |
| 53 | render, |
| 54 | props: mergeProps<"button">( |
| 55 | { |
| 56 | type: render ? undefined : "button", |
| 57 | // The touch target stays centered within the panel's 32px rows; spilling past them makes scrolling lists overflow. |
| 58 | className: cn( |
| 59 | "relative inline-flex shrink-0 cursor-pointer items-center whitespace-nowrap border outline-none transition-[box-shadow,scale] [&:not([aria-haspopup]):not(:disabled):not([aria-disabled=true])]:will-change-[scale] [&:active:not([aria-haspopup])]:scale-[0.97] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background pointer-coarse:after:absolute pointer-coarse:after:top-1/2 pointer-coarse:after:left-1/2 pointer-coarse:after:size-full pointer-coarse:after:min-h-8 pointer-coarse:after:min-w-8 pointer-coarse:after:-translate-x-1/2 pointer-coarse:after:-translate-y-1/2 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 disabled:pointer-events-none disabled:opacity-64 aria-disabled:cursor-not-allowed aria-disabled:opacity-64 [&_svg]:shrink-0", |
| 60 | parts[part], |
| 61 | multiline && "h-auto min-h-8 py-1.5 disabled:opacity-100 sm:h-auto", |
| 62 | tone === "muted" && "text-muted-foreground hover:text-foreground/80", |
| 63 | tone === "primary" && |
| 64 | // The row surface forces a faint hover fill with !important; the pill keeps its own. |
| 65 | "bg-black/[0.035] text-foreground/80 hover:text-foreground hover:!bg-black/[0.06] data-pressed:!bg-black/[0.06] dark:bg-white/[0.08] dark:hover:!bg-white/[0.12] dark:data-pressed:!bg-white/[0.12]", |
| 66 | tone === "destructive" && |
| 67 | "text-destructive hover:text-destructive data-pressed:text-destructive", |
| 68 | // Keep the inset focus ring clear of the 20px PR action label. |
| 69 | part === "meta" && |
| 70 | (tone === "primary" || tone === "destructive") && |
| 71 | "h-5 focus-visible:ring-1 focus-visible:ring-offset-0", |
| 72 | part === "meta" && |
| 73 | tone === "destructive" && |
| 74 | "bg-destructive/10 hover:!bg-destructive/16 data-pressed:!bg-destructive/16 dark:hover:!bg-destructive/16 dark:data-pressed:!bg-destructive/16", |
| 75 | className, |
| 76 | ), |
| 77 | }, |
| 78 | props, |
| 79 | { |
| 80 | children: |
| 81 | part === "select" ? ( |
| 82 | <> |
| 83 | <span data-slot="select-label" className={THREAD_DETAILS_PANEL_SELECT_LABEL_CLASS}> |
| 84 | {children} |
| 85 | </span> |
| 86 | <span data-slot="select-icon" className={THREAD_DETAILS_PANEL_SELECT_ICON_CLASS}> |
| 87 | <ChevronDownIcon className={THREAD_DETAILS_PANEL_CHEVRON_CLASS} /> |
| 88 | </span> |
| 89 | </> |
| 90 | ) : ( |
| 91 | children |
| 92 | ), |
| 93 | }, |
| 94 | ), |
| 95 | }); |
| 96 | if (!panel) { |
| 97 | return ( |
| 98 | <Button |
| 99 | {...props} |
| 100 | render={render} |
| 101 | size={multiline ? "sm-multiline" : size} |
| 102 | variant={variant} |
| 103 | className={className} |
| 104 | > |
| 105 | {children} |
| 106 | </Button> |
| 107 | ); |
| 108 | } |
| 109 | return control; |
| 110 | } |
| 111 | |
| 112 | export function ThreadDetailsMoreButton({ |
| 113 | expanded, |
| 114 | remaining, |
| 115 | onToggle, |
| 116 | }: { |
| 117 | expanded: boolean; |
| 118 | remaining: number; |
| 119 | onToggle: () => void; |
| 120 | }) { |
| 121 | const Icon = expanded ? ChevronUpIcon : ChevronDownIcon; |
| 122 | return ( |
| 123 | <ThreadDetailsControl |
| 124 | variant="ghost" |
| 125 | size="sm" |
| 126 | aria-expanded={expanded} |
| 127 | onClick={onToggle} |
| 128 | tone="muted" |
| 129 | className="w-full active:scale-100" |
| 130 | > |
| 131 | <Icon aria-hidden className="size-4 shrink-0" /> |
| 132 | {expanded ? ( |
| 133 | <T>Show less</T> |
| 134 | ) : ( |
| 135 | <T> |
| 136 | Show <Var>{remaining}</Var> more |
| 137 | </T> |
| 138 | )} |
| 139 | </ThreadDetailsControl> |
| 140 | ); |
| 141 | } |