Skip to content

Commit

Permalink
[base] Remove the legacy Extend* types (#38184)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak authored Aug 11, 2023
1 parent 731cd07 commit aa41bc0
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 109 deletions.
18 changes: 2 additions & 16 deletions packages/mui-base/src/Badge/Badge.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { OverrideProps, OverridableTypeMap, OverridableComponent, Simplify } from '@mui/types';
import { OverrideProps, Simplify } from '@mui/types';
import { SlotComponentProps } from '../utils';

export interface BadgeRootSlotPropsOverrides {}
Expand Down Expand Up @@ -75,23 +75,9 @@ export interface BadgeTypeMap<
defaultComponent: RootComponentType;
}

/**
* Utility to create component types that inherit props from Badge.
*/
export interface ExtendBadgeTypeMap<TypeMap extends OverridableTypeMap> {
props: TypeMap['props'] & BadgeTypeMap['props'];
defaultComponent: TypeMap['defaultComponent'];
}

export type ExtendBadge<TypeMap extends OverridableTypeMap> = OverridableComponent<
ExtendBadgeTypeMap<TypeMap>
>;

export type BadgeProps<
RootComponentType extends React.ElementType = BadgeTypeMap['defaultComponent'],
> = OverrideProps<BadgeTypeMap<{}, RootComponentType>, RootComponentType> & {
component?: RootComponentType;
};
> = OverrideProps<BadgeTypeMap<{}, RootComponentType>, RootComponentType>;

export type BadgeRootSlotProps = {
children?: React.ReactNode;
Expand Down
14 changes: 1 addition & 13 deletions packages/mui-base/src/Modal/Modal.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { OverridableComponent, OverridableTypeMap, Simplify } from '@mui/types';
import { Simplify } from '@mui/types';
import { PortalProps } from '../Portal';
import { PolymorphicProps, SlotComponentProps } from '../utils';

Expand Down Expand Up @@ -138,18 +138,6 @@ export interface ModalTypeMap<
defaultComponent: RootComponentType;
}

/**
* Utility to create component types that inherit props from Modal.
*/
export interface ExtendModalTypeMap<TypeMap extends OverridableTypeMap> {
props: TypeMap['props'] & ModalTypeMap['props'];
defaultComponent: TypeMap['defaultComponent'];
}

export type ExtendModal<TypeMap extends OverridableTypeMap> = OverridableComponent<
ExtendModalTypeMap<TypeMap>
>;

export type ModalProps<
RootComponentType extends React.ElementType = ModalTypeMap['defaultComponent'],
> = PolymorphicProps<ModalTypeMap<{}, RootComponentType>, RootComponentType>;
Expand Down
14 changes: 1 addition & 13 deletions packages/mui-base/src/Slider/Slider.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OverridableComponent, OverridableTypeMap, Simplify } from '@mui/types';
import { Simplify } from '@mui/types';
import * as React from 'react';
import { PolymorphicProps, SlotComponentProps, SlotComponentPropsWithSlotState } from '../utils';
import {
Expand Down Expand Up @@ -169,18 +169,6 @@ export interface SliderTypeMap<
defaultComponent: RootComponentType;
}

/**
* Utility to create component types that inherit props from Slider.
*/
export interface ExtendSliderTypeMap<TypeMap extends OverridableTypeMap> {
props: TypeMap['props'] & Omit<SliderTypeMap['props'], 'isRtl'>;
defaultComponent: TypeMap['defaultComponent'];
}

export type ExtendSlider<TypeMap extends OverridableTypeMap> = OverridableComponent<
ExtendSliderTypeMap<TypeMap>
>;

export type SliderProps<
RootComponentType extends React.ElementType = SliderTypeMap['defaultComponent'],
> = PolymorphicProps<SliderTypeMap<{}, RootComponentType>, RootComponentType>;
Expand Down
202 changes: 135 additions & 67 deletions packages/mui-material/src/Badge/Badge.d.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,158 @@
import * as React from 'react';
import { SxProps } from '@mui/system';
import { OverridableStringUnion } from '@mui/types';
import { BadgeTypeMap as BaseBadgeTypeMap, ExtendBadgeTypeMap } from '@mui/base/Badge';
import { OverridableStringUnion, Simplify } from '@mui/types';
import { SlotComponentProps } from '@mui/base/utils';
import { Theme } from '../styles';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import { BadgeClasses } from './badgeClasses';

export interface BadgePropsVariantOverrides {}

export interface BadgePropsColorOverrides {}
export interface BadgeRootSlotPropsOverrides {}
export interface BadgeBadgeSlotPropsOverrides {}

export type BadgeOwnerState = Simplify<
BadgeOwnProps & {
badgeContent: React.ReactNode;
invisible: boolean;
max: number;
displayValue: React.ReactNode;
showZero: boolean;
anchorOrigin: BadgeOrigin;
color: OverridableStringUnion<
'primary' | 'secondary' | 'default' | 'error' | 'info' | 'success' | 'warning',
BadgePropsColorOverrides
>;
overlap: 'rectangular' | 'circular';
variant: OverridableStringUnion<'standard' | 'dot', BadgePropsVariantOverrides>;
}
>;

