1.0.0 • Published 5 years ago

react-native-stepper-counter v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

react-native-simple-stepper

Platform npm version npm version Build Status codecov License

A super simple react-native implementation of the UIStepper control from iOS with added customization and flexibility.

Table of contents

  1. Installation
  2. Usage
  3. Props

Installation

npm i react-native-simple-stepper --save OR yarn add react-native-simple-stepper

Usage

import React, { Component } from 'react';
import { SimpleStepper } from 'react-native-simple-stepper';

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = { value: 0 };
  }
  valueChanged(value) {
    // Truncate value to 2 decimal places and cast as Number.
    const nextValue = Number(value.toFixed(2));
    this.setState({ value: nextValue });
    // ...
  }
  render() {
    return <SimpleStepper valueChanged={value => this.valueChanged(value)} />;
  }
}

Props

Values

NameTypeDescriptionDefault
initialValueNumberinitial value0
minimumValueNumberminimum value0
maximumValueNumbermaximum value10
stepValueNumberstep value (ex. increment by 10)1
incrementImageString or Numbernetwork or local imagerequire('./assets/increment.png')
decrementImageString or Numbernetwork or local imagerequire('./assets/decrement.png')
activeOpacityNumbertouch opacity0.4
disabledOpacityNumberwhen step button is disabled0.5
disabledBooleanstepper disable statefalse
wrapsBooleanwhether or not it wraps. more infofalse
bashowTextBooleanwhether or not to show text componentfalse
PositionStringplacement of the text componentcenter

Functions

NameTypeDescriptionDefault
valueChangedFunctioninvoked when value changes() => {}
onMinFunctioninvoked when value reaches min value() => {}
onMaxFunctioninvoked when value reaches min value() => {}
onIncrementFunctioninvoked each time value increments() => {}
onDecrementFunctioninvoked each time value decrements() => {}
renderDecrementImageFunctionused to override decrement image componentundefined
renderIncrementImageFunctionused to override increment image componentundefined
renderDecrementStepFunctionused to override decrement step componentundefined
renderIncrementStepFunctionused to override increment step componentundefined
renderTextFunctionused to override increment text componentundefined

Styles

NameTypeDescriptionDefault
StyleObjecttext component style{ padding: 8, fontSize: 20, fontWeight: 'bold', color: 'blue' }
containerStyleObjectcontainer component style{ backgroundColor: 'transparent', flexDirection: 'row', borderWidth: 2, borderRadius: 8, overflow: 'hidden', alignItems: 'center', borderColor: 'blue' }
separatorStyleObjectseparator component style{ width: StyleSheet.hairlineWidth, backgroundColor: 'blue', height: '100%' }
incrementStepStyleObjectincrement step component style{ padding: 8 }
decrementStepStyleObjectdecrement step component style{ padding: 8 }
incrementImageStyleObjectincrement image component styles{ height: 36, width: 36 }
decrementImageStyleObjectdecrement image component styles{ height: 36, width: 36 }