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

feat: Add backgroundColor var on LoadingDots #2991

Merged

Conversation

ahayes91
Copy link
Contributor

@ahayes91 ahayes91 commented Oct 21, 2024

Summary

Fixes: #2990

https://canvas.workdaydesign.com/components/indicators/loading-dots/ shows a circle variant for use on gray/dark/image-based backgrounds. Our LoadingDots component styling needed some TLC to allow consumers to set the background color to match this pattern, and our Storybook entries can be updated to show how to achieve this variant.

I also noticed some links to docs were broken in the codebase so I updated that too.

Release Category

Components
Documentation

Release Note

Adds capability to LoadingDots to accept a loadingDotColor prop to change loading dots color, with the capability to override that var with a stencil - intended for use with the circle variant for dark backgrounds/images, which is now shown in Storybook with Custom Shape story.
Also adds a animationDurationMs prop in the same pattern, with a Custom Color and Animation story in storybook demonstrating the use of both these new props.


Checklist

For the Reviewer

  • PR title is short and descriptive
  • PR summary describes the change (Fixes/Resolves linked correctly)
  • PR Release Notes describes additional information useful to call out in a release message or removed if not applicable
  • Breaking Changes provides useful information to upgrade to this code or removed if not applicable

Where Should the Reviewer Start?

Grab a cuppa and settle in because this is nice and short 🤞

Areas for Feedback? (optional)

  • Code
  • Documentation
  • Testing
  • Codemods

Testing Manually

To test this, run yarn start locally with this branch and test out the LoadingDots stories to make sure they're still a-ok

Screenshots or GIFs (if applicable)

Screen.Recording.2024-10-31.at.09.56.21.mov

Thank You Gif (optional)

Tom Hanks waving

@ahayes91 ahayes91 changed the title Update LoadingDots a11y example to more closely match designs feat: Update LoadingDots a11y example to more closely match designs, with capability to change backgroundColor of the loading dots Oct 21, 2024
@ahayes91 ahayes91 changed the base branch from master to prerelease/minor October 21, 2024 12:01
Copy link

cypress bot commented Oct 21, 2024

Workday/canvas-kit    Run #7965

Run Properties:  status check passed Passed #7965  •  git commit f66259bf38 ℹ️: Merge 37f0f71222f09d29e4a6805e56930a3e8ab2ed7f into d5be4cb8b7153fd97fb8c3301e83...
Project Workday/canvas-kit
Branch Review loading-dots-a11y-example
Run status status check passed Passed #7965
Run duration 03m 56s
Commit git commit f66259bf38 ℹ️: Merge 37f0f71222f09d29e4a6805e56930a3e8ab2ed7f into d5be4cb8b7153fd97fb8c3301e83...
Committer Aislinn Hayes
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 30
Tests that did not run due to a developer annotating a test with .skip  Pending 24
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 1092
View all changes introduced in this branch ↗︎
UI Coverage  21.86%
  Untested elements 1624  
  Tested elements 452  
Accessibility  99.18%
  Failed rules  5 critical   5 serious   0 moderate   2 minor
  Failed elements 177  

@ahayes91 ahayes91 changed the title feat: Update LoadingDots a11y example to more closely match designs, with capability to change backgroundColor of the loading dots feat: Update LoadingDots a11y example to cover circle variant design, with capability to change backgroundColor of the loading dots Oct 21, 2024
@ahayes91 ahayes91 changed the title feat: Update LoadingDots a11y example to cover circle variant design, with capability to change backgroundColor of the loading dots feat: Add capability to change backgroundColor of the dots on LoadingDots, and update a11y example to cover circle variant design Oct 21, 2024
@ahayes91 ahayes91 marked this pull request as ready for review October 21, 2024 13:48
@josh-bagwell josh-bagwell changed the title feat: Add capability to change backgroundColor of the dots on LoadingDots, and update a11y example to cover circle variant design feat: Add backgroundColor var on LoadingDots Oct 22, 2024
@mannycarrera4
Copy link
Contributor

Have a few thoughts on how we can improve this!

Using data-part

We've been trying to move towards having one stencil per component if possible and using data-part to style sub elements. Since LoadingDots doesn't have any sub components, we can still give access to those lower level elements via styling.

Instead of having LoadingAnimationDot we can just render a div with a data-part:

export const LoadingDots = createComponent('div')({
  displayName: 'LoadingDots',
  Component: (
    {backgroundColor, animationDurationMs, ...elemProps}: LoadingDotsProps,
    ref,
    Element
  ) => {
    return (
      <Element
        ref={ref}
        {...handleCsProp(elemProps, loadingDotsStencil({backgroundColor, animationDurationMs}))}
      >
        <div data-part="loading-animation-dot" />
        <div data-part="loading-animation-dot" />
        <div data-part="loading-animation-dot" />
      </Element>
    );
  },
});

Less components, cleaning up code, nice!

Targeting parts within the parent stencil

Now that we've removed some code, we need to update our stencil to style these elements

export const loadingDotsStencil = createStencil({
  vars: {
    animationDurationMs: '40ms',
    backgroundColor: system.color.bg.alt.strong,
  },
  base: ({backgroundColor, animationDurationMs}) => ({
    display: 'inline-flex',
    gap: system.space.x2,
    '& [data-part="loading-animation-dot"]': {
      backgroundColor,
      width: system.space.x4,
      height: system.space.x4,
      fontSize: system.space.zero,
      borderRadius: system.shape.round,
      transform: 'scale(0)',
      display: 'inline-block',
      animationName: keyframesLoading,
      animationDuration: calc.multiply(animationDurationMs, 35),
      animationIterationCount: 'infinite',
      animationTimingFunction: 'ease-in-out',
      animationFillMode: 'both',
      '&:nth-child(1)': {
        animationDelay: '0ms',
      },
      '&:nth-child(2)': {
        animationDelay: calc.multiply(animationDurationMs, 4),
      },
      '&:nth-child(3)': {
        animationDelay: calc.multiply(animationDurationMs, 8),
      },
    },
  }),
});

Notice how we target our sub elements with & [data-part="loading-animation-dor"]. Because we need these to be dynamic in color, we use the callback function to pass in our css variables at the start of base: ({backgroundColor, animationDuractionMs}) => ({}). Notice how we pass that to our stencil in the render function of the component up above.

API Suggestions

  • Maybe instead of naming the prop backgroundColor we change it to something like loadingDotColor.
  • We can make this even more flexible by adding animationDurationMs to the props so consumers can change the duration if they'd like.
  • We can now update the storybook example to reflect how you can style this component something like:
const loadingStencil = createStencil({
  base: {
    borderRadius: system.shape.round,
    backgroundColor: system.color.bg.overlay,
    height: 80,
    width: 80,
    alignItems: 'center',
    justifyContent: 'center',
    display: 'flex',
    [loadingDotsStencil.vars.backgroundColor]: 'red',
    [loadingDotsStencil.vars.animationDurationMs]: '100ms',
  },
});

export const CircleVariant = () => {
  return (
    <div className={styleOverrides.parentContainer}>
      <LoadingDots cs={loadingStencil()} />
    </div>
  );
};

@ahayes91
Copy link
Contributor Author

Looks great @mannycarrera4 ! One more question - should we show the use of the prop itself in Storybook too? Or keep the example of the stencil override as the default?

@@ -30,3 +32,9 @@ export const RTL: Story = {
export const Accessible: Story = {
render: AccessibleExample,
};
export const DarkBackgrounds: Story = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This story looks like it's the custom shape once since you're putting it in a circle, let's rename this CustomShape

alignItems: 'center',
justifyContent: 'center',
display: 'flex',
[loadingDotsStencil.vars.loadingDotColor]: system.color.bg.alt.strong,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think by default this is the color of the loading dots, so no need to showcase that here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my bad, this is supposed to be system.color.icon.inverse for the circle variant design!

Copy link
Contributor

@mannycarrera4 mannycarrera4 left a comment

Choose a reason for hiding this comment

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

Nice work on this! Thanks for making our dev experience better!

@alanbsmith alanbsmith merged commit 2ad2b08 into Workday:prerelease/minor Nov 1, 2024
18 of 19 checks passed
@ahayes91 ahayes91 deleted the loading-dots-a11y-example branch November 1, 2024 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants