Skip to content

feat: Added color picker component#1973

Draft
rkaraivanov wants to merge 23 commits into
masterfrom
rkaraivanov/color-picker
Draft

feat: Added color picker component#1973
rkaraivanov wants to merge 23 commits into
masterfrom
rkaraivanov/color-picker

Conversation

@rkaraivanov

Copy link
Copy Markdown
Member

No description provided.

rkaraivanov and others added 20 commits November 14, 2025 10:10
Introduce an explicit "missing color" sentinel and surface it through the
color picker.

ColorModel:
- Add `ColorModel.empty()` factory and an `isEmpty` getter representing a
  missing/undefined color. `default()` keeps returning black.
- Clear the empty state when any channel (r/g/b/h/s/l/v/alpha) is modified.
- `asString()` returns an empty string while empty; `clone()` preserves the
  empty state and `equals()` accounts for it.
- `parse()` returns the empty sentinel for null/undefined/empty/whitespace
  input.

Component:
- Initialize the internal color as empty so an unset picker has an empty value.
- Render the trigger anchor with a checkered background while the value is
  empty, via an `empty` shadow part token.
- Validate the color value input on commit using the new `isValidColor`
  helper; empty or invalid input reverts the field to the current color.

Styles:
- Add a checkered pattern on `[part~='empty']::part(base)`, mirroring the
  alpha slider track.

Add `isValidColor()` and update model, common and component unit tests to
cover the empty sentinel, validation and revert behavior.
Comment thread src/components/color-picker/common.ts Dismissed
Comment thread src/components/color-picker/common.ts Dismissed
Some code reorganization and refactoring was done to support the new input mode.
The color picker component now has an input mode that allows users to enter color values directly.
The component will handle changes from the input field and update the color value accordingly.
Copilot AI review requested due to automatic review settings July 21, 2026 12:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new igc-color-picker web component to the Ignite UI Web Components library, including its internal color model/converters, styles, Storybook story, and unit tests.

Changes:

  • Introduces the IgcColorPickerComponent (and supporting igc-picker-canvas) with theming and interactions (hue/SV selection, alpha, swatches, copy, eyedropper).
  • Adds a color parsing/model layer (ColorModel, converters, validation helpers) plus unit tests.
  • Wires the component into the public exports and the “define all components” registration list, and adds a Storybook story.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tsconfig.json Extends lit plugin global attributes (adds inert).
stories/color-picker.stories.ts Adds Storybook coverage for the new color picker.
src/index.ts Exports IgcColorPickerComponent from the package entry.
src/components/common/definitions/defineAllComponents.ts Registers IgcColorPickerComponent in the “define all” list.
src/components/color-picker/themes/picker-canvas.base.scss Styles for the SV picker canvas and marker.
src/components/color-picker/themes/color-picker.base.scss Styles for the overall color picker UI (sliders, buttons, swatches).
src/components/color-picker/picker-canvas.ts New SV picker surface with pointer + keyboard interactions and events.
src/components/color-picker/model.ts ColorModel implementation and context helper for parsing.
src/components/color-picker/model.spec.ts Unit tests for ColorModel.
src/components/color-picker/converters.ts RGB/HSL/HSV conversion utilities.
src/components/color-picker/common.ts Color parsing + validation helpers.
src/components/color-picker/common.spec.ts Unit tests for parsing/validation helpers.
src/components/color-picker/color-picker.ts Main igc-color-picker component implementation.
src/components/color-picker/color-picker.spec.ts Component-level tests incl. a11y and form association.


let t3: number;
let val: number;
const t2 = l < 0.5 ? l * (1 + s) : 1 + s - 1 * s;
Comment on lines +10 to +14
hex: (rgb: RGB): string => {
const [r, g, b] = rgb.map((v) => Math.round(v) & 0xff);
const value = (r << 16) + (g << 8) + b;
return value.toString(16).padStart(6, '0');
},
Comment on lines +237 to +240
this._color.s = event.detail.x;
this._color.v = 100 - event.detail.y;
this._updateColor();
}
Comment on lines +633 to +635
${isDefaultMode
? html`<label part="label" for="trigger">${this.label}</label>`
: nothing}
import type { Meta, StoryObj } from '@storybook/web-components';
import { html } from 'lit';

import { IgcColorPickerComponent, defineComponents } from '../src/index.js';
Comment on lines +305 to +307
private _handleCopy(): void {
navigator.clipboard.writeText(this.value);
}
Comment on lines +292 to +303
private _handleEyeDropperClick(): void {
const eyeDropper = new (globalThis as any).EyeDropper();

eyeDropper
.open()
.then((result: { sRGBHex: string }) => {
this.value = result.sRGBHex;
this._syncCanvasPosition();
this._emitColorPickedEvent();
})
.catch(() => {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants