|
| 1 | +import {useState} from 'react'; |
| 2 | +import {clsx} from 'clsx'; |
| 3 | +import {CaretDown, GitBranch} from '@phosphor-icons/react'; |
| 4 | +import {Grid} from 'react-loader-spinner'; |
| 5 | +import {Markdown} from './Markdown'; |
| 6 | + |
| 7 | +interface InlineBranchCardProps { |
| 8 | + description: string; |
| 9 | + completedAt: string | null; |
| 10 | + conclusion?: string | null; |
| 11 | + className?: string; |
| 12 | +} |
| 13 | + |
| 14 | +function InlineBranchCard({ |
| 15 | + description, |
| 16 | + completedAt, |
| 17 | + conclusion, |
| 18 | + className, |
| 19 | +}: InlineBranchCardProps) { |
| 20 | + const [expanded, setExpanded] = useState(false); |
| 21 | + const isRunning = !completedAt; |
| 22 | + |
| 23 | + return ( |
| 24 | + <div className={clsx('group flex min-w-0 flex-col items-start', className)}> |
| 25 | + <div className="min-w-0 max-w-full overflow-hidden rounded-2xl border border-app-line/50 bg-app-box/30 backdrop-blur-sm"> |
| 26 | + <button |
| 27 | + type="button" |
| 28 | + onClick={() => setExpanded((v) => !v)} |
| 29 | + className="flex w-full items-start gap-3 px-4 py-3 text-left transition-colors hover:bg-app-box/30" |
| 30 | + > |
| 31 | + <div className="mt-0.5 shrink-0"> |
| 32 | + {isRunning ? ( |
| 33 | + <Grid height={16} width={16} color="currentColor" ariaLabel="loading" wrapperClass="text-accent" /> |
| 34 | + ) : ( |
| 35 | + <div className="flex size-7 items-center justify-center rounded-full bg-accent/15 text-accent"> |
| 36 | + <GitBranch className="size-4" weight="bold" /> |
| 37 | + </div> |
| 38 | + )} |
| 39 | + </div> |
| 40 | + <div className="min-w-0 flex-1"> |
| 41 | + <div className="flex items-center gap-2"> |
| 42 | + <div className="line-clamp-2 min-w-0 flex-1 text-sm font-medium leading-5 text-ink"> |
| 43 | + {description} |
| 44 | + </div> |
| 45 | + <span |
| 46 | + className={clsx( |
| 47 | + 'rounded-full px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.12em]', |
| 48 | + isRunning |
| 49 | + ? 'bg-accent/12 text-accent' |
| 50 | + : 'bg-emerald-500/12 text-emerald-400', |
| 51 | + )} |
| 52 | + > |
| 53 | + {isRunning ? 'thinking' : 'done'} |
| 54 | + </span> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + {conclusion && ( |
| 58 | + <CaretDown |
| 59 | + className={clsx( |
| 60 | + 'mt-1 size-4 shrink-0 text-ink-faint transition-transform', |
| 61 | + expanded ? 'rotate-180' : '', |
| 62 | + )} |
| 63 | + weight="bold" |
| 64 | + /> |
| 65 | + )} |
| 66 | + </button> |
| 67 | + {expanded && conclusion && ( |
| 68 | + <div className="border-t border-app-line/30 px-4 py-3"> |
| 69 | + <Markdown content={conclusion} className="text-xs text-ink-dull" /> |
| 70 | + </div> |
| 71 | + )} |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + ); |
| 75 | +} |
| 76 | + |
| 77 | +export {InlineBranchCard}; |
| 78 | +export type {InlineBranchCardProps}; |
0 commit comments