Skip to content

Commit f80304f

Browse files
committed
add group example, use sub-components for statistic parts
1 parent 50c9632 commit f80304f

File tree

12 files changed

+179
-44
lines changed

12 files changed

+179
-44
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, {Component} from 'react';
2+
import {Statistic} from 'stardust';
3+
const {Label, Value} = Statistic;
4+
5+
export default class StatisticBottomLabelExample extends Component {
6+
render() {
7+
return (
8+
<Statistic>
9+
<Value>5,550</Value>
10+
<Label>Downloads</Label>
11+
</Statistic>
12+
);
13+
}
14+
}

docs/app/Examples/views/Statistic/Types/StatisticStatisticExample.js

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, {Component} from 'react';
2+
import {Statistic} from 'stardust';
3+
const {Statistics, Label, Value} = Statistic;
4+
5+
export default class StatisticStatisticsExample extends Component {
6+
render() {
7+
return (
8+
<Statistics>
9+
<Statistic>
10+
<Value>22</Value>
11+
<Label>Faves</Label>
12+
</Statistic>
13+
<Statistic>
14+
<Value>31,200</Value>
15+
<Label>Views</Label>
16+
</Statistic>
17+
<Statistic>
18+
<Value>22</Value>
19+
<Label>Members</Label>
20+
</Statistic>
21+
</Statistics>
22+
);
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, {Component} from 'react';
2+
import {Statistic} from 'stardust';
3+
const {Label, Value} = Statistic;
4+
5+
export default class StatisticTopLabelExample extends Component {
6+
render() {
7+
return (
8+
<Statistic>
9+
<Label>Views</Label>
10+
<Value>40,509</Value>
11+
</Statistic>
12+
);
13+
}
14+
}

docs/app/Examples/views/Statistic/Types/StatisticTypesExamples.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ export default class StatisticTypesExamples extends Component {
99
<ComponentExample
1010
title='Statistic'
1111
description='A statistic can display a value with a label above or below it.'
12-
examplePath='views/Statistic/Types/StatisticStatisticExample'
12+
examplePath='views/Statistic/Types/StatisticBottomLabelExample'
13+
/>
14+
<ComponentExample
15+
examplePath='views/Statistic/Types/StatisticTopLabelExample'
16+
/>
17+
<ComponentExample
18+
title='Statistic Group'
19+
description='A group of statistics'
20+
examplePath='views/Statistic/Types/StatisticStatisticsExample'
1321
/>
1422
</ExampleSection>
1523
);

src/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import Dropdown from 'src/modules/Dropdown/Dropdown';
3939
import Item from 'src/views/Items/Item';
4040
import Items from 'src/views/Items/Items';
4141
import Statistic from 'src/views/Statistic/Statistic';
42-
import Statistics from 'src/views/Statistic/Statistics';
4342

4443
export default {
4544
// Addons
@@ -83,5 +82,4 @@ export default {
8382
Item,
8483
Items,
8584
Statistic,
86-
Statistics,
8785
};

src/views/Statistic/Label.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, {Component, PropTypes} from 'react';
2+
import classNames from 'classnames';
3+
import getUnhandledProps from 'src/utils/getUnhandledProps';
4+
import META from 'src/utils/Meta';
5+
6+
export default class Statistic extends Component {
7+
static propTypes = {
8+
children: PropTypes.node.isRequired,
9+
className: PropTypes.string,
10+
};
11+
12+
static _meta = {
13+
library: META.library.semanticUI,
14+
name: 'StatisticLabel',
15+
type: META.type.view,
16+
parent: 'Statistic',
17+
};
18+
19+
render() {
20+
const classes = classNames(
21+
'sd-statistic-label',
22+
this.props.className,
23+
'label',
24+
);
25+
26+
const props = getUnhandledProps(this);
27+
28+
return (
29+
<div {...props} className={classes}>
30+
{this.props.children}
31+
</div>
32+
);
33+
}
34+
}

src/views/Statistic/Statistic.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
import React, {Component, PropTypes} from 'react';
1+
import _ from 'lodash';
22
import classNames from 'classnames';
3+
import React, {Children, Component, PropTypes} from 'react';
34
import getUnhandledProps from 'src/utils/getUnhandledProps';
45
import META from 'src/utils/Meta';
56

7+
import Statistics from './Statistics';
8+
import Label from './Label';
9+
import Value from './Value';
10+
611
export default class Statistic extends Component {
712
static propTypes = {
13+
children: (props, propName, componentName) => {
14+
let isValid = true;
15+
Children.forEach(props.children, (child) => {
16+
if (!_.includes([Statistics, Label, Value], child.type)) {
17+
isValid = false;
18+
}
19+
});
20+
if (!isValid) {
21+
return new Error('`Statistic` must only have `Label` or `Value` children.');
22+
}
23+
},
824
className: PropTypes.string,
9-
label: PropTypes.node.isRequired,
10-
value: PropTypes.node.isRequired,
1125
};
1226

1327
static _meta = {
@@ -16,6 +30,10 @@ export default class Statistic extends Component {
1630
type: META.type.view,
1731
};
1832

33+
static Statistics = Statistics;
34+
static Label = Label;
35+
static Value = Value;
36+
1937
render() {
2038
const classes = classNames(
2139
'sd-statistic',
@@ -28,12 +46,7 @@ export default class Statistic extends Component {
2846

2947
return (
3048
<div {...props} className={classes}>
31-
<div className='value'>
32-
{this.props.value}
33-
</div>
34-
<div className='label'>
35-
{this.props.label}
36-
</div>
49+
{this.props.children}
3750
</div>
3851
);
3952
}

src/views/Statistic/Statistics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class Statistics extends Component {
2020
'sd-statistics',
2121
'ui',
2222
this.props.className,
23-
'statistic'
23+
'statistics'
2424
);
2525
return (
2626
<div {...this.props} className={classes}>

src/views/Statistic/Value.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, {Component, PropTypes} from 'react';
2+
import classNames from 'classnames';
3+
import getUnhandledProps from 'src/utils/getUnhandledProps';
4+
import META from 'src/utils/Meta';
5+
6+
export default class Statistic extends Component {
7+
static propTypes = {
8+
children: PropTypes.node.isRequired,
9+
className: PropTypes.string,
10+
};
11+
12+
static _meta = {
13+
library: META.library.semanticUI,
14+
name: 'StatisticValue',
15+
type: META.type.view,
16+
parent: 'Statistic',
17+
};
18+
19+
render() {
20+
const classes = classNames(
21+
'sd-statistic-value',
22+
this.props.className,
23+
'value',
24+
);
25+
26+
const props = getUnhandledProps(this);
27+
28+
return (
29+
<div {...props} className={classes}>
30+
{this.props.children}
31+
</div>
32+
);
33+
}
34+
}

0 commit comments

Comments
 (0)