Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
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"
}
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
Copy link
Member

@rajsite rajsite Jan 23, 2026

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:

<NimbleMappingIcon Icon="ok-dynamic-icon-awesome"></NimbleMappingIcon>
<OkIconViewer Icon="ok-dynamic-icon-awesome"></OkIconViewer>

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.

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