@umbraco-ui/uui-color-picker 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 +21 -0
- package/README.md +31 -0
- package/custom-elements.json +170 -0
- package/lib/UUIColorPickerEvents.d.ts +5 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +574 -0
- package/lib/uui-color-picker.element.d.ts +126 -0
- package/package.json +46 -0
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-picker
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Umbraco style color-picker component.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
### ES imports
|
|
10
|
+
|
|
11
|
+
```zsh
|
|
12
|
+
npm i @umbraco-ui/uui-color-picker
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Import the registration of `<uui-color-picker>` via:
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import '@umbraco-ui/uui-color-picker';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
When looking to leverage the `UUIColorPickerElement` base class as a type and/or for extension purposes, do so via:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
import { UUIColorPickerElement } from '@umbraco-ui/uui-color-picker';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```html
|
|
30
|
+
<uui-color-picker></uui-color-picker>
|
|
31
|
+
```
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "experimental",
|
|
3
|
+
"tags": [
|
|
4
|
+
{
|
|
5
|
+
"name": "uui-color-picker",
|
|
6
|
+
"path": "./lib/uui-color-picker.element.ts",
|
|
7
|
+
"attributes": [
|
|
8
|
+
{
|
|
9
|
+
"name": "value",
|
|
10
|
+
"description": "The current color.",
|
|
11
|
+
"type": "string",
|
|
12
|
+
"default": "\"''\""
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "format",
|
|
16
|
+
"description": "The format to use for the display value. If opacity is enabled, these will translate to HEXA, RGBA, and HSLA\nrespectively. The color picker will always accept user input in any format (including CSS color names) and convert\nit to the desired format.",
|
|
17
|
+
"type": "UUIColorPickerFormat",
|
|
18
|
+
"default": "\"'hex'\""
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "name",
|
|
22
|
+
"description": "The input's name attribute.",
|
|
23
|
+
"type": "string",
|
|
24
|
+
"default": "\"''\""
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "size",
|
|
28
|
+
"description": "Determines the size of the color picker's trigger. This has no effect on inline color pickers.",
|
|
29
|
+
"type": "UUIColorPickerSize",
|
|
30
|
+
"default": "\"'medium'\""
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "no-format-toggle",
|
|
34
|
+
"description": "Removes the format toggle.",
|
|
35
|
+
"type": "boolean",
|
|
36
|
+
"default": "\"false\""
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "inline",
|
|
40
|
+
"description": "Renders the color picker inline rather than inside a dropdown.",
|
|
41
|
+
"type": "boolean",
|
|
42
|
+
"default": "\"false\""
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "disabled",
|
|
46
|
+
"description": "Disables the color picker.",
|
|
47
|
+
"type": "boolean",
|
|
48
|
+
"default": "\"false\""
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "opacity",
|
|
52
|
+
"description": "Whether to show the opacity slider.",
|
|
53
|
+
"type": "boolean",
|
|
54
|
+
"default": "\"false\""
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "uppercase",
|
|
58
|
+
"description": "By default, the value will be set in lowercase. Set this to true to set it in uppercase instead.",
|
|
59
|
+
"type": "boolean",
|
|
60
|
+
"default": "\"false\""
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "label",
|
|
64
|
+
"description": "Label to be used for aria-label and potentially as visual label for some components",
|
|
65
|
+
"type": "string"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"properties": [
|
|
69
|
+
{
|
|
70
|
+
"name": "styles",
|
|
71
|
+
"type": "CSSResult[]",
|
|
72
|
+
"default": "[null]"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"name": "value",
|
|
76
|
+
"attribute": "value",
|
|
77
|
+
"description": "The current color.",
|
|
78
|
+
"type": "string",
|
|
79
|
+
"default": "\"''\""
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "format",
|
|
83
|
+
"attribute": "format",
|
|
84
|
+
"description": "The format to use for the display value. If opacity is enabled, these will translate to HEXA, RGBA, and HSLA\nrespectively. The color picker will always accept user input in any format (including CSS color names) and convert\nit to the desired format.",
|
|
85
|
+
"type": "UUIColorPickerFormat",
|
|
86
|
+
"default": "\"'hex'\""
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"name": "name",
|
|
90
|
+
"attribute": "name",
|
|
91
|
+
"description": "The input's name attribute.",
|
|
92
|
+
"type": "string",
|
|
93
|
+
"default": "\"''\""
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"name": "size",
|
|
97
|
+
"attribute": "size",
|
|
98
|
+
"description": "Determines the size of the color picker's trigger. This has no effect on inline color pickers.",
|
|
99
|
+
"type": "UUIColorPickerSize",
|
|
100
|
+
"default": "\"'medium'\""
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "noFormatToggle",
|
|
104
|
+
"attribute": "no-format-toggle",
|
|
105
|
+
"description": "Removes the format toggle.",
|
|
106
|
+
"type": "boolean",
|
|
107
|
+
"default": "\"false\""
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"name": "inline",
|
|
111
|
+
"attribute": "inline",
|
|
112
|
+
"description": "Renders the color picker inline rather than inside a dropdown.",
|
|
113
|
+
"type": "boolean",
|
|
114
|
+
"default": "\"false\""
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"name": "disabled",
|
|
118
|
+
"attribute": "disabled",
|
|
119
|
+
"description": "Disables the color picker.",
|
|
120
|
+
"type": "boolean",
|
|
121
|
+
"default": "\"false\""
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"name": "opacity",
|
|
125
|
+
"attribute": "opacity",
|
|
126
|
+
"description": "Whether to show the opacity slider.",
|
|
127
|
+
"type": "boolean",
|
|
128
|
+
"default": "\"false\""
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"name": "uppercase",
|
|
132
|
+
"attribute": "uppercase",
|
|
133
|
+
"description": "By default, the value will be set in lowercase. Set this to true to set it in uppercase instead.",
|
|
134
|
+
"type": "boolean",
|
|
135
|
+
"default": "\"false\""
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"name": "swatches",
|
|
139
|
+
"description": "An array of predefined color swatches to display. Can include any format the color picker can parse, including\nHEX(A), RGB(A), HSL(A), and CSS color names.",
|
|
140
|
+
"type": "string[]",
|
|
141
|
+
"default": "[\"#d0021b\",\"#f5a623\",\"#f8e71c\",\"#8b572a\",\"#7ed321\",\"#417505\",\"#bd10e0\",\"#9013fe\",\"#4a90e2\",\"#50e3c2\",\"#b8e986\",\"#000\",\"#444\",\"#888\",\"#ccc\",\"#fff\"]"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"name": "label",
|
|
145
|
+
"attribute": "label",
|
|
146
|
+
"description": "Label to be used for aria-label and potentially as visual label for some components",
|
|
147
|
+
"type": "string"
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
"events": [
|
|
151
|
+
{
|
|
152
|
+
"name": "change",
|
|
153
|
+
"description": "Fired when the color changes"
|
|
154
|
+
}
|
|
155
|
+
],
|
|
156
|
+
"slots": [
|
|
157
|
+
{
|
|
158
|
+
"name": "",
|
|
159
|
+
"description": "Override the default label"
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
"cssProperties": [
|
|
163
|
+
{
|
|
164
|
+
"name": "--uui-color-picker-width",
|
|
165
|
+
"description": "The width of the color picker"
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
|
|
3
|
+
import { query, state, property } from 'lit/decorators.js';
|
|
4
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
5
|
+
import { live } from 'lit/directives/live.js';
|
|
6
|
+
import { demandCustomElement, clamp } from '@umbraco-ui/uui-base/lib/utils';
|
|
7
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
8
|
+
import { UUIEvent } from '@umbraco-ui/uui-base/lib/events';
|
|
9
|
+
import { LabelMixin } from '@umbraco-ui/uui-base/lib/mixins';
|
|
10
|
+
|
|
11
|
+
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)},S=[],k=function(r){r.forEach(function(r){S.indexOf(r)<0&&(r(j,y),S.push(r));});};
|
|
12
|
+
|
|
13
|
+
function namesPlugin(e,f){var a={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},r={};for(var d in a)r[a[d]]=d;var l={};e.prototype.toName=function(f){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return "transparent";var d,i,n=r[this.toHex()];if(n)return n;if(null==f?void 0:f.closest){var o=this.toRgb(),t=1/0,b="black";if(!l.length)for(var c in a)l[c]=new e(a[c]).toRgb();for(var g in a){var u=(d=o,i=l[g],Math.pow(d.r-i.r,2)+Math.pow(d.g-i.g,2)+Math.pow(d.b-i.b,2));u<t&&(t=u,b=g);}return b}};f.string.push([function(f){var r=f.toLowerCase(),d="transparent"===r?"#0000":a[r];return d?new e(d).toRgb():null},"name"]);}
|
|
14
|
+
|
|
15
|
+
class UUIColorPickerChangeEvent extends UUIEvent {
|
|
16
|
+
}
|
|
17
|
+
UUIColorPickerChangeEvent.CHANGE = "change";
|
|
18
|
+
|
|
19
|
+
var __defProp = Object.defineProperty;
|
|
20
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
21
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
22
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
23
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
24
|
+
if (decorator = decorators[i])
|
|
25
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
26
|
+
if (kind && result)
|
|
27
|
+
__defProp(target, key, result);
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
k([namesPlugin]);
|
|
31
|
+
const hasEyeDropper = "EyeDropper" in window;
|
|
32
|
+
let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
|
|
33
|
+
constructor() {
|
|
34
|
+
super(...arguments);
|
|
35
|
+
this.inputValue = "";
|
|
36
|
+
this.hue = 0;
|
|
37
|
+
this.saturation = 0;
|
|
38
|
+
this.lightness = 0;
|
|
39
|
+
this.alpha = 100;
|
|
40
|
+
this._colord = w("hsl(0, 0%, 0%)");
|
|
41
|
+
this.value = "";
|
|
42
|
+
this.format = "hex";
|
|
43
|
+
this.name = "";
|
|
44
|
+
this.size = "medium";
|
|
45
|
+
this.noFormatToggle = false;
|
|
46
|
+
this.inline = false;
|
|
47
|
+
this.disabled = false;
|
|
48
|
+
this.opacity = false;
|
|
49
|
+
this.uppercase = false;
|
|
50
|
+
this.swatches = [
|
|
51
|
+
"#d0021b",
|
|
52
|
+
"#f5a623",
|
|
53
|
+
"#f8e71c",
|
|
54
|
+
"#8b572a",
|
|
55
|
+
"#7ed321",
|
|
56
|
+
"#417505",
|
|
57
|
+
"#bd10e0",
|
|
58
|
+
"#9013fe",
|
|
59
|
+
"#4a90e2",
|
|
60
|
+
"#50e3c2",
|
|
61
|
+
"#b8e986",
|
|
62
|
+
"#000",
|
|
63
|
+
"#444",
|
|
64
|
+
"#888",
|
|
65
|
+
"#ccc",
|
|
66
|
+
"#fff"
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
connectedCallback() {
|
|
70
|
+
super.connectedCallback();
|
|
71
|
+
if (this.value) {
|
|
72
|
+
this.setColor(this.value);
|
|
73
|
+
} else {
|
|
74
|
+
this.setColor("#000");
|
|
75
|
+
}
|
|
76
|
+
demandCustomElement(this, "uui-icon");
|
|
77
|
+
demandCustomElement(this, "uui-icon-registry-essential");
|
|
78
|
+
demandCustomElement(this, "uui-input");
|
|
79
|
+
demandCustomElement(this, "uui-button");
|
|
80
|
+
demandCustomElement(this, "uui-button-group");
|
|
81
|
+
demandCustomElement(this, "uui-popover");
|
|
82
|
+
demandCustomElement(this, "uui-color-swatches");
|
|
83
|
+
demandCustomElement(this, "uui-color-swatch");
|
|
84
|
+
demandCustomElement(this, "uui-color-area");
|
|
85
|
+
demandCustomElement(this, "uui-color-slider");
|
|
86
|
+
}
|
|
87
|
+
getFormattedValue(format) {
|
|
88
|
+
const formatToUse = this.opacity ? `${format}a` : format;
|
|
89
|
+
const { h, l, s } = this._colord.toHsl();
|
|
90
|
+
const { r, g, b } = this._colord.toRgb();
|
|
91
|
+
const hexa = this.setLetterCase(this._colord.toHex());
|
|
92
|
+
const hex = this.setLetterCase(
|
|
93
|
+
hexa.length > 7 ? hexa.substring(0, hexa.length - 2) : hexa
|
|
94
|
+
);
|
|
95
|
+
switch (formatToUse) {
|
|
96
|
+
case "hex":
|
|
97
|
+
return hex;
|
|
98
|
+
case "hexa":
|
|
99
|
+
return hexa;
|
|
100
|
+
case "rgb":
|
|
101
|
+
return `rgb(${r} ${g} ${b})`;
|
|
102
|
+
case "rgba":
|
|
103
|
+
return this._colord.toRgbString();
|
|
104
|
+
case "hsl":
|
|
105
|
+
return `hsl(${h} ${s} ${l})`;
|
|
106
|
+
case "hsla":
|
|
107
|
+
return this._colord.toHslString();
|
|
108
|
+
default:
|
|
109
|
+
return "";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
getBrightness(lightness) {
|
|
113
|
+
return clamp(-1 * (200 * lightness / (this.saturation - 200)), 0, 100);
|
|
114
|
+
}
|
|
115
|
+
getLightness(brightness) {
|
|
116
|
+
return clamp(
|
|
117
|
+
(200 - this.saturation) * brightness / 100 * 5 / 10,
|
|
118
|
+
0,
|
|
119
|
+
100
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
handleFormatToggle() {
|
|
123
|
+
const formats = ["hex", "rgb", "hsl"];
|
|
124
|
+
const nextIndex = (formats.indexOf(this.format) + 1) % formats.length;
|
|
125
|
+
this.format = formats[nextIndex];
|
|
126
|
+
this._syncValues();
|
|
127
|
+
}
|
|
128
|
+
handleAlphaChange(event) {
|
|
129
|
+
var _a;
|
|
130
|
+
event.stopPropagation();
|
|
131
|
+
(_a = this._swatches) == null ? void 0 : _a.resetSelection();
|
|
132
|
+
const element = event.target;
|
|
133
|
+
const newColor = {
|
|
134
|
+
h: this.hue,
|
|
135
|
+
s: this.saturation,
|
|
136
|
+
l: this.lightness,
|
|
137
|
+
a: Math.round(element.value) / 100
|
|
138
|
+
};
|
|
139
|
+
this.setColor(newColor);
|
|
140
|
+
}
|
|
141
|
+
handleHueChange(event) {
|
|
142
|
+
var _a;
|
|
143
|
+
event.stopPropagation();
|
|
144
|
+
(_a = this._swatches) == null ? void 0 : _a.resetSelection();
|
|
145
|
+
const element = event.target;
|
|
146
|
+
const newColor = {
|
|
147
|
+
h: element.value,
|
|
148
|
+
s: this.saturation,
|
|
149
|
+
l: this.lightness,
|
|
150
|
+
a: this.alpha / 100
|
|
151
|
+
};
|
|
152
|
+
this.setColor(newColor);
|
|
153
|
+
}
|
|
154
|
+
handleGridChange(event) {
|
|
155
|
+
var _a;
|
|
156
|
+
event.stopPropagation();
|
|
157
|
+
(_a = this._swatches) == null ? void 0 : _a.resetSelection();
|
|
158
|
+
const element = event.target;
|
|
159
|
+
const newColor = {
|
|
160
|
+
h: this.hue,
|
|
161
|
+
s: element.saturation,
|
|
162
|
+
l: element.lightness,
|
|
163
|
+
a: this.alpha / 100
|
|
164
|
+
};
|
|
165
|
+
this.setColor(newColor);
|
|
166
|
+
}
|
|
167
|
+
handleInputChange(event) {
|
|
168
|
+
var _a;
|
|
169
|
+
(_a = this._swatches) == null ? void 0 : _a.resetSelection();
|
|
170
|
+
const target = event.target;
|
|
171
|
+
if (target.value) {
|
|
172
|
+
this.setColor(target.value);
|
|
173
|
+
target.value = this.value;
|
|
174
|
+
} else {
|
|
175
|
+
this.setColor("#000");
|
|
176
|
+
}
|
|
177
|
+
event.stopPropagation();
|
|
178
|
+
}
|
|
179
|
+
handleInputKeyDown(event) {
|
|
180
|
+
var _a;
|
|
181
|
+
if (event.key === "Enter") {
|
|
182
|
+
if (this.inputValue) {
|
|
183
|
+
this.setColor(this.inputValue);
|
|
184
|
+
(_a = this._swatches) == null ? void 0 : _a.resetSelection();
|
|
185
|
+
this.inputValue = this.value;
|
|
186
|
+
setTimeout(() => this._input.select());
|
|
187
|
+
} else {
|
|
188
|
+
this.setColor("#000");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
handleColorSwatchChange(event) {
|
|
193
|
+
event.stopImmediatePropagation();
|
|
194
|
+
const target = event.target;
|
|
195
|
+
if (target.value) {
|
|
196
|
+
this.setColor(target.value);
|
|
197
|
+
} else {
|
|
198
|
+
this.setColor("#000");
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
handleCopy() {
|
|
202
|
+
navigator.clipboard.writeText(this._input.value).then(() => {
|
|
203
|
+
this._previewButton.classList.add("color-picker__preview-color--copied");
|
|
204
|
+
this._previewButton.addEventListener("animationend", () => {
|
|
205
|
+
this._previewButton.classList.remove(
|
|
206
|
+
"color-picker__preview-color--copied"
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
openColorPicker(event) {
|
|
212
|
+
event.stopImmediatePropagation();
|
|
213
|
+
const target = event.target;
|
|
214
|
+
const popover = target.nextElementSibling;
|
|
215
|
+
popover.open = !(popover == null ? void 0 : popover.open);
|
|
216
|
+
target.setAttribute("aria-expanded", popover.open.toString());
|
|
217
|
+
}
|
|
218
|
+
closeColorPicker(event) {
|
|
219
|
+
const target = event.target;
|
|
220
|
+
const trigger = target.previousElementSibling;
|
|
221
|
+
if (trigger) {
|
|
222
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
handleEyeDropper() {
|
|
226
|
+
if (!hasEyeDropper) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const eyeDropper = new EyeDropper();
|
|
230
|
+
eyeDropper.open().then((result) => this.setColor(result.sRGBHex)).catch(() => {
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
setColor(colorString) {
|
|
234
|
+
this._colord = new j(colorString);
|
|
235
|
+
const { h, l, s, a } = this._colord.toHsl();
|
|
236
|
+
this.hue = h;
|
|
237
|
+
this.saturation = s;
|
|
238
|
+
this.lightness = l;
|
|
239
|
+
this.alpha = this.opacity ? a * 100 : 100;
|
|
240
|
+
this._syncValues();
|
|
241
|
+
this.dispatchEvent(
|
|
242
|
+
new UUIColorPickerChangeEvent(UUIColorPickerChangeEvent.CHANGE)
|
|
243
|
+
);
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
setLetterCase(string) {
|
|
247
|
+
if (typeof string !== "string") {
|
|
248
|
+
return "";
|
|
249
|
+
}
|
|
250
|
+
return this.uppercase ? string.toUpperCase() : string.toLowerCase();
|
|
251
|
+
}
|
|
252
|
+
_syncValues() {
|
|
253
|
+
this.inputValue = this.getFormattedValue(this.format);
|
|
254
|
+
this.value = this.inputValue;
|
|
255
|
+
}
|
|
256
|
+
_renderColorPicker() {
|
|
257
|
+
return html`
|
|
258
|
+
<div
|
|
259
|
+
class=${classMap({
|
|
260
|
+
"color-picker": true,
|
|
261
|
+
"color-picker--inline": this.inline,
|
|
262
|
+
"color-picker--disabled": this.disabled
|
|
263
|
+
})}
|
|
264
|
+
aria-disabled=${this.disabled ? "true" : "false"}>
|
|
265
|
+
<uui-color-area .value="${this.value}" @change=${this.handleGridChange}>
|
|
266
|
+
</uui-color-area>
|
|
267
|
+
<div class="color-picker__controls">
|
|
268
|
+
<div class="color-picker__sliders">
|
|
269
|
+
<uui-color-slider
|
|
270
|
+
label="hue"
|
|
271
|
+
class="hue-slider"
|
|
272
|
+
.value=${Math.round(this.hue)}
|
|
273
|
+
@change=${this.handleHueChange}>
|
|
274
|
+
</uui-color-slider>
|
|
275
|
+
${this.opacity ? html`
|
|
276
|
+
<uui-color-slider
|
|
277
|
+
label="alpha"
|
|
278
|
+
class="opacity-slider"
|
|
279
|
+
.value=${Math.round(this.alpha)}
|
|
280
|
+
type="opacity"
|
|
281
|
+
.color=${this.value}
|
|
282
|
+
@change=${this.handleAlphaChange}>
|
|
283
|
+
</uui-color-slider>
|
|
284
|
+
` : ""}
|
|
285
|
+
</div>
|
|
286
|
+
<button
|
|
287
|
+
type="button"
|
|
288
|
+
part="preview"
|
|
289
|
+
class="color-picker__preview color-picker__transparent-bg"
|
|
290
|
+
title="Copy"
|
|
291
|
+
aria-label="Copy"
|
|
292
|
+
style=${styleMap({
|
|
293
|
+
"--preview-color": `hsla(${this.hue}deg, ${this.saturation}%, ${this.lightness}%, ${this.alpha / 100})`
|
|
294
|
+
})}
|
|
295
|
+
@click=${this.handleCopy}></button>
|
|
296
|
+
</div>
|
|
297
|
+
<div class="color-picker__user-input" aria-live="polite">
|
|
298
|
+
<uui-input
|
|
299
|
+
label="label"
|
|
300
|
+
type="text"
|
|
301
|
+
part="input"
|
|
302
|
+
name=${this.name}
|
|
303
|
+
autocomplete="off"
|
|
304
|
+
autocapitalize="off"
|
|
305
|
+
spellcheck="false"
|
|
306
|
+
.value=${live(this.inputValue)}
|
|
307
|
+
?disabled=${this.disabled}
|
|
308
|
+
@keydown=${this.handleInputKeyDown}
|
|
309
|
+
@change=${this.handleInputChange}>
|
|
310
|
+
</uui-input>
|
|
311
|
+
<uui-button-group>
|
|
312
|
+
${!this.noFormatToggle ? html`
|
|
313
|
+
<uui-button
|
|
314
|
+
label="Toggle color format"
|
|
315
|
+
@click=${this.handleFormatToggle}
|
|
316
|
+
class="color-picker__toggle-format"
|
|
317
|
+
compact>
|
|
318
|
+
<span>${this.format}</span>
|
|
319
|
+
</uui-button>
|
|
320
|
+
` : ""}
|
|
321
|
+
${hasEyeDropper ? html` <uui-button
|
|
322
|
+
label="Select a color"
|
|
323
|
+
compact
|
|
324
|
+
@click=${this.handleEyeDropper}>
|
|
325
|
+
<uui-icon-registry-essential>
|
|
326
|
+
<uui-icon name="colorpicker"></uui-icon>
|
|
327
|
+
</uui-icon-registry-essential>
|
|
328
|
+
</uui-button>` : ""}
|
|
329
|
+
</uui-button-group>
|
|
330
|
+
</div>
|
|
331
|
+
<uui-color-swatches
|
|
332
|
+
id="swatches"
|
|
333
|
+
class="color-picker__swatches"
|
|
334
|
+
@change=${this.handleColorSwatchChange}>
|
|
335
|
+
${this.swatches.map(
|
|
336
|
+
(swatch) => html`<uui-color-swatch
|
|
337
|
+
label="${swatch}"
|
|
338
|
+
.value=${swatch}></uui-color-swatch>`
|
|
339
|
+
)}
|
|
340
|
+
</uui-color-swatches>
|
|
341
|
+
</div>
|
|
342
|
+
`;
|
|
343
|
+
}
|
|
344
|
+
_renderPreviewButton() {
|
|
345
|
+
return html`<button
|
|
346
|
+
type="button"
|
|
347
|
+
slot="trigger"
|
|
348
|
+
aria-label="${this.label || "Open Color picker"}"
|
|
349
|
+
class=${classMap({
|
|
350
|
+
"color-picker__trigger": true,
|
|
351
|
+
"color-dropdown__trigger--disabled": this.disabled,
|
|
352
|
+
"color-dropdown__trigger--small": this.size === "small",
|
|
353
|
+
"color-dropdown__trigger--medium": this.size === "medium",
|
|
354
|
+
"color-dropdown__trigger--large": this.size === "large",
|
|
355
|
+
"color-picker__transparent-bg": true
|
|
356
|
+
})}
|
|
357
|
+
style=${styleMap({
|
|
358
|
+
"--preview-color": `hsla(${this.hue}deg, ${this.saturation}%, ${this.lightness}%, ${this.alpha / 100})`
|
|
359
|
+
})}
|
|
360
|
+
@click=${this.openColorPicker}
|
|
361
|
+
aria-haspopup="true"
|
|
362
|
+
aria-expanded="false"></button>
|
|
363
|
+
<uui-popover placement="bottom-start" @close=${this.closeColorPicker}>
|
|
364
|
+
<div slot="popover">${this._renderColorPicker()}</div>
|
|
365
|
+
</uui-popover>`;
|
|
366
|
+
}
|
|
367
|
+
render() {
|
|
368
|
+
return this.inline ? this._renderColorPicker() : this._renderPreviewButton();
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
UUIColorPickerElement.styles = [
|
|
372
|
+
css`
|
|
373
|
+
:host {
|
|
374
|
+
--uui-look-outline-border: #ddd;
|
|
375
|
+
--uui-look-outline-border-hover: #aaa;
|
|
376
|
+
font-size: 0.8rem;
|
|
377
|
+
display: block;
|
|
378
|
+
width: var(--uui-color-picker-width, 280px);
|
|
379
|
+
}
|
|
380
|
+
.color-picker {
|
|
381
|
+
width: 100%;
|
|
382
|
+
background-color: #fff;
|
|
383
|
+
user-select: none;
|
|
384
|
+
border: solid 1px #e4e4e7;
|
|
385
|
+
}
|
|
386
|
+
.color-picker__user-input {
|
|
387
|
+
display: flex;
|
|
388
|
+
padding: 0 0.75rem 0.75rem 0.75rem;
|
|
389
|
+
}
|
|
390
|
+
.color-picker__user-input uui-button {
|
|
391
|
+
border: var(--uui-input-border-width, 1px) solid
|
|
392
|
+
var(--uui-input-border-color, var(--uui-color-border,#d8d7d9));
|
|
393
|
+
border-left: none;
|
|
394
|
+
}
|
|
395
|
+
.color-picker__preview,
|
|
396
|
+
.color-picker__trigger {
|
|
397
|
+
flex: 0 0 auto;
|
|
398
|
+
display: inline-flex;
|
|
399
|
+
align-items: center;
|
|
400
|
+
justify-content: center;
|
|
401
|
+
position: relative;
|
|
402
|
+
width: 2.25rem;
|
|
403
|
+
height: 2.25rem;
|
|
404
|
+
border: none;
|
|
405
|
+
border-radius: 50%;
|
|
406
|
+
background: none;
|
|
407
|
+
}
|
|
408
|
+
.color-picker__preview {
|
|
409
|
+
cursor: copy;
|
|
410
|
+
margin-left: 0.75rem;
|
|
411
|
+
border-radius: 50%;
|
|
412
|
+
}
|
|
413
|
+
color-picker__trigger {
|
|
414
|
+
cursor: pointer;
|
|
415
|
+
}
|
|
416
|
+
.color-picker__preview::before,
|
|
417
|
+
.color-picker__trigger::before {
|
|
418
|
+
content: '';
|
|
419
|
+
position: absolute;
|
|
420
|
+
top: 0;
|
|
421
|
+
left: 0;
|
|
422
|
+
width: 100%;
|
|
423
|
+
height: 100%;
|
|
424
|
+
border-radius: inherit;
|
|
425
|
+
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
|
|
426
|
+
/* We use a custom property in lieu of currentColor because of https://bugs.webkit.org/show_bug.cgi?id=216780 */
|
|
427
|
+
background-color: var(--preview-color);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
.color-dropdown__trigger--empty::before {
|
|
431
|
+
background-color: transparent;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
.color-picker__transparent-bg {
|
|
435
|
+
background-image: linear-gradient(
|
|
436
|
+
45deg,
|
|
437
|
+
var(--uui-palette-grey,#c4c4c4) 25%,
|
|
438
|
+
transparent 25%
|
|
439
|
+
),
|
|
440
|
+
linear-gradient(45deg, transparent 75%, var(--uui-palette-grey,#c4c4c4) 75%),
|
|
441
|
+
linear-gradient(45deg, transparent 75%, var(--uui-palette-grey,#c4c4c4) 75%),
|
|
442
|
+
linear-gradient(45deg, var(--uui-palette-grey,#c4c4c4) 25%, transparent 25%);
|
|
443
|
+
background-size: 10px 10px;
|
|
444
|
+
background-position: 0 0, 0 0, -5px -5px, 5px 5px;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.color-picker__preview-color--copied {
|
|
448
|
+
animation: pulse 0.75s;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
@keyframes pulse {
|
|
452
|
+
0% {
|
|
453
|
+
box-shadow: 0 0 0 0 var(--uui-palette-space-cadet-light,rgb(38, 53, 110));
|
|
454
|
+
}
|
|
455
|
+
70% {
|
|
456
|
+
box-shadow: 0 0 0 0.5rem transparent;
|
|
457
|
+
}
|
|
458
|
+
100% {
|
|
459
|
+
box-shadow: 0 0 0 0 transparent;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
.color-picker__controls {
|
|
464
|
+
padding: 0.75rem;
|
|
465
|
+
display: flex;
|
|
466
|
+
align-items: center;
|
|
467
|
+
}
|
|
468
|
+
.color-picker__sliders {
|
|
469
|
+
flex: 1 1 auto;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
uui-color-slider:not(:last-of-type) {
|
|
473
|
+
margin-bottom: 1rem;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
.color-picker__toggle-format {
|
|
477
|
+
min-width: 45px;
|
|
478
|
+
--uui-button-font-size: 0.8rem;
|
|
479
|
+
}
|
|
480
|
+
.color-picker__toggle-format > span {
|
|
481
|
+
text-transform: uppercase;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
uui-color-swatches {
|
|
485
|
+
border-top: solid 1px #d4d4d8;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
button[slot='trigger'] {
|
|
489
|
+
border-radius: 50%;
|
|
490
|
+
cursor: pointer;
|
|
491
|
+
width: 36px;
|
|
492
|
+
height: 36px;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
uui-popover {
|
|
496
|
+
display: block;
|
|
497
|
+
width: 100%;
|
|
498
|
+
margin: 5px 0;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
uui-input {
|
|
502
|
+
/* lower the font size to avoid overflow with hlsa format */
|
|
503
|
+
font-size: 0.85rem;
|
|
504
|
+
box-sizing: content-box;
|
|
505
|
+
flex: 1;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
uui-color-area {
|
|
509
|
+
width: 100%;
|
|
510
|
+
}
|
|
511
|
+
`
|
|
512
|
+
];
|
|
513
|
+
__decorateClass([
|
|
514
|
+
query('[part="input"]')
|
|
515
|
+
], UUIColorPickerElement.prototype, "_input", 2);
|
|
516
|
+
__decorateClass([
|
|
517
|
+
query(".color-picker__preview")
|
|
518
|
+
], UUIColorPickerElement.prototype, "_previewButton", 2);
|
|
519
|
+
__decorateClass([
|
|
520
|
+
query("#swatches")
|
|
521
|
+
], UUIColorPickerElement.prototype, "_swatches", 2);
|
|
522
|
+
__decorateClass([
|
|
523
|
+
state()
|
|
524
|
+
], UUIColorPickerElement.prototype, "inputValue", 2);
|
|
525
|
+
__decorateClass([
|
|
526
|
+
state()
|
|
527
|
+
], UUIColorPickerElement.prototype, "hue", 2);
|
|
528
|
+
__decorateClass([
|
|
529
|
+
state()
|
|
530
|
+
], UUIColorPickerElement.prototype, "saturation", 2);
|
|
531
|
+
__decorateClass([
|
|
532
|
+
state()
|
|
533
|
+
], UUIColorPickerElement.prototype, "lightness", 2);
|
|
534
|
+
__decorateClass([
|
|
535
|
+
state()
|
|
536
|
+
], UUIColorPickerElement.prototype, "alpha", 2);
|
|
537
|
+
__decorateClass([
|
|
538
|
+
state()
|
|
539
|
+
], UUIColorPickerElement.prototype, "_colord", 2);
|
|
540
|
+
__decorateClass([
|
|
541
|
+
property()
|
|
542
|
+
], UUIColorPickerElement.prototype, "value", 2);
|
|
543
|
+
__decorateClass([
|
|
544
|
+
property()
|
|
545
|
+
], UUIColorPickerElement.prototype, "format", 2);
|
|
546
|
+
__decorateClass([
|
|
547
|
+
property()
|
|
548
|
+
], UUIColorPickerElement.prototype, "name", 2);
|
|
549
|
+
__decorateClass([
|
|
550
|
+
property()
|
|
551
|
+
], UUIColorPickerElement.prototype, "size", 2);
|
|
552
|
+
__decorateClass([
|
|
553
|
+
property({ attribute: "no-format-toggle", type: Boolean })
|
|
554
|
+
], UUIColorPickerElement.prototype, "noFormatToggle", 2);
|
|
555
|
+
__decorateClass([
|
|
556
|
+
property({ type: Boolean, reflect: true })
|
|
557
|
+
], UUIColorPickerElement.prototype, "inline", 2);
|
|
558
|
+
__decorateClass([
|
|
559
|
+
property({ type: Boolean, reflect: true })
|
|
560
|
+
], UUIColorPickerElement.prototype, "disabled", 2);
|
|
561
|
+
__decorateClass([
|
|
562
|
+
property({ type: Boolean })
|
|
563
|
+
], UUIColorPickerElement.prototype, "opacity", 2);
|
|
564
|
+
__decorateClass([
|
|
565
|
+
property({ type: Boolean })
|
|
566
|
+
], UUIColorPickerElement.prototype, "uppercase", 2);
|
|
567
|
+
__decorateClass([
|
|
568
|
+
property({ attribute: false })
|
|
569
|
+
], UUIColorPickerElement.prototype, "swatches", 2);
|
|
570
|
+
UUIColorPickerElement = __decorateClass([
|
|
571
|
+
defineElement("uui-color-picker")
|
|
572
|
+
], UUIColorPickerElement);
|
|
573
|
+
|
|
574
|
+
export { UUIColorPickerChangeEvent, UUIColorPickerElement };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import { HslaColor } from 'colord';
|
|
3
|
+
import { UUIColorAreaEvent } from '@umbraco-ui/uui-color-area/lib';
|
|
4
|
+
import { UUIColorSliderEvent } from '@umbraco-ui/uui-color-slider/lib';
|
|
5
|
+
import { UUIColorSwatchesElement, UUIColorSwatchesEvent } from '@umbraco-ui/uui-color-swatches/lib';
|
|
6
|
+
import { UUIInputElement } from '@umbraco-ui/uui-input/lib';
|
|
7
|
+
export type UUIColorPickerFormat = 'hex' | 'rgb' | 'hsl';
|
|
8
|
+
export type UUIColorPickerFormatWithAlpha = UUIColorPickerFormat | 'hexa' | 'rgba' | 'hsla';
|
|
9
|
+
type UUIColorPickerSize = 'small' | 'medium' | 'large';
|
|
10
|
+
declare const UUIColorPickerElement_base: (new (...args: any[]) => import("@umbraco-ui/uui-base/lib/mixins").LabelMixinInterface) & typeof LitElement;
|
|
11
|
+
/**
|
|
12
|
+
* @element uui-color-picker
|
|
13
|
+
* @cssprop --uui-color-picker-width - The width of the color picker
|
|
14
|
+
* @description
|
|
15
|
+
* @fires {UUIColorPickerChangeEvent} change - Fired when the color changes
|
|
16
|
+
*/
|
|
17
|
+
export declare class UUIColorPickerElement extends UUIColorPickerElement_base {
|
|
18
|
+
static styles: import("lit").CSSResult[];
|
|
19
|
+
_input: UUIInputElement;
|
|
20
|
+
_previewButton: HTMLButtonElement;
|
|
21
|
+
_swatches: UUIColorSwatchesElement;
|
|
22
|
+
private inputValue;
|
|
23
|
+
private hue;
|
|
24
|
+
private saturation;
|
|
25
|
+
private lightness;
|
|
26
|
+
private alpha;
|
|
27
|
+
private _colord;
|
|
28
|
+
/**
|
|
29
|
+
* The current color.
|
|
30
|
+
* @attr
|
|
31
|
+
* @type {string}
|
|
32
|
+
* @default ''
|
|
33
|
+
**/
|
|
34
|
+
value: string;
|
|
35
|
+
/**
|
|
36
|
+
* The format to use for the display value. If opacity is enabled, these will translate to HEXA, RGBA, and HSLA
|
|
37
|
+
* respectively. The color picker will always accept user input in any format (including CSS color names) and convert
|
|
38
|
+
* it to the desired format.
|
|
39
|
+
* @attr
|
|
40
|
+
* @type {UUIColorPickerFormat}
|
|
41
|
+
* @default 'hex'
|
|
42
|
+
*/
|
|
43
|
+
format: UUIColorPickerFormat;
|
|
44
|
+
/**
|
|
45
|
+
* The input's name attribute.
|
|
46
|
+
* @attr
|
|
47
|
+
* @type {string}
|
|
48
|
+
* @default ''
|
|
49
|
+
**/
|
|
50
|
+
name: string;
|
|
51
|
+
/**
|
|
52
|
+
* Determines the size of the color picker's trigger. This has no effect on inline color pickers.
|
|
53
|
+
* @attr
|
|
54
|
+
* @type {UUIColorPickerSize}
|
|
55
|
+
* @default 'medium'
|
|
56
|
+
**/
|
|
57
|
+
size: UUIColorPickerSize;
|
|
58
|
+
/**
|
|
59
|
+
* Removes the format toggle.
|
|
60
|
+
* @attr
|
|
61
|
+
* @type {boolean}
|
|
62
|
+
* @default false
|
|
63
|
+
**/
|
|
64
|
+
noFormatToggle: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Renders the color picker inline rather than inside a dropdown.
|
|
67
|
+
* @attr
|
|
68
|
+
* @type {boolean}
|
|
69
|
+
* @default false
|
|
70
|
+
**/
|
|
71
|
+
inline: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Disables the color picker.
|
|
74
|
+
* @attr
|
|
75
|
+
* @type {boolean}
|
|
76
|
+
* @default false
|
|
77
|
+
**/
|
|
78
|
+
disabled: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Whether to show the opacity slider.
|
|
81
|
+
* @attr
|
|
82
|
+
* @type {boolean}
|
|
83
|
+
* @default false
|
|
84
|
+
**/
|
|
85
|
+
opacity: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* By default, the value will be set in lowercase. Set this to true to set it in uppercase instead.
|
|
88
|
+
* @attr
|
|
89
|
+
* @type {boolean}
|
|
90
|
+
* @default false
|
|
91
|
+
**/
|
|
92
|
+
uppercase: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* An array of predefined color swatches to display. Can include any format the color picker can parse, including
|
|
95
|
+
* HEX(A), RGB(A), HSL(A), and CSS color names.
|
|
96
|
+
*/
|
|
97
|
+
swatches: string[];
|
|
98
|
+
connectedCallback(): void;
|
|
99
|
+
/** Returns the current value as a string in the specified format. */
|
|
100
|
+
getFormattedValue(format: UUIColorPickerFormat): string;
|
|
101
|
+
getBrightness(lightness: number): number;
|
|
102
|
+
getLightness(brightness: number): number;
|
|
103
|
+
handleFormatToggle(): void;
|
|
104
|
+
handleAlphaChange(event: UUIColorSliderEvent): void;
|
|
105
|
+
handleHueChange(event: UUIColorSliderEvent): void;
|
|
106
|
+
handleGridChange(event: UUIColorAreaEvent): void;
|
|
107
|
+
handleInputChange(event: CustomEvent): void;
|
|
108
|
+
handleInputKeyDown(event: KeyboardEvent): void;
|
|
109
|
+
handleColorSwatchChange(event: UUIColorSwatchesEvent): void;
|
|
110
|
+
handleCopy(): void;
|
|
111
|
+
openColorPicker(event: Event): void;
|
|
112
|
+
closeColorPicker(event: Event): void;
|
|
113
|
+
handleEyeDropper(): void;
|
|
114
|
+
setColor(colorString: string | HslaColor): boolean;
|
|
115
|
+
setLetterCase(string: string): string;
|
|
116
|
+
private _syncValues;
|
|
117
|
+
private _renderColorPicker;
|
|
118
|
+
private _renderPreviewButton;
|
|
119
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
120
|
+
}
|
|
121
|
+
declare global {
|
|
122
|
+
interface HTMLElementTagNameMap {
|
|
123
|
+
'uui-color-picker': UUIColorPickerElement;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@umbraco-ui/uui-color-picker",
|
|
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 Picker"
|
|
12
|
+
],
|
|
13
|
+
"description": "Umbraco UI color-picker component",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/umbraco/Umbraco.UI.git",
|
|
17
|
+
"directory": "packages/uui-color-picker"
|
|
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
|
+
"colord": "^2.9.3"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js",
|
|
38
|
+
"clean": "tsc --build --clean && rimraf dist lib/*.js lib/**/*.js custom-elements.json",
|
|
39
|
+
"analyze": "web-component-analyzer **/*.element.ts --outFile custom-elements.json"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://uui.umbraco.com/?path=/story/uui-color-picker",
|
|
45
|
+
"gitHead": "43f1b9a8bd1721af30ba7c145517ee665d874df3"
|
|
46
|
+
}
|