erictsai83

Expandable Slider

Component

About

A composable slider that stays expanded on mobile and grows from an icon button on desktop hover, focus, or drag.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Expandable Slider to your project and fits it to your theme.

Code

How Expandable Slider is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";
import { Volume1, Volume2, VolumeX } from "lucide-react";

import {
  ExpandableSlider,
  ExpandableSliderTrack,
  ExpandableSliderTrigger,
} from "@/components/ui/ericts-expandable-slider";

export default function Preview() {
  const [volume, setVolume] = React.useState(70);
  const [restoreVolume, setRestoreVolume] = React.useState(70);
  const muted = volume === 0;
  const VolumeIcon = muted ? VolumeX : volume < 50 ? Volume1 : Volume2;

  const handleVolumeChange = (next: number) => {
    setVolume(next);

    if (next > 0) {
      setRestoreVolume(next);
    }
  };

  const toggleMute = () => {
    if (muted) {
      setVolume(restoreVolume || 50);
      return;
    }

    setRestoreVolume(volume);
    setVolume(0);
  };

  return (
    <div className="flex min-h-40 w-full items-center justify-center">
      <div className="relative flex items-center">
        {/* Anchored to the left of the trigger so it never sits in the space
            the track grows into. */}
        <div
          aria-hidden="true"
          className="pointer-events-none absolute top-1/2 right-full mr-1 hidden h-16 w-20 -translate-y-1/2 text-xs leading-4 font-medium text-foreground/65 italic sm:block"
        >
          <span className="absolute top-0 -left-2 whitespace-nowrap">
            Hover
          </span>
          <svg
            viewBox="0 0 80 64"
            className="absolute inset-0 h-16 w-20 overflow-visible text-foreground/60"
            fill="none"
          >
            {/* Control points sit below the chord, so the sweep dips under the
                label and rises into the trigger. */}
            <path
              d="M10 16C30 34 52 38 70 32"
              stroke="currentColor"
              strokeWidth="2"
              strokeLinecap="round"
              strokeLinejoin="round"
            />
            <path
              d="M61 42 70 32 57 29"
              stroke="currentColor"
              strokeWidth="2"
              strokeLinecap="round"
              strokeLinejoin="round"
            />
          </svg>
        </div>

        <ExpandableSlider
          label="Volume"
          value={volume}
          onValueChange={handleVolumeChange}
          formatValueText={(value) => `${value}%`}
        >
          <ExpandableSliderTrigger
            aria-label={muted ? "Unmute" : "Mute"}
            onClick={toggleMute}
          >
            <VolumeIcon />
          </ExpandableSliderTrigger>
          <ExpandableSliderTrack />
        </ExpandableSlider>
      </div>
    </div>
  );
}

Dependencies

More by erictsai83

View all
  • Adaptive Drawer

    Adaptive Drawer

  • Status Button

    Status Button

  • Floating Shortcut Button

    Floating Shortcut Button

  • Filter Tags

    Filter Tags

  • Feedback Popover

    Feedback Popover

  • Expandable Toolbar

    Expandable Toolbar

  • Expandable Toggle Button

    Expandable Toggle Button

  • Arc Menu

    Arc Menu