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

refactor(component: switch): make Switch component self-dependent by removing @radix-ui/react-switch dependency #82

Merged
merged 6 commits into from
Oct 20, 2024

Conversation

ruru-m07
Copy link
Owner

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

Fixes #63

Refactor the Switch component to be self-contained and remove dependency on @radix-ui/react-switch.

  • Switch Component:

    • Remove import statement for @radix-ui/react-switch.
    • Update the Switch component to be self-contained with its own state management and event handling.
    • Update the Switch component's props to include checked and onCheckedChange.
  • Documentation:

    • Update the documentation in apps/www/content/docs/components/switch.mdx to reference the self-contained Switch component.
    • Add a new props table to the documentation to reflect the updated Switch component's props.
  • Dependencies:

    • Remove @radix-ui/react-switch from packages/ui/package.json.
    • Update pnpm-lock.yaml to remove references to @radix-ui/react-switch.
  • Registry:

    • Update apps/www/public/registry/index.json and apps/www/public/registry/components/switch.json to remove the dependency on @radix-ui/react-switch.
    • Update apps/www/registry/ui.ts to remove the dependency on @radix-ui/react-switch.

For more details, open the Copilot Workspace session.

Summary by CodeRabbit

  • New Features

    • Updated documentation for the Switch component, including a new Props section detailing properties like className, disabled, id, defaultChecked, and onCheckedChange.
    • Introduced a fully custom implementation of the Switch component using a native <button> element, enhancing accessibility and state management.
  • Bug Fixes

    • Corrected the component name from SwiychEvent to SwitchEvent and updated related ID attributes for improved accessibility.
    • Removed outdated dependencies related to the Switch component, ensuring smoother functionality.
  • Documentation

    • Enhanced clarity and completeness of the Switch component's documentation with updated examples and usage instructions.

…removing @radix-ui/react-switch dependency

Fixes #63

Refactor the `Switch` component to be self-contained and remove dependency on `@radix-ui/react-switch`.

* **Switch Component**:
  - Remove import statement for `@radix-ui/react-switch`.
  - Update the `Switch` component to be self-contained with its own state management and event handling.
  - Update the `Switch` component's props to include `checked` and `onCheckedChange`.

* **Documentation**:
  - Update the documentation in `apps/www/content/docs/components/switch.mdx` to reference the self-contained `Switch` component.
  - Add a new props table to the documentation to reflect the updated `Switch` component's props.

* **Dependencies**:
  - Remove `@radix-ui/react-switch` from `packages/ui/package.json`.
  - Update `pnpm-lock.yaml` to remove references to `@radix-ui/react-switch`.

* **Registry**:
  - Update `apps/www/public/registry/index.json` and `apps/www/public/registry/components/switch.json` to remove the dependency on `@radix-ui/react-switch`.
  - Update `apps/www/registry/ui.ts` to remove the dependency on `@radix-ui/react-switch`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/ruru-m07/ruru-ui/issues/63?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 6:28am

Copy link

changeset-bot bot commented Oct 20, 2024

⚠️ No Changeset found

Latest commit: 62c6dea

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 involve a comprehensive refactor of the Switch component across multiple files. The primary modification is the removal of the dependency on @radix-ui/react-switch, replaced by a custom implementation using a native <button> element. Documentation updates include revised import statements and the addition of a detailed Props section. The component's internal state management has been enhanced, and accessibility features have been integrated. Overall, the changes ensure that the Switch component is self-sufficient and well-documented.

Changes

File Path Change Summary
apps/www/content/docs/components/switch.mdx Updated import statements to ruru-ui, added new Props section detailing properties of the Switch component. Updated examples to reflect new properties.
apps/www/public/registry/components/switch.json Removed dependency on @radix-ui/react-switch.
apps/www/public/registry/index.json Removed dependency for the "switch" component.
apps/www/registry/ui.ts Removed dependencies property for the switch component.
packages/ui/package.json Removed dependency on @radix-ui/react-switch.
packages/ui/src/components/switch.tsx Refactored Switch component to use a native <button>, introduced SwitchProps interface, managed internal state, and improved accessibility.

Assessment against linked issues

