Skip to main content
On this pageFunctions

Ui/Slider

Functions

forRoot

functionsource

fractionOfValue

functionsource
/**
 * Computes the fraction (0–1) of a value between min and max. Returns 0
 *  when the range has zero or negative width.
 */
(
  value: number,
  min: number,
  max: number
): number

snapAndClamp

functionsource
/**
 * Snaps a value to the nearest step and clamps it into `[min, max]`. Exported
 *  so a parent can conform the value it owns to the Slider's range, for example
 *  when seeding the initial value or reacting to an external update.
 */
(
  value: number,
  min: number,
  max: number,
  step: number
): number

valueFromPointer

functionsource
/**
 * Maps a pointer position to a Slider value. Vertical tracks place `min` at
 *  the bottom and `max` at the top. Edge-aligned tracks measure the rendered
 *  thumb and map the pointer across the same inset range it travels through.
 */
(
  clientX: number,
  clientY: number,
  track: Element,
  min: number,
  max: number
): number

Types

InitConfig

typesource
/** Configuration for creating a Slider Model with `init`. */
type InitConfig = Readonly<{
  id: string
  max: number
  min: number
  step: number
}>

SliderAttributes

typesource
/**
 * Attribute groups the Slider provides to the consumer's `toView`
 *  callback. Each group carries the boundary's captured dispatch, so the
 *  consumer can spread it directly into element attributes without manual
 *  Message wrapping.
 */
type SliderAttributes = Readonly<{
  filledTrack: ReadonlyArray<ChildAttribute>
  hiddenInput: ReadonlyArray<ChildAttribute>
  label: ReadonlyArray<ChildAttribute>
  root: ReadonlyArray<ChildAttribute>
  thumb: ReadonlyArray<ChildAttribute>
  track: ReadonlyArray<ChildAttribute>
}>

ViewInputs

typesource
/** Per-render view inputs passed to `view` via `h.block`'s `viewInputs` field. */
type ViewInputs = Readonly<{
  ariaLabel: string
  ariaLabelledBy: string
  formatValue: (value: number) => string
  getTrackRoot: () => Document | ShadowRoot
  isDisabled: boolean
  isReadOnly: boolean
  name: string
  orientation: Orientation
  thumbAlignment: ThumbAlignment
  thumbSize: string
  toView: (attributes: SliderAttributes) => Html
  value: number
}>

Constants

Orientation

constsource
/** Direction in which the Slider lays out its track and maps pointer input. */
const Orientation: Literals<readonly ["Horizontal", "Vertical"]>

ThumbAlignment

constsource
/** Whether the thumb's center or outer edge aligns with the track endpoints. */
const ThumbAlignment: Literals<readonly ["Center", "Edge"]>