@umbraco-ui/uui-color-picker 1.8.0 → 1.9.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -29,8 +29,7 @@ var __decorateClass = (decorators, target, key, kind) => {
29
29
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
30
30
  if (decorator = decorators[i])
31
31
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
32
- if (kind && result)
33
- __defProp(target, key, result);
32
+ if (kind && result) __defProp(target, key, result);
34
33
  return result;
35
34
  };
36
35
  k([namesPlugin]);
@@ -38,13 +37,13 @@ const hasEyeDropper = "EyeDropper" in window;
38
37
  let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
39
38
  constructor() {
40
39
  super(...arguments);
40
+ this._value = "";
41
41
  this.inputValue = "";
42
42
  this.hue = 0;
43
43
  this.saturation = 0;
44
44
  this.lightness = 0;
45
- this.alpha = 100;
45
+ this.alpha = 0;
46
46
  this._colord = w("hsl(0, 0%, 0%)");
47
- this.value = "";
48
47
  this.format = "hex";
49
48
  this.name = "";
50
49
  this.size = "medium";
@@ -72,13 +71,17 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
72
71
  "#fff"
73
72
  ];
74
73
  }
74
+ set value(value) {
75
+ if (this.value !== value) {
76
+ this.setColor(value);
77
+ }
78
+ this._value = value;
79
+ }
80
+ get value() {
81
+ return this._value;
82
+ }
75
83
  connectedCallback() {
76
84
  super.connectedCallback();
77
- if (this.value) {
78
- this.setColor(this.value);
79
- } else {
80
- this.setColor("#000");
81
- }
82
85
  demandCustomElement(this, "uui-icon");
83
86
  demandCustomElement(this, "uui-icon-registry-essential");
84
87
  demandCustomElement(this, "uui-input");
@@ -173,36 +176,24 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
173
176
  this.setColor(newColor);
174
177
  }
175
178
  handleInputChange(event) {
179
+ event.stopImmediatePropagation();
176
180
  this._swatches?.resetSelection();
177
- const target = event.target;
178
- if (target.value) {
179
- this.setColor(target.value);
180
- target.value = this.value;
181
- } else {
182
- this.setColor("#000");
183
- }
184
- event.stopPropagation();
181
+ this.inputValue = this._input.value;
182
+ this.setColor(this.inputValue);
185
183
  }
186
184
  handleInputKeyDown(event) {
185
+ event.stopImmediatePropagation();
187
186
  if (event.key === "Enter") {
188
- if (this.inputValue) {
189
- this.setColor(this.inputValue);
190
- this._swatches?.resetSelection();
191
- this.inputValue = this.value;
192
- setTimeout(() => this._input.select());
193
- } else {
194
- this.setColor("#000");
195
- }
187
+ this._swatches?.resetSelection();
188
+ this.inputValue = this._input.value;
189
+ this.setColor(this.inputValue);
190
+ setTimeout(() => this._input.select());
196
191
  }
197
192
  }
198
193
  handleColorSwatchChange(event) {
199
194
  event.stopImmediatePropagation();
200
195
  const target = event.target;
201
- if (target.value) {
202
- this.setColor(target.value);
203
- } else {
204
- this.setColor("#000");
205
- }
196
+ this.setColor(target.value);
206
197
  }
207
198
  handleCopy() {
208
199
  navigator.clipboard.writeText(this._input.value).then(() => {
@@ -223,6 +214,16 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
223
214
  });
224
215
  }
225
216
  setColor(colorString) {
217
+ if (colorString === this.value) return;
218
+ if (!colorString) {
219
+ this.alpha = 0;
220
+ this.inputValue = "";
221
+ this._value = colorString;
222
+ this.dispatchEvent(
223
+ new UUIColorPickerChangeEvent(UUIColorPickerChangeEvent.CHANGE)
224
+ );
225
+ return true;
226
+ }
226
227
  const colord2 = new j(colorString);
227
228
  const { h, s, l, a } = colord2.toHsl();
228
229
  this.hue = h;
@@ -258,7 +259,7 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
258
259
  }
259
260
  _syncValues() {
260
261
  this.inputValue = this.getFormattedValue(this.format);
261
- this.value = this.inputValue;
262
+ this._value = this.inputValue;
262
263
  }
263
264
  _renderColorPicker() {
264
265
  return html`
@@ -350,11 +351,11 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
350
351
  `;
351
352
  }
352
353
  _renderSwatches() {
353
- if (!this.swatches)
354
- return nothing;
354
+ if (!this.swatches) return nothing;
355
355
  return html`<uui-color-swatches
356
356
  id="swatches"
357
357
  class="color-picker__swatches"
358
+ label="Swatches"
358
359
  ?disabled=${this.disabled}
359
360
  @change=${this.handleColorSwatchChange}>
360
361
  ${this.swatches.map(
@@ -364,7 +365,7 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
364
365
  </uui-color-swatches>`;
365
366
  }
366
367
  _renderPreviewButton() {
367
- return html` <button
368
+ return html`<button
368
369
  type="button"
369
370
  part="trigger"
370
371
  aria-label="${this.label || "Open Color picker"}"
@@ -565,7 +566,7 @@ __decorateClass([
565
566
  ], UUIColorPickerElement.prototype, "_colord", 2);
566
567
  __decorateClass([
567
568
  property()
568
- ], UUIColorPickerElement.prototype, "value", 2);
569
+ ], UUIColorPickerElement.prototype, "value", 1);
569
570
  __decorateClass([
570
571
  property()
571
572
  ], UUIColorPickerElement.prototype, "format", 2);
@@ -2,8 +2,7 @@ import { LitElement } from 'lit';
2
2
  import { HslaColor } from 'colord';
3
3
  import type { UUIColorAreaEvent } from '@umbraco-ui/uui-color-area/lib';
4
4
  import type { UUIColorSliderEvent } from '@umbraco-ui/uui-color-slider/lib';
5
- import type { UUIColorSwatchesElement, UUIColorSwatchesEvent } from '@umbraco-ui/uui-color-swatches/lib';
6
- import type { UUIInputElement } from '@umbraco-ui/uui-input/lib';
5
+ import type { UUIColorSwatchesEvent } from '@umbraco-ui/uui-color-swatches/lib';
7
6
  export type UUIColorPickerFormat = 'hex' | 'rgb' | 'hsl' | 'hsv';
8
7
  export type UUIColorPickerFormatWithAlpha = UUIColorPickerFormat | 'hexa' | 'rgba' | 'hsla' | 'hsva';
9
8
  type UUIColorPickerSize = 'small' | 'medium' | 'large';
@@ -15,9 +14,10 @@ declare const UUIColorPickerElement_base: (new (...args: any[]) => import("@umbr
15
14
  * @fires {UUIColorPickerChangeEvent} change - Fired when the color changes
16
15
  */
17
16
  export declare class UUIColorPickerElement extends UUIColorPickerElement_base {
18
- _input: UUIInputElement;
19
- _previewButton: HTMLButtonElement;
20
- _swatches: UUIColorSwatchesElement;
17
+ private _input;
18
+ private _previewButton;
19
+ private _swatches;
20
+ private _value;
21
21
  private inputValue;
22
22
  private hue;
23
23
  private saturation;
@@ -30,7 +30,8 @@ export declare class UUIColorPickerElement extends UUIColorPickerElement_base {
30
30
  * @type {string}
31
31
  * @default ''
32
32
  **/
33
- value: string;
33
+ set value(value: string);
34
+ get value(): string;
34
35
  /**
35
36
  * The format to use for the display value. If opacity is enabled, these will translate to HEXA, RGBA, HSLA, and HSVA
36
37
  * respectively. The color picker will always accept user input in any format (including CSS color names) and convert
@@ -108,7 +109,7 @@ export declare class UUIColorPickerElement extends UUIColorPickerElement_base {
108
109
  handleColorSwatchChange(event: UUIColorSwatchesEvent): void;
109
110
  handleCopy(): void;
110
111
  handleEyeDropper(): void;
111
- setColor(colorString: string | HslaColor): boolean;
112
+ setColor(colorString: string | HslaColor): true | undefined;
112
113
  setLetterCase(string: string): string;
113
114
  /** Generates a hex string from HSL values. Hue must be 0-360. All other arguments must be 0-100. */
114
115
  private getHexString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umbraco-ui/uui-color-picker",
3
- "version": "1.8.0",
3
+ "version": "1.9.0-rc.0",
4
4
  "license": "MIT",
5
5
  "keywords": [
6
6
  "Umbraco",
@@ -30,8 +30,8 @@
30
30
  "custom-elements.json"
31
31
  ],
32
32
  "dependencies": {
33
- "@umbraco-ui/uui-base": "1.8.0",
34
- "@umbraco-ui/uui-popover-container": "1.8.0",
33
+ "@umbraco-ui/uui-base": "1.9.0-rc.0",
34
+ "@umbraco-ui/uui-popover-container": "1.9.0-rc.0",
35
35
  "colord": "^2.9.3"
36
36
  },
37
37
  "scripts": {
@@ -43,5 +43,5 @@
43
43
  "access": "public"
44
44
  },
45
45
  "homepage": "https://uui.umbraco.com/?path=/story/uui-color-picker",
46
- "gitHead": "53021762a52dc54a46f0c5ef829c1cbaabde1160"
46
+ "gitHead": "e3e398e07b6ff9874aa0656cb7767df42f58a4ce"
47
47
  }