-
Notifications
You must be signed in to change notification settings - Fork 2
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
Progress Bar Component #99
Conversation
A couple of reference points from recent work on AoU Rewards. They use two variations of this kind of idea; one shows progress "in" level progression, the other shows progress across the entire reward program.
|
I like the idea of making this just a pure progress bar. I created an issue #162 that could be a wrapper around this component that has labels/text that make it useful for a specific use case. This one I think would be good with the parameters that Chris suggested above. |
@@ -0,0 +1,50 @@ | |||
.progress-bar { |
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.
Should prefix all CSS classes with .mdhui-, so this should be .mdhui-progress-bar
I would also nest all classes in this file under that - so for the fill it shuold be .mdhui-progress-bar .mdhui-progress-bar-fill
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.
(alternative to consider at some point is using CSS modules; but so far we haven't taken that leap and CSS is still being overridden in places)
@@ -0,0 +1,50 @@ | |||
.progress-bar { | |||
display:inline-block; | |||
margin: 10px 0px; |
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.
Would remove the margin on this
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.
removed. I realize now that the reason this was there was to compensate for the way storybook is set to hide overflow.
@@ -0,0 +1,50 @@ | |||
.progress-bar { | |||
display:inline-block; |
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.
Why inline-block? I think we would want this to be block?
display:inline-block; | ||
margin: 10px 0px; | ||
width: 100%; | ||
max-width: 500px; |
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.
Why a max-width? Will look awkward on desktop so I would remove
|
||
.progress-bar-fill { | ||
position: absolute; | ||
min-height: 1px; |
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.
Seems like some autoformatting is off in this file
fillPercent: number; | ||
steps?: [ | ||
{ | ||
stepPercent: number; |
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.
"step" prefix here seems unnecessary since this will be in a "steps" array; so would just go with percent/icon
import React, { ReactElement, useEffect } from "react"; | ||
|
||
export interface ProgressBarProps { | ||
background?: string; |
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.
We use color suffix for color properties, so would use backgroundColor and fillColor.
Also would make both background/fill a ColorDefinition and not a string - that was probably introduced after this PR but see the button component for an example (ColorDefinition allows specifying 2 colors, one for light mode and one for dark mode)
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.
Oh hmm, i'm realizing that fill might actually be a gradient...yet let me think about that for a sec
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.
Nevermind, I think it does't matter too much actually. Should still use ColorDefinition which just ends up being 2 strings so you could specify 2 gradients theoretically. Currently view builder doesn't let you configure a gradient but that's something we could look at adding
|
||
ProgressBar.defaultProps = { | ||
background: "#d3d3d3", | ||
fill: "#00A862", |
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 would probably have the default fill be var(--mdhui-color-primary)
} | ||
|
||
ProgressBar.defaultProps = { | ||
background: "#d3d3d3", |
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.
Would have this be the closest CSS backround color var from the globalCss file
layout: 'auto', | ||
}, | ||
argTypes: { | ||
background: { control: 'color', description: "The background color of the progress bar" }, |
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.
Documentation! Awesome. Need to start doing that...
|
||
.progress-bar .step-icon { | ||
position: absolute; | ||
transform: translate(-100%, 0) |
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 does make things a bit awkward if you have a stop near the beginning of the progress bar - it will get clipped out...there's no way to have a stop at 0 reliably I think (since steps are based on percent).
That being said, this seems like the best and most reasonable solution to this and, as demonstrated by the stories, works pretty well. I don't think having a stop right at the beginning makes a ton of sense
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 someone using this could always fix that by having the element at the beginning have a left margin or something
transform: translate(-100%, 0) | ||
} | ||
|
||
.progress-bar .step-icon span { |
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 wouldn't assume a span will be used as the child element...
So there is actually some cool stuff you did in the story here for the various little star icons and how they are colored etc.
I would not just waste that in a story but would actually invest in a separate component called "ProgressBarStep"...it could be exported under the progress bar...such that we have some out of box progress bar steps that can be placed on this (but someone could also come up with their own to supply to this).
and the props could be like:
- borderColor?: ColorDefinition
- backgroundColor: ColorDefinition
- children (this is where you'd put in the font awesome icon for the star, or the text 75 or whatnot)
- height (based on this it would auto-calculate the top margin to center itself vertically, e.g. for the large star)
e.g. for the big star at the end your step would be like:
steps: [{
stepPercent: 100,
stepIcon: <ProgressBarStep borderColor="yellow" backgroundColor="orange" height="24px">
<FontAwesomeIcon icon={faStar} style={{ color: "yellow" }} />
</ProgressBarStep>
}],
Basically to have to limit the amount of work someone has to do to get it to look like the storybook, while still allowing some flexibility
@@ -0,0 +1 @@ | |||
export { default as ProgressBar } from './ProgressBar' |
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.
You'll want to also export this from presentational/index.ts
|
||
.mdhui-progress-bar .mdhui-progress-bar-background { | ||
border-radius: 500px; | ||
border-width: var(--icon_border_width) ; |
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.
Huh...did you just add a border to this? I didn't think there was a border before
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.
But the border width is added to the width so it ends up overflowing 100% width
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.
--icon_border_width: 2px; | ||
} | ||
|
||
.mdhui-progress-bar .mdhui-progress-bar-default-margin { |
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.
Looks like this isn't working because you have a space between these and this class is applied to the progress bar itself.
Also, you will need to adjust the width like we do for buttons so it's width:calc(100% - 32px)
, otherwise it overflows
@@ -0,0 +1,3 @@ | |||
.sb-story { |
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.
What does this CSS do?
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.
Trying to get some padding in the storybook component. I replaced this with an extra div in the Template
const Template: StoryFn<typeof ProgressBar> = (args: ProgressBarProps) => <Layout colorScheme="auto"><div style={{padding: "35px 0"}}><ProgressBar {...args} /></div></Layout>;
} | ||
} as Meta<typeof ProgressBar>; | ||
|
||
const Template: StoryFn<typeof ProgressBar> = (args: ProgressBarProps) => <Layout colorScheme="auto"><ProgressBar {...args} /></Layout>; |
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.
Minor, maybe put "defaultMargin" on this so it's spaced out from the edges
export { default as ProgressRing } from "./ProgressRing" | ||
export { default as ProgressBar } from "./ProgressBar" | ||
export { default as ProgressBarStep } from "./ProgressBar/ProgressBarStep" |
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.
Minor but I have attempted to keep this file alphabetical
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.
Looks good!
Overview
This adds a Progress Bar component to the library
The parameters are
Security
REMINDER: All file contents are public.
Describe briefly what security risks you considered, why they don't apply, or how they've been mitigated.
Checklist
Testing
Documentation
Consider "Squash and merge" as needed to keep the commit history reasonable on
main
.Reviewers
Assign to the appropriate reviewer(s). Minimally, a second set of eyes is needed ensure no non-public information is published. Consider also including: