1.0.1 • Published 5 years ago

cashestate-react-native-input v1.0.1

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

Reinput

devDependency Status js-standard-style semantic-release npm

A React Native TextInput with material style 😎

Installation

npm install --save reinput

yarn add reinput

Motivation

Styling react-native inputs can be cumbersome. And most of them heavily relies onto the material design patterns. This style layer over the regular TextInput paves the way towards and easier and faster development.

We also expose a ReinputButton. Check the docs ;)

Usage

import Reinput from 'reinput'

const Input = () => (
  <View>
    <Reinput label='name' />
    <Reinput error='Handles error' />
    <Reinput label='name' value='control value from outside' />
    <Reinput label='name' defaultValue='initial value' />
    <Reinput label='name' onChangeText={/* any TextInput prop */} />
  </View>
)

Props

Input

NameTypeDefault
activeColorString
colorString#000000
fontFamilyString
fontSizeNumber15
fontWeightString or Numbernormal
heightNumber64
marginBottomNumber8
marginLeftNumber
marginRightNumber
marginTopNumber
maxHeightNumber
minHeightNumber
onBlurFunction
onChangeTextFunction
onContentSizeChangeFunction
onFocusFunction
paddingBottomNumber8
paddingLeftNumber0
paddingRightNumber0
paddingTopNumber20
registerFunctionnoop
  • Register exposes the TextInput ref component out

Label

nametypedefault
labelString
labelActiveColorString#3f51b5
labelActiveScaleNumber0.8
labelActiveTopNumber-18
labelColorString#757575
labelDurationNumber200

Icon

NameTypeDefault
iconElement
iconOverlayElement

Placeholder

NameTypeDefault
placeholderString
placeholderColorString#757575
placeholderVisibilitybooleanundefinednull

How placeholderVisibility works?

{
    Always: 1,
    Never: null,
    OnFocus: true,
    OnBlur: false,
}

Underline

NameTypeDefault
underlineActiveColorString#3f51b5
underlineActiveHeightNumber2
underlineColorString#757575
underlineDurationNumber200
underlineHeightNumber1

Error

NameTypeDefault
errorString
errorColorString#fc1f4a
errorStyleTextStyle
errorStyle.fontSizeNumber12
errorStyle.paddingTopNumber4
errorStyle.paddingBottomNumber4

And also all the TextInput properties will work.

ReinputButton

We also expose a component that looks like an Input but it's a button so accepts onPress prop. We do following the material design guidelines.

Props are the same as the Input but it also accepts an onPress and doesn't have hooks for focus/blur events.

import { ReinputButton } from 'reinput'

const Input = () => (
  <ReinputButton
    label='This is not an Input'
    value='If there is no value it shows the label as placeholder'
    onPress={/* whatever callback */}
  />
)

Example

I'm working on an expo demo. So far, you can clone the project and check the example dir. It's the one of the gif ;)

Credits

Style patterns are mainly based on Material Design; properly adapted for iOS.