Skip to content

Conversation

@kotAPI
Copy link
Collaborator

@kotAPI kotAPI commented Mar 30, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new .code-block-blur class for enhanced visual effects on code blocks.
    • Added functionality to expand and collapse code blocks with a toggle button.
  • Refactor

    • Overhauled the Collapsible component for a more modular structure, utilizing new fragment components for better organization.
  • Style

    • Updated styles for collapsible components, including improved state definitions and visual presentation.
    • Enhanced animation syntax for smoother transitions in collapsible content.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 30, 2025

Walkthrough

The pull request includes updates across stylesheets, component logic, linting scripts, and documentation examples. The changes simplify animation keyframe declarations and introduce a new blur effect style. The code block component now manages an expansion state with a toggle button. The linting configuration in package.json is updated to auto-fix style issues. Major refactors of the collapsible component and its fragments remove legacy functionality, delegate behavior to new primitives, and simplify associated stories and styling.

Changes

File(s) Change Summary
docs/app/globals.scss Consolidated @keyframes AnimationName declarations and added the new .code-block-blur class with a gradient overlay effect.
docs/components/layout/Documentation/helpers/CodeBlock.js Introduced a new expanded state via useState and a toggle button to expand/collapse code blocks, applying a blur effect when collapsed.
package.json Modified the lint script to replace --no-fix with --fix for automatic style issue corrections.
src/components/ui/Collapsible/... Refactored the main Collapsible component to a minimal version (logging a warning and returning null), updated fragments (Content, Root, Trigger) to use CollapsiblePrimitive, removed CollapsibleHeader, CollapsibleItem, and the index file, and simplified stories.
styles/themes/components/collapsible.scss Updated CSS classes and state selectors by renaming the root class and adjusting the styling for closed ([data-state="closed"]) and open ([data-state="open"]) states.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CB as CodeBlock
    participant SC as State Manager

    U->>CB: Clicks toggle button
    CB->>SC: Toggle expanded state
    SC-->>CB: Returns updated state
    CB->>U: Re-renders code block (blur effect updated)
Loading
sequenceDiagram
    participant U as User
    participant CT as Collapsible.Trigger
    participant CP as CollapsiblePrimitive

    U->>CT: Clicks trigger
    CT->>CP: Delegates collapse/expand handling
    CP-->>CT: Returns updated state
    CP->>Content: Renders updated collapsible content
Loading

Possibly related PRs

  • Feat: Basic collapsible component added #407: The changes in the main PR, which focus on enhancing the styling and functionality of the collapsible component, are related to the retrieved PR that introduces a basic collapsible component and its associated stories, as both involve modifications to the collapsible functionality.

Suggested labels

automerge

Poem

I'm a rabbit, hopping by,
With code so fresh, my spirits fly.
Animations neat and toggles bright,
Collapsible parts now shining light.
I nibble bugs with joyful glee,
Leaping through changes, wild and free!
(_/) 🐇 (•‿•)

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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: 3

🧹 Nitpick comments (1)
docs/components/layout/Documentation/helpers/CodeBlock.js (1)

54-61: Consider conditionally rendering the expand button only when needed

The code block is always limited to 180px height when collapsed, but there's no check to see if the content actually requires collapsing. Consider only showing the expand button if content exceeds a certain height.

-{!expanded && <div className="code-block-blur"></div>}
-<div className="flex justify-center w-full bg-gradient-to-t from-background to-transparent bg-gray-100 px-4 py-2">
-   
-    <Button size="small" onClick={() => setExpanded(!expanded)}>
-        Show {expanded ? 'less' : 'more'}
-    </Button>
-</div>
+{codeHeight > 180 && (
+   <>
+     {!expanded && <div className="code-block-blur"></div>}
+     <div className="flex justify-center w-full bg-gradient-to-t from-background to-transparent bg-gray-100 px-4 py-2">
+       <Button size="small" onClick={() => setExpanded(!expanded)}>
+         Show {expanded ? 'less' : 'more'}
+       </Button>
+     </div>
+   </>
+)}

You would need to measure the content height using a ref:

const codeRef = useRef(null);
const [codeHeight, setCodeHeight] = useState(0);

