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(modal): enhance modal component with multiple animation variants #81

Merged
merged 6 commits into from
Oct 20, 2024

Conversation

ruru-m07
Copy link
Owner

@ruru-m07 ruru-m07 commented Oct 20, 2024

Fixes #65

Add support for multiple animation variants in the Modal component.

  • Extend the modalVariants object in packages/ui/src/components/modal.tsx to include multiple animation options such as fade, zoom, scaleBounce, slideUp, slideDown, slideRight, slideLeft, flip, and rotate.
  • Allow dynamic selection of animation variants based on the animationVariant prop in the Modal component.
  • Update the documentation in apps/www/content/docs/components/modal.mdx to explain how to select and use the new animation variants.
  • Add test cases in apps/www/app/playground/page.tsx to cover all supported animation options for the Modal component.
  • Add a new file apps/www/components/preview/Modal/modalAnimation.tsx to demonstrate the use of different animation variants in the Modal component.
  • Update the version in packages/ui/package.json from 2.2.3 to 2.2.4.

For more details, open the Copilot Workspace session.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced multiple animation variants for modals, enhancing visual effects.
    • Added a new ModalAnimation component for selecting animation styles.
  • Documentation

    • Updated modal documentation to include animation variants and usage examples.
  • Bug Fixes

    • Improved modal functionality by ensuring animation options are correctly applied.
  • Chores

    • Updated ruru-ui package version to 2.2.4.

Fixes #65

Add support for multiple animation variants in the Modal component.

* Extend the `modalVariants` object in `packages/ui/src/components/modal.tsx` to include multiple animation options such as `fade`, `zoom`, `scaleBounce`, `slideUp`, `slideDown`, `slideRight`, `slideLeft`, `flip`, and `rotate`.
* Allow dynamic selection of animation variants based on the `animationVariant` prop in the `Modal` component.
* Update the documentation in `apps/www/content/docs/components/modal.mdx` to explain how to select and use the new animation variants.
* Add test cases in `apps/www/app/playground/page.tsx` to cover all supported animation options for the `Modal` component.
* Add a new file `apps/www/components/preview/Modal/modalAnimation.tsx` to demonstrate the use of different animation variants in the Modal component.
* Update the version in `packages/ui/package.json` from `2.2.3` to `2.2.4`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/ruru-m07/ruru-ui/issues/65?shareId=XXXX-XXXX-XXXX-XXXX).
Copy link

vercel bot commented Oct 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ruru-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 20, 2024 5:01am

Copy link

changeset-bot bot commented Oct 20, 2024

⚠️ No Changeset found

Latest commit: 36a4446

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Oct 20, 2024

Walkthrough

The changes introduced in this pull request enhance the Modal component by adding support for multiple animation variants. A new modalVariants object is created, allowing users to select different animations when opening or closing the modal. The ModalAnimation component is added to facilitate user interaction with these variants. Documentation is updated to reflect these changes, including a new section on animation variants. The overall functionality of the modal remains intact, while its capabilities are expanded through these enhancements.

Changes

File Path Change Summary
apps/www/app/playground/page.tsx Added modalVariants import; enhanced modal implementation to support dynamic rendering of multiple variants.
apps/www/components/preview/Modal/modalAnimation.tsx Introduced ModalAnimation component for selecting animation variants; includes UI for user input and submission.
apps/www/content/docs/components/modal.mdx Updated documentation to include ModalAnimation and new section on animation variants; added animationVariant prop details.
apps/www/public/registry/components/modal.json Added animationVariant to ModalProps; defined and exported modalVariants with multiple animation configurations.
packages/ui/package.json Updated version number from 2.2.3 to 2.2.4.
packages/ui/src/components/modal.tsx Added animationVariant prop to ModalProps; defined modalVariants with animation states; updated modal implementation to use new prop.

Assessment against linked issues

