1.4.0 • Published 2 years ago

@mobeye/react-native-form-fields v1.4.0

Weekly downloads
10
License
MIT
Repository
github
Last release
2 years ago

@mobeye/react-native-form-fields

Optimized field components with nice design for react-native forms


Table of contents

Getting started

Install the library using Yarn:

// add library
yarn add @mobeye/react-native-form-fields

// add peer dependencies
yarn add @react-native-community/datetimepicker

General Usage

See example app (example/App.tsx) for more examples using TypeScript

You can use most Fields based on the example below, they work in the same way as a basic TextInput.
!!! All fields and component are wrapped with React.memo for memoization.

import React from 'react';
import SingleLineTextField from '@mobeye/react-native-form-fields';

const containerStyle = {
    width: '90%',
    marginTop: 10,
    borderRadius: 5,
    padding: 10,
    backgroundColor: '#fff',
    shadowColor: '#000',
    shadowOpacity: 0.1,
    shadowOffset: { width: 0, height: 2 },
    shadowRadius: 14,
    elevation: 5,
};

const App = () => {
    const [text, setText] = React.useState('');

    // Make sure to use React callbacks and/or memoized values to prevent unnecessary renders !
    return (
        <SingleLineTextField
            label="Click on me !"
            value={text}
            onChangeText={setText}
            containerStyle={containerStyle}
        />
    );
};

Field common props

Description

All fields come with an optional Description to display text and/or images above the field. Can be used to give context, indications or whatever you want.

Those props are present in every field and will be immediately passed to the Description component.

PropertyTypeDescription
descriptionTextstring(Optional) Text to display
descriptionPicturesFormUrl[](Optional) Pictures to display. See FormUrl
descriptionImageViewerFC<ImageViewerProps>(Optional) If an ImageViewer component is provided, it will open on picture press. See ImageViewerProps
onPressDescriptionPicture(index: number) => void(Optional) callback fired when user touches a picture
descriptionContainerStyleViewStyle(Optional) Style for the Description container
descriptionTextStyleTextStyle(Optional) Style for the text
descriptionPicturesContainerStyleViewStyle(Optional) Style for the view containing the pictures
descriptionPictureStyleImageStyle(Optional) Style for the Image components rendering the pictures

FormUrl

Custom type used to pass pictures to the Description component

PropertyTypeDescription
srcstring(Required) Url or path to the image
namestring(Optional) Not used for now
sizenumber(Optional) Not used for now
dimensions{ width: number; height: number }(Optional) If not provided will be computed on initial render and every time pictures changes

ImageViewerProps

Props of the custom ImageViewer component passed using descriptionImageViewer Those 4 props will be passed to the component by the DescriptionPictures component It is up to you to use them or not

PropertyTypeDescription
isVisibleboolean(Required) Show/Hide ImageViewer
pictureUrisstring[](Required) List of the description pictures
startingIndexnumber(Required) index of the picture pressed by the user
goBack() => void(Required) callback to dismiss the viewer

Styles

In addition to their own style props, every field has these 4 styles:

PropertyTypeDescription
containerStyleViewStyle(Optional) Container style
labelAndValidationContainerStyleViewStyle(Optional) Label/validation container style
labelStyleTextStyle(Optional) Label text style
validationDotStyleViewStyle(Optional) Validation dot style

Colors

All fields have an optional props colors which is an object with the optional following keys: valid, error, active, inactive, activeBackground, inactiveBackground, placeholder

Depending on the field only some of them can be used. If unsure please refer to the types exported with the library

Fields

SingleLineTextField

A TextInput with a nice animation on focus/blur

