import type { ComponentType, ForwardRefExoticComponent, JSX, RefAttributes } from 'react' import type React from 'react' export type ExtractProps = T extends ComponentType ? P : T export type AnyTag = keyof JSX.IntrinsicElements // Source: https://github.com/emotion-js/emotion/blob/master/packages/styled-base/types/helper.d.ts // A more precise version of just React.ComponentPropsWithoutRef on its own export type PropsOf> = JSX.LibraryManagedAttributes> interface AsProp { /** * An override of the default HTML tag. * Can also be another React component. */ as?: C } /** * Allows for extending a set of props (`ExtendedProps`) by an overriding set of props * (`OverrideProps`), ensuring that any duplicates are overridden by the overriding * set of props. */ export type ExtendableProps< ExtendedProps = Record, OverrideProps = Record, > = OverrideProps & Omit /** * Allows for inheriting the props from the specified element type so that * props like children, className & style work, as well as element-specific * attributes like aria roles. The component (`C`) must be passed in. */ export type InheritableElementProps> = ExtendableProps< PropsOf, Props > /** * A more sophisticated version of `InheritableElementProps` where * the passed in `as` prop will determine which props can be included */ export type PolymorphicComponentProps< C extends React.ElementType, Props = Record, > = InheritableElementProps> /** * Utility type to extract the `ref` prop from a polymorphic component */ export type PolymorphicRef = React.ComponentPropsWithRef['ref'] /** * A wrapper of `PolymorphicComponentProps` that also includes the `ref` * prop for the polymorphic component */ export type PolymorphicComponentPropsWithRef< C extends React.ElementType, Props = Record, > = PolymorphicComponentProps & { ref?: PolymorphicRef } export type ForwardRefWithAttributes< C extends HTMLElement, Props = Record, > = ForwardRefExoticComponent & RefAttributes>