npm install bootstrap-icons
To start using the library, follow these steps:
//= link_directory ../../../node_modules/bootstrap-icons .svg
Insert this line (in the app/assets/config/manifest.js
file) to reference the bootstrap-icons.svg
file for the 'shop' icon:
<svg class="bi" fill="currentColor">
<use xlink:href="<%= asset_path "bootstrap-icons/bootstrap-icons.svg" %>#shop"/>
</svg>
Similar to a "sprite" concept on the following page: . This method allows for easy sizing and color customization.
UPDATE:
Alternatively, you can create a helper function:
<%= bi_icon 'shop', class: 'shop-style' %>
.shop-style {
width: 16px; height: 16px; color: red;
}
A possible implementation for the above might be:
def bi_icon(icon, options = {})
classes = ["bi"].append(options.delete(:class)).compact
content_tag :svg, options.merge(class: classes, fill: "currentColor") do
content_tag :use, nil, "xlink:href" => "#{ asset_path 'bootstrap-icons/bootstrap-icons.svg' }##{icon}"
end
end