DocumentationStickerBurst
StickerBurst
Bursts colorful decorative symbols around an existing control when it is activated.
Shared live previews stay running while you switch code examples and API documentation.
Place content inside the component. Native attributes and events use Svelte spelling, such as onclick, and bind:element gives
you the root DOM element.
Quick start
Copy the component and everything it needs into your Svelte 5 project.
npx shadcn-svelte@1.8.0 add https://kida-ui.onrender.com/r/svelte/sticker-burst.jsonRun this from a project with components.json. The CLI creates all required files and installs the declared runtime dependencies. New to shadcn? Follow theinstallation guide first.
Files land in src/lib/components/ui/kida by default. SvelteKit 3 projects import them through #lib; SvelteKit 2 and Vite projects use $lib, as in the examples here.
Copy manually6 files
1. Install runtime dependencies
npm install motion@^13.1.02. Create the source files
Keep this directory structure so the component's relative imports continue to work.
src/lib/components/ui/kida/sticker-burst.svelte
<script lang="ts">
import './sticker-burst.css'
import { stickerBurst, stickerBurstLayout } from './sticker-burst.motion.js'
import { untrack } from 'svelte'
import type { StickerBurstProps } from './sticker-burst.types.js'
let {
stickers,
count,
distance,
seed,
element = $bindable(null),
children,
...rest
}: StickerBurstProps = $props()
const defaults = ['β¦', 'β', 'β₯', 'β
']
const symbols = $derived(stickers?.length ? stickers : defaults)
const points = $derived(stickerBurstLayout({ count, distance, seed }))
const root = $derived(element)
$effect(() => {
const node = root
if (!node) return
return untrack(() => stickerBurst(node))
})
</script>
<span {...rest} bind:this={element} data-kida-sticker-burst="" data-state="idle"><span data-kida-sticker-content="">{@render children?.()}</span><span aria-hidden="true" data-kida-sticker-layer="">{#each points as point, index (index)}<span
style:--kida-sticker-x={`${point.x}px`}
style:--kida-sticker-y={`${point.y}px`}
style:--kida-sticker-rotation={`${point.rotation}deg`}
style:--kida-sticker-delay={`${point.delay}ms`}
style:--kida-sticker-scale={point.scale}
>{symbols[index % symbols.length]}</span>{/each}</span></span>src/lib/components/ui/kida/sticker-burst.types.ts
import type { StickerBurstOptions } from './sticker-burst.motion.js';
import type { HTMLAttributes } from 'svelte/elements';
export interface StickerBurstProps extends StickerBurstOptions, HTMLAttributes<HTMLSpanElement> {
stickers?: readonly string[];
element?: HTMLSpanElement | null;
}src/lib/components/ui/kida/sticker-burst.css
@import './tokens.css';
[data-kida-sticker-burst] {
--kida-sticker-color: #e94f86;
--kida-sticker-color-secondary: #a78bfa;
--kida-sticker-color-tertiary: #75c9a6;
--kida-sticker-color-fourth: #f4a261;
--kida-sticker-size: 1rem;
--kida-sticker-duration: 620ms;
position: relative;
display: inline-flex;
isolation: isolate;
}
[data-kida-sticker-content] {
position: relative;
z-index: 1;
display: inline-flex;
}
[data-kida-sticker-layer] {
position: absolute;
z-index: 0;
top: 50%;
left: 50%;
width: 0;
height: 0;
pointer-events: none;
}
[data-kida-sticker-layer] > span {
position: absolute;
top: 0;
left: 0;
color: var(--kida-sticker-color);
font-size: calc(var(--kida-sticker-size) * var(--kida-sticker-scale));
line-height: 1;
opacity: 0;
transform: translate(-50%, -50%) scale(0.3);
}
[data-kida-sticker-layer] > span:nth-child(4n + 2) {
color: var(--kida-sticker-color-secondary);
}
[data-kida-sticker-layer] > span:nth-child(4n + 3) {
color: var(--kida-sticker-color-tertiary);
}
[data-kida-sticker-layer] > span:nth-child(4n) {
color: var(--kida-sticker-color-fourth);
}
[data-kida-sticker-burst][data-state="active"] [data-kida-sticker-layer] > span {
animation: kida-sticker-burst var(--kida-sticker-duration) var(--kida-ease-out)
var(--kida-sticker-delay) both;
}
@keyframes kida-sticker-burst {
0% {
opacity: 0;
transform: translate(-50%, -50%) rotate(0) scale(0.3);
}
18% {
opacity: 1;
}
68% {
opacity: 1;
transform: translate(calc(-50% + var(--kida-sticker-x)), calc(-50% + var(--kida-sticker-y)))
rotate(var(--kida-sticker-rotation)) scale(1);
}
100% {
opacity: 0;
transform: translate(calc(-50% + var(--kida-sticker-x)), calc(-50% + var(--kida-sticker-y)))
rotate(var(--kida-sticker-rotation)) scale(0.86);
}
}
@media (prefers-reduced-motion: reduce) {
[data-kida-sticker-burst][data-state="active"] [data-kida-sticker-layer] > span {
animation: none;
}
}src/lib/components/ui/kida/tokens.css
/*
* Kida UI β motion tokens.
* Plain CSS custom properties (ADR D7). No preprocessor, no Tailwind, no build step.
*/
:root {
/* Durations */
--kida-duration-xs: 100ms;
--kida-duration-sm: 150ms;
--kida-duration-md: 300ms;
--kida-duration-lg: 500ms;
--kida-duration-xl: 800ms;
/* Easings */
--kida-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
--kida-ease-in: cubic-bezier(0.7, 0, 0.84, 0);
--kida-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
--kida-ease-spring: linear(0, 0.5, 0.9, 1.02, 1);
/* Travel distances used by the enter/exit keyframes */
--kida-distance-sm: 4px;
--kida-distance-md: 8px;
--kida-distance-lg: 16px;
/* Stagger step between siblings */
--kida-stagger: 60ms;
}
/*
* The shared reduced-motion guard for CSS-driven animation in the library.
* Durations collapse to ~0 by default. Components whose presence lifecycle cannot safely observe
* a 1ms animation, such as Collapse, disable it explicitly and complete presence in their adapter.
*/
@media (prefers-reduced-motion: reduce) {
:root {
--kida-duration-xs: 1ms;
--kida-duration-sm: 1ms;
--kida-duration-md: 1ms;
--kida-duration-lg: 1ms;
--kida-duration-xl: 1ms;
--kida-distance-sm: 0px;
--kida-distance-md: 0px;
--kida-distance-lg: 0px;
--kida-stagger: 0ms;
}
}src/lib/components/ui/kida/sticker-burst.motion.ts
import { prefersReducedMotion } from './reduced-motion.motion.js'
export interface StickerBurstPoint {
x: number
y: number
rotation: number
delay: number
scale: number
}
export interface StickerBurstOptions {
/** Number of decorative pieces. @default 8 */
count?: number
/** Maximum travel in CSS pixels. @default 64 */
distance?: number
/** Stable layout seed. @default 17 */
seed?: number
}
const DEFAULTS = { count: 8, distance: 64, seed: 17 } as const
function random(seed: number) {
let state = seed >>> 0
return () => {
state += 0x6d2b79f5
let value = state
value = Math.imul(value ^ (value >>> 15), value | 1)
value ^= value + Math.imul(value ^ (value >>> 7), value | 61)
return ((value ^ (value >>> 14)) >>> 0) / 4294967296
}
}
/** Stable geometry keeps server output and hydration identical. */
export function stickerBurstLayout(options: StickerBurstOptions = {}): StickerBurstPoint[] {
const count = Math.max(1, Math.min(16, Math.round(options.count ?? DEFAULTS.count)))
const distance = Math.max(16, options.distance ?? DEFAULTS.distance)
const next = random(options.seed ?? DEFAULTS.seed)
return Array.from({ length: count }, (_, index) => {
const angle = -Math.PI / 2 + (Math.PI * 2 * index) / count + (next() - 0.5) * 0.3
const radius = distance * (0.72 + next() * 0.28)
return {
x: Math.round(Math.cos(angle) * radius * 100) / 100,
y: Math.round(Math.sin(angle) * radius * 100) / 100,
rotation: Math.round((next() * 100 - 50) * 100) / 100,
delay: Math.round(index * 18 + next() * 18),
scale: Math.round((0.82 + next() * 0.36) * 100) / 100,
}
})
}
/** Replays the CSS burst for pointer and keyboard-generated clicks. */
export function stickerBurst(root: HTMLElement): () => void {
root.dataset.state = 'idle'
if (prefersReducedMotion()) return () => {}
const replay = () => {
root.dataset.state = 'idle'
// A single layout read per intentional trigger restarts the finite CSS animation.
void root.offsetWidth
root.dataset.state = 'active'
}
root.addEventListener('click', replay)
return () => {
root.removeEventListener('click', replay)
root.dataset.state = 'idle'
}
}src/lib/components/ui/kida/reduced-motion.motion.ts
const QUERY = '(prefers-reduced-motion: reduce)'
/**
* Whether the user has asked for reduced motion.
*
* SSR-safe: returns `false` when there is no `window`, matching the CSS default
* (the `prefers-reduced-motion` media query in `@kida-ui/styles` is the real guard;
* this is for the JS-driven paths that CSS cannot express).
*/
export function prefersReducedMotion(): boolean {
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return false
return window.matchMedia(QUERY).matches
}
/**
* Subscribe to changes of the reduced-motion preference.
* Returns an unsubscribe function. No-op (and immediately unsubscribable) on the server.
*/
export function watchReducedMotion(onChange: (reduced: boolean) => void): () => void {
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return () => {}
const list = window.matchMedia(QUERY)
const handler = (event: MediaQueryListEvent) => onChange(event.matches)
list.addEventListener('change', handler)
return () => list.removeEventListener('change', handler)
}<script lang="ts">
import StickerBurst from '$lib/components/ui/kida/sticker-burst.svelte'
</script>
<StickerBurst stickers={['β¦', 'πββ¬', 'β₯', 'β
']}><button type="button">Celebrate</button></StickerBurst>API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
stickers |
readonly string[] |
['β¦', 'β', 'β₯', 'β
'] |
Decorative symbols repeated through the burst. |
count |
number |
8 |
Number of pieces, clamped from 1 to 16. |
distance |
number |
64 |
Maximum travel in CSS pixels. |
seed |
number |
17 |
Stable seed used to vary the layout. |
element |
HTMLSpanElement | null |
null |
Use bind:element to read the root DOM element. |
The root also accepts span attributes, class, style, and event handlers.
CSS custom properties
| Property | Default | Description |
|---|---|---|
--kida-sticker-color |
#e94f86 |
First piece color. |
--kida-sticker-color-secondary |
#a78bfa |
Second piece color. |
--kida-sticker-color-tertiary |
#75c9a6 |
Third piece color. |
--kida-sticker-color-fourth |
#f4a261 |
Fourth piece color. |
--kida-sticker-size |
1rem |
Base size of each symbol. |
--kida-sticker-duration |
620ms |
Burst duration. |
Customization
Pass a short stickers set to change the visual language, then tune count, distance, and
seed to control density and layout. The four color variables cycle through the generated pieces;
--kida-sticker-size and --kida-sticker-duration control their scale and timing.
Accessibility and input behavior
StickerBurst does not replace the wrapped controlβs semantics or click handler. Wrap a native button or another accessible interactive element so pointer and keyboard-generated clicks both trigger the effect. The burst layer is decorative and hidden from assistive technology, and its seeded geometry stays identical during server rendering and hydration.
When reduced motion is requested, no burst runs and the wrapped control continues to work normally.
Troubleshooting
StickerBurst responds to click events from its child. Wrap a native button or another element that produces keyboard clicks, and check ancestor
overflowrules if distant pieces are clipped.