Skip to content

Feat/modal component #76

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

Merged
merged 3 commits into from
Apr 17, 2025
Merged

Feat/modal component #76

merged 3 commits into from
Apr 17, 2025

Conversation

tractorss
Copy link
Contributor

@tractorss tractorss commented Apr 17, 2025

PR-Codex overview

This PR focuses on updating the Modal component in the @kleros/ui-components-library by enhancing its functionality and styling, while also updating the version in package.json.

Detailed summary

  • Updated :root[class="dark"] to :root.dark in src/styles/theme.css.
  • Bumped version from 3.0.1 to 3.1.2 in package.json.
  • Added Modal export in src/lib/index.ts.
  • Modified import of ModalComponent in src/stories/modal.stories.tsx.
  • Introduced isOpen and isDismissable props in Modal story.
  • Implemented useState for modal open state in the story.
  • Enhanced Modal component in src/lib/container/modal.tsx:
    • Added modalOverlayClassname and children props.
    • Changed from AriaModal to ModalOverlay structure.
    • Integrated Dialog for modal content rendering.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features
    • Introduced a new Modal component with improved overlay styling, animation, and accessibility.
  • Refactor
    • Updated the Modal component structure for better separation of overlay and dialog concerns.
  • Documentation
    • Enhanced the Modal story in Storybook with interactive open/close controls and prop controls.
  • Style
    • Modified dark theme CSS selector to improve theme application consistency.
  • Chores
    • Updated package version to 3.1.2.

Copy link
Contributor

coderabbitai bot commented Apr 17, 2025

Walkthrough

The changes introduce a refactored Modal component utilizing react-aria-components for improved structure and accessibility, separating overlay and dialog responsibilities. The Modal interface and props are updated, and the component is now exported from the main library index. The Storybook story for Modal is enhanced for interactivity, allowing users to control modal visibility and dismissibility via UI controls. Additionally, the CSS selector for dark theme variables is updated to use a class selector for better compatibility. The package version is also incremented.

Changes

File(s) Change Summary
src/lib/container/modal.tsx Refactored Modal to use ModalOverlay, AriaModal, and Dialog from react-aria-components; introduced ModalProps interface; updated styling and animation; props are now read-only; overlay and dialog concerns separated.
src/lib/index.ts Added export for the new Modal component from ./container/modal.
src/stories/modal.stories.tsx Updated Modal story to use React state for controlling open/close; added Button to trigger modal; enabled Storybook controls for isOpen and isDismissable; fixed import path.
src/styles/theme.css Changed dark theme selector from :root[class="dark"] to :root.dark; variable definitions unchanged.
package.json Updated package version from "3.0.1" to "3.1.2".

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Button
  participant ModalOverlay
  participant AriaModal
  participant Dialog

  User->>Button: Click "Open Modal"
  Button->>ModalOverlay: Set isOpen=true
  ModalOverlay->>AriaModal: Render modal structure
  AriaModal->>Dialog: Render modal content
  User->>Dialog: Interact with modal
  Dialog->>ModalOverlay: onOpenChange (close modal)
  ModalOverlay->>Button: Set isOpen=false
Loading

Poem

🐇
In the garden of code, a modal appears,
With overlays and dialogs, it now perseveres.
Stories grow lively, with buttons in bloom,
And dark themes now style with elegant zoom.
So here's to the changes, both structure and theme—
A hop, a refactor, and a modal supreme!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 29629c8 and 59b5a66.

📒 Files selected for processing (1)
  • package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json

🪧 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 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 or @coderabbitai title 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: 1

🧹 Nitpick comments (1)
src/lib/container/modal.tsx (1)

35-37: Be cautious with duplicate prop spreading

{...props} is being spread to both the ModalOverlay (line 35) and the AriaModal (line 37). This could potentially lead to prop conflicts or unexpected behavior if both components interpret the same props differently.

Consider being more explicit about which props go to which component:

- <ModalOverlay
-   className={cn(
-     "fixed top-0 left-0 isolate",
-     "z-20 h-(--visual-viewport-height) w-full bg-black/[50%] backdrop-blur-md",
-     "flex items-center justify-center",
-     "entering:animate-[fadeIn_100ms_ease-out] exiting:animate-[fadeOut_100ms_ease-in]",
-     modalOverlayClassname,
-   )}
-   {...props}
- >
-   <AriaModal {...props}>
+ <ModalOverlay
+   className={cn(
+     "fixed top-0 left-0 isolate",
+     "z-20 h-(--visual-viewport-height) w-full bg-black/[50%] backdrop-blur-md",
+     "flex items-center justify-center",
+     "entering:animate-[fadeIn_100ms_ease-out] exiting:animate-[fadeOut_100ms_ease-in]",
+     modalOverlayClassname,
+   )}
+   {...overlayProps}
+ >
+   <AriaModal {...modalProps}>

Where overlayProps and modalProps would be appropriately filtered from the original props.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a994a51 and 29629c8.

📒 Files selected for processing (4)
  • src/lib/container/modal.tsx (1 hunks)
  • src/lib/index.ts (1 hunks)
  • src/stories/modal.stories.tsx (2 hunks)
  • src/styles/theme.css (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/lib/container/modal.tsx (2)
src/stories/modal.stories.tsx (1)
  • Modal (26-48)
src/utils/index.ts (1)
  • cn (4-6)
🔇 Additional comments (8)
src/styles/theme.css (1)

37-37: Good improvement to class selector for dark theme

Changing from :root[class="dark"] to :root.dark is a more flexible approach that allows the dark theme to be applied alongside other root classes. The previous selector would only match if "dark" was the exact class attribute value, which is more restrictive.

src/lib/container/modal.tsx (3)

11-17: Well-structured interface with good documentation

The ModalProps interface is well-defined, extending the appropriate react-aria component props while adding specific customization options. The JSDoc comment for modalOverlayClassname provides clear guidance on its purpose.


25-25: Good use of Readonly type modifier

Using Readonly<ModalProps> helps ensure immutability of props, which is a best practice for React components.


38-47: Good use of nested components for accessibility

The nesting of Dialog within AriaModal within ModalOverlay provides good separation of concerns and aligns with accessibility best practices. The structure makes it clear which component is responsible for which aspect of the modal's behavior.

src/lib/index.ts (1)

9-9: Good addition of Modal export

Adding the Modal component to the library exports makes it available for consumers, consistent with other components.

src/stories/modal.stories.tsx (3)

5-6: Fixed import path and added Button component

The import path for the Modal component has been correctly updated, and the Button component is now imported to provide a trigger for the modal. This is a good improvement for the story's demonstration capability.


12-19: Good addition of Storybook controls

Adding argTypes for isOpen and isDismissable props improves the Storybook experience by allowing users to interactively control these properties.


33-46: Excellent implementation of controlled modal state

Using useState to control the modal's open state and the Button component to trigger it provides a much better demonstration of how the modal should be used in a real application. The centered content layout also improves the presentation.

alcercu
alcercu previously approved these changes Apr 17, 2025
Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

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

lgtm

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 17, 2025
@tractorss tractorss dismissed stale reviews from coderabbitai[bot] and alcercu via 59b5a66 April 17, 2025 11:16
Copy link

@tractorss tractorss merged commit 1c79ca2 into main Apr 17, 2025
5 checks passed
@tractorss tractorss deleted the feat/modal-component branch April 17, 2025 11:18
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