From 3d1b3026d8bdc16c1b52a26a6131674b8420808d Mon Sep 17 00:00:00 2001 From: Lucas Hilgert Date: Wed, 22 Nov 2023 13:58:08 +0100 Subject: [PATCH] add required default values to OwnerState --- .../mui-material-next/src/Switch/Switch.tsx | 19 ++++++++----------- .../src/Switch/Switch.types.ts | 4 ++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/mui-material-next/src/Switch/Switch.tsx b/packages/mui-material-next/src/Switch/Switch.tsx index 84b0d1e2e814bd..1cb06ff76c5ce2 100644 --- a/packages/mui-material-next/src/Switch/Switch.tsx +++ b/packages/mui-material-next/src/Switch/Switch.tsx @@ -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)}`], @@ -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, }, }), }), diff --git a/packages/mui-material-next/src/Switch/Switch.types.ts b/packages/mui-material-next/src/Switch/Switch.types.ts index f33c49fc5c5c85..2d5a89dd053cc2 100644 --- a/packages/mui-material-next/src/Switch/Switch.types.ts +++ b/packages/mui-material-next/src/Switch/Switch.types.ts @@ -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'; @@ -69,4 +69,4 @@ export type SwitchProps< AdditionalProps = {}, > = OverrideProps, RootComponentType>; -export interface SwitchOwnerState extends SwitchProps {} +export interface SwitchOwnerState extends PartiallyRequired {}