useEffect(() => {
  if (codeRef.current) {
    setCodeHeight(codeRef.current.scrollHeight);
  }
}, [children]);

// Then add ref={codeRef} to the code element
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7b9a1f2 and c115ec5.

📒 Files selected for processing (12)
  • docs/app/globals.scss (1 hunks)
  • docs/components/layout/Documentation/helpers/CodeBlock.js (3 hunks)
  • package.json (1 hunks)
  • src/components/ui/Collapsible/Collapsible.tsx (2 hunks)
  • src/components/ui/Collapsible/fragments/CollapsibleContent.tsx (2 hunks)
  • src/components/ui/Collapsible/fragments/CollapsibleHeader.tsx (0 hunks)
  • src/components/ui/Collapsible/fragments/CollapsibleItem.tsx (0 hunks)
  • src/components/ui/Collapsible/fragments/CollapsibleRoot.tsx (1 hunks)
  • src/components/ui/Collapsible/fragments/CollapsibleTrigger.tsx (2 hunks)
  • src/components/ui/Collapsible/index.tsx (0 hunks)
  • src/components/ui/Collapsible/stories/Collapsible.stories.tsx (2 hunks)
  • styles/themes/components/collapsible.scss (1 hunks)
💤 Files with no reviewable changes (3)
  • src/components/ui/Collapsible/fragments/CollapsibleHeader.tsx
  • src/components/ui/Collapsible/fragments/CollapsibleItem.tsx
  • src/components/ui/Collapsible/index.tsx
🧰 Additional context used
🧬 Code Definitions (1)
src/components/ui/Collapsible/fragments/CollapsibleTrigger.tsx (1)
src/components/ui/Collapsible/contexts/CollapsibleContext.tsx (1)
  • CollapsibleContext (19-20)
🪛 Biome (1.9.4)
docs/components/layout/Documentation/helpers/CodeBlock.js

[error] 46-46: This JSX property is assigned multiple times.

This attribute is assigned again here.

(lint/suspicious/noDuplicateJsxProps)

🔇 Additional comments (20)
package.json (1)

62-62: Great improvement to the linting process!

Changing the stylelint command from --no-fix to --fix enables automatic fixing of style issues during linting, which will help maintain consistent styling across the codebase and reduce manual fixes.

docs/components/layout/Documentation/helpers/CodeBlock.js (3)

1-2: Good addition of React imports and client directive

Adding the "use client" directive and importing useState is necessary for the new interactive functionality.


10-10: Imported Button component for the new toggle functionality

This is a necessary import for the show more/less button implementation.


34-34: Good addition of state management for code block expansion

The useState hook properly manages the expanded state of the code block.

docs/app/globals.scss (2)

79-86: Good simplification of keyframe syntax

Combining the 0% and 100% keyframes is a clean, efficient approach that maintains the same functionality while reducing redundancy.


90-104: Well-implemented blur effect for collapsed code blocks

The code-block-blur class with the pseudo-element gradient creates a nice visual indication that there's more content below. The implementation uses best practices with pointer-events: none to ensure clicks pass through to underlying elements.

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

27-29: Good addition of RightArrowIcon component

This SVG icon component is well-structured and provides visual feedback for the collapsible state.


31-74: Improved Collapsible component implementation with compound pattern

The refactored Default story showcases a much better implementation using the compound component pattern with Root, Trigger, and Content. This approach:

  1. Provides better composition and flexibility
  2. Makes the component more intuitive to use
  3. Properly handles animation with the transition classes
  4. Clearly demonstrates the component's usage pattern

The rotating arrow icon with group-data-[state=open]:rotate-90 is a nice touch for visual feedback.

src/components/ui/Collapsible/fragments/CollapsibleContent.tsx (3)

4-4: Good addition of CollapsiblePrimitive import

The import of CollapsiblePrimitive is appropriate for the refactoring approach, moving the implementation details to a primitive component.


13-14: Clean context usage simplification

Good refactoring to only extract the rootClass from context rather than unused properties. The new contentClass variable creates a cleaner class name derivation approach.


16-16: Appropriate delegation to primitive component

