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(ActionCard): add loading state with optional animation #1507

Merged
merged 6 commits into from
Feb 3, 2025

Conversation

JoannaSikora
Copy link
Contributor

@JoannaSikora JoannaSikora commented Jan 30, 2025

Resolves: #1234

Description

This pull request introduces a loading state to the ActionCard component, including both default and animated loading styles. It also refactors the existing skeleton loading animation into a reusable mixin.

Storybook

https://feature-1234--613a8e945a5665003a05113b.chromatic.com

Checklist

Obligatory:

  • Self review (use this as your final check for proposed changes before requesting the review)
  • Add correct label
  • Assign pull request with the correct issue

Summary by CodeRabbit

Release Notes: ActionCard Loading State Enhancement

  • New Features

    • Added loading state support for ActionCard component.
    • Introduced isLoading and isLoadingAnimated props.
    • Added new loading state examples in Storybook.
  • Improvements

    • Enhanced visual representation of loading state with new styles.
    • Improved user experience by disabling interactions during loading.
    • Updated loading animations for skeleton components.
  • Testing

    • Added new test cases to verify loading state behavior.

Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

Walkthrough

This pull request introduces a loading state for the ActionCard component across multiple files. The changes include adding isLoading and isLoadingAnimated props, updating the component's rendering logic to handle loading states, modifying styles to support loading animations, and creating a new skeleton loading animation mixin in the animations stylesheet.

Changes

File Change Summary
.../ActionCard/ActionCard.module.scss Added loading state styles and animations
.../ActionCard/ActionCard.spec.tsx Added test for loading state behavior
.../ActionCard/ActionCard.stories.tsx Added stories demonstrating loading states
.../ActionCard/ActionCard.tsx Implemented loading state props and rendering logic
.../ActionCard/types.ts Modified props to include loading states
.../styles/_animations.scss Created skeleton loading animation mixin

Assessment against linked issues

