Autoinject theme for Card
parent
d04c181fdf
commit
05c6dce5e1
|
@ -1,6 +1,7 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import { themr } from 'react-css-themr';
|
import { themr } from 'react-css-themr';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
|
import { CARD } from '../identifiers.js';
|
||||||
|
|
||||||
const Card = ({children, className, raised, theme, ...other}) => {
|
const Card = ({children, className, raised, theme, ...other}) => {
|
||||||
const classes = classnames(theme.card, {
|
const classes = classnames(theme.card, {
|
||||||
|
@ -19,9 +20,10 @@ Card.propTypes = {
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
raised: PropTypes.bool,
|
raised: PropTypes.bool,
|
||||||
theme: React.PropTypes.shape({
|
theme: React.PropTypes.shape({
|
||||||
card: React.PropTypes.string.isRequired,
|
card: React.PropTypes.string,
|
||||||
raised: React.PropTypes.string.isRequired
|
raised: React.PropTypes.string
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
export default themr('ToolboxCard')(Card);
|
export default themr(CARD)(Card);
|
||||||
|
export { Card };
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import { themr } from 'react-css-themr';
|
import { themr } from 'react-css-themr';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
|
import { CARD } from '../identifiers.js';
|
||||||
|
|
||||||
const CardActions = ({ children, className, theme, ...other }) => (
|
const CardActions = ({ children, className, theme, ...other }) => (
|
||||||
<div className={classnames(theme.cardActions, className)} {...other}>
|
<div className={classnames(theme.cardActions, className)} {...other}>
|
||||||
|
@ -16,4 +17,5 @@ CardActions.propTypes = {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
export default themr('ToolboxCard')(CardActions);
|
export default themr(CARD)(CardActions);
|
||||||
|
export { CardActions };
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import { themr } from 'react-css-themr';
|
import { themr } from 'react-css-themr';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
|
import { CARD } from '../identifiers.js';
|
||||||
|
|
||||||
const CardMedia = ({ aspectRatio, children, className, color, contentOverlay, image, theme, ...other }) => {
|
const CardMedia = ({ aspectRatio, children, className, color, contentOverlay, image, theme, ...other }) => {
|
||||||
const classes = classnames(theme.cardMedia, {
|
const classes = classnames(theme.cardMedia, {
|
||||||
|
@ -44,4 +45,5 @@ CardMedia.propTypes = {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
export default themr('ToolboxCard')(CardMedia);
|
export default themr(CARD)(CardMedia);
|
||||||
|
export { CardMedia };
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import { themr } from 'react-css-themr';
|
import { themr } from 'react-css-themr';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
|
import { CARD } from '../identifiers.js';
|
||||||
|
|
||||||
const CardText = ({ children, className, theme, ...other }) => (
|
const CardText = ({ children, className, theme, ...other }) => (
|
||||||
<div className={classnames(theme.cardText, className)} {...other}>
|
<div className={classnames(theme.cardText, className)} {...other}>
|
||||||
|
@ -16,4 +17,5 @@ CardText.propTypes = {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
export default themr('ToolboxCard')(CardText);
|
export default themr(CARD)(CardText);
|
||||||
|
export { CardText };
|
||||||
|
|
|
@ -1,62 +1,62 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import { themr } from 'react-css-themr';
|
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 factory = (Avatar) => {
|
||||||
const classes = classnames(theme.cardTitle, {
|
const CardTitle = ({avatar, children, className, subtitle, theme, title, ...other}) => {
|
||||||
[theme.small]: avatar,
|
const classes = classnames(theme.cardTitle, {
|
||||||
[theme.large]: !avatar
|
[theme.small]: avatar,
|
||||||
}, className);
|
[theme.large]: !avatar
|
||||||
|
}, className);
|
||||||
|
|
||||||
let avatarComponent;
|
return (
|
||||||
|
<div className={classes} {...other}>
|
||||||
if (typeof avatar === 'string') {
|
{typeof avatar === 'string' ? <Avatar image={avatar} /> : avatar}
|
||||||
avatarComponent = <Avatar image={avatar} />;
|
<div>
|
||||||
} else {
|
{title && <h5 className={theme.title}>{title}</h5>}
|
||||||
avatarComponent = avatar;
|
{children && typeof children === 'string' && (
|
||||||
}
|
<h5 className={theme.title}>{children}</h5>
|
||||||
|
)}
|
||||||
return (
|
{subtitle && <p className={theme.subtitle}>{subtitle}</p>}
|
||||||
<div className={classes} {...other}>
|
{children && typeof children !== 'string' && children}
|
||||||
{avatarComponent}
|
</div>
|
||||||
<div>
|
|
||||||
{title && <h5 className={theme.title}>{title}</h5>}
|
|
||||||
{children && typeof children === 'string' && (
|
|
||||||
<h5 className={theme.title}>{children}</h5>
|
|
||||||
)}
|
|
||||||
{subtitle && <p className={theme.subtitle}>{subtitle}</p>}
|
|
||||||
{children && typeof children !== 'string' && children}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
);
|
};
|
||||||
|
|
||||||
|
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 = {
|
const CardTitle = factory(InjectAvatar);
|
||||||
avatar: PropTypes.oneOfType([
|
export default themr(CARD)(CardTitle);
|
||||||
PropTypes.string,
|
export { CardTitle };
|
||||||
PropTypes.element
|
export { factory as cardTitleFactory };
|
||||||
]),
|
|
||||||
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);
|
|
||||||
|
|
|
@ -1,7 +1,23 @@
|
||||||
import Card from './Card';
|
import { themr } from 'react-css-themr';
|
||||||
export default Card;
|
import { CARD } from '../identifiers.js';
|
||||||
export { Card };
|
import { Card } from './Card.js';
|
||||||
export CardActions from './CardActions';
|
import { CardActions } from './CardActions.js';
|
||||||
export CardMedia from './CardMedia';
|
import { CardMedia } from './CardMedia.js';
|
||||||
export CardText from './CardText';
|
import { CardText } from './CardText.js';
|
||||||
export CardTitle from './CardTitle';
|
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 };
|
||||||
|
|
|
@ -7,29 +7,25 @@ Cards are composed of multiple subcomponents in React Toolbox. You can combine e
|
||||||
<!-- example -->
|
<!-- example -->
|
||||||
```jsx
|
```jsx
|
||||||
import { Card, CardMedia, CardTitle, CardText, CardActions } from 'react-toolbox/lib/card';
|
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 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 = () => (
|
const TestCards = () => (
|
||||||
<Card theme={theme} style={{width: '350px'}}>
|
<Card style={{width: '350px'}}>
|
||||||
<CardTitle
|
<CardTitle
|
||||||
avatar="https://placeimg.com/80/80/animals"
|
avatar="https://placeimg.com/80/80/animals"
|
||||||
title="Avatar style title"
|
title="Avatar style title"
|
||||||
subtitle="Subtitle here"
|
subtitle="Subtitle here"
|
||||||
theme={theme}
|
|
||||||
/>
|
/>
|
||||||
<CardMedia
|
<CardMedia
|
||||||
aspectRatio="wide"
|
aspectRatio="wide"
|
||||||
image="https://placeimg.com/800/450/nature"
|
image="https://placeimg.com/800/450/nature"
|
||||||
theme={theme}
|
|
||||||
/>
|
/>
|
||||||
<CardTitle
|
<CardTitle
|
||||||
title="Title goes here"
|
title="Title goes here"
|
||||||
subtitle="Subtitle here"
|
subtitle="Subtitle here"
|
||||||
theme={theme}
|
|
||||||
/>
|
/>
|
||||||
<CardText theme={theme}>{dummyText}</CardText>
|
<CardText>{dummyText}</CardText>
|
||||||
<CardActions theme={theme}>
|
<CardActions theme={theme}>
|
||||||
<Button label="Action 1" />
|
<Button label="Action 1" />
|
||||||
<Button label="Action 2" />
|
<Button label="Action 2" />
|
||||||
|
@ -40,7 +36,7 @@ const TestCards = () => (
|
||||||
return <TestCards />;
|
return <TestCards />;
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--component-docgen-start-->
|
This component and all of its subcomponents are themeable by context using the key `RTCard`. This component theme can also include class modifiers for `Button` and `Avatar` component.
|
||||||
|
|
||||||
## Card
|
## Card
|
||||||
|
|
||||||
|
@ -54,15 +50,15 @@ that all subcomponents are placed within.
|
||||||
| `className` | `String` | | Additional class(es) for custom styling. |
|
| `className` | `String` | | Additional class(es) for custom styling. |
|
||||||
| `raised` | `Boolean` | | Increases the shadow depth to appear elevated. |
|
| `raised` | `Boolean` | | Increases the shadow depth to appear elevated. |
|
||||||
|
|
||||||
|
### Theme
|
||||||
|
|
||||||
Since the `Button` implements a ripple, it accepts theme properties for the ripple as well. If you want to compose the default style for the ripple, you just have to provide Ripple keys with custom styles in the theme object.
|
| Name | Description|
|
||||||
|
|:---------|:-----------|
|
||||||
|
| `card` | Class used for the root element.|
|
||||||
|
| `raised` | Added to the root element in case the card is raised.|
|
||||||
|
|
||||||
## CardTitle
|
## CardTitle
|
||||||
A versatile title block that can be used in
|
A versatile title block that can be used in various places on the card, including the media area. This component can also display an avatar next to the title content.
|
||||||
various places on the card, including the media
|
|
||||||
area. This component can also display an avatar next
|
|
||||||
to the title content.
|
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|
@ -73,11 +69,18 @@ to the title content.
|
||||||
| `subtitle` | `String` | | Text used for the sub header of the card. |
|
| `subtitle` | `String` | | Text used for the sub header of the card. |
|
||||||
| `title` | `String` | | Text used for the title of the card. |
|
| `title` | `String` | | Text used for the title of the card. |
|
||||||
|
|
||||||
|
### Theme
|
||||||
|
|
||||||
|
| Name | Description|
|
||||||
|
|:---------|:-----------|
|
||||||
|
| `large` | Added to the root element when the card has avatar.|
|
||||||
|
| `small` | Added to the root element when the card has no avatar.|
|
||||||
|
| `subtitle` | Added to the root element for subtitle.|
|
||||||
|
| `title` | Used in for the root element.|
|
||||||
|
|
||||||
## CardMedia
|
## CardMedia
|
||||||
|
|
||||||
Used for displaying media such as images or videos
|
Used for displaying media such as images or videos on a card. Can also be used with a solid background color instead of an image.
|
||||||
on a card. Can also be used with a solid background
|
|
||||||
color instead of an image.
|
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|
@ -89,9 +92,18 @@ color instead of an image.
|
||||||
| `contentOverlay` | `Boolean` | | Creates a dark overlay underneath the child components. |
|
| `contentOverlay` | `Boolean` | | Creates a dark overlay underneath the child components. |
|
||||||
| `image` | `String`, `Element` | | Can be used instead of children. Accepts an element or a URL string. |
|
| `image` | `String`, `Element` | | Can be used instead of children. Accepts an element or a URL string. |
|
||||||
|
|
||||||
|
### Theme
|
||||||
|
|
||||||
|
| Name | Description|
|
||||||
|
|:---------|:-----------|
|
||||||
|
| `cardMedia` | Added to the element root.|
|
||||||
|
| `content` | Used for the content element.|
|
||||||
|
| `contentOverlay` | Added to content element if its overlayed.|
|
||||||
|
| `square` | Added to content element if its squared.|
|
||||||
|
| `wide` | Added to content element if its wide.|
|
||||||
|
|
||||||
## CardText
|
## CardText
|
||||||
Basic card content container. Good for
|
Basic card content container. Good for small descriptions or other supplementary text.
|
||||||
small descriptions or other supplementary text.
|
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|
@ -99,37 +111,25 @@ small descriptions or other supplementary text.
|
||||||
| `children` | `Any` | | Children to pass through the component. |
|
| `children` | `Any` | | Children to pass through the component. |
|
||||||
| `className` | `String` | | Additional class(es) for custom styling. |
|
| `className` | `String` | | Additional class(es) for custom styling. |
|
||||||
|
|
||||||
## CardActions
|
### Theme
|
||||||
|
|
||||||
This component is used as a container for supplemental
|
|
||||||
card actions. Supplemental actions within the card are
|
|
||||||
explicitly called out using icons, text, and UI controls,
|
|
||||||
typically placed at the bottom of the card.
|
|
||||||
|
|
||||||
### Properties
|
|
||||||
| Name | Type | Default | Description |
|
|
||||||
|:-----|:-----|:-----|:-----|
|
|
||||||
| `children` | `Any` | | Children to pass through the component. |
|
|
||||||
| `className` | `String` | | Additional class(es) for custom styling. |
|
|
||||||
|
|
||||||
## Theming
|
|
||||||
|
|
||||||
Each subcomponent takes it's own classes but since usually you'd want to include every card subcomponent, and also those styles are related to each other, we use the same themed key `ToolboxCard` for context styles. The interface is as follows:
|
|
||||||
|
|
||||||
| Name | Description|
|
| Name | Description|
|
||||||
|:-----------|:-----------|
|
|:-----------|:-----------|
|
||||||
| `card` | Used in `Card` as root class.|
|
| `cardText` | Used for the main root element.|
|
||||||
| `cardActions` | Used in `CardActions` for the wrapper.|
|
|
||||||
| `cardMedia` | Used in `CardMedia` for the wrapper.|
|
|
||||||
| `cardText` | Used in `CardText` for text wrapper.|
|
|
||||||
| `content` | Used in `CardMedia` for inner content.|
|
|
||||||
| `contentOverlay` | Used in `CardMedia` for inner content if its overlayed.|
|
|
||||||
| `large` | Used in `CardTitle` when the card has avatar.|
|
|
||||||
| `raised` | Used in `Card` for raised cards.|
|
|
||||||
| `small` | Used in `CardTitle` when the card has no avatar.|
|
|
||||||
| `square` | Used in `CardMedia` for square content.|
|
|
||||||
| `subtitle` | Used in `CardTitle` for subtitle.|
|
|
||||||
| `title` | Used in `CardTitle` for title main wrapper.|
|
|
||||||
| `wide` | Used in `CardMedia` for wide content.|
|
|
||||||
|
|
||||||
This component theme also includes modifiers for `Button` and for `Avatar` component.
|
## CardActions
|
||||||
|
|
||||||
|
This component is used as a container for supplemental card actions. Supplemental actions within the card are explicitly called out using icons, text, and UI controls, typically placed at the bottom of the card.
|
||||||
|
|
||||||
|
### Properties
|
||||||
|
|
||||||
|
| Name | Type | Default | Description |
|
||||||
|
|:-----|:-----|:-----|:-----|
|
||||||
|
| `children` | `Any` | | Children to pass through the component. |
|
||||||
|
| `className` | `String` | | Additional class(es) for custom styling. |
|
||||||
|
|
||||||
|
### Theme
|
||||||
|
|
||||||
|
| Name | Description|
|
||||||
|
|:-----------|:-----------|
|
||||||
|
| `cardActions` | Used for a wrapper around actions as the root element.|
|
||||||
|
|
|
@ -2,6 +2,7 @@ export const APP_BAR = 'RTAppBar';
|
||||||
export const AUTOCOMPLETE = 'RTAutocomplete';
|
export const AUTOCOMPLETE = 'RTAutocomplete';
|
||||||
export const AVATAR = 'RTAvatar';
|
export const AVATAR = 'RTAvatar';
|
||||||
export const BUTTON = 'RTButton';
|
export const BUTTON = 'RTButton';
|
||||||
|
export const CARD = 'RTCard';
|
||||||
export const CHIP = 'RTChip';
|
export const CHIP = 'RTChip';
|
||||||
export const INPUT = 'RTInput';
|
export const INPUT = 'RTInput';
|
||||||
export const RIPPLE = 'RTRipple';
|
export const RIPPLE = 'RTRipple';
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import '../components/commons.scss';
|
import '../components/commons.scss';
|
||||||
|
|
||||||
import ToolboxCard from '../components/card/theme.scss';
|
|
||||||
import ToolboxCheckbox from '../components/checkbox/theme.scss';
|
import ToolboxCheckbox from '../components/checkbox/theme.scss';
|
||||||
import ToolboxDatePicker from '../components/date_picker/theme.scss';
|
import ToolboxDatePicker from '../components/date_picker/theme.scss';
|
||||||
import ToolboxDialog from '../components/dialog/theme.scss';
|
import ToolboxDialog from '../components/dialog/theme.scss';
|
||||||
|
@ -23,7 +22,6 @@ import ToolboxTimePicker from '../components/time_picker/theme.scss';
|
||||||
import ToolboxTooltip from '../components/tooltip/theme.scss';
|
import ToolboxTooltip from '../components/tooltip/theme.scss';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
ToolboxCard,
|
|
||||||
ToolboxCheckbox,
|
ToolboxCheckbox,
|
||||||
ToolboxDatePicker,
|
ToolboxDatePicker,
|
||||||
ToolboxDialog,
|
ToolboxDialog,
|
||||||
|
|
Loading…
Reference in New Issue