Use web components for SVG icons

This commit is contained in:
2019-08-30 16:04:28 +09:00
parent b32005cdee
commit d974156d68
13 changed files with 113 additions and 61 deletions

View File

@ -1,28 +1,15 @@
package utils
import (
"io/ioutil"
"strings"
"fmt"
)
var svgIcons = make(map[string]string)
func init() {
files, _ := ioutil.ReadDir("images/icons/")
for _, file := range files {
name := strings.TrimSuffix(file.Name(), ".svg")
data, _ := ioutil.ReadFile("images/icons/" + name + ".svg")
svgIcons[name] = strings.Replace(string(data), "<svg ", "<svg class='icon icon-"+name+"' ", 1)
}
}
// Icon ...
// Icon shows an icon that has a margin-right attribute.
func Icon(name string) string {
return svgIcons[name]
return fmt.Sprintf("<svg-icon name='%s' class='padded-icon'></svg-icon>", name)
}
// RawIcon ...
// RawIcon shows the raw icon without any additional margin.
func RawIcon(name string) string {
return strings.Replace(svgIcons[name], "class='icon", "class='raw-icon", 1)
return fmt.Sprintf("<svg-icon name='%s'></svg-icon>", name)
}