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!

    Rating

    <pc-rating> 0.1.0 experimental

    Ratings give users a way to quickly view and provide feedback.

    <pc-rating label="Rating"></pc-rating>
    Code Edit

    Demos#

    Labels#

    Ratings are commonly identified contextually, so labels aren’t displayed. However, you should always provide one for assistive devices using the label attribute.

    Edit

    Maximum value#

    The rating’s maximum value is 5 by default. To change the maximum value, use the max attribute.

    Edit

    Precision#

    Use the precision attribute to let users select fractional ratings.

    Edit

    Icon size#

    Set the --icon-size custom property to adjust the size.

    Edit

    Readonly#

    Use the readonly attribute to display a rating that users can’t change.

    Edit

    Disabled#

    Use the disabled attribute to disable the rating.

    Edit

    Detecting hover#

    Use the pc-hover event to detect when the user hovers over (or touches and drags) the rating. This lets you hook into values as the user interacts with the rating before they select a value.

    This event has a payload with phase and value properties. The phase property tells when hovering starts, moves to a new value and ends. The value property tells what the rating’s value would be if the user were to commit to the hovered value.

    Edit

    Custom icons#

    You can provide custom icons by passing a function to the getIcon property.

    Edit

    Value‐based icons#

    You can also use the getIcon property to render different icons based on the value chosen on the rating.

    Edit

    Properties#

    NameDescriptionReflectsDefault
    labelA label that describes the rating to assistive devices.
    Type: string
    ""
    valueThe default rating set for the rating.
    Type: number
    0
    maxThe maximum amount able to be set for the rating.
    Type: number
    5
    precisionThe precision at which the rating will increase and decrease (e.g., to allow half stars, set the precision attribute/property to 0.5).
    Type: number
    1
    readonlyMakes the rating readonly.
    Type: boolean
    false
    disabledDisables the rating.
    Type: boolean
    false
    getIconA property that customises the icon to be rendered. The first and only argument is the rating’s current value. The property should return a string containing trusted HTML of the icon to render at the specified value. This works well with <pc-icon> elements.
    Type: (value: number) => string
    updateComplete A read‐only promise that resolves when the component has finished updating.

    Learn more about attributes and properties.

    Methods#

    NameDescriptionArguments
    focus()Focuses the rating.options: FocusOptions
    blur()Unfocuses the rating (i.e., blurs it).

    Learn more about methods.

    Events#

    NameDescriptionEvent detail
    pc-changeEmitted when the rating’s value changes.
    pc-hoverEmitted when the user hovers over a value. The phase property indicates when hovering starts, moves to a new value or ends. The value property tells what the rating’s value would be if the user were to commit to the hovered value.{ phase: "start" | "move" | "end", value: number }

    Learn more about events.

    Custom properties#

    NameDescriptionDefault
    --icon-colorThe inactive colour for icons.var(--pc-color-neutral-fill-normal)
    --icon-color-activeThe active colour for icons.var(--pc-color-warning-fill-loud)
    --icon-sizeThe icons’ size.1.2rem

    Learn more about customising custom properties.

    Parts#

    NameDescription
    baseThe component’s base wrapper.

    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/rating/rating.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/rating/rating.js";

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

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

    Dependencies#

    This component automatically imports these components: