Skip to content

Commit

Permalink
test(mixed): add test for content prop, remove useless tests (#2144)
Browse files Browse the repository at this point in the history
* breaking(Statistic): refactor Statistic to use factories, update content props

* test(mixed): add test for `content` prop, remove useless tests

* breaking(Step): refactor Step to use factories, update content props, add missing props

* test(mixed): add test for `content` prop, remove useless tests

* test(mixed): add test for `content` prop, remove useless tests

* style(mixed): remove TODOs, style fixes
  • Loading branch information
layershifter authored and levithomason committed Oct 16, 2017
1 parent c276f35 commit b9086d3
Show file tree
Hide file tree
Showing 149 changed files with 754 additions and 380 deletions.
4 changes: 4 additions & 0 deletions src/collections/Form/FormField.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import {
HtmlLabelProps,
SemanticShorthandContent,
SemanticShorthandItem,
SemanticWIDTHS
} from '../..';
Expand All @@ -17,6 +18,9 @@ export interface FormFieldProps {
/** Additional classes. */
className?: string;

/** Shorthand for primary content. */
content?: SemanticShorthandContent;

/**
* A form control component (i.e. Dropdown) or HTML tagName (i.e. 'input').
* Extra FormField props are passed to the control component.
Expand Down
13 changes: 12 additions & 1 deletion src/collections/Form/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
import React, { createElement } from 'react'

import {
childrenUtils,
createHTMLLabel,
customPropTypes,
getElementType,
Expand Down Expand Up @@ -31,6 +32,7 @@ function FormField(props) {
const {
children,
className,
content,
control,
disabled,
error,
Expand Down Expand Up @@ -58,7 +60,13 @@ function FormField(props) {
// ----------------------------------------

if (_.isNil(control)) {
if (_.isNil(label)) return <ElementType {...rest} className={classes}>{children}</ElementType>
if (_.isNil(label)) {
return (
<ElementType {...rest} className={classes}>
{childrenUtils.isNil(children) ? content : children}
</ElementType>
)
}

return <ElementType {...rest} className={classes}>{createHTMLLabel(label)}</ElementType>
}
Expand Down Expand Up @@ -118,6 +126,9 @@ FormField.propTypes = {
/** Additional classes. */
className: PropTypes.string,

/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,

/**
* A form control component (i.e. Dropdown) or HTML tagName (i.e. 'input').
* Extra FormField props are passed to the control component.
Expand Down
2 changes: 1 addition & 1 deletion src/collections/Menu/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class MenuItem extends Component {
return (
<ElementType {...rest} className={classes} onClick={this.handleClick}>
{Icon.create(icon)}
{content || _.startCase(name)}
{childrenUtils.isNil(content) ? _.startCase(name) : content}
</ElementType>
)
}
Expand Down
4 changes: 4 additions & 0 deletions src/collections/Menu/MenuMenu.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { SemanticShorthandContent } from '../..';

export interface MenuMenuProps {
[key: string]: any;
Expand All @@ -12,6 +13,9 @@ export interface MenuMenuProps {
/** Additional classes. */
className?: string;

/** Shorthand for primary content. */
content?: SemanticShorthandContent;

/** A sub menu can take left or right position. */
position?: 'left' | 'right';
}
Expand Down
12 changes: 10 additions & 2 deletions src/collections/Menu/MenuMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import React from 'react'

import {
childrenUtils,
customPropTypes,
getElementType,
getUnhandledProps,
Expand All @@ -13,7 +14,7 @@ import {
* A menu can contain a sub menu.
*/
function MenuMenu(props) {
const { children, className, position } = props
const { children, className, content, position } = props

const classes = cx(
position,
Expand All @@ -23,7 +24,11 @@ function MenuMenu(props) {
const rest = getUnhandledProps(MenuMenu, props)
const ElementType = getElementType(MenuMenu, props)

return <ElementType {...rest} className={classes}>{children}</ElementType>
return (
<ElementType {...rest} className={classes}>
{childrenUtils.isNil(children) ? content : children}
</ElementType>
)
}

MenuMenu._meta = {
Expand All @@ -42,6 +47,9 @@ MenuMenu.propTypes = {
/** Additional classes. */
className: PropTypes.string,

/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,

/** A sub menu can take left or right position. */
position: PropTypes.oneOf(['left', 'right']),
}
Expand Down
4 changes: 4 additions & 0 deletions src/collections/Message/MessageContent.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { SemanticShorthandContent } from '../..';

export interface MessageContentProps {
[key: string]: any;
Expand All @@ -11,6 +12,9 @@ export interface MessageContentProps {

/** Additional classes. */
className?: string;

/** Shorthand for primary content. */
content?: SemanticShorthandContent;
}

declare const MessageContent: React.StatelessComponent<MessageContentProps>;
Expand Down
12 changes: 10 additions & 2 deletions src/collections/Message/MessageContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import React from 'react'

import {
childrenUtils,
customPropTypes,
getElementType,
getUnhandledProps,
Expand All @@ -13,12 +14,16 @@ import {
* A message can contain a content.
*/
function MessageContent(props) {
const { children, className } = props
const { children, className, content } = props
const classes = cx('content', className)
const rest = getUnhandledProps(MessageContent, props)
const ElementType = getElementType(MessageContent, props)

return <ElementType {...rest} className={classes}>{children}</ElementType>
return (
<ElementType {...rest} className={classes}>
{childrenUtils.isNil(children) ? content : children}
</ElementType>
)
}

MessageContent._meta = {
Expand All @@ -36,6 +41,9 @@ MessageContent.propTypes = {

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

/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,
}

export default MessageContent
4 changes: 4 additions & 0 deletions src/collections/Table/TableHeader.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { SemanticShorthandContent } from '../..';

export interface TableHeaderProps {
[key: string]: any;
Expand All @@ -12,6 +13,9 @@ export interface TableHeaderProps {
/** Additional classes. */
className?: string;

/** Shorthand for primary content. */
content?: SemanticShorthandContent;

/** A definition table can have a full width header or footer, filling in the gap left by the first column. */
fullWidth?: boolean;
}
Expand Down
12 changes: 10 additions & 2 deletions src/collections/Table/TableHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import React from 'react'

import {
childrenUtils,
customPropTypes,
getElementType,
getUnhandledProps,
Expand All @@ -14,15 +15,19 @@ import {
* A table can have a header.
*/
function TableHeader(props) {
const { children, className, fullWidth } = props
const { children, className, content, fullWidth } = props
const classes = cx(
useKeyOnly(fullWidth, 'full-width'),
className,
)
const rest = getUnhandledProps(TableHeader, props)
const ElementType = getElementType(TableHeader, props)

return <ElementType {...rest} className={classes}>{children}</ElementType>
return (
<ElementType {...rest} className={classes}>
{childrenUtils.isNil(children) ? content : children}
</ElementType>
)
}

TableHeader._meta = {
Expand All @@ -45,6 +50,9 @@ TableHeader.propTypes = {
/** Additional classes. */
className: PropTypes.string,

/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,

/** A definition table can have a full width header or footer, filling in the gap left by the first column. */
fullWidth: PropTypes.bool,
}
Expand Down
4 changes: 4 additions & 0 deletions src/elements/Button/ButtonContent.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { SemanticShorthandContent } from '../..';

export interface ButtonContentProps {
[key: string]: any;
Expand All @@ -12,6 +13,9 @@ export interface ButtonContentProps {
/** Additional classes. */
className?: string;

/** Shorthand for primary content. */
content?: SemanticShorthandContent;

/** Initially hidden, visible on hover. */
hidden?: boolean;

Expand Down
11 changes: 10 additions & 1 deletion src/elements/Button/ButtonContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import React from 'react'

import {
childrenUtils,
customPropTypes,
getElementType,
getUnhandledProps,
Expand All @@ -17,6 +18,7 @@ function ButtonContent(props) {
const {
children,
className,
content,
hidden,
visible,
} = props
Expand All @@ -29,7 +31,11 @@ function ButtonContent(props) {
const rest = getUnhandledProps(ButtonContent, props)
const ElementType = getElementType(ButtonContent, props)

return <ElementType {...rest} className={classes}>{children}</ElementType>
return (
<ElementType {...rest} className={classes}>
{childrenUtils.isNil(children) ? content : children}
</ElementType>
)
}

ButtonContent._meta = {
Expand All @@ -48,6 +54,9 @@ ButtonContent.propTypes = {
/** Additional classes. */
className: PropTypes.string,

/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,

/** Initially hidden, visible on hover. */
hidden: PropTypes.bool,

Expand Down
4 changes: 4 additions & 0 deletions src/elements/Button/ButtonGroup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import {
SemanticCOLORS,
SemanticFLOATS,
SemanticShorthandContent,
SemanticSIZES,
SemanticWIDTHS
} from '../..';
Expand Down Expand Up @@ -30,6 +31,9 @@ export interface ButtonGroupProps {
/** Groups can reduce their padding to fit into tighter spaces. */
compact?: boolean;

/** Shorthand for primary content. */
content?: SemanticShorthandContent;

/** Groups can be aligned to the left or right of its container. */
floated?: SemanticFLOATS;

Expand Down
11 changes: 10 additions & 1 deletion src/elements/Button/ButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import React from 'react'

import {
childrenUtils,
customPropTypes,
getElementType,
getUnhandledProps,
Expand All @@ -25,6 +26,7 @@ function ButtonGroup(props) {
className,
color,
compact,
content,
floated,
fluid,
icon,
Expand Down Expand Up @@ -65,7 +67,11 @@ function ButtonGroup(props) {
const rest = getUnhandledProps(ButtonGroup, props)
const ElementType = getElementType(ButtonGroup, props)

return <ElementType {...rest} className={classes}>{children}</ElementType>
return (
<ElementType {...rest} className={classes}>
{childrenUtils.isNil(children) ? content : children}
</ElementType>
)
}

ButtonGroup._meta = {
Expand Down Expand Up @@ -99,6 +105,9 @@ ButtonGroup.propTypes = {
/** Groups can reduce their padding to fit into tighter spaces. */
compact: PropTypes.bool,

/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,

/** Groups can be aligned to the left or right of its container. */
floated: PropTypes.oneOf(SUI.FLOATS),

Expand Down
5 changes: 4 additions & 1 deletion src/elements/Container/Container.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { SemanticTEXTALIGNMENTS } from '../..';
import { SemanticShorthandContent, SemanticTEXTALIGNMENTS } from '../..';

export interface ContainerProps {
[key: string]: any;
Expand All @@ -13,6 +13,9 @@ export interface ContainerProps {
/** Additional classes. */
className?: string;

/** Shorthand for primary content. */
content?: SemanticShorthandContent;

/** Container has no maximum width. */
fluid?: boolean;

Expand Down
Loading

0 comments on commit b9086d3

Please sign in to comment.