-
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
breaking(Progress): control progress solely with progress #1355
breaking(Progress): control progress solely with progress #1355
Conversation
2056b84
to
6a7a830
Compare
src/modules/Progress/Progress.js
Outdated
@@ -140,10 +140,9 @@ class Progress extends Component { | |||
} | |||
|
|||
showProgress = () => { | |||
const { label, precision, progress, total, value } = this.props | |||
const { label, precision, progress } = this.props | |||
|
|||
if (label || progress || !_.isUndefined(precision)) return true |
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.
Let's make this condition more simple:
-if (label || progress || !_.isUndefined(precision)) return true
+return label || progress || !_.isUndefined(precision)
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.
Sure. I noticed it, but I didn't want to make changes that were not directly related to the task. I'll do that now
6a7a830
to
b248a18
Compare
Codecov Report
@@ Coverage Diff @@
## master #1355 +/- ##
=======================================
Coverage 99.74% 99.74%
=======================================
Files 140 140
Lines 2346 2346
=======================================
Hits 2340 2340
Misses 6 6
Continue to review full report at Codecov.
|
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.
@BrainMaestro Thanks for PR 👍
IssueI think we need to rework the relationship of the
Fix ProposalI think we need to make the This would be more inline with our prop-to-subcomponent relationship we have across the entire library as well. Thoughts? |
@levithomason I agree. That makes it clearer. The other way was slightly confusing. |
Awesome. Here are some pointers are how to handle the new propTypes and values. The /** Can be set to either to display progress as percent or ratio. */
label: customPropTypes.itemShorthand,
/** A progress bar can contain a text value indicating current progress. */
progress: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.oneOf(['ratio', 'percent']),
]), The We have a factory function for doing this called, import { createShorthand } from '../../lib' This function takes an element class (string or function), a function to map number/string values to props, and finally the value you want to create an element with (number, string, props object, or another element). Create a const labelElement = createShorthand(
'div', // create a div
val => ({ children: val }), // map string/numbers to children
label, // use the label prop as the value
{ className: 'label' } // default props
) Now, we can conditionally display the -{children && <div className='label'>{children}</div>}
+{children ? <div className='label'>{children}</div> : labelElement} |
b248a18
to
341a036
Compare
Hey @levithomason. Thanks for the task breakdown. I implemented it exactly as you suggested, but the check |
We've updated the code base to use |
Okay has it been merged in? |
src/modules/Progress/Progress.js
Outdated
</div> | ||
)} | ||
</div> | ||
{children && <div className='label'>{children}</div>} | ||
{!_.isUndefined(children) ? <div className='label'>{children}</div> : labelElement} |
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 is the line I was talking about. Can I safely change it to {children ? <div className='label'>{children}</div> : labelElement}
without the false positives of 0
failing the truthy check?
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.
- {!_.isUndefined(children) ? <div className='label'>{children}</div> : labelElement}
+ {_.isNil(children) ? this.getLabel() : <div className='label'>{children}</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.
okay the label should take priority over the children? I thought it was the reverse. I will make the change
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.
{_.isNil(children) ? this.getLabel() : <div className='label'>{children}</div>}
{!_.isNil(children) ? <div className='label'>{children}</div> : this.getLabel()}
There conditions do same, but first looks more clear to me.
20957e3
to
206ca0f
Compare
src/modules/Progress/Progress.js
Outdated
</div> | ||
)} | ||
</div> | ||
{children && <div className='label'>{children}</div>} | ||
{!_.isNil(children) ? <div className='label'>{children}</div> : this.getLabel()} |
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.
I think we can move this condition to getLabel
:
- getLabel = () => {
- const { label } = this.props
-
- return createShorthand(
- 'div',
- val => ({ children: val }),
- label,
- { className: 'label' }
- )
- }
+ renderLabel = () => {
+ const { children, label } = this.props
+
+ if(!_.isNil(children)) return <div className='label'>{children}</div>
+ return createShorthand(
+ 'div',
+ val => ({ children: val }),
+ label,
+ { className: 'label' }
+ )
+ }
src/modules/Progress/Progress.js
Outdated
@@ -190,11 +195,11 @@ class Progress extends Component { | |||
<div className='bar' style={{ width: `${percent}%` }}> | |||
{this.showProgress() && ( | |||
<div className='progress'> | |||
{ label !== 'ratio' ? `${percent}%` : `${value}/${total}` } | |||
{ progress !== 'ratio' ? `${percent}%` : `${value}/${total}` } | |||
</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.
And this to renderProgress
:
- {this.showProgress() && (
- <div className='progress'>
- { progress !== 'ratio' ? `${percent}%` : `${value}/${total}` }
- </div>
- })
+ {this.renderProgress()}
+ renderProgress = () => {
+ const { precision, progress } = this.props
+
+ if(!progress && _.isUndefined(precision)) return
+ return (
+ <div className='progress'>
+ { progress === 'ratio' ? `${value}/${total}` : `${percent}%` }
+ </div>
+ )
+}
206ca0f
to
463b1f3
Compare
Excellent! |
…emantic-Org#1355) * fix(Progress): do not show progress without progress or label props * style(Progress): some style fixes * style(Progress): update typings * Update Progress.js
Thanks for the great notes @BrainMaestro 👍 |
Released in |
Breaking Changes!
The
label
prop no longer acceptsratio|percent
as a means to control the progress readout on the bar. It now refers to the text label applied to the element. Thechildren
prop takes precedence however.The
progress
prop now handles this by either accepting aboolean
which defaults topercent
or a string with eitherratio
orpercent
.Before
After
Unchanged
Fixes #1352