Zum Hauptinhalt springen Seitenleiste
Auf dieser Seite
Zum Inhaltsverzeichnis springen

Rating

<pc-rating> 0.1.0 experimental

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

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

Eigenschaften

NameBeschreibungReflektiertStandard
labelA label that describes the rating to assistive devices.
Typ: string
""
valueThe default rating set for the rating.
Typ: number
0
maxThe maximum amount able to be set for the rating.
Typ: 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).
Typ: number
1
readonlyMakes the rating readonly.
Typ: boolean
false
disabledDisables the rating.
Typ: 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.
Typ: (value: number) => string
updateComplete Ein schreibgeschütztes Promise, das erfüllt ist, sobald die Komponente fertig aktualisiert wurde.

Erfahre mehr über Attribute und Eigenschaften.

Methoden

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

Erfahre mehr über Methoden.

Events

NameBeschreibungEvent‐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 }

Erfahre mehr über Events.

Benutzerdefinierte Eigenschaften

NameBeschreibungStandard
--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

Erfahre mehr über das Anpassen von benutzerdefinierten Eigenschaften.

Parts

NameBeschreibung
baseThe component’s base wrapper.

Erfahre mehr über das Anpassen von CSS‐Parts.

Importieren

Wenn du den Autoloader oder den Standard‐Loader nutzt, kannst du diesen Abschnitt überspringen. Falls du „Cherry Picking“ betreibst, kannst du die folgenden Snippets verwenden, um diese Komponente zu importieren.

CDN (Skript‐Tag)CDN (Import)npm (Import)

Um diese Komponente manuell vom CDN zu importieren, kannst du dieses Code‐Snippet kopieren und es in dein HTML einfügen.

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

Um diese Komponente manuell vom CDN zu importieren, kannst du dieses Code‐Snippet kopieren und es in deine JavaScript‐Datei einfügen.

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

Um diese Komponente manuell von npm zu importieren, kannst du dieses Code‐Snippet kopieren und es in deine JavaScript‐Datei einfügen.

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

Abhängigkeiten

Diese Komponente importiert automatisch folgende Komponenten:

Wir würden uns freuen, von dir zu hören. Kontaktiere uns bitte bei Fragen oder Anliegen, die du hast.

Du kannst uns per E‐Mail unter placer.coc.reports+contact@gmail.com erreichen.

Wir freuen uns darauf, von dir zu hören!

Alles klar!
Gefährliche Lande

Ui! Du bist in die gefährlichen Lande von Placer Toolkit geraten. Version 0 ist veraltet und entspricht nicht den EU‐Datenschutzstandards, einschließlich DSGVO.

Willst du die neuesten Kräfte, Sicherheit und Compliance? Bleib bei der aktuellen Version von Placer Toolkit!

Ups! Aufladen!

Unsere Website ist zu 100 % frei von Cookies! Wir legen großen Wert auf deine Privatsphäre und speichern daher keinerlei Cookies oder persönliche Informationen über dich.

Dein Browserverlauf bleibt sauber und deine Daten sind geschützt, ganz im Einklang mit modernen Datenschutzstandards wie der DSGVO. Genieße deinen Besuch ganz ohne digitale Cookies! 🍪🚫

Weitere Informationen findest du in unserer Datenschutzerklärung.

Alles klar!