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(Accordion): moved to emotion styles #1470

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

Conversation

marcinsawicki
Copy link
Contributor

@marcinsawicki marcinsawicki commented Jan 10, 2025

Resolves: #{issue-number}

Description

Styling the component using the @emotion/css. Currently, only the Accordion component is affected for the test.

Storybook

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

  • Dependencies

    • Added @emotion/css as a peer and regular dependency
  • Styling

    • Migrated Accordion component from SCSS to Emotion CSS
    • Removed SCSS module files for Accordion components
    • Introduced new dynamic styling functions in styles.ts
  • Component Updates

    • Updated import paths for Accordion-related components
    • Simplified style references and class name generation
    • Updated component exports in index.ts
  • Code Structure

    • Refactored styling approach to use functional CSS methods
    • Improved maintainability of styling logic

Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

Walkthrough

The pull request introduces a comprehensive refactoring of the Accordion component's styling approach, transitioning from SCSS modules to Emotion CSS. This involves adding @emotion/css as a dependency, removing existing SCSS module files, and creating new styles.ts files with functional style definitions. The changes modify import paths, style application methods, and overall component structure while maintaining the core functionality of the Accordion component.

Changes

File Change Summary
packages/react-components/package.json Added @emotion/css as peer and regular dependency
packages/react-components/src/components/Accordion/Accordion.tsx Updated import from clsx to @emotion/css, replaced static class references with style functions
packages/react-components/src/components/Accordion/styles.ts New file with functional style definitions for Accordion component
packages/react-components/src/components/Accordion/components/... Removed .module.scss files, added styles.ts files with Emotion CSS

Suggested labels

dependencies, documentation

Suggested reviewers

  • VadymBezpalko
  • vladko-uxds

Possibly related PRs

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.

@marcinsawicki marcinsawicki changed the title feat(Accordion): moved to emotion styles part 1 feat(Accordion): moved to emotion styles Jan 10, 2025
@marcinsawicki marcinsawicki self-assigned this Jan 16, 2025
@marcinsawicki marcinsawicki added the feature New feature or request label Jan 16, 2025
@marcinsawicki marcinsawicki added this to the Cycle #11 milestone Jan 16, 2025
@marcinsawicki marcinsawicki marked this pull request as ready for review January 16, 2025 15:50
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 (10)
packages/react-components/src/components/Accordion/styles.ts (6)

11-41: Optimize transition performance.

Instead of transitioning 'all' properties, specify only the properties that need to change for better performance.

-  transition: all var(${TransitionDurationToken.Moderate1});
+  transition: border-color var(${TransitionDurationToken.Moderate1}),
+              box-shadow var(${TransitionDurationToken.Moderate1}),
+              background-color var(${TransitionDurationToken.Moderate1});

43-61: Add type safety for kind parameter.

Consider using a union type for the kind parameter to prevent potential errors.

type AccordionKind = 'warning' | 'error';
export const kind = (kind?: AccordionKind) => css`

73-87: Enhance keyboard accessibility.

Add focus styles to improve keyboard navigation experience.

   &:hover {
     cursor: pointer;
   }
+  &:focus-visible {
+    outline: none;
+    box-shadow: var(${ShadowToken.Focus});
+  }

89-107: Add RTL support for chevron positioning.

Consider using logical properties for better RTL support.

-  right: 20px;
+  inset-inline-end: 20px;

115-133: Extract common padding logic.

Consider creating a shared function for isPromo padding to avoid duplication.

const getPromoPadding = (isPromo: boolean) => 
  isPromo ? SpacingToken.Spacing6 : SpacingToken.Spacing5;

135-146: Remove padding logic duplication.

The padding logic is duplicated. Use the suggested shared function from the previous comment.

export const footer = (isPromo?: boolean) => css`
  border-top: 1px solid var(${DesignToken.BorderBasicSecondary});
