Synertech Web/ui v0.57.5 Site Storybook

Documentation / Forms

Slider

Client@synertech/uiOpen in Storybook

The value slider: a native <input type="range">, made invisible on top of a styled track, fill and thumb. It therefore keeps all the native behaviour — arrows, Page Up / Down, Home / End, screen readers — with the library’s look.

Controlled (value + onValueChange, which receives a number) or not (defaultValue). One value per slider: for a range, use two. valueFormat only formats the display (showValue, showTooltip): for screen readers to announce the same thing, also pass aria-valuetext.

Client component ("use client"). Six semantic colours through color, or free CSS values through trackColor, fillColor and thumbColor.

Examples

Basic usage

Uncontrolled: defaultValue sets the initial position, showValue displays it next to the label.

Open in a tab
import { Slider } from "@synertech/ui";

export function Basic() {
  return <Slider label="Volume" defaultValue={40} showValue />;
}

Controlled, formatted value

onValueChange returns a number; valueFormat dresses up the display and the tooltip.

Open in a tab
import { useState } from "react";
import { Slider } from "@synertech/ui";

export function Controlled() {
  const [budget, setBudget] = useState(1500);
  const format = (value: number) =>
    value.toLocaleString("fr-FR", { style: "currency", currency: "EUR", maximumFractionDigits: 0 });

  return (
    <Slider
      label="Budget mensuel"
      min={0}
      max={5000}
      step={100}
      value={budget}
      onValueChange={setBudget}
      showValue
      showTooltip
      valueFormat={format}
      aria-valuetext={format(budget)}
      description="Par tranche de 100 €."
    />
  );
}

Marks

marks takes a list of labelled marks, or true for one mark per step.

Open in a tab
import { Slider, type SliderMark } from "@synertech/ui";

const qualityMarks: SliderMark[] = [
  { value: 0, label: "Basse" },
  { value: 50, label: "Moyenne" },
  { value: 100, label: "Haute" },
];

export function Marks() {
  return (
    <div className="flex flex-col gap-8">
      <Slider label="Qualité d’export" defaultValue={50} step={50} marks={qualityMarks} />
      <Slider label="Note" min={1} max={5} step={1} defaultValue={4} marks showValue />
    </div>
  );
}

Sizes and colours

size sets the thickness of the track and thumb, color the semantic hue.

Open in a tab
import { Slider } from "@synertech/ui";

export function SizesAndColors() {
  return (
    <div className="flex flex-col gap-6">
      <Slider size="sm" color="neutral" label="Petit, neutre" defaultValue={30} />
      <Slider size="md" color="success" label="Moyen, succès" defaultValue={55} />
      <Slider size="lg" color="warning" label="Grand, avertissement" defaultValue={80} />
      <Slider
        label="Couleurs libres"
        defaultValue={65}
        fillColor="#7c3aed"
        thumbColor="#7c3aed"
        trackColor="#ede9fe"
      />
    </div>
  );
}

Validation and states

A string passed to error shows under the track and turns the slider red; disabled and readOnly freeze it.

Open in a tab
import { useState } from "react";
import { Slider } from "@synertech/ui";

export function States() {
  const [discount, setDiscount] = useState(35);

  return (
    <div className="flex flex-col gap-6">
      <Slider
        label="Remise accordée"
        max={50}
        value={discount}
        onValueChange={setDiscount}
        showValue
        valueFormat={(v) => `${v} %`}
        error={discount > 30 ? "Au-delà de 30 %, l’accord d’un responsable est requis." : false}
      />
      <Slider label="Remise validée" defaultValue={20} max={50} showValue readOnly />
      <Slider label="Remise (désactivée)" defaultValue={10} max={50} disabled />
    </div>
  );
}

API reference

Components

Slider

ComponentClient
import { Slider } from "@synertech/ui";

Props — SliderProps

PropTypeDefaultDescription
color SliderColor "primary"
containerClassName string —

className applied to the outer container.

defaultValue number —

Uncontrolled initial value.

description string —

Help written below the track; a message passed as error takes its place.

disabled boolean false
error boolean | string —

true marks the slider invalid; a message also does, and is written below the track in place of description. The slider is then aria-invalid and described by the message. false and "" are no error.

fillColor string —

Override the filled portion color.

label string —

Field label rendered above the track.

marks boolean | SliderMark[] —

Tick marks — an array of marks, or true to auto-generate from the step.

max number 100
min number 0
onValueChange (value: number) => void —

Called with the new numeric value whenever it changes.

readOnly boolean false
showTooltip boolean false

Display a value bubble above the thumb on hover/focus.

showValue boolean false

Display the current value next to the label.

size SliderSize "md"
step number 1
thumbColor string —

Override the thumb color.

trackColor string —

Override the track (rail) background color.

value number —

Controlled value.

valueFormat (value: number) => string —

Format the displayed value (for showValue and showTooltip).

+ 299 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).

Types

SliderMark

Interface
interface SliderMark
FieldTypeDefaultDescription
value• number —
label ReactNode —
type SliderColor = "primary" | "success" | "warning" | "error" | "info" | "neutral"
type SliderSize = "sm" | "md" | "lg"