@umbraco-ui/uui-color-swatch 1.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 uui-app
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # uui-color-swatch
2
+
3
+ ![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-color-swatch?logoColor=%231B264F)
4
+
5
+ Umbraco style color-swatch component.
6
+
7
+ ## Installation
8
+
9
+ ### ES imports
10
+
11
+ ```zsh
12
+ npm i @umbraco-ui/uui-color-swatch
13
+ ```
14
+
15
+ Import the registration of `<uui-color-swatch>` via:
16
+
17
+ ```javascript
18
+ import '@umbraco-ui/uui-color-swatch';
19
+ ```
20
+
21
+ When looking to leverage the `UUIColorSwatchElement` base class as a type and/or for extension purposes, do so via:
22
+
23
+ ```javascript
24
+ import { UUIColorSwatchElement } from '@umbraco-ui/uui-color-swatch';
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```html
30
+ <uui-color-swatch></uui-color-swatch>
31
+ ```
@@ -0,0 +1,146 @@
1
+ {
2
+ "version": "experimental",
3
+ "tags": [
4
+ {
5
+ "name": "uui-color-swatch",
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.",
8
+ "attributes": [
9
+ {
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.",
12
+ "type": " string ",
13
+ "default": "\"\\\"\\\"\""
14
+ },
15
+ {
16
+ "name": "disabled",
17
+ "description": "Determines if the options is disabled. If true the option can't be selected",
18
+ "type": " boolean ",
19
+ "default": "\"false\""
20
+ },
21
+ {
22
+ "name": "show-label",
23
+ "description": "When true shows element label below the color checkbox",
24
+ "type": "boolean",
25
+ "default": "false"
26
+ },
27
+ {
28
+ "name": "label",
29
+ "description": "Label to be used for aria-label and potentially as visual label for some components",
30
+ "type": "string"
31
+ },
32
+ {
33
+ "name": "selectable",
34
+ "description": "Enable the ability to select this element.",
35
+ "type": "boolean"
36
+ },
37
+ {
38
+ "name": "selected",
39
+ "description": "Attribute applied when the element is selected.",
40
+ "type": "boolean",
41
+ "default": "false"
42
+ },
43
+ {
44
+ "name": "active",
45
+ "description": "Set this boolean to true for then the related composition is sorted.",
46
+ "type": "boolean",
47
+ "default": "false"
48
+ }
49
+ ],
50
+ "properties": [
51
+ {
52
+ "name": "styles",
53
+ "type": "CSSResult[]",
54
+ "default": "[null]"
55
+ },
56
+ {
57
+ "name": "value",
58
+ "attribute": "value",
59
+ "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.",
60
+ "type": " string ",
61
+ "default": "\"\\\"\\\"\""
62
+ },
63
+ {
64
+ "name": "disabled",
65
+ "attribute": "disabled",
66
+ "description": "Determines if the options is disabled. If true the option can't be selected",
67
+ "type": " boolean ",
68
+ "default": "\"false\""
69
+ },
70
+ {
71
+ "name": "showLabel",
72
+ "attribute": "show-label",
73
+ "description": "When true shows element label below the color checkbox",
74
+ "type": "boolean",
75
+ "default": "false"
76
+ },
77
+ {
78
+ "name": "color",
79
+ "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/)",
80
+ "type": "(Colord | null)"
81
+ },
82
+ {
83
+ "name": "isLight",
84
+ "description": "Returns true if the color brightness is >= 0.5",
85
+ "type": "boolean"
86
+ },
87
+ {
88
+ "name": "label",
89
+ "attribute": "label",
90
+ "description": "Label to be used for aria-label and potentially as visual label for some components",
91
+ "type": "string"
92
+ },
93
+ {
94
+ "name": "selectable",
95
+ "attribute": "selectable",
96
+ "description": "Enable the ability to select this element.",
97
+ "type": "boolean"
98
+ },
99
+ {
100
+ "name": "selected",
101
+ "attribute": "selected",
102
+ "description": "Attribute applied when the element is selected.",
103
+ "type": "boolean",
104
+ "default": "false"
105
+ },
106
+ {
107
+ "name": "active",
108
+ "attribute": "active",
109
+ "description": "Set this boolean to true for then the related composition is sorted.",
110
+ "type": "boolean",
111
+ "default": "false"
112
+ }
113
+ ],
114
+ "events": [
115
+ {
116
+ "name": "selected",
117
+ "description": "fires when the media card is selected"
118
+ },
119
+ {
120
+ "name": "unselected",
121
+ "description": "fires when the media card is unselected"
122
+ }
123
+ ],
124
+ "slots": [
125
+ {
126
+ "name": "label",
127
+ "description": "Default slot for the label."
128
+ },
129
+ {
130
+ "name": "",
131
+ "description": "Override the default label"
132
+ }
133
+ ],
134
+ "cssProperties": [
135
+ {
136
+ "name": "--uui-swatch-size",
137
+ "description": "The size of the swatch."
138
+ },
139
+ {
140
+ "name": "--uui-swatch-border-width",
141
+ "description": "The width of the border."
142
+ }
143
+ ]
144
+ }
145
+ ]
146
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './uui-color-swatch.element';
package/lib/index.js ADDED
@@ -0,0 +1,237 @@
1
+ import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
2
+ import { property } from 'lit/decorators.js';
3
+ import { classMap } from 'lit/directives/class-map.js';
4
+ import { LitElement, html, css } from 'lit';
5
+ import { iconCheck } from '@umbraco-ui/uui-icon-registry-essential/lib/svgs';
6
+ import { styleMap } from 'lit/directives/style-map.js';
7
+ import { LabelMixin, SelectableMixin, ActiveMixin } from '@umbraco-ui/uui-base/lib/mixins';
8
+
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
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __decorateClass = (decorators, target, key, kind) => {
14
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
15
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
16
+ if (decorator = decorators[i])
17
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
18
+ if (kind && result)
19
+ __defProp(target, key, result);
20
+ return result;
21
+ };
22
+ let UUIColorSwatchElement = class extends LabelMixin(
23
+ "label",
24
+ SelectableMixin(ActiveMixin(LitElement))
25
+ ) {
26
+ constructor() {
27
+ super();
28
+ this._value = "";
29
+ this.disabled = false;
30
+ this.showLabel = false;
31
+ this._color = null;
32
+ this.addEventListener("click", this._setAriaAttributes);
33
+ }
34
+ get value() {
35
+ var _a;
36
+ return this._value ? this._value : ((_a = this.textContent) == null ? void 0 : _a.trim()) || "";
37
+ }
38
+ set value(newValue) {
39
+ const oldValue = this._value;
40
+ this._value = newValue;
41
+ this.requestUpdate("value", oldValue);
42
+ }
43
+ get color() {
44
+ return this._color;
45
+ }
46
+ set color(_) {
47
+ return;
48
+ }
49
+ get isLight() {
50
+ var _a, _b;
51
+ return (_b = (_a = this.color) == null ? void 0 : _a.isLight()) != null ? _b : false;
52
+ }
53
+ _initializeColor() {
54
+ var _a;
55
+ this._color = new j((_a = this.value) != null ? _a : "");
56
+ if (!this._color.isValid()) {
57
+ this.disabled = true;
58
+ console.error(
59
+ `Invalid color provided to uui-color-swatch: ${this.value}`
60
+ );
61
+ }
62
+ }
63
+ _setAriaAttributes() {
64
+ if (this.selectable)
65
+ this.setAttribute("aria-checked", this.selected.toString());
66
+ }
67
+ firstUpdated() {
68
+ this._initializeColor();
69
+ this._setAriaAttributes();
70
+ }
71
+ willUpdate(changedProperties) {
72
+ if (changedProperties.has("value")) {
73
+ this._initializeColor();
74
+ }
75
+ if (changedProperties.has("disabled")) {
76
+ if (this.selectable) {
77
+ this.selectable = !this.disabled;
78
+ this.unselectable = !this.disabled;
79
+ }
80
+ }
81
+ if (changedProperties.has("selectable") || changedProperties.has("selected")) {
82
+ this._setAriaAttributes();
83
+ }
84
+ }
85
+ render() {
86
+ return html`
87
+ <div
88
+ class=${classMap({
89
+ "color-swatch": true,
90
+ "color-swatch--transparent-bg": true,
91
+ "color-swatch--light": this.isLight
92
+ })}
93
+ role="button"
94
+ aria-label=${this.label}
95
+ aria-disabled="${this.disabled}">
96
+ <div
97
+ class="color-swatch__color"
98
+ style=${styleMap({ backgroundColor: this.value })}></div>
99
+ <div class="color-swatch__check">${iconCheck}</div>
100
+ </div>
101
+ ${this.showLabel ? this.renderLabel() : ""}
102
+ `;
103
+ }
104
+ };
105
+ UUIColorSwatchElement.styles = [
106
+ css`
107
+ :host {
108
+ position: relative;
109
+ display: inline-flex;
110
+ align-items: center;
111
+ justify-content: center;
112
+ box-sizing: border-box;
113
+ transition: box-shadow 100ms ease-out;
114
+ flex-direction: column;
115
+ }
116
+
117
+ :host(*),
118
+ * {
119
+ /* TODO: implement globally shared outline style */
120
+ outline-color: var(--uui-color-focus,#3879ff);
121
+ outline-offset: 4px;
122
+ }
123
+
124
+ :host(:focus-within:not([disabled])) {
125
+ outline: none;
126
+ }
127
+
128
+ :host(:focus:not([disabled])) .color-swatch {
129
+ outline-color: var(--uui-color-focus,#3879ff);
130
+ outline-width: var(--uui-swatch-border-width, 1px);
131
+ outline-style: solid;
132
+ outline-offset: var(--uui-swatch-border-width, 1px);
133
+ }
134
+
135
+ :host([selectable]) {
136
+ cursor: pointer;
137
+ }
138
+
139
+ :host([disabled]) {
140
+ cursor: not-allowed;
141
+ }
142
+
143
+ :host([selectable]) .color-swatch::after {
144
+ content: '';
145
+ position: absolute;
146
+ pointer-events: none;
147
+ inset: calc(var(--uui-swatch-border-width, 1px) * -1);
148
+ width: calc(100% + calc(var(--uui-swatch-border-width, 1px) * 2));
149
+ height: calc(100% + calc(var(--uui-swatch-border-width, 1px) * 2));
150
+ box-sizing: border-box;
151
+ border: var(--uui-swatch-border-width, 1px) solid
152
+ var(--uui-color-selected,#3544b1);
153
+ border-radius: calc(
154
+ var(--uui-border-radius,3px) + var(--uui-swatch-border-width, 1px)
155
+ );
156
+ transition: opacity 100ms ease-out;
157
+ opacity: 0;
158
+ }
159
+ :host([selectable]:not([disabled]):hover) .color-swatch::after {
160
+ opacity: 0.33;
161
+ }
162
+ :host([selectable][selected]:not([disabled]):hover) .color-swatch::after {
163
+ opacity: 0.66;
164
+ }
165
+ :host([selectable][selected]:not([disabled])) .color-swatch::after {
166
+ opacity: 1;
167
+ }
168
+
169
+ .color-swatch {
170
+ position: relative;
171
+ width: var(--uui-swatch-size, 25px);
172
+ height: var(--uui-swatch-size, 25px);
173
+ border-radius: 3px;
174
+ display: flex;
175
+ justify-content: center;
176
+ align-items: center;
177
+ }
178
+ .color-swatch--transparent-bg {
179
+ background-image: linear-gradient(
180
+ 45deg,
181
+ var(--uui-palette-grey,#c4c4c4) 25%,
182
+ transparent 25%
183
+ ),
184
+ linear-gradient(45deg, transparent 75%, var(--uui-palette-grey,#c4c4c4) 75%),
185
+ linear-gradient(45deg, transparent 75%, var(--uui-palette-grey,#c4c4c4) 75%),
186
+ linear-gradient(45deg, var(--uui-palette-grey,#c4c4c4) 25%, transparent 25%);
187
+ background-size: 10px 10px;
188
+ background-position: 0 0, 0 0, -5px -5px, 5px 5px;
189
+ }
190
+ .color-swatch__color {
191
+ width: 100%;
192
+ height: 100%;
193
+ border: 1px solid rgba(0, 0, 0, 0.125);
194
+ border-radius: inherit;
195
+ box-sizing: border-box;
196
+ }
197
+
198
+ .color-swatch__check {
199
+ position: absolute;
200
+ vertical-align: middle;
201
+ width: calc(var(--uui-swatch-size, 25px) / 2);
202
+ height: calc(var(--uui-swatch-size, 25px) / 2);
203
+ line-height: 0;
204
+ transition: fill 120ms, opacity 120ms;
205
+ fill: #fff;
206
+ pointer-events: none;
207
+ opacity: 0;
208
+ }
209
+
210
+ .color-swatch--light .color-swatch__check {
211
+ fill: #000;
212
+ }
213
+
214
+ :host([selected]) .color-swatch__check {
215
+ opacity: 1;
216
+ }
217
+
218
+ slot[name='label']::slotted(*),
219
+ .label {
220
+ font-size: var(--uui-size-4,12px);
221
+ }
222
+ `
223
+ ];
224
+ __decorateClass([
225
+ property({ type: String })
226
+ ], UUIColorSwatchElement.prototype, "value", 1);
227
+ __decorateClass([
228
+ property({ type: Boolean, reflect: true })
229
+ ], UUIColorSwatchElement.prototype, "disabled", 2);
230
+ __decorateClass([
231
+ property({ type: Boolean, attribute: "show-label" })
232
+ ], UUIColorSwatchElement.prototype, "showLabel", 2);
233
+ UUIColorSwatchElement = __decorateClass([
234
+ defineElement("uui-color-swatch")
235
+ ], UUIColorSwatchElement);
236
+
237
+ export { UUIColorSwatchElement };
@@ -0,0 +1,64 @@
1
+ import { Colord } from 'colord';
2
+ import { LitElement } from 'lit';
3
+ 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
+ /**
5
+ * Color swatch, can have label and be selectable. Depends on colord library and exposes it's utility functions under color property.
6
+ *
7
+ * @element uui-color-swatch
8
+ * @cssprop --uui-swatch-size - The size of the swatch.
9
+ * @cssprop --uui-swatch-border-width - The width of the border.
10
+ * @slot label - Default slot for the label.
11
+ */
12
+ export declare class UUIColorSwatchElement extends UUIColorSwatchElement_base {
13
+ static styles: import("lit").CSSResult[];
14
+ private _value;
15
+ /**
16
+ * 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.
17
+ * @type { string }
18
+ * @attr
19
+ * @default ""
20
+ */
21
+ get value(): string;
22
+ set value(newValue: string);
23
+ /**
24
+ * Determines if the options is disabled. If true the option can't be selected
25
+ * @type { boolean }
26
+ * @attr
27
+ * @default false
28
+ */
29
+ disabled: boolean;
30
+ /**
31
+ * When true shows element label below the color checkbox
32
+ *
33
+ * @memberof UUIColorSwatchElement
34
+ */
35
+ showLabel: boolean;
36
+ /**
37
+ * 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/)
38
+ *
39
+ * @type {(Colord | null)}
40
+ * @memberof UUIColorSwatchElement
41
+ */
42
+ get color(): Colord | null;
43
+ set color(_: Colord | null);
44
+ private _color;
45
+ /**
46
+ * Returns true if the color brightness is >= 0.5
47
+ *
48
+ * @readonly
49
+ * @memberof UUIColorSwatchElement
50
+ */
51
+ get isLight(): boolean;
52
+ constructor();
53
+ private _initializeColor;
54
+ private _setAriaAttributes;
55
+ firstUpdated(): void;
56
+ willUpdate(changedProperties: Map<string, any>): void;
57
+ render(): import("lit-html").TemplateResult<1>;
58
+ }
59
+ declare global {
60
+ interface HTMLElementTagNameMap {
61
+ 'uui-color-swatch': UUIColorSwatchElement;
62
+ }
63
+ }
64
+ export {};
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@umbraco-ui/uui-color-swatch",
3
+ "version": "1.2.0-rc.0",
4
+ "license": "MIT",
5
+ "keywords": [
6
+ "Umbraco",
7
+ "Custom elements",
8
+ "Web components",
9
+ "UI",
10
+ "Lit",
11
+ "Color Swatch"
12
+ ],
13
+ "description": "Umbraco UI color-swatch component",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/umbraco/Umbraco.UI.git",
17
+ "directory": "packages/uui-color-swatch"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/umbraco/Umbraco.UI/issues"
21
+ },
22
+ "main": "./lib/index.js",
23
+ "module": "./lib/index.js",
24
+ "types": "./lib/index.d.ts",
25
+ "type": "module",
26
+ "customElements": "custom-elements.json",
27
+ "files": [
28
+ "lib/**/*.d.ts",
29
+ "lib/**/*.js",
30
+ "custom-elements.json"
31
+ ],
32
+ "dependencies": {
33
+ "@umbraco-ui/uui-base": "1.2.0-rc.0",
34
+ "@umbraco-ui/uui-icon-registry-essential": "1.2.0-rc.0",
35
+ "colord": "^2.9.3"
36
+ },
37
+ "scripts": {
38
+ "build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js",
39
+ "clean": "tsc --build --clean && rimraf dist lib/*.js lib/**/*.js custom-elements.json",
40
+ "analyze": "web-component-analyzer **/*.element.ts --outFile custom-elements.json"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "homepage": "https://uui.umbraco.com/?path=/story/uui-color-swatch",
46
+ "gitHead": "43f1b9a8bd1721af30ba7c145517ee665d874df3"
47
+ }