Sticker
A sticker is hand-drawn art cut out like a paper sticker, marking a moment such as the end of a trip or a page with nothing on it yet.
Installation
npx shadcn@latest add @flyingsalmon/stickerUsage
import { houseStickerArt } from '@/components/house-sticker-art'
import {
houseStickerLabel,
houseStickerRoleClassNames,
} from '@/components/house-sticker'
import { Sticker } from '@/components/ui/sticker'
export function TripHomeSticker() {
return (
<Sticker
art={houseStickerArt}
label={houseStickerLabel}
roleClassNames={houseStickerRoleClassNames}
/>
)
}Examples
Beside its title
The sticker sits next to a title that says the same thing in words. A small tilt, two or three degrees either way, keeps it from looking printed.
Welcome home, Brian
Your Hanoi in spring trip is over. Share the photos with the people who came along.
Pop-in on scroll
By default the sticker grows from small and tilted, overshoots, and settles as it scrolls into view. Scroll this one in and out of view; it plays backwards when you scroll back.
Size and tilt
The sticker fills the width its parent gives it and keeps the art’s aspect ratio. It sets no size and no tilt of its own, so set both with className.
Still heap
Three stickers overlap as one piece of art, and each holds still on its first drawing. Boiling together, they would jitter against each other and read as noise rather than as one picture.
Guidelines
When to use
- To mark a moment: a finished trip, a first visit, a page with nothing on it yet.
- Beside a title that says the same thing in words.
When not to use
- Use Badge to label a status or a count, because a badge is small, static, and states the state in words.
- Use Empty state to tell the traveller a page is empty, with a sticker beside the message rather than in place of it.
Do and don’t
- DoKeep a title beside the sticker that says what it says.The art is decoration with a job. It never replaces the words.
- DoUse one sticker per screen, or one heap of stickers that reads as a single picture, tilted a few degrees.The tilt makes it read as stuck on rather than laid out in the grid, and a second sticker apart from the first would compete for the same moment.
- DoHold every sticker in a heap still.Boiling together, overlapping stickers jitter against each other and read as noise; held still, the heap reads as one illustration.
- DoHold a sticker still when it sits beside content that needs the reader's attention, such as a form or a long passage.Motion pulls the eye, and a boiling sticker competes with the words and fields beside it.
- DoPut a sticker beside the heading of a long wait, such as a trip being planned.The spinner says work is under way and the sticker turns the wait into a moment, so the screen never reads as empty.
- Don’tLay a sticker over text or controls.A sticker may bleed off the edge of its panel, but it never hides a word or catches a press meant for a control.
- Don’tUse a sticker for a routine state the traveller sees on every visit.Stickers are kept for moments. Seen every time, one stops reading as a moment and becomes wallpaper.
Accessibility
The sticker is one image: an svg with role="img" named by label, with its paths presentational. Keep the label short and describe the picture, not its purpose: “A house with a plane flying home”. It takes no focus and has no states. Its colours carry no meaning of their own, so they have no contrast floor; the title beside the sticker carries the meaning.
API
Sticker
Also takes every <svg> attribute; className reaches the root svg.
| Prop | Type | Default | Description |
|---|---|---|---|
| art | StickerArt | Required | The frames a drawing script generated: a width and height in drawing units and exactly three frames. Never write or edit it by hand: a hand-edited module is lost the next time the script runs. |
| label | string | Required | Names the picture for screen readers. |
| roleClassNames | StickerRoleClassNames | Required | Maps each role in the art to a Tailwind class per paint. A role the map leaves out draws in the foreground colour. |
| popIn | boolean | true | Plays the scroll-linked pop-in. Pass false for a sticker already in view when its page opens: the pop is tied to scroll position, so a sticker at the top of a page would sit part-way through it until the reader scrolled. |
| boil | boolean | true | Boils the lines, swapping the three frames on a loop. Pass false to hold the sticker still on its first drawing. |
The role map
roleClassNames gives each role a class per paint. Spell the classes out in full so Tailwind finds them, and split them by paint, because a fill class on a stroke path would override its fill="none". Take colours from the theme’s functional aliases: --foreground for ink, --card for paper, and the group colours for everything that tells one part from another. Every line draws at the same weight unless its role’s classes set another, as the dotted trail behind the plane does. This is the house sticker’s map. Name each role after a part of the drawing, such as roof or door, never after a colour, so the same art follows whatever theme draws it.
| Role | Fill | Stroke |
|---|---|---|
ink | fill-foreground | stroke-foreground |
trail | | stroke-foreground stroke-[2.4] [stroke-dasharray:0.5_7] |
paper | fill-card | |
wall | fill-group-sky-soft | |
roof | | stroke-group-pink |
brick | fill-group-fuchsia-border | |
door | fill-group-teal | |
glass | fill-group-sky | |
smoke | fill-muted | |
plane | fill-card | |
petal | fill-group-pink | |