Chronstruct / primitives

MIT License
3 stars 0 forks source link

fix `as` type!? #124

Open kylpo opened 6 months ago

kylpo commented 6 months ago

Does this work!? https://www.christianvm.dev/blog/react-as-prop

type PolymorphicProps<E extends React.ElementType> = React.PropsWithChildren<
   React.ComponentPropsWithoutRef<E> & {
      as?: E
   }
>

type TypographyProps<T extends React.ElementType> = PolymorphicProps<T> & {
   color?: string
}

export function Typography<T extends React.ElementType = 'p'>({
   as,
   color,
   ...props
}: TypographyProps<T>) {
   const Component = as || 'p'
   console.log(color)

   return <Component {...props} />
}