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

Add Size small for toogle #571

Merged
merged 6 commits into from
Dec 6, 2024
Merged

Add Size small for toogle #571

merged 6 commits into from
Dec 6, 2024

Conversation

aralovelace
Copy link
Contributor

@aralovelace aralovelace commented Dec 5, 2024

Jira Ticket Link / Motivation

To be used - WEB-4036 as it require a smaller size and based on the design element here

Summary of changes

This pull request includes updates to the Toggle component to introduce a new size prop, allowing for different sizes of the toggle switch. Additionally, it includes a version bump for the package and updates to the snapshots to reflect the new changes.

Updates to Toggle component:

  • src/core/Toggle.tsx: Added a size prop to the ToggleProps type and updated the Toggle component to handle different sizes for the root and thumb elements.

Updates to stories and snapshots:

Version bump:

How do you manually test this?

Reviewer Tasks (optional)

Merge/Deploy Checklist

  • Written automated tests for implemented features/fixed bugs
  • Rebased and squashed commits
  • Commits have clear descriptions of their changes
  • Checked for any performance regressions

Frontend Checklist

  • No frontend changes in this PR
  • Added before/after screenshots for changes
  • Tested on different platforms/browsers with Browserstack
  • Compared with the initial design / our brand guidelines
  • Checked the code for accessibility issues (VoiceOver User Guide)?

Summary by CodeRabbit

  • New Features

    • Introduced a new optional size property for the Toggle component, allowing users to customize its dimensions.
    • Added a new story for the Toggle component in Storybook to demonstrate the smaller size variant.
  • Chores

    • Updated the version number in the package.json file to reflect a new development version.

@aralovelace aralovelace self-assigned this Dec 5, 2024
Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces updates to the package.json file for the @ably/ui project, changing the version from 15.1.3 to 15.1.4-dev.0746ac8. Additionally, it modifies the Toggle component in src/core/Toggle.tsx by adding a new optional size property to its props, allowing for size customization. A new story named Small is also added to the Storybook configuration for the Toggle component, demonstrating its smaller size variant.

Changes

File Change Summary
package.json Version updated from 15.1.3 to 15.1.4-dev.0746ac8.
src/core/Toggle.tsx Added optional size property to ToggleProps, updated component to support size customization.
src/core/Toggle/Toggle.stories.tsx Added new story Small for the Toggle component to showcase smaller size variant.

Assessment against linked issues

Objective Addressed Explanation
Pricing page usage estimator (WEB-4036) No relevant changes related to the issue.

Possibly related PRs

Suggested labels

review

Suggested reviewers

  • jamiehenson
  • kennethkalmer

🐇 In the meadow, the toggles play,
With sizes small, they brighten the day.
A version new, it hops along,
In stories told, where they belong.
Let's celebrate this joyful change,
In code we trust, it's not so strange! 🌼


🪧 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)
src/core/Toggle/Toggle.stories.tsx (1)

28-31: Consider enhancing story documentation

While the implementation is correct, consider adding:

  1. A description for the Small story to document the use case
  2. Parameters to control the checked/disabled states for comprehensive testing
 export const Small = Template.bind({});
+Small.parameters = {
+  docs: {
+    description: 'Small variant of the Toggle component, designed for compact UI layouts.',
+  },
+};
 Small.args = {
   size: "small",
 };
src/core/Toggle.tsx (3)

19-21: Extract size-specific styles to constants

The inline Tailwind classes contain magic numbers and make the code harder to maintain. Consider extracting these into named constants or a configuration object.

+const TOGGLE_SIZES = {
+  small: {
+    root: 'w-[42px] h-[24px]',
+    thumb: 'w-[21px] h-[21px] translate-x-1 data-[state=checked]:translate-x-[20px]',
+  },
+  default: {
+    root: 'w-[56px] h-32',
+    thumb: 'h-[28px] w-[28px] translate-x-2 data-[state=checked]:translate-x-[26px]',
+  },
+} as const;
+
-  const rootSize = size === "small" ? "w-[42px] h-[24px]" : "w-[56px] h-32";
-  const thumbSize =
-    size === "small" ? "w-[21px] h-[21px] translate-x-1 data-[state=checked]:translate-x-[20px]" : "h-[28px] w-[28px] translate-x-2  data-[state=checked]:translate-x-[26px]";
+  const sizeKey = size || 'default';
+  const rootSize = TOGGLE_SIZES[sizeKey].root;
+  const thumbSize = TOGGLE_SIZES[sizeKey].thumb;

27-29: Consider adding data-size attribute

