Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions .claude/skills/openbot-screen-layout/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ PageShell the page: header (title, description, action, backButton) then
`PageShell` takes a `width`: `prose` (`max-w-3xl`, 768px) is the default, and every
configuration screen uses it so no screen is wider than another. Sentences inside it are held to
`max-w-prose`, so the column has room for a label beside its control without stretching the text.
`wide` (`max-w-5xl`) exists for one screen — `admin/audit.tsx`, because an audit log is a table to be
scanned and prose width would wrap every row. It is not a licence for anything else to be wide.
`wide` (`max-w-4xl`, 896px) is for a grid of cards picked out by how they look: the Artifacts
gallery, three cards a row on a desktop window. `full` (no column) exists for one screen, the audit
log (`manage/audit-page.tsx`), because it is a table to be scanned and prose width would wrap every
row. Neither is a licence for rows or forms to be wide.

## The Rhythm

Expand Down Expand Up @@ -227,7 +229,8 @@ is actually on screen. The root was once 15px, and every constant taken from the
- A width, ratio or scale needs a number in pixels → the Units section. Measure, do not assume.
- Choosing a margin or gap between blocks → the Rhythm table. If the frame already gives it, set none.
- The screen genuinely does not fit this shape → say so in the response and comment the reason in the
code. There are two accepted precedents: a table (`admin/audit.tsx`, `width="wide"`), and the
code. There are three accepted precedents: a table (the audit log, `width="full"`), the
Artifacts gallery (`width="wide"`, a grid of cards), and the
Connections tiles (`connections.index.tsx`), a grid of separate `variant="outline"` cards, 56px
tall and 12px apart, because apps are picked out by their mark rather than read down as a list.
- The question is which states the screen renders while loading or failing → not this skill;
Expand All @@ -239,7 +242,7 @@ is actually on screen. The root was once 15px, and every constant taken from the
|--------|---------------|------------|
| A hand-written `rounded-lg border border-border bg-card` div wrapping rows | `PageRows` re-implemented, and it will drift from the other seven screens | Use `PageRows` |
| Rows separated by `gap-*` instead of `<Separator />` | A stack of cards rather than one card of rows | `<Separator />` between rows, none after the last |
| `width="wide"` on anything that is not a table | Prose width is the default for a reason; wide was for the audit log | Leave `width` alone |
| `width="wide"` or `"full"` on rows or a form | Prose width is the default for a reason; the others are for a grid of cards and a table | Leave `width` alone |
| A `max-w-*`, `p-*` or text size invented for one screen | A fifth container width, which is what this layout exists to stop | Reach for the existing component |
| Children on an element passed to `Item`'s `render` | They replace the row's own children; the row draws empty | Pass a childless element |
| `bg-card` on a row inside a dialog | `--card` equals `--popover`; the row is invisible | `variant="muted"` |
Expand Down
132 changes: 132 additions & 0 deletions app/src/components/artifacts/artifact-full-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { Link } from "@tanstack/react-router";
import { type Ref, useEffect, useRef } from "react";
import { IconChevronLeft } from "@/components/icons";
import { SidebarToggle } from "@/components/layout/sidebar-toggle";
import { Button } from "@/components/ui/button";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import {
ArtifactViewer,
type ArtifactViewerProps,
} from "./viewer/artifact-viewer";

const BACK_LABEL = "Back to Artifacts";

declare module "@tanstack/react-router" {
interface HistoryState {
/**
* Set by the panel's Open full screen: the artifact's own page was opened from the conversation
* beside it, so its Back goes back there.
*/
artifactFromConversation?: boolean;
}
}

/** Escape closes the artifact, as the sheet it replaces did, unless something else takes it. */
function escapeIsOurs(event: KeyboardEvent): boolean {
if (event.key !== "Escape" || event.defaultPrevented || event.isComposing)
return false;
const target = event.target instanceof Element ? event.target : null;
// A field keeps Escape: half a comment is not thrown away with the artifact.
if (target?.closest("input, textarea, select, [contenteditable=true]"))
return false;
// A menu, a select or a dialog over the viewer closes first, on its own Escape.
return !document.querySelector(
"[role=dialog], [role=alertdialog], [role=menu], [role=listbox]",
);
}

