Clawscale

Slider

A Slider picks a number from a range. A RangeSlider picks a start and an end, and a MultiSlider takes any number of handles.

Usage#

import { MultiSlider, MultiSliderHandle, RangeSlider, Slider } from "@clawscale/react";
<Slider max={32} value={workers} onChange={setWorkers} />

Sliders are controlled. Pass value and update it in onChange. onRelease fires once when the user lets go of a handle.

Examples#

Single value#

min, max and stepSize define the scale, and labelStepSize spaces the labels. Name the handle with handleHtmlProps.

0
8
16
24
32
12
import { Slider } from "@clawscale/react";
import { useState } from "react";

export default function SliderBasic() {
  const [workers, setWorkers] = useState(12);
  return (
    <Slider
      handleHtmlProps={{ "aria-label": "Worker count" }}
      labelStepSize={8}
      max={32}
      min={0}
      value={workers}
      onChange={setWorkers}
    />
  );
}

Range#

RangeSlider takes a [start, end] pair and fills the track between the two handles.

0
8
16
24
32
416
import { RangeSlider } from "@clawscale/react";
import { useState } from "react";

export default function SliderRange() {
  const [replicas, setReplicas] = useState<[number, number]>([4, 16]);
  return (
    <RangeSlider
      handleHtmlProps={{ start: { "aria-label": "Minimum replicas" }, end: { "aria-label": "Maximum replicas" } }}
      labelStepSize={8}
      max={32}
      min={0}
      value={replicas}
      onChange={setReplicas}
    />
  );
}

Multiple handles#

MultiSlider renders one MultiSliderHandle per value. intentBefore and intentAfter color the track on each side of a handle, which suits threshold bands.

0
20
40
60
80
100
7090
import { MultiSlider, MultiSliderHandle } from "@clawscale/react";
import { useState } from "react";

export default function SliderMulti() {
  const [warning, setWarning] = useState(70);
  const [critical, setCritical] = useState(90);
  return (
    <MultiSlider labelStepSize={20} max={100} min={0}>
      <MultiSliderHandle
        htmlProps={{ "aria-label": "Disk usage warning threshold" }}
        intentAfter="warning"
        intentBefore="success"
        value={warning}
        onChange={setWarning}
      />
      <MultiSliderHandle
        htmlProps={{ "aria-label": "Disk usage critical threshold" }}
        intentAfter="danger"
        value={critical}
        onChange={setCritical}
      />
    </MultiSlider>
  );
}

Vertical#

vertical draws the track from bottom to top.

0
25
50
75
100
65
import { Slider } from "@clawscale/react";
import { useState } from "react";

export default function SliderVertical() {
  const [cpuLimit, setCpuLimit] = useState(65);
  return (
    <Slider
      handleHtmlProps={{ "aria-label": "CPU limit" }}
      labelStepSize={25}
      max={100}
      min={0}
      value={cpuLimit}
      vertical
      onChange={setCpuLimit}
    />
  );
}

Label renderer#

labelRenderer formats labels, for example as a percentage or in milliseconds. Its second argument tells you when the label is the handle's own tooltip.

0%
25%
50%
75%
100%
25%
0 s
1 s
2 s
3 s
4 s
5 s
1500 ms
import { Slider } from "@clawscale/react";
import { useState } from "react";

export default function SliderLabelRenderer() {
  const [sampleRate, setSampleRate] = useState(0.25);
  const [timeoutMs, setTimeoutMs] = useState(1500);
  return (
    <>
      <Slider
        handleHtmlProps={{ "aria-label": "Sample rate" }}
        labelRenderer={(value) => `${Math.round(value * 100)}%`}
        labelStepSize={0.25}
        max={1}
        min={0}
        stepSize={0.05}
        value={sampleRate}
        onChange={setSampleRate}
      />
      <Slider
        handleHtmlProps={{ "aria-label": "Request timeout" }}
        labelRenderer={(value, opts) => (opts?.isHandleTooltip ? `${value} ms` : `${value / 1000} s`)}
        labelStepSize={1000}
        max={5000}
        min={0}
        stepSize={100}
        value={timeoutMs}
        onChange={setTimeoutMs}
      />
    </>
  );
}

