Zum Hauptinhalt springen Seitenleiste
Auf dieser Seite
Zum Inhaltsverzeichnis springen

Color Picker

<pc-color-picker> 1.0.0-alpha.2 experimental

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

Colour pickers allow the user to pick a colour.

Edit

This component works well with standard <form> elements. Please refer to the form controls page to learn more about form submission and client‐side validation.

Demos

Initial value

Use the value attribute to set an initial value for the colour picker.

Edit

Opacity

Use the opacity attribute to enable the opacity slider.

Edit

Formats

Use the format attribute to set the colour picker’s format. Valid options include hex, rgb, hsl and hsv. Note that the colour picker’s input will accept any parsable format (including CSS colour names) regardless of this option.

To prevent users from toggling the format themselves, add the no-format-toggle attribute.

Edit

Swatches

Use the swatches attribute to add convenient presets to the colour picker. Any format the colour picker can parse is acceptable (including CSS colour names), but each value must be separated by a semicolon (;). Alternatively, you can pass an array of colour values to this property using JavaScript.

Edit

Size

Use the size attribute to change the colour picker’s size.

Edit

Disabled

Use the disabled attribute to disable the colour picker.

Edit

Inline

The colour picker can be rendered inline instead of in a popup using the inline attribute.

Edit

Eigenschaften

NameBeschreibungReflektiertStandard
valueThe current value of the colour picker. The value’s format will vary based on the format attribute. To get the value in a specific format, use the getFormattedValue() method. The value is submitted as a name/value pair with form data.
Typ: string
""
defaultValueThe default value of the colour picker. Primarily used for resetting the colour picker.
Typ: string
""
labelThe colour picker’s label. If you need to display HTML, use the label slot instead.
Typ: string
""
hintThe colour picker’s hint. If you need to display HTML, use the hint slot instead.
Typ: string
""
formatThe format to use. The colour picker will accept user input in any format (including CSS colour names) and convert it to the desired format.
Typ: "hex" | "rgb" | "hsl" | "hsv"
"hex"
inlineRenders the color picker inline rather than in a dropdown.
Typ: boolean
false
sizeDetermines the size of the colour picker’s trigger. This has no effect on inline colour pickers.
Typ: "small" | "medium" | "large"
"medium"
noFormatToggle
no-format-toggle
Removes the button that lets users toggle between formats.
Typ: boolean
false
nameThe name of the colour picker, submitted as a name/value pair with form data.
Typ: string
""
disabledDisables the colour picker.
Typ: boolean
false
openIndicates whether or not the popup is open. You can toggle this attribute to show and hide the popup, or you can use the show() and hide() methods and this attribute will reflect the popup’s open state.
Typ: boolean
false
opacityShows the opacity slider.
Typ: boolean
false
uppercaseBy default, values are lowercase. With this attribute, values will be uppercase instead.
Typ: boolean
false
swatchesOne or more predefined colour swatches to display as presets in the colour picker. Can include any format the colour picker can parse, including hex, rgb, hsl, hsv and CSS colour names. Each colour must be separated by a semicolon (;). Alternatively, you can pass an array of colour values to this property using JavaScript.
Typ: string | string[]
""
formBy default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work.
Typ: string
""
requiredIndicates if the colour picker must be filled in or not.
Typ: boolean
false
validityGets the validity state object.
validationMessageGets the validation message.
updateComplete Ein schreibgeschütztes Promise, das erfüllt ist, sobald die Komponente fertig aktualisiert wurde.

Erfahre mehr über Attribute und Eigenschaften.

Slots

NameBeschreibung
labelThe colour picker’s label. Alternatively, you can use the label attribute.
hintThe colour picker’s hint. Alternatively, you can use the hint attribute.

Erfahre mehr über die Benutzung von Slots.

Methoden

NameBeschreibungArgumente
focus()Focuses the colour picker.options: FocusOptions
blur()Unfocuses the colour picker (i.e., blurs it).
getFormattedValue()Returns the current value as a string in the specified format.format: "hex" | "hexa" | "rgb" | "rgba" | "hsl" | "hsla" | "hsv" | "hsva"
show()Shows the colour picker popup.
hide()Hides the colour picker popup.
checkValidity()Checks for validity but does not show a validation message. Returns true when valid and false when invalid.
getForm()Gets the associated form, if one exists.
reportValidity()Checks for validity and shows the browser’s validation message if the control is invalid.
setCustomValidity()Sets a custom validation message. Pass an empty string to restore validity.message: string

Erfahre mehr über Methoden.

Events

NameBeschreibungEvent‐Detail
pc-changeEmitted when the colour picker’s value changes.
pc-inputEmitted when the colour picker receives input.
pc-focusEmitted when the colour picker receives focus.
pc-blurEmitted when the colour picker loses focus (i.e., is blurred).
pc-invalidEmitted when the form control has been checked for validity and its constraints aren’t satisfied.

Erfahre mehr über Events.

Benutzerdefinierte Eigenschaften

NameBeschreibungStandard
--grid-widthThe width of the colour grid.17em
--grid-heightThe height of the colour grid.12em
--grid-handle-sizeThe size of the colour grid’s handle.1.25em
--slider-heightThe height of the hue and alpha sliders.1em
--slider-thumb-sizeThe size of both slider thumbs.calc(var(--slider-height) + 0.25em)
--swatch-sizeThe size of each predefined colour swatch.1.5em

Erfahre mehr über das Anpassen von benutzerdefinierten Eigenschaften.

Parts

NameBeschreibung
baseThe component’s base wrapper.
popupThe colour picker’s popup popup.
triggerThe colour picker’s popup trigger.
swatchesThe container that holds the swatches.
swatchThe individual swatches in the colour picker.
gridThe colour grid.
grid-handleThe colour grid’s handle.
sliderThe hue and opacity sliders.
slider-thumbThe hue and opacity slider thumbs.
hue-sliderThe hue slider.
hue-slider-thumbThe hue slider’s thumb.
opacity-sliderThe opacity slider.
opacity-slider-thumbThe opacity slider’s thumb.
previewThe preview colour.
inputThe text input.
copy-buttonThe text input’s copy button.
copy-button-buttonThe button part of the text input’s copy button.
eyedropper-buttonThe eyedropper button.
eyedropper-button-baseThe eyedropper button’s button part.
eyedropper-button-prefixThe eyedropper button’s prefix part.
eyedropper-button-labelThe eyedropper button’s label part.
eyedropper-button-suffixThe eyedropper button’s suffix part.
format-buttonThe format switch button.
format-button-baseThe format switch button’s button part.
format-button-prefixThe format switch button’s prefix part.
format-button-labelThe format switch button’s label part.
format-button-suffixThe format switch button’s suffix part.

Erfahre mehr über das Anpassen von CSS‐Parts.

Animationen

NameBeschreibung
colorPicker.showThe animation to use when showing the colour picker popup.
colorPicker.hideThe animation to use when hiding the colour picker popup.

Erfahre mehr über das Anpassen von Animationen.

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/color-picker/color-picker.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/color-picker/color-picker.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/color-picker/color-picker.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!