// ~/src/siteplane/components/illustration/illustration.tsx import * as React from "react"; import { cn } from "../../system/utils/cn"; import { slotClass } from "../../system/utils/slot-class"; import "./illustration.css"; /** The drawing: a cloud, a box, a credit card or a few documents. */ export type IllustrationType = "cloud" | "box" | "credit-card" | "documents"; /** `sm` is 120 px high, `md` 128 px and `lg`, the default, 160 px. */ export type IllustrationSize = "sm" | "md" | "lg"; export interface IllustrationProps extends Omit< React.ComponentProps<"div">, "children" | "title" > { /** Which drawing to show. */ type: IllustrationType; /** * The size: `sm` is 120 px high, `md` 128 px and `lg` 160 px. The width follows from the drawing's proportions. An * Illustration in the media of an Empty takes the height of the Empty's size * instead. `lg` by default. */ size?: IllustrationSize | undefined; /** * The glyph that floats over the drawing in a frosted disc, such as a * magnifier on the cloud or an upload arrow on the box. Pass a Phosphor icon * with `aria-hidden="true"`; its size comes from the disc. Without it the * drawing stands alone. */ children?: React.ReactNode; } /** The small discs that scatter around the large one: x, y and radius. */ const specks = [ [26, 20, 8], [191, 11, 7], [210, 46, 10], [198, 126, 6], [25, 138, 10], ] as const; /** A rounded rectangle as a path, so a surface and its shade share one shape. */ function roundedRect( x: number, y: number, width: number, height: number, radius: number, ): string { const r = radius; return `M${x + r} ${y}H${x + width - r}A${r} ${r} 0 0 1 ${x + width} ${y + r}V${y + height - r}A${r} ${r} 0 0 1 ${x + width - r} ${y + height}H${x + r}A${r} ${r} 0 0 1 ${x} ${y + height - r}V${y + r}A${r} ${r} 0 0 1 ${x + r} ${y}Z`; } /** * A shape that is lit from its top start corner: the opaque surface, then the * shade that fades out of the corner, then, when the shape asks for it, its * hairline edge. */ function Lit({ d, edge = true, shade, }: { d: string; edge?: boolean; shade: string; }) { return ( <> {edge ? : null} ); } /** A cloud of three lobes on a flat base, shaded lobe by lobe. */ function Cloud({ shade }: { shade: string }) { const outline = "M63.77 115.43A39.77 39.77 0 1 1 72.94 36.95A49.71 49.71 0 0 1 159.16 46.06A34.8 34.8 0 1 1 163.2 115.43Z"; return ( <> ); } /** A closed box seen from above and aside, with a slit on its lid. */ function Box({ shade }: { shade: string }) { const outline = "M110 12 168 39V109L110 136 52 109V39Z"; return ( <> ); } /** A card with a chip, two overlapping discs and four groups of digits. */ function CreditCard({ shade }: { shade: string }) { return ( <> {[58, 84, 110, 136].map((x) => ( ))} ); } /** One sheet of paper with a folded corner and three lines of text. */ function Sheet({ angle = 0, shade, x, y, }: { angle?: number; shade: string; x: number; y: number; }) { const width = 58; const height = 76; const fold = 14; const r = 6; const d = `M${x + r} ${y}H${x + width - fold}L${x + width} ${y + fold}V${y + height - r}A${r} ${r} 0 0 1 ${x + width - r} ${y + height}H${x + r}A${r} ${r} 0 0 1 ${x} ${y + height - r}V${y + r}A${r} ${r} 0 0 1 ${x + r} ${y}Z`; return ( {[28, 40, 52].map((offset, index) => ( ))} ); } function Documents({ shade }: { shade: string }) { return ( <> ); } const drawings = { box: Box, "credit-card": CreditCard, cloud: Cloud, documents: Documents, } as const satisfies Record< IllustrationType, (props: { shade: string }) => React.ReactElement >; /** * A drawing for an empty state: a cloud, a box, a credit card or a few * documents on a soft disc with a few specks, an optional glyph floating over * it in a frosted disc. It is drawn in the kit's surface * and edge tokens, so it follows the theme, and it is decoration: it is hidden * from assistive technology unless it carries an `aria-label`, which makes it * an image. Put it in an EmptyMedia with `variant="illustration"` to give an * empty state its picture. */ export function Illustration({ children, className, size = "lg", type, ...props }: IllustrationProps): React.ReactElement { const id = React.useId(); const shade = `${id}-shade`; const shadow = `${id}-shadow`; const Drawing = drawings[type]; const labelled = props["aria-label"] !== undefined; return (
{specks.map(([cx, cy, r]) => ( ))} {children ? ( {children} ) : null}
); } // ~/src/siteplane/components/illustration/illustration.css @layer theme, base, components, siteplane, utilities; @layer siteplane { /* An Illustration is an empty-state drawing in the kit's surface * and edge tokens: a soft disc with a few specks, an object on it that * casts a shadow, and an optional glyph in a frosted disc over the object's * lower middle. One drawing at one proportion (220 by 160); the size is its * height, 120, 128 or 160 px, and the width follows. The frosted disc and * its glyph are measured against that height, so they scale with it, which * is also what lets an Empty give the illustration its own height. The * defaults sit at zero specificity, so the media of an Empty, which sets the * height of its size, replaces them (P6). */ :where(.sp-illustration) { position: relative; display: inline-block; height: calc(var(--sp-rw-space) * 40); flex-shrink: 0; aspect-ratio: 220 / 160; } :where(.sp-illustration[data-size="md"]) { height: calc(var(--sp-rw-space) * 32); } :where(.sp-illustration[data-size="sm"]) { height: calc(var(--sp-rw-space) * 30); } :root .sp-illustration-svg { display: block; width: 100%; height: 100%; overflow: visible; } /* The disc and the specks are the muted surface tint, so they follow the * theme and show through nothing. */ :root .sp-illustration-disc { fill: var(--sp-rw-bg-muted); } /* The object: an opaque surface with a hairline edge, lit from its top start * corner by a shade that fades out of it, and the folds, lines and marks * drawn on it in the edge tone. */ :root .sp-illustration-surface { fill: var(--sp-rw-bg-secondary); } :root .sp-illustration-depth { fill: var(--sp-rw-bg-depth); } :root .sp-illustration-fold { fill: var(--sp-rw-border-translucent); } :root .sp-illustration-edge { fill: none; stroke: var(--sp-rw-border-translucent); stroke-linejoin: round; stroke-width: 1; } :root .sp-illustration-shade-start { stop-color: var(--sp-rw-bg-depth); } :root .sp-illustration-shade-end { stop-color: var(--sp-rw-bg-depth); stop-opacity: 0; } /* The shadow under the object, a tight contact shadow and a long soft one, in * black at the kit's shadow strengths; darker in Dark. */ :root .sp-illustration-contact { flood-color: oklch(0% 0 0); flood-opacity: 0.06; } :root .sp-illustration-ambient { flood-color: oklch(0% 0 0); flood-opacity: 0.08; } :where(.dark, [data-theme="dark"]) .sp-illustration-contact { flood-opacity: 0.24; } :where(.dark, [data-theme="dark"]) .sp-illustration-ambient { flood-opacity: 0.32; } /* The glyph floats at the bottom middle of the drawing in a frosted disc: a * translucent dark disc that blurs what is behind it, with a white glyph at * half its size. Its size and its distance from the bottom are shares of the * illustration's height. */ :root .sp-illustration-badge { position: absolute; bottom: 12.5%; left: 50%; z-index: 10; display: flex; height: 35%; aspect-ratio: 1; align-items: center; justify-content: center; border-radius: var(--sp-rw-radius-full); background: oklch(0% 0 0 / 20%); color: var(--sp-rw-fg-on-accent); translate: -50% 0; -webkit-backdrop-filter: blur(var(--sp-rw-space-1)); backdrop-filter: blur(var(--sp-rw-space-1)); } :root .sp-illustration[data-size="md"] .sp-illustration-badge { bottom: 9.375%; height: 43.75%; } :root .sp-illustration[data-size="sm"] .sp-illustration-badge { bottom: 6.667%; height: 40%; } :root .sp-illustration-badge > svg { width: 50%; height: 50%; flex-shrink: 0; } } // ~/src/siteplane/components/illustration/index.ts export * from "./illustration";