1.0.0 • Published 4 years ago

react-native-number-slider v1.0.0

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

react-native-number-slider

Number slider component created in React Native

Demo

Installation

$ npm install react-native-number-slider --save

width: PropTypes.number, displayValues: PropTypes.arrayOf(PropTypes.number), value: PropTypes.number, fontSize: PropTypes.number, containerBackground: PropTypes.string, selectedBackground: PropTypes.string, onValueChange: PropTypes.func.isRequired,

How to use

Common Props

PropTypeDefaultDescription
widthNumber300Width of the component.
displayValuesArray1,2,3,4,5Array of inputs that needs to be displayed.
valueNumber1Selected value of the slider. This value will be applied to the Slider and change it's state on every render. Use this prop if you want a Controlled Component.
onValueChangeFunctionThe method that gives you the value of selected number every time it is changed.
fontSizeNumber15Font size style property for the display numbers.
containerBackgroundString'#F1F2F6'The background color of unselected area of the slider.
selectedBackgroundString#FA8072''The background color of the selected area of the slider.

Example

See Example.js file.

Follow those steps to run the example:

  1. Clone the repo git clone https://github.com/vamsiabishek/react-native-number-slider.git && cd react-native-number-slider/examples
  2. Install dependencies `npm install
  3. Follow official instructions to run the example project in a simulator or device.
import React, {useState} from 'react'
import NumberSlider from 'react-native-number-slider'

export default () => {
  const [value, setValue] = useState(1)
  onValueChange = (value) => {
    setValue(value)
  }
  return (
    <NumberSlider 
      onValueChange={onValueChange} 
      value={value} 
      width={300}
      displayValues= {[1, 2, 3, 4, 5]}
      fontSize={15}
      containerBackground='#f1f2f6'
      selectedBackground='#FA8072'
    />
  )
}

Licence

MIT