Skip to content

Commit 2237a09

Browse files
committed
add single Statistic example and tests
1 parent 17554f2 commit 2237a09

File tree

7 files changed

+66
-4
lines changed

7 files changed

+66
-4
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+
import _ from 'lodash';
4+
5+
export default class StatisticStatisticExample extends Component {
6+
render() {
7+
const value = _.random(0, 12000).toLocaleString();
8+
9+
return (
10+
<Statistic value={value} label='Value'/>
11+
);
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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/StatisticStatisticExample'
13+
/>
14+
</ExampleSection>
15+
);
16+
}
17+
}

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ 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';
42+
import Statistics from 'src/views/Statistic/Statistics';
4143

4244
export default {
4345
// Addons
@@ -80,4 +82,6 @@ export default {
8082
// Views
8183
Item,
8284
Items,
85+
Statistic,
86+
Statistics,
8387
};

src/views/Statistic/Statistic.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ import META from 'src/utils/Meta';
66
export default class Statistic extends Component {
77
static propTypes = {
88
className: PropTypes.string,
9-
label: PropTypes.node,
10-
value: PropTypes.node,
9+
label: PropTypes.node.isRequired,
10+
value: PropTypes.node.isRequired,
1111
};
1212

1313
static _meta = {
1414
library: META.library.semanticUI,
15-
name: 'Statistics',
15+
name: 'Statistic',
1616
type: META.type.view,
1717
};
1818

1919
render() {
2020
const classes = classNames(
21+
'sd-statistic',
2122
'ui',
2223
this.props.className,
2324
'statistic',

src/views/Statistic/Statistics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class Statistics extends Component {
1717

1818
render() {
1919
const classes = classNames(
20-
'sd-statistic',
20+
'sd-statistics',
2121
'ui',
2222
this.props.className,
2323
'statistic'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import _ from 'lodash';
2+
import React from 'react';
3+
import {Statistic} from 'stardust';
4+
import faker from 'faker';
5+
6+
describe('Statistic', () => {
7+
it('renders value', () => {
8+
const value = faker.hacker.phrase();
9+
render(<Statistic value={value} />).assertText(value);
10+
});
11+
it('renders data', () => {
12+
const data = _.random(0, 10000000);
13+
render(<Statistic data={data} />).assertText(data);
14+
});
15+
});

0 commit comments

Comments
 (0)