1.0.2 • Published 4 years ago

@strv/react-sliders v1.0.2

Weekly downloads
45
License
MIT
Repository
github
Last release
4 years ago

@strv/react-sliders

Continuous Integration Dependabot Mergify Status npm latest bundlephobia code style: prettier semantic-release

Features

Install

# npm
npm install @strv/react-sliders --save

# yarn
yarn add @strv/react-sliders

Usage

Basic Examples

useSlider

import React from 'react'
import { useSlider } from '@strv/react-sliders'

const SliderExample = () => {
  const [value, setValue] = React.useState(0)
  const { getRailProps, getTrackProps, getHandleProps } = useSlider({
    value,
    min: 0,
    max: 100,
    onChange: setValue,
  })

  return (
    <div className="slider-container">
      <span className="slider-rail" {...getRailProps()} />
      <span className="slider-track" {...getTrackProps()} />

      <span className="slider-handle" {...getHandleProps()} />
    </div>
  )
}

useRangeSlider

import React from 'react'
import { useRangeSlider, TRangeTuple } from '@strv/react-sliders'

const RangeSliderExample = () => {
  const [value, setValue] = React.useState<TRangeTuple>([0, 100])
  const { getRailProps, getTrackProps, getMinHandleProps, getMaxHandleProps } = useRangeSlider({
    value,
    min: 0,
    max: 100,
    onChange: setValue,
  })

  return (
    <div className="range-slider-container">
      <span className="range-slider-rail" {...getRailProps()} />
      <span className="range-slider-track" {...getTrackProps()} />

      <span className="range-slider-handle" {...getMinHandleProps()} />
      <span className="range-slider-handle" {...getMaxHandleProps()} />
    </div>
  )
}

If you want so see more, head to the list of existing CodeSandbox examples.

Hooks API


Related

This project was bootstrapped with TSDX.

Contribution

See Contributing guide

Authors

License

MIT License

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago