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(18794): add two-directional feature to toggle component #94

Merged
merged 5 commits into from
Jun 18, 2024

Conversation

Natallia-Harshunova
Copy link
Contributor

@Natallia-Harshunova Natallia-Harshunova commented Jun 17, 2024

https://kontur.fibery.io/Tasks/Team/Insights-6/Tasks-by-User-Stories-current-and-next-sprint-3939#Task/Improve-ui-kit-for-pricing-page-needs-18794

Summary by CodeRabbit

  • New Features

    • Added a new FavAdded16 icon component.
  • Enhancements

    • Updated the Toggler component to handle payment frequency selection with new labels for "Annually" and "Monthly."
    • Introduced additional properties to the Toggler component for improved label and style customization.
  • Style

    • Added new CSS class .twoDirectional for enhanced styling of toggle elements.

Copy link

coderabbitai bot commented Jun 17, 2024

Walkthrough

The recent updates introduce a new SVG icon component FavAdded16 in the default-icons package and enhance the Toggler component within the ui-kit package. The FavAdded16 icon is now optimized and exported for reuse. In the Toggler, new functionalities, such as handling payment frequency and additional label properties, were implemented. Styling adjustments were made to support these new features, enhancing both visual and functional aspects.

Changes

Files Change Summary
packages/.../FavAdded16.tsx Added new memoized FavAdded16 component, set displayName, and exported.
packages/.../index.ts Exported the new FavAdded16 component alongside existing exports.
packages/ui-kit/src/Toggler/Toggler.fixture.tsx Enhanced Toggler with additional state and UI for payment frequency selection, modified onChange function, and added styling classes.
packages/ui-kit/src/Toggler/index.tsx Updated Toggler interface with new properties (leftLabel, offValueLabel, and classes), and adjusted label rendering logic to include these new properties.
packages/ui-kit/src/Toggler/style.module.css Introduced new .twoDirectional class for toggle element styling, including background color and margin properties.

Poem

🐇 In the realm of code so fine,
A new icon doth brightly shine.
The Toggler now with flair and gleam,
From monthly dreams to yearly scheme.
Stylish toggles, swift and slick,
A rabbit's touch, a coder's trick.
Hopping through lines, our joy we share,
In every byte, boundless care. 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

github-actions bot commented Jun 17, 2024

♻️ PR Preview 559c05f has been successfully destroyed since this PR has been closed.

🤖 By surge-preview

Copy link

@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 comments (2)
packages/ui-kit/src/Toggler/index.tsx (1)

Line range hint 8-32: Consider using a self-closing tag for the toggle div.

30a31
>       <div className={s.toggle} />

For elements without children, like the toggle div, using self-closing tags can improve the readability and cleanliness of the code.

Tools
Biome

[error] 31-31: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing. (lint/style/useSelfClosingElements)

Unsafe fix: Use a SelfClosingElement instead

packages/ui-kit/src/Toggler/Toggler.fixture.tsx (1)

Line range hint 19-31: Refactor the state update logic for clarity.

23c23
<       setState((state) => ((state[e.target.id] = e.target.checked), { ...state }));
---
>       setState((prevState) => ({ ...prevState, [e.target.id]: e.target.checked }));

The current state update logic uses the comma operator, which can be confusing and obscure side effects. It's better to use a more straightforward approach for updating the state.

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 923d0ff and 0eed880.

Files selected for processing (5)
  • packages/default-icons/src/figma-icons/FavAdded16.tsx (1 hunks)
  • packages/default-icons/src/figma-icons/index.ts (1 hunks)
  • packages/ui-kit/src/Toggler/Toggler.fixture.tsx (2 hunks)
  • packages/ui-kit/src/Toggler/index.tsx (2 hunks)
  • packages/ui-kit/src/Toggler/style.module.css (1 hunks)
Additional context used
Biome
packages/default-icons/src/figma-icons/FavAdded16.tsx

[error] 4-4: Alternative text title element cannot be empty (lint/a11y/noSvgWithoutTitle)

For accessibility purposes, SVGs should have an alternative text, provided via title element. If the svg element has role="img", you should add the aria-label or aria-labelledby attribute.

packages/ui-kit/src/Toggler/index.tsx

[error] 31-31: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing. (lint/style/useSelfClosingElements)

Unsafe fix: Use a SelfClosingElement instead

packages/ui-kit/src/Toggler/Toggler.fixture.tsx

[error] 23-23: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 23-23: The comma operator is disallowed. (lint/style/noCommaOperator)

Its use is often confusing and obscures side effects.

Additional comments not posted (5)
packages/default-icons/src/figma-icons/FavAdded16.tsx (1)

14-16: Good use of memo for performance optimization.

packages/ui-kit/src/Toggler/index.tsx (1)

18-32: Well-implemented new leftLabel property.

Tools
Biome

[error] 31-31: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing. (lint/style/useSelfClosingElements)

Unsafe fix: Use a SelfClosingElement instead

packages/ui-kit/src/Toggler/Toggler.fixture.tsx (1)

Line range hint 19-31: Good addition of the payment state variable.

packages/ui-kit/src/Toggler/style.module.css (1)

60-75: The new .twoLabels class is well-defined and enhances the component styling.

packages/default-icons/src/figma-icons/index.ts (1)

183-183: Export of FavAdded16 correctly follows existing module patterns.

@albaranau
Copy link
Contributor

albaranau commented Jun 17, 2024

Please rename the PR according to Conventional Commits naming + give it more informative name

Copy link
Contributor

@albaranau albaranau left a comment

Choose a reason for hiding this comment

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

