github.com/kyleu/dbaudit@v0.0.2-0.20240321155047-ff2f2c940496/views/components/SVG.html (about) 1 <!-- Content managed by Project Forge, see [projectforge.md] for details. --> 2 {% import ( 3 "fmt" 4 "strings" 5 6 "github.com/kyleu/dbaudit/app" 7 "github.com/kyleu/dbaudit/app/controller/cutil" 8 "github.com/kyleu/dbaudit/app/util" 9 ) %} 10 11 {% func SVG(k string) %}{%s= util.SVGLibrary[k] %}{% endfunc %} 12 13 {% func SVGRef(k string, w int, h int, cls string, ps *cutil.PageState) %}{% stripspace %} 14 {% if k != "" %} 15 {% code 16 ps.AddIcon(k) 17 if w == 0 { w = 20 } 18 if h == 0 { h = 20 } 19 style := fmt.Sprintf("width: %dpx; height: %dpx;", w, h) 20 %} 21 {% if cls == "" %} 22 <svg style="{%s style %}"><use xlink:href="#svg-{%s k %}" /></svg> 23 {% else %} 24 <svg class="{%s cls %}" style="{%s style %}"><use xlink:href="#svg-{%s k %}" /></svg> 25 {% endif %} 26 {% endif %} 27 {% endstripspace %}{% endfunc %} 28 29 {% func Icon(k string, size int, cls string, ps *cutil.PageState) %}{% stripspace %} 30 {% if strings.Contains(k, "/") %} 31 <img alt="SVG icon [{%s k %}]" src="{%s k %}" style="width: {%d size %}px; height: {%d size %}px;" /> 32 {% else %} 33 {%= SVGRef(k, size, size, cls, ps) %} 34 {% endif %} 35 {% endstripspace %}{% endfunc %} 36 37 {% func SVGRefIcon(k string, ps *cutil.PageState) %}{% stripspace %} 38 {%= SVGRef(k, 20, 20, "icon", ps) %} 39 {% endstripspace %}{% endfunc %} 40 41 {%- func IconGallery(as *app.State, ps *cutil.PageState) -%} 42 <div class="flex-wrap mt"> 43 {%- for _, k := range util.SVGIconKeys -%} 44 <div class="icon-gallery-icon"> 45 <div class="gallery-svg">{%= SVGRef(k, 64, 64, "icon", ps) %}</div> 46 <div class="gallery-title">{%s k %}</div> 47 </div> 48 {%- endfor -%} 49 </div> 50 {%- endfunc -%}