@umbraco-ui/uui-color-swatch 1.5.0-rc.3 → 1.6.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.
@@ -4,13 +4,18 @@
4
4
  {
5
5
  "name": "uui-color-swatch",
6
6
  "path": "./lib/uui-color-swatch.element.ts",
7
- "description": "Color swatch, can have label and be selectable. Depends on colord library and exposes it's utility functions under color property.",
7
+ "description": "Color swatch, can have label and be selectable.",
8
8
  "attributes": [
9
9
  {
10
10
  "name": "value",
11
- "description": "Value of the swatch. Should be a valid hex, hexa, rgb, rgba, hsl or hsla string. Should fulfill this [css spec](https://www.w3.org/TR/css-color-4/#color-type). If not provided element will look at its text content.",
11
+ "description": "Value of the swatch. This will become the color value if color is left undefined, see the property `color` for more details.",
12
12
  "type": "string"
13
13
  },
14
+ {
15
+ "name": "color",
16
+ "description": "Color of the swatch. Should be a valid hex, hexa, rgb, rgba, hsl or hsla string. Should fulfill this [css spec](https://www.w3.org/TR/css-color-4/#color-type). If not provided element will look at its text content.",
17
+ "type": "string | undefined"
18
+ },
14
19
  {
15
20
  "name": "disabled",
16
21
  "description": "Determines if the options is disabled. If true the option can't be selected",
@@ -50,9 +55,15 @@
50
55
  {
51
56
  "name": "value",
52
57
  "attribute": "value",
53
- "description": "Value of the swatch. Should be a valid hex, hexa, rgb, rgba, hsl or hsla string. Should fulfill this [css spec](https://www.w3.org/TR/css-color-4/#color-type). If not provided element will look at its text content.",
58
+ "description": "Value of the swatch. This will become the color value if color is left undefined, see the property `color` for more details.",
54
59
  "type": "string"
55
60
  },
61
+ {
62
+ "name": "color",
63
+ "attribute": "color",
64
+ "description": "Color of the swatch. Should be a valid hex, hexa, rgb, rgba, hsl or hsla string. Should fulfill this [css spec](https://www.w3.org/TR/css-color-4/#color-type). If not provided element will look at its text content.",
65
+ "type": "string | undefined"
66
+ },
56
67
  {
57
68
  "name": "disabled",
58
69
  "attribute": "disabled",
@@ -67,16 +78,6 @@
67
78
  "type": "boolean",
68
79
  "default": "false"
69
80
  },
70
- {
71
- "name": "color",
72
- "description": "Colord object instance based on the value provided to the element. If the value is not a valid color, it falls back to black (like Amy Winehouse). For more information about Colord, see [Colord](https://omgovich.github.io/colord/)",
73
- "type": "Colord | null"
74
- },
75
- {
76
- "name": "isLight",
77
- "description": "Returns true if the color brightness is >= 0.5",
78
- "type": "boolean"
79
- },
80
81
  {
81
82
  "name": "styles",
82
83
  "type": "CSSResult[]",
@@ -133,6 +134,10 @@
133
134
  {
134
135
  "name": "--uui-swatch-border-width",
135
136
  "description": "The width of the border."
137
+ },
138
+ {
139
+ "name": "--uui-swatch-color",
140
+ "description": "The width of the border."
136
141
  }
137
142
  ]
138
143
  }
package/lib/index.js CHANGED
@@ -1,13 +1,9 @@
1
1
  import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
2
2
  import { property } from 'lit/decorators.js';
3
- import { classMap } from 'lit/directives/class-map.js';
4
3
  import { LitElement, html, nothing, css } from 'lit';
5
4
  import { iconCheck } from '@umbraco-ui/uui-icon-registry-essential/lib/svgs';
6
- import { styleMap } from 'lit/directives/style-map.js';
7
5
  import { LabelMixin, SelectableMixin, ActiveMixin } from '@umbraco-ui/uui-base/lib/mixins';
8
6
 
9
- var r={grad:.9,turn:360,rad:360/(2*Math.PI)},t=function(r){return "string"==typeof r?r.length>0:"number"==typeof r},n=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=Math.pow(10,t)),Math.round(n*r)/n+0},e=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=1),r>n?n:r>t?r:t},u=function(r){return (r=isFinite(r)?r%360:0)>0?r:r+360},a=function(r){return {r:e(r.r,0,255),g:e(r.g,0,255),b:e(r.b,0,255),a:e(r.a)}},o=function(r){return {r:n(r.r),g:n(r.g),b:n(r.b),a:n(r.a,3)}},i=/^#([0-9a-f]{3,8})$/i,s=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},h=function(r){var t=r.r,n=r.g,e=r.b,u=r.a,a=Math.max(t,n,e),o=a-Math.min(t,n,e),i=o?a===t?(n-e)/o:a===n?2+(e-t)/o:4+(t-n)/o:0;return {h:60*(i<0?i+6:i),s:a?o/a*100:0,v:a/255*100,a:u}},b=function(r){var t=r.h,n=r.s,e=r.v,u=r.a;t=t/360*6,n/=100,e/=100;var a=Math.floor(t),o=e*(1-n),i=e*(1-(t-a)*n),s=e*(1-(1-t+a)*n),h=a%6;return {r:255*[e,i,o,o,s,e][h],g:255*[s,e,e,i,o,o][h],b:255*[o,o,s,e,e,i][h],a:u}},g=function(r){return {h:u(r.h),s:e(r.s,0,100),l:e(r.l,0,100),a:e(r.a)}},d=function(r){return {h:n(r.h),s:n(r.s),l:n(r.l),a:n(r.a,3)}},f=function(r){return b((n=(t=r).s,{h:t.h,s:(n*=((e=t.l)<50?e:100-e)/100)>0?2*n/(e+n)*100:0,v:e+n,a:t.a}));var t,n,e;},c=function(r){return {h:(t=h(r)).h,s:(u=(200-(n=t.s))*(e=t.v)/100)>0&&u<200?n*e/100/(u<=100?u:200-u)*100:0,l:u/2,a:t.a};var t,n,e,u;},l=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,p=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,v=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,m=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,y={string:[[function(r){var t=i.exec(r);return t?(r=t[1]).length<=4?{r:parseInt(r[0]+r[0],16),g:parseInt(r[1]+r[1],16),b:parseInt(r[2]+r[2],16),a:4===r.length?n(parseInt(r[3]+r[3],16)/255,2):1}:6===r.length||8===r.length?{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16),a:8===r.length?n(parseInt(r.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(r){var t=v.exec(r)||m.exec(r);return t?t[2]!==t[4]||t[4]!==t[6]?null:a({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:void 0===t[7]?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(t){var n=l.exec(t)||p.exec(t);if(!n)return null;var e,u,a=g({h:(e=n[1],u=n[2],void 0===u&&(u="deg"),Number(e)*(r[u]||1)),s:Number(n[3]),l:Number(n[4]),a:void 0===n[5]?1:Number(n[5])/(n[6]?100:1)});return f(a)},"hsl"]],object:[[function(r){var n=r.r,e=r.g,u=r.b,o=r.a,i=void 0===o?1:o;return t(n)&&t(e)&&t(u)?a({r:Number(n),g:Number(e),b:Number(u),a:Number(i)}):null},"rgb"],[function(r){var n=r.h,e=r.s,u=r.l,a=r.a,o=void 0===a?1:a;if(!t(n)||!t(e)||!t(u))return null;var i=g({h:Number(n),s:Number(e),l:Number(u),a:Number(o)});return f(i)},"hsl"],[function(r){var n=r.h,a=r.s,o=r.v,i=r.a,s=void 0===i?1:i;if(!t(n)||!t(a)||!t(o))return null;var h=function(r){return {h:u(r.h),s:e(r.s,0,100),v:e(r.v,0,100),a:e(r.a)}}({h:Number(n),s:Number(a),v:Number(o),a:Number(s)});return b(h)},"hsv"]]},N=function(r,t){for(var n=0;n<t.length;n++){var e=t[n][0](r);if(e)return [e,t[n][1]]}return [null,void 0]},x=function(r){return "string"==typeof r?N(r.trim(),y.string):"object"==typeof r&&null!==r?N(r,y.object):[null,void 0]},M=function(r,t){var n=c(r);return {h:n.h,s:e(n.s+100*t,0,100),l:n.l,a:n.a}},H=function(r){return (299*r.r+587*r.g+114*r.b)/1e3/255},$=function(r,t){var n=c(r);return {h:n.h,s:n.s,l:e(n.l+100*t,0,100),a:n.a}},j=function(){function r(r){this.parsed=x(r)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1};}return r.prototype.isValid=function(){return null!==this.parsed},r.prototype.brightness=function(){return n(H(this.rgba),2)},r.prototype.isDark=function(){return H(this.rgba)<.5},r.prototype.isLight=function(){return H(this.rgba)>=.5},r.prototype.toHex=function(){return r=o(this.rgba),t=r.r,e=r.g,u=r.b,i=(a=r.a)<1?s(n(255*a)):"","#"+s(t)+s(e)+s(u)+i;var r,t,e,u,a,i;},r.prototype.toRgb=function(){return o(this.rgba)},r.prototype.toRgbString=function(){return r=o(this.rgba),t=r.r,n=r.g,e=r.b,(u=r.a)<1?"rgba("+t+", "+n+", "+e+", "+u+")":"rgb("+t+", "+n+", "+e+")";var r,t,n,e,u;},r.prototype.toHsl=function(){return d(c(this.rgba))},r.prototype.toHslString=function(){return r=d(c(this.rgba)),t=r.h,n=r.s,e=r.l,(u=r.a)<1?"hsla("+t+", "+n+"%, "+e+"%, "+u+")":"hsl("+t+", "+n+"%, "+e+"%)";var r,t,n,e,u;},r.prototype.toHsv=function(){return r=h(this.rgba),{h:n(r.h),s:n(r.s),v:n(r.v),a:n(r.a,3)};var r;},r.prototype.invert=function(){return w({r:255-(r=this.rgba).r,g:255-r.g,b:255-r.b,a:r.a});var r;},r.prototype.saturate=function(r){return void 0===r&&(r=.1),w(M(this.rgba,r))},r.prototype.desaturate=function(r){return void 0===r&&(r=.1),w(M(this.rgba,-r))},r.prototype.grayscale=function(){return w(M(this.rgba,-1))},r.prototype.lighten=function(r){return void 0===r&&(r=.1),w($(this.rgba,r))},r.prototype.darken=function(r){return void 0===r&&(r=.1),w($(this.rgba,-r))},r.prototype.rotate=function(r){return void 0===r&&(r=15),this.hue(this.hue()+r)},r.prototype.alpha=function(r){return "number"==typeof r?w({r:(t=this.rgba).r,g:t.g,b:t.b,a:r}):n(this.rgba.a,3);var t;},r.prototype.hue=function(r){var t=c(this.rgba);return "number"==typeof r?w({h:r,s:t.s,l:t.l,a:t.a}):n(t.h)},r.prototype.isEqual=function(r){return this.toHex()===w(r).toHex()},r}(),w=function(r){return r instanceof j?r:new j(r)};
10
-
11
7
  var __defProp = Object.defineProperty;
