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

Accordion Variants #787

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

Accordion Variants #787

wants to merge 6 commits into from

Conversation

kotAPI
Copy link
Collaborator

@kotAPI kotAPI commented Jan 16, 2025

Summary by CodeRabbit

  • New Features

    • Added color and variant customization options for Accordion and Button components
    • Introduced new Accordion stories with variant and color options
  • Style Changes

    • Updated Accordion component styling in SCSS
    • Refined border-radius and color schemes for Accordion and its elements
  • Documentation

    • Enhanced Storybook examples for Accordion and Button components
  • Chores

    • Minor test file formatting and cleanup across multiple components

Copy link
Contributor

coderabbitai bot commented Jan 16, 2025

Walkthrough

This pull request introduces enhancements to the Accordion and Button components, focusing on adding customization options through new optional properties like variant, color, and loop. The changes span multiple files across the UI components, including updates to component interfaces, styling in SCSS, and Storybook stories. The modifications aim to provide more flexible rendering and styling capabilities for these components, with particular emphasis on the Accordion's visual presentation and interaction states.

Changes

File Change Summary
src/components/ui/Accordion/Accordion.tsx Added optional variant and color properties to AccordionProps
src/components/ui/Accordion/fragments/AccordionHeader.tsx Enhanced context usage, added expanded state and data attributes
src/components/ui/Accordion/fragments/AccordionRoot.tsx Added variant, color, and loop props with default values
src/components/ui/Accordion/stories/Accordion.stories.tsx Introduced new stories with variant and color configurations
src/components/ui/Button/Button.tsx Added optional color property to ButtonProps
src/components/ui/Button/stories/Button.stories.js Added Color story, renamed All to AllVariants
styles/themes/components/accordion.scss Comprehensive styling updates for accordion components

Sequence Diagram

sequenceDiagram
    participant User
    participant AccordionRoot
    participant AccordionItem
    participant AccordionHeader
    participant AccordionTrigger

    User->>AccordionRoot: Render with variant/color
    AccordionRoot->>AccordionItem: Pass context
    AccordionItem->>AccordionHeader: Render with expanded state
    AccordionHeader->>AccordionTrigger: Apply styling
    User->>AccordionTrigger: Interact with trigger
    AccordionTrigger->>AccordionItem: Toggle expanded state
Loading

Possibly related PRs

Suggested labels

automerge

Poem

🐰 Hop, hop, accordion unfurls,
With colors bright and variant swirls,
Flexible UI, a rabbit's delight,
Components dancing, pure and bright!
Code magic springs, new features bloom 🎨

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.

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

🔭 Outside diff range comments (1)
src/components/ui/Button/stories/Button.stories.js (1)

Line range hint 1-86: Convert file to TypeScript.

This file contains JSX and would benefit from TypeScript's type safety. Consider:

  1. Renaming to .tsx
  2. Adding proper types for props and components
  3. Using the Story type from Storybook
🧹 Nitpick comments (9)
styles/themes/components/accordion.scss (1)

7-30: Reduce code duplication using SCSS mixins.

The accordion item styles are duplicated in the outline variant. Consider extracting common styles into a mixin for better maintainability.

@mixin accordion-item-base {
  width: 100%;
  display: flex;
  flex-direction: column;
  flex: 1;
  margin-bottom: 12px;
  border-radius: 10px;
  overflow: hidden;

  &:focus {
    outline: none;
    border: none;
  }

  &:focus-within {
    border: 1px solid var(--rad-ui-color-accent-900);
    color: var(--rad-ui-color-accent-900);
  }
}

.rad-ui-accordion-item {
  @include accordion-item-base;
  // unique styles for default variant
}

&[data-variant='outline'] .rad-ui-accordion-item {
  @include accordion-item-base;
  // unique styles for outline variant
}
src/components/ui/Accordion/fragments/AccordionHeader.tsx (1)

11-12: Remove unused context values.

The following context values are imported but never used in the component:

  • From AccordionContext: setActiveItem, focusNextItem, focusPrevItem
  • From AccordionItemContext: handleBlurEvent, handleClickEvent, handleFocusEvent
- const { setActiveItem, rootClass, focusNextItem, focusPrevItem, activeItem } = useContext(AccordionContext);
- const { itemValue, handleBlurEvent, handleClickEvent, handleFocusEvent } = useContext(AccordionItemContext);
+ const { rootClass, activeItem } = useContext(AccordionContext);
+ const { itemValue } = useContext(AccordionItemContext);
src/components/ui/Accordion/Accordion.tsx (1)