export interface BadgeOrigin {
vertical: 'top' | 'bottom';
horizontal: 'left' | 'right';
}

export type BadgeTypeMap<
DefaultComponent extends React.ElementType = 'span',
AdditionalProps = {},
> = ExtendBadgeTypeMap<{
props: AdditionalProps & {
/**
* The anchor of the badge.
* @default {
* vertical: 'top',
* horizontal: 'right',
* }
*/
anchorOrigin?: BadgeOrigin;
/**
* Override or extend the styles applied to the component.
*/
classes?: Partial<BadgeClasses>;
/**
* @ignore
*/
className?: string;
/**
* The color of the component.
* It supports both default and custom theme colors, which can be added as shown in the
* [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors).
* @default 'default'
*/
color?: OverridableStringUnion<
'primary' | 'secondary' | 'default' | 'error' | 'info' | 'success' | 'warning',
BadgePropsColorOverrides
>;
/**
* The extra props for the slot components.
* You can override the existing props or add new ones.
*
* This prop is an alias for the `slotProps` prop.
* It's recommended to use the `slotProps` prop instead, as `componentsProps` will be deprecated in the future.
*
* @default {}
*/
componentsProps?: BaseBadgeTypeMap['props']['slotProps'];
/**
* The components used for each slot inside.
*
* This prop is an alias for the `slots` prop.
* It's recommended to use the `slots` prop instead.
*
* @default {}
*/
components?: {
Root?: React.ElementType;
Badge?: React.ElementType;
};
/**
* Wrapped shape the badge should overlap.
* @default 'rectangular'
*/
overlap?: 'rectangular' | 'circular';
export interface BadgeOwnProps {
/**
* The anchor of the badge.
* @default {
* vertical: 'top',
* horizontal: 'right',
* }
*/
anchorOrigin?: BadgeOrigin;
/**
* The content rendered within the badge.
*/
badgeContent?: React.ReactNode;
/**
* The badge will be added relative to this node.
*/
children?: React.ReactNode;
/**
* Override or extend the styles applied to the component.
*/
classes?: Partial<BadgeClasses>;
/**
* @ignore
*/
className?: string;
/**
* The color of the component.
* It supports both default and custom theme colors, which can be added as shown in the
* [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors).
* @default 'default'
*/
color?: OverridableStringUnion<
'primary' | 'secondary' | 'default' | 'error' | 'info' | 'success' | 'warning',
BadgePropsColorOverrides
>;
/**
* The extra props for the slot components.
* You can override the existing props or add new ones.
*
* This prop is an alias for the `slotProps` prop.
* It's recommended to use the `slotProps` prop instead, as `componentsProps` will be deprecated in the future.
*
* @default {}
*/
componentsProps?: BadgeOwnProps['slotProps'];
/**
* The components used for each slot inside.
*
* This prop is an alias for the `slots` prop.
* It's recommended to use the `slots` prop instead.
*
* @default {}
*/
components?: {
Root?: React.ElementType;
Badge?: React.ElementType;
};
/**
* If `true`, the badge is invisible.
* @default false
*/
invisible?: boolean;
/**
* Max count to show.
* @default 99
*/
max?: number;
/**
* Wrapped shape the badge should overlap.
* @default 'rectangular'
*/
overlap?: 'rectangular' | 'circular';
/**
* The props used for each slot inside the Badge.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'span', BadgeRootSlotPropsOverrides, BadgeOwnerState>;
badge?: SlotComponentProps<'span', BadgeBadgeSlotPropsOverrides, BadgeOwnerState>;
};
/**
* The components used for each slot inside the Badge.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots?: {
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
* The component that renders the root.
* @default 'span'
*/
sx?: SxProps<Theme>;
root?: React.ElementType;
/**
* The variant to use.
* @default 'standard'
* The component that renders the badge.
* @default 'span'
*/
variant?: OverridableStringUnion<'standard' | 'dot', BadgePropsVariantOverrides>;
badge?: React.ElementType;
};
/**
* Controls whether the badge is hidden when `badgeContent` is zero.
* @default false
*/
showZero?: boolean;
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme>;
/**
* The variant to use.
* @default 'standard'
*/
variant?: OverridableStringUnion<'standard' | 'dot', BadgePropsVariantOverrides>;
}

export interface BadgeTypeMap<
DefaultComponent extends React.ElementType = 'span',
AdditionalProps = {},
> {
props: AdditionalProps & BadgeOwnProps;
defaultComponent: DefaultComponent;
}>;
}

type BadgeRootProps = NonNullable<BadgeTypeMap['props']['slotProps']>['root'];
type BadgeBadgeProps = NonNullable<BadgeTypeMap['props']['slotProps']>['badge'];
Expand Down

0 comments on commit aa41bc0

Please sign in to comment.