Skip to content

Commit

Permalink
create PR for card component
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismcv committed Jun 17, 2015
1 parent cb70f0d commit a92fa6d
Show file tree
Hide file tree
Showing 12 changed files with 405 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/src/app/app-routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var Components = require('./components/pages/components.jsx');
var AppBar = require('./components/pages/components/app-bar.jsx');
var Avatars = require('./components/pages/components/avatars.jsx');
var Buttons = require('./components/pages/components/buttons.jsx');
var Cards = require('./components/pages/components/cards.jsx');
var DatePicker = require('./components/pages/components/date-picker.jsx');
var Dialog = require('./components/pages/components/dialog.jsx');
var DropDownMenu = require('./components/pages/components/drop-down-menu.jsx');
Expand Down Expand Up @@ -62,6 +63,7 @@ var AppRoutes = (
<Route name="appbar" handler={AppBar} />
<Route name="avatars" handler={Avatars} />
<Route name="buttons" handler={Buttons} />
<Route name="cards" handler={Cards} />
<Route name="date-picker" handler={DatePicker} />
<Route name="dialog" handler={Dialog} />
<Route name="dropdown-menu" handler={DropDownMenu} />
Expand Down
1 change: 1 addition & 0 deletions docs/src/app/components/pages/components.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Components extends React.Component {
{ route: 'appbar', text: 'AppBar'},
{ route: 'avatars', text: 'Avatars'},
{ route: 'buttons', text: 'Buttons'},
{ route: 'cards', text: 'Cards'},
{ route: 'date-picker', text: 'Date Picker'},
{ route: 'dialog', text: 'Dialog'},
{ route: 'dropdown-menu', text: 'Dropdown Menu'},
Expand Down
88 changes: 88 additions & 0 deletions docs/src/app/components/pages/components/cards.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
var React = require('react');
var mui = require('mui');
var ComponentDoc = require('../../component-doc.jsx');
var {Card, CardMedia, CardTitle, CardActions, CardText, CardHeader, FlatButton, Avatar} = mui;

class CardPage extends React.Component {

constructor(props) {
super(props);

this.code = `
<Card>
<CardHeader
title="Title"
subtitle="Subtitle"
avatar={<Avatar>A</Avatar>}/>
<CardHeader
title="Demo Url Based Avatar"
subtitle="Subtitle"
avatar="http://lorempixel.com/100/100/nature/"/>
<CardMedia overlay={<CardTitle title="Title" subtitle="Subtitle"/>}>
<img src="http://lorempixel.com/600/337/nature/"/>
</CardMedia>
<CardTitle title="Title" subtitle="Subtitle"/>
<CardActions>
<FlatButton label="Action1"/>
<FlatButton label="Action2"/>
</CardActions>
<CardText>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Donec mattis pretium massa. Aliquam erat volutpat. Nulla facilisi.
Donec vulputate interdum sollicitudin. Nunc lacinia auctor quam sed pellentesque.
Aliquam dui mauris, mattis quis lacus id, pellentesque lobortis odio.
</CardText>
</Card>`;

this.desc =
'A card is a piece of paper with unique related data that serves as an '+
'entry point to more detailed information. For example, a card could '+
'contain a photo, text, and a link about a single subject.'+
'\n\n'+
'Cards have a constant width and variable height. The maximum height is '+
'limited to the height of the available space on a platform, '+
'but it can temporarily expand (for example, to display a comment field). '+
'Cards do not flip over to reveal information on the back.';


this.componentInfo = [];
}

render() {
return (
<ComponentDoc
name="Card"
code={this.code}
desc={this.desc}
componentInfo={this.componentInfo}>
<Card>
<CardHeader
title="Title"
subtitle="Subtitle"
avatar={<Avatar>A</Avatar>}/>
<CardHeader
title="Demo Url Based Avatar"
subtitle="Subtitle"
avatar="http://lorempixel.com/100/100/nature/"/>
<CardMedia overlay={<CardTitle title="Title" subtitle="Subtitle"/>}>
<img src="http://lorempixel.com/600/337/nature/"/>
</CardMedia>
<CardTitle title="Title" subtitle="Subtitle"/>
<CardActions>
<FlatButton label="Action1"/>
<FlatButton label="Action2"/>
</CardActions>
<CardText>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Donec mattis pretium massa. Aliquam erat volutpat. Nulla facilisi.
Donec vulputate interdum sollicitudin. Nunc lacinia auctor quam sed pellentesque.
Aliquam dui mauris, mattis quis lacus id, pellentesque lobortis odio.
</CardText>
</Card>
</ComponentDoc>
);
}

}

module.exports = CardPage;
1 change: 1 addition & 0 deletions src/avatar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var SvgIcon = React.createClass({
borderRadius: '50%',
border: src ? 'solid 1px' : 'none',
borderColor: this.context.muiTheme.palette.borderColor,
display:'inline-block',

//Needed for letter avatars
textAlign: 'center',
Expand Down
29 changes: 29 additions & 0 deletions src/card/card-actions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var React = require('react');
var Styles = require('../styles');

var CardActions = React.createClass({
getStyles: function () {
return {
root: {
padding: 8
}
}
},
render: function () {
var styles = this.getStyles();

var children = React.Children.map(this.props.children, function (child) {
return React.cloneElement(child, {
style: {marginRight: 8}
});
});

return (
<div style={styles.root}>
{children}
</div>
);
}
});

module.exports = CardActions;
69 changes: 69 additions & 0 deletions src/card/card-header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var React = require('react');
var Styles = require('../styles');
var Avatar = require('../avatar');

var CardHeader = React.createClass({
propTypes: {
avatar: React.PropTypes.string,
title: React.PropTypes.string,
titleColor: React.PropTypes.string,
subtitle: React.PropTypes.string,
subtitleColor: React.PropTypes.string
},
getDefaultProps: function () {
return {
titleColor: Styles.Colors.darkBlack,
subtitleColor: Styles.Colors.lightBlack
};
},
getStyles: function () {
return {
root: {
height: 72,
padding: 16,
fontWeight: Styles.Typography.fontWeightMedium,
boxSizing: 'border-box'
},
text: {
display: 'inline-block',
verticalAlign: 'top'
},
avatar: {
marginRight:16
},
title: {
color: this.props.titleColor,
display: 'block',
fontSize: 15
},
subtitle: {
color: this.props.subtitleColor,
display: 'block',
fontSize: 14
}
}
},
render: function () {
var styles = this.getStyles();
var avatar = this.props.avatar;

if (React.isValidElement(this.props.avatar))
avatar = React.cloneElement(avatar, {style:styles.avatar})
else
avatar = <Avatar src={this.props.avatar} style={styles.avatar}/>



return (
<div style={styles.root}>
{avatar}
<div style={styles.text}>
<span style={styles.title}>{this.props.title}</span>
<span style={styles.subtitle}>{this.props.subtitle}</span>
</div>
</div>
);
}
});

module.exports = CardHeader;
81 changes: 81 additions & 0 deletions src/card/card-media.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
var React = require('react');
var Styles = require('../styles');

var CardMedia = React.createClass({
propTypes: {
overlay: React.PropTypes.node
},
getStyles: function () {
return {
root: {
position: 'relative'
},
overlayContainer: {
position: 'absolute',
top: 0,
bottom: 0,
right: 0,
left: 0
},
overlay: {
height: '100%',
position: 'relative'
},
overlayContent: {
position: 'absolute',
bottom: 0,
right: 0,
left: 0,
paddingTop: 8,
background: Styles.Colors.lightBlack
}
};
},
render: function () {
var styles = this.getStyles();

var children = React.Children.map(this.props.children, function (child) {
return React.cloneElement(child, {
style: {
verticalAlign: 'top',
maxWidth: '100%',
minWidth: '100%'
}
});
});

var overlayChildren = React.Children.map(this.props.overlay, function (child) {
if (child.type.displayName === 'CardHeader' || child.type.displayName === 'CardTitle'
) {
return React.cloneElement(child, {
titleColor: Styles.Colors.darkWhite,
subtitleColor: Styles.Colors.lightWhite
});
} else if (child.type.displayName === 'CardText') {
return React.cloneElement(child, {
color: Styles.Colors.darkWhite
});
} else {
return child;
}
});

return (
<div style={styles.root}>
<div style={styles.media}>
{children}
</div>
{(this.props.overlay) ?
<div style={styles.overlayContainer}>
<div style={styles.overlay}>
<div style={styles.overlayContent}>
{overlayChildren}
</div>
</div>
</div> : ''}
</div>
);
}
});

module.exports = CardMedia;
33 changes: 33 additions & 0 deletions src/card/card-text.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var React = require('react');
var Styles = require('../styles');

var CardText = React.createClass({
propTypes: {
color: React.PropTypes.string
},
getDefaultProps: function () {
return {
color: Styles.Colors.ck
}
},
getStyles: function () {
return {
root: {
padding: 16,
fontSize: '14px',
color: this.props.color
}
}
},
render: function () {
var styles = this.getStyles();

return (
<div style={styles.root}>
{this.props.children}
</div>
);
}
});

module.exports = CardText;
47 changes: 47 additions & 0 deletions src/card/card-title.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var React = require('react');
var Styles = require('../styles');

var CardTitle = React.createClass({
propTypes: {
title: React.PropTypes.string,
titleColor: React.PropTypes.string,
subtitle: React.PropTypes.string,
subtitleColor: React.PropTypes.string
},
getDefaultProps: function () {
return {
titleColor: Styles.Colors.darkBlack,
subtitleColor: Styles.Colors.lightBlack
};
},
getStyles: function () {
return {
root: {
padding: 16
},
title: {
fontSize: 24,
color: this.props.titleColor,
display: 'block',
lineHeight: '36px'
},
subtitle: {
fontSize: 14,
color: this.props.subtitleColor,
display: 'block'
}
}
},
render: function () {
var styles = this.getStyles();

return (
<div style={styles.root}>
<span style={styles.title}>{this.props.title}</span>
<span style={styles.subtitle}>{this.props.subtitle}</span>
</div>
);
}
});

module.exports = CardTitle;
Loading

0 comments on commit a92fa6d

Please sign in to comment.