Skip to Content
All Articles

Dice, coins, wheels, and a D20

I like interfaces that can roll a die. I also like handing that interface to someone else as a component, with the source sitting in the open. That is rng-react-components: an open-source React and TypeScript library of RNG and gaming-inspired UI. Dice, coins, wheels, and a D20 roller.

The pieces I reach for first are the ones that match how I play. CoinFlip is a click-to-flip coin. DiceSlider is a dice track with a target you can move. RngWheel is a spinning wheel. D20Roll is the twenty-sided die. The repository also includes roulette, a blackjack-style game of twenty-one, and TextFx, which renders RuneScape-style chat text with colours and effects. A coin flip can take an injected random source, and it uses Math.random when you do not pass one. I want the roll to stay visible in the code, and I want the component to stay readable.

CoinFlip Storybook demo showing a gold coin ready to flip
CoinFlip in Storybook.
DiceSlider Storybook demo with a sliding dice target on a track
DiceSlider in Storybook.
RngWheel Storybook demo with a colourful prize wheel
RngWheel in Storybook.
D20Roll Storybook demo showing a twenty-sided die
D20Roll in Storybook.
Roulette Storybook demo with a betting table and chip controls

Roulette in Storybook (default story).

TwentyOne Storybook demo with a blackjack-style table
TwentyOne in Storybook.
TextFx Storybook demo with styled chat-colour text
TextFx in Storybook.

The package is on npm as @itme.day/rng-react-components, under the MIT license. Interactive stories are published on GitHub Pages. The code is the part I care about most. I like clean code: boring in the best way, and easy for the next person (often future me) to pick up. A little library of dice is a good place to practice that.

I live in Seattle. I studied computer science at the University of Washington Tacoma, and I build software at GoDaddy. This library is one of the small, useful things I tinker with, next to the rest of what lives at itme.day. If you need a coin, a wheel, or a twenty-sided die in a React app, the repository is yours to read.