From 0775fd1a4eb7e46fe4fd533daebf5a25e878689c Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 22 Aug 2022 14:05:11 -0600 Subject: [PATCH] Icon improvements: - If Et2ButtonIcon image does not resolve to a egw image, treat it as a Shoelace icon name - Add egw images as an icon library for Shoelace eg: --- api/js/etemplate/Et2Button/Et2ButtonIcon.ts | 6 +++++- api/js/etemplate/Styles/shoelace.ts | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/api/js/etemplate/Et2Button/Et2ButtonIcon.ts b/api/js/etemplate/Et2Button/Et2ButtonIcon.ts index 482ce12394..15084b8b71 100644 --- a/api/js/etemplate/Et2Button/Et2ButtonIcon.ts +++ b/api/js/etemplate/Et2Button/Et2ButtonIcon.ts @@ -28,11 +28,15 @@ export class Et2ButtonIcon extends ButtonMixin(Et2InputWidget(SlIconButton)) { this.src = this.egw().image(new_image); } + if(new_image && !this.src) + { + this.name = new_image; + } } get image() { - return this.src; + return this.src || this.name; } } diff --git a/api/js/etemplate/Styles/shoelace.ts b/api/js/etemplate/Styles/shoelace.ts index 1c5062539f..aa2850f521 100644 --- a/api/js/etemplate/Styles/shoelace.ts +++ b/api/js/etemplate/Styles/shoelace.ts @@ -4,13 +4,21 @@ import {css} from "lit"; import {registerIconLibrary} from '@shoelace-style/shoelace/dist/utilities/icon-library.js'; import {egw} from "../../jsapi/egw_global"; + /** - * This makes sure the built-in icons can be found + * Here is the common overrides and customisations for Shoelace */ -registerIconLibrary('default', { + + +/** + * Register egw images as an icon library + * @example + * @example + */ +registerIconLibrary('egw', { resolver: name => { - return typeof egw !== "undefined" ? `${egw.webserverUrl}/node_modules/@shoelace-style/shoelace/dist/assets/icons/${name}.svg` : '' + return typeof egw !== "undefined" ? (egw.image(name) || '') : '' }, });