Successfully migrated from a custom implementation to using the primitive component, which should provide more consistent behavior. The class composition with clsx is maintained correctly.

src/components/ui/Collapsible/fragments/CollapsibleTrigger.tsx (2)

3-3: Good import of CollapsiblePrimitive

Appropriate addition of the primitive component import to support the refactoring approach.


17-19: Well-implemented trigger refactoring

The refactoring successfully simplifies the component by:

  1. Only extracting needed context values
  2. Creating a consistent class naming pattern
  3. Delegating behavior to the primitive component

This should make the code more maintainable and consistent across the collapsible components.

styles/themes/components/collapsible.scss (4)

1-9: Good styling structure for the trigger component

The updated class structure uses more semantic naming (.rad-ui-collapsible instead of -root) and properly styles the trigger element with appropriate spacing, colors and dimensions.


11-19: Well-structured content styling

The content styling provides good visual consistency with appropriate spacing, colors and border-radius.


20-39: Nice implementation of the collapse effect with gradient

The closed state implementation with the gradient overlay creates a nice blur/fade effect. The fixed height of 200px with overflow hidden works well with the gradient to indicate there's more content.


41-44: Good open state handling

Using height: auto !important ensures the expanded content displays properly regardless of other style rules that might affect the height.

src/components/ui/Collapsible/fragments/CollapsibleRoot.tsx (1)

9-13: Good implementation of CollapsibleRoot with primitive component

The refactoring correctly:

  1. Passes only the necessary rootClass value to the context
  2. Uses the primitive component with all relevant props
  3. Maintains the class name composition pattern

This creates a cleaner interface that delegates behavior to the primitive while maintaining consistency with the rest of the UI components.

src/components/ui/Collapsible/Collapsible.tsx (2)

1-3: No issues found with these imports.


20-22: Exposing subcomponents as static properties is consistent with the compound component pattern.

Comment on lines +46 to +53
<code className={`language-${language} whitespace-pre-wrap`} style={{ wordBreak: 'break-word' }}
style={{
height: expanded ? 'auto' : 180,
maxHeight: 640,
overflowY: expanded ? 'scroll' : 'hidden',

}}
>{code}</code>
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

Fix duplicate style attribute on code element

There's a duplicate style attribute on the code element which will cause only the second one to be applied.

-<code className={`language-${language} whitespace-pre-wrap`} style={{ wordBreak: 'break-word' }}
-     style={{
-         height: expanded ? 'auto' : 180,
-         maxHeight: 640,
-         overflowY: expanded ? 'scroll' : 'hidden',
-         
-     }}
+<code 
+     className={`language-${language} whitespace-pre-wrap`} 
+     style={{
+         wordBreak: 'break-word',
+         height: expanded ? 'auto' : 180,
+         maxHeight: 640,
+         overflowY: expanded ? 'scroll' : 'hidden'
+     }}
📝 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
<code className={`language-${language} whitespace-pre-wrap`} style={{ wordBreak: 'break-word' }}
style={{
height: expanded ? 'auto' : 180,
maxHeight: 640,
overflowY: expanded ? 'scroll' : 'hidden',
}}
>{code}</code>
<code
className={`language-${language} whitespace-pre-wrap`}
style={{
wordBreak: 'break-word',
height: expanded ? 'auto' : 180,
maxHeight: 640,
overflowY: expanded ? 'scroll' : 'hidden'
}}
>{code}</code>
🧰 Tools
🪛 Biome (1.9.4)

[error] 46-46: This JSX property is assigned multiple times.

This attribute is assigned again here.

(lint/suspicious/noDuplicateJsxProps)

