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(EmptyState): add EmptyState component #1491

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

JoannaSikora
Copy link
Contributor

@JoannaSikora JoannaSikora commented Jan 21, 2025

Resolves: #1379

Description

This pull request introduces the new EmptyState component.

New EmptyState Component:

  • Added the EmptyState component implementation, which supports different types (full and inline), and includes properties for:
  • title
  • image or icon (optional)
  • description (optional)
  • centered (default false)
  • and actions (optional)
  • Performed self review and tested this implementation in AA app

Figma: https://www.figma.com/design/9FDwjR8lYvincseDkKypC4/%5BDS%5D-Component-Documentations?node-id=24836-20224&m=dev

Storybook

https://feature-1379--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

  • New Features

    • Introduced a new EmptyState component for displaying content when no data is available.
    • Added comprehensive Storybook documentation with various usage examples.
    • Implemented responsive styling for different screen sizes and component configurations.
  • Documentation

    • Created detailed documentation for the EmptyState component with multiple variations and a Figma link for design specifications.
  • Tests

    • Implemented unit tests to validate the rendering and behavior of the EmptyState component.

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Walkthrough

The pull request introduces a new EmptyState component for React, including TypeScript definitions, styling, documentation in Storybook format, and unit tests. It provides various configurations for displaying content when no data is available, such as inline, centered, and full-width layouts. The implementation features SCSS modules for styling, comprehensive Storybook stories to illustrate usage, and tests to ensure proper rendering behavior.

Changes

File Change Summary
EmptyState.tsx New React component with flexible rendering based on props
EmptyState.module.scss Styling for EmptyState with responsive modifiers
EmptyState.stories.tsx Comprehensive Storybook stories showcasing component variations
types.ts TypeScript interface defining component prop types
index.ts Exports component and types for external use
EmptyState.spec.tsx Unit tests for rendering behavior of EmptyState component
EmptyState.stories.module.scss SCSS module for styling Storybook examples of EmptyState

Assessment against linked issues

Objective Addressed Explanation
New Empty State component
Match Figma design spec

Possibly related PRs

Suggested reviewers

  • marcinsawicki
  • vladko-uxds

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c4882fb and 1e67f5c.

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

🪧 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 22, 2025 12:13
@JoannaSikora JoannaSikora added feature New feature or request High-prio High priority task labels Jan 22, 2025
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: 2

🧹 Nitpick comments (12)
packages/react-components/src/components/EmptyState/types.ts (1)

3-21: Add JSDoc documentation for better DX

The type definition is well-structured but would benefit from documentation explaining the different variants and prop combinations.

Add JSDoc comments like this:

