Icons
Components draw their icons from one library you choose: Lucide, Tabler or Phosphor. Each icon is an SVG file in your app, drawn into the page on the server, with no JavaScript.
Choose a library
Pick it when you install. Lucide is the default.
bin/rails generate velvetkit:install --icons=phosphor
The choice is saved in config/velvetkit.yml, and every component you add after that uses it:
namespace: UI
icons: phosphor
-
search -
x -
check -
chevron-down -
circle-alert -
info -
eye-off -
grip-vertical -
loader -
settings -
mail -
calendar
class UI::Alert < UI::Base
DEFAULT_ICONS = {
default: "info",
destructive: "circle-alert",
warning: "circle-alert",
success: "circle-check",
info: "info"
}.freeze
Browse Lucide ·
lucide-static@0.545.0 · ISC licence
-
search -
x -
check -
chevron-down -
alert-circle -
info-circle -
eye-off -
grip-vertical -
loader -
settings -
mail -
calendar
class UI::Alert < UI::Base
DEFAULT_ICONS = {
default: "info-circle",
destructive: "alert-circle",
warning: "alert-circle",
success: "circle-check",
info: "info-circle"
}.freeze
Browse Tabler ·
@tabler/icons@3.50.0 · MIT licence
-
magnifying-glass -
x -
check -
caret-down -
warning-circle -
info -
eye-slash -
dots-six-vertical -
spinner -
gear -
envelope -
calendar-blank
class UI::Alert < UI::Base
DEFAULT_ICONS = {
default: "info",
destructive: "warning-circle",
warning: "warning-circle",
success: "check-circle",
info: "info"
}.freeze
Browse Phosphor ·
@phosphor-icons/core@2.1.1 · MIT licence
How it works
The components are written with Lucide names. When velvetkit:add copies one into an app that uses another library, it renames every icon in the component, its tests and its previews, so the Alert above asks for warning-circle under Phosphor. It also copies the SVG of each icon the component draws into app/assets/icons.
After that, nothing looks anything up. UI::Icon.new(name: "warning-circle") reads app/assets/icons/warning-circle.svg and puts the SVG into the page, sized by the component and coloured with the text around it.
Add your own icons
Use any icon from your library by its name in that library. Add its SVG first:
bin/rails generate velvetkit:icons rocket user
Run it with no names to add every icon your own components, views and helpers draw that has no SVG yet. Icons the kit uses come from the gem; others are downloaded from the npm CDN, at the version the kit was built with.
<%= render UI::Icon.new(name: "rocket") %>
<%= render UI::Icon.new(name: "user", size: :sm, label: "Account") %>
An icon with no SVG draws a dashed square, and the log names the missing file. In production it draws nothing. Any SVG can go in app/assets/icons, from another library or your designer, as long as it has a viewBox and uses currentColor.
Switch libraries later
Change icons: in config/velvetkit.yml, then add your components again so they're renamed and get the new SVGs. This overwrites them, so commit first and review the diff for your own changes.
bin/rails generate velvetkit:add dialog menu alert --force
Icons in your own views keep the names you gave them. Rename those to the new library's names, then run velvetkit:icons to fetch their SVGs.
Upgrading from 0.2
Before 0.3, icons were drawn in the browser by the lucide package. Components you added then keep working that way until you add them again.
- Add your components again with
--force, includingicon. They now draw SVGs, and copy the ones they need. - Run
bin/rails generate velvetkit:iconswith no names, to add an SVG for every icon your own views draw. - Delete
app/javascript/velvetkit_icons.tsand its import, and removelucidefrompackage.json.