-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c81acb1
commit d61f889
Showing
4 changed files
with
342 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { Box } from 'leather-styles/jsx'; | ||
|
||
import { Slider as Component } from './slider.web'; | ||
|
||
const meta: Meta<typeof Component.Root> = { | ||
component: Component.Root, | ||
tags: ['autodocs'], | ||
title: 'Slider', | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Component.Root>; | ||
|
||
export const Default: Story = { | ||
render: () => ( | ||
<Box width="300px"> | ||
<Component.Root defaultValue={[50]} max={100} step={1}> | ||
<Component.Track> | ||
<Component.Range /> | ||
</Component.Track> | ||
<Component.Thumb /> | ||
</Component.Root> | ||
</Box> | ||
), | ||
}; | ||
|
||
export const RangeSlider: Story = { | ||
render: () => ( | ||
<Box width="300px"> | ||
<Component.Root defaultValue={[20, 80]} max={100} step={1}> | ||
<Component.Track> | ||
<Component.Range /> | ||
</Component.Track> | ||
<Component.Thumb /> | ||
<Component.Thumb /> | ||
</Component.Root> | ||
</Box> | ||
), | ||
}; | ||
|
||
export const SteppedSlider: Story = { | ||
render: () => ( | ||
<Box width="300px"> | ||
<Component.Root defaultValue={[50]} max={100} step={10}> | ||
<Component.Track> | ||
<Component.Range /> | ||
</Component.Track> | ||
<Component.Thumb /> | ||
</Component.Root> | ||
</Box> | ||
), | ||
}; | ||
|
||
export const CustomWidth: Story = { | ||
render: () => ( | ||
<Box width="500px"> | ||
<Component.Root defaultValue={[50]} max={100} step={1}> | ||
<Component.Track> | ||
<Component.Range /> | ||
</Component.Track> | ||
<Component.Thumb /> | ||
</Component.Root> | ||
</Box> | ||
), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { forwardRef } from 'react'; | ||
|
||
import * as RadixSlider from '@radix-ui/react-slider'; | ||
import { css } from 'leather-styles/css'; | ||
|
||
const sliderRootStyles = css({ | ||
position: 'relative', | ||
display: 'flex', | ||
alignItems: 'center', | ||
userSelect: 'none', | ||
touchAction: 'none', | ||
width: '100%', | ||
}); | ||
|
||
const sliderTrackStyles = css({ | ||
backgroundColor: 'ink.component-background-default', | ||
position: 'relative', | ||
flexGrow: 1, | ||
height: '4px', | ||
borderRadius: '0 9999px 9999px 0', | ||
}); | ||
|
||
const sliderRangeStyles = css({ | ||
position: 'absolute', | ||
backgroundColor: 'ink.text-primary', | ||
height: '100%', | ||
}); | ||
|
||
const sliderThumbStyles = css({ | ||
display: 'block', | ||
width: '24px', | ||
height: '24px', | ||
backgroundColor: 'ink.background-primary', | ||
borderRadius: '14px', | ||
boxShadow: 'lg', | ||
cursor: 'pointer', | ||
transition: 'transform 0.2s', | ||
border: '1px solid', | ||
borderColor: 'ink.border-primary', | ||
|
||
'&:hover': { | ||
transform: 'scale(1.1)', | ||
}, | ||
'&:focus': { | ||
outline: 'none', | ||
boxShadow: 'focus', | ||
}, | ||
}); | ||
|
||
const Root = forwardRef<HTMLDivElement, RadixSlider.SliderProps>((props, ref) => ( | ||
<RadixSlider.Root className={sliderRootStyles} ref={ref} {...props} /> | ||
)); | ||
|
||
const Track = forwardRef<HTMLDivElement, RadixSlider.SliderTrackProps>((props, ref) => ( | ||
<RadixSlider.Track className={sliderTrackStyles} ref={ref} {...props} /> | ||
)); | ||
|
||
const Range = forwardRef<HTMLDivElement, RadixSlider.SliderRangeProps>((props, ref) => ( | ||
<RadixSlider.Range className={sliderRangeStyles} ref={ref} {...props} /> | ||
)); | ||
|
||
const Thumb = forwardRef<HTMLDivElement, RadixSlider.SliderThumbProps>((props, ref) => ( | ||
<RadixSlider.Thumb className={sliderThumbStyles} ref={ref} {...props} /> | ||
)); | ||
|
||
export const Slider = { | ||
Root, | ||
Track, | ||
Range, | ||
Thumb, | ||
}; |
Oops, something went wrong.