@umbraco-ui/uui-color-swatches 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 +59 -0
- package/lib/UUIColorSwatchesEvents.d.ts +5 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +132 -0
- package/lib/uui-color-swatches.element.d.ts +43 -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-swatches
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Umbraco style color-swatches component.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
### ES imports
|
|
10
|
+
|
|
11
|
+
```zsh
|
|
12
|
+
npm i @umbraco-ui/uui-color-swatches
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Import the registration of `<uui-color-swatches>` via:
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import '@umbraco-ui/uui-color-swatches';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
When looking to leverage the `UUIColorSwatchesElement` base class as a type and/or for extension purposes, do so via:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
import { UUIColorSwatchesElement } from '@umbraco-ui/uui-color-swatches';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```html
|
|
30
|
+
<uui-color-swatches></uui-color-swatches>
|
|
31
|
+
```
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "experimental",
|
|
3
|
+
"tags": [
|
|
4
|
+
{
|
|
5
|
+
"name": "uui-color-swatches",
|
|
6
|
+
"path": "./lib/uui-color-swatches.element.ts",
|
|
7
|
+
"description": "Put uui-stacked-color-swatch elements inside this element to create a color swatch selector.",
|
|
8
|
+
"attributes": [
|
|
9
|
+
{
|
|
10
|
+
"name": "value",
|
|
11
|
+
"description": "Value of selected option.",
|
|
12
|
+
"type": " string ",
|
|
13
|
+
"default": "\"\\\"\\\"\""
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "label",
|
|
17
|
+
"description": "Label to be used for aria-label and potentially as visual label for some components",
|
|
18
|
+
"type": "string"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"properties": [
|
|
22
|
+
{
|
|
23
|
+
"name": "styles",
|
|
24
|
+
"type": "CSSResult[]",
|
|
25
|
+
"default": "[null]"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "value",
|
|
29
|
+
"attribute": "value",
|
|
30
|
+
"description": "Value of selected option.",
|
|
31
|
+
"type": " string ",
|
|
32
|
+
"default": "\"\\\"\\\"\""
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "swatches",
|
|
36
|
+
"type": "UUIColorSwatchElement[]"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "label",
|
|
40
|
+
"attribute": "label",
|
|
41
|
+
"description": "Label to be used for aria-label and potentially as visual label for some components",
|
|
42
|
+
"type": "string"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"events": [
|
|
46
|
+
{
|
|
47
|
+
"name": "change",
|
|
48
|
+
"description": "Fires when a color swatch is selected."
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"slots": [
|
|
52
|
+
{
|
|
53
|
+
"name": "",
|
|
54
|
+
"description": "Default slot for content."
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UUIEvent } from '@umbraco-ui/uui-base/lib/events';
|
|
2
|
+
import { UUIColorSwatchElement } from '@umbraco-ui/uui-color-swatch/lib/uui-color-swatch.element';
|
|
3
|
+
export declare class UUIColorSwatchesEvent extends UUIEvent<{}, UUIColorSwatchElement> {
|
|
4
|
+
static readonly CHANGE = "change";
|
|
5
|
+
}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { UUIEvent, UUISelectableEvent } from '@umbraco-ui/uui-base/lib/events';
|
|
2
|
+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
|
|
3
|
+
import { LitElement, html, css } from 'lit';
|
|
4
|
+
import { property, queryAssignedElements } from 'lit/decorators.js';
|
|
5
|
+
import { LabelMixin } from '@umbraco-ui/uui-base/lib/mixins';
|
|
6
|
+
|
|
7
|
+
class UUIColorSwatchesEvent extends UUIEvent {
|
|
8
|
+
}
|
|
9
|
+
UUIColorSwatchesEvent.CHANGE = "change";
|
|
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 UUIColorSwatchesElement = class extends LabelMixin("label", LitElement) {
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
this.value = "";
|
|
26
|
+
this._onSelected = (event) => {
|
|
27
|
+
const target = event.target;
|
|
28
|
+
if (!this.swatches.includes(target))
|
|
29
|
+
return;
|
|
30
|
+
if (this._selectedElement) {
|
|
31
|
+
this._selectedElement.selected = false;
|
|
32
|
+
this._selectedElement.active = false;
|
|
33
|
+
this._selectedElement = void 0;
|
|
34
|
+
}
|
|
35
|
+
this._selectedElement = target;
|
|
36
|
+
this._activeElement = this._selectedElement;
|
|
37
|
+
this.value = this._selectedElement.value || "";
|
|
38
|
+
this.dispatchEvent(new UUIColorSwatchesEvent(UUIColorSwatchesEvent.CHANGE));
|
|
39
|
+
};
|
|
40
|
+
this._onUnselected = (event) => {
|
|
41
|
+
const target = event.target;
|
|
42
|
+
if (!this.swatches.includes(target))
|
|
43
|
+
return;
|
|
44
|
+
if (this._activeElement === target) {
|
|
45
|
+
this._activeElement = void 0;
|
|
46
|
+
}
|
|
47
|
+
if (this._selectedElement === target) {
|
|
48
|
+
this._selectedElement.selected = false;
|
|
49
|
+
this._selectedElement.active = false;
|
|
50
|
+
this._selectedElement = void 0;
|
|
51
|
+
this.value = "";
|
|
52
|
+
this.dispatchEvent(
|
|
53
|
+
new UUIColorSwatchesEvent(UUIColorSwatchesEvent.CHANGE)
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
this.addEventListener(UUISelectableEvent.SELECTED, this._onSelected);
|
|
58
|
+
this.addEventListener(UUISelectableEvent.UNSELECTED, this._onUnselected);
|
|
59
|
+
}
|
|
60
|
+
get _activeElement() {
|
|
61
|
+
return this.__activeElement;
|
|
62
|
+
}
|
|
63
|
+
set _activeElement(el) {
|
|
64
|
+
if (this.__activeElement) {
|
|
65
|
+
this.__activeElement.active = false;
|
|
66
|
+
}
|
|
67
|
+
if (el) {
|
|
68
|
+
el.active = true;
|
|
69
|
+
this.__activeElement = el;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
connectedCallback() {
|
|
73
|
+
super.connectedCallback();
|
|
74
|
+
this.setAttribute("role", "radiogroup");
|
|
75
|
+
this.setAttribute("aria-label", this.label);
|
|
76
|
+
}
|
|
77
|
+
willUpdate(_changedProperties) {
|
|
78
|
+
if (_changedProperties.has("label")) {
|
|
79
|
+
this.setAttribute("aria-label", this.label);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
_handleSlotChange() {
|
|
83
|
+
if (!this.swatches || this.swatches.length === 0)
|
|
84
|
+
return;
|
|
85
|
+
this.swatches.forEach((swatch) => {
|
|
86
|
+
var _a;
|
|
87
|
+
swatch.setAttribute("selectable", "selectable");
|
|
88
|
+
swatch.setAttribute("aria-checked", "false");
|
|
89
|
+
swatch.setAttribute("role", "radio");
|
|
90
|
+
if (this.value !== "" && ((_a = swatch.color) == null ? void 0 : _a.isEqual(this.value))) {
|
|
91
|
+
swatch.selected = true;
|
|
92
|
+
swatch.setAttribute("aria-checked", "true");
|
|
93
|
+
this._selectedElement = swatch;
|
|
94
|
+
this._activeElement = this._selectedElement;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
resetSelection() {
|
|
99
|
+
this.swatches.forEach((swatch) => {
|
|
100
|
+
swatch.selected = false;
|
|
101
|
+
swatch.active = false;
|
|
102
|
+
swatch.selectable = true;
|
|
103
|
+
});
|
|
104
|
+
this._activeElement = void 0;
|
|
105
|
+
this._selectedElement = void 0;
|
|
106
|
+
this.value = "";
|
|
107
|
+
}
|
|
108
|
+
render() {
|
|
109
|
+
return html`<slot @slotchange=${this._handleSlotChange}></slot>`;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
UUIColorSwatchesElement.styles = [
|
|
113
|
+
css`
|
|
114
|
+
:host {
|
|
115
|
+
display: flex;
|
|
116
|
+
flex-wrap: wrap;
|
|
117
|
+
gap: 0.4rem;
|
|
118
|
+
padding: 0.75rem;
|
|
119
|
+
}
|
|
120
|
+
`
|
|
121
|
+
];
|
|
122
|
+
__decorateClass([
|
|
123
|
+
property()
|
|
124
|
+
], UUIColorSwatchesElement.prototype, "value", 2);
|
|
125
|
+
__decorateClass([
|
|
126
|
+
queryAssignedElements({ selector: "uui-color-swatch" })
|
|
127
|
+
], UUIColorSwatchesElement.prototype, "swatches", 2);
|
|
128
|
+
UUIColorSwatchesElement = __decorateClass([
|
|
129
|
+
defineElement("uui-color-swatches")
|
|
130
|
+
], UUIColorSwatchesElement);
|
|
131
|
+
|
|
132
|
+
export { UUIColorSwatchesElement, UUIColorSwatchesEvent };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { UUIColorSwatchElement } from '@umbraco-ui/uui-color-swatch/lib';
|
|
2
|
+
import { LitElement, PropertyValueMap } from 'lit';
|
|
3
|
+
declare const UUIColorSwatchesElement_base: (new (...args: any[]) => import("@umbraco-ui/uui-base/lib/mixins").LabelMixinInterface) & typeof LitElement;
|
|
4
|
+
/**
|
|
5
|
+
* Put uui-stacked-color-swatch elements inside this element to create a color swatch selector.
|
|
6
|
+
* @element uui-color-swatches
|
|
7
|
+
* @slot - Default slot for content.
|
|
8
|
+
* @fires {UUIColorSwatchesEvent} change - Fires when a color swatch is selected.
|
|
9
|
+
*/
|
|
10
|
+
export declare class UUIColorSwatchesElement extends UUIColorSwatchesElement_base {
|
|
11
|
+
static styles: import("lit").CSSResult[];
|
|
12
|
+
/**
|
|
13
|
+
* Value of selected option.
|
|
14
|
+
* @type { string }
|
|
15
|
+
* @attr
|
|
16
|
+
* @default ""
|
|
17
|
+
*/
|
|
18
|
+
value: string;
|
|
19
|
+
swatches: Array<UUIColorSwatchElement>;
|
|
20
|
+
private __activeElement;
|
|
21
|
+
private get _activeElement();
|
|
22
|
+
private set _activeElement(value);
|
|
23
|
+
private _selectedElement;
|
|
24
|
+
constructor();
|
|
25
|
+
connectedCallback(): void;
|
|
26
|
+
protected willUpdate(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
|
|
27
|
+
private _handleSlotChange;
|
|
28
|
+
private _onSelected;
|
|
29
|
+
private _onUnselected;
|
|
30
|
+
/**
|
|
31
|
+
* Deselects all swatches.
|
|
32
|
+
*
|
|
33
|
+
* @memberof UUIColorSwatchesElement
|
|
34
|
+
*/
|
|
35
|
+
resetSelection(): void;
|
|
36
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
37
|
+
}
|
|
38
|
+
declare global {
|
|
39
|
+
interface HTMLElementTagNameMap {
|
|
40
|
+
'uui-color-swatches': UUIColorSwatchesElement;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@umbraco-ui/uui-color-swatches",
|
|
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 Swatches"
|
|
12
|
+
],
|
|
13
|
+
"description": "Umbraco UI color-swatches component",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/umbraco/Umbraco.UI.git",
|
|
17
|
+
"directory": "packages/uui-color-swatches"
|
|
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-color-swatch": "1.2.0-rc.0"
|
|
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-swatches",
|
|
45
|
+
"gitHead": "43f1b9a8bd1721af30ba7c145517ee665d874df3"
|
|
46
|
+
}
|