1.0.12 • Published 4 years ago

fitx-form v1.0.12

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

A responsive React form for various input types controlled by a JSON component for faster and easier web development.

npm package npm downloads

Fitx - Form Image Fitx - Form Output

Installation

fitx-form is available as an npm package.

// with npm
npm install fitx-form

// with yarn
yarn add fitx-form

Please note that @next will only point to pre-releases; to get the latest stable release use @latest instead.

Usage

constants.js

export default [
  {
    elements: [
      {
        id: 'fName',
        name: 'First Name',
        type: 'TextInput',
        placeholder: 'Full Name',
      },
    ],
    groupName: 'Personal Details',
    groupId: 'personalDetails',
  },
];

Here is a quick example to get you started, it's all you need:

import React from 'react';
import ReactDOM from 'react-dom';
import FitxForm from 'fitx-form';
import * as R from 'ramda';
import * as Constants from './constants';

function App() {
  return (
    <FitxForm
      metaData={Constants.metaData}
    />
  );
}

ReactDOM.render(<App />, document.querySelector('#app'));

Full working exapmle with handlers is given in the Example section

Documentation

FitxForm Props

PropsTypeDescription
formValuesobjectThe value object
metaDataarrayArray of the components
onChangefuncOn Change event
onClickfuncOn Click event
columnsnumberNumber of columns to be displayed

Component Props

PropsTypeDescription
allowClearboolEnables date clear button
defaultValueBased on the typeDefault value for the field, Triggers onChange when component renders
disabledboolMark the element to be disabled
displayNamestringDisplay text of ButtonInput
emptyOptionboolDisplay empty option in SelectInput as placeHolder
errorboolShow the error container and display errorText
errorTextstringString to be displayed in the error container
helperTextstringString to be displayed as a helper text in error container
maxnumberThe max input for Number and Date
maxLengthnumberMax length of the input in chars
minnumberThe min input for Number and Date
onClickfuncTriggers on a ButtonInput click () => (groupId, elementId)
onChangefuncTriggers on a value change () => (groupId, elementId, value)
onSelectfuncTriggers on a value select () => (groupId, elementId, value)
optionsarrayList of options as { label, value, disabled}
options.labelstringThe display name of the option
options.valuestringThe id of the option
options.disabledboolDisables the option
placeholderstringString to be displayed as a placeholder
readOnlyboolMarks the field as read only
regexregexpRegex for input value -> error is true if regex fails
spellCheckboolEnables native spell check in text inputs
valuestringThe value to be hardcoded
typeButtonInput, CheckboxInput, DateInput, RadioInput, SelectInput, TextInputThe Component Type
subTypestringSub type of available components

Example

Full Working Example

Constants File.

import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import FitxForm from 'fitx-form';
import * as R from 'ramda';
import * as Constants from './constants';

function App() {
  const [values, setValues] = useState({});
  const onFormValuesChange = (groupId, elementId, value) => {
    const lensProp = R.lensPath([groupId, elementId]);
    const newValue = R.set(lensProp, value, { ...values });
    setValues(newValue);
  };
  const onFormElementClick = (groupId, elementId) => {
    let query = `${groupId} ${elementId}`;
    switch (query) {
      case 'personalDetails submit':
        onPartySave();
        break;
      default: {
        query = '';
      }
    }
  };
  return (
    <FitxForm
      formValues={values}
      metaData={Constants.metaData}
      onChange={onFormValuesChange}
      onClick={onFormElementClick}
      columns={2}
    />
  );
}

ReactDOM.render(<App />, document.querySelector('#app'));

Fitx - Form Exapmle

Changelog

Recently Updated? Please read the changelog.

Roadmap

  1. To Add custom themes
  2. Make is more backward compactible

Author

Balkishan S

Github, Medium, Facebook,

License

This project is licensed under the terms of the MIT license.

1.0.11

4 years ago

1.0.12

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.10

4 years ago

1.0.0

4 years ago