Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supertype for icons? #542

Closed
RobRoseKnows opened this issue Nov 3, 2021 · 4 comments
Closed

Supertype for icons? #542

RobRoseKnows opened this issue Nov 3, 2021 · 4 comments

Comments

@RobRoseKnows
Copy link

As of #64, there's now Typescript types for the icons. I was hoping though that there could be some sort of "supertype" for all the icons, so that I could define a React component that would require an icon instead of just a generic ReactNode. My usecase is I'm trying to make a generic version of this component from Tailwind UI, and it would be nice if I could make it so a generic icon could be provided.

@timroes
Copy link

timroes commented Nov 27, 2021

Since all icons are just taking svgs props into them (since they are just that), you can define a type for any generic icons, like:

type Icon = React.ComponentType<React.ComponentProps<'svg'>>;

@RobRoseKnows
Copy link
Author

Good point, I ended up figuring that out and forgot to close earlier. Thanks!

@jaidetree
Copy link

It seems in a recent update that definition no longer applies. Anyone know what it should be now?

@michaelphines
Copy link

michaelphines commented May 28, 2023

This works for me:

export type HeroIcon = React.ComponentType<
  React.PropsWithoutRef<React.ComponentProps<"svg">> & {
    title?: string | undefined;
    titleId?: string | undefined;
  }
>;

I think you can also just do something like get the typeof an example icon:

import { PencilIcon } from "@heroicons/react/24/outline";
export type HeroIcon = typeof PencilIcon;

Both have upsides and downsides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants