Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Statistic and Statistics components #117

Merged
merged 8 commits into from
Nov 24, 2015
12 changes: 12 additions & 0 deletions docs/app/Examples/views/Statistic/StatisticExamples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React, {Component} from 'react';
import StatisticTypesExamples from './Types/StatisticTypesExamples';

export default class StatisticExamples extends Component {
render() {
return (
<div>
<StatisticTypesExamples />
</div>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single basic example, just to prove the component. Extended examples can be added on a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the <div> here?

);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, {Component} from 'react';
import {Statistic} from 'stardust';
import _ from 'lodash';

export default class StatisticStatisticExample extends Component {
render() {
const value = _.random(0, 12000).toLocaleString();

return (
<Statistic value={value} label='Value'/>
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual rendered example.

}
}
17 changes: 17 additions & 0 deletions docs/app/Examples/views/Statistic/Types/StatisticTypesExamples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, {Component} from 'react';
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample';
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection';

export default class StatisticTypesExamples extends Component {
render() {
return (
<ExampleSection title='Types'>
<ComponentExample
title='Statistic'
description='A statistic can display a value with a label above or below it.'
examplePath='views/Statistic/Types/StatisticStatisticExample'
/>
</ExampleSection>
);
}
}
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import Dropdown from 'src/modules/Dropdown/Dropdown';
// Views
import Item from 'src/views/Items/Item';
import Items from 'src/views/Items/Items';
import Statistic from 'src/views/Statistic/Statistic';
import Statistics from 'src/views/Statistic/Statistics';

export default {
// Addons
Expand Down Expand Up @@ -80,4 +82,6 @@ export default {
// Views
Item,
Items,
Statistic,
Statistics,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included both the single component and it's plural grouping component.

};
40 changes: 40 additions & 0 deletions src/views/Statistic/Statistic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, {Component, PropTypes} from 'react';
import classNames from 'classnames';
import getUnhandledProps from 'src/utils/getUnhandledProps';
import META from 'src/utils/Meta';

export default class Statistic extends Component {
static propTypes = {
className: PropTypes.string,
label: PropTypes.node.isRequired,
value: PropTypes.node.isRequired,
};

static _meta = {
library: META.library.semanticUI,
name: 'Statistic',
type: META.type.view,
};

render() {
const classes = classNames(
'sd-statistic',
'ui',
this.props.className,
'statistic',
);

const props = getUnhandledProps(this);

return (
<div {...props} className={classes}>
<div className='value'>
{this.props.value}
</div>
<div className='label'>
{this.props.label}
</div>
</div>
);
}
}
31 changes: 31 additions & 0 deletions src/views/Statistic/Statistics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, {Component, PropTypes} from 'react';
import classNames from 'classnames';
import META from 'src/utils/Meta';

export default class Statistics extends Component {
static propTypes = {
children: PropTypes.node,
className: PropTypes.string,
};

static _meta = {
library: META.library.semanticUI,
name: 'Statistics',
type: META.type.view,
parent: 'Statistic'
};

render() {
const classes = classNames(
'sd-statistics',
'ui',
this.props.className,
'statistic'
);
return (
<div {...this.props} className={classes}>
{this.props.children}
</div>
);
}
}
15 changes: 15 additions & 0 deletions test/specs/views/Items/Statistic-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import _ from 'lodash';
import React from 'react';
import {Statistic} from 'stardust';
import faker from 'faker';

describe('Statistic', () => {
it('renders value', () => {
const value = faker.hacker.phrase();
render(<Statistic value={value} />).assertText(value);
});
it('renders data', () => {
const data = _.random(0, 10000000).toLocaleString();
render(<Statistic data={data} />).assertText(data);
});
});
11 changes: 11 additions & 0 deletions test/specs/views/Items/Statistics-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import {Statistics} from 'stardust';
import faker from 'faker';

describe('Statistics', () => {
it('renders children', () => {
const child = faker.hacker.phrase();
render(<Statistics>{child}</Statistics>)
.assertText(child);
});
});