Skip to content

API reference

Every function, option and type, as the package exports them.

@cesarvenzac/stickersv0.2.0

sticker

function sticker(element: HTMLElement, src: Source, options?: StickerOptions): Sticker;

type Source = string | CanvasImageSource;

type Sticker = {
  readonly element: HTMLElement;
  readonly place: Place;
  readonly state: "loading" | "resting" | "peeling" | "held" | "off";
  set(options: StickerOptions & { src?: Source }): void;
  peelOff(): void;
  restore(): void;
  destroy(): void;
};

type Place = { x: number; y: number; angle: number };

StickerOptions

type StickerOptions = {
  finish?: Finish; // "gloss"
  pattern?: Pattern; // a holographic foil's, "smooth"
  label?: string;
  outline?: number; // a 16th of the box's shorter side
  smooth?: number; // twice the outline
  border?: string; // white
  back?: string;
  print?: string;
  peel?: boolean; // true
  drag?: boolean; // false
  bounds?: Element | null; // its parent
  dark?: boolean | "auto"; // "auto"
  glow?: string; // phosphor green
  curl?: number; // the curl's radius, pixels
  comesOff?: number; // 0.5
  shine?: boolean; // true
  place?: Place;
  seed?: number;
  reducedMotion?: boolean; // the visitor's setting
  onPeel?: () => void;
  onPick?: () => void;
  onDrop?: (place: Place) => void;
};

type Finish = "paper" | "gloss" | "holo" | "glitter" | "glow";
type Pattern = "smooth" | "lines" | "squares" | "dots" | "shards";
const FINISHES: readonly Finish[];
const PATTERNS: readonly Pattern[];

React

@cesarvenzac/stickers/react, a client component. Every option is a prop; the rest go on the <div>.

function Sticker(props: StickerOptions & HTMLAttributes<HTMLDivElement> & {
  src: Source;
  handle?: (sticker: Sticker | null) => void;
}): JSX.Element;