Skip to main content Sidebar Design tokens Components Layout Style utilities

We’d love to hear from you. Please reach out to us with any questions or inquiries you may have.

You can contact us via e‐mail at placer.coc.reports+contact@gmail.com.

We look forward to hearing from you!

Got it!
Skip to table of contents

The Placer Toolkit alpha has arrived! 🎉
Plenty of changes are coming your way—some big, some breaking, some even nuclear! Beware the changelog…

Bring it on!

    Icon

    <pc-icon> 0.1.0 experimental

    Icons are visual symbols that represent actions, objects or ideas.

    Placer Toolkit comes bundled with over 2 000 free icons courtesy of Font Awesome. These icons are part of the default icon library. If you prefer, you can register custom icon libraries as well as Font Awesome Pro.

    Not sure which icon to use? Find the perfect icon over at Font Awesome!

    Demos#

    Icon styles#

    The default icon library uses Font Awesome Free, which comes with three icon styles: Solid, Regular and Brands. If you’re a Font Awesome Pro user, you can provide your Kit code to unlock Pro icon packs and styles.

    Edit

    Colours#

    Icons inherit their colour from the current text colour. Thus, you can set the color property on the <pc-icon> element or an ancestor to change the colour.

    Edit

    Sizes#

    Icons are sized relative to the current font size. To change the size of an icon, set the font-size property on the icon itself or on a parent element as shown below.

    Edit

    Labels#

    For non‐decorative icons, use the label attribute to announce the label’s content to assistive devices.

    Edit

    Auto‐width icons#

    By default, Font Awesome icons have a 1em height and a fixed 1em width. Use the auto-width attribute to allow the icon to use its natural variable width.

    Edit

    Images#

    Images that are supposed to act like icons can be loaded individually with the src attribute. Only SVGs on a local or CORS‐enabled endpoint are supported. If you’re using more than one custom icon, it might make sense to register a custom icon library instead.

    Edit

    Defining a custom icon library#

    You can register additional icons to use with the <pc-icon> component through custom icon libraries. Icon files can exist locally or on a CORS‐enabled endpoint (e.g., a CDN). There is no limit to how many custom icon libraries you can register and there is no cost associated with registering them, as individual icons are only requested when they’re used.

    Placer Toolkit ships with two built‐in icon libraries, default and system. The default icon library contains all icons in Font Awesome Free. The system icon library only contains a subset of icons in Font Awesome Free that are used internally by Placer Toolkit components.

    To register a custom icon library, use the registerIconLibrary() function exported from utilities/icon-library.js. At a minimum, you must provide a name and a resolver function. The resolver function translates an icon name to a URL where the corresponding SVG file exists. Refer to the examples below to better understand how it works.

    Here’s an example that registers an icon library located in the /assets/icons directory.

    <script type="module">
        import { registerIconLibrary } from "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/utilities/icon-library.js";
    
        registerIconLibrary("custom-icon-library", {
            resolver: (name) => `/assets/icons/${name}.svg`,
        });
    </script>

    To display an icon, set the library and name attributes of a <pc-icon> element. The icon-style attribute is not set up for custom icon libraries by default, as it’s designed for the default and system icon libraries.

    <!-- This will show the icon located at /assets/icons/face-smile.svg -->
    <pc-icon library="custom-icon-library" name="face-smile"></pc-icon>

    If an icon is used, before registration occurs, it will be initially empty, but shown when it gets registered.

    Properties#

    NameDescriptionReflectsDefault
    nameThe name of the icon to render. Available names depend on the icon library being used.
    Type: string | undefined
    iconStyle
    icon-style
    The icon style to use for the icon. If not configured, this only works for the default icon library.
    Type: string
    "solid"
    autoWidth
    auto-width
    Sets the width of the icon to match the cropped SVG viewBox. This operates like the Font Awesome fa-width-auto class.
    Type: boolean
    false
    swapOpacity
    swap-opacity
    Swaps the opacity of duotone icons. Has no effect on custom icon libraries.
    Type: boolean
    false
    srcThe external URL of an SVG file. Make sure you trust the content you are included, as it will be executed as code and can result in XSS attacks.
    Type: string | undefined
    labelA label to include for assistive devices. If omitted, the icon will be considered presentational and ignored by assistive devices.
    Type: string
    ""
    libraryThe name of a registered icon library.
    Type: string
    "default"
    updateComplete A read‐only promise that resolves when the component has finished updating.

    Learn more about attributes and properties.

    Events#

    NameDescriptionEvent detail
    pc-loadEmitted when the icon has loaded. When using spriteSheet: true, this will not emit.
    pc-errorEmitted when the icon fails to load due to an error. When using spriteSheet: true, this will not emit.

    Learn more about events.

    Custom properties#

    NameDescriptionDefault
    --fa-primary-colorThe primary colour for the primary layer in duotone icons.currentColor
    --fa-secondary-colorThe secondary colour for the secondary layer in duotone icons.currentColor
    --fa-primary-opacityThe primary opacity for the primary layer in duotone icons.1
    --fa-secondary-opacityThe secondary opacity for the secondary layer in duotone icons.0.4

    Learn more about customising custom properties.

    Parts#

    NameDescription
    svgThe component’s internal SVG element.
    useThe <use> element generated when using spriteSheet: true.

    Learn more about customising CSS parts.

    Importing#

    If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.

    CDN (script tag) CDN (import) npm (import)

    To manually import this component from the CDN, copy this code snippet and paste it in your HTML.

    <script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/icon/icon.js"></script>

    To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.

    import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/icon/icon.js";

    To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.

    import "placer-toolkit/dist/components/icon/icon.js";