diff --git a/components/card/Card.js b/components/card/Card.js index 0fa04ee7..af621993 100644 --- a/components/card/Card.js +++ b/components/card/Card.js @@ -1,6 +1,7 @@ import React, { PropTypes } from 'react'; import { themr } from 'react-css-themr'; import classnames from 'classnames'; +import { CARD } from '../identifiers.js'; const Card = ({children, className, raised, theme, ...other}) => { const classes = classnames(theme.card, { @@ -19,9 +20,10 @@ Card.propTypes = { className: PropTypes.string, raised: PropTypes.bool, theme: React.PropTypes.shape({ - card: React.PropTypes.string.isRequired, - raised: React.PropTypes.string.isRequired + card: React.PropTypes.string, + raised: React.PropTypes.string }) }; -export default themr('ToolboxCard')(Card); +export default themr(CARD)(Card); +export { Card }; diff --git a/components/card/CardActions.js b/components/card/CardActions.js index e2e09145..bd83a57b 100644 --- a/components/card/CardActions.js +++ b/components/card/CardActions.js @@ -1,6 +1,7 @@ import React, { PropTypes } from 'react'; import { themr } from 'react-css-themr'; import classnames from 'classnames'; +import { CARD } from '../identifiers.js'; const CardActions = ({ children, className, theme, ...other }) => (
@@ -16,4 +17,5 @@ CardActions.propTypes = { }) }; -export default themr('ToolboxCard')(CardActions); +export default themr(CARD)(CardActions); +export { CardActions }; diff --git a/components/card/CardMedia.js b/components/card/CardMedia.js index ecaba7d3..91939238 100644 --- a/components/card/CardMedia.js +++ b/components/card/CardMedia.js @@ -1,6 +1,7 @@ import React, { PropTypes } from 'react'; import { themr } from 'react-css-themr'; import classnames from 'classnames'; +import { CARD } from '../identifiers.js'; const CardMedia = ({ aspectRatio, children, className, color, contentOverlay, image, theme, ...other }) => { const classes = classnames(theme.cardMedia, { @@ -44,4 +45,5 @@ CardMedia.propTypes = { }) }; -export default themr('ToolboxCard')(CardMedia); +export default themr(CARD)(CardMedia); +export { CardMedia }; diff --git a/components/card/CardText.js b/components/card/CardText.js index 14c4683d..df13ffc6 100644 --- a/components/card/CardText.js +++ b/components/card/CardText.js @@ -1,6 +1,7 @@ import React, { PropTypes } from 'react'; import { themr } from 'react-css-themr'; import classnames from 'classnames'; +import { CARD } from '../identifiers.js'; const CardText = ({ children, className, theme, ...other }) => (
@@ -16,4 +17,5 @@ CardText.propTypes = { }) }; -export default themr('ToolboxCard')(CardText); +export default themr(CARD)(CardText); +export { CardText }; diff --git a/components/card/CardTitle.js b/components/card/CardTitle.js index 287c6ba9..a9e83ef3 100644 --- a/components/card/CardTitle.js +++ b/components/card/CardTitle.js @@ -1,62 +1,62 @@ import React, { PropTypes } from 'react'; import classnames from 'classnames'; import { themr } from 'react-css-themr'; -import { Avatar } from '../avatar'; +import { CARD } from '../identifiers.js'; +import InjectAvatar from '../avatar/Avatar.js'; -const CardTitle = ({avatar, children, className, subtitle, theme, title, ...other}) => { - const classes = classnames(theme.cardTitle, { - [theme.small]: avatar, - [theme.large]: !avatar - }, className); +const factory = (Avatar) => { + const CardTitle = ({avatar, children, className, subtitle, theme, title, ...other}) => { + const classes = classnames(theme.cardTitle, { + [theme.small]: avatar, + [theme.large]: !avatar + }, className); - let avatarComponent; - - if (typeof avatar === 'string') { - avatarComponent = ; - } else { - avatarComponent = avatar; - } - - return ( -
- {avatarComponent} -
- {title &&
{title}
} - {children && typeof children === 'string' && ( -
{children}
- )} - {subtitle &&

{subtitle}

} - {children && typeof children !== 'string' && children} + return ( +
+ {typeof avatar === 'string' ? : avatar} +
+ {title &&
{title}
} + {children && typeof children === 'string' && ( +
{children}
+ )} + {subtitle &&

{subtitle}

} + {children && typeof children !== 'string' && children} +
-
- ); + ); + }; + + CardTitle.propTypes = { + avatar: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.element + ]), + children: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.element, + PropTypes.array + ]), + className: PropTypes.string, + subtitle: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.element + ]), + theme: React.PropTypes.shape({ + large: React.PropTypes.string.isRequired, + title: React.PropTypes.string.isRequired, + small: React.PropTypes.string.isRequired, + subtitle: React.PropTypes.string.isRequired + }), + title: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.element + ]) + }; + + return CardTitle; }; -CardTitle.propTypes = { - avatar: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.element - ]), - children: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.element, - PropTypes.array - ]), - className: PropTypes.string, - subtitle: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.element - ]), - theme: React.PropTypes.shape({ - large: React.PropTypes.string.isRequired, - title: React.PropTypes.string.isRequired, - small: React.PropTypes.string.isRequired, - subtitle: React.PropTypes.string.isRequired - }), - title: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.element - ]) -}; - -export default themr('ToolboxCard')(CardTitle); +const CardTitle = factory(InjectAvatar); +export default themr(CARD)(CardTitle); +export { CardTitle }; +export { factory as cardTitleFactory }; diff --git a/components/card/index.js b/components/card/index.js index 5f9ceb93..ef571e9b 100644 --- a/components/card/index.js +++ b/components/card/index.js @@ -1,7 +1,23 @@ -import Card from './Card'; -export default Card; -export { Card }; -export CardActions from './CardActions'; -export CardMedia from './CardMedia'; -export CardText from './CardText'; -export CardTitle from './CardTitle'; +import { themr } from 'react-css-themr'; +import { CARD } from '../identifiers.js'; +import { Card } from './Card.js'; +import { CardActions } from './CardActions.js'; +import { CardMedia } from './CardMedia.js'; +import { CardText } from './CardText.js'; +import { cardTitleFactory } from './CardTitle.js'; +import Avatar from '../avatar'; +import theme from './theme.scss'; + +const CardTitle = cardTitleFactory(Avatar); +const ThemedCard = themr(CARD, theme)(Card); +const ThemedCardActions = themr(CARD, theme)(CardActions); +const ThemedCardMedia = themr(CARD, theme)(CardMedia); +const ThemedCardText = themr(CARD, theme)(CardText); +const ThemedCardTitle = themr(CARD, theme)(CardTitle); + +export default ThemedCard; +export { ThemedCard as Card }; +export { ThemedCardActions as CardActions }; +export { ThemedCardMedia as CardMedia }; +export { ThemedCardText as CardText }; +export { ThemedCardTitle as CardTitle }; diff --git a/components/card/readme.md b/components/card/readme.md index 68518a54..a2add5f0 100644 --- a/components/card/readme.md +++ b/components/card/readme.md @@ -7,29 +7,25 @@ Cards are composed of multiple subcomponents in React Toolbox. You can combine e ```jsx import { Card, CardMedia, CardTitle, CardText, CardActions } from 'react-toolbox/lib/card'; -import theme from 'react-toolbox/lib/card/theme'; const dummyText = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.'; const TestCards = () => ( - + - {dummyText} + {dummyText}