Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add slider component#17431

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jaaydenh merged 2 commits intomainfromjaaydenh/slider-component
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletionssite/src/components/Slider/Slider.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
import type { Meta, StoryObj } from "@storybook/react";
import React from "react";
import { Slider } from "./Slider";

const meta: Meta<typeof Slider> = {
title: "components/Slider",
component: Slider,
args: {},
argTypes: {
value: {
control: "number",
description: "The controlled value of the slider",
},
defaultValue: {
control: "number",
description: "The default value when initially rendered",
},
disabled: {
control: "boolean",
description:
"When true, prevents the user from interacting with the slider",
},
},
};

export default meta;
type Story = StoryObj<typeof Slider>;

export const Default: Story = {};

export const Controlled: Story = {
render: (args) => {
const [value, setValue] = React.useState(50);
return (
<Slider {...args} value={[value]} onValueChange={([v]) => setValue(v)} />
);
},
args: { value: [50], min: 0, max: 100, step: 1 },
};

export const Uncontrolled: Story = {
args: { defaultValue: [30], min: 0, max: 100, step: 1 },
};

export const Disabled: Story = {
args: { defaultValue: [40], disabled: true },
};

export const MultipleThumbs: Story = {
args: {
defaultValue: [20, 80],
min: 0,
max: 100,
step: 5,
minStepsBetweenThumbs: 1,
},
};
39 changes: 39 additions & 0 deletionssite/src/components/Slider/Slider.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
/**
* Copied from shadc/ui on 04/16/2025
* @see {@link https://ui.shadcn.com/docs/components/slider}
*/
import * as SliderPrimitive from "@radix-ui/react-slider";
import * as React from "react";

import { cn } from "utils/cn";

export const Slider = React.forwardRef<
React.ElementRef<typeof SliderPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root>
>(({ className, ...props }, ref) => (
<SliderPrimitive.Root
ref={ref}
className={cn(
"relative flex w-full items-center h-1.5",
className,
"touch-none select-none",
)}
{...props}
>
<SliderPrimitive.Track className="relative h-1.5 w-full grow overflow-hidden rounded-full bg-surface-secondary data-[disabled]:opacity-40">
<SliderPrimitive.Range className="absolute h-full bg-content-primary" />
</SliderPrimitive.Track>
<SliderPrimitive.Thumb
className="block h-4 w-4 rounded-full border border-solid border-surface-invert-secondary bg-surface-primary shadow transition-colors
focus-visible:outline-none hover:border-content-primary
focus-visible:ring-0 focus-visible:ring-content-primary focus-visible:ring-offset-surface-primary
disabled:pointer-events-none data-[disabled]:opacity-100 data-[disabled]:border-border"
/>
<SliderPrimitive.Thumb
className="block h-4 w-4 rounded-full border border-solid border-surface-invert-secondary bg-surface-primary shadow transition-colors
focus-visible:outline-none hover:border-content-primary
focus-visible:ring-0 focus-visible:ring-content-primary focus-visible:ring-offset-surface-primary
disabled:pointer-events-none data-[disabled]:opacity-100 data-[disabled]:border-border"
/>
</SliderPrimitive.Root>
));
Loading

[8]ページ先頭

©2009-2025 Movatter.jp