import { type ComponentPropsWithoutRef, type ElementType, type ForwardRefExoticComponent, type ReactNode, type Ref, type RefAttributes } from 'react'; import { type TypographySlotRecipeVariant } from '../../styled-system/recipes'; /** * Extract the ref type from a component. */ type ExtractRefType = Component extends ForwardRefExoticComponent ? Props extends RefAttributes ? Ref : never : never; type Props = { /** * The content to display. */ children?: ReactNode; /** * Specify the variant of Typography from the following list: * * 'body', 'strongBody', 'condensedBody', 'strongCondensedBody', 'amount', 'strongAmount', 'helpMessage', 'strongHelpMessage', 'label', 'controlLabel', 'condensedControlLabel', 'impactControlLabel', 'strongControlLabel', 'pageHeading1', 'pageHeading2', 'sectionHeading1', 'sectionHeading2', 'contentHeading' * * @default 'body' */ variant?: TypographySlotRecipeVariant['variant']; /** * Additional class names to apply to the component. * * Use this prop if you need to change the color of the component. */ className?: string; }; /** * Typography props when users don't pass `as` or `href` prop, it will be a span element. */ type TypographySpanProps = { as?: never; href?: never; ref?: Ref; } & ComponentPropsWithoutRef<'span'>; /** * Typography props when users pass `href` prop, it will be an anchor element. */ type TypographyAnchorProps = { as?: never; href: string; ref?: Ref; } & ComponentPropsWithoutRef<'a'>; /** * Typography props when users pass `as` prop, it will be a dynamic element. */ type TypographyDynamicProps = { as: Component; ref?: Ref>; } & ComponentPropsWithoutRef; /** * The base props for the Typography component. * It will automatically determine the element type based on the props passed. * * @template C - The element type. */ type TypographyBaseProps = TypographySpanProps | TypographyAnchorProps | TypographyDynamicProps; /** * The props for the Typography component. * It will automatically determine the element type based on the props passed. * * If `as` is provided, it should be the specified element. * If `as` is undefined and `href` is provided, it should be an anchor element. * Otherwise, it should be a span element. */ export type TypographyProps = Props & TypographyBaseProps; /** * Dynamic-only props for Typography component. * * Use this type when creating wrapper components that need proper TypeScript * inference for element-specific props. Unlike TypographyProps, this type * only includes the dynamic element branch, allowing TypeScript to properly * narrow the type based on the generic parameter. * * @typeParam Component - The HTML element type (e.g., 'time', 'a', 'div') * * @example * ```tsx * type DateTextProps = TypographyDynamicOnlyProps<'time'>; * * const DateText = ({ dateTime, ...rest }: DateTextProps) => ( * * ); * ``` */ export type TypographyDynamicOnlyProps = Props & TypographyDynamicProps; export {};