context-bar.tsx
This file
Path
apps/web/src/features/shared/shell/context-bar.tsx
117 lines · 3.5 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118import { Check, Copy } from "lucide-react";import type { ReactNode } from "react";
import { Button } from "../../../components/ui/button.tsx";import { useCopy } from "../copy-action.tsx";import { useNumberedCommand } from "../keys.tsx";import { AppLink } from "../link.tsx";import { GUTTER } from "./gutter.ts";import type { Crumb } from "./sections.ts";
export const Breadcrumb = ({ crumbs,}: { readonly crumbs: readonly Crumb[];}) => ( <nav aria-label="Breadcrumb" className="min-w-0"> <ol className="text-ui flex min-w-0 items-center gap-1.5"> {crumbs.map(({ label, mono = false, to }, index) => { const last = index === crumbs.length - 1; const face = mono ? "text-mono font-mono" : "";
return ( <li className={`${last ? "flex" : "tablet:flex hidden"} min-w-0 items-center gap-1.5`} key={`${index}:${label}`} > {index === 0 ? null : ( <span aria-hidden="true" className={`text-muted-foreground ${last ? "tablet:inline hidden" : ""}`} > / </span> )} {last || to === undefined ? ( <span aria-current={last ? "page" : undefined} className={`min-w-0 truncate ${last ? "text-foreground font-medium" : "text-muted-foreground"} ${face}`} title={label} > {label} </span> ) : ( <AppLink activeOptions={{ exact: true, includeSearch: false }} className={`text-muted-foreground hover:text-foreground max-w-[14rem] min-w-0 truncate no-underline transition-colors duration-[120ms] ${face}`} title={label} to={to} > {label} </AppLink> )} </li> ); })} </ol> </nav>);
export const CopyCommand = ({ command }: { readonly command: string }) => { const { copied, copy } = useCopy(command); const number = useNumberedCommand(command);
return ( <Button onClick={copy} size="sm" title={ number === undefined ? `Copy: ${command}` : `Copy (${number}): ${command}` } variant="outline" > {copied ? ( <Check aria-hidden="true" strokeWidth={1.75} /> ) : ( <Copy aria-hidden="true" strokeWidth={1.75} /> )} <span aria-hidden="true">{copied ? "Copied" : "Copy"}</span> <code className="sr-only"> {copied ? `Copied ${command}` : `Copy ${command}`} </code> </Button> );};
export const ContextBar = ({ count, crumbs, primaryCommand, state,}: { readonly count?: string | undefined; readonly crumbs: readonly Crumb[]; readonly primaryCommand?: string | undefined; readonly state?: ReactNode;}) => ( <div className={`border-rule bg-background flex h-11 shrink-0 items-center gap-3 border-b ${GUTTER}`} > <Breadcrumb crumbs={crumbs} /> <div className="ml-auto flex shrink-0 items-center gap-3"> {count === undefined ? null : ( <p className="text-ui text-muted-foreground truncate tabular-nums"> {count} </p> )} {state === undefined ? null : ( <div className="text-ui flex items-center">{state}</div> )} {primaryCommand === undefined ? null : ( <CopyCommand command={primaryCommand} /> )} </div> </div>);