PropertyTypeDescription
labelstring(Required) Label to display and animate
valuestring(Required) Value to display in the input. Can be empty
isValidbool | null(Optional) If undefined or null, validation will not be rendered. If boolean validation will be rendered either as valid or invalid
onChangeText(text: string) => void(Optional) TextInput onChangeText callback
onFocus() => void(Optional) Triggered on input focus
onBlur() => void(Optional) Triggered on input blur
leftIcon(isExpanded: boolean) => React.ReactNode(Optional) Func that return icon to display on the left part of the field. isExpanded is true when the field contain a value
rightIcon(isExpanded: boolean) => React.ReactNode(Optional) Func that return icon to display on the right part of the field. isExpanded is true when the field contain a value
minFontSizenumber(Optional) the min size for the font
maxFontSizenumber(Optional) the max size for the font
textInputPropsTextInputProps(Optional) Props that will be directly passed down to the TextInput
inputContainerStyleViewStyle(Optional) input container style
inputStyleTextStyle(Optional) Style to pass down to the TextInput
disabledboolean(Optional) To make it not editable

MultiLineTextField

A multi line TextInput with a nice animation on focus/blur

PropertyTypeDescription
labelstring(Required) Label to display and animate
valuestring(Required) Value to display in the input. Can be empty
isValidbool | null(Optional) If undefined or null, validation will not be rendered. If boolean validation will be rendered either as valid or invalid
placeholderstring(Optional) Placeholder to display is no value
onChangeText(text: string) => void(Optional) TextInput onChangeText callback
onFocus() => void(Optional) Triggered on input focus
onBlur() => void(Optional) Triggered on input blur
textInputPropsTextInputProps(Optional) Props that will be directly passed down to the TextInput
inputStyleTextStyle(Optional) Style to pass down to the TextInput
disabledboolean(Optional) To make it not editable

MCQField

A MCQ field that can be foldable.

PropertyTypeDescription
labelstring(Required) Label to display and animate
possibleAnswersstring[](Required) List of possible answers to display
selectedAnswersIndicesnumber[](Required) List of indices of the selected answers
onSelectAnswer(answerIndex: number) => void(Required) Callback fired when user selects an answer
isValidbool | null(Optional) If undefined or null, validation will not be rendered. If boolean validation will be rendered either as valid or invalid
foldableboolean(Optional) Should the MCQField be foldable (useful when there are a lot of possible answers)
openFoldableLabelstring(Optional) Opening button label for foldable MCQ
closeFoldableLabelstring(Optional) Closing button label for foldable MCQ
activeAnswerIconReact.ReactNode(Optional) Icon to display next to the answer when it is selected
inactiveAnswerIconReact.ReactNode(Optional) Icon to display next to the answer when it is not selected
activeOpenFoldableIconReact.ReactNode(Optional) Icon to display in the open button for foldable MCQ when it is closed
inactiveOpenFoldableIconReact.ReactNode(Optional) Icon to display in the open button for foldable MCQ when it is opened
activeCloseFoldableIconReact.ReactNode(Optional) Icon to display in the close button for foldable MCQ when it is closed
inactiveCloseFoldableIconReact.ReactNode(Optional) Icon to display in the close button for foldable MCQ when it is opened
shouldAnimateOpenFoldableIconboolean(Optional) Should the openFoldableIcon be animated (90° rotation) on opening
answerContainerStyleViewStyle(Optional) Answer container style
answerTextStyleTextStyle(Optional) Answer text style
openFoldableBoxStyleViewStyle(Optional) Open foldable button style
openFoldableLabelStyleTextStyle(Optional) Open foldable button label style
closeFoldableBoxStyleViewStyle(Optional) Close foldable button style
closeFoldableLabelStyleTextStyle(Optional) Close foldable button label style
validLabelstring(Optional) Text to put inside tablet
validLabelStyleViewStyle(Optional) Style for tablet text
disabledboolean(Optional) To make it not editable

PickerField

A simple presentational picker field with an openPicker prop to work with an input picker component like DatePicker.

PropertyTypeDescription
labelstring(Required) Label to display and animate
valuestring(Required) Value to display in the input. Can be empty
openPicker() => void(Required) Callback fired when user presses the field to open the picker
isValidbool | null(Optional) If undefined or null, validation will not be rendered. If boolean validation will be rendered either as valid or invalid
leftIcon(isExpanded: boolean) => React.ReactNode(Optional) Func that return icon to display on the left part of the field. isExpanded is true when the field contain a value
rightIcon(isExpanded: boolean) => React.ReactNode(Optional) Func that return icon to display on the right part of the field. isExpanded is true when the field contain a value
inputContainerStyleViewStyle(Optional) input container style
inputStyleTextStyle(Optional) Style to pass down to the TextInput
disabledboolean(Optional) To make it not editable