Adding a data attribute for size would improve testability and allow for easier styling overrides.

 <Switch.Root
   className={cn(
     "p-0 bg-neutral-600 rounded-full relative inline-block transition-colors data-[disabled]:bg-gui-unavailable data-[disabled]:cursor-not-allowed data-[state=checked]:bg-orange-600 focus:outline-none focus-visible:outline-offset-0 focus-visible:outline-4 focus-visible:outline-gui-focus",
     className,
     rootSize,
   )}
+  data-size={size || 'default'}
   id={id}
   {...props}
 >

Version in package.json needs to be updated to match PR description

The version in package.json is currently "15.1.4-dev.0746ac8", which is a development version. According to the PR description, this should be "15.1.4" for the release.

🔗 Analysis chain

Line range hint 1-1: Verify version bump in package.json

The PR description mentions a version bump from 15.1.3 to 15.1.4. Let's verify this change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check package.json version
rg '"version":\s*"15\.1\.' package.json

Length of output: 76

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1c19ce9 and 3d65468.

⛔ Files ignored due to path filters (1)
  • src/core/Toggle/__snapshots__/Toggle.stories.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/core/Toggle.tsx (1 hunks)
  • src/core/Toggle/Toggle.stories.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🔇 Additional comments (1)
src/core/Toggle.tsx (1)

34-36: Verify accessibility for small toggle

The reduced size might affect touch targets and accessibility. Ensure the small toggle meets WCAG requirements for interactive elements.

✅ Verification successful

Small toggle meets accessibility requirements

The Toggle component is built using Radix UI's Switch component, which is inherently accessible and follows WCAG guidelines. The small toggle dimensions (42x24px with 21x21px thumb) meet the minimum touch target size requirements:

  • The root size of 42x24px exceeds the WCAG 2.1 minimum target size of 24x24px
  • The component inherits Radix UI's built-in accessibility features including:
    • Proper ARIA attributes
    • Keyboard navigation
    • Screen reader support

The implementation aligns with the project's accessibility guidelines as documented in the README, which emphasizes AA standards compliance.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any existing accessibility tests
rg -l "accessibility|a11y|WCAG" --type ts --type tsx

Length of output: 82


Script:

#!/bin/bash
# Check if there are any existing accessibility tests with correct file type
rg -l "accessibility|a11y|WCAG" --type-add 'tsx:*.tsx' --type tsx --type ts

# Check the dimensions of the small toggle
rg "thumbSize|small.*toggle" --type-add 'tsx:*.tsx' --type tsx -C 2

# Look for any aria attributes or role definitions
rg "aria-|role=" --type-add 'tsx:*.tsx' --type tsx -C 2 src/core/Toggle.tsx

Length of output: 907


Script:

#!/bin/bash
# Check the Switch component import to see if it's from an accessible UI library
rg "import.*Switch" --type-add 'tsx:*.tsx' --type tsx src/core/Toggle.tsx -C 2

# Look for any documentation about accessibility
fd README.md --exec cat {} \; 

# Check if there are any test files for the Toggle component
fd -e test.tsx -e spec.tsx -e test.ts -e spec.ts Toggle --exec cat {} \;

Length of output: 14270

src/core/Toggle.tsx Outdated Show resolved Hide resolved
Copy link
Member

@jamiehenson jamiehenson left a comment

Choose a reason for hiding this comment

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

Looks great, very small comments. Also, did we lose the Small story? It was there when I first checked but not when I pulled the latest. Only thing that needs to be changed here is the package.json version, rest are suggestions

package.json Outdated Show resolved Hide resolved
src/core/Toggle.tsx Outdated Show resolved Hide resolved
src/core/Toggle.tsx Outdated Show resolved Hide resolved
src/core/Toggle.tsx Outdated Show resolved Hide resolved
@aralovelace aralovelace force-pushed the Add_toogle_size_option branch 2 times, most recently from 82f7fa6 to 84d6f05 Compare December 5, 2024 21:02
@aralovelace aralovelace force-pushed the Add_toogle_size_option branch from 969e483 to bbb8e64 Compare December 6, 2024 10:24
@aralovelace aralovelace force-pushed the Add_toogle_size_option branch from bbb8e64 to 68a8247 Compare December 6, 2024 10:31
Copy link
Member

@jamiehenson jamiehenson left a comment

Choose a reason for hiding this comment

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

🎚️

@aralovelace aralovelace merged commit 285b81e into main Dec 6, 2024
4 checks passed
@aralovelace aralovelace deleted the Add_toogle_size_option branch December 6, 2024 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants