1.0.0 • Published 4 years ago

@metasys96/react-native-form-fields v1.0.0

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

react-native-form-fields

Cross-platform development is now an essential aspect of software development. Node Packet Manager, the online repository is a go to site for React Programmers. This is MetaSys' contribution based on challenges we had while developing a single application for both Android and iOS. We offer a flexible NPM package, for UI form field widgets which will work on both Android and iOS platforms. The package is based on React hooks and typescript, which provides an error-free field. It also gives you a clean and consistent look and feel on iOS and Android devices with high performance.\ \ This React Native package has the basic form fields such as Radio Button, CheckBox, Dropdown List and different types of Text Fields. The code takes care of most use cases for the different fields. Developers can pass the required properties and get the results easily and very quickly. The documentation below will help you to easily integrate with your React Native projects. This version is compatible with react-native 0.60 and above.

Content

  1. Installation

  2. Screenshots

  3. Getting started

  4. Properties

  5. Contribution

Installation

Run npm i react-native-form-fields--save

import {

  RadioButton,

  CheckBox,

  IconTextField,

  BasicTextField,

  CustomTextField,

  DropDown } from 'react-native-form-fields';

Screenshot

Getting started

Add react-native-form-fields to your JS file.

RadioButton

import {RadioButton} from 'react-native-form-fields'

const onChangeRadio = (selectedObj: any) => {

    console.log('Selected item = ', selectedObj.value)

  };

<RadioButton

  items={[{id:'item1',value:'male'},{id:'item2',value:'female'}]}

  onChange={onChangeRadio}

/>

Properties

NameDescriptionTypeDefault
itemsField Items ArrayArray[ {id: 1, value: 'Option 1'}, {id: 2, value: 'Option 2'}
sizeField SizeNumber-
isVerticalFields' DirectionBooleanfalse
selectedValueSelected FieldObject-
onChangeChange Radio callbackFunction-
containerStyleField Container StyleObject{ flexDirection: 'row', justifyContent: 'center', marginRight: isVertical: '5%'
icon ContainerStyleField Icon Container StyleObject{justifyContent: 'center', shadowColor: 'rgba(0,0,0, .2)', shadowOffset: { height: 1, width: 1 }, shadowOpacity: 1, shadowRadius: 1}
label ContainerStyleField Label Container StyleObject{ justifyContent: 'center'}
labelStyleField Label StyleObject{fontSize: 20, paddingLeft: '2%',color: 'white'}
labelFontSizeField Label Font SizeNumber20
labelColorField Label Font ColorStringblack
selectedIconSelected IconObject{size: 20, name: 'radio-button-checked',type: 'MaterialIcons',color:'black' }
unSelectedIconUnselected IconObject{ size: 20, name:'radio-button-unchecked', type: 'MaterialIcons', color: 'black' }
selectedElementSelected ComponentReact Native Component-
unSelectedElementUnselected ComponentReact Native Component-

CheckBox

import {CheckBox} from 'react-native-form-fields'

<CheckBox label='Javascript' isMarked={true}/>

Properties

NameDescriptionTypeDefault
isCheckedSet Checkbox CheckedBooleanfalse
containerBgColorField Background ColorNumber-
containerFlexDirectionFields' DirectionStringrow
containerStyleField Container StyleObject{ flexDirection:'row',justifyContent: 'center',  marginRight: isVertical : '5%'}
icon ContainerStyleField Icon Container StyleObject{height: 20,justifyContent: 'flex-start',shadowColor: 'rgba(0,0,0, .2)',shadowOffset:{ height: 1,width: 1 },shadowOpacity: 1,shadowRadius: 1}
label ContainerStyleField Label Container StyleObject{ justifyContent:'flex-end'}
labelStyleField Label StyleObject{ fontSize:16, color: 'black'}
labelField labelString-
labelFontSizeField Label Font SizeNumber16
labelColorField Label Font ColorStringblack
onChangeChange checkbox callbackFunction-
checkedIconChecked IconObject{ size: 20, name: 'check-box-outline', type: 'material-community',color:'black' }
unCheckedIconUnchecked IconObject{ size:20, name: 'checkbox-blank-outline', type: 'material-community',color:'black' } 
checkedElementChecked ComponentReact Native Component-
unCheckedElementUnchecked ComponentReact Native Component-

DropDown

import {DropDown} from 'react-native-form-fields'

const dropdownStyles = {

      select: {color: 'white'},

      modalViewBottom: {backgroundColor: 'pink'},

      placeholder: {backgroundColor: 'yellow'},

      modalViewMiddle: {backgroundColor: 'red'},

    };

const onChangeDropdown = (value: any) => {

    console.log('selected value = ', value);

  };

<PickerSelect

     onChange={onChangeDropdown}

     style={dropdownStyles}

     items={[

             {id: 'item1', label: 'Apple', value: 'Apple'},

             {id: 'item2', label: 'Ball', value: 'Ball'},

             {id: 'item3', label: 'Cat', value: 'Cat'}

            ]}

     selectedItem={{id: 'item3', label: 'Cat', value: 'Cat'}}

/>

Properties

NameDescriptionTypeDefault
itemsField Items ArrayArray-
useNativeAndroidPickerStyleNative Android DropdownBooleanfalse
styleDifferent stylesObject-
modalPropsModal View Props (Only iOS)Props-
dropDownPropsDropDown PropsProps-
disabledDropDown disabled for selectionBooleanfalse
textInputPropsField Text Input PropsProps-
placeholderTextColorDropdown Placeholder Text ColorString#C7C7CD
placeholderPlaceholder For DropDownObject-
selectTextDefault Text for Dropdown viewStringSelect
hideSelectBarRender Dropdown Select Button Bar (iOS only)BooleanSelect
onChangeChange Picker callbackFunction-
selectedItemSelected item in the Dropdown listObject
itemTextColorItems Text ColorStringblack
dropdownIconDropDown IconObject{ size: 20, name: 'chevron-down', type: 'entypo', color: 'black' }
fieldIconDropDown Icon ComponentReact Component-

BasicTextField

import {BasicTextField} from 'react-native-form-fields'

const onChangeText = (text: string) => {

    console.log('Field text = ',text);

    setEmail(text);

  };

<BasicTextField

  label='Email'

  value={this.state.email}

  onChange={onChangeText}

/>

Properties

NameDescriptionTypeDefault
labelField LabelString-
labelColorField Label ColorStringblack
labelStyleField Label StyleObject-
isRequiredDisplay Asterisk SymbolBooleanfalse
asteriskTextStyleAsterisk Symbol StyleObject{ color: 'red', fontSize: 16 }
ValueField ValueString-
onFocusBorderColorField Border Color on focusString'#007AFE'
isErrorTo Display errorBooleanfalse
errorTextDisplay Error TextString-
errorColorError Text ColorStringred
errorTextStyleError Text StyleObject-
errorContainerStyleError Container StyleObject{justifyContent:'center', marginLeft: '1%' }
hintTextHintString-
hintTextStyleHint StyleObject{ color: 'orange', fontSize: 16, marginLeft: '2%' }
isSecureEntryTo Set Sensetive Text Stay SecureBooleanfalse
placeholderField PlaceholderString
keyboardTypeKeyboard TypeStringdefault
maxLengthMax Length Of The FieldNumbernull
isClearTextOnFocusTo Clear The Text On FocusBooleanfalse
onChangeChange Text callbackFunction-
text FieldBorderColorField Border ColorStringblack
textFieldStyleObject{color: 'black', paddingLeft: '2%', height: 40,fontSize: 20, paddingVertical: Platform.OS == 'android' ? 0 : null}
textFieldContainerStyleObject{borderColor:'black', borderWidth: 1, borderRadius: 10}
headerStyleObject{alignText: 'center', flexDirection: 'row',flexWrap: 'wrap', marginVertical: '0.5%',paddingLeft: '1%'}
textInputPropsProps for Text InputProps

IconTextField

import {IconTextField} from 'react-native-form-fields'

const onChangeText = (text: string) => {

    console.log('Field text = ',text);

    setUserName(text);

  };

<IconTextField

   icon={{size: 20, name: 'female', type: 'font-awesome'}}

   value={this.state.userName}

   errorText='add text'

   isRequired={true}

   onChange={onChangeText}

/>

Properties

NameDescriptionTypeDefault
iconField IconString{ size: 20,name: 'user', type: 'font-awesome'}
iconColorField Icon ColorStringblack
valueField ValueString
borderColorField Border ColorObjectblack
isRequiredStyleAsterisk Symbol StyleObject
defaultValueDefault ValueString
isErrorTo Display errorBooleanfalse
errorTextDisplay Error TextString
errorColorError Text ColorStringred
errorTextStyleError Text StyleObject{ marginLeft: '5%', color: 'blue' }
isSecureEntryTo Set Sensetive Text Stay SecureBooleanfalse
placeholderField PlaceholderString
placeholderTextColorPlaceholder Text ColorStringgrey
mainContainerStyleMain Container StyleObject{ borderWidth: 1, flexDirection: 'row',borderRadius: 20,alignItems: 'center', height: 40, padding: 8, width: '100%'}
iconContainerStyleIcon Container StyleObject{width:'8%',marginRight: '2%', padding: 1 }
textFieldContainerStyleTextInput Container StyleObject{width:'88%'}
textInputStyleTextInput StyleObject{padding:2,color: 'black',...Platform.select({android: {height: 40}})}
onChangeChange Text callbackFunction-

Custom Text Field

import {CustomTextField} from 'react-native-form-fields'

Features

Customized TextField Features

Animated state transitions (normal, focused and errored)

Customizable font size, colors and animation duration

Disabled state

Outlined and filled fields

Masked input support

Multiline text input

Character counter

Prefix and suffix

Accessory views

Helper text

const onChangeText = (text: string) => {

    console.log('Field text = ',text);

    setFirstName(text);

};

<CustomTextField

   labelText='First Name'

   errorMsg={this.state.firstNameErrorMsg}

   onChange={onChangeText}

   defaultText='Mr.'

   defaultTextPosition={right}

   animationDuration={500}

   isRequired={true}

   isMultiline={true}

   value={this.state.firstName}

/>

Properties

NameDescriptionTypeDefault
isMultilineAllow Multiple LinesBooleanfalse
defaultTextPrefix or Suffix TextString-
defaultTextPositionPosition Of The Default TextStringleft
valueField ValueString-
editableSet Field EditableBooleantrue
isRequiredDisplay Asterisk SymbolBooleanfalse
animationDurationAnimation DurationNumber20
isErrorTo Display errorBooleanfalse
errorTextDisplay Error TextString-
errorColorError Text ColorStringred
tintColorField Color On FocusString'rgb(0,100,234)'
rootColorField Color When Not FocusedString'rgba(0, 0, 0, .87)'
textColorText ColorString'rgba(0, 0, 0, .87)
clearTextOnFocusClear The Text When FocusedBooleanfalse
fontSizeFont Size Of The Text Input When Not FocusedNumber16
errorFontSizeError Text Font SizeNumber12
activeFontSizeFont Size Of The Text Input When FocusedNumber12
autoCapitalizeCapitalize Text,Sentences,Words,CharachtersString'none'
characterLimitCharachter Limit For The Text FieldNumber-
inputContainerOverrideStyleSet Input Container StyleObject-
inputOverrideStyleSet Text Input StyleObject-
onChangeChange Text callbackFunction-
textInputPropsProps for Text InputProps-

Contribution

Any type of issues are welcome. Please add screenshots of the bug and code snippet. Also the quickest way to solve the bug is to reproduce it with one of the examples. We would also welcome Pull Requests.

git clone https://github.com/metasyssoftware/react-native-form-fields

npm install

npm run ios # or npm run android

Copyright and License

Author

MetaSys Software Pvt. Ltd.

License

MIT Copyright 2020 MetaSys Software Pvt. Ltd. All rights reserved.