Skip to content

Commit

Permalink
add required default values to OwnerState
Browse files Browse the repository at this point in the history
  • Loading branch information
lhilgert9 committed Nov 22, 2023
1 parent 922509e commit 3d1b302
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
19 changes: 8 additions & 11 deletions packages/mui-material-next/src/Switch/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import switchClasses, { getSwitchUtilityClass } from './switchClasses';
import { SwitchOwnerState, SwitchProps, SwitchTypeMap } from './Switch.types';

const useUtilityClasses = (ownerState: SwitchOwnerState) => {
const { classes, edge, size = 'medium', color = 'primary', checked, disabled } = ownerState;
const { classes, edge, size, color, checked, disabled } = ownerState;

const slots = {
root: ['root', edge && `edge${capitalize(edge)}`, `size${capitalize(size)}`],
Expand Down Expand Up @@ -143,32 +143,29 @@ const SwitchSwitchBase = styled(SwitchBase, {
},
...(ownerState.color !== 'default' && {
[`&.${switchClasses.checked}`]: {
color: (theme.vars || theme).palette[ownerState.color ?? 'primary'].main,
color: (theme.vars || theme).palette[ownerState.color].main,
'&:hover': {
backgroundColor: theme.vars
? `rgba(${theme.vars.palette[ownerState.color ?? 'primary'].mainChannel} / ${
? `rgba(${theme.vars.palette[ownerState.color].mainChannel} / ${
theme.vars.palette.action.hoverOpacity
})`
: alpha(
theme.palette[ownerState.color ?? 'primary'].main,
theme.palette.action.hoverOpacity,
),
: alpha(theme.palette[ownerState.color].main, theme.palette.action.hoverOpacity),
'@media (hover: none)': {
backgroundColor: 'transparent',
},
},
[`&.${switchClasses.disabled}`]: {
color: theme.vars
? theme.vars.palette.Switch[`${ownerState.color ?? 'primary'}DisabledColor`]
? theme.vars.palette.Switch[`${ownerState.color}DisabledColor`]
: `${
theme.palette.mode === 'light'
? lighten(theme.palette[ownerState.color ?? 'primary'].main, 0.62)
: darken(theme.palette[ownerState.color ?? 'primary'].main, 0.55)
? lighten(theme.palette[ownerState.color].main, 0.62)
: darken(theme.palette[ownerState.color].main, 0.55)
}`,
},
},
[`&.${switchClasses.checked} + .${switchClasses.track}`]: {
backgroundColor: (theme.vars || theme).palette[ownerState.color ?? 'primary'].main,
backgroundColor: (theme.vars || theme).palette[ownerState.color].main,
},
}),
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material-next/src/Switch/Switch.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { SxProps } from '@mui/system';
import { OverridableStringUnion, OverrideProps } from '@mui/types';
import { OverridableStringUnion, OverrideProps, PartiallyRequired } from '@mui/types';
import { Theme } from '@mui/material/styles';
// eslint-disable-next-line no-restricted-imports
import { InternalStandardProps as StandardProps } from '@mui/material';
Expand Down Expand Up @@ -69,4 +69,4 @@ export type SwitchProps<
AdditionalProps = {},
> = OverrideProps<SwitchTypeMap<AdditionalProps, RootComponentType>, RootComponentType>;

export interface SwitchOwnerState extends SwitchProps {}
export interface SwitchOwnerState extends PartiallyRequired<SwitchProps, 'color' | 'size'> {}

0 comments on commit 3d1b302

Please sign in to comment.