import PButton from "../button/button.component.js"; import PButtonGroup from "../button-group/button-group.component.js"; import PDropdown from "../dropdown/dropdown.component.js"; import PIcon from "../icon/icon.component.js"; import PInput from "../input/input.component.js"; import PureElement from "../../internal/pure-ui-element.js"; import PVisuallyHidden from "../visually-hidden/visually-hidden.component.js"; import type { CSSResultGroup } from "lit"; import type { PureFormControl } from "../../internal/pure-ui-element.js"; /** * @summary Color pickers allow the user to select a color. * @documentation https://pureui.online/components/color-picker * @status stable * @since 1.0 * * @dependency p-button * @dependency p-button-group * @dependency p-dropdown * @dependency p-input * @dependency p-visually-hidden * * @slot label - The color picker's form label. Alternatively, you can use the `label` attribute. * * @event p-blur - Emitted when the color picker loses focus. * @event p-change - Emitted when the color picker's value changes. * @event p-focus - Emitted when the color picker receives focus. * @event p-input - Emitted when the color picker receives input. * @event p-invalid - Emitted when the form control has been checked for validity and its constraints aren't satisfied. * * @csspart base - The component's base wrapper. * @csspart trigger - The color picker's dropdown trigger. * @csspart swatches - The container that holds the swatches. * @csspart swatch - Each individual swatch. * @csspart grid - The color grid. * @csspart grid-handle - The color grid's handle. * @csspart slider - Hue and opacity sliders. * @csspart slider-handle - Hue and opacity slider handles. * @csspart hue-slider - The hue slider. * @csspart hue-slider-handle - The hue slider's handle. * @csspart opacity-slider - The opacity slider. * @csspart opacity-slider-handle - The opacity slider's handle. * @csspart preview - The preview color. * @csspart input - The text input. * @csspart eye-dropper-button - The eye dropper button. * @csspart eye-dropper-button__base - The eye dropper button's exported `button` part. * @csspart eye-dropper-button__prefix - The eye dropper button's exported `prefix` part. * @csspart eye-dropper-button__label - The eye dropper button's exported `label` part. * @csspart eye-dropper-button__suffix - The eye dropper button's exported `suffix` part. * @csspart eye-dropper-button__caret - The eye dropper button's exported `caret` part. * @csspart format-button - The format button. * @csspart format-button__base - The format button's exported `button` part. * @csspart format-button__prefix - The format button's exported `prefix` part. * @csspart format-button__label - The format button's exported `label` part. * @csspart format-button__suffix - The format button's exported `suffix` part. * @csspart format-button__caret - The format button's exported `caret` part. * * @cssproperty --grid-width - The width of the color grid. * @cssproperty --grid-height - The height of the color grid. * @cssproperty --grid-handle-size - The size of the color grid's handle. * @cssproperty --slider-height - The height of the hue and alpha sliders. * @cssproperty --slider-handle-size - The diameter of the slider's handle. * @cssproperty --swatch-size - The size of each predefined color swatch. */ export default class PColorPicker extends PureElement implements PureFormControl { static styles: CSSResultGroup; static dependencies: { "p-button-group": typeof PButtonGroup; "p-button": typeof PButton; "p-dropdown": typeof PDropdown; "p-icon": typeof PIcon; "p-input": typeof PInput; "p-visually-hidden": typeof PVisuallyHidden; }; private readonly formControlController; private isSafeValue; private readonly localize; base: HTMLElement; input: PInput; dropdown: PDropdown; previewButton: HTMLButtonElement; trigger: HTMLButtonElement; private hasFocus; private isDraggingGridHandle; private isEmpty; private inputValue; private hue; private saturation; private brightness; private alpha; /** * The current value of the color picker. The value's format will vary based 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. */ value: string; /** The default value of the form control. Primarily used for resetting the form control. */ defaultValue: string; /** * The color picker's label. This will not be displayed, but it will be announced by assistive devices. If you need to * display HTML, you can use the `label` slot` instead. */ label: string; /** * The format to use. If opacity is enabled, these will translate to HEXA, RGBA, HSLA, and HSVA respectively. The color * picker will accept user input in any format (including CSS color names) and convert it to the desired format. */ format: "hex" | "rgb" | "hsl" | "hsv"; /** Renders the color picker inline rather than in a dropdown. */ inline: boolean; /** Determines the size of the color picker's trigger. This has no effect on inline color pickers. */ size: "small" | "medium" | "large"; /** Removes the button that lets users toggle between format. */ noFormatToggle: boolean; /** The name of the form control, submitted as a name/value pair with form data. */ name: string; /** Disables the color picker. */ disabled: boolean; /** * Enable this option to prevent the panel from being clipped when the component is placed inside a container with * `overflow: auto|scroll`. Hoisting uses a fixed positioning strategy that works in many, but not all, scenarios. */ hoist: boolean; /** Shows the opacity slider. Enabling this will cause the formatted value to be HEXA, RGBA, or HSLA. */ opacity: boolean; /** By default, values are lowercase. With this attribute, values will be uppercase instead. */ uppercase: boolean; /** * One or more predefined color swatches to display as presets in the color picker. Can include any format the color * picker can parse, including HEX(A), RGB(A), HSL(A), HSV(A), and CSS color names. Each color must be separated by a * semicolon (`;`). Alternatively, you can pass an array of color values to this property using JavaScript. */ swatches: string | string[]; /** * By default, form controls are associated with the nearest containing `