Objective Addressed Explanation
Add support for multiple animation variants in Modal component (#65)
Update documentation to explain how to select and use animations (#65)
Ensure test cases cover all supported animation options (#65) No test cases were mentioned in the changes.

🐰 In the land of code, where changes bloom,
New animations dance, dispelling the gloom.
With modals that twirl, and variants to choose,
Our playground's now lively, with options to use!
So hop along, friends, let’s celebrate this feat,
For every new variant makes our project sweet! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4928f5b and 36a4446.

📒 Files selected for processing (1)
  • apps/www/components/preview/Modal/modalAnimation.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/www/components/preview/Modal/modalAnimation.tsx

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 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.

@ruru-m07
Copy link
Owner Author

This pull request enhances the Modal component by introducing support for multiple animation variants and updating the documentation accordingly. The key changes include importing the modalVariants from the ruru-ui library, adding examples of different modal animations in the playground, and updating the documentation to reflect these new features.

Enhancements to Modal component:

Documentation updates:

@ruru-m07 ruru-m07 self-assigned this Oct 20, 2024
@ruru-m07 ruru-m07 added documentation Improvements or additions to documentation enhancement New feature or request component: update Updates or modifications to an existing component. component: review needed Component changes require review. docs: update Updates to existing documentation. refactor: component Refactoring code related to UI components. labels Oct 20, 2024
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: 4

🧹 Outside diff range and nitpick comments (7)
apps/www/components/preview/Modal/modalAnimation.tsx (1)

49-69: LGTM: Modal structure and content are well-implemented.

The Modal component is correctly structured and uses the selectedVariant appropriately for the animationVariant prop. The content is well-organized with a clear header, input field, and action buttons.

To enhance accessibility, consider adding an aria-label to the Modal component:

- <Modal animationVariant={selectedVariant as keyof typeof modalVariants}>
+ <Modal animationVariant={selectedVariant as keyof typeof modalVariants} aria-label="Create Username Modal">

This will provide better context for screen readers and improve the overall accessibility of your component.

apps/www/public/registry/components/modal.json (1)

Line range hint 62-242: LGTM: Comprehensive modalVariants object with suggestion for 3D animations

The modalVariants object is well-implemented, providing a diverse range of animation options that align perfectly with the PR objectives. Each variant is clearly defined with appropriate properties for hidden, visible, and exit states.

Suggestion for enhancement:
Consider adding the perspective property to 3D animations like flip and rotate for a more polished effect. For example:

flip: {
  hidden: {
    opacity: 0,
    rotateY: "90deg",
    perspective: 1000,
    transition: { duration: 0.15 },
  },
  // ... (apply to visible and exit states as well)
},

This addition can enhance the depth perception of these 3D animations.

packages/ui/src/components/modal.tsx (3)

62-68: LGTM! Consider enhancing the documentation.

The addition of the animationVariant prop to the ModalProps interface is well-implemented. It provides type safety by using keyof typeof modalVariants and maintains backward compatibility with the default value.

Consider adding an example of usage in the JSDoc comment to make it more clear for developers. For instance:

/**
 * The animation variant to use for the modal.
 *
 * @type {keyof typeof modalVariants}
 * @default "default"
 * @example
 * <Modal animationVariant="zoom">
 *   {/* Modal content *\/}
 * </Modal>
 */
animationVariant?: keyof typeof modalVariants;

130-304: Great addition of animation variants! Consider minor adjustments for consistency.

The modalVariants constant provides a rich set of animation options, enhancing the flexibility of the Modal component. The animations are well-defined and cover a good range of effects.

For consistency, consider the following adjustments:

  1. The scaleBounce variant uses a duration of 0.3s for the visible state, while all other variants use 0.15s. Consider either:
    a) Updating scaleBounce to use 0.15s for consistency, or
    b) Adding a comment explaining why this animation has a different duration.

  2. Consider extracting the common transition duration into a constant for easier maintenance:

const DEFAULT_TRANSITION_DURATION = 0.15;

// Then use it in the variants like this:
transition: { duration: DEFAULT_TRANSITION_DURATION },

This would make it easier to adjust the duration globally if needed in the future.


363-363: LGTM! Consider adding error handling for invalid animation variants.

The implementation of the animationVariant prop in the Modal component is correct and maintains backward compatibility with the default value.

Consider adding a runtime check for invalid animation variants. While TypeScript provides compile-time safety, it's good practice to handle potential runtime errors:

const selectedVariant = modalVariants[animationVariant] || modalVariants.default;

<motion.div
  // ...other props
  variants={selectedVariant}
  // ...other props
>
  {children}
</motion.div>

This ensures that even if an invalid variant is somehow passed at runtime, the modal will still function with the default animation.

Also applies to: 398-401

apps/www/content/docs/components/modal.mdx (2)

528-614: LGTM: New Animation Variants section

The new Animation Variants section effectively demonstrates the added support for various animation options, aligning well with the PR objectives. The example using the ModalAnimation component is comprehensive and illustrates how to use the new animationVariant prop.

Consider adding a brief explanation of each animation variant (e.g., fade, zoom, scaleBounce, etc.) to help users understand what each option does visually. This could be added as a short list or table before the code example.


Line range hint 1-651: Overall assessment: Documentation updates align well with PR objectives

The changes made to the Modal component documentation effectively capture the new animation variants feature. The addition of the Animation Variants section with a comprehensive example, along with the update to the props table, provides users with the necessary information to utilize the new functionality.

These updates align well with the PR objectives of enhancing the Modal component with multiple animation variants. The documentation now reflects the added support for various animation options and guides users on how to implement them.

To further improve the documentation:

  1. Consider adding brief descriptions of each animation variant to help users visualize the effects.
  2. Ensure that all supported animation variants are accurately listed in the props table.
  3. If possible, consider adding visual examples (e.g., GIFs) of each animation variant to enhance user understanding.

These enhancements will provide a more comprehensive and user-friendly documentation for the updated Modal component.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 894b8b4 and 2acf2ae.

📒 Files selected for processing (6)
  • apps/www/app/playground/page.tsx (2 hunks)
  • apps/www/components/preview/Modal/modalAnimation.tsx (1 hunks)
  • apps/www/content/docs/components/modal.mdx (2 hunks)
  • apps/www/public/registry/components/modal.json (1 hunks)
  • packages/ui/package.json (1 hunks)
  • packages/ui/src/components/modal.tsx (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/ui/package.json
🧰 Additional context used
🪛 Biome
apps/www/components/preview/Modal/modalAnimation.tsx

[error] 44-44: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🔇 Additional comments (8)
apps/www/components/preview/Modal/modalAnimation.tsx (3)

1-17: LGTM: Imports and dependencies are well-organized.

The imports are correctly structured and include all necessary dependencies for the component. The "use client" directive is appropriately placed at the top of the file, indicating that this is a Client Component in Next.js.


74-74: LGTM: Component export is correct.

The ModalAnimation component is properly exported as the default export, which is a common and acceptable practice for React components.


1-74: Overall, great implementation of the ModalAnimation component.

This new component effectively demonstrates the enhanced Modal functionality with multiple animation variants, aligning well with the PR objectives. The code is well-structured, uses appropriate UI components, and provides a user-friendly interface for selecting and demonstrating different animation options.

A few minor improvements were suggested:

  1. Enhancing the handleSubmit function with better error handling and state management.
  2. Adding a key prop to the mapped SelectItem components for better React performance.
  3. Including an aria-label on the Modal component for improved accessibility.

These small changes will further improve the component's functionality, performance, and accessibility. Great work on implementing this feature!

🧰 Tools
🪛 Biome

[error] 44-44: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

apps/www/public/registry/components/modal.json (3)

Line range hint 36-36: LGTM: New animationVariant property aligns with PR objectives

The addition of the animationVariant property to the ModalProps interface is a well-implemented change that directly supports the PR's goal of enhancing the Modal component with multiple animation variants. The typing keyof typeof modalVariants ensures type safety by only allowing valid animation variants to be used.


Line range hint 293-307: LGTM: Correct implementation of animationVariant in Modal component

The changes in the Modal component implementation correctly utilize the new animationVariant prop:

  1. The prop is added with a default value of "default", ensuring backward compatibility.
  2. The variants prop of the inner motion.div now uses modalVariants[animationVariant], allowing for dynamic selection of animation variants.

These changes align perfectly with the PR objectives, providing users with the ability to choose from various animation options when opening or closing the modal.


Line range hint 1-482: LGTM: Successful implementation of multiple animation variants for Modal component

This review confirms that the changes in the modal.tsx content within the modal.json file successfully implement the enhancement of the Modal component with multiple animation variants, as outlined in the PR objectives and issue #65. Key points:

  1. The animationVariant prop is added to ModalProps with proper typing.
  2. A comprehensive modalVariants object is implemented with various animation options.
  3. The Modal component is updated to utilize the new animationVariant prop.

These changes provide users with the ability to choose from a variety of animations when opening or closing the modal, increasing flexibility and customization options as intended. The implementation is type-safe, maintains consistency with the existing codebase, and ensures backward compatibility.

packages/ui/src/components/modal.tsx (1)

Line range hint 1-605: Overall, excellent enhancement of the Modal component!

The implementation of multiple animation variants for the Modal component is well-executed and aligns perfectly with the PR objectives. The changes provide users with a rich set of animation options while maintaining backward compatibility.

Key points:

  1. The ModalProps interface is correctly updated with the new animationVariant prop.
  2. The modalVariants constant provides a comprehensive set of animation options.
  3. The Modal component correctly implements the new animation feature.

The suggestions provided are minor and aimed at improving documentation, consistency, and error handling. Great job on this enhancement!

apps/www/content/docs/components/modal.mdx (1)

17-17: LGTM: New import statement for ModalAnimation

The import statement for ModalAnimation is correctly formatted and follows the existing import pattern. This import is necessary for the new Animation Variants section.

apps/www/components/preview/Modal/modalAnimation.tsx Outdated Show resolved Hide resolved
apps/www/components/preview/Modal/modalAnimation.tsx Outdated Show resolved Hide resolved
apps/www/content/docs/components/modal.mdx Outdated Show resolved Hide resolved
apps/www/app/playground/page.tsx Outdated Show resolved Hide resolved
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: 7

🧹 Outside diff range and nitpick comments (5)
apps/www/app/playground/page.tsx (1)

613-642: LGTM: Effective implementation of multiple modal variants

The implementation successfully demonstrates all available modal variants using Object.keys(modalVariants). Each variant is properly rendered with a unique key and the correct animationVariant prop. The consistent content across modals allows for easy comparison of animation effects.

To improve readability, consider extracting the modal content into a separate component:

const ModalContent = () => (
  <Modal.Body>
    <Modal.Header>
      <Modal.Title>Create Username</Modal.Title>
      <Modal.Subtitle>
        Enter a unique name for your token to differentiate it
        from other tokens and then select the scope.
      </Modal.Subtitle>
    </Modal.Header>
    <Modal.Content>
      <Input
        label="username"
        placeholder="enter your username."
      />
    </Modal.Content>
  </Modal.Body>
);

// Then in the map function:
<Modal animationVariant={variantKey}>
  <ModalContent />
  <Modal.Actions>
    <Modal.Close variant="secondary">Cancel</Modal.Close>
    <Modal.Action onClick={handleSubmit}>Submit</Modal.Action>
  </Modal.Actions>
</Modal>

This refactoring would reduce repetition and make the code more maintainable.

apps/www/content/docs/components/modal.mdx (2)

528-614: LGTM: Comprehensive documentation for Animation Variants

The new "Animation Variants" section provides a clear and detailed explanation of the new feature. The inclusion of both a preview and a code example is excellent for helping users understand and implement the feature. The interactive demonstration using the Select component is particularly helpful.

Consider adding a brief description of each animation variant to help users choose the most appropriate one for their use case. This could be added as a list or table before the code example.


622-626: LGTM: New animationVariant prop added to the props table

The animationVariant prop has been correctly added to the props table with an accurate type definition and a clear description. This addition properly documents the new feature for users.

There's a minor formatting issue in the table. The pipe characters (|) at the beginning and end of each line are misaligned. Please adjust the spacing to ensure all pipe characters are vertically aligned for better readability.

apps/www/components/preview/Modal/modalAnimation.tsx (2)

74-74: Standardize capitalization in labels and placeholders

Ensure consistent capitalization in the label and placeholder text. Consider capitalizing "Username" and starting the placeholder with a capital letter.

Apply this diff:

-<Input label="username" placeholder="enter your username." />
+<Input label="Username" placeholder="Enter your username." />

85-85: Remove unnecessary whitespace in JSX

The {" "} between the Spinner and "Submit" is unnecessary since the mr-2 class adds sufficient spacing.

Apply this diff:

-{submissionStatus === "loading" && <Spinner className="mr-2" />}{" "} Submit
+{submissionStatus === "loading" && <Spinner className="mr-2" />}Submit
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2acf2ae and 4928f5b.

📒 Files selected for processing (4)
  • apps/www/app/playground/page.tsx (2 hunks)
  • apps/www/components/preview/Modal/modalAnimation.tsx (1 hunks)
  • apps/www/content/docs/components/modal.mdx (2 hunks)
  • apps/www/public/registry/components/modal.json (1 hunks)
🧰 Additional context used
🔇 Additional comments (5)
apps/www/public/registry/components/modal.json (2)

6-6: Excellent addition of the animationVariant prop!

The new animationVariant property in the ModalProps interface is a great addition. It allows users to specify different animation styles for the modal, which aligns perfectly with the PR objective of enhancing the Modal component with multiple animation variants. The type keyof typeof modalVariants ensures type safety by only allowing valid animation variant names to be used.


6-6: Summary: Excellent enhancement of the Modal component with animation variants!

This implementation successfully achieves the PR objective of adding support for multiple animation variants to the Modal component. The changes include:

  1. Addition of the animationVariant prop to ModalProps.
  2. Implementation of a comprehensive modalVariants object with diverse animation options.
  3. Integration of the new animation system into the Modal component.

These enhancements significantly improve the flexibility and customization options for the Modal component, allowing users to easily apply different animations. The implementation is clean, type-safe, and maintains backward compatibility.

Great job on this feature addition! The minor suggestions provided earlier can further refine this already solid implementation.

apps/www/app/playground/page.tsx (2)

41-41: LGTM: Proper import of modalVariants

The import statement for modalVariants is correctly placed with other imports from the same module, which is a good practice for code organization.


Line range hint 1-643: Overall: Well-implemented modal variants demonstration

The changes in this file effectively implement and showcase multiple modal variants. The code is well-structured and follows good practices. The suggested refactoring for the modal content is a minor improvement that could enhance readability and maintainability.

Great job on implementing this feature!

apps/www/content/docs/components/modal.mdx (1)

17-17: LGTM: New import statement added correctly

The new import statement for ModalAnimation is correctly placed and follows the existing import style. This is a good practice for importing components that will be used in the documentation.

…onent

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Owner Author

@ruru-m07 ruru-m07 left a comment

Choose a reason for hiding this comment

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

all changes looks good ready to merge 🤖

spookychicken

@ruru-m07 ruru-m07 merged commit 8c6833a into main Oct 20, 2024
7 checks passed
@ruru-m07 ruru-m07 deleted the enhance-modal-animations branch October 20, 2024 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: review needed Component changes require review. component: update Updates or modifications to an existing component. docs: update Updates to existing documentation. documentation Improvements or additions to documentation enhancement New feature or request refactor: component Refactoring code related to UI components.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enhancement: add support for multiple animation variants in Modal component
1 participant