Skip to content

Component Library

@randsum/component-library ships React components for embedding interactive dice rolling UIs into any web application. Self-contained with bundled styles.

Terminal window
bun add @randsum/component-library

Requires react, react-dom, @randsum/roller, and @randsum/notation as peer dependencies.

An interactive dice notation editor. Type a notation string, press roll, and see the total with a step-by-step breakdown panel.

import { RollerPlayground } from '@randsum/component-library'
export default function App() {
return <RollerPlayground defaultNotation="4d6L" />
}
PropTypeDefaultDescription
defaultNotationstring'4d6L'Initial dice notation shown in the input
size's' | 'm' | 'l''l'Overall size — scales font, padding, and chip
stackblitzbooleantrueShow the Code button to open notation in StackBlitz
classNamestringAdditional class name appended to the root element

size=“s”

size=“m”

size=“l” (default)

The component respects prefers-color-scheme automatically. Force a specific theme by setting data-theme on any ancestor:

<div data-theme="light">
<RollerPlayground />
</div>
<div data-theme="dark">
<RollerPlayground />
</div>

In an Astro project, use the client:only="react" directive:

<RollerPlayground client:only="react" defaultNotation="2d6+3" />

A compact reference grid of all supported dice notation modifiers. Useful as a help panel or notation guide.

import { ModifierReference } from '@randsum/component-library'
export default function HelpPanel() {
return <ModifierReference />
}
PropTypeDefaultDescription
coreDisabledbooleanfalseHide (grey out) the core xdY row
modifiersDisabledbooleanfalseHide (grey out) all modifier rows
onCellClick(cell: ModifierReferenceCell) => voidCalled when a cell is clicked

Use onCellClick to build a notation-builder — clicking a modifier appends its notation to the input:

import { useState } from 'react'
import { ModifierReference } from '@randsum/component-library'
import type { ModifierReferenceCell } from '@randsum/component-library'
export default function NotationBuilder() {
const [notation, setNotation] = useState('4d6')
function handleCellClick(cell: ModifierReferenceCell) {
if (cell.isCore) {
setNotation('NdS')
} else {
setNotation(prev => prev + cell.notation)
}
}
return (
<>
<input value={notation} onChange={e => setNotation(e.target.value)} />
<ModifierReference onCellClick={handleCellClick} />
</>
)
}

A portal-based overlay component used internally by the playground for tooltips and popovers.

import { Overlay } from '@randsum/component-library'
<Overlay visible={isOpen} onClose={() => setOpen(false)}>
<div>Overlay content</div>
</Overlay>

A React error boundary that catches rendering errors in child components and displays a fallback.

import { ErrorBoundary } from '@randsum/component-library'
<ErrorBoundary>
<RollerPlayground />
</ErrorBoundary>