-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Enable the type to be an enumerator instead of a type. #25
Comments
We can do that 👍Would be string enum because I think if you use the icons with a registry it's better to have a string as runtime representation than a number. Generally, you should already get a list of all available icons by using the type. Usually, your IDEA can display them and you would see a list of all available icons. So if for example, your component accepts an icon of Just out of curiosity, what is your use case? |
Yes, I use IntelliJ and VSCode. My VSCode does not autocomplete it but IntelliJ does, although is not quite the same experience as with an enum. But my main use case is that I have a components library using Storybook, and I can easily provide the list of available icons through a dropdown to the end user (UI/UX) team by setting a I'm half way with a PR to the project with the enum implementation. My idea was to implement a variable |
Wow. Sounds amazing. Looking forward to the PR! 👍 |
I second that. Enum instead of type! It is also possible to iterate through an enum, since it doesn't get "lost" from TS -> JS compilation. Therefore creating a demo page showing off all icons is much easier. |
I think we should support both. Maybe some background why it is currently a type. Most often the icons are used with a component and a registry. The usage for an end consumers would be the following:
In such a scenario using a type has the following advantage.
But I also see the point where it is easier to display all the available icons. |
I understand @kreuzerk. I'm currently finishing this implementation and thus I was thinking that we can add two options: 1 - My only question is what do you believe is the best as the default option? |
It's also possible to export both an quasi export type DinosaurIcon = 'tyrannosaurusIcon' | 'stegosaurusIcon';
export const DinosaurIcon = {
tyrannosaurusIcon: 'tyrannosaurusIcon' as DinosaurIcon,
stegosaurusIcon: 'stegosaurusIcon' as DinosaurIcon
}; Then you can pass in either a string, as currently, or use the DinosaurIcon.tyrannosaurusIcon. And easily map it to an array, like so: export function enumToStringArray<T>(_enum: Object): T[] {
return Object.keys(_enum).map(k => _enum[k]);
}
const iconArray = [
...enumToStringArray<DinosaurIcon>(DinosaurIcon),
]; |
I personally would prefer to generate types by default. Then I would also offer the possibility to generate only the const or const and type like suggested by @akehir. I would not generate both by default. I imagine some options like this
|
Fixed with version 4.2.0. Thanks to everybody involved in the discussion and special thank to @felipeplets for the awesome PR. |
I've been using the library since version 2 and for my use case the best would be that type can be an enumerator instead so that users have easily idea of all the icon options available in the library.
The text was updated successfully, but these errors were encountered: