npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rhfa-react-native

v1.2.0

Published

Generate automatic forms following a schema for React Native

Downloads

20

Readme

rhfa-react-native

This library allows your React application to automatically generate forms using ReactHookForm that are redered by React Native. The form and validations are generated following a schema inspired by SimpleSchema.

It uses some react-native-community packages to help with checkbox, slider and picker.

Upgrade to 1.2.0

You must change your package.json entry from @react-native-community/picker to @react-native-picker/picker. It will look like this:

    "dependencies": {
      "@react-native-picker/picker": "^2.0.0",
      ...
    }

Installation

$ npm install react-hook-form rhfa-react-native @react-native-community/checkbox @react-native-community/slider @react-native-picker/picker --save

Usage

    import { createSchema, Autoform } from 'rhfa-react-native'
    import { createStyles } from 'rhfa-react-native/dist/emergencyStyles'

    const style = createStyles()

    export const client = createSchema('client', {
      name: {
        type: 'string',
        required: true,
        max: 32
      },
      age: {
        type: 'number'
      }
    })

    const MyForm = ({ onSubmit }) =>
      <Autoform
        schema={client}
        onSubmit={onSubmit}
        styles={styles}
      />

Styling

The emergency styles are separated in its own bundle. The function createStyles will generate some styles for the components. It gereates some styles proceduraly and you can set some better defaults:

  createStyles({
    backgroundColor = '#e0e0e0',
    height = 32,
    headerColor = '#a0a0a0',
    panelBorderColor = '#a0a0a0',
    inputBorderColor = '#c0c0c0',
    inputBackgroundColor = '#ffffff',
    radioRadio = 8,
    radioColor = '#808080',
    radioSelectedColor = '#404040',
    buttonColor = '#909090',
    addColor = '#70a070',
    addTextColor = '#104010',
    removeColor = '#a07070',
    removeTextColor = '#ffe0e0',
    errorColor = '#601010',
    errorBackgroundColor = '#ffe0e0',
    miniHeight = 24,
    fontSize = 16
  } = {})

Specific schema attributes for React Native

type = 'range'

Appart from min and max, you should setup step. It will coerce to nearest step:

  something: {
    type: 'range',
    min: 10,
    max: 90,
    step: 5,
    defaultValue: 50
  }

Helper text

You can specify helperText in the schema.

    import { createSchema } from 'rhfa-react-native'

    const smt = createSchema('something', {
      name: {
        type: 'string',
        helperText: tr('models.name.helper')
      }
    })

You can set the text directly too, without using tr().

Also you can set model translation string attribute _helper to any value:

    setTranslations({
      name: {
        _field: 'Name',
        _helper: 'Please, enter your name'
      }
    })

Label info

Labels can have a field that appears in a less prominent color adding some clarification. This label info will come from translations:

    setTranslations({
      name: {
        _field: 'Name',
        _labelInfo: '(given name)'
      }
    })

The label tr('requiredLabel') will be added automatically for required fields (unless you override with translations).

Documentation