12
8
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
9
  var __decorateClass = (decorators, target, key, kind) => {
@@ -25,64 +21,35 @@ let UUIColorSwatchElement = class extends LabelMixin(
25
21
  ) {
26
22
  constructor() {
27
23
  super();
28
- this._value = "";
29
24
  this.disabled = false;
30
25
  this.showLabel = false;
31
- this._color = null;
32
26
  this.addEventListener("click", this._setAriaAttributes);
33
27
  }
34
28
  get value() {
35
29
  var _a;
36
- return this._value ? this._value : ((_a = this.textContent) == null ? void 0 : _a.trim()) || "";
30
+ return (_a = this._value) != null ? _a : "";
37
31
  }
38
32
  set value(newValue) {
39
33
  const oldValue = this._value;
40
34
  this._value = newValue;
41
35
  this.requestUpdate("value", oldValue);
42
36
  }
43
- /**
44
- * Colord object instance based on the value provided to the element. If the value is not a valid color, it falls back to black (like Amy Winehouse). For more information about Colord, see [Colord](https://omgovich.github.io/colord/)
45
- *
46
- * @memberof UUIColorSwatchElement
47
- */
48
37
  get color() {
49
38
  return this._color;
50
39
  }
51
- set color(_) {
52
- return;
53
- }
54
- /**
55
- * Returns true if the color brightness is >= 0.5
56
- *
57
- * @readonly
58
- * @memberof UUIColorSwatchElement
59
- */
60
- get isLight() {
61
- var _a, _b;
62
- return (_b = (_a = this.color) == null ? void 0 : _a.isLight()) != null ? _b : false;
63
- }
64
- _initializeColor() {
65
- var _a;
66
- this._color = new j((_a = this.value) != null ? _a : "");
67
- if (!this._color.isValid()) {
68
- this.disabled = true;
69
- console.error(
70
- `Invalid color provided to uui-color-swatch: ${this.value}`
71
- );
72
- }
40
+ set color(newValue) {
41
+ const oldValue = this._color;
42
+ this._color = newValue;
43
+ this.requestUpdate("color", oldValue);
73
44
  }
74
45
  _setAriaAttributes() {
75
46
  if (this.selectable)
76
47
  this.setAttribute("aria-checked", this.selected.toString());
77
48
  }
78
49
  firstUpdated() {
79
- this._initializeColor();
80
50
  this._setAriaAttributes();
81
51
  }
82
52
  willUpdate(changedProperties) {
83
- if (changedProperties.has("value")) {
84
- this._initializeColor();
85
- }
86
53
  if (changedProperties.has("disabled")) {
87
54
  if (this.selectable) {
88
55
  this.selectable = !this.disabled;
@@ -94,23 +61,22 @@ let UUIColorSwatchElement = class extends LabelMixin(
94
61
  }
95
62
  }
96
63
  render() {
64
+ var _a, _b;
97
65
  return html`
98
66
  <button
99
67
  id="swatch"
100
68
  aria-label=${this.label}
101
69
  aria-disabled="${this.disabled}"
102
70
  title="${this.label}">
103
- <div
104
- class=${classMap({
105
- "color-swatch": true,
106
- "color-swatch--transparent-bg": true,
107
- "color-swatch--light": this.isLight,
108
- "color-swatch--big": this.showLabel
109
- })}>
71
+ <div class="color-swatch color-swatch--transparent-bg">
110
72
  <div
111
73
  class="color-swatch__color"
112
- style=${styleMap({ backgroundColor: this.value })}></div>
113
- <div class="color-swatch__check">${iconCheck}</div>
74
+ style="background-color: var(--uui-swatch-color, ${(_a = this.color) != null ? _a : this.value})"></div>
75
+ <div
76
+ class="color-swatch__check"
77
+ style="fill: var(--uui-swatch-color, ${(_b = this.color) != null ? _b : this.value})">
78
+ ${iconCheck}
79
+ </div>
114
80
  </div>
115
81
  ${this._renderWithLabel()}
116
82
  </button>
@@ -187,7 +153,7 @@ UUIColorSwatchElement.styles = [
187
153
  width: calc(100% + calc(var(--uui-swatch-border-width, 1px) * 2));
188
154
  height: calc(100% + calc(var(--uui-swatch-border-width, 1px) * 2));
189
155
  box-sizing: border-box;
190
- border: var(--uui-swatch-border-width, 1px) solid
156
+ border: var(--uui-swatch-border-width, 2px) solid
191
157
  var(--uui-color-selected,#3544b1);
192
158
  border-radius: calc(
193
159
  var(--uui-border-radius,3px) + var(--uui-swatch-border-width, 1px)
@@ -215,7 +181,13 @@ UUIColorSwatchElement.styles = [
215
181
  justify-content: center;
216
182
  align-items: center;
217
183
  }
218
- .color-swatch--transparent-bg {
184
+
185
+ :host([show-label]) .color-swatch {
186
+ width: 120px;
187
+ height: 50px;
188
+ }
189
+
190
+ .color-swatch.color-swatch--transparent-bg {
219
191
  background-image: linear-gradient(
220
192
  45deg,
221
193
  var(--uui-palette-grey,#c4c4c4) 25%,
@@ -235,7 +207,7 @@ UUIColorSwatchElement.styles = [
235
207
  box-sizing: border-box;
236
208
  }
237
209
 
238
- .color-swatch--big .color-swatch__color {
210
+ :host([show-label]) .color-swatch__color {
239
211
  border-radius: 3px 3px 0 0;
240
212
  }
241
213
 
@@ -245,16 +217,11 @@ UUIColorSwatchElement.styles = [
245
217
  width: calc(var(--uui-swatch-size, 25px) / 2);
246
218
  height: calc(var(--uui-swatch-size, 25px) / 2);
247
219
  line-height: 0;
248
- transition: fill 120ms, opacity 120ms;
249
- fill: #fff;
220
+ filter: invert(1) grayscale(1) contrast(9);
250
221
  pointer-events: none;
251
222
  opacity: 0;
252
223
  }
253
224
 
254
- .color-swatch--light .color-swatch__check {
255
- fill: #000;
256
- }
257
-
258
225
  :host([selected]) .color-swatch__check {
259
226
  opacity: 1;
260
227
  }
@@ -264,11 +231,6 @@ UUIColorSwatchElement.styles = [
264
231
  font-size: var(--uui-size-4,12px);
265
232
  }
266
233
 
267
- .color-swatch--big {
268
- width: 120px;
269
- height: 50px;
270
- }
271
-
272
234
  .color-swatch__label {
273
235
  max-width: 120px;
274
236
  box-sizing: border-box;
@@ -293,11 +255,14 @@ UUIColorSwatchElement.styles = [
293
255
  __decorateClass([
294
256
  property()
295
257
  ], UUIColorSwatchElement.prototype, "value", 1);
258
+ __decorateClass([
259
+ property()
260
+ ], UUIColorSwatchElement.prototype, "color", 1);
296
261
  __decorateClass([
297
262
  property({ type: Boolean, reflect: true })
298
263
  ], UUIColorSwatchElement.prototype, "disabled", 2);
299
264
  __decorateClass([
300
- property({ type: Boolean, attribute: "show-label" })
265
+ property({ type: Boolean, attribute: "show-label", reflect: true })
301
266
  ], UUIColorSwatchElement.prototype, "showLabel", 2);
302
267
  UUIColorSwatchElement = __decorateClass([
303
268
  defineElement("uui-color-swatch")
@@ -1,23 +1,27 @@
1
- import { Colord } from 'colord';
2
1
  import { LitElement } from 'lit';
3
2
  declare const UUIColorSwatchElement_base: (new (...args: any[]) => import("@umbraco-ui/uui-base/lib/mixins").LabelMixinInterface) & (new (...args: any[]) => import("@umbraco-ui/uui-base/lib/mixins").SelectableMixinInterface) & (new (...args: any[]) => import("@umbraco-ui/uui-base/lib/mixins").ActiveMixinInterface) & typeof LitElement;
4
3
  /**
5
- * Color swatch, can have label and be selectable. Depends on colord library and exposes it's utility functions under color property.
4
+ * Color swatch, can have label and be selectable.
6
5
  *
7
6
  * @element uui-color-swatch
8
7
  * @cssprop --uui-swatch-size - The size of the swatch.
9
8
  * @cssprop --uui-swatch-border-width - The width of the border.
9
+ * @cssprop --uui-swatch-color - The width of the border.
10
10
  * @slot label - Default slot for the label.
11
11
  */
12
12
  export declare class UUIColorSwatchElement extends UUIColorSwatchElement_base {
13
- private _value;
14
13
  /**
15
- * Value of the swatch. Should be a valid hex, hexa, rgb, rgba, hsl or hsla string. Should fulfill this [css spec](https://www.w3.org/TR/css-color-4/#color-type). If not provided element will look at its text content.
16
- *
17
- * @attr
14
+ * Value of the swatch. This will become the color value if color is left undefined, see the property `color` for more details.
18
15
  */
19
16
  get value(): string;
20
17
  set value(newValue: string);
18
+ private _value?;
19
+ /**
20
+ * Color of the swatch. Should be a valid hex, hexa, rgb, rgba, hsl or hsla string. Should fulfill this [css spec](https://www.w3.org/TR/css-color-4/#color-type). If not provided element will look at its text content.
21
+ */
22
+ get color(): string | undefined;
23
+ set color(newValue: string);
24
+ private _color?;
21
25
  /**
22
26
  * Determines if the options is disabled. If true the option can't be selected
23
27
  *
@@ -31,23 +35,7 @@ export declare class UUIColorSwatchElement extends UUIColorSwatchElement_base {
31
35
  * @memberof UUIColorSwatchElement
32
36
  */
33
37
  showLabel: boolean;
34
- /**
35
- * Colord object instance based on the value provided to the element. If the value is not a valid color, it falls back to black (like Amy Winehouse). For more information about Colord, see [Colord](https://omgovich.github.io/colord/)
36
- *
37
- * @memberof UUIColorSwatchElement
38
- */
39
- get color(): Colord | null;
40
- set color(_: Colord | null);
41
- private _color;
42
- /**
43
- * Returns true if the color brightness is >= 0.5
44
- *
45
- * @readonly
46
- * @memberof UUIColorSwatchElement
47
- */
48
- get isLight(): boolean;
49
38
  constructor();
50
- private _initializeColor;
51
39
  private _setAriaAttributes;
52
40
  firstUpdated(): void;
53
41
  willUpdate(changedProperties: Map<string, any>): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umbraco-ui/uui-color-swatch",
3
- "version": "1.5.0-rc.3",
3
+ "version": "1.6.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.5.0-rc.3",
34
- "@umbraco-ui/uui-icon-registry-essential": "1.5.0-rc.3",
33
+ "@umbraco-ui/uui-base": "1.6.0-rc.0",
34
+ "@umbraco-ui/uui-icon-registry-essential": "1.6.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-swatch",
46
- "gitHead": "9301fe65bae63502f49e6024cc32aa3b3844556e"
46
+ "gitHead": "04709c32cb81b058bdf7976b69533e5b793c49ab"
47
47
  }