Icon sets

oxblade-icons Alpha Rust

A registry holds one or more icon sets; this page shows how to register generated sets and your own SVGs, and how defaults and fallbacks work.

Generated sets

oxblade-icon-sets publishes one crate per set. Each crate is plain data: it doesn't depend on oxblade-icons, and oxblade-icons doesn't select a set until you register it. icon_set! takes the crate's Rust name, checks its data format at compile time, and returns an IconSet with the set's name, prefix, upstream source and licence notice:

use oxblade_icons::{Icons, icon_set};

let icons = Icons::builder()
    .set(icon_set!(oxblade_heroicons))
    .set(icon_set!(oxblade_lucide))
    .build()?;

icon_set! takes one crate per call; call .set(...) once per set.

CratePrefixNames look like
oxblade-heroiconsheroiconheroicon-o-home (outline), heroicon-s-home (solid), heroicon-m-home (mini), heroicon-c-home (micro)
oxblade-lucidelucidelucide-map-pin

The names are the same as in the PHP packages blade-heroicons and blade-lucide-icons.

Licence notices

Generated sets carry their upstream notices. Icons::notices() returns each registered set's notice once, and IconSet::provenance() returns the pinned source, for example mallardduck/blade-lucide-icons 2.0.38 (Lucide 1.66.0). If you publish a page or binary that includes the artwork, include the notices; each set crate's NOTICE file has the full text.

for notice in icons.notices() {
    println!("{} ({})", notice.title, notice.spdx);
}

Your own SVGs

Icon sources are trusted SVG markup: the renderer inlines them as they are. Register files you ship with the application, never SVGs that users upload, unless you have validated them yourself.

From a static slice, sorted by key:

use oxblade_icons::{IconSet, Icons};

static BRAND: &[(&str, &str)] = &[
    ("flags/be", include_str!("../icons/flags/be.svg")),
    ("logo", include_str!("../icons/logo.svg")),
];

let icons = Icons::builder()
    .set(IconSet::from_static("brand", "brand", BRAND))
    .build()?;
icons.icon("brand-logo")?;
icons.icon("brand-flags.be")?; // a dot in the name is a subfolder

The slice must be sorted by key, because lookups use a binary search. Write subfolders with / in the key and with . in the icon name, as in Blade Icons.

From a lookup function, when the SVGs live somewhere else:

use std::borrow::Cow;
use oxblade_icons::IconSet;

let set = IconSet::from_lookup("brand", "brand", |key| {
    my_assets::get(&format!("{key}.svg")).map(Cow::Borrowed)
});

The function receives a checked key such as logo or flags/be: names that are empty, contain .., / or other characters outside letters, digits, - and _ are rejected before it is called. A lookup set can't list its keys, so Icons::names returns nothing for it.

With the laravel feature, oxblade_icons::laravel::embedded_set(name, prefix, folder) registers a folder embedded with laravel::embed! in the same way.

The default set

A set named default catches names whose prefix matches no set. With a default set registered, icons.icon("foreign-flag") looks up foreign-flag in it. This follows Blade Icons, where the default set has no prefix.

Defaults

Classes and attributes can be set for every icon and for each set:

use oxblade_icons::{Attributes, Icons, icon_set};

let icons = Icons::builder()
    .class("icon")
    .attributes(Attributes::new().set("focusable", "false"))
    .set(icon_set!(oxblade_heroicons).class("size-6"))
    .build()?;

Classes join in order: global, then set, then the class passed to the call. Attributes merge in the same order; a later value for the same name replaces an earlier one and keeps its position. If the call passes a class attribute itself, that value is used as it is and the defaults are ignored, as in PHP.

Fallbacks

A fallback is shown when an icon is missing. A set's fallback is a name within that set, without its prefix; the global fallback is a full name:

let icons = Icons::builder()
    .set(icon_set!(oxblade_lucide).fallback("circle-help"))
    .fallback("lucide-circle-help")
    .build()?;

The set's fallback is tried first, then the global one. build() fails with Error::UnknownFallback if either doesn't exist. Icons::has reports exact matches only; fallbacks don't count.