diff --git a/elements/rh-icon/demo/gradient-fill.html b/elements/rh-icon/demo/gradient-fill.html new file mode 100644 index 0000000000..dabde55865 --- /dev/null +++ b/elements/rh-icon/demo/gradient-fill.html @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/elements/rh-icon/rh-icon.css b/elements/rh-icon/rh-icon.css index f191127c25..d0232d4ca3 100644 --- a/elements/rh-icon/rh-icon.css +++ b/elements/rh-icon/rh-icon.css @@ -12,7 +12,9 @@ svg { /** Override default icon size */ width: var(--rh-icon-size, var(--rh-size-icon-01, 16px)); - fill: currentcolor; + + /** color of the icon */ + fill: var(--rh-icon-fill, currentcolor); aspect-ratio: 1/1; } @@ -25,3 +27,26 @@ svg { max-width: 12px; width: var(--rh-icon-size, 12px); } + +.gradient-fill { + --rh-icon-fill: url('#svg-gradient'); +} + +#svg-gradients { + position: absolute; + width: 0; + height: 0; +} + +#svg-gradient { + --_icon-gradient-color-stop-1: + /** color of the gradient's 1st stop */ + var(--rh-icon-gradient-color-stop-1, + var(--rh-color-red-50, #ee0000) + ); + --_icon-gradient-color-stop-2: + /** color of the gradient's 2nd stop */ + var(--rh-icon-gradient-color-stop-2, + var(--rh-color-purple-50, #5e40be) + ); +} diff --git a/elements/rh-icon/rh-icon.ts b/elements/rh-icon/rh-icon.ts index 42d5d4a918..4e82b9cad2 100644 --- a/elements/rh-icon/rh-icon.ts +++ b/elements/rh-icon/rh-icon.ts @@ -96,6 +96,14 @@ export class RhIcon extends LitElement { */ @property() loading?: 'idle' | 'lazy' | 'eager' = 'lazy'; + /** + * Adds gradient fill to icon. + * Default color stops can be overwritten by using its CSS Custom Properties. + * - `--rh-icon-gradient-color-stop-1` + * - `--rh-icon-gradient-color-stop-2` + */ + @property({ attribute: 'gradient-fill', reflect: true, type: Boolean }) gradientFill = false; + /** Icon content. Any value that lit can render */ @state() private content?: unknown; @@ -113,10 +121,21 @@ export class RhIcon extends LitElement { render(): TemplateResult { const { set } = this; const content = this.#getContent(); + const gradientFill = (this.gradientFill === true) ? 'gradient-fill' : ''; + console.log(gradientFill); + return html` + ${!this.gradientFill ? '' : html` + + `}
${!isServer ? content + class="${classMap({ [set]: true, [gradientFill]: true })}">${!isServer ? content : unsafeHTML(content as unknown as string)}