diff libervia/backend/tools/common/template.py @ 4084:f742f28b3934

tools/common (template): add `id` argument to `_icon_use`
author Goffi <goffi@goffi.org>
date Wed, 07 Jun 2023 22:26:54 +0200
parents 84f6bee6440d
children e7ee611fc860
line wrap: on
line diff
--- a/libervia/backend/tools/common/template.py	Wed Jun 07 22:26:17 2023 +0200
+++ b/libervia/backend/tools/common/template.py	Wed Jun 07 22:26:54 2023 +0200
@@ -955,11 +955,18 @@
             defs_elt.append(icon_svg_elt)
         return safe(etree.tostring(svg_elt, encoding="unicode"))
 
-    def _icon_use(self, name, cls=""):
-        return safe('<svg class="svg-icon{cls}" xmlns="http://www.w3.org/2000/svg" '
+    def _icon_use(self, name, cls="", id=""):
+        if id:
+            id = id.replace('"', '_')
+        return safe('<svg class="svg-icon{cls}"{id} xmlns="http://www.w3.org/2000/svg" '
                     'viewBox="0 0 100 100">\n'
                     '    <use href="#{name}"/>'
-                    '</svg>\n'.format(name=name, cls=(" " + cls) if cls else ""))
+                    '</svg>\n'.format(
+                        name=name,
+                        cls=(" " + cls) if cls else "",
+                        id=f' id="{id}"' if id else ""
+                    )
+                    )
 
     def _icon_from_client(self, client):
         """Get icon name to represent a disco client"""