Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Add CardMedia component #114

Merged
merged 1 commit into from
Nov 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion demo/card/card.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Card, CardTitle, CardText, CardActions, CardMenu } from '../../src/Card';
import { Card, CardTitle, CardText, CardActions, CardMenu, CardMedia } from '../../src/Card';
import Button from '../../src/Button';
import IconButton from '../../src/IconButton';
import Icon from '../../src/Icon';
Expand Down Expand Up @@ -62,6 +62,17 @@ class Demo extends React.Component {
<Icon name="event" />
</CardActions>
</Card>

<p>Media card</p>
<Card shadow={0} style={{width: '256px'}}>
<CardTitle>Media card</CardTitle>
<CardMedia>
<img src="http://www.getmdl.io/assets/demos/image_card.jpg" width="256" height="256" />
</CardMedia>
<CardText>
This card contains media.
</CardText>
</Card>
</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
Card: Card.Card,
CardTitle: Card.CardTitle,
CardActions: Card.CardActions,
CardMedia: Card.CardMedia,
CardText: Card.CardText,
CardMenu: Card.CardMenu,
Checkbox: require('./lib/Checkbox'),
Expand Down
38 changes: 38 additions & 0 deletions src/Card/__tests__/CardMedia-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-env mocha */
import expect from 'expect';
import React from 'react';
import { render } from '../../__tests__/render';
import { CardMedia } from '../';

describe('Card', () => {
describe('CardMedia', () => {
it('should render a div with the card media css class', () => {
const output = render(<CardMedia />);

expect(output.type).toBe('div');
expect(output.props.className).toInclude('mdl-card__media');
});

it('should allow custom css classes', () => {
const output = render(<CardMedia className="my-media" />);

expect(output.props.className)
.toInclude('mdl-card__media')
.toInclude('my-media');
});

it('should render with the children', () => {
const element = (
<CardMedia>
<img src="test.png" />
</CardMedia>
);

const output = render(element);

expect(output.props.children)
.toEqual(<img src="test.png" />);
});
});
});

1 change: 1 addition & 0 deletions src/Card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const CardText = basicClassCreator('CardText', 'mdl-card__supporting-text
export const CardMenu = basicClassCreator('CardMenu', 'mdl-card__menu');
export CardTitle from './CardTitle';
export CardActions from './CardActions';
export const CardMedia = basicClassCreator('CardMedia', 'mdl-card__media');