UNPKG

semantic-ui-react

Version:
108 lines (87 loc) 3.16 kB
import _extends from 'babel-runtime/helpers/extends'; import _without from 'lodash/without'; import cx from 'classnames'; import React, { PropTypes } from 'react'; import { customPropTypes, getElementType, getUnhandledProps, META, SUI, useKeyOnly, useWidthProp } from '../../lib'; import FormButton from './FormButton'; import FormCheckbox from './FormCheckbox'; import FormDropdown from './FormDropdown'; import FormField from './FormField'; import FormGroup from './FormGroup'; import FormInput from './FormInput'; import FormRadio from './FormRadio'; import FormSelect from './FormSelect'; import FormTextArea from './FormTextArea'; /** * A Form displays a set of related user input fields in a structured way. * @see Button * @see Checkbox * @see Dropdown * @see Input * @see Message * @see Radio * @see Select * @see TextArea */ function Form(props) { var children = props.children, className = props.className, error = props.error, inverted = props.inverted, loading = props.loading, reply = props.reply, size = props.size, success = props.success, warning = props.warning, widths = props.widths; var classes = cx('ui', size, useKeyOnly(error, 'error'), useKeyOnly(inverted, 'inverted'), useKeyOnly(loading, 'loading'), useKeyOnly(reply, 'reply'), useKeyOnly(success, 'success'), useKeyOnly(warning, 'warning'), useWidthProp(widths, null, true), 'form', className); var rest = getUnhandledProps(Form, props); var ElementType = getElementType(Form, props); return React.createElement( ElementType, _extends({}, rest, { className: classes }), children ); } Form.handledProps = ['as', 'children', 'className', 'error', 'inverted', 'loading', 'reply', 'size', 'success', 'warning', 'widths']; process.env.NODE_ENV !== "production" ? Form.propTypes = { /** An element type to render as (string or function). */ as: customPropTypes.as, /** Primary content. */ children: PropTypes.node, /** Additional classes. */ className: PropTypes.string, /** Automatically show any error Message children. */ error: PropTypes.bool, /** A form can have its color inverted for contrast. */ inverted: PropTypes.bool, /** Automatically show a loading indicator. */ loading: PropTypes.bool, /** A comment can contain a form to reply to a comment. This may have arbitrary content. */ reply: PropTypes.bool, /** A form can vary in size. */ size: PropTypes.oneOf(_without(SUI.SIZES, 'medium')), /** Automatically show any success Message children. */ success: PropTypes.bool, /** Automatically show any warning Message children .*/ warning: PropTypes.bool, /** Forms can automatically divide fields to be equal width. */ widths: PropTypes.oneOf(['equal']) } : void 0; Form.defaultProps = { as: 'form' }; Form._meta = { name: 'Form', type: META.TYPES.COLLECTION }; Form.Field = FormField; Form.Button = FormButton; Form.Checkbox = FormCheckbox; Form.Dropdown = FormDropdown; Form.Group = FormGroup; Form.Input = FormInput; Form.Radio = FormRadio; Form.Select = FormSelect; Form.TextArea = FormTextArea; export default Form;