UNPKG

1.39 kBTypeScriptView Raw
1import * as React from 'react';
2import { Simplify } from '@mui/types';
3/**
4 * Type of the ownerState based on the type of an element it applies to.
5 * This resolves to the provided OwnerState for React components and `undefined` for host components.
6 * Falls back to `OwnerState | undefined` when the exact type can't be determined in development time.
7 */
8type OwnerStateWhenApplicable<ElementType extends React.ElementType, OwnerState> = ElementType extends React.ComponentType<any> ? OwnerState : ElementType extends keyof JSX.IntrinsicElements ? undefined : OwnerState | undefined;
9export type AppendOwnerStateReturnType<ElementType extends React.ElementType, OtherProps, OwnerState> = Simplify<OtherProps & {
10 ownerState: OwnerStateWhenApplicable<ElementType, OwnerState>;
11}>;
12/**
13 * Appends the ownerState object to the props, merging with the existing one if necessary.
14 *
15 * @param elementType Type of the element that owns the `existingProps`. If the element is a DOM node or undefined, `ownerState` is not applied.
16 * @param otherProps Props of the element.
17 * @param ownerState
18 */
19export default function appendOwnerState<ElementType extends React.ElementType, OtherProps extends Record<string, any>, OwnerState>(elementType: ElementType | undefined, otherProps: OtherProps, ownerState: OwnerState): AppendOwnerStateReturnType<ElementType, OtherProps, OwnerState>;
20export {};