/**
* An artifact, opened full page in the app's main pane, edge to edge: the viewer with one header
* row, which starts with the sidebar's toggle (when the sidebar is hidden) and the way back to the
* Artifacts page. The sidebar stays where it is, so the person can go anywhere else from here too.
*
* Drawn over the Artifacts page when a tile opens it (`?artifact=<id>`), and on its own address
* (`/artifacts/<id>`).
*
* `onBack` is for a page that goes back in the history: the Artifacts page, so the list comes back
* as it was left, or the conversation it was opened from. Without it, Back is a link to the
* Artifacts page. Escape is Back too.
*/
export function ArtifactFullPage({
onBack,
backLabel = BACK_LABEL,
focusBack = false,
...viewer
}: Omit<ArtifactViewerProps, "place" | "leading" | "fullScreen"> & {
onBack?: () => void;
/** What Back is called, to the eye and to a screen reader: where it goes. */
backLabel?: string;
/** Move focus to Back once drawn: the tile that opened it is behind the viewer now. */
focusBack?: boolean;
}) {
const back = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
useEffect(() => {
const onKey = (event: KeyboardEvent) => {
if (!escapeIsOurs(event)) return;
event.preventDefault();
back.current?.click();
};
document.addEventListener("keydown", onKey);
return () => document.removeEventListener("keydown", onKey);
}, []);
// The viewer draws its header once the artifact is read, so Back may come a moment later.
useEffect(() => {
if (!focusBack) return;
let frame = 0;
let tries = 0;
const focus = () => {
if (back.current) back.current.focus();
else if (tries++ < 120) frame = requestAnimationFrame(focus);
};
focus();
return () => cancelAnimationFrame(frame);
}, [focusBack]);

const backButton = (
<Tooltip>
<TooltipTrigger
render={
onBack ? (
<Button
aria-label={backLabel}
onClick={onBack}
ref={back as Ref<HTMLButtonElement>}
size="icon"
variant="ghost"
/>
) : (
<Button
aria-label={backLabel}
ref={back as Ref<HTMLButtonElement>}
render={(props) => <Link {...props} to="/artifacts" />}
size="icon"
variant="ghost"
/>
)
}
>
<IconChevronLeft />
</TooltipTrigger>
<TooltipContent side="bottom">{backLabel}</TooltipContent>
</Tooltip>
);

return (
<div className="flex h-full min-h-0 flex-col">
<ArtifactViewer
{...viewer}
leading={
<>
<SidebarToggle />
{backButton}
</>
}
place="page"
/>
</div>
);
}
44 changes: 26 additions & 18 deletions app/src/components/artifacts/artifacts-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ function useDebounced<T>(value: T, ms: number): T {
/**
* Every artifact the person can open: All, their own, those shared with them, and those they pinned,
* with a search by title, a filter by kind, and a grid of glimpses or a list of rows. Opening one
* shows it in the panel beside the list.
* shows it full page, over the list (`routes/_authed/_app/artifacts.tsx`).
*
* DEVIATES FROM THE ROWS-ONLY LAYOUT, on purpose. The grid is a set of separate cards, as the
* Connections tiles are, because an artifact is picked out by how it looks, not read down as a list.
* The list is the usual `PageRows`.
* So the page is `wide`: three cards a row on a desktop window, two when the column is narrower,
* one on a phone. The list is the usual `PageRows`.
*/
export function ArtifactsPage({
filter,
Expand All @@ -110,7 +111,7 @@ export function ArtifactsPage({
filter: ArtifactsFilter;
onFilterChange: (next: Partial<ArtifactsFilter>) => void;
onOpen: (artifactId: string) => void;
/** The artifact open in the panel, marked in the list. */
/** The artifact open over the list, marked in it. */
openId: string | undefined;
}) {
const [typed, setTyped] = useState(filter.search);
Expand All @@ -134,6 +135,7 @@ export function ArtifactsPage({
<PageShell
description="Documents, decks, dashboards and pages your Bots made, and the ones shared with you."
title="Artifacts"
width="wide"
>
<nav aria-label="Which artifacts" className="flex flex-wrap gap-1">
{VIEWS.map(({ view, label }) => (
Expand Down Expand Up @@ -231,21 +233,25 @@ export function ArtifactsPage({
</PageEmpty>
)
) : filter.layout === "grid" ? (
<ul
aria-label="Artifacts"
className="mt-4 grid grid-cols-1 gap-3 sm:grid-cols-2"
>
{artifacts.map((artifact) => (
<li key={artifact.id}>
<ArtifactTile
artifact={artifact}
me={me}
onOpen={onOpen}
open={artifact.id === openId}
/>
</li>
))}
</ul>
// The columns follow the column's own width, not the window's: the sidebar takes a share of
// the window that a breakpoint can't see.
<div className="@container mt-4">
<ul
aria-label="Artifacts"
className="grid grid-cols-1 gap-3 @md:grid-cols-2 @3xl:grid-cols-3"
>
{artifacts.map((artifact) => (
<li key={artifact.id}>
<ArtifactTile
artifact={artifact}
me={me}
onOpen={onOpen}
open={artifact.id === openId}
/>
</li>
))}
</ul>
</div>
) : (
<PageRows>
{artifacts.map((artifact, index) => (
Expand Down Expand Up @@ -305,6 +311,7 @@ function ArtifactTile({
"relative overflow-hidden transition-colors hover:border-ring",
open && "border-ring",
)}
data-artifact-id={artifact.id}
data-slot="artifact-tile"
>
<ArtifactGlimpse
Expand Down Expand Up @@ -356,6 +363,7 @@ function ArtifactRow({
return (
<Item
aria-current={open || undefined}
data-artifact-id={artifact.id}
className={cn(
"cursor-pointer text-left hover:bg-muted",
open && "bg-muted",
Expand Down
Loading
Loading