15-16: Consider using union types for better type safety.

Instead of using string type for variant and color, consider defining specific allowed values using union types.

- variant?: string;
- color?: string;
+ variant?: 'default' | 'bordered' | 'contained';
+ color?: 'primary' | 'secondary' | 'accent';
src/components/ui/Button/Button.tsx (2)

Line range hint 8-8: Remove or implement the TODO comment.

The comment "make the color prop default accent color" appears to be a TODO item that hasn't been implemented.

Either implement the default color or remove the comment.


13-13: Consider using union types for better type safety.

Similar to the Accordion component, consider using a union type for the color prop to restrict it to valid values.

- color?: string;
+ color?: 'primary' | 'secondary' | 'accent';
src/components/ui/Accordion/fragments/AccordionRoot.tsx (2)

12-14: Fix inconsistent type definitions.

The type definitions for variant and color use an unusual union with empty string literal:

- variant?: string | ''
- color?: string | ''
+ variant?: string
+ color?: string

Consider using union types for better type safety:

variant?: 'default' | 'bordered' | 'contained'
color?: 'primary' | 'secondary' | 'accent'

33-33: Remove empty useEffect hook.

The useEffect hook is empty and has no dependencies.

- useEffect(() => {}, []);
src/components/ui/Accordion/stories/Accordion.stories.tsx (1)

6-47: Consider enhancing the movie data structure.

The movie data structure is well-organized but could benefit from some improvements:

  1. The summary for "The Shawshank Redemption" appears incomplete
  2. Consider adding types for the movie data structure
interface MovieItem {
  title: string;
  content: React.ReactNode;
}

const items: MovieItem[] = [
  // ... existing items
];
src/components/ui/Button/stories/Button.stories.js (1)

69-86: Enhance the Color story implementation.

The Color story implementation could be improved:

  1. ArrowIcon's color isn't properly handled for different button variants
  2. The story lacks TypeScript types
  3. Consider using a consistent layout with other stories
export const Color: Story = () => (
  <SandboxEditor>
    <div className='space-y-4'>
      <div>
        <h3 className='text-gray-950 mb-2'>Button Colors</h3>
        <div className='flex items-center space-x-[40px]'>
          <Button color='red'>
            <span>{BUTTON_TEXT}</span>
            <ArrowIcon className={variant === 'solid' ? 'text-white' : 'text-accent-900'} />
          </Button>
          <Button>
            <span>{BUTTON_TEXT}</span>
            <ArrowIcon className={variant === 'solid' ? 'text-white' : 'text-accent-900'} />
          </Button>
        </div>
      </div>
    </div>
  </SandboxEditor>
);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 91b2343 and 6f79edf.

📒 Files selected for processing (11)
  • src/components/ui/Accordion/Accordion.tsx (1 hunks)
  • src/components/ui/Accordion/fragments/AccordionHeader.tsx (1 hunks)
  • src/components/ui/Accordion/fragments/AccordionRoot.tsx (3 hunks)
  • src/components/ui/Accordion/fragments/AccordionTrigger.tsx (0 hunks)
  • src/components/ui/Accordion/stories/Accordion.stories.tsx (2 hunks)
  • src/components/ui/Button/Button.tsx (2 hunks)
  • src/components/ui/Button/stories/Button.stories.js (2 hunks)
  • src/components/ui/Code/tests/Code.test.tsx (1 hunks)
  • src/components/ui/Em/tests/Em.test.js (1 hunks)
  • src/components/ui/Table/tests/Table.test.tsx (1 hunks)
  • styles/themes/components/accordion.scss (1 hunks)
💤 Files with no reviewable changes (1)
  • src/components/ui/Accordion/fragments/AccordionTrigger.tsx
✅ Files skipped from review due to trivial changes (3)
  • src/components/ui/Code/tests/Code.test.tsx
  • src/components/ui/Table/tests/Table.test.tsx
  • src/components/ui/Em/tests/Em.test.js
🔇 Additional comments (10)
styles/themes/components/accordion.scss (2)

1-4: LGTM! Root styles are clean and consistent.


56-59: LGTM! Content styles use design system colors appropriately.

src/components/ui/Accordion/fragments/AccordionHeader.tsx (1)

14-14: LGTM! Good use of data attributes for styling hooks.

The expanded state is correctly derived from context values and properly exposed via data attributes for styling purposes.

Also applies to: 17-17

src/components/ui/Accordion/Accordion.tsx (1)

19-19: LGTM! Props are correctly passed down.

