-
-
Notifications
You must be signed in to change notification settings - Fork 45
Added slider component #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| "use client"; | ||
| import { forwardRef, useMemo } from "react"; | ||
| import * as SliderPrimitive from "@radix-ui/react-slider"; | ||
| import { cn } from "@/lib/utils"; | ||
| import { cva } from "class-variance-authority"; | ||
|
|
||
| const sliderVariants = cva("relative w-full grow", { | ||
| variants: { | ||
| variant: { | ||
| default: "h-5.5", | ||
| thin: "h-4", | ||
| }, | ||
| }, | ||
| defaultVariants: { | ||
| variant: "default", | ||
| }, | ||
| }); | ||
|
|
||
| interface SliderProps | ||
| extends React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root> { | ||
| variant?: "default" | "thin"; | ||
| } | ||
|
|
||
| const Slider = forwardRef< | ||
| React.ComponentRef<typeof SliderPrimitive.Root>, | ||
| SliderProps | ||
| >( | ||
| ( | ||
| { | ||
| variant = "default", | ||
| className, | ||
| defaultValue, | ||
| value, | ||
| min = 0, | ||
| max = 100, | ||
| ...props | ||
| }, | ||
| ref | ||
| ) => { | ||
| const _values = useMemo( | ||
| () => | ||
| Array.isArray(value) | ||
| ? value | ||
| : Array.isArray(defaultValue) | ||
| ? defaultValue | ||
| : [min, max], | ||
| [value, defaultValue, min, max] | ||
| ); | ||
|
|
||
| return ( | ||
| <div className="space-y-2"> | ||
| <div className="relative"> | ||
| <SliderPrimitive.Root | ||
| ref={ref} | ||
| defaultValue={defaultValue} | ||
| value={value} | ||
| min={min} | ||
| max={max} | ||
| className={cn( | ||
| "relative flex w-full touch-none select-none items-center data-[disabled]:opacity-50", | ||
| className | ||
| )} | ||
| {...props} | ||
| > | ||
| <SliderPrimitive.Track | ||
| className={cn( | ||
| sliderVariants({ variant }), | ||
| "overflow-hidden border-2 border-black bg-white shadow-[4px_4px_0_0_rgba(0,0,0,1)]" | ||
| )} | ||
| > | ||
| <SliderPrimitive.Range className="absolute h-full bg-primary" /> | ||
| </SliderPrimitive.Track> | ||
| {_values.map((_, index) => ( | ||
| <SliderPrimitive.Thumb | ||
| key={index} | ||
| className={cn( | ||
| "block transition-colors focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50", | ||
| variant === "default" | ||
| ? "h-5 w-5 border-2 border-black bg-white" | ||
| : "h-4 w-4 border-2 border-black bg-white" | ||
| )} | ||
| > | ||
| <div className="absolute inset-0 -translate-x-[2px] -translate-y-[2px] border-2 border-black transition-transform hover:-translate-y-1 active:translate-y-0 bg-white group-data-[disabled]:pointer-events-none"> | ||
| <div className="absolute inset-x-0 -top-1 h-[2px] bg-black/10" /> | ||
| <div className="absolute inset-x-0 -bottom-1 h-[2px] bg-black/10" /> | ||
| </div> | ||
| </SliderPrimitive.Thumb> | ||
| ))} | ||
| </SliderPrimitive.Root> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| Slider.displayName = "Slider"; | ||
|
|
||
| export { Slider }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from "./Slider" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| --- | ||
| title: Slider | ||
| description: A customizable slider component with two variants. | ||
| lastUpdated: 25 Mar, 2025 | ||
| links: | ||
| api_reference: https://www.radix-ui.com/docs/primitives/components/slider#api-reference | ||
| source: https://github.com/Logging-Stuff/RetroUI/blob/main/components/ui/Slider.tsx | ||
ahmrafi22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --- | ||
|
|
||
| <ComponentShowcase name="slider-style-default" /> | ||
| <br /> | ||
| <br /> | ||
|
|
||
| ## Installation | ||
|
|
||
| <ComponentInstall> | ||
| <ComponentInstall.Cli> | ||
| ```sh | ||
| npx shadcn@latest add "https://retroui.dev/r/slider.json" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify the CLI installation URL. The CLI installation command references a URL to a JSON file that might not exist yet for this new component. Please verify that this URL will be valid when the PR is merged. 🏁 Script executed: #!/bin/bash
# Check if the slider.json file exists or is planned to be created
curl -s -o /dev/null -w "%{http_code}" https://retroui.dev/r/slider.jsonLength of output: 78 Action Required: Fix the CLI installation URL for slider.json The verification shows that the URL
|
||
| ``` | ||
| </ComponentInstall.Cli> | ||
| <ComponentInstall.Manual> | ||
|
|
||
| #### 1. Install dependencies: | ||
|
|
||
| ```sh | ||
| npm install @radix-ui/react-slider | ||
| ``` | ||
|
|
||
| <br /> | ||
|
|
||
| #### 2. Copy the code 👇 into your project: | ||
|
|
||
| <ComponentSource name="slider" /> | ||
|
|
||
| </ComponentInstall.Manual> | ||
| </ComponentInstall> | ||
|
|
||
| <br /> | ||
| <br /> | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Default | ||
|
|
||
| <ComponentShowcase name="slider-style-default" /> | ||
| <br /> | ||
| <br /> | ||
|
|
||
| ### Thin | ||
|
|
||
| <ComponentShowcase name="slider-style-thin" /> | ||
| <br /> | ||
| <br /> | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { Slider } from "@/components/ui" | ||
| import { Label } from "@/components/ui" | ||
|
|
||
| export default function SliderDefault() { | ||
| return ( | ||
| <div className="p-6 max-w-md mx-auto"> | ||
| <div className="mb-6"> | ||
| <Label | ||
| htmlFor="default-slider" | ||
| className="block text-sm font-medium mb-2" | ||
| > | ||
| Slider control | ||
| </Label> | ||
| <Slider | ||
| defaultValue={[50]} | ||
| min={0} | ||
| max={100} | ||
| step={1} | ||
| variant="default" | ||
| aria-label="Slider Control" | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { Slider } from "@/components/ui"; | ||
| import { Label } from "@/components/ui" | ||
|
|
||
| export default function SliderDefault() { | ||
| return ( | ||
| <div className="p-6 max-w-md mx-auto"> | ||
| <div className="mb-6"> | ||
| <Label | ||
| htmlFor="default-slider" | ||
| className="block text-sm font-medium mb-2" | ||
| > | ||
| Volume Control | ||
| </Label> | ||
| <Slider | ||
| defaultValue={[45]} | ||
| min={0} | ||
| max={100} | ||
| step={1} | ||
| variant="thin" | ||
| aria-label="Volume Control" | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the file path for the slider component.
The file path in the configuration doesn't match the actual implementation path. The slider component is implemented in "components/ui/Slider/Slider.tsx" but referenced as "components/ui/Slider.tsx".
slider: { name: "slider", dependencies: ["@radix-ui/react-slider"], - filePath: "components/ui/Slider.tsx", + filePath: "components/ui/Slider/Slider.tsx", }📝 Committable suggestion