Please address the comments

@Natallia-Harshunova Natallia-Harshunova changed the title 18794 improve UI kit for pricing page needs feat(18794): add two-directional feature to toggle component Jun 17, 2024
Copy link

@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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 0eed880 and 4ffb015.

Files selected for processing (4)
  • packages/ui-kit/src/Toggler/Toggler.fixture.style.module.css (1 hunks)
  • packages/ui-kit/src/Toggler/Toggler.fixture.tsx (3 hunks)
  • packages/ui-kit/src/Toggler/index.tsx (2 hunks)
  • packages/ui-kit/src/Toggler/style.module.css (1 hunks)
Additional context used
Biome
packages/ui-kit/src/Toggler/index.tsx

[error] 42-42: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing. (lint/style/useSelfClosingElements)

Unsafe fix: Use a SelfClosingElement instead

packages/ui-kit/src/Toggler/Toggler.fixture.tsx

[error] 29-29: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 29-29: The comma operator is disallowed. (lint/style/noCommaOperator)

Its use is often confusing and obscures side effects.

Additional comments not posted (3)
packages/ui-kit/src/Toggler/index.tsx (1)

8-13: The addition of leftLabel and related class handling enhances the component's flexibility. Ensure className prop is appropriately used when leftLabel is rendered.

packages/ui-kit/src/Toggler/style.module.css (1)

60-65: The new .twoDirectional class provides specific styling for toggles with dual directions. Ensure consistency in design when applying these styles across different components.

packages/ui-kit/src/Toggler/Toggler.fixture.tsx (1)

20-26: The addition of payment state and associated classes enhances the interactive capabilities of this fixture.

packages/ui-kit/src/Toggler/index.tsx Outdated Show resolved Hide resolved
packages/ui-kit/src/Toggler/Toggler.fixture.tsx Outdated Show resolved Hide resolved
packages/ui-kit/src/Toggler/index.tsx Outdated Show resolved Hide resolved
packages/ui-kit/src/Toggler/Toggler.fixture.tsx Outdated Show resolved Hide resolved
packages/ui-kit/src/Toggler/Toggler.fixture.tsx Outdated Show resolved Hide resolved
Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 4ffb015 and 559c05f.

Files selected for processing (2)
  • packages/ui-kit/src/Toggler/Toggler.fixture.tsx (2 hunks)
  • packages/ui-kit/src/Toggler/index.tsx (2 hunks)
Additional context used
Biome
packages/ui-kit/src/Toggler/index.tsx

[error] 42-42: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing. (lint/style/useSelfClosingElements)

Unsafe fix: Use a SelfClosingElement instead

Additional comments not posted (3)
packages/ui-kit/src/Toggler/index.tsx (1)

8-13: Consider renaming offValueLabel to reflect its purpose more clearly, such as negativeLabel or offLabel.
: This is a repeat of a previous comment by albaranau.

packages/ui-kit/src/Toggler/Toggler.fixture.tsx (2)

20-28: The state management and event handling in the onChange function are implemented correctly. However, consider renaming isAnnualPayment to a more descriptive name like annualPaymentMode for clarity.
: This is a repeat of a previous comment by albaranau.


36-46: The implementation of the Toggler component for the isAnnualPayment toggle is correct. Ensure that the CSS classes used (s.label, s.active) are well-defined in the associated CSS module to maintain style consistency.

Comment on lines +31 to +43
<label
className={cn(
s.root,
{ [s.checked]: on, [s.disabled]: native.disabled, [s.twoDirectional]: offValueLabel },
className,
)}
>
<input id={id} className={s.hidden} type="checkbox" {...native} checked={on} />
{offValueLabel && (
<div className={cn(s.label, classes?.label, { [classes?.activeLabel || '']: !on })}>{offValueLabel}</div>
)}
<div className={s.toggle}></div>
<div className={s.label}>{label}</div>
<div className={cn(s.label, classes?.label, { [classes?.activeLabel || '']: on })}>{label}</div>
Copy link

Choose a reason for hiding this comment

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

Ensure the <div className={s.toggle}></div> is self-closing to adhere to JSX best practices.

- <div className={s.toggle}></div>
+ <div className={s.toggle} />
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
<label
className={cn(
s.root,
{ [s.checked]: on, [s.disabled]: native.disabled, [s.twoDirectional]: offValueLabel },
className,
)}
>
<input id={id} className={s.hidden} type="checkbox" {...native} checked={on} />
{offValueLabel && (
<div className={cn(s.label, classes?.label, { [classes?.activeLabel || '']: !on })}>{offValueLabel}</div>
)}
<div className={s.toggle}></div>
<div className={s.label}>{label}</div>
<div className={cn(s.label, classes?.label, { [classes?.activeLabel || '']: on })}>{label}</div>
<label
className={cn(
s.root,
{ [s.checked]: on, [s.disabled]: native.disabled, [s.twoDirectional]: offValueLabel },
className,
)}
>
<input id={id} className={s.hidden} type="checkbox" {...native} checked={on} />
{offValueLabel && (
<div className={cn(s.label, classes?.label, { [classes?.activeLabel || '']: !on })}>{offValueLabel}</div>
)}
<div className={s.toggle} />
<div className={cn(s.label, classes?.label, { [classes?.activeLabel || '']: on })}>{label}</div>
Tools
Biome

[error] 42-42: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing. (lint/style/useSelfClosingElements)

Unsafe fix: Use a SelfClosingElement instead

@Natallia-Harshunova Natallia-Harshunova merged commit 38cb9fa into v5 Jun 18, 2024
3 checks passed
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.

3 participants