Skip to content

Commit

Permalink
refactor(Card): update to use refactored utils
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Aug 13, 2016
1 parent 932da94 commit 37877e5
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 52 deletions.
12 changes: 7 additions & 5 deletions src/views/Card/Card.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import cx from 'classnames'
import React, { PropTypes } from 'react'

import META from '../../utils/Meta'
import * as sui from '../../utils/semanticUtils'
import { useKeyOnly } from '../../utils/propUtils'
import {
META,
SUI,
useKeyOnly,
} from '../../lib'
import CardContent from './CardContent'
import CardDescription from './CardDescription'
import CardHeader from './CardHeader'
Expand Down Expand Up @@ -50,9 +52,9 @@ function Card(props) {

Card._meta = {
name: 'Card',
type: META.type.view,
type: META.TYPES.VIEW,
props: {
color: sui.colors,
color: SUI.COLORS,
},
}

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

import META from '../../utils/Meta'
import { customPropTypes, useKeyOnly } from '../../utils/propUtils'
import {
customPropTypes,
META,
useKeyOnly,
} from '../../lib'
import CardDescription from './CardDescription'
import CardHeader from './CardHeader'
import CardMeta from './CardMeta'
Expand All @@ -21,37 +24,46 @@ function CardContent(props) {

return (
<div {...rest} className={classes}>
{header && <CardHeader header={header} />}
{meta && <CardMeta meta={meta} />}
{description && <CardDescription description={description} />}
{header && <CardHeader content={header} />}
{meta && <CardMeta content={meta} />}
{description && <CardDescription content={description} />}
</div>
)
}

CardContent._meta = {
name: 'CardContent',
parent: 'Card',
type: META.type.view,
type: META.TYPES.VIEW,
}

CardContent.propTypes = {
className: PropTypes.string,
children: customPropTypes.all([
customPropTypes.mutuallyExclusive(['description', 'header', 'meta']),
children: customPropTypes.every([
customPropTypes.disallow(['description', 'header', 'meta']),
PropTypes.node,
]),
description: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
PropTypes.node,
description: customPropTypes.every([
customPropTypes.disallow(['children']),
PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
]),
extra: PropTypes.bool,
header: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
PropTypes.node,
header: customPropTypes.every([
customPropTypes.disallow(['children']),
PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
]),
meta: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
PropTypes.node,
meta: customPropTypes.every([
customPropTypes.disallow(['children']),
PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
]),
}

Expand Down
25 changes: 15 additions & 10 deletions src/views/Card/CardDescription.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import cx from 'classnames'
import React, { PropTypes } from 'react'

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

function CardDescription(props) {
const { className, children, description, ...rest } = props
const { className, children, content, ...rest } = props
const classes = cx(className, 'description')

return <div {...rest} className={classes}>{ children || description }</div>
return <div {...rest} className={classes}>{ children || content }</div>
}

CardDescription._meta = {
name: 'CardDescription',
parent: 'Card',
type: META.type.view,
type: META.TYPES.VIEW,
}

CardDescription.propTypes = {
className: PropTypes.string,
children: customPropTypes.all([
customPropTypes.mutuallyExclusive(['description']),
children: customPropTypes.every([
customPropTypes.disallow(['description']),
PropTypes.node,
]),
description: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
PropTypes.node,
content: customPropTypes.every([
customPropTypes.disallow(['children']),
PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
]),
}

Expand Down
25 changes: 15 additions & 10 deletions src/views/Card/CardHeader.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import cx from 'classnames'
import React, { PropTypes } from 'react'

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

function CardHeader(props) {
const { className, children, header, ...rest } = props
const { className, children, content, ...rest } = props
const classes = cx(className, 'header')

return <div {...rest} className={classes}>{children || header}</div>
return <div {...rest} className={classes}>{children || content}</div>
}

CardHeader._meta = {
name: 'CardHeader',
parent: 'Card',
type: META.type.view,
type: META.TYPES.VIEW,
}

CardHeader.propTypes = {
className: PropTypes.string,
children: customPropTypes.all([
customPropTypes.mutuallyExclusive(['header']),
children: customPropTypes.every([
customPropTypes.disallow(['header']),
PropTypes.node,
]),
header: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
PropTypes.node,
content: customPropTypes.every([
customPropTypes.disallow(['children']),
PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
]),
}

Expand Down
25 changes: 15 additions & 10 deletions src/views/Card/CardMeta.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import cx from 'classnames'
import React, { PropTypes } from 'react'

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

function CardMeta(props) {
const { className, children, meta, ...rest } = props
const { className, children, content, ...rest } = props
const classes = cx(className, 'meta')

return <div {...rest} className={classes}>{children || meta}</div>
return <div {...rest} className={classes}>{children || content}</div>
}

CardMeta._meta = {
name: 'CardMeta',
parent: 'Card',
type: META.type.view,
type: META.TYPES.VIEW,
}

CardMeta.propTypes = {
className: PropTypes.string,
children: customPropTypes.all([
customPropTypes.mutuallyExclusive(['meta']),
children: customPropTypes.every([
customPropTypes.disallow(['meta']),
PropTypes.node,
]),
meta: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
PropTypes.node,
content: customPropTypes.every([
customPropTypes.disallow(['children']),
PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
]),
}

Expand Down

0 comments on commit 37877e5

Please sign in to comment.