Demo Label
The label under a piece in a demo or gallery, set in the mono face at 12px in the default text color so it reads as a note about the piece, never part of it.
import type { ComponentProps } from "react"
import { cn } from "cn"
/**
* A caption under a demo or gallery piece, in medium-weight mono at
* 12px/20px. Long captions wrap with balanced last lines. The caption
* inherits its ground's text color; native paragraph props pass through.
*/
function DemoLabel({ className, ...props }: ComponentProps<"p">) {
return (
<p
data-slot="demo-label"
className={cn("font-mono text-xs/5 font-medium text-pretty", className)}
{...props}
/>
)
}
export { DemoLabel }
import { PlanetIcon } from "@phosphor-icons/react/ssr"
import { GlassIcon } from "@/components/graphics/glass-icon"
import { DemoLabel } from "@/components/text/demo-label"
import { Badge } from "@/components/ui/badge"
import { Kbd, KbdGroup } from "@/components/ui/kbd"
const COPY = {
badge: "Published",
badgeCaption: "Badge · outline",
glassCaption: "Glass Icon · sm, 64px",
modifier: "⌘",
key: "K",
keyboardCaption:
"Keyboard shortcut · Command K, with a longer caption in a narrow layout.",
} as const
/** Captions under a badge, a glass icon on dark ink, and a keyboard shortcut. */
export default function DemoLabelDemo() {
return (
<div className="flex w-full max-w-3xl flex-wrap items-start gap-6 p-6">
<div className="grid w-full min-w-0 justify-items-start gap-3 p-4 sm:w-48">
<div className="flex h-16 items-center">
<Badge variant="outline">{COPY.badge}</Badge>
</div>
<DemoLabel>{COPY.badgeCaption}</DemoLabel>
</div>
<div className="dark grid w-full min-w-0 justify-items-start gap-3 rounded-(--tile-radius) bg-scene p-4 text-scene-foreground sm:w-56">
<GlassIcon size="sm" className="bg-blue-9/20">
<PlanetIcon
aria-hidden="true"
className="text-blue-8"
weight="regular"
/>
</GlassIcon>
<DemoLabel>{COPY.glassCaption}</DemoLabel>
</div>
<div className="grid w-full min-w-0 justify-items-start gap-3 p-4 sm:w-48">
<div className="flex h-16 items-center">
<KbdGroup>
<Kbd>{COPY.modifier}</Kbd>
<Kbd>{COPY.key}</Kbd>
</KbdGroup>
</div>
<DemoLabel>{COPY.keyboardCaption}</DemoLabel>
</div>
</div>
)
}
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const glassIconVariants = cva(
"flex shrink-0 items-center justify-center surface-glaze text-scene-foreground glass-edge",
{
variants: {
size: {
sm: "size-16 rounded-lg [&_svg:not([class*='size-'])]:size-6",
md: "size-24 rounded-xl [&_svg:not([class*='size-'])]:size-9",
lg: "size-32 rounded-2xl [&_svg:not([class*='size-'])]:size-12",
},
},
defaultVariants: { size: "md" },
}
)
/**
* A rounded glass tile that frames one icon. `size` sets the tile, its
* corners and the icon together: `sm` 64px with a 24px icon, `md` (the
* default) 96px with 36px, `lg` 128px with 48px. An icon with its own
* `size-*` class keeps it. The look is `surface-glaze` with `glass-edge` and
* light scene ink, made for dark art surfaces.
*/
function GlassIcon({
className,
size,
children,
...props
}: React.ComponentProps<"div"> & VariantProps<typeof glassIconVariants>) {
return (
<div
className={cn(glassIconVariants({ size }), className)}
data-slot="glass-icon"
data-size={size ?? "md"}
{...props}
>
{children}
</div>
)
}
export { GlassIcon, glassIconVariants }
Installation
npx shadcn@latest add @01orbital/demo-labelUsage
import { PlanetIcon } from "@phosphor-icons/react/ssr"
import { GlassIcon } from "@/components/graphics/glass-icon"
import { DemoLabel } from "@/components/text/demo-label"
import { Badge } from "@/components/ui/badge"
import { Kbd, KbdGroup } from "@/components/ui/kbd"
const COPY = {
badge: "Published",
badgeCaption: "Badge · outline",
glassCaption: "Glass Icon · sm, 64px",
modifier: "⌘",
key: "K",
keyboardCaption:
"Keyboard shortcut · Command K, with a longer caption in a narrow layout.",
} as const
/** Captions under a badge, a glass icon on dark ink, and a keyboard shortcut. */
export default function DemoLabelDemo() {
return (
<div className="flex w-full max-w-3xl flex-wrap items-start gap-6 p-6">
<div className="grid w-full min-w-0 justify-items-start gap-3 p-4 sm:w-48">
<div className="flex h-16 items-center">
<Badge variant="outline">{COPY.badge}</Badge>
</div>
<DemoLabel>{COPY.badgeCaption}</DemoLabel>
</div>
<div className="dark grid w-full min-w-0 justify-items-start gap-3 rounded-(--tile-radius) bg-scene p-4 text-scene-foreground sm:w-56">
<GlassIcon size="sm" className="bg-blue-9/20">
<PlanetIcon
aria-hidden="true"
className="text-blue-8"
weight="regular"
/>
</GlassIcon>
<DemoLabel>{COPY.glassCaption}</DemoLabel>
</div>
<div className="grid w-full min-w-0 justify-items-start gap-3 p-4 sm:w-48">
<div className="flex h-16 items-center">
<KbdGroup>
<Kbd>{COPY.modifier}</Kbd>
<Kbd>{COPY.key}</Kbd>
</KbdGroup>
</div>
<DemoLabel>{COPY.keyboardCaption}</DemoLabel>
</div>
</div>
)
}This example installs with everything it uses:
npx shadcn@latest add @01orbital/demo-label-demoAPI reference
A caption under a demo or gallery piece, in medium-weight mono at 12px/20px. Long captions wrap with balanced last lines. The caption inherits its ground's text color; native paragraph props pass through.
It accepts the HTML attributes of the element it renders.
Dependencies
npm: cn. The CLI installs it for you.
Requires these pieces. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
font-geist-mono
Last updated on