Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(Form): update typings and propTypes usage #1320

Merged
merged 5 commits into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/addons/Radio/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { CheckboxProps } from '../../modules/Checkbox';

interface RadioProps extends CheckboxProps {
export interface RadioProps extends CheckboxProps {
[key: string]: any;

/** Format to emphasize the current selection state. */
Expand Down
2 changes: 1 addition & 1 deletion src/addons/Select/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DropdownProps
} from '../../modules/Dropdown';

interface SelectProps extends DropdownProps {
export interface SelectProps extends DropdownProps {
selection: true;
}

Expand Down
46 changes: 20 additions & 26 deletions src/collections/Form/Form.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash'
import cx from 'classnames'
import _ from 'lodash'
import React, { Component, PropTypes } from 'react'

import {
Expand Down Expand Up @@ -156,15 +156,6 @@ function formSerializer(formNode) {
return json
}

const _meta = {
name: 'Form',
type: META.TYPES.COLLECTION,
props: {
widths: ['equal'],
size: _.without(SUI.SIZES, 'medium'),
},
}

/**
* A Form displays a set of related user input fields in a structured way.
* @see Button
Expand All @@ -177,11 +168,6 @@ const _meta = {
* @see TextArea
*/
export default class Form extends Component {
static defaultProps = {
as: 'form',
serializer: formSerializer,
}

static propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,
Expand All @@ -192,13 +178,13 @@ export default class Form extends Component {
/** Additional classes. */
className: PropTypes.string,

/** Automatically show any error Message children */
/** Automatically show any error Message children. */
error: PropTypes.bool,

/** A form can have its color inverted for contrast */
/** A form can have its color inverted for contrast. */
inverted: PropTypes.bool,

/** Automatically show a loading indicator */
/** Automatically show a loading indicator. */
loading: PropTypes.bool,

/**
Expand All @@ -212,23 +198,31 @@ export default class Form extends Component {
/** A comment can contain a form to reply to a comment. This may have arbitrary content. */
reply: PropTypes.bool,

/** Called onSubmit with the form node that returns the serialized form object */
/** Called onSubmit with the form node that returns the serialized form object. */
serializer: PropTypes.func,

/** A form can vary in size */
size: PropTypes.oneOf(_meta.props.size),
/** A form can vary in size. */
size: PropTypes.oneOf(_.without(SUI.SIZES, 'medium')),

/** Automatically show any success Message children */
/** Automatically show any success Message children. */
success: PropTypes.bool,

/** Automatically show any warning Message children */
/** Automatically show any warning Message children .*/
warning: PropTypes.bool,

/** Forms can automatically divide fields to be equal width */
widths: PropTypes.oneOf(_meta.props.widths),
/** Forms can automatically divide fields to be equal width. */
widths: PropTypes.oneOf(['equal']),
}

static _meta = _meta
static defaultProps = {
as: 'form',
serializer: formSerializer,
}

static _meta = {
name: 'Form',
type: META.TYPES.COLLECTION,
}

static Field = FormField
static Button = FormButton
Expand Down
5 changes: 2 additions & 3 deletions src/collections/Form/FormButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
META,
} from '../../lib'
import Button from '../../elements/Button'

import FormField from './FormField'

/**
* Sugar for <Form.Field control={Button} />
* Sugar for <Form.Field control={Button} />.
* @see Button
* @see Form
*/
Expand All @@ -33,7 +32,7 @@ FormButton.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** A FormField control prop */
/** A FormField control prop. */
control: FormField.propTypes.control,
}

Expand Down
5 changes: 2 additions & 3 deletions src/collections/Form/FormCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
META,
} from '../../lib'
import Checkbox from '../../modules/Checkbox'

import FormField from './FormField'

/**
* Sugar for <Form.Field control={Checkbox} />
* Sugar for <Form.Field control={Checkbox} />.
* @see Checkbox
* @see Form
*/
Expand All @@ -33,7 +32,7 @@ FormCheckbox.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** A FormField control prop */
/** A FormField control prop. */
control: FormField.propTypes.control,
}

Expand Down
5 changes: 2 additions & 3 deletions src/collections/Form/FormDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
META,
} from '../../lib'
import Dropdown from '../../modules/Dropdown'

import FormField from './FormField'

/**
* Sugar for <Form.Field control={Dropdown} />
* Sugar for <Form.Field control={Dropdown} />.
* @see Dropdown
* @see Form
*/
Expand All @@ -33,7 +32,7 @@ FormDropdown.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** A FormField control prop */
/** A FormField control prop. */
control: FormField.propTypes.control,
}

Expand Down
23 changes: 7 additions & 16 deletions src/collections/Form/FormField.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash'
import cx from 'classnames'
import _ from 'lodash'
import React, { createElement, PropTypes } from 'react'

import {
Expand All @@ -16,7 +16,7 @@ import Checkbox from '../../modules/Checkbox'
import Radio from '../../addons/Radio'

/**
* A field is a form element containing a label and an input
* A field is a form element containing a label and an input.
* @see Form
* @see Button
* @see Checkbox
Expand Down Expand Up @@ -103,15 +103,6 @@ FormField._meta = {
name: 'FormField',
parent: 'Form',
type: META.TYPES.COLLECTION,
props: {
width: SUI.WIDTHS,
control: [
'button',
'input',
'select',
'textarea',
],
},
}

FormField.propTypes = {
Expand All @@ -131,16 +122,16 @@ FormField.propTypes = {
*/
control: customPropTypes.some([
PropTypes.func,
PropTypes.oneOf(FormField._meta.props.control),
PropTypes.oneOf(['button', 'input', 'select', 'textarea']),
]),

/** Individual fields may be disabled */
/** Individual fields may be disabled. */
disabled: PropTypes.bool,

/** Individual fields may display an error state */
/** Individual fields may display an error state. */
error: PropTypes.bool,

/** A field can have its label next to instead of above it */
/** A field can have its label next to instead of above it. */
inline: PropTypes.bool,

// Heads Up!
Expand All @@ -167,7 +158,7 @@ FormField.propTypes = {
]),

/** A field can specify its width in grid columns */
width: PropTypes.oneOf(FormField._meta.props.width),
width: PropTypes.oneOf(SUI.WIDTHS),
}

export default FormField
36 changes: 18 additions & 18 deletions src/collections/Form/FormGroup.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import React, { PropTypes } from 'react'
import cx from 'classnames'
import React, { PropTypes } from 'react'

import {
customPropTypes,
getElementType,
getUnhandledProps,
META,
SUI,
useWidthProp,
useKeyOnly,
customPropTypes,
useWidthProp,
} from '../../lib'

/**
* A set of fields can appear grouped together
* A set of fields can appear grouped together.
* @see Form
*/
function FormGroup(props) {
const { children, className, grouped, inline, widths } = props
const {
children,
className,
grouped,
inline,
widths,
} = props

const classes = cx(
useWidthProp(widths, null, true),
useKeyOnly(inline, 'inline'),
useKeyOnly(grouped, 'grouped'),
useKeyOnly(inline, 'inline'),
useWidthProp(widths, null, true),
'fields',
className,
)
Expand All @@ -34,9 +41,6 @@ FormGroup._meta = {
name: 'FormGroup',
parent: 'Form',
type: META.TYPES.COLLECTION,
props: {
widths: [...SUI.WIDTHS, 'equal'],
},
}

FormGroup.propTypes = {
Expand All @@ -49,24 +53,20 @@ FormGroup.propTypes = {
/** Additional classes. */
className: PropTypes.string,

/** Fields can show related choices */
/** Fields can show related choices. */
grouped: customPropTypes.every([
customPropTypes.disallow(['inline']),
PropTypes.bool,
]),

/** Multiple fields may be inline in a row */
/** Multiple fields may be inline in a row. */
inline: customPropTypes.every([
customPropTypes.disallow(['grouped']),
PropTypes.bool,
]),

/** Fields Groups can specify their width in grid columns or automatically divide fields to be equal width */
widths: PropTypes.oneOf(FormGroup._meta.props.widths),
}

FormGroup.defaultProps = {
as: 'div',
/** Fields Groups can specify their width in grid columns or automatically divide fields to be equal width. */
widths: PropTypes.oneOf([...SUI.WIDTHS, 'equal']),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ElementType is div by default.

}

export default FormGroup
5 changes: 2 additions & 3 deletions src/collections/Form/FormInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
META,
} from '../../lib'
import Input from '../../elements/Input'

import FormField from './FormField'

/**
* Sugar for <Form.Field control={Input} />
* Sugar for <Form.Field control={Input} />.
* @see Form
* @see Input
*/
Expand All @@ -33,7 +32,7 @@ FormInput.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** A FormField control prop */
/** A FormField control prop. */
control: FormField.propTypes.control,
}

Expand Down
5 changes: 2 additions & 3 deletions src/collections/Form/FormRadio.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
META,
} from '../../lib'
import Radio from '../../addons/Radio'

import FormField from './FormField'

/**
* Sugar for <Form.Field control={Radio} />
* Sugar for <Form.Field control={Radio} />.
* @see Form
* @see Radio
*/
Expand All @@ -33,7 +32,7 @@ FormRadio.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** A FormField control prop */
/** A FormField control prop. */
control: FormField.propTypes.control,
}

Expand Down
5 changes: 2 additions & 3 deletions src/collections/Form/FormSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
META,
} from '../../lib'
import Select from '../../addons/Select'

import FormField from './FormField'

/**
* Sugar for <Form.Field control={Select} />
* Sugar for <Form.Field control={Select} />.
* @see Form
* @see Select
*/
Expand All @@ -33,7 +32,7 @@ FormSelect.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** A FormField control prop */
/** A FormField control prop. */
control: FormField.propTypes.control,
}

Expand Down
Loading