import React from 'react' type Rainbow = | 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'indigo' | 'violet' type PolymorphicRef = React.ComponentPropsWithRef['ref'] type AsProp = { as?: C } type PropsToOmit = keyof (AsProp & P) type PolymorphicComponentProp< C extends React.ElementType, Props = object, > = React.PropsWithChildren> & Omit, PropsToOmit> type PolymorphicComponentPropWithRef< C extends React.ElementType, Props = object, > = PolymorphicComponentProp & { ref?: PolymorphicRef } type TextProps = PolymorphicComponentPropWithRef< C, { color?: Rainbow | 'black' } > type TextComponent = ( props: TextProps, ) => React.ReactElement | null const TextRef = React.forwardRef( ( { as, color, children }: TextProps, ref?: PolymorphicRef, ) => { const Component = as || 'span' const style = color ? { style: { color } } : {} return ( {children} ) }, ) TextRef.displayName = 'Text' export const Text = TextRef as unknown as TextComponent