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

[SwitchUnstyled] Define ownerState and slot props' types #32573

Merged
merged 3 commits into from
May 24, 2022

Conversation

michaldudak
Copy link
Member

Defined types for SwitchUnstyled's ownerState, its slots and useSwitch return type.
Also renamed types and files according to #31415

@michaldudak michaldudak added component: switch This is the name of the generic UI component, not the React module! typescript package: base-ui Specific to @mui/base labels May 3, 2022
@michaldudak michaldudak requested a review from a team May 3, 2022 08:13
@mui-bot
Copy link

mui-bot commented May 3, 2022

Details of bundle changes

Generated by 🚫 dangerJS against 3ecf140

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label May 9, 2022
@michaldudak michaldudak force-pushed the ownerstate-types/switch branch from 818ec67 to e31af1c Compare May 10, 2022 11:30
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label May 10, 2022
@michaldudak michaldudak changed the title [SwitchUnstyled] Add types for ownerState and slots [SwitchUnstyled] Define ownerState and slot props' types May 10, 2022
PropTypes.oneOf(['danger', 'info', 'primary', 'success', 'warning']),
PropTypes.string,
]),
color: PropTypes.oneOf(['danger', 'info', 'neutral', 'primary', 'success', 'warning']),
Copy link
Member

Choose a reason for hiding this comment

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

We should revert these no?

Copy link
Member Author

@michaldudak michaldudak May 12, 2022

Choose a reason for hiding this comment

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

Yes, thanks!

BTW, the generated proptypes include neutral, which does not exist in the hardcoded ones (it's a similar case in `variant'). Shouldn't the hardcoded ones be updated? (cc @siriwatknp)

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch, I guess it should be added indeed. @siriwatknp in case if you missed the prev notification :)

PropTypes.oneOf(['danger', 'info', 'primary', 'success', 'warning']),
PropTypes.string,
]),
color: PropTypes.oneOf(['danger', 'info', 'neutral', 'primary', 'success', 'warning']),
Copy link
Member

Choose a reason for hiding this comment

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

These too.

onFocus: (event: React.FocusEvent) => handleFocus(event, otherProps.onFocus),
onBlur: (event: React.FocusEvent) => handleBlur(event, otherProps.onBlur),
ref: handleRefChange,
onChange: createHandleInputChange(otherProps),
Copy link
Member

Choose a reason for hiding this comment

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

Much more readable 👍

required?: boolean;
}

interface UseSwitchInputSlotOwnProps {
Copy link
Member

Choose a reason for hiding this comment

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

Should we extend here UseSwitchParameters?

Copy link
Member Author

@michaldudak michaldudak May 24, 2022

Choose a reason for hiding this comment

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

The optionality of parameters differs. Plus, the UseSwitchParameters has onFocusVisible, which is not a valid HTML parameter. I could Pick, Omit, etc. but it would be less readable than specifying the interface explicitly IMO.


describe('useSwitch', () => {
const { render } = createRenderer();
const invokeUseSwitch = (props: UseSwitchProps): UseSwitchResult => {
const ref = React.createRef<UseSwitchResult>();
const invokeUseSwitch = (props: UseSwitchParameters) => {
Copy link
Member

Choose a reason for hiding this comment

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

Let's mark this as breaking change so that we can add it in the changelog for people to be aware of.

@michaldudak michaldudak merged commit ae87437 into mui:master May 24, 2022
@michaldudak michaldudak deleted the ownerstate-types/switch branch May 24, 2022 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: switch This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants