Skip to content

Commit

Permalink
feat(shorthand): Custom shorthand proptypes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcarbs committed Oct 5, 2016
1 parent 661cf35 commit fafbb24
Show file tree
Hide file tree
Showing 108 changed files with 557 additions and 1,067 deletions.
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,10 @@ Label.propTypes = {
/** A label can reduce its complexity. */
basic: PropTypes.bool,
/** Primary content of the label, same as text. */
/** Primary content. */
children: PropTypes.node,
/** Classes to add to the label className. */
/** Additional classes. */
className: PropTypes.string,
/** Color of the label. */
Expand Down
2 changes: 1 addition & 1 deletion src/addons/Confirm/Confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Confirm.propTypes = {
/** The ModalHeader text */
header: PropTypes.string,

/** The ModalContent text. Mutually exclusive with children. */
/** The ModalContent text. */
content: PropTypes.string,

/** Called when the OK button is clicked */
Expand Down
4 changes: 2 additions & 2 deletions src/addons/Portal/Portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const _meta = {
*/
class Portal extends Component {
static propTypes = {
/** Primary content */
/** Primary content. */
children: PropTypes.node.isRequired,

/** Classes to be added to the portal node element. */
/** Additional classes. */
className: PropTypes.string,

/** Controls whether or not the portal should close on a click outside. */
Expand Down
17 changes: 3 additions & 14 deletions src/addons/Select/Select.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { PropTypes } from 'react'
import React from 'react'

import { getUnhandledProps, META } from '../../lib'
import { META } from '../../lib'
import Dropdown from '../../modules/Dropdown'

/**
Expand All @@ -9,23 +9,12 @@ import Dropdown from '../../modules/Dropdown'
* @see Form
*/
function Select(props) {
const { selection } = props
const rest = getUnhandledProps(Select, props)
return <Dropdown {...rest} selection={selection} />
return <Dropdown {...props} selection />
}

Select._meta = {
name: 'Select',
type: META.TYPES.ADDON,
}

Select.propTypes = {
/** selection value */
selection: PropTypes.bool,
}

Select.defaultProps = {
selection: true,
}

export default Select
28 changes: 12 additions & 16 deletions src/collections/Breadcrumb/Breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ function Breadcrumb(props) {
const rest = getUnhandledProps(Breadcrumb, props)
const ElementType = getElementType(Breadcrumb, props)

if (!sections) return <ElementType {...rest} className={classes}>{children}</ElementType>
if (children) {
return <ElementType {...rest} className={classes}>{children}</ElementType>
}

const dividerJSX = <BreadcrumbDivider icon={icon}>{divider}</BreadcrumbDivider>
const sectionsJSX = []

sections.forEach(({ text, key, ...restSection }, index) => {
_.each(sections, ({ text, key, ...restSection }, index) => {
const finalKey = key || text
const dividerKey = `${finalKey}-divider`

Expand Down Expand Up @@ -55,33 +57,27 @@ Breadcrumb.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** Primary content of the Breadcrumb */
children: customPropTypes.every([
customPropTypes.disallow(['sections', 'icon', 'divider']),
PropTypes.node,
]),
/** Primary content. */
children: PropTypes.node,

/** Classes that will be added to the Breadcrumb className. */
/** Additional classes. */
className: PropTypes.string,

/** For use with the sections prop. Primary content of the Breadcrumb.Divider. */
/** Shorthand for primary content of the Breadcrumb.Divider. */
divider: customPropTypes.every([
customPropTypes.disallow(['icon']),
PropTypes.string,
customPropTypes.content,
]),

/** For use with the sections prop. Render as an `Icon` component with `divider` class instead of a `div` in
* Breadcrumb.Divider. */
icon: customPropTypes.every([
customPropTypes.disallow(['divider']),
PropTypes.node,
customPropTypes.item,
]),

/** Array of props for Breadcrumb.Section. */
sections: customPropTypes.every([
customPropTypes.disallow(['children']),
React.PropTypes.array,
]),
/** Shorthand array of props for Breadcrumb.Section. */
sections: customPropTypes.items,

/** Size of Breadcrumb */
size: PropTypes.oneOf(Breadcrumb._meta.props.size),
Expand Down
14 changes: 4 additions & 10 deletions src/collections/Breadcrumb/BreadcrumbDivider.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,14 @@ BreadcrumbDivider.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** Primary content of the Breadcrumb.Divider. */
children: customPropTypes.every([
customPropTypes.disallow(['icon']),
PropTypes.node,
]),
/** Primary content. */
children: PropTypes.node,

/** Classes that will be added to the BreadcrumbDivider className. */
/** Additional classes. */
className: PropTypes.string,

/** Render as an `Icon` component with `divider` class instead of a `div`. */
icon: customPropTypes.every([
customPropTypes.disallow(['children']),
PropTypes.node,
]),
icon: customPropTypes.item,
}

export default BreadcrumbDivider
4 changes: 2 additions & 2 deletions src/collections/Breadcrumb/BreadcrumbSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export default class BreadcrumbSection extends Component {
/** Style as the currently active section. */
active: PropTypes.bool,

/** Primary content of the Breadcrumb.Section. */
/** Primary content. */
children: PropTypes.node,

/** Classes that will be added to the BreadcrumbSection className. */
/** Additional classes. */
className: PropTypes.string,

/** Render as an `a` tag instead of a `div`. */
Expand Down
4 changes: 2 additions & 2 deletions src/collections/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ export default class Form extends Component {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** Primary content */
/** Primary content. */
children: PropTypes.node,

/** Additional classes */
/** Additional classes. */
className: PropTypes.string,

/** Automatically show any error Message children */
Expand Down
4 changes: 2 additions & 2 deletions src/collections/Form/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ FormField.propTypes = {
PropTypes.oneOf(FormField._meta.props.control),
]),

/** Primary content */
/** Primary content. */
children: PropTypes.node,

/** Additional classes to add */
/** Additional classes. */
className: PropTypes.string,

/** Individual fields may be disabled */
Expand Down
4 changes: 2 additions & 2 deletions src/collections/Form/FormGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ FormGroup.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** Primary content. Intended to be Form Fields. */
/** Primary content. */
children: PropTypes.node,

/** Additional classes */
/** Additional classes. */
className: PropTypes.string,

/** Fields can show related choices */
Expand Down
4 changes: 2 additions & 2 deletions src/collections/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ Grid.propTypes = {
/** A grid can have its columns centered. */
centered: PropTypes.bool,

/** Primary content of the Grid. */
/** Primary content. */
children: PropTypes.node,

/** Classes that will be added to the Grid className. */
/** Additional classes. */
className: PropTypes.string,

/** Represents column count per row in Grid. */
Expand Down
4 changes: 2 additions & 2 deletions src/collections/Grid/GridColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ GridColumn.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** Primary content of the GridColumn. */
/** Primary content. */
children: PropTypes.node,

/** Classes that will be added to the GridColumn className. */
/** Additional classes. */
className: PropTypes.string,

/** A column can specify a width for a computer. */
Expand Down
4 changes: 2 additions & 2 deletions src/collections/Grid/GridRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ GridRow.propTypes = {
/** A row can have its columns centered. */
centered: PropTypes.bool,

/** Primary content of the GridRow. */
/** Primary content. */
children: PropTypes.node,

/** Classes that will be added to the GridRow className. */
/** Additional classes. */
className: PropTypes.string,

/** A grid row can be colored. */
Expand Down
16 changes: 4 additions & 12 deletions src/collections/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class Menu extends Component {
/** A menu item or menu can have no borders. */
borderless: PropTypes.bool,

/** Primary content of the Menu. Mutually exclusive with items. */
/** Primary content. */
children: PropTypes.node,

/** Classes that will be added to the Menu className. */
/** Additional classes. */
className: PropTypes.string,

/** Additional colors can be specified. */
Expand Down Expand Up @@ -90,16 +90,8 @@ class Menu extends Component {
/** A menu may have its colors inverted to show greater contrast. */
inverted: PropTypes.bool,

/** Shorthand array of props for Menu. Mutually exclusive with children. */
items: customPropTypes.every([
customPropTypes.disallow(['children']),
// Array of shorthands for MenuItem
PropTypes.arrayOf(PropTypes.oneOfType([
PropTypes.string,
PropTypes.element,
PropTypes.object,
])),
]),
/** Shorthand array of props for Menu. */
items: customPropTypes.items,

/** onClick handler for MenuItem. Mutually exclusive with children. */
onItemClick: customPropTypes.every([
Expand Down
11 changes: 4 additions & 7 deletions src/collections/Menu/MenuHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ MenuHeader.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** Primary content */
/** Primary content. */
children: PropTypes.node,

/** Additional classes */
/** Additional classes. */
className: PropTypes.string,

/** Shorthand for primary content */
content: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
]),
/** Shorthand for primary content. */
content: customPropTypes.content,
}

export default MenuHeader
16 changes: 5 additions & 11 deletions src/collections/Menu/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,17 @@ export default class MenuItem extends Component {
/** A menu item can be active. */
active: PropTypes.bool,

/** Primary content of the MenuItem. */
children: customPropTypes.every([
customPropTypes.disallow(['content']),
PropTypes.node,
]),
/** Primary content. */
children: PropTypes.node,

/** Classes that will be added to the MenuItem className. */
/** Additional classes. */
className: PropTypes.string,

/** Additional colors can be specified. */
color: PropTypes.oneOf(_meta.props.color),

/** Shorthand for primary content of the MenuItem. Mutually exclusive with the children. */
content: customPropTypes.every([
customPropTypes.disallow(['children']),
PropTypes.string,
]),
/** Shorthand for primary content. */
content: customPropTypes.content,

/** A menu item or menu can remove element padding, vertically or horizontally. */
fitted: PropTypes.oneOfType([
Expand Down
4 changes: 2 additions & 2 deletions src/collections/Menu/MenuMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ MenuMenu.propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** Primary content of the MenuMenu. */
/** Primary content. */
children: PropTypes.node,

/** Classes that will be added to the MenuMenu className. */
/** Additional classes. */
className: PropTypes.string,

/** A sub menu can take right position. */
Expand Down
Loading

0 comments on commit fafbb24

Please sign in to comment.