Skip to content
Tennantite
中文
Documentation

Slider

Vanilla slider with a dark track and a raised button thumb.

Install

CLI copy

$npx shadcn add @tennantite/slider

npm install

$pnpm add @tennantite/ui

npm installs the compiled package; use the CLI copy above to adapt the source.

Usage

npm import

import { Slider } from "@tennantite/ui";

CLI copy import

import { Slider } from "@/components/tennantite/slider";
import { useState } from "react";

import { Slider } from "./index";

/**
 * Slider 预览用例:受控音量滑条
*/
export function SliderDemo() {
  const [volume, setVolume] = useState(70);

  return (
    <div className="flex w-160 flex-col gap-8">
      <label className="flex flex-col gap-4">
        <span className="font-mc mc-text">
          音乐音量:
          {volume}
          %
        </span>
        <Slider
          aria-label="音乐音量"
          onValueChange={(value) => {
            setVolume(Array.isArray(value) ? (value[0] ?? 30) : value);
          }}
          value={volume}
        />
      </label>
      <Slider aria-label="默认值滑条" defaultValue={30} />
    </div>
  );
}

API Reference

No public props.

Source

packages/ui/src/primitives/slider/index.tsx

The npm package keeps the source tree, so you can copy and adapt it directly.