A Go code generator that creates type-safe Templ components for Lucide Icons.
- π― Type-safe: All icon names are compile-time checked
- π Zero runtime dependencies: Pure Go/Templ components
- π¦ Tree-shakeable: Only used icons are included
- π Auto-updating: Fetch latest icons from Lucide repository
- π·οΈ Categorized: Icons organized by logical categories
- π¨ Customizable: Full control over attributes and styling
- π Well-documented: Generated code includes documentation
go install github.com/riclib/lucide-templ-gen/cmd/lucide-gen@latest
go get github.com/riclib/lucide-templ-gen
Download pre-built binaries from the releases page:
- Linux:
lucide-gen-linux-amd64.tar.gz
- macOS:
lucide-gen-darwin-amd64.tar.gz
(Intel) orlucide-gen-darwin-arm64.tar.gz
(Apple Silicon) - Windows:
lucide-gen-windows-amd64.zip
# Generate all icons
lucide-gen -output ./icons
# Generate specific categories
lucide-gen -output ./icons -categories "navigation,actions,media"
# Generate with custom package name
lucide-gen -output ./ui/icons -package icons -prefix Icon
# Dry run to see what would be generated
lucide-gen -output ./icons -dry-run
package main
import (
"log"
lucidegen "github.com/riclib/lucide-templ-gen"
)
func main() {
config := lucidegen.Config{
OutputDir: "./web/components/icons",
PackageName: "icons",
Prefix: "Lucide",
Categories: []string{"navigation", "actions"},
}
if err := lucidegen.Generate(config); err != nil {
log.Fatal(err)
}
}
# Taskfile.yml
tasks:
icons:generate:
desc: Generate Lucide icon components
cmds:
- lucide-gen -output web/templates/components -package components
- templ generate web/templates/components/icons_templ.go
icons:update:
desc: Update to latest Lucide icons
cmds:
- task: icons:generate
After generation, use the type-safe icon components:
package main
import "your-project/web/templates/components"
// Direct icon usage
templ HomePage() {
<div class="nav">
@components.Home(templ.Attributes{"class": "nav-icon"})
@components.User(templ.Attributes{"class": "user-icon", "size": "24"})
</div>
}
// Dynamic icon usage with registry
templ IconButton(iconName components.IconName, label string) {
<button class="btn">
@components.Icon(iconName, templ.Attributes{"class": "btn-icon"})
{ label }
</button>
}
// Usage with type safety
templ Dashboard() {
@IconButton(components.IconHome, "Home")
@IconButton(components.IconSettings, "Settings")
}
The generator creates several files:
Individual icon components:
// Home renders the home Lucide icon
templ Home(attrs templ.Attributes) { /* ... */ }
// User renders the user Lucide icon
templ User(attrs templ.Attributes) { /* ... */ }
Type-safe registry and utilities:
type IconName string
const (
IconHome IconName = "home"
IconUser IconName = "user"
)
// Icon renders any icon by name
templ Icon(name IconName, attrs templ.Attributes) { /* ... */ }
// IconExists checks if an icon is available
func IconExists(name string) bool { /* ... */ }
// AllIcons returns all available icons
func AllIcons() []IconName { /* ... */ }
Categorized icon access:
// NavigationIcons returns all navigation-related icons
func NavigationIcons() []IconName { /* ... */ }
// ActionIcons returns all action-related icons
func ActionIcons() []IconName { /* ... */ }
Usage: lucide-gen [options]
Options:
-output string Output directory (default ".")
-package string Package name (default "icons")
-prefix string Function name prefix (default "")
-categories string Comma-separated categories to include (default: all)
-dry-run Show what would be generated without creating files
-version Show version information
-help Show this help message
type Config struct {
OutputDir string // Output directory path
PackageName string // Go package name
Prefix string // Function name prefix
Categories []string // Icon categories to include
DryRun bool // Preview without generating
Verbose bool // Enable verbose output
}
Icons are organized into logical categories:
- Navigation: home, menu, chevron-, arrow-, etc.
- Actions: plus, minus, edit, trash, save, copy, etc.
- Media: play, pause, stop, volume, music, video, etc.
- Communication: mail, phone, message, bell, etc.
- Files: file, folder, download, upload, etc.
- UI: eye, eye-off, lock, unlock, search, etc.
- Data: database, server, cloud, wifi, etc.
- Devices: smartphone, laptop, monitor, etc.
- Social: heart, star, share, thumbs-up, etc.
- Weather: sun, moon, cloud, umbrella, etc.
Check the examples directory for complete integration examples:
- Basic Usage - Simple icon generation
- Custom Categories - Category-specific generation
- Advanced Integration - Full project integration
- Taskfile Integration - Build system integration
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
MIT License - see LICENSE file for details.
- Lucide Icons for the beautiful icon set
- Templ for the excellent templating system