The variant and color props are properly initialized with default values and passed to AccordionRoot.

Also applies to: 21-21

src/components/ui/Button/Button.tsx (1)

31-33: LGTM! Consistent use of data attributes.

The data attribute handling for color follows the same pattern as other attributes, maintaining consistency.

src/components/ui/Accordion/fragments/AccordionRoot.tsx (2)

24-31: LGTM! Good implementation of data attributes.

The data attributes are properly constructed and applied to the root element, providing good styling hooks.

Also applies to: 72-72


38-38: LGTM! Proper implementation of loop functionality.

The loop prop is correctly passed to the navigation helper functions.

Also applies to: 50-50

src/components/ui/Accordion/stories/Accordion.stories.tsx (2)

1-1: LGTM! Good type safety improvement.

Adding the AccordionProps type import enhances type safety and documentation.


70-86: Verify story variants align with design system.

The stories effectively demonstrate the new variant and color capabilities. However, ensure that:

  1. The 'solid' and 'outline' variants align with your design system
  2. The 'blue' color choice is part of your approved color palette
✅ Verification successful

Variants and colors are aligned with the design system

The 'solid' and 'outline' variants are properly integrated into the design system, as evidenced by their consistent implementation across components (Button, Accordion) and their inclusion in the standard variant set ('solid', 'soft', 'outline', 'ghost'). The 'blue' color is also validated as a standard accent color in the theming system.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for consistent variant/color usage across components
rg -g '*.{tsx,scss}' -A 2 "variant.*=.*['\"](solid|outline)['\"]\|color.*=.*['\"]blue['\"]\|@include.*variant\((solid|outline)\)"

Length of output: 139


Script:

#!/bin/bash
# Search for variant usage
rg -g '*.{tsx,scss}' "variant.*['\"]solid['\"]" 
rg -g '*.{tsx,scss}' "variant.*['\"]outline['\"]"

# Search for color usage
rg -g '*.{tsx,scss}' "color.*['\"]blue['\"]"

# Look for design system files
fd -e ts -e tsx -e scss "theme|tokens|colors|variants" --type f

# Check content of any design system related files
fd -e ts -e tsx -e scss "theme|tokens|colors|variants" --type f -x head -n 20 {}

Length of output: 2414

src/components/ui/Button/stories/Button.stories.js (1)

Line range hint 40-44: Consider documenting the breaking change.

Renaming the export from 'All' to 'AllVariants' is a breaking change that could affect existing story references.

Comment on lines +110 to +115
.rad-ui-accordion-content {
padding: 12px 16px;
color: var(--rad-ui-color-gray-950);
font-weight: 400;
font-size: 0.875rem;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure consistent typography across variants.

Typography styles (font-weight and font-size) are only defined in the outline variant. This could lead to inconsistent text styling between variants. Consider moving these styles to the base content class.

.rad-ui-accordion-content {
    background-color: var(--rad-ui-color-accent-50);
    padding: 12px 16px;
    color: var(--rad-ui-color-gray-950);
+   font-weight: 400;
+   font-size: 0.875rem;
}

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +33 to +51
.rad-ui-accordion-header {

// and if data expanded is true, add bottom border
&[data-expanded="true"] {
border-bottom: 1px solid var(--rad-ui-color-accent-700);
color: var(--rad-ui-color-accent-900);

}

.rad-ui-accordion-trigger {
background-color: var(--rad-ui-color-accent-50);
padding: 12px 16px;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;

&:focus {
outline: none;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Address accessibility concerns with focus states.

  1. Removing the focus outline without providing an alternative visual indicator could impact keyboard navigation accessibility. Consider adding a visible focus indicator.

  2. The comment on line 35 is redundant as the code is self-documenting through the data attribute usage.

- // and if data expanded is true, add bottom border
  &[data-expanded="true"] {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.rad-ui-accordion-header {
// and if data expanded is true, add bottom border
&[data-expanded="true"] {
border-bottom: 1px solid var(--rad-ui-color-accent-700);
color: var(--rad-ui-color-accent-900);
}
.rad-ui-accordion-trigger {
background-color: var(--rad-ui-color-accent-50);
padding: 12px 16px;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
&:focus {
outline: none;
}
.rad-ui-accordion-header {
&[data-expanded="true"] {
border-bottom: 1px solid var(--rad-ui-color-accent-700);
color: var(--rad-ui-color-accent-900);
}
.rad-ui-accordion-trigger {
background-color: var(--rad-ui-color-accent-50);
padding: 12px 16px;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
&:focus {
outline: none;
}

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.

1 participant