Skip to documentation
Design system / Sources & standards
Current repository source
reviewDrawer.tsx
src/components/reviews/reviewDrawer.tsx
This view contains the escaped source read during the deployment build. Code and policy text are unchanged. Markdown is shown as source, not rendered as a document. A new deployment refreshes the content.
"use client";
import { useId, useRef, useState, type ReactNode } from "react";
import { X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Sheet, SheetClose, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
import { Text } from "@/components/ui/text";
/** Review-owned Sheet composition. The form owner retains draft and mutation state. */
export function ReviewDrawer({ children, hasReview, canEdit, busy = false }: { children: ReactNode; hasReview: boolean; canEdit: boolean; busy?: boolean }) {
const [open, setOpen] = useState(false);
const owner = useRef<HTMLDivElement>(null);
const title = useRef<HTMLHeadingElement>(null);
const descriptionId = useId();
const action = hasReview ? "Edit review" : "Start review";
const description = canEdit
? hasReview ? "Edit your review of this work" : "Start your review of this work"
: hasReview ? "This review round is inactive. Your review is read-only." : "This review round is inactive. Starting a review is unavailable.";
return <Sheet open={open} onOpenChange={next => { if (next || !busy) setOpen(next); }}>
<div ref={owner} data-slot="review-drawer-trigger" className="flex w-full min-w-0 flex-wrap items-center justify-end gap-3">
<Text id={descriptionId} variant="supporting" className="min-w-0 text-right">{description}</Text>
{canEdit ? <SheetTrigger asChild><Button type="button" size="sm" aria-describedby={descriptionId}>{action}</Button></SheetTrigger>
: <Button type="button" size="sm" aria-describedby={descriptionId} disabled>{action}</Button>}
{!canEdit && hasReview ? <SheetTrigger asChild><Button type="button" size="sm" variant="outline" aria-describedby={descriptionId}>View review</Button></SheetTrigger> : null}
</div>
<SheetContent side="right" showCloseButton={false} container={owner.current?.closest<HTMLElement>("[data-tenant-theme]") ?? undefined}
aria-busy={busy} className="h-dvh w-full gap-0 sm:max-w-(--cxh-container-sm) motion-reduce:animate-none motion-reduce:transition-none"
onOpenAutoFocus={event => { event.preventDefault(); title.current?.focus(); }}
onEscapeKeyDown={event => { if (busy) event.preventDefault(); }}
onInteractOutside={event => { if (busy) event.preventDefault(); }}>
<SheetHeader className="shrink-0 p-6 pr-16">
<SheetTitle ref={title} tabIndex={-1} className="text-title">Your review</SheetTitle>
<SheetDescription>Review this work using the round’s evaluation criteria.</SheetDescription>
</SheetHeader>
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-6 pb-6">{children}</div>
<SheetClose asChild><Button type="button" variant="ghost" size="icon-sm" className="absolute top-4 right-4" aria-label="Close review" disabled={busy}><X aria-hidden="true" /></Button></SheetClose>
</SheetContent>
</Sheet>;
}
All sources and standards