Skip to content

Commit b4a4df5

Browse files
committed
Merge pull request #117 from TechnologyAdvice/feature/statistic
Add Statistic and Statistics components
2 parents ac379f2 + e4cce0b commit b4a4df5

File tree

11 files changed

+276
-0
lines changed

11 files changed

+276
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React, {Component} from 'react';
2+
import StatisticTypesExamples from './Types/StatisticTypesExamples';
3+
4+
export default class StatisticExamples extends Component {
5+
render() {
6+
return (
7+
<div>
8+
<StatisticTypesExamples />
9+
</div>
10+
);
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React, {Component} from 'react';
2+
import {Statistic} from 'stardust';
3+
4+
export default class StatisticBottomLabelExample extends Component {
5+
render() {
6+
return (
7+
<Statistic>
8+
<Statistic.Label>5,550</Statistic.Label>
9+
<Statistic.Value>Downloads</Statistic.Value>
10+
</Statistic>
11+
);
12+
}
13+
}
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 StatisticGroupExample 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React, {Component} from 'react';
2+
import {Statistic} from 'stardust';
3+
4+
export default class StatisticTopLabelExample extends Component {
5+
render() {
6+
return (
7+
<Statistic>
8+
<Statistic.Label>Views</Statistic.Label>
9+
<Statistic.Value>40,509</Statistic.Value>
10+
</Statistic>
11+
);
12+
}
13+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, {Component} from 'react';
2+
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample';
3+
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection';
4+
5+
export default class StatisticTypesExamples extends Component {
6+
render() {
7+
return (
8+
<ExampleSection title='Types'>
9+
<ComponentExample
10+
title='Statistic'
11+
description='A statistic can display a value with a label above or below it.'
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/StatisticGroupExample'
21+
/>
22+
</ExampleSection>
23+
);
24+
}
25+
}

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import Dropdown from 'src/modules/Dropdown/Dropdown';
3838
// Views
3939
import Item from 'src/views/Items/Item';
4040
import Items from 'src/views/Items/Items';
41+
import Statistic from 'src/views/Statistic/Statistic';
4142

4243
export default {
4344
// Addons
@@ -80,4 +81,5 @@ export default {
8081
// Views
8182
Item,
8283
Items,
84+
Statistic,
8385
};

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 Label 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: 'Label',
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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import _ from 'lodash';
2+
import classNames from 'classnames';
3+
import React, {Children, Component, PropTypes} from 'react';
4+
import getUnhandledProps from 'src/utils/getUnhandledProps';
5+
import META from 'src/utils/Meta';
6+
7+
import Statistics from './Statistics';
8+
import Label from './Label';
9+
import Value from './Value';
10+
11+
export default class Statistic extends Component {
12+
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+
},
24+
className: PropTypes.string,
25+
};
26+
27+
static _meta = {
28+
library: META.library.semanticUI,
29+
name: 'Statistic',
30+
type: META.type.view,
31+
};
32+
33+
static Statistics = Statistics;
34+
static Label = Label;
35+
static Value = Value;
36+
37+
render() {
38+
const classes = classNames(
39+
'sd-statistic',
40+
'ui',
41+
this.props.className,
42+
'statistic',
43+
);
44+
45+
const props = getUnhandledProps(this);
46+
47+
return (
48+
<div {...props} className={classes}>
49+
{this.props.children}
50+
</div>
51+
);
52+
}
53+
}

src/views/Statistic/Statistics.js

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

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 Value 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: 'Value',
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)