This plugin adds a shortcode to your Eleventy project to easily include icons from the Phosphor Icons collection.
Install the plugin from npm:
npm install eleventy-plugin-phosphoricons --save-dev
class - The class attribute to be added to the svg element.phiconstyle - The style attribute to be added to the svg element.undefinedsize - The width and height attribute to be added to the svg element.256fill - The fill attribute to be added to the svg element.currentColorwidth - The width attribute to be added to the img element.size attributeheight - The height attribute to be added to the img element.size attributerender - The render method allows you to render icon as inline svg or image.svg, other options: image or imgtransformClass - A CSS class that you want to map using a callback function transformFill.falsetransformFill - A callback function that allows you to transform the fill attribute based on the transformClass attribute.undefinedrender is set to image or img, the following attributes can be used:alt - The alt attribute to be added to the img element.altPrefix + iconNamealtPrefix - The alt attribute prefix to be added to the img element.iconloading - The loading attribute to be added to the img element.lazydecoding - The decoding attribute to be added to the img element.asynceleventyIgnore - The eleventyIgnore attribute to be added to the img element to prevent @11ty/eleventy-img plugin from processing the image.trueAdd it to your Eleventy Config config file:
const eleventyPluginPhosphoricons = require('eleventy-plugin-phosphoricons');
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(eleventyPluginPhosphoricons);
};
const eleventyPluginPhosphoricons = require('eleventy-plugin-phosphoricons');
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(eleventyPluginPhosphoricons, {
class: "phicon",
style: "vertical-align: middle;",
size: 32,
fill: "currentColor"
});
};
transformFill callback functionMay be useful if you using a CSS framework like Tailwind CSS, Bootstrap, etc. and you want to map the fill attribute to the text color classes.
TailwindCSS usage example:
const eleventyPluginPhosphoricons = require('eleventy-plugin-phosphoricons');
const resolveConfig = require('tailwindcss/resolveConfig.js')
const tailwindConfig = require('tailwind.config.js')
const fullConfig = resolveConfig(tailwindConfig)
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(eleventyPluginPhosphoricons, {
class: "phicon",
style: "vertical-align: middle;",
size: 32,
fill: "currentColor",
transformFill: (color) => {
const [baseColor, shade] = color.replace('text-', '').split('-');
return shade ? fullConfig.theme.colors[baseColor][shade] : fullConfig.theme.colors[baseColor]['DEFAULT'];
}
});
};
SVG example contains 16 child elements.
Image example contains 7 child elements.
Rendering icons as images can help to avoid an excessive DOM size. This can be useful when you have a lot of icons on a page, or when you want to avoid the overhead of rendering SVGs in the DOM.
>Note: rendered icons as image, can't get the same color as the text color.