Comment on lines +15 to +17
const Collapsible = () => {
console.warn('Direct usage of Tabs is not supported. Please use Tabs.Root, Tabs.List, etc. instead.');
return null;
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

Console warning references "Tabs" instead of "Collapsible."
This appears to be an unintentional leftover from another component, which can confuse users.

Here is a suggested fix:

-    console.warn('Direct usage of Tabs is not supported. Please use Tabs.Root, Tabs.List, etc. instead.');
+    console.warn('Direct usage of Collapsible is not supported. Please use Collapsible.Root, Collapsible.Trigger, etc. instead.');
📝 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
const Collapsible = () => {
console.warn('Direct usage of Tabs is not supported. Please use Tabs.Root, Tabs.List, etc. instead.');
return null;
const Collapsible = () => {
console.warn('Direct usage of Collapsible is not supported. Please use Collapsible.Root, Collapsible.Trigger, etc. instead.');
return null;

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 (1)
src/components/ui/Collapsible/tests/Collapsible.test.tsx (1)

70-79: Good addition of new component test.

Adding a dedicated test for the Collapsible.Content component is a good practice. It ensures that each component in the composition works correctly in isolation.

Consider adding more test cases to verify different states and behaviors of the Content component (e.g., with different children, when it's initially collapsed, etc.).

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c115ec5 and 25fe65a.

📒 Files selected for processing (1)
  • src/components/ui/Collapsible/tests/Collapsible.test.tsx (2 hunks)
🔇 Additional comments (3)
src/components/ui/Collapsible/tests/Collapsible.test.tsx (3)

8-13: Good refactoring to a more composable pattern!

The change to use the compositional pattern with Collapsible.Root, Collapsible.Trigger, and Collapsible.Content is a great improvement. This approach follows modern React component design patterns (similar to Radix UI or Headless UI) and provides more flexibility for consumers of the component.


21-26: Props correctly moved to appropriate component.

The disabled prop has been correctly moved to the Collapsible.Root component, which is consistent with the new component structure. This maintains the same functionality while adapting to the new pattern.


59-65: Consistent naming update.

The test suite name has been appropriately updated to match the new compositional pattern, and the test implementation follows the new structure 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 (1)
src/components/ui/Collapsible/tests/Collapsible.test.tsx (1)

5-141: Consider adding tests for transitionDuration prop

While the tests cover most functionality, there's no test for the newly added transitionDuration prop on CollapsibleRoot. Consider adding a test that verifies this prop is properly passed to the underlying component.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 25fe65a and e232659.

📒 Files selected for processing (2)
  • src/components/ui/Collapsible/fragments/CollapsibleRoot.tsx (1 hunks)
  • src/components/ui/Collapsible/tests/Collapsible.test.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (8)
src/components/ui/Collapsible/fragments/CollapsibleRoot.tsx (3)

5-5: Good addition of primitive component

Using the CollapsiblePrimitive from core/primitives is a good architectural choice that promotes better separation of concerns.


9-18: Well-defined props interface

The CollapsibleRootProps type is now properly defined with all necessary properties. This addresses the previous TypeScript error and provides good documentation for component usage.


20-24: Cleaner implementation with proper prop forwarding

The refactored implementation properly forwards all relevant props to the CollapsiblePrimitive.Root component while maintaining the context provider for consistency. This is a good improvement that simplifies the component structure.

src/components/ui/Collapsible/tests/Collapsible.test.tsx (5)

6-23: Good mock implementation for useControllableState

This mock properly simulates both controlled and uncontrolled behavior, ensuring that tests accurately reflect component functionality. The mock correctly updates state and calls callbacks when necessary.


27-37: Updated test structure to match new component API

The test now correctly uses the new component structure with Collapsible.Root, Collapsible.Trigger, and Collapsible.Content, ensuring proper validation of the new implementation.


39-59: Improved test for disabled state

The test now properly verifies that:

  1. The onOpenChange callback is not called when disabled
  2. Content remains visible despite clicking the trigger

This is a more thorough validation of the disabled behavior.


61-93: Good controlled component test implementation

This test thoroughly verifies the controlled component behavior by:

  1. Testing initial closed state
  2. Verifying callback is called with correct value
  3. Testing content visibility after parent-controlled state change

This addresses the previous review comment about toggle verification.


96-141: Thorough subcomponent testing

The tests for Collapsible.Trigger and Collapsible.Content are well-structured and verify both content rendering and ARIA attributes, which is great for accessibility.

@kotAPI kotAPI merged commit 5665a67 into main Mar 30, 2025
6 checks passed
@kotAPI kotAPI deleted the kotapi/collapsible-improvements branch March 30, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants