Looking for recommendations to integrate Modus Icons(1000+) in Modus Web Components #13
Unanswered
msankaran0712
asked this question in
Q&A
Replies: 2 comments
-
Since you have experimented with some of the approaches already, could you share the findings? I would do mostly what Shoelace is doing, as I think it's a fairly well thought through approach:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
@mihkeleidast I still need to figure out how to get the path of the sprite svg file so the icon path can be referenced in Below is the wrapper component I created, // eslint-disable-next-line
import { Component, h, Prop, Event, Element, EventEmitter } from '@stencil/core';
import solidIcons from '@trimble-oss/modus-icons/dist/modus-solid/sprites/modus-icons.svg';
import outlinedIcons from '@trimble-oss/modus-icons/dist/modus-outlined/sprites/modus-icons.svg';
import { MODUS_ICONS_OUTLINED, ModusIconType } from './modus-icon.models';
@Component({
tag: 'modus-icon',
styleUrl: 'modus-icon.scss',
shadow: true,
})
export class ModusIcon {
@Element() el: HTMLElement;
/** (optional) The color of the Icon */
@Prop() color?: string;
/** The name of the icon */
@Prop() name: string | null;
/** (optional) The size of the Icon */
@Prop() size?: string = '16';
/** (optional) The size of the Icon */
@Prop() type?: ModusIconType = 'solid';
/** (optional) The click handler function */
@Event() iconClick?: EventEmitter;
onClick(event: MouseEvent): void {
if (event.defaultPrevented) {
return;
}
this.iconClick.emit(event);
}
render(): unknown {
return (
this.name && (
<svg
onClick={this.onClick}
style={{ width: this.size, height: this.size, color: this.color }}
fill={this.color ?? 'currentColor'}>
<use href={`${this.type === MODUS_ICONS_OUTLINED ? outlinedIcons : solidIcons}#${this.name}`}></use>
</svg>
)
);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We have experimented with various approaches in order to achieve the desired result. Some of these approaches include implementing icons as CSS classes, utilizing icons as CSS properties, and creating a wrapper web component that leverages sprite files from the Modus Icons npm package.
Beta Was this translation helpful? Give feedback.
All reactions