Icons
Lucide icons as named Go accessors, sized and tinted like text.
The icons/lucide package provides Lucide icons as MyGo SVGs. Each icon is a function named after it in PascalCase, as arrow-up-right becomes lucide.ArrowUpRight; names that start with a digit take an Icon prefix.
Loading the live example…
import (
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
"github.com/oneo-me/onevra/source/icons/lucide"
)
type iconSet struct{}
func (iconSet) View(c *ui.Context) {
t := c.Theme()
icons := []struct {
name string
svg func() *ui.SVG
}{
{"House", lucide.House}, {"Search", lucide.Search}, {"Settings", lucide.Settings},
{"Folder", lucide.Folder}, {"Download", lucide.Download}, {"Bell", lucide.Bell},
{"Heart", lucide.Heart}, {"Sparkles", lucide.Sparkles},
}
ui.Row(c).Wrap().Gap(t.Space(2)).Justify(ui.Center).Children(func() {
for _, icon := range icons {
ui.Column(c).Key(icon.name).Width(84).Padding(t.Space(3)).Gap(t.Space(2)).
AlignItems(ui.Center).Radius(t.Radius).Background(t.Surface).
Border(1, t.Border.Alpha(.6)).Children(func() {
components.Icon(c, icon.svg).Size(24, 24)
components.Text(c, icon.name).FontSize(t.Rem(0.75)).TextColor(t.TextMuted)
})
}
})
}Show an icon
import (
"github.com/oneo-me/onevra/source/components"
"github.com/oneo-me/onevra/source/icons/lucide"
)
components.Icon(c, lucide.Search).Size(20, 20)components.Icon takes the accessor itself or the *ui.SVG it returns. Icons inherit the surrounding text color; change it with TextColor. They keep Lucide's strokes and scale with the element.
Components that show icons take them as *ui.SVG, so call the accessor:
components.SidebarItem(c, "Home", lucide.House(), selected)
components.IconButton(c, lucide.Trash(), "Delete", components.IconButtonPlain)Cost
Each accessor parses its SVG the first time it is called and returns the same shared value after that. There is no runtime registry, so an application carries only the icons it calls. The package pins the upstream release it was generated from and ships under Lucide's ISC and Feather's MIT licenses.
API
Icon
func Icon[T *ui.SVG | func() *ui.SVG](c *ui.Context, source T) ui.ElementIcon creates an SVG icon from a parsed asset or a named accessor such as lucide.Search (without calling it). Accessors run synchronously when the element is built; the asset package owns parsing and caching. A typed nil SVG or accessor produces an empty icon.
Icons inherit text color and font size from their parent. Use Size to set explicit dimensions and Label to supply application-owned accessible text. MyGo owns rendering, aspect ratio and element semantics. No icon registry or dependency on a particular icon pack is introduced.
pkg.go.dev