npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@casino-ui/slot-machine

v1.0.1

Published

Responsive, configurable React slot machine / reel component with customizable item rendering

Readme

slot-machine

A responsive, configurable React slot machine / reel component. Use one component per reel; combine multiple reels for a full slot grid. No external UI or state library required—bring your own items and styling.

Framework-agnostic: All layout uses inline styles (no Tailwind or CSS required). Works in Vite, Next.js, CRA, or any React app. Give the wrapper a defined size (e.g. height: 400px or width: 100%; height: 100% inside a sized parent) so the reel centers and displays correctly.

Install

npm install slot-machine
# or
yarn add slot-machine
pnpm add slot-machine

Peer dependencies

  • react >= 18
  • react-dom >= 18

Basic usage

import { SlotMachine, type SlotItem, type SlotMachineHandle } from "slot-machine";
import { useRef } from "react";

const items: SlotItem[] = [
  { id: "1", image: "/cherry.png", name: "Cherry" },
  { id: "2", image: "/lemon.png", name: "Lemon" },
  { id: "3", image: "/seven.png", name: "Seven" },
];

function App() {
  const ref = useRef<SlotMachineHandle>(null);

  return (
    <div style={{ width: "100%", height: "400px" }}>
      <SlotMachine
        ref={ref}
        items={items}
        onSpinEnd={(result) => console.log("Landed on", result)}
      />
      <button onClick={() => ref.current?.spin()}>Spin</button>
    </div>
  );
}

Multiple reels (slot count)

Render one SlotMachine per reel and control spin via refs:

const SLOT_COUNT = 6;
const refs = useRef<(SlotMachineHandle | null)[]>([]);

<div style={{ display: "flex", gap: 8, width: "100%", height: 450 }}>
  {Array.from({ length: SLOT_COUNT }).map((_, i) => (
    <div key={i} style={{ flex: 1, minWidth: 0 }}>
      <SlotMachine
        ref={(r) => { refs.current[i] = r; }}
        items={items}
        slotIndex={i}
        forcedResult={serverResults[i]} // optional: fix outcome per reel
        onSpinEnd={(result) => handleReelEnd(i, result)}
      />
    </div>
  ))}
</div>
<button onClick={() => refs.current.forEach((r) => r?.spin())}>
  Spin all
</button>

Props (input data & settings)

| Prop | Type | Default | Description | |------|------|---------|-------------| | items | T[] | required | Pool of items for the reel (and optional forced result). | | slotIndex | number | 0 | Index of this reel (e.g. 0..5 for 6 reels). | | forcedResult | T \| null | null | If set, this reel stops on this item (e.g. from server). | | duration | number | 2500 | Spin duration in ms. | | twistDuration | number | 400 | Twist-back (snap to center) duration in ms. | | orientation | "vertical" \| "horizontal" | "vertical" | Reel direction. | | itemSize | number | derived | Item size in px. Omit for responsive (size from container). | | itemGap | number | 20 | Gap around each item in px. | | reelItemCount | number | 35 | Number of items in the reel (longer = longer spin feel). | | forcedTargetIndex | number | 30 | Index in reel where forcedResult is placed. | | onSpinStart | () => void | - | Called when spin starts. | | onSpinEnd | (result: T) => void | - | Called when reel stops with selected item. | | renderItem | (item, options) => ReactNode | - | Custom render per item (see below). | | itemClassName | string | - | Class for default item wrapper. | | itemStyle | CSSProperties | - | Style for default item wrapper. | | className | string | - | Root wrapper class. | | style | CSSProperties | - | Root wrapper style. | | overlayGradient | "none" \| "top-bottom" \| "left-right" | auto | Fade overlay; default by orientation. | | placeholderImage | string | "" | Image URL when item has no image. | | getItemImage | (item: T) => string | item => item.image | Resolve image URL from item. | | getItemName | (item: T) => string | item => item.name | Resolve name (e.g. alt text). |

Custom item style

  • Simple: use itemClassName and itemStyle to style the default image wrapper.
  • Full control: use renderItem to render each cell yourself. You receive (item, { isCenter, index, centerScale }) and return any ReactNode. The component handles position and animation; you control content and style.
<SlotMachine
  items={items}
  itemClassName="rounded-lg shadow-md"
  itemStyle={{ border: "2px solid gold" }}
/>
<SlotMachine
  items={items}
  renderItem={(item, { isCenter, centerScale }) => (
    <div style={{ transform: `scale(${isCenter ? centerScale : 1})` }}>
      <img src={item.image} alt={item.name} />
      {isCenter && <span className="badge">Selected</span>}
    </div>
  )}
/>

Responsive behavior

  • Root wrapper is width: 100%, height: 100%, and uses containerType: "size" so you can size it from a parent (e.g. flex, grid, or fixed height).
  • If you don’t pass itemSize, the component uses a default and adjusts with container size (ResizeObserver). For full control, pass itemSize from your own breakpoints or layout.

Example: full-width row of reels that scales with viewport:

<div className="slot-grid" style={{
  display: "flex",
  gap: "clamp(4px, 1vw, 16px)",
  width: "100%",
  height: "clamp(200px, 40vmin, 450px)",
}}>
  {reels.map((_, i) => (
    <div key={i} style={{ flex: 1, minWidth: 0 }}>
      <SlotMachine items={items} />
    </div>
  ))}
</div>

Types

  • SlotItem: { id: string; image: string; name?: string; [key: string]: unknown }. Extend this in your app (e.g. add price, rarity).
  • SlotMachineHandle: { spin: () => void } for imperative spin.
  • SlotMachineProps<T>: props type; T must extend SlotItem.
  • SlotItemRenderOptions: { isCenter: boolean; index: number; centerScale: number } passed to renderItem.

License

MIT