+/**
+ * Props for the EmptyState component
+ * @property {('full'|'inline')} type - Layout type. 'full' supports description and image, 'inline' is compact
+ * @property {string} title - Main message to display
+ * @property {ReactNode} [actions] - Optional action buttons/links
+ * @property {boolean} [centered] - Whether to center the content
+ * @property {string} [image] - Optional image URL (mutually exclusive with icon)
+ * @property {ReactNode} [icon] - Optional icon element (mutually exclusive with image)
+ */
export type IEmptyStateProps = (
packages/react-components/src/components/EmptyState/EmptyState.tsx (2)

21-27: Add aria-label for accessibility

The empty state should be labeled for screen readers.

    <div
      className={cx(
        styles[baseClass],
        styles[`${baseClass}--${type}`],
        centered && styles[`${baseClass}--centered`]
      )}
+     aria-label={`Empty state: ${title}`}
    >

11-73: Consider memoizing the component

For performance optimization, especially with complex children in actions or icon props.

-export const EmptyState = ({
+export const EmptyState = React.memo(({
   type = 'full',
   // ... other props
-}: IEmptyStateProps) => {
+}: IEmptyStateProps) => {
   // component implementation
-};
+});
🧰 Tools
🪛 Biome (1.9.4)

[error] 54-60: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

packages/react-components/src/components/EmptyState/EmptyState.stories.tsx (3)

26-42: Consider adding aria-label to buttons

The Default story's buttons lack accessibility labels, which could impact screen reader users.

-        <Button kind="primary">Primary action</Button>
+        <Button kind="primary" aria-label="Primary action">Primary action</Button>
-        <Button kind="secondary">Secondary action</Button>
+        <Button kind="secondary" aria-label="Secondary action">Secondary action</Button>
-        <Button icon={<Icon source={InfoIcon} />} kind="secondary">
+        <Button icon={<Icon source={InfoIcon} />} kind="secondary" aria-label="More information">
           Tell me more
         </Button>
-        <Button kind="link">Link action</Button>
+        <Button kind="link" aria-label="Link action">Link action</Button>

44-80: Add loading state to ActionMenu

The Inline story's ActionMenu might benefit from a loading state for better UX.

         <ActionMenu
+          isLoading={false}
           options={[

130-151: Fix typo in Facebook Messenger

There's a typo in the social media platform name.

-            <Text bold>Facebook Messanger</Text>
+            <Text bold>Facebook Messenger</Text>
packages/react-components/src/components/EmptyState/EmptyState.stories.module.scss (2)

16-18: Use consistent media query breakpoints

Consider extracting the breakpoint value to a variable for better maintainability.

+$mobile-breakpoint: 600px;
+
 @media (width <= 600px) {

Also applies to: 28-30


21-27: Use design tokens for measurements

Replace hardcoded values with design system tokens for consistency.

-      border-radius: 8px;
+      border-radius: var(--radius-m);
-      width: 220px;
+      width: var(--width-box-default);
packages/react-components/src/components/EmptyState/EmptyState.mdx (1)

21-28: Add accessibility guidelines

Consider adding a section about accessibility best practices and ARIA attributes.

 #### Example implementation
+
+#### Accessibility
+
+The EmptyState component follows WCAG guidelines:
+- Use semantic HTML elements
+- Ensure proper heading hierarchy
+- Provide descriptive button labels
packages/react-components/src/components/EmptyState/EmptyState.module.scss (3)

23-25: Extract hardcoded breakpoint value into a variable.

Consider defining the breakpoint value (600px) as a design system variable for consistency and maintainability.

+$breakpoint-mobile: 600px;
+
 .#{$base-class} {
   // ...
-    @media (width <= 600px) {
+    @media (width <= $breakpoint-mobile) {

42-58: Extract repeated max-width value into a variable.

The max-width value of 600px is used multiple times. Consider extracting it into a variable for better maintainability.

+$content-max-width: 600px;
+
 .#{$base-class} {
   // ...
   &__description {
-    max-width: 600px;
+    max-width: $content-max-width;
     text-align: center;
   }
   // ...
   &__title {
     margin: 0;
     margin-bottom: var(--spacing-2);
-    max-width: 600px;
+    max-width: $content-max-width;
     text-align: center;
   }

69-76: Use the same breakpoint variable here.

Once the breakpoint variable is extracted, update this media query to use it as well.

-    @media (width <= 600px) {
+    @media (width <= $breakpoint-mobile) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 12f096d and c6b6e26.

📒 Files selected for processing (9)
  • packages/react-components/src/components/EmptyState/EmptyState.mdx (1 hunks)
  • packages/react-components/src/components/EmptyState/EmptyState.module.scss (1 hunks)
  • packages/react-components/src/components/EmptyState/EmptyState.spec.tsx (1 hunks)
  • packages/react-components/src/components/EmptyState/EmptyState.stories.module.scss (1 hunks)
  • packages/react-components/src/components/EmptyState/EmptyState.stories.tsx (1 hunks)
  • packages/react-components/src/components/EmptyState/EmptyState.tsx (1 hunks)
  • packages/react-components/src/components/EmptyState/index.ts (1 hunks)
  • packages/react-components/src/components/EmptyState/types.ts (1 hunks)
  • packages/react-components/src/index.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/react-components/src/components/EmptyState/EmptyState.tsx

[error] 54-60: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

🔇 Additional comments (4)
packages/react-components/src/components/EmptyState/index.ts (1)

1-2: Clean exports following barrel pattern!

packages/react-components/src/index.ts (1)

24-24: LGTM!

The EmptyState component export follows the alphabetical ordering convention.

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

1-24: LGTM!

Clean imports organization and proper Storybook setup with Meta and Story types.

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

28-40: LGTM! Well-structured image and icon styles.

The styles handle responsive sizing appropriately and use design system tokens consistently.

@JoannaSikora JoannaSikora changed the title feat(EmptyState): add base EmptyState component feat(EmptyState): add EmptyState component Jan 22, 2025
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 (6)
packages/react-components/src/components/EmptyState/EmptyState.stories.tsx (6)

26-42: Consider using a more reliable image source.

Replace the placeholder URL with a local asset or a more reliable CDN to prevent potential story rendering issues.

-    image: 'https://placehold.co/600x300',
+    image: '/assets/empty-state-default.png',

64-64: Document the purpose of openedOnInit.

Add a comment explaining why the menu needs to be initially opened in this story.


85-85: Document the purpose of the custom icon class.

Add a comment explaining what styles empty-state-story__icon applies and why they're needed.


122-128: Use a reliable image source.

Replace the placeholder URL with a local asset for reliability.

-    image: 'https://placehold.co/250x200',
+    image: '/assets/empty-state-small.png',

136-146: Consider more generic class names for reusability.

The current class names are tightly coupled to the story. Consider more generic names if these styles might be reused.


160-160: Replace inline styles with CSS modules.

Move the margin style to the CSS module for consistency with the rest of the stories.

-      <Text style={{ margin: 0 }}>
+      <Text className={styles['empty-state-story__description']}>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7f8d86a and a58e4eb.

📒 Files selected for processing (2)
  • packages/react-components/src/components/EmptyState/EmptyState.stories.tsx (1 hunks)
  • packages/react-components/src/components/EmptyState/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-components/src/components/EmptyState/types.ts
🧰 Additional context used
📓 Learnings (1)
📓 Common learnings
Learnt from: JoannaSikora
PR: livechat/design-system#1491
File: packages/react-components/src/components/EmptyState/EmptyState.spec.tsx:15-50
Timestamp: 2025-01-22T12:18:56.927Z
Learning: For React components, styling and layout aspects (like centering, inline vs block display, etc.) should be verified through visual testing tools rather than React Testing Library (RTL) tests. RTL tests should focus on behavior and functionality instead.
🔇 Additional comments (2)
packages/react-components/src/components/EmptyState/EmptyState.stories.tsx (2)

1-24: LGTM! Well-organized imports and proper Storybook setup.

The imports are logically grouped and the story configuration follows Storybook best practices.


113-119: Verify if the decorator is necessary.

Since the component has a centered prop, the decorator might be redundant. Consider removing it if the prop handles centering.

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 (3)
packages/react-components/src/components/EmptyState/EmptyState.stories.tsx (3)

28-28: Consider using local assets instead of external placeholder service.

Replace placehold.co with a local asset to ensure reliability in the stories.


140-142: Consider enforcing character limits in the component.

The story mentions character limits (50 for title, 100 for description) but these aren't enforced. Consider adding prop validation in the component itself.


168-168: Move inline styles to CSS module.

Replace style={{ margin: 0 }} with a class in the CSS module for better maintainability.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a58e4eb and c4882fb.

📒 Files selected for processing (2)
  • packages/react-components/src/components/EmptyState/EmptyState.module.scss (1 hunks)
  • packages/react-components/src/components/EmptyState/EmptyState.stories.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-components/src/components/EmptyState/EmptyState.module.scss
🧰 Additional context used
📓 Learnings (1)
📓 Common learnings
Learnt from: JoannaSikora
PR: livechat/design-system#1491
File: packages/react-components/src/components/EmptyState/EmptyState.spec.tsx:15-50
Timestamp: 2025-01-22T12:18:56.927Z
Learning: For React components, styling and layout aspects (like centering, inline vs block display, etc.) should be verified through visual testing tools rather than React Testing Library (RTL) tests. RTL tests should focus on behavior and functionality instead.
🔇 Additional comments (4)
packages/react-components/src/components/EmptyState/EmptyState.stories.tsx (4)

1-24: LGTM! Clean imports and proper Storybook setup.


64-64: Verify visual regression tests with openedOnInit.

The openedOnInit prop might affect visual regression tests. Consider adding a specific test case for this scenario.


82-96: LGTM! Good demonstration of icon usage.


98-120: Verify centered layout in visual tests.

As per our learnings, ensure the centered layout is verified through visual testing tools rather than RTL tests.

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.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request High-prio High priority task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Empty states] - new component
2 participants