adaptui / react-tailwind

React UI built with @adaptui/react, ariakit & tailwind
https://adaptui-react-tailwind.vercel.app
MIT License
37 stars 8 forks source link

[RFC] Slider Component #53

Closed anuraghazra closed 3 years ago

anuraghazra commented 3 years ago

Slider API RFC

Goal

Create an accessible, easy to use but still flexible enough slider component.

Following our renderlesskit slider component: renderlesskit/react slider

Components

Props

All the basic props from :- useSliderState

API

<Slider defaultValue={10} onChane={e => console.log(e)} />

Multi slider

Two values

<Slider defaultValue={[10, 20]} />

If defaultValues contains exactly two values we render this :- image

More than two values

<Slider defaultValue={[10, 20, 30, 40]} />

If defaultValues contains more than two values we render this :-

image

Customization

Track

Customization of track can be done via the theme file

Thumb

To change the styles of the thumb users can use the theme file.

To change the thumb content

<Slider thumbContent={<SomeIcon />} />

Showing values in thumb

<Slider thumbContent={value => <span>{value} %</span>} />

Tooltip content

Format tooltip text

const tooltipFormatter = value => `${value}$`;

<Slider tooltipContent={tooltipFormatter} />;

Rendering react elements in tooltipContent

const tooltipFormatter = (value) => <span className="px-2">{value}</span>

<Slider tooltipContent={tooltipFormatter} />

Full customization

Users can do full customization through renderprops

<Slider>
  {state => (
    <>
      <SliderTrack />
      <SliderThumb>
        <VisuallyHidden>
          <SliderInput />
        </VisuallyHidden>
      </SliderThumb>
      <SliderThumbTooltip>Tooltip content</SliderThumbTooltip>
    </>
  )}
</Slider>
navin-moorthy commented 3 years ago

Merged #54