Skip to content

Commit

Permalink
refactor(Feed): update to refactored utils
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Aug 13, 2016
1 parent 1d31612 commit 51da3e3
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 119 deletions.
2 changes: 1 addition & 1 deletion src/collections/Message/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function Message(props) {
return (
<div {...rest} className={classes}>
{dismissIcon}
{icon && createIcon(icon)}
{createIcon(icon)}
{(header || content || list) && (
<MessageContent>
{header && <MessageHeader>{header}</MessageHeader>}
Expand Down
27 changes: 15 additions & 12 deletions src/views/Feed/Feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import _ from 'lodash'
import cx from 'classnames'
import React, { PropTypes } from 'react'

import META from '../../utils/Meta'
import { customPropTypes, getUnhandledProps } from '../../utils/propUtils'
import * as sui from '../../utils/semanticUtils'
import {
customPropTypes,
getUnhandledProps,
META,
SUI,
} from '../../lib'
import FeedContent from './FeedContent'
import FeedDate from './FeedDate'
import FeedEvent from './FeedEvent'
Expand All @@ -24,8 +27,8 @@ function Feed(props) {
return <div {...rest} className={classes}>{children}</div>
}

const eventsJSX = events.map(({ key, ...eventData }, index) => {
const finalKey = key || index
const eventsJSX = events.map(({ childKey, ...eventData }, index) => {
const finalKey = childKey || index

return <FeedEvent key={finalKey} {...eventData} />
})
Expand All @@ -35,27 +38,27 @@ function Feed(props) {

Feed._meta = {
name: 'Feed',
type: META.type.view,
type: META.TYPES.VIEW,
props: {
size: _.without(sui.sizes, 'mini', 'tiny', 'medium', 'big', 'huge', 'massive'),
size: _.without(SUI.SIZES, 'mini', 'tiny', 'medium', 'big', 'huge', 'massive'),
},
}

Feed.propTypes = {
/** Primary content of the Feed. */
children: customPropTypes.all([
customPropTypes.mutuallyExclusive(['events']),
children: customPropTypes.every([
customPropTypes.disallow(['events']),
PropTypes.node,
]),

/** Classes that will be added to the Feed className. */
className: PropTypes.string,

/** Array of props for FeedEvent. */
events: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
events: customPropTypes.every([
customPropTypes.disallow(['children']),
PropTypes.arrayOf(PropTypes.shape({
key: PropTypes.string,
childKey: PropTypes.string,
date: PropTypes.string,
image: PropTypes.node,
icon: PropTypes.node,
Expand Down
25 changes: 14 additions & 11 deletions src/views/Feed/FeedContent.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import cx from 'classnames'
import React, { PropTypes } from 'react'

import META from '../../utils/Meta'
import { customPropTypes, getUnhandledProps } from '../../utils/propUtils'
import {
customPropTypes,
getUnhandledProps,
META,
} from '../../lib'
import FeedDate from './FeedDate'
import FeedExtra from './FeedExtra'
import FeedMeta from './FeedMeta'
Expand All @@ -28,37 +31,37 @@ function FeedContent(props) {
FeedContent._meta = {
name: 'FeedContent',
parent: 'Feed',
type: META.type.view,
type: META.TYPES.VIEW,
}

FeedContent.propTypes = {
/** Primary content of the FeedContent. */
children: customPropTypes.all([
customPropTypes.mutuallyExclusive(['content']),
children: customPropTypes.every([
customPropTypes.disallow(['content']),
PropTypes.node,
]),

/** Classes that will be added to the FeedContent className. */
className: PropTypes.string,

/** Primary content of the FeedContent. Mutually exclusive with children. */
content: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
content: customPropTypes.every([
customPropTypes.disallow(['children']),
PropTypes.string,
]),

/** An event can contain a date. */
date: PropTypes.string,

/** Shorthand for FeedExtra with prop images. */
extraImages: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'content']),
extraImages: customPropTypes.every([
customPropTypes.disallow(['children', 'content']),
PropTypes.arrayOf(PropTypes.string),
]),

/** Shorthand for FeedExtra with prop text. */
extraText: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'content']),
extraText: customPropTypes.every([
customPropTypes.disallow(['children', 'content']),
PropTypes.string,
]),

Expand Down
17 changes: 10 additions & 7 deletions src/views/Feed/FeedDate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import cx from 'classnames'
import React, { PropTypes } from 'react'

import META from '../../utils/Meta'
import { customPropTypes, getUnhandledProps } from '../../utils/propUtils'
import {
customPropTypes,
getUnhandledProps,
META,
} from '../../lib'

function FeedDate(props) {
const { children, className, date } = props
Expand All @@ -15,22 +18,22 @@ function FeedDate(props) {
FeedDate._meta = {
name: 'FeedDate',
parent: 'Feed',
type: META.type.view,
type: META.TYPES.VIEW,
}

FeedDate.propTypes = {
/** Primary content of the FeedDate. Mutually exclusive with the date prop. */
children: customPropTypes.all([
customPropTypes.mutuallyExclusive(['date']),
children: customPropTypes.every([
customPropTypes.disallow(['date']),
PropTypes.node,
]),

/** Classes that will be added to the FeedDate className. */
className: PropTypes.string,

/** Shorthand for primary content of the FeedDate. Mutually exclusive with the children prop. */
date: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
date: customPropTypes.every([
customPropTypes.disallow(['children']),
PropTypes.string,
]),
}
Expand Down
37 changes: 20 additions & 17 deletions src/views/Feed/FeedEvent.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import cx from 'classnames'
import React, { PropTypes } from 'react'

import META from '../../utils/Meta'
import { customPropTypes, getUnhandledProps } from '../../utils/propUtils'
import {
customPropTypes,
getUnhandledProps,
META,
} from '../../lib'
import FeedContent from './FeedContent'
import FeedLabel from './FeedLabel'

Expand All @@ -25,40 +28,40 @@ function FeedEvent(props) {
FeedEvent._meta = {
name: 'FeedEvent',
parent: 'Feed',
type: META.type.view,
type: META.TYPES.VIEW,
}

FeedEvent.propTypes = {
/** Primary content of the FeedEvent. */
children: customPropTypes.all([
customPropTypes.mutuallyExclusive(['content', 'date', 'extraImages', 'extraText', 'meta', 'summary']),
children: customPropTypes.every([
customPropTypes.disallow(['content', 'date', 'extraImages', 'extraText', 'meta', 'summary']),
PropTypes.node,
]),

/** Classes that will be added to the FeedEvent className. */
className: PropTypes.string,

/** Shorthand for FeedContent. */
content: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'date', 'extraImages', 'extraText', 'meta', 'summary']),
content: customPropTypes.every([
customPropTypes.disallow(['children', 'date', 'extraImages', 'extraText', 'meta', 'summary']),
PropTypes.string,
]),

/** Shorthand for FeedDate. */
date: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'content']),
date: customPropTypes.every([
customPropTypes.disallow(['children', 'content']),
PropTypes.string,
]),

/** Shorthand for FeedExtra with prop images. */
extraImages: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'content']),
extraImages: customPropTypes.every([
customPropTypes.disallow(['children', 'content']),
PropTypes.arrayOf(PropTypes.node),
]),

/** Shorthand for FeedExtra with prop text. */
extraText: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'content']),
extraText: customPropTypes.every([
customPropTypes.disallow(['children', 'content']),
PropTypes.string,
]),

Expand All @@ -69,14 +72,14 @@ FeedEvent.propTypes = {
image: PropTypes.node,

/** Shorthand for FeedMeta. */
meta: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'content']),
meta: customPropTypes.every([
customPropTypes.disallow(['children', 'content']),
PropTypes.string,
]),

/** Shorthand for FeedSummary. */
summary: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'content']),
summary: customPropTypes.every([
customPropTypes.disallow(['children', 'content']),
PropTypes.string,
]),
}
Expand Down
18 changes: 11 additions & 7 deletions src/views/Feed/FeedExtra.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import _ from 'lodash'
import cx from 'classnames'
import React, { PropTypes } from 'react'

import META from '../../utils/Meta'
import { customPropTypes, getUnhandledProps, useKeyOnly } from '../../utils/propUtils'
import {
customPropTypes,
getUnhandledProps,
META,
useKeyOnly,
} from '../../lib'

function FeedExtra(props) {
const { children, className, images, text } = props
Expand All @@ -29,7 +33,7 @@ function FeedExtra(props) {
FeedExtra._meta = {
name: 'FeedExtra',
parent: 'Feed',
type: META.type.view,
type: META.TYPES.VIEW,
}

FeedExtra.propTypes = {
Expand All @@ -40,17 +44,17 @@ FeedExtra.propTypes = {
className: PropTypes.string,

/** An event can contain additional information like a set of images. */
images: customPropTypes.all([
customPropTypes.mutuallyExclusive(['text']),
images: customPropTypes.every([
customPropTypes.disallow(['text']),
PropTypes.oneOfType([
PropTypes.bool,
PropTypes.arrayOf(PropTypes.node),
]),
]),

/** An event can contain additional information like a set of images. */
text: customPropTypes.all([
customPropTypes.mutuallyExclusive(['images']),
text: customPropTypes.every([
customPropTypes.disallow(['images']),
PropTypes.oneOfType([
PropTypes.bool,
PropTypes.string,
Expand Down
31 changes: 16 additions & 15 deletions src/views/Feed/FeedLabel.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
import _ from 'lodash'
import cx from 'classnames'
import React, { PropTypes } from 'react'

import META from '../../utils/Meta'
import { customPropTypes, getUnhandledProps, iconPropRenderer } from '../../utils/propUtils'
import {
customPropTypes,
getUnhandledProps,
META,
} from '../../lib'
import { createIcon, createImg } from '../../factories'

function FeedLabel(props) {
const { children, className, icon, image } = props
const classes = cx(className, 'label')
const rest = getUnhandledProps(FeedLabel, props)

const imageJSX = image && (_.isString(image) ? <img src={image} /> : image)

return (
<div {...rest} className={classes}>
{children && children}
{icon && iconPropRenderer(icon)}
{imageJSX}
{children}
{createIcon(icon)}
{createImg(image)}
</div>
)
}

FeedLabel._meta = {
name: 'FeedLabel',
parent: 'Feed',
type: META.type.view,
type: META.TYPES.VIEW,
}

FeedLabel.propTypes = {
/** Primary content of the FeedLabel. */
children: customPropTypes.all([
customPropTypes.mutuallyExclusive(['icon', 'image']),
children: customPropTypes.every([
customPropTypes.disallow(['icon', 'image']),
PropTypes.node,
]),

/** Classes that will be added to the FeedLabel className. */
className: PropTypes.string,

/** An event can contain icon label. */
icon: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'image']),
icon: customPropTypes.every([
customPropTypes.disallow(['children', 'image']),
PropTypes.node,
]),

/** An event can contain image label. */
image: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'icon']),
image: customPropTypes.every([
customPropTypes.disallow(['children', 'icon']),
PropTypes.node,
]),
}
Expand Down
Loading

0 comments on commit 51da3e3

Please sign in to comment.