Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .claude/skills/openbot-screen-layout/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ button.
`className="line-clamp-none"`.
7. To make the whole row navigate or open something, pass `render`:
`render={<button type="button" onClick={…} />}` or `render={<Link to=… />}`. A real element, so
the keyboard reaches it and a link can be opened in a new tab.
the keyboard reaches it and a link can be opened in a new tab. Such a row takes `muted` under the
pointer and the solid focus ring on its own: add no `hover:bg-…`. A skin or a screen that draws
its own hover names `[a,button]:hover:`, which replaces the row's; a plain `hover:` loses to it.

**The one mistake this makes easy:** the element passed to `render` must have **no children**.
`useRender` merges props, and children given there replace the row's own — the media, the content
Expand Down
5 changes: 1 addition & 4 deletions app/src/components/artifacts/artifacts-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,7 @@ function ArtifactRow({
<Item
aria-current={open || undefined}
data-artifact-id={artifact.id}
className={cn(
"cursor-pointer text-left hover:bg-muted",
open && "bg-muted",
)}
className={cn("cursor-pointer text-left", open && "bg-muted")}
render={<button onClick={() => onOpen(artifact.id)} type="button" />}
size="sm"
>
Expand Down
51 changes: 20 additions & 31 deletions app/src/components/artifacts/kinds/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TableHead,
TableHeader,
TableRow,
TableSortButton,
} from "@/components/ui/table";
import { cn } from "@/lib/utils";
import { ALIGN_CLASS, alignOf, CellText } from "./cells";
Expand Down Expand Up @@ -112,51 +113,39 @@ export function ArtifactTable({
className={size === "large" ? "text-lg" : undefined}
containerClassName="min-h-0 flex-1"
>
<TableHeader className="bg-muted">
<TableRow className="hover:bg-transparent">
<TableHeader>
<TableRow>
{columns.map((column, index) => {
const align = alignOf(column);
const active = sort?.column === index;
const order =
sort?.column === index
? sort.ascending
? "ascending"
: "descending"
: undefined;
return (
<TableHead
aria-sort={
active
? sort.ascending
? "ascending"
: "descending"
: undefined
}
aria-sort={order}
className={cn(
"p-0",
size === "large" ? "h-12 text-base" : "h-9 text-xs",
size === "large" ? "h-12 text-base" : "h-9",
align === "right" && "text-right",
align === "center" && "text-center",
)}
key={column.key}
style={column.width ? { minWidth: column.width } : undefined}
>
{onPaper ? (
// Paper can't be sorted: the heading alone.
<span
className={cn(
"flex h-full w-full items-center px-3",
align === "right" && "justify-end text-right",
align === "center" && "justify-center",
)}
>
<span className="truncate">{column.label}</span>
</span>
column.label
) : (
<button
className={cn(
"flex h-full w-full items-center gap-1.5 px-3 hover:bg-foreground/5 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring",
align === "right" && "flex-row-reverse text-right",
align === "center" && "justify-center",
)}
<TableSortButton
// A right-aligned column's words end at its edge, the arrow before them.
className={cn(align === "right" && "flex-row-reverse")}
onClick={() => setSort(nextSort(sort, index))}
type="button"
sort={order ?? false}
>
<span className="truncate">{column.label}</span>
<SortIcon active={active} ascending={sort?.ascending} />
</button>
{column.label}
</TableSortButton>
)}
</TableHead>
);
Expand Down
30 changes: 14 additions & 16 deletions app/src/components/audit/audit-table.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
IconArrowDown,
IconArrowUp,
IconCirclePlus,
IconSearch,
} from "@/components/icons";
import { IconCirclePlus, IconSearch } from "@/components/icons";
import { useQuery } from "@tanstack/react-query";
import {
type ColumnDef,
Expand Down Expand Up @@ -36,6 +31,7 @@ import {
TableHead,
TableHeader,
TableRow,
TableSortButton,
} from "@/components/ui/table";
import { useIsMobile } from "@/hooks/use-mobile";
import { type AuditOutcome, outcomeOf } from "@/lib/audit/outcome";
Expand Down Expand Up @@ -92,6 +88,13 @@ const STACKED_ON_A_PHONE = new Set(["bot", "decision"]);

const INITIAL_SORT: SortingState = [{ id: "when", desc: true }];

/** A heading's `aria-sort`, for the column the rows are sorted by. */
function ariaSort(sorted: false | "asc" | "desc") {
if (sorted === "asc") return "ascending";
if (sorted === "desc") return "descending";
return undefined;
}

const OUTCOME_LABEL: Record<AuditOutcome, string> = {
allowed: "Allowed",
refused: "Blocked",
Expand Down Expand Up @@ -206,11 +209,12 @@ export function AuditTable({
>
<TableHeader>
{table.getHeaderGroups().map((group) => (
<TableRow className="hover:bg-transparent" key={group.id}>
<TableRow key={group.id}>
{group.headers
.filter((header) => drawn(header.column.id))
.map((header) => (
<TableHead
aria-sort={ariaSort(header.column.getIsSorted())}
className={cn(
header.column.id === "mark" && "w-8 pr-0 pl-4",
)}
Expand Down Expand Up @@ -423,21 +427,15 @@ function auditColumns(
header: ({ column }) => {
const sorted = column.getIsSorted();
return (
<button
className="-mx-1 inline-flex items-center gap-1 rounded px-1 hover:text-foreground"
<TableSortButton
onClick={column.getToggleSortingHandler()}
type="button"
sort={sorted === "asc" ? "ascending" : "descending"}
>
When
{sorted === "asc" ? (
<IconArrowUp className="size-3.5" />
) : (
<IconArrowDown className="size-3.5" />
)}
<span className="sr-only">
{sorted === "asc" ? ", oldest first" : ", newest first"}
</span>
</button>
</TableSortButton>
);
},
cell: ({ row }) => <WhenCell event={row.original} />,
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/settings/learning-review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export function LearningReview({
<Fragment key={group.label}>
{index > 0 && <Separator />}
<Item
className="cursor-pointer text-left hover:bg-muted focus-visible:bg-muted"
className="cursor-pointer text-left focus-visible:bg-muted"
size="sm"
render={
<button
Expand Down
99 changes: 99 additions & 0 deletions app/src/components/ui/alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { cva, type VariantProps } from "class-variance-authority";
import type * as React from "react";

import { cn } from "@/lib/utils";

/*
* shadcn's Alert: a notice that stands in the page, with an icon, a title, a description and an
* action, drawn as the design's Notifications draw a toast (a tint, the icon on a tile of its own,
* the action on the right).
*
* IT SITS IN THE PAGE, so it has a card's corner and a card's hairline in `border`, and no shadow.
* The design's toast floats over the app; that is `toast.tsx`, not this.
*
* `success` and `warning` are ours, beside shadcn's `default` and `destructive`. Every status is a
* 10% tint, and its color is on the icon and its tile; the words are `foreground`, so they read on
* the tint wherever the alert stands. `success` and `warning` fall under 4.5:1 as words on their
* tint in light (components/ui/badge.tsx), and a red title over a red tint is shouting. `default`
* is a card with `muted-foreground` words under the title, as shadcn draws it.
*/
const alertVariants = cva(
"group/alert relative grid w-full grid-cols-[minmax(0,1fr)] items-center gap-x-3 gap-y-0.5 rounded-lg border border-border px-4 py-3 text-left text-sm has-[>svg]:grid-cols-[auto_minmax(0,1fr)] has-data-[slot=alert-action]:grid-cols-[minmax(0,1fr)_auto] has-[>svg]:has-data-[slot=alert-action]:grid-cols-[auto_minmax(0,1fr)_auto] has-data-[slot=alert-description]:[&>svg]:row-span-2 [&>svg]:size-8 [&>svg]:shrink-0 [&>svg]:self-start [&>svg]:rounded-md [&>svg]:p-2",
{
variants: {
variant: {
default: "bg-card text-card-foreground [&>svg]:bg-muted",
destructive:
"bg-destructive/10 text-foreground *:data-[slot=alert-description]:text-foreground [&>svg]:bg-destructive/10 [&>svg]:text-destructive",
success:
"bg-success/10 text-foreground *:data-[slot=alert-description]:text-foreground [&>svg]:bg-success/10 [&>svg]:text-success",
warning:
"bg-warning/10 text-foreground *:data-[slot=alert-description]:text-foreground [&>svg]:bg-warning/10 [&>svg]:text-warning",
},
},
defaultVariants: {
variant: "default",
},
},
);

function Alert({
className,
variant = "default",
...props
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
return (
<div
data-slot="alert"
data-variant={variant}
role="alert"
className={cn(alertVariants({ variant }), className)}
{...props}
/>
);
}

function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-title"
className={cn(
"min-w-0 font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3",
className,
)}
{...props}
/>
);
}

function AlertDescription({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-description"
className={cn(
"min-w-0 text-muted-foreground text-sm text-pretty group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4",
className,
)}
{...props}
/>
);
}

/** What the alert asks for, on its right: a button or two. */
function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-action"
className={cn(
"col-end-[-1] row-span-2 row-start-1 flex shrink-0 items-center gap-2",
className,
)}
{...props}
/>
);
}

export { Alert, AlertAction, AlertDescription, AlertTitle };
43 changes: 30 additions & 13 deletions app/src/components/ui/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,46 @@ import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";

/*
* shadcn's Badge, in its Base UI flavor. Two edits, both to the look (docs/app-guidelines.md):
* the corner is `rounded-full`, the step for round things, where shadcn writes `rounded-4xl`; and
* the `dark:` overrides are gone, since every token already carries its dark value.
* shadcn's Badge, in its Base UI flavor. Three edits, all to the look (docs/app-guidelines.md):
* the corner is `rounded-full`, the step for round things, where shadcn writes `rounded-4xl`; the
* `dark:` overrides are gone, since every token already carries its dark value; and keyboard focus
* is the button's solid ring, with no halo over it.
*
* `muted` and `warning` are ours, beside shadcn's variants and never in place of one: `muted` for a
* quiet state ("Paused"), `warning` for one that wants a look ("needs review").
* `muted`, `success`, `warning` and `in-progress` are ours, beside shadcn's variants and never in
* place of one: `muted` for a quiet state ("Paused"), `success` for what worked or is working
* ("Connected"), `warning` for one that wants a look ("Needs review"), `in-progress` for one still
* going.
*
* A STATUS IS ITS COLOR'S WORDS ON ITS 10% TINT, as the design's kit draws every badge, in 12px
* regular words. tokens/tests/contrast.test.ts holds each status's words at 4.5:1 on its tint over
* the page, a card, a menu, a muted row and the sidebar, in light and dark; light `warning` is the
* kit's warning/25 so that it does on a muted row.
*
* A CHIP IS THE SAME BADGE, rendered as a link or a button (`render`). Only then does the pointer
* change it, its tint deepening to 12% as the design's chip does, and only then can the keyboard
* reach it. Disabled is half strength.
*/
const badgeVariants = cva(
"inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 [&>svg]:pointer-events-none [&>svg]:size-3!",
"inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-normal whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive [&>svg]:pointer-events-none [&>svg]:size-3!",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
default:
"bg-primary text-primary-foreground [a,button]:hover:bg-primary/80",
secondary:
"bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
"bg-secondary text-secondary-foreground [a,button]:hover:bg-secondary/80",
destructive:
"bg-destructive/10 text-destructive focus-visible:ring-destructive/20 [a]:hover:bg-destructive/20",
"bg-destructive/10 text-destructive [a,button]:hover:bg-destructive/12",
outline:
"border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
ghost: "hover:bg-muted hover:text-muted-foreground",
link: "text-primary underline-offset-4 hover:underline",
"border-border text-foreground [a,button]:hover:bg-muted [a,button]:hover:text-muted-foreground",
ghost:
"[a,button]:hover:bg-muted [a,button]:hover:text-muted-foreground",
link: "text-primary underline-offset-4 [a,button]:hover:underline",
muted: "bg-muted text-muted-foreground",
warning: "bg-warning/10 text-warning",
success: "bg-success/10 text-success [a,button]:hover:bg-success/12",
warning: "bg-warning/10 text-warning [a,button]:hover:bg-warning/12",
"in-progress":
"bg-in-progress/10 text-in-progress [a,button]:hover:bg-in-progress/12",
},
},
defaultVariants: {
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/ui/bubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function BubbleContent({
props: mergeProps<"div">(
{
className: cn(
"w-fit max-w-full min-w-0 overflow-hidden rounded-xl border border-transparent px-3 py-2 text-sm leading-relaxed wrap-break-word group-data-[align=end]/bubble:self-end [button]:text-left [button,a]:transition-colors [button,a]:outline-none [button,a]:focus-visible:border-ring [button,a]:focus-visible:ring-3 [button,a]:focus-visible:ring-ring/50",
"w-fit max-w-full min-w-0 overflow-hidden rounded-xl border border-transparent px-3 py-2 text-sm leading-relaxed wrap-break-word group-data-[align=end]/bubble:self-end [button]:text-left [button,a]:transition-colors [button,a]:outline-none [button,a]:focus-visible:border-ring [button,a]:focus-visible:ring-3 [button,a]:focus-visible:ring-ring",
className,
),
},
Expand Down
20 changes: 18 additions & 2 deletions app/src/components/ui/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ import { cn } from "@/lib/utils";
* 1.4.11 asks for 3:1 between a control and what is beside it; `muted-foreground` is the app's
* secondary text, at 4.5:1 or more on every surface in every skin. Ticked, focused and invalid keep
* their own edges. app/tests/checkbox-contrast.test.tsx measures what the browser paints.
*
* PARTLY TICKED (`indeterminate`) is filled as a ticked box is, with a dash for the tick.
*
* UNDER THE POINTER an empty box's edge turns `foreground`, and a ticked one's fill eases to
* `primary/80`, as the button's does. An invalid box keeps its `destructive` edge.
*
* KEYBOARD FOCUS IS THE BUTTON'S SOLID RING: the edge turns `ring`, ticked or not, and 3px more of
* it are drawn outside, 4px in all. AN INVALID BOX IS RED, as the design draws it: filled with
* `destructive/10` under a `destructive` edge, and ticked or partly ticked it is filled with
* `destructive`, as a chosen radio's dot turns `destructive`. It keeps that edge under the focus
* ring and doesn't change under the pointer. No halo hides the ring. Disabled is half strength.
* Flat, as the radio is: no shadow.
*/
function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
return (
<CheckboxPrimitive.Root
data-slot="checkbox"
className={cn(
"peer flex size-4 shrink-0 items-center justify-center rounded-sm border border-muted-foreground shadow-xs outline-none transition-[background-color,border-color,box-shadow] duration-150 ease-out focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground data-disabled:cursor-not-allowed data-disabled:opacity-50",
"group/checkbox peer flex size-4 shrink-0 items-center justify-center rounded-sm border border-muted-foreground outline-none transition-[background-color,border-color,box-shadow] duration-150 ease-out data-unchecked:hover:not-data-disabled:not-aria-invalid:border-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring aria-invalid:border-destructive aria-invalid:bg-destructive/10 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground data-indeterminate:border-primary data-indeterminate:bg-primary data-indeterminate:text-primary-foreground aria-invalid:data-checked:border-destructive aria-invalid:data-checked:bg-destructive aria-invalid:data-indeterminate:border-destructive aria-invalid:data-indeterminate:bg-destructive data-checked:hover:not-data-disabled:not-aria-invalid:border-primary/80 data-checked:hover:not-data-disabled:not-aria-invalid:bg-primary/80 data-indeterminate:hover:not-data-disabled:not-aria-invalid:border-primary/80 data-indeterminate:hover:not-data-disabled:not-aria-invalid:bg-primary/80 data-checked:not-aria-invalid:focus-visible:border-ring data-indeterminate:not-aria-invalid:focus-visible:border-ring data-disabled:cursor-not-allowed data-disabled:opacity-50",
className,
)}
{...props}
Expand All @@ -25,7 +37,11 @@ function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
data-slot="checkbox-indicator"
className="flex items-center justify-center text-current"
>
<IconCheck className="size-3" />
<IconCheck className="size-3 group-data-indeterminate/checkbox:hidden" />
<span
aria-hidden="true"
className="hidden h-0.5 w-2 rounded-full bg-current group-data-indeterminate/checkbox:block"
/>
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
);
Expand Down
Loading