-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7a6c346
scaffold Statistic and Statistics components
levithomason 05f0d7e
remove incorrect Statistic _meta.parent property
levithomason 17554f2
clean up copy pasta
levithomason 2237a09
add single Statistic example and tests
levithomason 50c9632
add Statistics test, stringify data prop on Statistic test
levithomason f80304f
add group example, use sub-components for statistic parts
levithomason 0443118
fix Statistic sub-component names
levithomason e4cce0b
do not destructure simple Statistic component examples
levithomason File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
docs/app/Examples/views/Statistic/Types/StatisticStatisticExample.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'/> | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The actual rendered example. |
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
docs/app/Examples/views/Statistic/Types/StatisticTypesExamples.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -80,4 +82,6 @@ export default { | |
// Views | ||
Item, | ||
Items, | ||
Statistic, | ||
Statistics, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Included both the single component and it's plural grouping component. |
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?