Skip to content

Commit 211cb97

Browse files
committed
Add documentation and examples for cards
1 parent 1e662d1 commit 211cb97

File tree

9 files changed

+109
-56
lines changed

9 files changed

+109
-56
lines changed

components/card/index.jsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import style from './style';
55

66
class Card extends React.Component {
77
static propTypes = {
8+
actions: React.PropTypes.array,
89
className: React.PropTypes.string,
910
color: React.PropTypes.string,
1011
image: React.PropTypes.string,
11-
text: React.PropTypes.string,
1212
loading: React.PropTypes.bool,
1313
onClick: React.PropTypes.func,
14+
text: React.PropTypes.string,
1415
title: React.PropTypes.string,
15-
type: React.PropTypes.string
16+
type: React.PropTypes.oneOf(['wide', 'event', 'image'])
1617
};
1718

1819
static defaultProps = {
1920
className: '',
20-
loading: false,
21-
type: 'default'
21+
loading: false
2222
};
2323

2424
handleMouseDown = (event) => {
@@ -41,8 +41,8 @@ class Card extends React.Component {
4141
if (this.props.title || this.props.image) {
4242
return (
4343
<figure className={style.figure} style={styleFigure}>
44-
{ this.props.subtitle ? <small>{this.props.subtitle}</small> : null }
45-
{ this.props.title ? <h5>{this.props.title}</h5> : null }
44+
{ this.props.title ? <h5 data-role='title'>{this.props.title}</h5> : null }
45+
{ this.props.subtitle ? <small data-role='subtitle'>{this.props.subtitle}</small> : null }
4646
{ this.props.color ? <div className={style.overflow} style={styleOverflow}></div> : null }
4747
</figure>
4848
);
@@ -52,7 +52,7 @@ class Card extends React.Component {
5252
renderActions () {
5353
if (this.props.actions) {
5454
return (
55-
<Navigation className={style.navigation} actions={this.props.actions} />
55+
<Navigation data-role='actions' className={style.navigation} actions={this.props.actions} />
5656
);
5757
}
5858
}
@@ -73,7 +73,7 @@ class Card extends React.Component {
7373
onMouseDown={this.handleMouseDown}
7474
>
7575
{ this.renderTitle() }
76-
{ this.props.text ? <p className={style.text}>{this.props.text}</p> : null }
76+
{ this.props.text ? <p data-role='text' className={style.text}>{this.props.text}</p> : null }
7777
{ this.renderActions() }
7878
<Ripple
7979
ref='ripple'

components/card/readme.md

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,56 @@
11
# Card
22

3+
A [card](https://www.google.com/design/spec/components/cards.html) 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.
4+
5+
<!-- example -->
36
```
4-
var Card = require('react-toolbox/components/card');
5-
6-
<Card title="Default Card" />
7-
<Card title="Default Card with text" text={text} />
8-
<Card title="Default Card with legend" legend={legend} />
9-
<Card title="Default Card with actions" actions={actions} />
10-
<Card title="Defaulr Card with text & image" text={text} image="http://" />
11-
<Card title="Default Card with text, color & onClick event" text={text}
12-
color="#e91e63" onClick={@onClick} />
13-
<Card type="small" title="Small Card with text & onClick event"
14-
text={text} color="#00bcd4" onClick={@onClick} />
7+
import Card from 'react-toolbox/card';
8+
9+
const actions = [
10+
{ label: 'Play', icon: 'play-arrow'},
11+
{ label: 'Close' }
12+
];
13+
14+
const TestCards = () => (
15+
<Card
16+
image='http://pitchfork-cdn.s3.amazonaws.com/longform/221/Deerhunter-Fading-Frontier640.jpg'
17+
text='A Deerhunter album rollout usually coincides with some pithy and provocative statements from Bradford Cox on pop culture...'
18+
title='Deerhunter - Fading Frontier'
19+
color="rgba(0,0,0,.4)"
20+
actions={actions}
21+
/>
22+
);
1523
```
1624

1725
## Properties
1826

1927
| Name | Type | Default | Description|
2028
|:- |:-: | :- |:-|
21-
| **className** | String | | Sets the class-styles of the Component.|
22-
| **color** | String | | Sets HEX of the Component.|
23-
| **image** | String | | Sets a background image url.|
24-
| **text** | String | | Sets a complementary text.|
25-
| **legend** | String | | Sets a legend text.|
26-
| **loading** | Boolean | | If true, component will be disabled and show a loading animation.|
27-
| **onClick** | Function | | Callback function that is fired when the components's is clicked.|
28-
| **title** | String | "text" | Sets the title of the component.|
29-
| **type** | String | "text" | Type of the component, overwrite this property if you need set a different stylesheet.|
29+
| actions | Array | | Array of objects describing actions. These actions will be rendered as buttons and the object fields will be transferred to those.|
30+
| className | String | `''` | Sets a class to give customized styles to the card.|
31+
| color | String | | Sets HEX or RGBA color to add a colored layer to the heading.|
32+
| image | String | | URL to sets a background image in the heading.|
33+
| loading | Boolean | `false` | If true, component will be disabled and showing a loading animation.|
34+
| onClick | Function | | Callback function that is fired when the components's is clicked. It also will display a ripple effect on click. |
35+
| subtitle | String | | Sets a complementary smaller text under the title.|
36+
| text | String | | Sets a complementary text display as a card description.|
37+
| title | String | | Sets the title of the card.|
38+
| type | String | `default` | Type of the component to display general modifications. It can be `wide` for a larger card, `image` if it's an image card or `event` which shows just a title on top. |
3039

31-
## Methods
40+
## Structure
3241

33-
#### loading
34-
If true, component will be disabled and show a loading animation.
42+
This can generate different structures depending on the props. A complicated one can be as follows:
3543

3644
```
37-
card_instance.loading(true);
45+
<div data-react-toolbox="card">
46+
<figure>
47+
<h5 data-role='title'>Title</h5>
48+
<small data-role='subtitle'>Subtitle</small>
49+
</figure>
50+
<p data-role='text'>Description</p>
51+
<nav data-role='actions'>
52+
<button data-react-toolbox="button">...</button>
53+
<button data-react-toolbox="button">...</button>
54+
</nav>
55+
</div>
3856
```

docs/app/components/editor/style.scss

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
@import "../globals";
22
@import "../mixins";
33

4-
$documentation-code-background: rgba(0, 0, 0, .0588235);
5-
64
.editor {
75
position: relative;
86

@@ -11,16 +9,4 @@ $documentation-code-background: rgba(0, 0, 0, .0588235);
119
@import "solarized";
1210
@import "custom";
1311
}
14-
15-
&:before {
16-
display: block;
17-
width: 100%;
18-
padding: 3px 7px;
19-
font-size: $font-size-tiny;
20-
font-weight: $font-weight-bold;
21-
font-family: $code-font-family;
22-
color: $color-text;
23-
content: "React Toolbox Virtual Console";
24-
background-color: rgba(0,0,0,0.1);
25-
}
2612
}

docs/app/components/layout/main/components/navigation.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const MainNavigation = React.createClass({
3838

3939
return (
4040
<aside className={className}>
41-
<List className={style.list} selectable>
41+
<List className={style.list} selectable ripple>
4242
{ this.renderDrawerItems() }
4343
</List>
4444
<footer className={style.footer}>

docs/app/components/layout/main/components/playground.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import Editor from '../../../editor';
33
import Preview from '../../../preview';
44
import codeText from '../modules/examples/example.txt';
5+
import style from './playground.scss';
56

67
class Playground extends React.Component {
78
static propTypes = {
@@ -19,8 +20,16 @@ class Playground extends React.Component {
1920
render () {
2021
return (
2122
<aside className={this.props.className}>
22-
<Editor ref='editor' codeText={this.state.code} onChange={this.handleCodeChange} />
23-
<Preview code={this.state.code} />
23+
<Editor
24+
ref='editor'
25+
className={style.editor}
26+
codeText={this.state.code}
27+
onChange={this.handleCodeChange}
28+
/>
29+
<Preview
30+
className={style.preview}
31+
code={this.state.code}
32+
/>
2433
</aside>
2534
);
2635
}
Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
@import "../config";
22

3-
.root {
4-
width: $playground-width;
5-
height: 100%;
6-
overflow-y: auto;
7-
background-color: $color-background;
3+
.editor {
4+
position: absolute;
5+
top: 0;
6+
right: 0;
7+
bottom: 60%;
8+
left: 0;
9+
overflow-y: scroll;
10+
div:global(.CodeMirror) {
11+
display: flex;
12+
height: 100%;
13+
min-height: 100%;
14+
max-height: 100%;
15+
flex-direction: column;
16+
flex-grow: 1;
17+
}
18+
}
19+
20+
.preview {
21+
position: absolute;
22+
top: 40%;
23+
right: 0;
24+
bottom: 0;
25+
left: 0;
26+
display: flex;
27+
overflow-y: scroll;
28+
border-top: 1px solid $color-divider;
829
}

docs/app/components/layout/main/modules/components.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import TimePicker from 'react-toolbox/time_picker/readme';
2626
// Examples for the Playground
2727
import ButtonExample1 from './examples/button_example_1.txt';
2828
import AutocompleteExample1 from './examples/autocomplete_example_1.txt';
29+
import CardExample1 from './examples/card_example_1.txt';
2930

3031
export default {
3132
app_bar: {
@@ -48,7 +49,8 @@ export default {
4849
card: {
4950
name: 'Card',
5051
docs: Card,
51-
path: '/components/card'
52+
path: '/components/card',
53+
examples: [CardExample1]
5254
},
5355
checkbox: {
5456
name: 'Checkbox',
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const actions = [
2+
{ label: 'Play', icon: 'play-arrow'},
3+
{ label: 'Close' }
4+
];
5+
6+
const TestCards = () => (
7+
<Card
8+
image='http://pitchfork-cdn.s3.amazonaws.com/longform/221/Deerhunter-Fading-Frontier640.jpg'
9+
text='A Deerhunter album rollout usually coincides with some pithy and provocative statements from Bradford Cox on pop culture...'
10+
title='Deerhunter'
11+
subtitle='Fading Frontier'
12+
color="rgba(0,0,0,.4)"
13+
actions={actions}
14+
/>
15+
);
16+
17+
return <TestCards />;

docs/app/components/preview/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $preview-error-color: #fff;
1111

1212
.content {
1313
flex-grow: 1;
14-
padding: $unit;
14+
margin: 2 * $unit;
1515
}
1616

1717
.error {

0 commit comments

Comments
 (0)