Skip to main content

BoldSlider

Pick a single value on a filled track that shows its label and value inline.

Props
Slots

Anatomy#

BoldSlider [component; slot=root]
├── track [slot]
│   ├── range [slot]
│   └── marker [slot]
├── thumb [slot]
├── content [slot]
│   ├── label [slot]
│   └── value [slot]
└── indicator [slot]

Usage#

Use BoldSlider for dense settings such as inspector panels and animation controls, where each row holds one number and the track doubles as its readout. Use Slider for ranges, vertical layouts, or a thin track with a visible thumb.

import { BoldSlider } from 'moraine'

export function Example() {
  return <BoldSlider label="Opacity" defaultValue={80} valueLabel={({ value }) => `${value}%`} />
}

BoldSlider is built on Slider, so value, defaultValue, onValueChange, onValueCommit, min, max, step, markers, reversed, form props, keyboard interaction, and translations behave the same way. The value is always a single number; BoldSlider has no range or multi-thumb mode. size accepts sm, md (default), or lg.

Label and value#

label is drawn at the start of the track; a string label is also the default aria-label. The value is drawn at the end; set valueLabel={false} to hide it. By default the value is rounded to the decimal places of step (two places without step) and has no digit grouping. Set formatOptions to format it with Intl.NumberFormat instead. Pass a function to valueLabel to add units or other formatting. It receives { percent, value, max }, the same shape as Progress valueLabel. percent is the filled share of the track from 0 to 100, and max is 100 when unset.

Both texts are drawn twice: once over the track and once clipped to the filled range. Each part of the text uses the colors of the surface behind it, so it stays readable while the fill passes through it. Pass a JSX label inline rather than as a shared node, so each layer gets its own copy.

Variants#

The default variant="subtle" uses a solid neutral fill, like the controls in an inspector panel. The label, value, and indicator keep the same colors over the fill and the track. Set variant="solid" for a primary-colored fill; the label, value, and indicator then switch to primary-foreground where the fill passes under them.

<BoldSlider variant="solid" label="Bounce" defaultValue={0.5} max={1} step={0.1} />

Step and markers#

Set step to snap pointer and keyboard input to increments. Without step, pointer movement is continuous and arrow keys move by 1% of the range. Set markers to true to draw a tick at each step (this requires a step greater than 0), or to a number to draw a tick every that many units without changing how the value snaps. Ticks use muted-foreground, so they stay visible in light and dark themes.

Indicator#

The indicator is a capsule just inside the edge of the fill. When the value is 0, the fill is hidden and the indicator rests at the minimum-fill position as a drag anchor. Once the value is greater than 0, the fill appears and the indicator sits just inside its edge. Where it sits on the fill it uses --bs-indicator-fill, and where it sits on the track it uses --bs-indicator-track, so its color follows the surface behind it. It stays dim and shorter at rest, and brightens to full size while the track is hovered, the slider is dragged, or the thumb has keyboard focus. Clicking the track focuses the thumb without the keyboard focus ring.

These states use peer-* selectors on the track and thumb, so each slider reacts only to its own interaction, even inside a parent with a group class.

Examples#

Tune animation settings#

Stack several sliders to build a compact control panel.

import { BoldSlider } from 'moraine'
import { createSignal } from 'solid-js'

export function ControlPanel() {
  const [bounce, setBounce] = createSignal(0.5)
  const [stiffness, setStiffness] = createSignal(120)
  const [delay, setDelay] = createSignal(0)

  return (
    <div class="max-w-sm w-full space-y-2">
      <BoldSlider
        label="Bounce"
        value={bounce()}
        onValueChange={setBounce}
        min={0}
        max={1}
        step={0.1}
        markers
      />
      <BoldSlider
        label="Stiffness"
        value={stiffness()}
        onValueChange={setStiffness}
        min={0}
        max={300}
        step={10}
      />
      <BoldSlider
        label="Delay"
        value={delay()}
        onValueChange={setDelay}
        min={0}
        max={2000}
        step={50}
        valueLabel={({ value }) => `${value}ms`}
      />
    </div>
  )
}

Show a unit with the value#

Use valueLabel to append a unit.

import { BoldSlider } from 'moraine'
import { createSignal } from 'solid-js'

export function BlurSlider() {
  const [value, setValue] = createSignal(32)

  return (
    <div class="max-w-md w-full">
      <BoldSlider
        label="Blur"
        value={value()}
        onValueChange={setValue}
        min={0}
        max={100}
        step={1}
        size="lg"
        valueLabel={({ value }) => `${value}px`}
      />
    </div>
  )
}

Map steps to preset names#

valueLabel can return any string, so snapped steps can read as names instead of numbers.

import { BoldSlider } from 'moraine'
import { createSignal } from 'solid-js'

const PRESETS = ['Low', 'Medium', 'High', 'Ultra']

export function QualitySlider() {
  const [value, setValue] = createSignal(2)

  return (
    <div class="max-w-md w-full">
      <BoldSlider
        label="Quality"
        value={value()}
        onValueChange={setValue}
        min={0}
        max={3}
        step={1}
        markers
        valueLabel={({ value }) => PRESETS[value] ?? String(value)}
      />
    </div>
  )
}

Bind brightness to a form#

Place the slider in form.Field so the schema owns the committed number.

import { BoldSlider, Button, createForm } from 'moraine'
import * as v from 'valibot'

export function FormIntegration() {
  const form = createForm({
    schema: v.object({
      brightness: v.pipe(v.number(), v.minValue(20, 'Brightness must be at least 20%.')),
    }),
    initialInput: { brightness: 60 },
    validate: 'input',
  })

  return (
    <form.Form>
      <div class="max-w-sm space-y-4">
        <form.Field name="brightness" label="Brightness" description="Keep it at least 20%.">
          <BoldSlider defaultValue={60} step={5} valueLabel={({ value }) => `${value}%`} />
        </form.Field>
        <Button type="submit" variant="soft" tone="neutral" size="sm">
          Validate
        </Button>
      </div>
    </form.Form>
  )
}

API Reference#

Attributes#

Attributes
data-fill
Slot: bold-slider-labelbold-slider-value
Description: —

Props#

Props for the BoldSlider component. Renders a <div> element by default.

Prop