-
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
Update Statistic to v1 API #334
Update Statistic to v1 API #334
Conversation
…into feature/rail
Refers #269 |
What about this? <Statistic label='Faves' value='22' /> |
Current coverage is 92.47%@@ master #334 diff @@
==========================================
Files 62 62
Lines 777 797 +20
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 711 737 +26
+ Misses 66 60 -6
Partials 0 0
|
API looks great. The simplified props version look right as well: <Statistic label='Faves' value='22' /> We probably just accept the limitation that using props only like this will generate markup with the value on top and the label on bottom. I assume this is the most common configuration. Any intuitive ideas on how to allow reordering label/value with the props API? |
What about boolean |
What about short syntax for label and value? <Statistic.Label text='Faves' />
<Statistic.Value text='22' /> UPD: |
I've implemented all features, added tests and docs. @levithomason wait for feedback 😄 |
After thinking it through, I think we should just provide a single layout, value on top, label on bottom. If a user wants more control, they can use the sub components. This seems to be the cleanest solution, for now.
Nice catch, I never saw the Perhaps add a TODO in each component to find a shorthand prop for each that is not |
Some more ideas on props for Statistic sub components. The Statistic already accepts <Statistic.Value value={99} />
<Statistic.Label label='Likes' /> Regarding label/value order for Statistic shorthand props, React props are order dependent. As noted in the React docs:
So we could simply do this: <Statistic label='Label first' value={3} />
<Statistic value={99} label='Label last' /> See it in action here: http://www.react.run/HJxagQKP/2 |
return (<div className={classes} {...rest}> | ||
<Statistic.Value text={text}>{value}</Statistic.Value> | ||
<Statistic.Label>{label}</Statistic.Label> | ||
</div>) |
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.
Since props are applied in order, we need to spread the rest
before applying the className. The classes
includes the user's className values. If we apply the rest
after the classes
, then their classNames will override the classes
we've built up.
Also, I think the linter should have caught this but let's return multiline JSX like this:
return (
<div {...rest} className={classes}>
<Statistic.Value text={text}>{value}</Statistic.Value>
<Statistic.Label>{label}</Statistic.Label>
</div>
)
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.
itemsJSX.push(<Statistic key={key} {...item} />) | ||
}) | ||
|
||
return <div className={classes} {...rest}>{itemsJSX}</div> |
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.
As noted in Statistic, spread before applying className to prevent user's className from overriding the className build up.
Conformance tests ensure props are spread, I should add a test to ensure className is not override during spread ;)
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.
Have to correct myself here, while this is true regarding prop order rest
actually does not include className in this example. That is because the className prop is being handled in the propTypes, so getUnhandledProps
is returning an object of props that does not include className
.
Let's still spread them first, and I'm adding the common test now. I just wanted to point out that this would actually work as is and my original comment was incorrect.
import StatisticGroup from 'src/views/Statistic/StatisticGroup' | ||
|
||
describe('StatisticGroup', () => { | ||
common.isConformant(StatisticGroup) | ||
common.hasUIClassName(StatisticGroup) | ||
common.rendersChildren(StatisticGroup) | ||
common.propKeyOnlyToClassName(StatisticGroup, 'horizontal') | ||
common.propValueOnlyToClassName(StatisticGroup, 'widths') |
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.
This test is mostly accurate, but not entirely. Consider when a user passes widths='3'
, the value '3'
is not actually added to the className, the word three
is.
We should likely add a common test for implementsNumberToWordProp(Statistic, 'widths')
. This test would assert that the numberToWord
value is added to the className
. It would also assert that it works with numbers, strings, and number words (i.e. 'two').
The reason I think we should allow the second param to this common tests is that on other components, like FormFields
, the numerToWord
prop is width
. This way, we can point this test to a specific prop name.
I've created Need fix for |
Oh boy, yep. That isn't good nor intuitive. Let's not sort. |
I'll be tied up the next couple hours. Will check on the rest then. Thanks much for all the refactors and rapid responses! |
It seems that |
Whoops, missed this one. Checking... |
Rebase and give this a shot. TechnologyAdvice/stardust@c5b0425 Tested on this branch and master. It uses the plural name of the parent for componentClassName on sub component groups. So, |
…into fix/statistic
Seems it works 👍 Waiting for review |
On it |
* (feat) Rail Semantic-Org#181 * (feat) Rail Semantic-Org#181 * (feat) Rail docs Semantic-Org#181 * (fix) Sort Rail props Semantic-Org#181 * (fix) Rail review fixes Semantic-Org#181 * (fix) Rail review fixes Semantic-Org#181 * (fix) Rail review fixes Semantic-Org#181 * (fix) Rail sizes Semantic-Org#181 * (fix) Rail sizes in docs Semantic-Org#181 * (fix) Statistic * (feat) Statistic Item * (feat) Statistic Label and Value * (feat) Statistic Group * (fix) Statistic fix sizes * (fix) Statistic functionality * (fix) Statistic docs * (fix) Statistic lint fixes * (fix) Statistic tests * (Statistic) Remove shorthands * (utils) Update numberToWord * (Statistic) Fix returned JSX * (utils) Update numberToWord, fix imports * (Statistic) Update widths usage * (Statistic) Fix JSDoc * (Statistic) Update `rest` prop * (utils) implementsNumberToWordProp test * (Statistic) Test update * fix(Statistic) Fix example
API
Types
Statistic
A statistic can display a value with a label above or below it.
Statistic Group
A group of statistics
Content
Value
A statistic can contain a numeric, icon, image, or text value
Label
A statistic can contain a label to help provide context for the presented value
Already showed
Variations
Horizontal Statistic
A statistic can present its measurement horizontally
Colored
A statistic can be formatted to be different colors
Inverted
A statistic can be formatted to fit on a dark background
Evenly Divided
A statistic group can have its items divided evenly
Will be taken from #183
Floated
An statistic can sit to the left or right of other content
Size
A statistic can vary in size