cl-react-ui
TypeScript icon, indicating that this package has built-in type declarations

1.5.1 • Public • Published

cl-react-form

Simple react form rendering

Examples

You can try out some of the component via react story book, still a work in progress:

yarn storybook

In the mean time the old examples can be built :

cd src/examples
yarn build
google-chrome index.html

Forms

import layout from './MyFormLayout';
import {validations} from 'cl-react-ui';
 
const config = {
    view: 'example',
    lib : 'reactstrap',
    form: {
      actions: {
        submit: {
          id: 'upload-action-submit',
          type: 'submit',
          label: 'Upload',
          style: 'primary'
        }
      },
      fields: {
        id: {
          type: 'hidden'
        },
        name: {
          label: 'Name',
          type: 'text',
          ref: 'name',
          value: '',
          placeholder: 'Name',
          validate: {
            promises: [{
              rule: validations.required
            }],
            msg: (value, data) => 'Name required'
          }
        },
        label: {
          value: 'foo',
          access: {
            new: (field, data) => true,
            edit: (field, data) => true
          }
        },
        age: {
          pristine: true,
          accesss: {}
        },
        checkbox: {
          type: 'checkbox'
        }
      }
    }
  };
 
<Form
  config={config}
  layout={layout}
  errors={errors}
  title="override title (can be a function or string)"
  visibility={{age: false}} // Hide the age field
  onSubmit={(e: Event, data: Object) => {
 
  }} />

lib: 'react-bootstrap' | 'reactstrap'

Validations

Validations use the validate-promise library

Errors

Form errors should be an object, keyed on the field name, whose values are an array of error messages

 
let errors = {
  name: ['Please enter a name', 'Cheese is not a proper name']
};
 

Lists

render() {
 
  const config = {
    view: 'example',
    lib : 'reactstrap',
    list: {
      columns: {
        id: {
          label: 'ID'
        },
        name: {
          label: 'Name'
        },
      }
    },
    messages: {
      emptyData: 'No records found',
    },
  }
  const data = [
    {id: '1', name: 'one'},
    {id: '2', name: 'two'}
  ];
 
// Hooks into various list events, this is a good place to bind your redux actions
  const listActions = {
    add: (view, state) => {
      this.props.save(state);
    },
    setForm: (view, row) => null, // A row is selected for editing
    selectRow: () => null, // A Row is selected
  }
  
  return <List 
      config={config} 
      data={data}
      access={{
        add: true,
      }}
      actions={listActions}>
      {({actions, handleUpdate, showModal, close}) => <Modal isOpen={showModal} toggle={close}>
            <Form
              actions={{close: {
                action: close,
                id: 'modal-close',
                label: 'Close',
                type: 'button',
              }}}
              data={{            // Initial form data
                name: 'three',
              }}
              formUpdate={actions.formUpdate}
              layout="Modal"
              config={config}
              onSubmit={(e, state) => handleUpdate(e, state)}
            />
        </Modal>
          }
    <List>
}

Icon

Renders a font-awesome icon

import {Icon} from 'cl-react-ui';
 
<Icon
  icon: string,
  color?: string,
  label?: string,
  pull?: string,
  size?: 0 | 1 | 2 | 3 | 4 | 5,
  stack: number,
  inverse: boolean,
  spin: boolean />

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.5.10latest

Version History

VersionDownloads (Last 7 Days)Published
1.5.10
1.5.00
1.4.90
1.4.80
1.4.70
1.4.60
1.4.50
1.4.40
1.4.30
1.4.20
1.4.00
1.3.140
1.3.130
1.3.120
1.3.110
1.3.100
1.3.90
1.3.80
1.3.70
1.3.60
1.3.50
1.3.40
1.3.30
1.3.20
1.3.10
1.3.00
1.2.20
1.2.10
1.2.00
1.1.00
1.0.360
1.0.350
1.0.340
1.0.330
1.0.320
1.0.310
1.0.300
1.0.290
1.0.280
1.0.270
1.0.260
1.0.250
1.0.240
1.0.230
1.0.220
1.0.210
1.0.200
1.0.190
1.0.180
1.0.170
1.0.160
1.0.150
1.0.140
1.0.130
1.0.1-2.10
1.0.120
1.0.110
1.0.100
1.0.90
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i cl-react-ui

Weekly Downloads

0

Version

1.5.1

License

MIT

Last publish

Collaborators

  • infosum_sre
  • andrew.murphy.is
  • pollen8
  • andyjs_is