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

Progress Bar Component #99

Merged
merged 17 commits into from
Nov 30, 2023
Merged

Progress Bar Component #99

merged 17 commits into from
Nov 30, 2023

Conversation

zwkohn
Copy link
Contributor

@zwkohn zwkohn commented Aug 7, 2023

Overview

This adds a Progress Bar component to the library
Screenshot 2023-08-24 at 1 49 12 PM

The parameters are
Screenshot 2023-11-30 at 3 50 22 PM

Security

REMINDER: All file contents are public.

  • I have ensured no secure credentials or sensitive information remain in code, metadata, comments, etc.
    • Please verify that you double checked that .storybook/preview.js does not contain your participant access key details.
    • There are no temporary testing changes committed such as API base URLs, access tokens, print/log statements, etc.
  • These changes do not introduce any security risks, or any such risks have been properly mitigated.

Describe briefly what security risks you considered, why they don't apply, or how they've been mitigated.

Checklist

Testing

Documentation

  • I have added relevant Storybook updates to this PR as well.
  • If this feature requires a developer doc update, tag @CareEvolution/api-docs.

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:

  • Subject-matter experts
  • Style/editing reviewers
  • Others requested by the content owner

@chrisnowak
Copy link
Contributor

Few thoughts:

  • I think we want to name this a lot more narrowly; e.g. "IncentivesProgressBar"; or honestly just "ProgressBar" since it may not always be in the context of incentives but could work for goal setting etc.
  • We should do a bit of a review of other incentives progress bars we have done for other studies...e.g. PROGRESS...may suggest different options or look/feel. PROGRESS may be the gold standard here in some ways
    image - I would see if we can track a bit more to that look / feel
  • Would suggest we do not have an "increment" or anything...but rather we should leave this as a presentational component and have:
    • background (string that does into CSS background prop; could be color or gradient)
    • fill (string that does into CSS background prop of the fill layer; could be color or gradient)
    • fillPercent (how wide the fill bar is): 0 to 100
    • steps[] e.g. the placement of the various icons...each of these would have
      • stepPercent: number 0 to 100 for where the step should be placed on the progress bar
      • a react element for the thing that should be displayed on the step...could be an icon or something...
        image

Then I think maybe another component for "IncentiveProgressBarStepIcon" that has some options like a $$ amount that you can use in the "step" array...

@ajmenca
Copy link
Collaborator

ajmenca commented Aug 9, 2023

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.

image
image

image
image

  • I think that for both the AoU and Progress designs, having the right side of the fill bar be curved looks really nice, I think we should integrate that.
  • I think both of these designs also animate the bar when the percentage changes; that's definitely a feature we should have. There's also some subtle animations that the AoU Bar has; if you hit 100%, the bar animates to the top, and then the star icon changes from gray to orange. This is also a really nice effect that looks polished.
  • In your screenshots, it looks like some things might need to get adjusted left/right by a pixel or so. There's some aliasing between the circle of the "100" and the blue border, and also in the second screenshot there's some white pixels leaking through on the left side of the completion bar.

@bxh
Copy link
Contributor

bxh commented Aug 15, 2023

AOU clearly has more than one kind of progress bar in mind.

Screenshot 2023-08-15 160615

@zwkohn zwkohn changed the title Incentives component Progress Bar Component Aug 28, 2023
@zwkohn zwkohn marked this pull request as ready for review November 27, 2023 20:57
@Suvarna-Thejas-CE
Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor Author

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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)

Copy link
Contributor

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

Copy link
Contributor

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",
Copy link
Contributor

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",
Copy link
Contributor

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" },
Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Contributor

@chrisnowak chrisnowak Nov 28, 2023

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 {
Copy link
Contributor

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'
Copy link
Contributor

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

@zwkohn zwkohn requested a review from chrisnowak November 30, 2023 15:10

.mdhui-progress-bar .mdhui-progress-bar-background {
border-radius: 500px;
border-width: var(--icon_border_width) ;
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

i would probably drop the border because it makes it look a bit awkward when stuff overlaps it:
Screenshot 2023-11-30 at 2 04 36 PM

--icon_border_width: 2px;
}

.mdhui-progress-bar .mdhui-progress-bar-default-margin {
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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>;
Copy link
Contributor

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"
Copy link
Contributor

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

Copy link
Contributor

@chrisnowak chrisnowak left a comment

Choose a reason for hiding this comment

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

Looks good!

@zwkohn zwkohn merged commit 959c676 into main Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants