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

[Joy] Add functional Switch component #30487

Merged
merged 14 commits into from
Jan 7, 2022

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Jan 4, 2022

Preview: https://deploy-preview-30487--material-ui.netlify.app/experiments/joy/switch/

Summary

  • add Switch component to Joy
  • add unit tests
  • add types spec
  • add visual regression

Review suggestion

  • please review the unstyled usage, tests, and necessary props
  • theme & CSS variables can be neglected in this PR
  • you can skip docs/pages/experiments/joy/switch.tsx

@siriwatknp siriwatknp changed the title [Joy] Add Switch component [Joy] Add functional Switch component Jan 4, 2022
@mui-pr-bot
Copy link

mui-pr-bot commented Jan 4, 2022

Details of bundle changes

@mui/joy: parsed: +7.26% , gzip: +5.63%

Generated by 🚫 dangerJS against f0be10a

@siriwatknp siriwatknp marked this pull request as ready for review January 4, 2022 10:00
Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

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

Good work overall! I found just a few things to discuss.

name: 'MuiSwitch',
slot: 'Track',
overridesResolver: (props, styles) => styles.track,
})<{ ownerState: SwitchProps & { focusVisible: boolean } }>(() => ({
Copy link
Member

Choose a reason for hiding this comment

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

This reminds me I need to export the SwitchOwnerState interface to avoid construction of such types ad hoc.

Comment on lines 180 to 182
<SwitchTrack ownerState={ownerState} className={clsx(classes.track)} />
<SwitchThumb ownerState={ownerState} className={clsx(classes.thumb)} />
<SwitchInput ownerState={ownerState} {...getInputProps()} className={clsx(classes.input)} />
Copy link
Member

Choose a reason for hiding this comment

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

I see there's no ability to customize the props of inner components (componentsProps is not exposed). Is it by design or do you plan to still add it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, I will add it.

return generateUtilityClass('MuiSwitch', slot);
}

const switchClasses: SwitchClasses = generateUtilityClasses('MuiSwitch', [
Copy link
Member

Choose a reason for hiding this comment

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

IMO we should use a different prefix to avoid conflicts with @mui/material's Switch. It may be a rare use case to have both in the same project, but it doesn't cost us anything to prevent such problems.

Copy link
Member Author

Choose a reason for hiding this comment

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

avoid conflicts with @mui/material's Switch

Do you mean when developers use both material and joy in the same project? In that case, they can do this:

import { switchClasses as materialSwitchClasses } from '@mui/material/Switch';
import { switchClasses as joySwitchClasses } from '@mui/joy/Switch';

unless I misunderstand the meaning of the different prefix that you mentioned.

Copy link
Member

Choose a reason for hiding this comment

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

No, I meant the MuiSwitch prefix that gets added to CSS classes. If a project uses plain CSS to customize our components, it'll be impossible to differentiate between Material's Switch and Joy's Switch, as they both will have MuiSwitch-* classes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, got it. I will change it in another PR for Switch, Button and Typography.

@siriwatknp siriwatknp requested a review from michaldudak January 6, 2022 04:41
Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

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

👍

@siriwatknp siriwatknp merged commit bf85575 into mui:master Jan 7, 2022
wladimirguerra pushed a commit to wladimirguerra/material-ui that referenced this pull request Feb 2, 2022
@zannager zannager added the design: joy This is about Joy Design, please involve a visual or UX designer in the process label Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design: joy This is about Joy Design, please involve a visual or UX designer in the process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants