-
Notifications
You must be signed in to change notification settings - Fork 11
Support Non-Nimble icons in the Nimble table #2813
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2a1ecff
HLD draft for non-nimble icons in the table
hellovolcano 4d03e44
change spec location
hellovolcano 59a10b1
cleanup
hellovolcano 6fcc0c0
Change files
hellovolcano 380ba30
move to ok, apply new template
hellovolcano 6c546be
Change files
hellovolcano 84ed3b3
change approach to separate Icon base class
hellovolcano 4f40bb0
Merge branch 'main' into users/vgleason/non-nimble-icons-hld
hellovolcano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-components-e24ccafe-f3e9-4a34-bd19-7696fb0d00d1.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "none", | ||
| "comment": "HLD draft for non-nimble icons in the table", | ||
| "packageName": "@ni/nimble-components", | ||
| "email": "5265744+hellovolcano@users.noreply.github.com", | ||
| "dependentChangeType": "none" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@ni-ok-components-fcf4988c-1c17-46a4-a0c0-381fc8974f5a.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "none", | ||
| "comment": "HLD draft for non-nimble icons in the table", | ||
| "packageName": "@ni/ok-components", | ||
| "email": "5265744+hellovolcano@users.noreply.github.com", | ||
| "dependentChangeType": "none" | ||
| } |
62 changes: 62 additions & 0 deletions
62
packages/ok-components/src/mapping/dynamic-icon/specs/custom-icons-hld.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # High Level Design: Support for Custom Icons | ||
|
|
||
| ## Problem Statement | ||
|
|
||
| The current nimble icon system has the `Icon` class handling both general icon functionality and SVG-specific functionality. This limits extensibility for other icon types, like PNG. | ||
|
|
||
| This design introduces a separation between base icon functionality and SVG-specific icon implementations and can be extended to support custom icon types. It also introduces a new component in Ok to render icons dynamically. | ||
|
|
||
| ## Links To Relevant Work Items and Reference Material | ||
|
|
||
| - [GitHub PR #2814: SVGIcon prototype](https://github.com/ni/nimble/pull/2814) | ||
|
|
||
| ## Implementation / Design | ||
|
|
||
| ### Class Hierarchy Changes | ||
|
|
||
| ``` | ||
| Icon (base class with severity, etc.) | ||
| ├── SvgIcon (extends Icon, handles SVG data) - Class for Nimble Icons | ||
| └── DynamicIcon (extends Icon, dynamically register custom icons) | ||
| ``` | ||
|
|
||
| ### API Changes | ||
|
|
||
| - Rename `registerIcon()` to `registerSvgIcon()` | ||
| - Update type signature to accept `typeof SvgIcon` instead of generic type | ||
|
|
||
| ### New Component: Ok Dynamic Icon | ||
| A component that enables dynamic registration and usage of custom icons from URLs (data URLs, external URLs, etc.) following the same patterns as standard nimble icons. | ||
|
|
||
| #### API | ||
| - **registerDynamicIcon(name: string, src: string)**: Registers a new dynamic icon | ||
| - **getDynamicIconTag(name: string)**: Returns the custom element tag name for a registered icon | ||
| - **Generated Custom Elements**: Each registered icon creates its own custom element (e.g., `<ok-dynamic-icon-rumham>`) | ||
|
|
||
| #### Usage Example | ||
| ```javascript | ||
| // Registration | ||
| registerDynamicIcon('rumham', 'data:image/png;base64,...'); | ||
|
|
||
| // Usage in HTML | ||
| const tag = getDynamicIconTag('rumham'); // Returns 'ok-dynamic-icon-rumham' | ||
| // <ok-dynamic-icon-rumham></ok-dynamic-icon-rumham> | ||
| ``` | ||
|
|
||
| #### Blazor Integration | ||
| Provide a Blazor wrapper component that handles JavaScript interop for icon registration and returns the appropriate custom element tag for use in Blazor applications. | ||
|
|
||
| **Usage in Blazor:** | ||
| ```html | ||
| <OkDynamicIcon Name="rumham" Source="data:image/svg+xml;base64,..." /> | ||
| ``` | ||
|
|
||
| The component automatically registers the icon and renders the corresponding custom element (e.g., `<ok-dynamic-icon-rumham></ok-dynamic-icon-rumham>`) using the OkDynamicIcon.register method accessed through OkBlazor.module.js. | ||
|
|
||
| ## Alternative Implementations / Designs | ||
|
|
||
| 1. **Create a new table column mapping in Ok**: Would require significant duplication of nimble table column components, and introduce a circular dependency. | ||
|
|
||
| ## Open Issues | ||
|
|
||
| N/A | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talking with @jattasNI put together a more end-to-end prototype that I think shows the pattern more clearly. Instead of having a declarative icon registration and renderer at the same time we will split the registration and rendering into separate parts.
Registration will be a programmatic API call from C#, i.e. a function like
RegisterIconDynamicAsync. With the registration complete you have all the pieces you need to render in a table. The PoC PR #2827 shows what calling a registration from C# looks like and how it is used in the table. To take the PoC over the finish line we should move the JSInvoke calls from the example app and into the OkBlazor library. I added some comments about where they should go. In the example we have a helper JS Component with a static method for registering I think we should have a similar helper Blazor Component with a static method for registering. We'd then also want tests in the component, blazor, and storybook docs to finish up.As a follow-on if you want to use the icons in spots outside the table we can add an addtional helper component to render the icon like
<OkIconViewer Icon="ok-dynamic-icon-awesome"></OkIconViewer>. That's only if you also want to render dynamic icons in buttons, dropdowns, etc (the PoC branch linked does not demonstrate the Viewer but my understanding is for today you just need the Table support). The pattern suggested here is to align with the table mapping icon:If the above sounds good and you want to take the PoC branch over the finish line with the above suggestions then we have enough detail captured here to avoid needing the complete HLD.