themesberg / flowbite-react

Official React components built for Flowbite and Tailwind CSS
https://flowbite-react.com
MIT License
1.77k stars 395 forks source link

react-icons v5 (required by ui/package.json) is not type compatible with icon prop in components like Alert #1359

Open akshetpandey opened 2 months ago

akshetpandey commented 2 months ago

Steps to reproduce

Sample form https://flowbite-react.com/docs/components/alert#alert-with-icon

import { HiInformationCircle } from "react-icons/hi";
import { Alert } from "flowbite-react";

function Component() {
  return (
    <Alert color="failure" icon={HiInformationCircle}>
      <span className="font-medium">Info alert!</span> Change a few things up and try submitting again.
    </Alert>
  );
}

This will produce a TS error: HiInformationCircle:IconType is not assignable to icon:FC<SVGProps<SVGSVGElement>>

victorfunes commented 2 months ago

I found the same, and as a work around I defined this type:

export type IconSVGProps = React.PropsWithoutRef<React.SVGProps<SVGSVGElement>> & React.RefAttributes<SVGSVGElement>;
export type FlowbiteIconProps = IconSVGProps & {
  title?: string;
  titleId?: string;
};

export type FlowbiteIcon = FC<Omit<SVGProps<SVGSVGElement>, "ref">> & FlowbiteIconProps;

then you can do something like this in the flowbite components with the issue:

icon={FilmIcon as FlowbiteIcon}