Objective Addressed Explanation
Refactor the Switch component to remove its dependency on @radix-ui/react-switch. (#63)

🐰 In the meadow, where the switches gleam,
A new design, oh what a dream!
No more dependencies, just pure delight,
With buttons that toggle, shining so bright.
Props now detailed, clear as can be,
Hopping along, come switch with me! 🌼✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b018ad7 and 3a94dd6.

📒 Files selected for processing (1)
  • .husky/pre-commit (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
.husky/pre-commit (2)

1-2: LGTM: Proper shell script setup

The shebang line and sourcing of the Husky shell script are correctly implemented, following best practices for Git hook scripts.


4-14: Excellent implementation of error handling and verbose output

The pre-commit process has been significantly improved:

  1. Clear error handling for both the registry build and Prettier formatting.
  2. Verbose output at each step, enhancing the user experience.
  3. Appropriate use of exit codes to abort the commit on failures.

These changes align perfectly with the suggestions from previous reviews and contribute to a more robust pre-commit hook.


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.

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

🧹 Outside diff range and nitpick comments (4)
apps/www/public/registry/components/switch.json (1)

6-6: Props and state management look good, but consider a minor improvement

The implementation of the Switch component as a custom button with its own state management is well done. The use of React.forwardRef and the custom SwitchProps interface provides good type safety and flexibility.

However, there's a small improvement we can make to better sync the internal state with the external checked prop:

Consider updating the isChecked state when the checked prop changes. You can do this by adding a useEffect hook:

React.useEffect(() => {
  if (checked !== undefined) {
    setIsChecked(checked);
  }
}, [checked]);

This ensures that the component's state always reflects the checked prop, even if it changes externally.

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

172-180: LGTM: Comprehensive Props section added

The new Props section is a valuable addition to the documentation. It provides clear and detailed information about each prop, including types, default values, and descriptions. This addition greatly enhances the usability of the component for developers.

One minor suggestion for consistency:

Consider updating the default value for className from "" (with a space) to "" (without a space) to match the format of other default values in the table.

packages/ui/src/components/switch.tsx (2)

4-7: Use ButtonHTMLAttributes for more comprehensive props

Extending React.ButtonHTMLAttributes<HTMLButtonElement> ensures all standard button attributes are included, providing better type safety and flexibility.

Apply this diff to update the interface:

-interface SwitchProps extends React.ComponentPropsWithoutRef<"button"> {
+interface SwitchProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
   checked?: boolean;
   onCheckedChange?: (checked: boolean) => void;
 }

13-15: Revise JSDoc comments for accuracy and completeness

The @param tags should accurately reflect the component's props. Also, since ref is handled by forwardRef, it doesn't need to be documented as a prop.

Consider updating the JSDoc comments:

 /**
  * Switch component
  *
  * @param {string} className - Additional class names for the switch.
  * @param {boolean} checked - Whether the switch is checked.
  * @param {(checked: boolean) => void} onCheckedChange - Callback when the switch is checked or unchecked.
- * @param {React.Ref<HTMLButtonElement>} ref - Forwarded ref.
  *
  * @example
  *
  * ```tsx
  * <Switch />
  * ```
  */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8c6833a and 17fed7e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • apps/www/content/docs/components/switch.mdx (5 hunks)
  • apps/www/public/registry/components/switch.json (1 hunks)
  • apps/www/public/registry/index.json (0 hunks)
  • apps/www/registry/ui.ts (0 hunks)
  • packages/ui/package.json (0 hunks)
  • packages/ui/src/components/switch.tsx (1 hunks)
💤 Files with no reviewable changes (3)
  • apps/www/public/registry/index.json
  • apps/www/registry/ui.ts
  • packages/ui/package.json
🧰 Additional context used
🔇 Additional comments (10)
apps/www/public/registry/components/switch.json (4)

6-6: Click handler implementation is correct

The handleClick function correctly toggles the internal state and calls the onCheckedChange callback when provided. This implementation allows the component to be used in both controlled and uncontrolled modes.


6-6: Rendering and accessibility attributes are well implemented

The use of appropriate ARIA attributes (role="switch" and aria-checked) enhances the accessibility of the component. The button type is correctly set to "button" to prevent form submission.


6-6: Styling implementation is flexible and maintainable

The use of the cn utility for class name composition and the conditional application of classes based on the isChecked state is a good approach. It allows for easy customization and maintains a clear separation between logic and styling.


Line range hint 1-53: Overall implementation aligns well with PR objectives

The refactoring of the Switch component to remove the dependency on @radix-ui/react-switch has been successfully implemented. The component is now self-dependent, using native HTML elements and React hooks for its functionality. This aligns perfectly with the objectives outlined in the PR and the linked issue #63.

Key achievements:

  1. Removal of external dependencies
  2. Custom implementation using a button element
  3. Proper state management
  4. Accessibility considerations
  5. Flexible styling

The JSON structure of the file is correct, and the absence of listed dependencies in the file accurately reflects the component's new self-dependent nature.

apps/www/content/docs/components/switch.mdx (5)

58-58: LGTM: Import statement updated correctly

The import statement has been successfully updated to use the new path "ruru-ui/components/switch". This change is consistent with the PR objective of making the Switch component self-dependent and removing the external dependency.


78-78: LGTM: Disabled switch example updated correctly

The import statement in the disabled switch example has been correctly updated to use the new path. The usage of the disabled prop remains unchanged, which is appropriate.


102-102: LGTM: Switch with labels example updated and improved

The import statement has been correctly updated. Additionally, the inclusion of the id prop for the Switch component is a great improvement for accessibility. This change ensures that the label is properly associated with the switch, enhancing usability for all users, including those using assistive technologies.


127-127: LGTM: Default checked switch example updated correctly

The import statement in the default checked switch example has been properly updated to use the new path. The usage of the defaultChecked prop remains unchanged, which is correct and consistent with the component's functionality.


Line range hint 1-180: Overall documentation update is comprehensive and aligned with PR objectives

The changes made to this documentation file are thorough and consistent with the PR's objective of making the Switch component self-dependent. Key improvements include:

  1. Updated import statements across all examples.
  2. Addition of the id prop in examples, enhancing accessibility.
  3. A new, detailed Props section that accurately reflects the component's current implementation.

These updates ensure that the documentation is in sync with the refactored Switch component, providing developers with accurate and comprehensive information for using the component.

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

37-55: Component rendering follows best practices

The rendering logic is clear, and accessibility attributes like role="switch" and aria-checked are properly used. Conditional class names effectively manage the visual state.

packages/ui/src/components/switch.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: 1

🧹 Outside diff range and nitpick comments (8)
apps/www/components/SwitchEvent.tsx (1)

11-12: Approved: Improved accessibility and HTML compliance

The changes to the id attribute of the Switch component and the corresponding htmlFor attribute of the label improve accessibility and comply with HTML best practices. The new id "toggle-value" is more appropriate for an HTML id attribute.

Consider updating the label text to be more descriptive:

-        <label htmlFor="toggle-value"> toggle value </label>
+        <label htmlFor="toggle-value">Toggle switch state</label>

This change would make the purpose of the switch clearer to users.

apps/www/public/registry/components/switch.json (2)

Line range hint 18-33: LGTM: State management and event handling are well-implemented.

The component correctly handles both controlled and uncontrolled states, and the handleClick function properly manages state updates and callbacks. This implementation aligns well with React best practices.

Consider using the functional update form of setIsCheckedInternal for better consistency with React's state update batching:

- setIsCheckedInternal(newChecked);
+ setIsCheckedInternal(prev => !prev);

Line range hint 35-53: LGTM: Rendering and styling are well-implemented with good accessibility considerations.

The use of a native <button> element with appropriate ARIA attributes enhances accessibility. The styling approach using Tailwind CSS classes is consistent with the project's standards.

Consider adding a visually hidden text description of the switch state for screen readers:

 <button
   type="button"
   role="switch"
   aria-checked={isCheckedValue}
   className={cn(
     "peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",
     isCheckedValue ? "bg-primary" : "bg-accent",
     className,
   )}
   onClick={handleClick}
   ref={ref}
   {...props}
 >
+  <span className="sr-only">{isCheckedValue ? 'On' : 'Off'}</span>
   <span
     className={cn(
       "pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform",
       isCheckedValue ? "translate-x-4" : "translate-x-0",
     )}
   />
 </button>

This addition would improve the component's accessibility by providing a clear text description of the switch state for screen reader users.

packages/ui/src/components/switch.tsx (2)

12-26: LGTM: Component documentation is comprehensive

The JSDoc style comments provide clear and comprehensive documentation for the Switch component. All important props are well-described, and a simple usage example is included.

Consider adding a brief description of the component's purpose at the beginning of the documentation block. For example:

/**
 * Switch component - A toggleable on/off state input
 * ...
 */

38-71: LGTM: Well-implemented event handling and rendering

The handleClick function and rendering logic are well-implemented. The component correctly uses ARIA attributes for accessibility, and the styling changes appropriately based on the checked state.

Consider extracting the long className string into a separate constant for improved readability. For example:

const switchClassName = "peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50";

// Then in the JSX:
className={cn(switchClassName, isCheckedValue ? "bg-primary" : "bg-accent", className)}
apps/www/content/docs/components/switch.mdx (3)

58-61: LGTM: Updated import and usage example

The import statement and usage example have been correctly updated to reflect the new package structure. This change aligns with the refactoring of the Switch component to be self-dependent.

Consider adding a comment above the Demo function to explain its purpose, e.g.:

// Basic usage of the Switch component
export function Demo() {
    return <Switch />;
}

95-96: LGTM: Updated Switch with labels example

The example has been correctly updated to include the id prop for the Switch component and the corresponding htmlFor attribute for the label. This change improves accessibility and demonstrates proper usage of the component with associated labels.

Consider updating the label text to be more descriptive, e.g.:

<label htmlFor="airplane-mode-demo">Airplane Mode</label>

This would make the example more realistic and informative.


172-181: Excellent addition of the Props section

The new Props section provides comprehensive and clear documentation for the Switch component's properties. This addition greatly enhances the usability of the component by clearly outlining all available props, their types, default values, and descriptions.

Consider adding a brief introductory sentence before the table to provide context, e.g.:

## Props

The following props can be used to customize the Switch component:

| Name                | Type                     | Default     | Description                                                  |
...

This would help set the context for the table that follows.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 17fed7e and b018ad7.

📒 Files selected for processing (5)
  • .husky/pre-commit (1 hunks)
  • apps/www/components/SwitchEvent.tsx (1 hunks)
  • apps/www/content/docs/components/switch.mdx (7 hunks)
  • apps/www/public/registry/components/switch.json (1 hunks)
  • packages/ui/src/components/switch.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (15)
.husky/pre-commit (1)

1-4: LGTM! The pre-commit hook is well-structured.

The script correctly sets up a pre-commit hook using Husky. It ensures that the registry is built and the code is formatted before each commit, which aligns well with the PR objectives of refactoring the Switch component and updating its documentation.

apps/www/components/SwitchEvent.tsx (3)

6-6: Approved: Component name correction

The component name has been correctly updated from SwiychEvent to SwitchEvent, fixing the typographical error. This change improves code readability and maintains consistency with the component's purpose.


19-19: Approved: Consistent export statement

The export statement has been correctly updated to use the new component name SwitchEvent. This change maintains consistency with the earlier component name update and ensures the correct export of the component.


Line range hint 1-20: Overall assessment: Positive improvements to SwitchEvent component

The changes made to this file have successfully addressed several important aspects:

  1. Corrected the component name from SwiychEvent to SwitchEvent.
  2. Improved accessibility by updating the id and htmlFor attributes.
  3. Ensured consistency in the export statement.

These modifications align well with the PR objectives of refactoring the Switch component and its usage. They enhance code quality, improve accessibility, and maintain consistency throughout the file.

To ensure these changes haven't introduced any unintended side effects, please run the following verification:

This script will help ensure that the component renaming has been applied consistently across the project and that there are no naming conflicts.

✅ Verification successful

Verification Complete: SwitchEvent Component Renaming is Consistent

All checks have passed successfully:

  1. No remaining instances of SwiychEvent were found.
  2. SwitchEvent is used correctly in all import statements.
  3. No naming conflicts with SwitchEvent detected.

The component renaming has been applied consistently across the project without introducing any issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that the new component name is used consistently across the project

echo "Checking for any remaining instances of 'SwiychEvent':"
rg "SwiychEvent" --type ts --type tsx

echo "Verifying the usage of 'SwitchEvent' in import statements:"
rg "import.*SwitchEvent" --type ts --type tsx

echo "Checking for any potential naming conflicts with 'SwitchEvent':"
rg "(?<![a-zA-Z])SwitchEvent(?![a-zA-Z])" --type ts --type tsx

Length of output: 848


Script:

#!/bin/bash
# Verify that the new component name is used consistently across the project

echo "Checking for any remaining instances of 'SwiychEvent':"
rg "SwiychEvent" --glob "*.ts" --glob "*.tsx"

echo "Verifying the usage of 'SwitchEvent' in import statements:"
rg "import.*SwitchEvent" --glob "*.ts" --glob "*.tsx"

echo "Checking for any potential naming conflicts with 'SwitchEvent':"
rg "\bSwitchEvent\b" --glob "*.ts" --glob "*.tsx"

Length of output: 699

apps/www/public/registry/components/switch.json (4)

Line range hint 6-10: LGTM: Imports and interface definition are well-structured.

The new SwitchProps interface correctly extends React.ComponentPropsWithoutRef<"button"> and includes the necessary props for both controlled and uncontrolled usage. This aligns well with the PR objective of making the Switch component self-dependent.


Line range hint 13-17: LGTM: Component definition and props handling are well-implemented.

The use of React.forwardRef and proper props destructuring, including default values, demonstrates good React practices. This implementation supports both controlled and uncontrolled usage of the Switch component.


Line range hint 55-57: LGTM: Component export and display name are correctly implemented.

Setting the display name to "Switch" is a good practice for debugging and development tools. The export statement is correct and consistent with the component implementation.


Line range hint 1-62: Overall, the Switch component refactor is well-implemented and meets the PR objectives.

The new implementation successfully removes the dependency on @radix-ui/react-switch, creating a self-dependent Switch component. Key improvements include:

  1. Proper state management for both controlled and uncontrolled usage.
  2. Enhanced accessibility with ARIA attributes and a native button element.
  3. Consistent styling using Tailwind CSS classes.
  4. Support for forwarded refs.

The component now aligns well with React best practices and the project's coding standards. The minor suggestions provided earlier can further enhance its accessibility and state management.

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

1-10: LGTM: Imports and SwitchProps interface are well-defined

The import statements and SwitchProps interface are correctly implemented. The "use client" directive is appropriate for a client-side component, and the SwitchProps interface extends React.ComponentPropsWithoutRef<"button">, allowing for all standard button props while adding the necessary custom properties for the Switch component.


27-37: LGTM: Robust state management implementation

The component implementation demonstrates excellent handling of both controlled and uncontrolled usage. The use of forwardRef is appropriate, and the state management logic is well-implemented. The defaultChecked prop is correctly used to initialize the internal state.


Line range hint 73-76: LGTM: Correct displayName and export

The displayName is correctly set to "Switch", which is helpful for debugging. The component is properly exported.

apps/www/content/docs/components/switch.mdx (4)

10-10: LGTM: Import statement corrected

The import statement for SwitchEvent has been correctly updated, fixing the typo from 'SwiychEvent' to 'SwitchEvent'. This change ensures consistency with the component name and file path.


78-81: LGTM: Updated import for Disabled Switch example

The import statement has been correctly updated to use the new package structure. The example still effectively demonstrates the usage of the disabled prop for the Switch component.


127-130: LGTM: Updated Default Checked Switch example

The import statement has been correctly updated to use the new package structure. The example continues to effectively demonstrate the usage of the defaultChecked prop for the Switch component.


Line range hint 1-181: Overall excellent documentation update

The changes to this documentation file effectively capture the refactoring of the Switch component to be self-dependent. The updates include:

  1. Corrected import statements throughout the file.
  2. Updated usage examples that demonstrate various features of the component.
  3. A comprehensive new Props section that clearly outlines all available properties.

These changes significantly improve the usability and understanding of the Switch component for developers. The documentation now accurately reflects the component's implementation and provides clear guidance on its usage.

Great job on maintaining and improving the documentation alongside the component changes!

.husky/pre-commit Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@ruru-m07 ruru-m07 self-assigned this Oct 20, 2024
@ruru-m07 ruru-m07 added 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
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.

elmofire1

@ruru-m07 ruru-m07 merged commit 6426efb into main Oct 20, 2024
7 checks passed
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. refactor: component Refactoring code related to UI components.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor: make Switch component self-dependent by removing @radix-ui/react-switch dependency
1 participant