-  padding: var(${SpacingToken.Spacing5});
-
-  ${isPromo
-    ? `
-    padding: var(${SpacingToken.Spacing6});
-  `
-    : `
-    padding: var(${SpacingToken.Spacing5});
-  `}
+  padding: var(${getPromoPadding(isPromo)});
`;
packages/react-components/src/components/Accordion/components/AccordionMultilineElement/styles.ts (1)

11-14: Consider adding type safety for style exports

Consider using const assertion to prevent accidental style mutations:

-export const baseStyles = css`
+export const baseStyles = css` as const;

-export const inner = css`
+export const inner = css` as const;
packages/react-components/src/components/Accordion/components/AccordionAnimatedLabel/styles.ts (2)

5-19: Consider memoizing style functions

The style function is recreated on every render. Consider memoizing it for better performance.

+import { useMemo } from 'react';

-export const baseStyles = (containerHeight?: number) => css`
+export const useBaseStyles = (containerHeight?: number) => useMemo(
+  () => css`
   display: flex;
   position: relative;
   align-items: center;
   transition: all var(${TransitionDurationToken.Fast2}) ease-in-out;
   min-height: 24px;

   ${containerHeight
     ? `
       height: ${containerHeight}px;
     `
     : `
       height: auto;
     `}
-`;
+`, [containerHeight]);

21-33: Same memoization recommendation applies here

Similar performance optimization can be applied to the element styles.

-export const element = (isVisible: boolean) => css`
+export const useElement = (isVisible: boolean) => useMemo(
+  () => css`
   position: absolute;
   transition: all var(${TransitionDurationToken.Fast2}) ease-in-out;
   max-width: 100%;

   ${isVisible
     ? `
         opacity: 1;
       `
     : `
         opacity: 0;
       `}
-`;
+`, [isVisible]);
packages/react-components/src/components/Accordion/components/AccordionMultilineElement/AccordionMultilineElement.tsx (1)

24-24: Consider using cx for className composition

For better type safety and className composition, consider using emotion's cx utility.

+import { cx } from '@emotion/css';

-className={styles.baseStyles}
+className={cx(styles.baseStyles)}

-className={styles.inner}
+className={cx(styles.inner)}

Also applies to: 29-29

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fa5db09 and db655e7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (13)
  • packages/react-components/package.json (2 hunks)
  • packages/react-components/src/components/Accordion/Accordion.module.scss (0 hunks)
  • packages/react-components/src/components/Accordion/Accordion.tsx (8 hunks)
  • packages/react-components/src/components/Accordion/components/AccordionAnimatedLabel.module.scss (0 hunks)
  • packages/react-components/src/components/Accordion/components/AccordionAnimatedLabel/AccordionAnimatedLabel.spec.tsx (1 hunks)
  • packages/react-components/src/components/Accordion/components/AccordionAnimatedLabel/AccordionAnimatedLabel.tsx (2 hunks)
  • packages/react-components/src/components/Accordion/components/AccordionAnimatedLabel/styles.ts (1 hunks)
  • packages/react-components/src/components/Accordion/components/AccordionMultilineElement.module.scss (0 hunks)
  • packages/react-components/src/components/Accordion/components/AccordionMultilineElement/AccordionMultilineElement.tsx (2 hunks)
  • packages/react-components/src/components/Accordion/components/AccordionMultilineElement/styles.ts (1 hunks)
  • packages/react-components/src/components/Accordion/components/index.ts (1 hunks)
  • packages/react-components/src/components/Accordion/helpers.tsx (1 hunks)
  • packages/react-components/src/components/Accordion/styles.ts (1 hunks)
💤 Files with no reviewable changes (3)
  • packages/react-components/src/components/Accordion/components/AccordionAnimatedLabel.module.scss
  • packages/react-components/src/components/Accordion/components/AccordionMultilineElement.module.scss
  • packages/react-components/src/components/Accordion/Accordion.module.scss
✅ Files skipped from review due to trivial changes (2)
  • packages/react-components/src/components/Accordion/components/AccordionAnimatedLabel/AccordionAnimatedLabel.spec.tsx
  • packages/react-components/src/components/Accordion/helpers.tsx
🔇 Additional comments (11)
packages/react-components/src/components/Accordion/styles.ts (3)

1-10: LGTM! Well-organized imports.

Clean import structure using named imports for design tokens.


63-71: LGTM! Clean open state implementation.

Consistent use of design tokens for styling.


109-113: LGTM! Clean content styles.

Minimal and effective implementation.

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

1-2: Clean and clear exports!

The barrel exports follow best practices for component organization.

packages/react-components/src/components/Accordion/components/AccordionMultilineElement/styles.ts (1)

5-9: Style definition looks good!

Clean transition from SCSS to emotion styles.

packages/react-components/src/components/Accordion/components/AccordionAnimatedLabel/AccordionAnimatedLabel.tsx (3)

3-6: Import paths look good!

The updated paths correctly reflect the new directory structure.


38-38: Good use of functional styles!

The dynamic height calculation is properly passed to the style function.


40-47: Clean implementation of conditional styles!

The visibility states are handled consistently for both open and closed elements.

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

3-3: Excellent emotion migration!

The transition from SCSS modules to emotion is clean and consistent throughout the component.

Also applies to: 13-13, 56-56, 66-66, 85-85, 94-94, 103-103, 112-112


126-126: Well-structured component variants!

The base styles are properly differentiated between regular and promo variants.

Also applies to: 132-132

packages/react-components/package.json (1)

37-37: Verify @emotion/css version compatibility.

Please ensure version 11.13.0 is compatible with the rest of the dependencies.

Run this script to check for potential version conflicts:

Also applies to: 78-78

✅ Verification successful

@emotion/css version ^11.13.0 is compatible

The version is recent, safely allows minor updates, and has no conflicts with other dependencies.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential version conflicts with @emotion/css

# Get the latest version from npm
echo "Latest @emotion/css version:"
npm view @emotion/css version

# Check for any dependencies that require a specific @emotion/css version
npm info . dependencies peerDependencies devDependencies | grep -i emotion

Length of output: 614


Script:

#!/bin/bash
# Find all package.json files and grep for emotion-related dependencies
echo "=== Searching for @emotion dependencies in package.json files ==="
fd package.json --type f --exec grep -l "emotion" {} \; | while read -r file; do
    echo "=== $file ==="
    grep "emotion" "$file" || true
done

echo -e "\n=== Searching for @emotion/css imports ==="
rg "@emotion/css" --type ts --type tsx --type js --type jsx -l

Length of output: 647


Script:

#!/bin/bash
# Search for @emotion/css imports in tsx files specifically
echo "=== Searching for @emotion/css imports in tsx files ==="
find . -name "*.tsx" -type f -exec grep -l "@emotion/css" {} \;

# Double check all package.json files for any emotion-related entries
echo -e "\n=== Double checking all package.json files for emotion packages ==="
find . -name "package.json" -type f -exec grep -i "emotion" {} \;

Length of output: 535

export const AccordionPromo: React.FC<IAccordionPromoProps> = (props) => {
const mainClassName = cx(styles[baseClass], styles[promoBaseClass]);
const mainClassName = cx(styles.baseStyles(true));

return (
<AccordionComponent mainClassName={mainClassName} isPromo {...props} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Now we can just pass the class name without cx
<AccordionComponent mainClassName={styles.baseStyles} ...

Copy link
Contributor

@JoannaSikora JoannaSikora left a comment

Choose a reason for hiding this comment

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

🥳

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
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

3 participants