14 unstable releases (6 breaking)

0.7.0 Dec 27, 2023
0.5.5 Feb 14, 2023
0.5.1 Dec 30, 2022

#1817 in Web programming

Download history 1/week @ 2024-07-18 1/week @ 2024-07-25 3/week @ 2024-08-22 121/week @ 2024-08-29 109/week @ 2024-09-05 53/week @ 2024-09-12 63/week @ 2024-09-19 124/week @ 2024-09-26 73/week @ 2024-10-03 36/week @ 2024-10-10 16/week @ 2024-10-17

259 downloads per month
Used in jinja-renderer

MIT license

1.5MB
826 lines

Free Icons

This crate will generate helper data structures for accessing icons. It is highly inspired by dioxus-free-icons. Because I just need pure SVG icons to be embedded in HTML without any client-side javascript, I decided to write this crate.

Usage

If you need raw SVG icons without any modification, you can use the general get function:

// generate a heroicon
let icon = free_icons::get(IconType::Heroicons(Heroicons::Outline), "academic-cap");
assert_eq!(icon, r###"<svg viewbox="0 0 24 24" fill=none height=24 width=24 xmlns=http://www.w3.org/2000/svg><path d="M11.6998 2.80541C11.8912 2.72176 12.1089 2.72176 12.3003 2.80541C16.0192 4.43023 19.5437 6.41649 22.8295 8.71968C23.0673 8.88636 23.1875 9.17532 23.1381 9.46147C23.0887 9.74762 22.8785 9.97953 22.5986 10.0568C21.9137 10.2459 21.2347 10.4495 20.5618 10.6665C17.8307 11.5473 15.2018 12.6555 12.6972 13.9689L12.6939 13.9706C12.5803 14.0302 12.467 14.0902 12.354 14.1506C12.1331 14.2686 11.8679 14.2686 11.6471 14.1506C11.533 14.0896 11.4186 14.029 11.3039 13.9689C10.0655 13.3195 8.79658 12.7202 7.5 12.1738V11.9501C7.5 11.8187 7.56742 11.7022 7.67173 11.639C9.17685 10.7271 10.7294 9.88577 12.3247 9.11948C12.6981 8.94014 12.8554 8.49207 12.6761 8.1187C12.4967 7.74532 12.0486 7.58803 11.6753 7.76737C10.036 8.55475 8.44086 9.41921 6.89449 10.356C6.44111 10.6307 6.13632 11.0803 6.03607 11.5839C5.18115 11.255 4.31499 10.9487 3.43829 10.666C2.76546 10.449 2.08644 10.2458 1.40154 10.0568C1.12162 9.97952 0.911461 9.74761 0.86204 9.46146C0.812619 9.17531 0.932824 8.88634 1.17061 8.71967C4.45645 6.41648 7.98097 4.43023 11.6998 2.80541Z" fill=#0F172A /><path d="M13.0609 15.4735C15.4997 14.1704 18.0621 13.0688 20.7258 12.1907C20.8601 13.6055 20.9458 15.0344 20.9813 16.4756C20.9889 16.7848 20.8059 17.067 20.5205 17.1862C17.6693 18.3765 14.9574 19.8342 12.4159 21.5278C12.1641 21.6957 11.836 21.6957 11.5841 21.5278C9.04267 19.8342 6.33073 18.3765 3.4796 17.1862C3.19416 17.067 3.01116 16.7848 3.01878 16.4756C3.05429 15.0343 3.14001 13.6053 3.27427 12.1904C4.19527 12.494 5.10415 12.8243 6 13.1804V14.4508C5.55165 14.7102 5.25 15.1949 5.25 15.7501C5.25 16.2454 5.49008 16.6847 5.86022 16.9578C5.7707 17.3385 5.63822 17.7109 5.46277 18.0676C5.91546 18.2813 6.36429 18.5018 6.8091 18.7291C7.06243 18.2138 7.24612 17.673 7.36014 17.1208C7.88449 16.8871 8.25 16.3613 8.25 15.7501C8.25 15.1949 7.94835 14.7102 7.5 14.4508V13.806C8.6714 14.3178 9.81885 14.8744 10.9402 15.4735C11.6028 15.8276 12.3983 15.8276 13.0609 15.4735Z" fill=#0F172A /><path d="M4.46222 19.4624C4.88136 19.0433 5.21502 18.5712 5.46277 18.0676C5.91546 18.2813 6.36429 18.5018 6.8091 18.7291C6.49055 19.3769 6.06164 19.9843 5.52288 20.5231C5.22999 20.816 4.75512 20.816 4.46222 20.5231C4.16933 20.2302 4.16933 19.7553 4.46222 19.4624Z" fill=#0F172A /></svg>"###);

If you want to add extra attributes to the SVG icon, you could use the specific function (currently bootstrap, feather, font_awesome, heroicons, ionicons, octicons are supported):


```rust
// generate a bootstrap alarm icon
let attrs = IconAttrs::default()
    .class("h-8 w-8 text-white")
    .fill("none")
    .stroke_color("currentColor");
let icon = free_icons::bootstrap("alarm", true, &attrs);
assert_eq!(icon, r###"<svg class="h-8 w-8 text-white" fill="none" stroke="currentColor" viewbox="0 0 16 16" fill=currentColor height=16 width=16 xmlns=http://www.w3.org/2000/svg><path d="M6 .5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1H9v1.07a7.001 7.001 0 0 1 3.274 12.474l.601.602a.5.5 0 0 1-.707.708l-.746-.746A6.97 6.97 0 0 1 8 16a6.97 6.97 0 0 1-3.422-.892l-.746.746a.5.5 0 0 1-.707-.708l.602-.602A7.001 7.001 0 0 1 7 2.07V1h-.5A.5.5 0 0 1 6 .5zm2.5 5a.5.5 0 0 0-1 0v3.362l-1.429 2.38a.5.5 0 1 0 .858.515l1.5-2.5A.5.5 0 0 0 8.5 9V5.5zM.86 5.387A2.5 2.5 0 1 1 4.387 1.86 8.035 8.035 0 0 0 .86 5.387zM11.613 1.86a2.5 2.5 0 1 1 3.527 3.527 8.035 8.035 0 0 0-3.527-3.527z"/></svg>"###);

Dependencies

~1.2–3.5MB
~65K SLoC