Objective Addressed Explanation
Add skeleton state to Action Card [#1234]

Possibly related PRs

Suggested reviewers

  • vladko-uxds
  • marcinsawicki
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@JoannaSikora JoannaSikora marked this pull request as ready for review January 30, 2025 10:36
@JoannaSikora JoannaSikora added the feature New feature or request label Jan 30, 2025

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 7 changed files in this pull request and generated no comments.

Files not reviewed (3)
  • packages/react-components/src/components/ActionCard/ActionCard.module.scss: Language not supported
  • packages/react-components/src/components/Skeleton/Skeleton.module.scss: Language not supported
  • packages/react-components/src/styles/_animations.scss: Language not supported
Comments suppressed due to low confidence (1)

packages/react-components/src/components/ActionCard/ActionCard.spec.tsx:77

  • The test case should also check for the presence of the loading indicator to ensure the loading state is correctly displayed.
it('should display loading state when isLoading is true', () => {
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (6)
packages/react-components/src/components/ActionCard/ActionCard.tsx (3)

57-59: Enhance accessibility during loading state.

Consider adding aria-busy="true" when loading to improve screen reader experience.

 role={isLoading ? 'presentation' : 'button'}
 aria-label="Action Card"
+aria-busy={isLoading}
 tabIndex={isLoading ? -1 : 0}

29-29: Extract loading state check to a helper function.

The loading check is duplicated in both handlers.

+const isInteractionDisabled = () => isLoading;
+
 const handleOnClick = (e: MouseEvent<HTMLDivElement>) => {
-  if (isLoading) return;
+  if (isInteractionDisabled()) return;
   // ...
 };

 const handleOnKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
-  if (isLoading) return;
+  if (isInteractionDisabled()) return;
   // ...
 };

Also applies to: 38-38


Line range hint 44-48: Use constants for keyboard keys.

Define keyboard keys as constants to avoid magic strings and improve maintainability.

+const KEYBOARD_KEYS = {
+  ENTER: 'Enter',
+  SPACE: ' ',
+  SPACEBAR: 'Spacebar',
+  SPACE_LEGACY: 'Space',
+} as const;
+
 if (
-  e.key === 'Enter' ||
-  e.key === ' ' ||
-  e.key === 'Spacebar' ||
-  e.key === 'Space'
+  e.key === KEYBOARD_KEYS.ENTER ||
+  e.key === KEYBOARD_KEYS.SPACE ||
+  e.key === KEYBOARD_KEYS.SPACEBAR ||
+  e.key === KEYBOARD_KEYS.SPACE_LEGACY
 )
packages/react-components/src/components/ActionCard/ActionCard.spec.tsx (1)

77-84: Add more test coverage for loading states.

Consider adding tests for:

  1. Animated loading state
  2. Interaction prevention during loading
  3. Accessibility attributes
it('should prevent interactions when loading', () => {
  const onClick = vi.fn();
  const { getByRole } = renderComponent({
    onClick,
    isLoading: true
  });
  
  userEvent.click(getByRole('presentation'));
  expect(onClick).not.toHaveBeenCalled();
});

it('should set correct accessibility attributes when loading', () => {
  const { getByRole } = renderComponent({
    isLoading: true
  });
  
  const card = getByRole('presentation');
  expect(card).toHaveAttribute('aria-busy', 'true');
  expect(card).toHaveAttribute('tabIndex', '-1');
});
packages/react-components/src/styles/_animations.scss (2)

1-9: Consider adding easing for smoother animation.

The linear movement might appear mechanical. Adding easing could create a more polished effect.

 @keyframes loading {
   0% {
     left: -100%;
+    animation-timing-function: ease-in-out;
   }

   100% {
     left: 100%;
   }
 }

11-29: Add fallback values for CSS variables.

The gradient colors rely on CSS variables without fallbacks, which could cause issues if variables are undefined.

     background: linear-gradient(
       90deg,
-      var(--animated-gradient-value-1),
-      var(--animated-gradient-value-2),
-      var(--animated-gradient-value-3)
+      var(--animated-gradient-value-1, #f0f0f0),
+      var(--animated-gradient-value-2, #e0e0e0),
+      var(--animated-gradient-value-3, #f0f0f0)
     );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 090918a and 2b7716c.

📒 Files selected for processing (7)
  • packages/react-components/src/components/ActionCard/ActionCard.module.scss (2 hunks)
  • packages/react-components/src/components/ActionCard/ActionCard.spec.tsx (1 hunks)
  • packages/react-components/src/components/ActionCard/ActionCard.stories.tsx (2 hunks)
  • packages/react-components/src/components/ActionCard/ActionCard.tsx (3 hunks)
  • packages/react-components/src/components/ActionCard/types.ts (1 hunks)
  • packages/react-components/src/components/Skeleton/Skeleton.module.scss (3 hunks)
  • packages/react-components/src/styles/_animations.scss (1 hunks)
🔇 Additional comments (5)
packages/react-components/src/components/ActionCard/types.ts (1)

24-31: Well-documented props with clear types!

The new loading state props are properly typed as optional booleans with clear JSDoc comments.

packages/react-components/src/components/ActionCard/ActionCard.stories.tsx (1)

82-97: Great story implementation showcasing both loading states!

The story effectively demonstrates both regular and animated loading states using StoryDescriptor for clear organization.

packages/react-components/src/components/ActionCard/ActionCard.tsx (1)

18-19: Props initialized with sensible defaults!

The loading props default to false, which is the expected behavior.

packages/react-components/src/components/Skeleton/Skeleton.module.scss (1)

30-30: Clean implementation using the new mixin!

Good job reusing the skeleton-loading mixin consistently across components.

Also applies to: 41-41

packages/react-components/src/components/ActionCard/ActionCard.module.scss (1)

32-34: Clean implementation of animated loading state!

The skeleton-loading mixin is applied correctly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/react-components/src/components/ActionCard/ActionCard.tsx (2)

18-26: Extract loading class name prefix to a constant.

Consider extracting the repeated ${baseClass}--loading prefix to improve maintainability.

 const baseClass = 'action-card';
+const loadingClass = `${baseClass}--loading`;

 export const ActionCard: FC<PropsWithChildren<ActionCardProps>> = ({
   // ...props
 }) => {
   const wrapperClassNames = cx(styles[`main-wrapper`], {
-    [styles[`${baseClass}--loading`]]: isLoading,
-    [styles[`${baseClass}--loading--animated`]]: isLoadingAnimated,
+    [styles[loadingClass]]: isLoading,
+    [styles[`${loadingClass}--animated`]]: isLoadingAnimated,
   });

56-63: Enhance the aria-label for better accessibility.

The current "Action Card" label is generic. Consider making it more descriptive of the card's purpose.

-        aria-label="Action Card"
+        aria-label={`${children} action card`}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b7716c and 2708e4b.

📒 Files selected for processing (3)
  • packages/react-components/src/components/ActionCard/ActionCard.module.scss (2 hunks)
  • packages/react-components/src/components/ActionCard/ActionCard.tsx (3 hunks)
  • packages/react-components/src/components/ActionCard/types.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-components/src/components/ActionCard/ActionCard.module.scss
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: chromatic-deployment
🔇 Additional comments (3)
packages/react-components/src/components/ActionCard/types.ts (1)

Line range hint 3-45: Well-structured discriminated union type!

The type definition effectively enforces the relationship between isLoading and isLoadingAnimated props, preventing invalid combinations.

packages/react-components/src/components/ActionCard/ActionCard.tsx (2)

29-29: Good defensive programming!

Early returns during loading state effectively prevent unwanted interactions.

Also applies to: 38-38


68-92: Clean conditional rendering implementation!

Content is properly hidden during loading while maintaining the component structure.

Copy link

@vladko-uxds vladko-uxds left a comment

Choose a reason for hiding this comment

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

👍

@JoannaSikora JoannaSikora merged commit 6c90ff8 into main Feb 3, 2025
6 checks passed
@JoannaSikora JoannaSikora deleted the feature/1234 branch February 3, 2025 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Action card] - add state with skeleton
3 participants