my/ui

Command Palette

Search for a command to run...

All components

Temperature Slider Input

sliders

Origin UI component.

responsive · 600px

Install

Same command in any shadcn project — React (Vite/CRA), Next.js, Remix, Astro, and more:

$npx shadcn@latest add https://your-domain/r/comp-254.json

Usage

import Cmp from "@/registry/origin-ui/comp-254";

export default function Demo() {
  return <Cmp />;
}

Component source

"use client";

import { RotateCcwIcon } from "lucide-react";

import { useSliderWithInput } from "@/registry/origin-ui/use-slider-with-input";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Slider } from "@/components/ui/slider";
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@/components/ui/tooltip";

export default function Component() {
  const minValue = 0;
  const maxValue = 2;
  const initialValue = [1.25];
  const defaultValue = [1];

  const {
    sliderValue,
    inputValues,
    validateAndUpdateValue,
    handleInputChange,
    handleSliderChange,
    resetToDefault,
    showReset,
  } = useSliderWithInput({ defaultValue, initialValue, maxValue, minValue });

  return (
    <div className="space-y-3">
      <div className="flex items-center justify-between gap-2">
        <Label>Temperature</Label>
        <div className="flex items-center gap-1">
          <TooltipProvider delayDuration={0}>
            <Tooltip>
              <TooltipTrigger asChild>
                <Button
                  aria-label="Reset"
                  className={cn(
                    "size-7 transition-opacity",
                    showReset ? "opacity-100" : "opacity-0",
                  )}
                  onClick={resetToDefault}
                  size="icon"
                  variant="ghost"
                >
                  <RotateCcwIcon aria-hidden="true" size={16} />
                </Button>
              </TooltipTrigger>
              <TooltipContent className="px-2 py-1 text-xs">
                Reset to default
              </TooltipContent>
            </Tooltip>
          </TooltipProvider>
          <Input
            aria-label="Enter value"
            className="h-7 w-12 px-2 py-0"
            inputMode="decimal"
            onBlur={() => validateAndUpdateValue(inputValues[0] ?? "", 0)}
            onChange={(e) => handleInputChange(e, 0)}
            onKeyDown={(e) => {
              if (e.key === "Enter") {
                validateAndUpdateValue(inputValues[0] ?? "", 0);
              }
            }}
            type="text"
            value={inputValues[0]}
          />
        </div>
      </div>
      <div className="flex items-center gap-4">
        <Slider
          aria-label="Temperature"
          className="grow"
          max={maxValue}
          min={minValue}
          onValueChange={handleSliderChange}
          step={0.01}
          value={sliderValue}
        />
      </div>
    </div>
  );
}

Source: Origin UI