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

Added Static class IconType for intellisense #987

Merged

Conversation

porkopek
Copy link
Contributor

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • Bundle size optimization
  • Performance optimization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other A convenience static class for icons, with the same sugar as an Enum

🔗 Related issue link

The Icon Type expects a string, not an enum, but there is no way to use this component without insert a magic string as the Type. With this static class, you don't need to remember the name of the icons, nor you can write the wrong name, besides it provides intellisense.

💡 Background and solution

I made a static class to provide intellisense and type safety for icons
image

📝 Changelog

No breaking changes, just more convenience

Language Changelog
🇺🇸 English X
🇨🇳 Chinese

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Changelog is provided or not needed

@codecov-io
Copy link

codecov-io commented Jan 15, 2021

Codecov Report

Merging #987 (0584325) into master (81d6603) will decrease coverage by 0.06%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #987      +/-   ##
=========================================
- Coverage    5.58%   5.51%   -0.07%     
=========================================
  Files         406     408       +2     
  Lines       21815   22663     +848     
=========================================
+ Hits         1218    1250      +32     
- Misses      20597   21413     +816     
Impacted Files Coverage Δ
components/icon/IconType.cs 0.00% <0.00%> (ø)
components/icon/internal/StaticClassGenerator.cs 0.00% <0.00%> (ø)
components/cascader/Cascader.razor.cs 0.00% <0.00%> (ø)
components/tabs/TabPane.razor.cs 92.06% <0.00%> (+1.58%) ⬆️
components/core/Base/AntComponentBase.cs 42.30% <0.00%> (+5.12%) ⬆️
components/tabs/Tabs.razor.cs 55.51% <0.00%> (+11.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81d6603...0584325. Read the comment docs.

@ElderJames
Copy link
Member

Thank you for contribution @porkopek .

It helps a lot. Did you make it by a generator script? Could you offer it that we can use for Icon synchronization?

@porkopek
Copy link
Contributor Author

Sure. I did it with a little script just to generate the code, not the file. But if you point me where in the code you put the auto-generated files, I could write a class that generate the file automatically, so no need to synchronize it

@ElderJames
Copy link
Member

You can put it in the ./scripts directory. I want to generate the icon components from svg files. Like the icon components in react version.

@porkopek
Copy link
Contributor Author

porkopek commented Jan 16, 2021

I've created a C# static class that generates the IconType, or can be used to generate all kind of static classes that work as enums, as IconType does.
It's a C# class, because it uses IconStore.GetAllIconNames() to fill the icons type, so it didn't feel right to put it under /scripts and I put it under /icon/internal, but I don't know how are you going to call it to create the file.
The class has a method GenerateIconTypeFile(string path) that creates this file.
You can use GetClassString(string className, IEnumerable<string> properties) to create the string of the class (that can be then generated on disk) passing a collection of properties. So, for example color properties, you could generate the file calling

            var colors = new List<string> { "primary", "secondary", "tertiary" };
            var classString =StaticClassGenerator.GetClassString("ColorType", colors);
            StaticClassGenerator.GenerateFile(classString, "some-path", "ColorType.cs");

Let me know if this is useful for the project or needs any changes, and if you want me to provide some tests for the logic

@ElderJames
Copy link
Member

Thank you @porkopek .

I'm prefer to generate the icon class form https://github.com/ant-design/ant-design-icons/tree/master/packages/icons-svg/svg

@porkopek
Copy link
Contributor Author

This is just to have intellisense in <Icon Type="**you have intellisense here**" />, because even if you create individual icon components for each type, you are going to keep maintaining this component

@ElderJames ElderJames merged commit bc062f4 into ant-design-blazor:master Jan 22, 2021
ElderJames added a commit that referenced this pull request Apr 23, 2022
* Added Static class IconType for intellisense

* Added: Static Class Generator

* move the generator file to cli

Co-authored-by: ElderJames <shunjiey@hotmail.com>
ElderJames added a commit that referenced this pull request Apr 30, 2022
* Added Static class IconType for intellisense

* Added: Static Class Generator

* move the generator file to cli

Co-authored-by: ElderJames <shunjiey@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants