Skip to content

Commit

Permalink
AutoFields (closes #31).
Browse files Browse the repository at this point in the history
  • Loading branch information
radekmie committed Jun 16, 2016
1 parent 92c20c7 commit 3995ab2
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const ExplicitAutoForm = () =>
| Component | Description | Prerequisites |
|:---------------:|:---------------------------------------------------------------:|:------------------------:|
| `AutoField` | Automatically renders a correct field, based on field's `type`. | *none* |
| `AutoFields` | Render `fields` without `omitFields` (given in `props`). | *none* |
| `BoolField` | Checkbox. | `type: Boolean` |
| `DateField` | HTML5 `date-localtime` input. | `type: Date` |
| `ErrorField` | Error message for given field. | *none* |
Expand Down
32 changes: 32 additions & 0 deletions packages/uniforms-bootstrap3/src/components/fields/AutoFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {PropTypes} from 'react';
import {createElement} from 'react';

import AutoField from './AutoField';

const AutoFields = ({autoField, element, fields, omitFields, ...props}, {uniforms: {schema}}) =>
createElement(
element,
props,
(fields || schema.getSubfields())
.filter(field => omitFields.indexOf(field) === -1)
.map(field => createElement(autoField, {key: field, name: field}))
)
;

AutoFields.contextTypes = AutoField.contextTypes;

AutoFields.propTypes = {
autoField: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
element: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),

fields: PropTypes.arrayOf(PropTypes.string),
omitFields: PropTypes.arrayOf(PropTypes.string)
};

AutoFields.defaultProps = {
autoField: AutoField,
element: 'section',
omitFields: []
};

export default AutoFields;
32 changes: 32 additions & 0 deletions packages/uniforms-bootstrap4/src/components/fields/AutoFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {PropTypes} from 'react';
import {createElement} from 'react';

import AutoField from './AutoField';

const AutoFields = ({autoField, element, fields, omitFields, ...props}, {uniforms: {schema}}) =>
createElement(
element,
props,
(fields || schema.getSubfields())
.filter(field => omitFields.indexOf(field) === -1)
.map(field => createElement(autoField, {key: field, name: field}))
)
;

AutoFields.contextTypes = AutoField.contextTypes;

AutoFields.propTypes = {
autoField: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
element: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),

fields: PropTypes.arrayOf(PropTypes.string),
omitFields: PropTypes.arrayOf(PropTypes.string)
};

AutoFields.defaultProps = {
autoField: AutoField,
element: 'section',
omitFields: []
};

export default AutoFields;
32 changes: 32 additions & 0 deletions packages/uniforms-semantic/src/components/fields/AutoFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {PropTypes} from 'react';
import {createElement} from 'react';

import AutoField from './AutoField';

const AutoFields = ({autoField, element, fields, omitFields, ...props}, {uniforms: {schema}}) =>
createElement(
element,
props,
(fields || schema.getSubfields())
.filter(field => omitFields.indexOf(field) === -1)
.map(field => createElement(autoField, {key: field, name: field}))
)
;

AutoFields.contextTypes = AutoField.contextTypes;

AutoFields.propTypes = {
autoField: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
element: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),

fields: PropTypes.arrayOf(PropTypes.string),
omitFields: PropTypes.arrayOf(PropTypes.string)
};

AutoFields.defaultProps = {
autoField: AutoField,
element: 'section',
omitFields: []
};

export default AutoFields;
32 changes: 32 additions & 0 deletions packages/uniforms-unstyled/src/components/fields/AutoFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {PropTypes} from 'react';
import {createElement} from 'react';

import AutoField from './AutoField';

const AutoFields = ({autoField, element, fields, omitFields, ...props}, {uniforms: {schema}}) =>
createElement(
element,
props,
(fields || schema.getSubfields())
.filter(field => omitFields.indexOf(field) === -1)
.map(field => createElement(autoField, {key: field, name: field}))
)
;

AutoFields.contextTypes = AutoField.contextTypes;

AutoFields.propTypes = {
autoField: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
element: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),

fields: PropTypes.arrayOf(PropTypes.string),
omitFields: PropTypes.arrayOf(PropTypes.string)
};

AutoFields.defaultProps = {
autoField: AutoField,
element: 'section',
omitFields: []
};

export default AutoFields;

0 comments on commit 3995ab2

Please sign in to comment.