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

[WIP] feat(Toggle): Implement base component #3860

Closed
wants to merge 1 commit into from

Conversation

will-lamb
Copy link
Contributor

@will-lamb will-lamb commented Aug 13, 2024

Related issue

Closes #3859

Overview

Created a Toggle component

Reason

To add a Toggle component to the design system

Work carried out

Example.

  • Created Toggle component with no Icons
  • Created Toggle component with Icons
  • Created a disabled Toggle component
  • A bit of work I did not complete

Screenshot

Screen.Recording.2024-08-15.at.18.03.38.mov

Developer notes

At the next major release, we should change the name of this component to Switch and change the current Switch component to ToggleGroup / Toggle

Copy link

netlify bot commented Aug 13, 2024

Deploy Preview for storybook-navy-digital-mod-uk ready!

Name Link
🔨 Latest commit 04543e5
🔍 Latest deploy log https://app.netlify.com/sites/storybook-navy-digital-mod-uk/deploys/66e97bf8dd50b60008d92dfa
😎 Deploy Preview https://deploy-preview-3860--storybook-navy-digital-mod-uk.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@will-lamb will-lamb marked this pull request as ready for review August 15, 2024 16:59
@will-lamb will-lamb self-assigned this Aug 15, 2024
@will-lamb will-lamb marked this pull request as draft August 15, 2024 17:34
Copy link
Collaborator

@m7kvqbe1 m7kvqbe1 left a comment

Choose a reason for hiding this comment

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

This is a great start! A few important things we need to consider:

  • Usage within forms and integration with different supported form libraries.
    • Understanding the difference between controlled and uncontrolled and supporting them.
    • It might be worth using an input type="checkbox" (remember defaultChecked).
    • Make sure the component supports a forwardedRef.
    • Check it plays nice with the Field wrapper component.
    • Update form usage examples and Playwright tests.
  • Make sure the appropriate ARIA and other a11y attributes are applied to the control.
  • The user should be able to manipulate the component solely by using the keyboard.
    • Styled focus state is missing.
  • The component should support an error state.
    • Red outline (see other form controls).

Very happy for you to continue rolling your own implementation as a learning exercise, but we need to make sure to address all of the stuff above. There is quite a lot to consider, which is why I suggested styling a hardened headless implementation like the Radix one:

https://github.com/radix-ui/primitives/blob/main/packages/react/switch/src/Switch.tsx

@will-lamb will-lamb force-pushed the feature/build-toggle-component branch 2 times, most recently from e6ba17f to b4badca Compare August 20, 2024 09:02
@will-lamb will-lamb force-pushed the feature/build-toggle-component branch from eeddec5 to a7bfc30 Compare August 28, 2024 10:16
@will-lamb will-lamb marked this pull request as ready for review August 28, 2024 10:17
@m7kvqbe1 m7kvqbe1 changed the title feat(Toggle): WIP feat(Toggle): Implement base component Sep 17, 2024
@m7kvqbe1 m7kvqbe1 changed the title feat(Toggle): Implement base component [WIP] feat(Toggle): Implement base component Sep 17, 2024
feat(Toggle): Created Toggle component

feat(Toggle): Created Toggle component

feat(Toggle): Working on spacing issues

feat(Toggle): Working on spacing issues

feat(Toggle): Spacing

feat(Toggle): Added Aria labels

feat(Toggle): Added test file

feat(Toggle): Added toggle to formik story

feat(Toggle): Centering Icons in Knobs

feat(Toggle): Scaled toggle to be bigger

feat(Toggle): Added keyboard handling

feat(Toggle): Updated test file

feat(Toggle): Updated toggle component

feat(Toggle): updated toggle test file

feat(Toggle): Updated form tests

feat(Toggle): Fixed cursor issues with disabled component

feat(Toggle): Updated form tests
@m7kvqbe1 m7kvqbe1 force-pushed the feature/build-toggle-component branch from a7bfc30 to 04543e5 Compare September 17, 2024 12:54
Copy link

sonarcloud bot commented Sep 17, 2024

@m7kvqbe1 m7kvqbe1 closed this Oct 30, 2024
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.

Create toggle component
2 participants