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(List): update typings and remove propTypes #1270

Merged
merged 1 commit into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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/elements/Icon/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {SemanticCOLORS, SemanticROTATION} from '../..';

type ICON_SIZES = 'mini' | 'tiny' | 'small' | 'large' | 'big' | 'huge' | 'massive';

interface IconProps {
export interface IconProps {
[key: string]: any;

/** An element type to render as (string or function). */
Expand Down
20 changes: 7 additions & 13 deletions src/elements/List/List.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, { PropTypes } from 'react'

import {
Expand All @@ -21,7 +21,7 @@ import ListItem from './ListItem'
import ListList from './ListList'

/**
* A list groups related content
* A list groups related content.
*/
function List(props) {
const {
Expand All @@ -38,8 +38,8 @@ function List(props) {
link,
ordered,
relaxed,
size,
selection,
size,
verticalAlign,
} = props

Expand Down Expand Up @@ -78,12 +78,6 @@ function List(props) {
List._meta = {
name: 'List',
type: META.TYPES.ELEMENT,
props: {
floated: SUI.FLOATS,
relaxed: ['very'],
size: SUI.SIZES,
verticalAlign: SUI.VERTICAL_ALIGNMENTS,
},
}

List.propTypes = {
Expand All @@ -109,7 +103,7 @@ List.propTypes = {
divided: PropTypes.bool,

/** An list can be floated left or right. */
floated: PropTypes.oneOf(List._meta.props.floated),
floated: PropTypes.oneOf(SUI.FLOATS),

/** A list can be formatted to have items appear horizontally. */
horizontal: PropTypes.bool,
Expand All @@ -129,17 +123,17 @@ List.propTypes = {
/** A list can relax its padding to provide more negative space. */
relaxed: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.oneOf(List._meta.props.relaxed),
PropTypes.oneOf(['very']),
]),

/** A selection list formats list items as possible choices. */
selection: PropTypes.bool,

/** A list can vary in size. */
size: PropTypes.oneOf(List._meta.props.size),
size: PropTypes.oneOf(SUI.SIZES),

/** An element inside a list can be vertically aligned. */
verticalAlign: PropTypes.oneOf(List._meta.props.verticalAlign),
verticalAlign: PropTypes.oneOf(SUI.VERTICAL_ALIGNMENTS),
}

List.Content = ListContent
Expand Down
14 changes: 6 additions & 8 deletions src/elements/List/ListContent.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, { PropTypes } from 'react'

import {
Expand All @@ -12,10 +12,12 @@ import {
useValueAndKey,
useVerticalAlignProp,
} from '../../lib'

import ListDescription from './ListDescription'
import ListHeader from './ListHeader'

/**
* A list item can contain a content.
*/
function ListContent(props) {
const {
children,
Expand Down Expand Up @@ -53,10 +55,6 @@ ListContent._meta = {
name: 'ListContent',
parent: 'List',
type: META.TYPES.ELEMENT,
props: {
floated: SUI.FLOATS,
verticalAlign: SUI.VERTICAL_ALIGNMENTS,
},
}

ListContent.propTypes = {
Expand All @@ -76,13 +74,13 @@ ListContent.propTypes = {
description: customPropTypes.itemShorthand,

/** An list content can be floated left or right. */
floated: PropTypes.oneOf(ListContent._meta.props.floated),
floated: PropTypes.oneOf(SUI.FLOATS),

/** Shorthand for ListHeader. */
header: customPropTypes.itemShorthand,

/** An element inside a list can be vertically aligned. */
verticalAlign: PropTypes.oneOf(ListContent._meta.props.verticalAlign),
verticalAlign: PropTypes.oneOf(SUI.VERTICAL_ALIGNMENTS),
}

ListContent.create = createShorthandFactory(ListContent, content => ({ content }))
Expand Down
11 changes: 9 additions & 2 deletions src/elements/List/ListDescription.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, { PropTypes } from 'react'

import {
Expand All @@ -10,13 +10,20 @@ import {
META,
} from '../../lib'

/**
* A list item can contain a description.
*/
function ListDescription(props) {
const { children, className, content } = props
const classes = cx(className, 'description')
const rest = getUnhandledProps(ListDescription, props)
const ElementType = getElementType(ListDescription, props)

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

ListDescription._meta = {
Expand Down
13 changes: 10 additions & 3 deletions src/elements/List/ListHeader.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, { PropTypes } from 'react'

import {
Expand All @@ -10,13 +10,20 @@ import {
META,
} from '../../lib'

/**
* A list item can contain a header.
*/
function ListHeader(props) {
const { children, className, content } = props
const classes = cx(className, 'header')
const classes = cx('header', className)
const rest = getUnhandledProps(ListHeader, props)
const ElementType = getElementType(ListHeader, props)

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

ListHeader._meta = {
Expand Down
8 changes: 4 additions & 4 deletions src/elements/List/ListIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
} from '../../lib'
import Icon from '../Icon/Icon'

/**
* A list item can contain an icon.
*/
function ListIcon(props) {
const { className, verticalAlign } = props
const classes = cx(
Expand All @@ -25,17 +28,14 @@ ListIcon._meta = {
name: 'ListIcon',
parent: 'List',
type: META.TYPES.ELEMENT,
props: {
verticalAlign: SUI.VERTICAL_ALIGNMENTS,
},
}

ListIcon.propTypes = {
/** Additional classes. */
className: PropTypes.string,

/** An element inside a list can be vertically aligned. */
verticalAlign: PropTypes.oneOf(ListIcon._meta.props.verticalAlign),
verticalAlign: PropTypes.oneOf(SUI.VERTICAL_ALIGNMENTS),
}

ListIcon.create = createShorthandFactory(ListIcon, name => ({ name }))
Expand Down
13 changes: 8 additions & 5 deletions src/elements/List/ListItem.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, { isValidElement, PropTypes } from 'react'

import {
Expand All @@ -17,6 +17,9 @@ import ListDescription from './ListDescription'
import ListHeader from './ListHeader'
import ListIcon from './ListIcon'

/**
* A list item can contain a set of items.
*/
function ListItem(props) {
const {
active,
Expand All @@ -42,7 +45,7 @@ function ListItem(props) {
const valueProp = ElementType === 'li' ? { value } : { 'data-value': value }

if (!_.isNil(children)) {
return <ElementType {...rest} role='listitem' className={classes} {...valueProp}>{children}</ElementType>
return <ElementType {...rest} {...valueProp} role='listitem' className={classes}>{children}</ElementType>
}

const iconElement = ListIcon.create(icon)
Expand All @@ -51,7 +54,7 @@ function ListItem(props) {
// See description of `content` prop for explanation about why this is necessary.
if (!isValidElement(content) && _.isPlainObject(content)) {
return (
<ElementType {...rest} role='listitem' className={classes} {...valueProp}>
<ElementType {...rest} {...valueProp} role='listitem' className={classes}>
{iconElement || imageElement}
{ListContent.create(content, { header, description })}
</ElementType>
Expand All @@ -63,7 +66,7 @@ function ListItem(props) {

if (iconElement || imageElement) {
return (
<ElementType {...rest} role='listitem' className={classes} {...valueProp}>
<ElementType {...rest} {...valueProp} role='listitem' className={classes}>
{iconElement || imageElement}
{(content || headerElement || descriptionElement) && (
<ListContent>
Expand All @@ -77,7 +80,7 @@ function ListItem(props) {
}

return (
<ElementType {...rest} role='listitem' className={classes} {...valueProp}>
<ElementType {...rest} {...valueProp} role='listitem' className={classes}>
{headerElement}
{descriptionElement}
{content}
Expand Down
3 changes: 3 additions & 0 deletions src/elements/List/ListList.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
useKeyOnly,
} from '../../lib'

/**
* A list can contain a sub list.
*/
function ListList(props) {
const { children, className } = props

Expand Down
Loading