From 383625aedecd6ae447e28512e647e901a2a40b1a Mon Sep 17 00:00:00 2001 From: Felix Schulze Date: Thu, 1 May 2025 13:57:54 +0200 Subject: [PATCH] shadcn slider --- package-lock.json | 34 +++++++++++++++++++ package.json | 1 + src/components/ui/slider.tsx | 63 ++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 src/components/ui/slider.tsx diff --git a/package-lock.json b/package-lock.json index 8a10bcd..c0e4f9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@radix-ui/react-accordion": "^1.2.8", "@radix-ui/react-label": "^2.1.4", "@radix-ui/react-select": "^2.2.2", + "@radix-ui/react-slider": "^1.3.2", "@radix-ui/react-slot": "^1.2.0", "@t3-oss/env-nextjs": "^0.12.0", "class-variance-authority": "^0.7.1", @@ -1358,6 +1359,39 @@ } } }, + "node_modules/@radix-ui/react-slider": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@radix-ui/react-slider/-/react-slider-1.3.2.tgz", + "integrity": "sha512-oQnqfgSiYkxZ1MrF6672jw2/zZvpB+PJsrIc3Zm1zof1JHf/kj7WhmROw7JahLfOwYQ5/+Ip0rFORgF1tjSiaQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/number": "1.1.1", + "@radix-ui/primitive": "1.1.2", + "@radix-ui/react-collection": "1.1.4", + "@radix-ui/react-compose-refs": "1.1.2", + "@radix-ui/react-context": "1.1.2", + "@radix-ui/react-direction": "1.1.1", + "@radix-ui/react-primitive": "2.1.0", + "@radix-ui/react-use-controllable-state": "1.2.2", + "@radix-ui/react-use-layout-effect": "1.1.1", + "@radix-ui/react-use-previous": "1.1.1", + "@radix-ui/react-use-size": "1.1.1" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-slot": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.2.0.tgz", diff --git a/package.json b/package.json index 1758bfb..b90342f 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "@radix-ui/react-accordion": "^1.2.8", "@radix-ui/react-label": "^2.1.4", "@radix-ui/react-select": "^2.2.2", + "@radix-ui/react-slider": "^1.3.2", "@radix-ui/react-slot": "^1.2.0", "@t3-oss/env-nextjs": "^0.12.0", "class-variance-authority": "^0.7.1", diff --git a/src/components/ui/slider.tsx b/src/components/ui/slider.tsx new file mode 100644 index 0000000..56aed84 --- /dev/null +++ b/src/components/ui/slider.tsx @@ -0,0 +1,63 @@ +"use client"; + +import * as React from "react"; +import * as SliderPrimitive from "@radix-ui/react-slider"; + +import { cn } from "@/lib/utils"; + +function Slider({ + className, + defaultValue, + value, + min = 0, + max = 100, + ...props +}: React.ComponentProps) { + const _values = React.useMemo( + () => + Array.isArray(value) + ? value + : Array.isArray(defaultValue) + ? defaultValue + : [min, max], + [value, defaultValue, min, max], + ); + + return ( + + + + + {Array.from({ length: _values.length }, (_, index) => ( + + ))} + + ); +} + +export { Slider };