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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@scriptless/react-dice

v1.0.0

Published

A React dice component.

Readme

@scriptless/react-dice

NPM Version MIT License

A React dice component with inky rolling animations.

Dice Demo


I designed this component to work a little bit like an input. When it's enabled, a click from a user is a request for a new dice roll. The component can handle coming up with a value - or in cases where cheating is a concern, it can make a call to your server to get a new value using getNextValue.

When a roll is done, the component will deliver its value to its onChange. If you want the dice to show a particular value before its first roll, pass that down with the initialValue prop.

Installation

npm install @scriptless/react-dice --save

Basic Usage

import { Dice } from '@scriptless/react-dice';
import '@scriptless/react-dice/styles.css';

function App() {
  return <Dice onChange={(value) => console.log('New value:', value)} />;
}

Group Usage

import { DiceGroup, Dice } from '@scriptless/react-dice';
import '@scriptless/react-dice/styles.css';

function App() {
  const diceValueFromServer = useFetchValue();

  const [
    diceValue, // use me for other UI elements, no need to pass me to the dice component
    setDiceValue,
  ] = useState(undefined);

  return (
    <DiceGroup
      onChange={setDiceValue} // this will get called with an array of three values
    >
      <Dice />
      {/* dice will work with any arbitrary dom structure */}
      <div style={{ border: '1px solid black', padding: 40 }}>
        <Dice />
        <div style={{ position: 'absolute', top: 0 }}>
          <Dice />
        </div>
      </div>
    </DiceGroup>
  );
}

API Reference

Dice Component Props

| Prop | Type | Default | Description | | -------------------- | --------------------------------- | --------- | ------------------------------------- | | initialValue | number | 1 | Initial value of the die (1-6) | | onChange | (value?: number) => void | - | Callback fired when die value changes | | getNextValue | () => number \| Promise<number> | random | Function to generate next die value | | disabled | boolean | false | Disables die rolling | | size | number | 66 | Size of the die in pixels | | pipSize | number | 12 | Size of the pips in pixels | | borderColor * | string | 'black' | Color of die border | | borderRadius | number | 8 | Border radius in pixels | | borderWidth | number | 3 | Border width in pixels | | backgroundColor * | string | 'white' | Die background color | | pipColor * | string | 'black' | Color of the pips |

* be careful with these props, because this component works by blurring and contrasting for the inky effect, colors of similar luminosity may cause a strange strobe effect during roll

DiceGroup Component Props

| Prop | Type | Default | Description | | ----------- | ---------------------------- | ---------------------------------- | ----------------------------------------- | | onChange | (values: number[]) => void | - | Callback fired when any die value changes | | disabled | boolean | false | Disables rolling for all dice | | className | string | - | Additional CSS class | | style | CSSProperties | { display: 'flex', gap: '10px' } | Inline styles |

Advanced Usage

Get your dice values from a server

const CustomDice = () => {
  const diceValueFromServer = useFetchFromServer();

  const [
    diceValue, // use me for other UI elements, no need to pass me to the dice component
    setDiceValue,
  ] = useState(undefined);

  const getNextValue = async () => {
    const response = await fetch('https://api.random.org/v1/dice');
    const data = await response.json();
    return data.value;
  };

  return (
    <Dice
      initialValue={diceValueFromServer}
      onChange={setDiceValue}
      getNextValue={getNextValue}
    />
  );
};

Styled Dice

const StyledDice = () => (
  <Dice borderWidth={2} borderRadius={20} size={80} pipSize={14} />
);

License

MIT © Gus Nordhielm

To do, contributions welcome

  • [x] Better same-to-same number animations, e.g. two dots should switch sides, one dot should pulse
  • [ ] Use rolling as a loader, when I'm waiting for an async getNextValue, I should see feedback immediately
  • [ ] When I rapid click a dice item, they weirdly alternate rolls
  • [ ] Custom colors are causing weird behaviors - e.g. dark bg with dark pips make them bleed a lot, perhaps there's a way of using b/w pips and then masking them over the background. Also the background is flashing with the contrast setting.
  • [ ] On initial click, there's like a little bounce - but this happens inconsistently and sometimes twice, worth making that consistent