DatePickerField

A date picker field which use the DatePicker component.

PropertyTypeDescription
labelstring(Required) Label to display and animate
valueDate(Optional) date value to display in the input.
isValidbool | null(Optional) If undefined or null, validation will not be rendered. If boolean validation will be rendered either as valid or invalid
onChange(date?: Date) => void(Required) Callback fired when user selects a date
leftIcon(isExpanded: boolean) => React.ReactNode(Optional) Func that return icon to display on the left part of the field. isExpanded is true when the field contain a value
rightIcon(isExpanded: boolean) => React.ReactNode(Optional) Func that return icon to display on the right part of the field. isExpanded is true when the field contain a value
dateStringFormatstring(Optional) the format of the value. default is 'DD/MM/YYYY'
minimumDateDate(Optional) The min date selectable in the picker
maximumDateDate(Optional) The max date selectable in the picker
iosClearButtonTextstring(Optional) The label for the clear button on iOS. Default: 'CLEAR'
iosValidateButtonTextstring(Optional) The label for the validate button on iOS. Default: 'OK'
inputContainerStyleViewStyle(Optional) Style to pass down to the input container
inputStyleTextStyle(Optional) Style to pass down to the input text
modalStyleViewStyle(Optional) Style to pass down to the modal wrapping the date picker
datePickerIOSContainerStyleViewStyle(Optional) Style to pass to the date picker container on iOS only
datePickerIOSHeaderStyleViewStyle(Optional) Style to pass to the date picker header on iOS only
disabledboolean(Optional) To make it not editable

PhotoField

A field that display photos. To take photo with it, you need to implement yourself a camera.

PropertyTypeDescription
labelstring(Required) Label to display and animate
pictureUrisstring[](Required) List of picture uris to display
openCameraButtonReact.ReactNode(Required) Open Camera button to be pressed by the user to open the camera
isValidbool | null(Optional) If undefined or null, validation will not be rendered. If boolean validation will be rendered either as valid or invalid
onPressPicture(index: number) => void(Optional) Callback fired when user presses a picture
openCameraButtonReact.ReactNode(Required) The open camera button component
imageComponent(uri: string, style?: StyleProp<any>) => React.ReactNode(Optional) Func that return the Image component to display. Default: <Image source={{ uri }} style={style} />
imagesContainerStyleViewStyle(Optional) Style for the view containing the images
imageContainerStyleViewStyle(Optional) Style for the Touchable containing each individual image
imageStyleImageStyle(Optional) Style for the images

Other components

Description

You can directly import and use the Description component.

DatePicker

A date picker component. To be used with a presentational component like PickerField that can display the picked date.

PropertyTypeDescription
isVisibleboolean(Required) Boolean to show or hide the picker.
valueDate(Optional) Date value to display in the input.
onClosePicker(date?: Date) => void(required) Callback fired when the picker is closed.
minimumDateDate(Optional) The min date selectable in the picker
maximumDateDate(Optional) The max date selectable in the picker
iosClearButtonTextstring(Optional) The label for the clear button on iOS. Default: 'CLEAR'
iosValidateButtonTextstring(Optional) The label for the validate button on iOS. Default: 'OK'
modalStyleViewStyle(Optional) Style to pass to the modal wrapping the date picker
datePickerIOSContainerStyleViewStyle(Optional) Style to pass to the date picker container on iOS only
datePickerIOSHeaderStyleViewStyle(Optional) Style to pass to the date picker header on iOS only

Example

You can run a simple example present in the module to test the form. First, you need to install node_modules and example pods:

yarn && cd example/ios/ && pod install && cd .. && yarn && yarn start

Then, open the example directory with xcode or android studio to build the example.


1.4.0

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

4 years ago