Props interface#

interface SliderProps extends SliderBaseProps@clawscale/react
PropsDescription
children
React.ReactNode
Inherited from SliderBaseProps
className
string
A space-delimited list of class names to pass along to a child element.
Inherited from Props
disabled
boolean = false
Whether the slider is non-interactive.
Inherited from SliderBaseProps
handleHtmlProps
HandleHtmlProps
A limited subset of HTML props to apply to the slider Handle
initialValue
number = 0
Initial value of the slider. This determines the other end of the track fill: from initialValue to value.
intent
Intent
Visual intent color to apply to element.
Inherited from IntentProps
labelPrecision
number = inferred from stepSize
Number of decimal places to use when rendering label value. Default value is the number of decimals used in the stepSize prop. This prop has _no effect_ if you supply a custom labelRenderer callback.
Inherited from SliderBaseProps
labelRenderer
boolean | ((value: number, opts?: { isHandleTooltip: boolean; }) => string | React.JSX.Element) = true
Callback to render a single label. Useful for formatting numbers as currency or percentages. If true, labels will use number value formatted to labelPrecision decimal places. If false, labels will not be shown.
Inherited from SliderBaseProps
labelStepSize
number = inferred (if labelStepSize is undefined)
Increment between successive labels. Must be greater than zero.
Inherited from SliderBaseProps
labelValues
readonly number[]
Array of specific values for the label placement. This prop is mutually exclusive with labelStepSize.
Inherited from SliderBaseProps
max
number = 10
Maximum value of the slider. Value must be a finite number.
Inherited from SliderBaseProps
min
number = 0
Minimum value of the slider. Value must be a finite number.
Inherited from SliderBaseProps
onChange
(value: number): void
Callback invoked when the value changes.
onRelease
(value: number): void
Callback invoked when the handle is released.
showTrackFill
boolean = true
Whether a solid bar should be rendered on the track between current and initial values, or between handles for RangeSlider.
Inherited from SliderBaseProps
stepSize
number = 1
Increment between successive values; amount by which the handle moves. Must be greater than zero.
Inherited from SliderBaseProps
value
number = 0
Value of slider.
vertical
boolean = false
Whether to show the slider in a vertical orientation.
Inherited from SliderBaseProps
interface RangeSliderProps extends SliderBaseProps@clawscale/react
PropsDescription
children
React.ReactNode
Inherited from SliderBaseProps
className
string
A space-delimited list of class names to pass along to a child element.
Inherited from Props
disabled
boolean = false
Whether the slider is non-interactive.
Inherited from SliderBaseProps
handleHtmlProps
{ start?: HandleHtmlProps; end?: HandleHtmlProps; }
HTML props to apply to the slider Handles
intent
Intent
Visual intent color to apply to element.
Inherited from IntentProps
labelPrecision
number = inferred from stepSize
Number of decimal places to use when rendering label value. Default value is the number of decimals used in the stepSize prop. This prop has _no effect_ if you supply a custom labelRenderer callback.
Inherited from SliderBaseProps
labelRenderer
boolean | ((value: number, opts?: { isHandleTooltip: boolean; }) => string | React.JSX.Element) = true
Callback to render a single label. Useful for formatting numbers as currency or percentages. If true, labels will use number value formatted to labelPrecision decimal places. If false, labels will not be shown.
Inherited from SliderBaseProps
labelStepSize
number = inferred (if labelStepSize is undefined)
Increment between successive labels. Must be greater than zero.
Inherited from SliderBaseProps
labelValues
readonly number[]
Array of specific values for the label placement. This prop is mutually exclusive with labelStepSize.
Inherited from SliderBaseProps
max
number = 10
Maximum value of the slider. Value must be a finite number.
Inherited from SliderBaseProps
min
number = 0
Minimum value of the slider. Value must be a finite number.
Inherited from SliderBaseProps
onChange
(value: NumberRange): void
Callback invoked when the range value changes.
onRelease
(value: NumberRange): void
Callback invoked when a handle is released.
showTrackFill
boolean = true
Whether a solid bar should be rendered on the track between current and initial values, or between handles for RangeSlider.
Inherited from SliderBaseProps
stepSize
number = 1
Increment between successive values; amount by which the handle moves. Must be greater than zero.
Inherited from SliderBaseProps
value
NumberRange = [0, 10]
Range value of slider. Handles will be rendered at each position in the range.
vertical
boolean = false
Whether to show the slider in a vertical orientation.
Inherited from SliderBaseProps
interface MultiSliderProps extends SliderBaseProps@clawscale/react
PropsDescription
children
React.ReactNode
Inherited from SliderBaseProps
className
string
A space-delimited list of class names to pass along to a child element.
Inherited from Props
defaultTrackIntent
Intent
Default intent of a track segment, used only if no handle specifies intentBefore/After.
disabled
boolean = false
Whether the slider is non-interactive.
Inherited from SliderBaseProps
intent
Intent
Visual intent color to apply to element.
Inherited from IntentProps
labelPrecision
number = inferred from stepSize
Number of decimal places to use when rendering label value. Default value is the number of decimals used in the stepSize prop. This prop has _no effect_ if you supply a custom labelRenderer callback.
Inherited from SliderBaseProps
labelRenderer
boolean | ((value: number, opts?: { isHandleTooltip: boolean; }) => string | React.JSX.Element) = true
Callback to render a single label. Useful for formatting numbers as currency or percentages. If true, labels will use number value formatted to labelPrecision decimal places. If false, labels will not be shown.
Inherited from SliderBaseProps
labelStepSize
number = inferred (if labelStepSize is undefined)
Increment between successive labels. Must be greater than zero.
Inherited from SliderBaseProps
labelValues
readonly number[]
Array of specific values for the label placement. This prop is mutually exclusive with labelStepSize.
Inherited from SliderBaseProps
max
number = 10
Maximum value of the slider. Value must be a finite number.
Inherited from SliderBaseProps
min
number = 0
Minimum value of the slider. Value must be a finite number.
Inherited from SliderBaseProps
onChange
(values: number[]): void
Callback invoked when a handle value changes. Receives handle values in sorted order.
onRelease
(values: number[]): void
Callback invoked when a handle is released. Receives handle values in sorted order.
showTrackFill
boolean = true
Whether a solid bar should be rendered on the track between current and initial values, or between handles for RangeSlider.
Inherited from SliderBaseProps
stepSize
number = 1
Increment between successive values; amount by which the handle moves. Must be greater than zero.
Inherited from SliderBaseProps
vertical
boolean = false
Whether to show the slider in a vertical orientation.
Inherited from SliderBaseProps
interface HandleProps extends Props@clawscale/react
PropsDescription
className
string
A space-delimited list of class names to pass along to a child element.
Inherited from Props
htmlProps
HandleHtmlProps
A limited subset of HTML props to apply to the rendered <span> element.
intentAfter
Intent
Intent for the track segment immediately after this handle, taking priority over intentBefore.
intentBefore
Intent
Intent for the track segment immediately before this handle.
interactionKind
HandleInteractionKind = "lock"
How this handle interacts with other handles.
onChange
(newValue: number) => void
Callback invoked when this handle's value is changed due to a drag interaction. Note that "push" interactions can cause multiple handles to update at the same time.
onRelease
(newValue: number) => void
Callback invoked when this handle is released (the end of a drag interaction).
trackStyleAfter
CSSProperties
Style to use for the track segment immediately after this handle, taking priority over trackStyleBefore.
trackStyleBefore
CSSProperties
Style to use for the track segment immediately before this handle
type
HandleType = "full"
Handle appearance type.
valuerequired
number
Numeric value of this handle.