@spectrum-web-components/swatch 0.1.2-devmode.0 → 0.1.2
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/package.json +8 -5
- package/sp-swatch-group.js +14 -3
- package/sp-swatch-group.js.map +1 -7
- package/sp-swatch.js +14 -3
- package/sp-swatch.js.map +1 -7
- package/src/Swatch.js +170 -165
- package/src/Swatch.js.map +1 -7
- package/src/SwatchGroup.js +216 -201
- package/src/SwatchGroup.js.map +1 -7
- package/src/index.js +14 -3
- package/src/index.js.map +1 -7
- package/src/spectrum-swatch-group.css.js +14 -3
- package/src/spectrum-swatch-group.css.js.map +1 -7
- package/src/spectrum-swatch.css.js +14 -3
- package/src/spectrum-swatch.css.js.map +1 -7
- package/src/swatch-group.css.js +14 -3
- package/src/swatch-group.css.js.map +1 -7
- package/src/swatch.css.js +14 -3
- package/src/swatch.css.js.map +1 -7
- package/stories/swatch-group.stories.js +133 -124
- package/stories/swatch-group.stories.js.map +1 -7
- package/stories/swatch-sizes.stories.js +21 -15
- package/stories/swatch-sizes.stories.js.map +1 -7
- package/stories/swatch.stories.js +73 -69
- package/stories/swatch.stories.js.map +1 -7
- package/test/benchmark/basic-test.js +16 -5
- package/test/benchmark/basic-test.js.map +1 -7
- package/test/swatch-group.test-vrt.js +15 -4
- package/test/swatch-group.test-vrt.js.map +1 -7
- package/test/swatch-group.test.js +240 -229
- package/test/swatch-group.test.js.map +1 -7
- package/test/swatch-sizes.test-vrt.js +15 -4
- package/test/swatch-sizes.test-vrt.js.map +1 -7
- package/test/swatch.test-vrt.js +15 -4
- package/test/swatch.test-vrt.js.map +1 -7
- package/test/swatch.test.js +135 -124
- package/test/swatch.test.js.map +1 -7
- package/sp-swatch-group.dev.js +0 -3
- package/sp-swatch-group.dev.js.map +0 -7
- package/sp-swatch.dev.js +0 -3
- package/sp-swatch.dev.js.map +0 -7
- package/src/Swatch.dev.js +0 -219
- package/src/Swatch.dev.js.map +0 -7
- package/src/SwatchGroup.dev.js +0 -220
- package/src/SwatchGroup.dev.js.map +0 -7
- package/src/index.dev.js +0 -3
- package/src/index.dev.js.map +0 -7
- package/src/spectrum-swatch-group.css.dev.js +0 -10
- package/src/spectrum-swatch-group.css.dev.js.map +0 -7
- package/src/spectrum-swatch.css.dev.js +0 -66
- package/src/spectrum-swatch.css.dev.js.map +0 -7
- package/src/swatch-group.css.dev.js +0 -10
- package/src/swatch-group.css.dev.js.map +0 -7
- package/src/swatch.css.dev.js +0 -66
- package/src/swatch.css.dev.js.map +0 -7
package/src/SwatchGroup.js
CHANGED
|
@@ -1,220 +1,235 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { __decorate } from "tslib";
|
|
13
|
+
import { html, SizedMixin, SpectrumElement, } from '@spectrum-web-components/base';
|
|
14
|
+
import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
15
|
+
import { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';
|
|
16
|
+
import { MutationController } from '@lit-labs/observers/mutation_controller.js';
|
|
17
|
+
import styles from './swatch-group.css.js';
|
|
18
|
+
/**
|
|
19
|
+
* @element sp-swatch-group
|
|
20
|
+
*
|
|
21
|
+
* @slot - Swatch elements to manage as a group
|
|
22
|
+
*/
|
|
21
23
|
export class SwatchGroup extends SizedMixin(SpectrumElement, {
|
|
22
|
-
|
|
24
|
+
validSizes: ['xs', 's', 'm', 'l'],
|
|
23
25
|
}) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
this._selected = [];
|
|
29
|
+
this.selectedSet = new Set();
|
|
30
|
+
this.rovingTabindexController = new RovingTabindexController(this, {
|
|
31
|
+
focusInIndex: (elements) => {
|
|
32
|
+
let firstEnabledIndex = -1;
|
|
33
|
+
const firstSelectedIndex = elements.findIndex((el, index) => {
|
|
34
|
+
if (!elements[firstEnabledIndex] && !el.disabled) {
|
|
35
|
+
firstEnabledIndex = index;
|
|
36
|
+
}
|
|
37
|
+
return el.selected && !el.disabled;
|
|
38
|
+
});
|
|
39
|
+
return elements[firstSelectedIndex]
|
|
40
|
+
? firstSelectedIndex
|
|
41
|
+
: firstEnabledIndex;
|
|
42
|
+
},
|
|
43
|
+
elements: () => [...this.children],
|
|
44
|
+
isFocusableElement: (el) => !el.disabled,
|
|
45
|
+
});
|
|
46
|
+
this.manageChange = () => {
|
|
47
|
+
const presentSet = new Set();
|
|
48
|
+
this.selectedSet = new Set(this.selected);
|
|
49
|
+
const swatches = [...this.children];
|
|
50
|
+
swatches.forEach((swatch) => {
|
|
51
|
+
presentSet.add(swatch.value);
|
|
52
|
+
if (swatch.selected) {
|
|
53
|
+
this.selectedSet.add(swatch.value);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
this.selectedSet.forEach((value) => {
|
|
57
|
+
if (!presentSet.has(value)) {
|
|
58
|
+
this.selectedSet.delete(value);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
this._selected = [...this.selectedSet];
|
|
62
|
+
};
|
|
63
|
+
new MutationController(this, {
|
|
64
|
+
config: {
|
|
65
|
+
attributes: true,
|
|
66
|
+
childList: true,
|
|
67
|
+
subtree: true,
|
|
68
|
+
},
|
|
69
|
+
callback: () => {
|
|
70
|
+
this.manageChange();
|
|
71
|
+
},
|
|
36
72
|
});
|
|
37
|
-
return elements[firstSelectedIndex] ? firstSelectedIndex : firstEnabledIndex;
|
|
38
|
-
},
|
|
39
|
-
elements: () => [...this.children],
|
|
40
|
-
isFocusableElement: (el) => !el.disabled
|
|
41
|
-
});
|
|
42
|
-
this.manageChange = () => {
|
|
43
|
-
const presentSet = /* @__PURE__ */ new Set();
|
|
44
|
-
this.selectedSet = new Set(this.selected);
|
|
45
|
-
const swatches = [...this.children];
|
|
46
|
-
swatches.forEach((swatch) => {
|
|
47
|
-
presentSet.add(swatch.value);
|
|
48
|
-
if (swatch.selected) {
|
|
49
|
-
this.selectedSet.add(swatch.value);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
this.selectedSet.forEach((value) => {
|
|
53
|
-
if (!presentSet.has(value)) {
|
|
54
|
-
this.selectedSet.delete(value);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
this._selected = [...this.selectedSet];
|
|
58
|
-
};
|
|
59
|
-
new MutationController(this, {
|
|
60
|
-
config: {
|
|
61
|
-
attributes: true,
|
|
62
|
-
childList: true,
|
|
63
|
-
subtree: true
|
|
64
|
-
},
|
|
65
|
-
callback: () => {
|
|
66
|
-
this.manageChange();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
static get styles() {
|
|
71
|
-
return [styles];
|
|
72
|
-
}
|
|
73
|
-
get selected() {
|
|
74
|
-
return this._selected;
|
|
75
|
-
}
|
|
76
|
-
set selected(selected) {
|
|
77
|
-
if (selected === this.selected)
|
|
78
|
-
return;
|
|
79
|
-
const oldSelected = this.selected;
|
|
80
|
-
this._selected = selected;
|
|
81
|
-
this.requestUpdate("selected", oldSelected);
|
|
82
|
-
}
|
|
83
|
-
focus(options) {
|
|
84
|
-
this.rovingTabindexController.focus(options);
|
|
85
|
-
}
|
|
86
|
-
handleChange(event) {
|
|
87
|
-
event.stopPropagation();
|
|
88
|
-
const oldSelected = this.selected;
|
|
89
|
-
if (!this.selects) {
|
|
90
|
-
event.preventDefault();
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (this.selects === "single") {
|
|
94
|
-
const { target } = event;
|
|
95
|
-
target.tabIndex = 0;
|
|
96
|
-
this.selectedSet.clear();
|
|
97
|
-
this.selectedSet.add(target.value);
|
|
98
|
-
this.rovingTabindexController.elements.forEach((child) => {
|
|
99
|
-
if (child === target)
|
|
100
|
-
return;
|
|
101
|
-
child.selected = false;
|
|
102
|
-
});
|
|
103
|
-
} else if (this.selects === "multiple") {
|
|
104
|
-
const { target } = event;
|
|
105
|
-
if (target.selected) {
|
|
106
|
-
this.selectedSet.add(target.value);
|
|
107
|
-
} else {
|
|
108
|
-
this.selectedSet.delete(target.value);
|
|
109
|
-
}
|
|
110
73
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
cancelable: true,
|
|
114
|
-
bubbles: true
|
|
115
|
-
}));
|
|
116
|
-
if (!applyDefault) {
|
|
117
|
-
this.selected = oldSelected;
|
|
118
|
-
event.preventDefault();
|
|
74
|
+
static get styles() {
|
|
75
|
+
return [styles];
|
|
119
76
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const targetValues = {};
|
|
123
|
-
if (changes.has("border") && (this.border || typeof changes.get("border") !== "undefined")) {
|
|
124
|
-
targetValues.border = this.border;
|
|
77
|
+
get selected() {
|
|
78
|
+
return this._selected;
|
|
125
79
|
}
|
|
126
|
-
|
|
127
|
-
|
|
80
|
+
set selected(selected) {
|
|
81
|
+
if (selected === this.selected)
|
|
82
|
+
return;
|
|
83
|
+
const oldSelected = this.selected;
|
|
84
|
+
this._selected = selected;
|
|
85
|
+
this.requestUpdate('selected', oldSelected);
|
|
128
86
|
}
|
|
129
|
-
|
|
130
|
-
|
|
87
|
+
focus(options) {
|
|
88
|
+
this.rovingTabindexController.focus(options);
|
|
131
89
|
}
|
|
132
|
-
|
|
133
|
-
|
|
90
|
+
handleChange(event) {
|
|
91
|
+
event.stopPropagation();
|
|
92
|
+
const oldSelected = this.selected;
|
|
93
|
+
if (!this.selects) {
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (this.selects === 'single') {
|
|
98
|
+
const { target } = event;
|
|
99
|
+
target.tabIndex = 0;
|
|
100
|
+
this.selectedSet.clear();
|
|
101
|
+
this.selectedSet.add(target.value);
|
|
102
|
+
this.rovingTabindexController.elements.forEach((child) => {
|
|
103
|
+
if (child === target)
|
|
104
|
+
return;
|
|
105
|
+
child.selected = false;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else if (this.selects === 'multiple') {
|
|
109
|
+
const { target } = event;
|
|
110
|
+
if (target.selected) {
|
|
111
|
+
this.selectedSet.add(target.value);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
this.selectedSet.delete(target.value);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
this._selected = [...this.selectedSet];
|
|
118
|
+
const applyDefault = this.dispatchEvent(new Event('change', {
|
|
119
|
+
cancelable: true,
|
|
120
|
+
bubbles: true,
|
|
121
|
+
}));
|
|
122
|
+
if (!applyDefault) {
|
|
123
|
+
this.selected = oldSelected;
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
}
|
|
134
126
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
127
|
+
getPassthroughSwatchActions(changes) {
|
|
128
|
+
const targetValues = {};
|
|
129
|
+
if (changes.has('border') &&
|
|
130
|
+
(this.border || typeof changes.get('border') !== 'undefined')) {
|
|
131
|
+
targetValues.border = this.border;
|
|
132
|
+
}
|
|
133
|
+
if (changes.has('rounding') &&
|
|
134
|
+
(this.rounding || typeof changes.get('rounding') !== 'undefined')) {
|
|
135
|
+
targetValues.rounding = this.rounding;
|
|
136
|
+
}
|
|
137
|
+
if (changes.has('size') &&
|
|
138
|
+
(this.size || typeof changes.get('size') !== 'undefined')) {
|
|
139
|
+
targetValues.size = this.size;
|
|
140
|
+
}
|
|
141
|
+
if (changes.has('shape') &&
|
|
142
|
+
(this.shape || typeof changes.get('shape') !== 'undefined')) {
|
|
143
|
+
targetValues.shape = this.shape;
|
|
144
|
+
}
|
|
145
|
+
const passThroughSwatchActions = [];
|
|
146
|
+
if (Object.keys(targetValues).length) {
|
|
147
|
+
passThroughSwatchActions.push((swatch) => {
|
|
148
|
+
if ('border' in targetValues)
|
|
149
|
+
swatch.border = targetValues.border;
|
|
150
|
+
if ('rounding' in targetValues)
|
|
151
|
+
swatch.rounding = targetValues.rounding;
|
|
152
|
+
if ('shape' in targetValues)
|
|
153
|
+
swatch.shape = targetValues.shape;
|
|
154
|
+
if ('size' in targetValues)
|
|
155
|
+
swatch.size = targetValues.size;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return passThroughSwatchActions;
|
|
147
159
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
160
|
+
getSelectionSwatchActions(changes) {
|
|
161
|
+
const selectionSwatchActions = [];
|
|
162
|
+
if (!changes.has('selects'))
|
|
163
|
+
return selectionSwatchActions;
|
|
164
|
+
if (this.selects) {
|
|
165
|
+
this.setAttribute('role', this.selects === 'single' ? 'radiogroup' : 'group');
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
this.removeAttribute('role');
|
|
169
|
+
}
|
|
170
|
+
const swatchRoles = {
|
|
171
|
+
single: 'radio',
|
|
172
|
+
multiple: 'checkbox',
|
|
173
|
+
};
|
|
174
|
+
const swatchRole = this.selects ? swatchRoles[this.selects] : 'button';
|
|
175
|
+
selectionSwatchActions.push((swatch) => {
|
|
176
|
+
swatch.setAttribute('role', swatchRole);
|
|
177
|
+
});
|
|
178
|
+
return selectionSwatchActions;
|
|
158
179
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
multiple: "checkbox"
|
|
162
|
-
};
|
|
163
|
-
const swatchRole = this.selects ? swatchRoles[this.selects] : "button";
|
|
164
|
-
selectionSwatchActions.push((swatch) => {
|
|
165
|
-
swatch.setAttribute("role", swatchRole);
|
|
166
|
-
});
|
|
167
|
-
return selectionSwatchActions;
|
|
168
|
-
}
|
|
169
|
-
render() {
|
|
170
|
-
return html`
|
|
180
|
+
render() {
|
|
181
|
+
return html `
|
|
171
182
|
<slot
|
|
172
183
|
@change=${this.handleChange}
|
|
173
184
|
@slotchange=${this.manageChange}
|
|
174
185
|
></slot>
|
|
175
186
|
`;
|
|
176
|
-
}
|
|
177
|
-
willUpdate(changes) {
|
|
178
|
-
const swatchActions = [
|
|
179
|
-
...this.getPassthroughSwatchActions(changes),
|
|
180
|
-
...this.getSelectionSwatchActions(changes)
|
|
181
|
-
];
|
|
182
|
-
const nextSelected = new Set(this.selected);
|
|
183
|
-
const currentValues = /* @__PURE__ */ new Set();
|
|
184
|
-
if (changes.has("selected")) {
|
|
185
|
-
swatchActions.push((swatch) => {
|
|
186
|
-
currentValues.add(swatch.value);
|
|
187
|
-
if (nextSelected.has(swatch.value) || swatch.selected) {
|
|
188
|
-
swatch.selected = true;
|
|
189
|
-
} else {
|
|
190
|
-
swatch.selected = false;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
187
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
188
|
+
willUpdate(changes) {
|
|
189
|
+
const swatchActions = [
|
|
190
|
+
...this.getPassthroughSwatchActions(changes),
|
|
191
|
+
...this.getSelectionSwatchActions(changes),
|
|
192
|
+
];
|
|
193
|
+
// Create Swatch actions that build state to be applied later.
|
|
194
|
+
const nextSelected = new Set(this.selected);
|
|
195
|
+
const currentValues = new Set();
|
|
196
|
+
if (changes.has('selected')) {
|
|
197
|
+
swatchActions.push((swatch) => {
|
|
198
|
+
currentValues.add(swatch.value);
|
|
199
|
+
if (nextSelected.has(swatch.value) || swatch.selected) {
|
|
200
|
+
swatch.selected = true;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
swatch.selected = false;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
// Do Swatch actions to each Swach in the collection.
|
|
208
|
+
this.rovingTabindexController.elements.forEach((swatch) => {
|
|
209
|
+
swatchActions.forEach((action) => {
|
|
210
|
+
action(swatch);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
// Apply state built in actions back to the Swatch Group
|
|
214
|
+
if (changes.has('selected')) {
|
|
215
|
+
this.selected = [...nextSelected].filter((selectedValue) => currentValues.has(selectedValue));
|
|
216
|
+
this.rovingTabindexController.clearElementCache();
|
|
217
|
+
}
|
|
202
218
|
}
|
|
203
|
-
}
|
|
204
219
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
], SwatchGroup.prototype, "border",
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
], SwatchGroup.prototype, "rounding",
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
], SwatchGroup.prototype, "selected",
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
], SwatchGroup.prototype, "selects",
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
], SwatchGroup.prototype, "shape",
|
|
220
|
-
//# sourceMappingURL=SwatchGroup.js.map
|
|
220
|
+
__decorate([
|
|
221
|
+
property({ reflect: true })
|
|
222
|
+
], SwatchGroup.prototype, "border", void 0);
|
|
223
|
+
__decorate([
|
|
224
|
+
property({ reflect: true })
|
|
225
|
+
], SwatchGroup.prototype, "rounding", void 0);
|
|
226
|
+
__decorate([
|
|
227
|
+
property({ type: Array })
|
|
228
|
+
], SwatchGroup.prototype, "selected", null);
|
|
229
|
+
__decorate([
|
|
230
|
+
property()
|
|
231
|
+
], SwatchGroup.prototype, "selects", void 0);
|
|
232
|
+
__decorate([
|
|
233
|
+
property({ reflect: true })
|
|
234
|
+
], SwatchGroup.prototype, "shape", void 0);
|
|
235
|
+
//# sourceMappingURL=SwatchGroup.js.map
|
package/src/SwatchGroup.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["SwatchGroup.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n ElementSize,\n html,\n PropertyValues,\n SizedMixin,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\nimport { property } from 'lit/decorators.js';\n\nimport styles from './swatch-group.css.js';\nimport type {\n Swatch,\n SwatchBorder,\n SwatchRounding,\n SwatchShape,\n} from './Swatch.js';\n\nexport type SwatchGroupSizes = Exclude<ElementSize, 'xxs' | 'xl' | 'xxl'>;\n\n/**\n * @element sp-swatch-group\n *\n * @slot - Swatch elements to manage as a group\n */\nexport class SwatchGroup extends SizedMixin(SpectrumElement, {\n validSizes: ['xs', 's', 'm', 'l'],\n}) {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n @property({ reflect: true })\n public border: SwatchBorder;\n\n @property({ reflect: true })\n public rounding: SwatchRounding;\n\n @property({ type: Array })\n public get selected(): string[] {\n return this._selected;\n }\n\n public set selected(selected: string[]) {\n if (selected === this.selected) return;\n const oldSelected = this.selected;\n this._selected = selected;\n this.requestUpdate('selected', oldSelected);\n }\n\n private _selected: string[] = [];\n\n @property()\n public selects: 'single' | 'multiple' | undefined;\n\n private selectedSet = new Set<string>();\n\n @property({ reflect: true })\n public shape: SwatchShape;\n\n constructor() {\n super();\n\n new MutationController(this, {\n config: {\n attributes: true,\n childList: true,\n subtree: true,\n },\n callback: () => {\n this.manageChange();\n },\n });\n }\n\n rovingTabindexController = new RovingTabindexController<Swatch>(this, {\n focusInIndex: (elements: Swatch[]) => {\n let firstEnabledIndex = -1;\n const firstSelectedIndex = elements.findIndex((el, index) => {\n if (!elements[firstEnabledIndex] && !el.disabled) {\n firstEnabledIndex = index;\n }\n return el.selected && !el.disabled;\n });\n return elements[firstSelectedIndex]\n ? firstSelectedIndex\n : firstEnabledIndex;\n },\n elements: () => [...this.children] as Swatch[],\n isFocusableElement: (el: Swatch) => !el.disabled,\n });\n\n public override focus(options?: FocusOptions): void {\n this.rovingTabindexController.focus(options);\n }\n\n protected handleChange(event: Event & { target: Swatch }): void {\n event.stopPropagation();\n const oldSelected = this.selected;\n if (!this.selects) {\n event.preventDefault();\n return;\n }\n if (this.selects === 'single') {\n const { target } = event;\n target.tabIndex = 0;\n this.selectedSet.clear();\n this.selectedSet.add(target.value);\n this.rovingTabindexController.elements.forEach((child) => {\n if (child === target) return;\n child.selected = false;\n });\n } else if (this.selects === 'multiple') {\n const { target } = event;\n if (target.selected) {\n this.selectedSet.add(target.value);\n } else {\n this.selectedSet.delete(target.value);\n }\n }\n this._selected = [...this.selectedSet];\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n cancelable: true,\n bubbles: true,\n })\n );\n if (!applyDefault) {\n this.selected = oldSelected;\n event.preventDefault();\n }\n }\n\n private manageChange = (): void => {\n const presentSet = new Set();\n this.selectedSet = new Set(this.selected);\n const swatches = [...this.children] as Swatch[];\n swatches.forEach((swatch) => {\n presentSet.add(swatch.value);\n if (swatch.selected) {\n this.selectedSet.add(swatch.value);\n }\n });\n this.selectedSet.forEach((value) => {\n if (!presentSet.has(value)) {\n this.selectedSet.delete(value);\n }\n });\n this._selected = [...this.selectedSet];\n };\n\n private getPassthroughSwatchActions(\n changes: PropertyValues\n ): ((swatch: Swatch) => void)[] {\n const targetValues: {\n border?: SwatchBorder;\n rounding?: SwatchRounding;\n shape?: SwatchShape;\n size?: SwatchGroupSizes;\n } = {};\n if (\n changes.has('border') &&\n (this.border || typeof changes.get('border') !== 'undefined')\n ) {\n targetValues.border = this.border;\n }\n if (\n changes.has('rounding') &&\n (this.rounding || typeof changes.get('rounding') !== 'undefined')\n ) {\n targetValues.rounding = this.rounding;\n }\n if (\n changes.has('size') &&\n (this.size || typeof changes.get('size') !== 'undefined')\n ) {\n targetValues.size = this.size as SwatchGroupSizes;\n }\n if (\n changes.has('shape') &&\n (this.shape || typeof changes.get('shape') !== 'undefined')\n ) {\n targetValues.shape = this.shape;\n }\n const passThroughSwatchActions: ((swatch: Swatch) => void)[] = [];\n if (Object.keys(targetValues).length) {\n passThroughSwatchActions.push((swatch) => {\n if ('border' in targetValues)\n swatch.border = targetValues.border;\n if ('rounding' in targetValues)\n swatch.rounding = targetValues.rounding;\n if ('shape' in targetValues) swatch.shape = targetValues.shape;\n if ('size' in targetValues)\n swatch.size = targetValues.size as SwatchGroupSizes;\n });\n }\n return passThroughSwatchActions;\n }\n\n private getSelectionSwatchActions(\n changes: PropertyValues\n ): ((swatch: Swatch) => void)[] {\n const selectionSwatchActions: ((swatch: Swatch) => void)[] = [];\n if (!changes.has('selects')) return selectionSwatchActions;\n if (this.selects) {\n this.setAttribute(\n 'role',\n this.selects === 'single' ? 'radiogroup' : 'group'\n );\n } else {\n this.removeAttribute('role');\n }\n const swatchRoles = {\n single: 'radio',\n multiple: 'checkbox',\n };\n const swatchRole = this.selects ? swatchRoles[this.selects] : 'button';\n selectionSwatchActions.push((swatch) => {\n swatch.setAttribute('role', swatchRole);\n });\n return selectionSwatchActions;\n }\n\n protected override render(): TemplateResult {\n return html`\n <slot\n @change=${this.handleChange}\n @slotchange=${this.manageChange}\n ></slot>\n `;\n }\n\n protected override willUpdate(changes: PropertyValues<this>): void {\n const swatchActions = [\n ...this.getPassthroughSwatchActions(changes),\n ...this.getSelectionSwatchActions(changes),\n ];\n\n // Create Swatch actions that build state to be applied later.\n const nextSelected = new Set(this.selected);\n const currentValues = new Set();\n if (changes.has('selected')) {\n swatchActions.push((swatch) => {\n currentValues.add(swatch.value);\n if (nextSelected.has(swatch.value) || swatch.selected) {\n swatch.selected = true;\n } else {\n swatch.selected = false;\n }\n });\n }\n\n // Do Swatch actions to each Swach in the collection.\n this.rovingTabindexController.elements.forEach((swatch) => {\n swatchActions.forEach((action) => {\n action(swatch);\n });\n });\n\n // Apply state built in actions back to the Swatch Group\n if (changes.has('selected')) {\n this.selected = [...nextSelected].filter((selectedValue) =>\n currentValues.has(selectedValue)\n );\n this.rovingTabindexController.clearElementCache();\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;AAYA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AACA;AAEA;AAeO,aAAM,oBAAoB,WAAW,iBAAiB;AAAA,EACzD,YAAY,CAAC,MAAM,KAAK,KAAK,GAAG;AACpC,CAAC,EAAE;AAAA,EAiCC,cAAc;AACV,UAAM;AAXF,qBAAsB,CAAC;AAKvB,uBAAc,oBAAI,IAAY;AAoBtC,oCAA2B,IAAI,yBAAiC,MAAM;AAAA,MA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CAAC;QACP,CAAC,CAAC,CAAC;QAEH,wDAAwD;QACxD,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YACzB,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,EAAE,CACvD,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,CACnC,CAAC;YACF,IAAI,CAAC,wBAAwB,CAAC,iBAAiB,EAAE,CAAC;SACrD;IACL,CAAC;CACJ;AA1OG;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;2CACA;AAG5B;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;6CACI;AAGhC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;2CAGzB;AAYD;IADC,QAAQ,EAAE;4CACuC;AAKlD;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;0CACF","sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n ElementSize,\n html,\n PropertyValues,\n SizedMixin,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nimport styles from './swatch-group.css.js';\nimport type {\n Swatch,\n SwatchBorder,\n SwatchRounding,\n SwatchShape,\n} from './Swatch.js';\n\nexport type SwatchGroupSizes = Exclude<ElementSize, 'xxs' | 'xl' | 'xxl'>;\n\n/**\n * @element sp-swatch-group\n *\n * @slot - Swatch elements to manage as a group\n */\nexport class SwatchGroup extends SizedMixin(SpectrumElement, {\n validSizes: ['xs', 's', 'm', 'l'],\n}) {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n @property({ reflect: true })\n public border: SwatchBorder;\n\n @property({ reflect: true })\n public rounding: SwatchRounding;\n\n @property({ type: Array })\n public get selected(): string[] {\n return this._selected;\n }\n\n public set selected(selected: string[]) {\n if (selected === this.selected) return;\n const oldSelected = this.selected;\n this._selected = selected;\n this.requestUpdate('selected', oldSelected);\n }\n\n private _selected: string[] = [];\n\n @property()\n public selects: 'single' | 'multiple' | undefined;\n\n private selectedSet = new Set<string>();\n\n @property({ reflect: true })\n public shape: SwatchShape;\n\n constructor() {\n super();\n\n new MutationController(this, {\n config: {\n attributes: true,\n childList: true,\n subtree: true,\n },\n callback: () => {\n this.manageChange();\n },\n });\n }\n\n rovingTabindexController = new RovingTabindexController<Swatch>(this, {\n focusInIndex: (elements: Swatch[]) => {\n let firstEnabledIndex = -1;\n const firstSelectedIndex = elements.findIndex((el, index) => {\n if (!elements[firstEnabledIndex] && !el.disabled) {\n firstEnabledIndex = index;\n }\n return el.selected && !el.disabled;\n });\n return elements[firstSelectedIndex]\n ? firstSelectedIndex\n : firstEnabledIndex;\n },\n elements: () => [...this.children] as Swatch[],\n isFocusableElement: (el: Swatch) => !el.disabled,\n });\n\n public override focus(options?: FocusOptions): void {\n this.rovingTabindexController.focus(options);\n }\n\n protected handleChange(event: Event & { target: Swatch }): void {\n event.stopPropagation();\n const oldSelected = this.selected;\n if (!this.selects) {\n event.preventDefault();\n return;\n }\n if (this.selects === 'single') {\n const { target } = event;\n target.tabIndex = 0;\n this.selectedSet.clear();\n this.selectedSet.add(target.value);\n this.rovingTabindexController.elements.forEach((child) => {\n if (child === target) return;\n child.selected = false;\n });\n } else if (this.selects === 'multiple') {\n const { target } = event;\n if (target.selected) {\n this.selectedSet.add(target.value);\n } else {\n this.selectedSet.delete(target.value);\n }\n }\n this._selected = [...this.selectedSet];\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n cancelable: true,\n bubbles: true,\n })\n );\n if (!applyDefault) {\n this.selected = oldSelected;\n event.preventDefault();\n }\n }\n\n private manageChange = (): void => {\n const presentSet = new Set();\n this.selectedSet = new Set(this.selected);\n const swatches = [...this.children] as Swatch[];\n swatches.forEach((swatch) => {\n presentSet.add(swatch.value);\n if (swatch.selected) {\n this.selectedSet.add(swatch.value);\n }\n });\n this.selectedSet.forEach((value) => {\n if (!presentSet.has(value)) {\n this.selectedSet.delete(value);\n }\n });\n this._selected = [...this.selectedSet];\n };\n\n private getPassthroughSwatchActions(\n changes: PropertyValues\n ): ((swatch: Swatch) => void)[] {\n const targetValues: {\n border?: SwatchBorder;\n rounding?: SwatchRounding;\n shape?: SwatchShape;\n size?: SwatchGroupSizes;\n } = {};\n if (\n changes.has('border') &&\n (this.border || typeof changes.get('border') !== 'undefined')\n ) {\n targetValues.border = this.border;\n }\n if (\n changes.has('rounding') &&\n (this.rounding || typeof changes.get('rounding') !== 'undefined')\n ) {\n targetValues.rounding = this.rounding;\n }\n if (\n changes.has('size') &&\n (this.size || typeof changes.get('size') !== 'undefined')\n ) {\n targetValues.size = this.size as SwatchGroupSizes;\n }\n if (\n changes.has('shape') &&\n (this.shape || typeof changes.get('shape') !== 'undefined')\n ) {\n targetValues.shape = this.shape;\n }\n const passThroughSwatchActions: ((swatch: Swatch) => void)[] = [];\n if (Object.keys(targetValues).length) {\n passThroughSwatchActions.push((swatch) => {\n if ('border' in targetValues)\n swatch.border = targetValues.border;\n if ('rounding' in targetValues)\n swatch.rounding = targetValues.rounding;\n if ('shape' in targetValues) swatch.shape = targetValues.shape;\n if ('size' in targetValues)\n swatch.size = targetValues.size as SwatchGroupSizes;\n });\n }\n return passThroughSwatchActions;\n }\n\n private getSelectionSwatchActions(\n changes: PropertyValues\n ): ((swatch: Swatch) => void)[] {\n const selectionSwatchActions: ((swatch: Swatch) => void)[] = [];\n if (!changes.has('selects')) return selectionSwatchActions;\n if (this.selects) {\n this.setAttribute(\n 'role',\n this.selects === 'single' ? 'radiogroup' : 'group'\n );\n } else {\n this.removeAttribute('role');\n }\n const swatchRoles = {\n single: 'radio',\n multiple: 'checkbox',\n };\n const swatchRole = this.selects ? swatchRoles[this.selects] : 'button';\n selectionSwatchActions.push((swatch) => {\n swatch.setAttribute('role', swatchRole);\n });\n return selectionSwatchActions;\n }\n\n protected override render(): TemplateResult {\n return html`\n <slot\n @change=${this.handleChange}\n @slotchange=${this.manageChange}\n ></slot>\n `;\n }\n\n protected override willUpdate(changes: PropertyValues<this>): void {\n const swatchActions = [\n ...this.getPassthroughSwatchActions(changes),\n ...this.getSelectionSwatchActions(changes),\n ];\n\n // Create Swatch actions that build state to be applied later.\n const nextSelected = new Set(this.selected);\n const currentValues = new Set();\n if (changes.has('selected')) {\n swatchActions.push((swatch) => {\n currentValues.add(swatch.value);\n if (nextSelected.has(swatch.value) || swatch.selected) {\n swatch.selected = true;\n } else {\n swatch.selected = false;\n }\n });\n }\n\n // Do Swatch actions to each Swach in the collection.\n this.rovingTabindexController.elements.forEach((swatch) => {\n swatchActions.forEach((action) => {\n action(swatch);\n });\n });\n\n // Apply state built in actions back to the Swatch Group\n if (changes.has('selected')) {\n this.selected = [...nextSelected].filter((selectedValue) =>\n currentValues.has(selectedValue)\n );\n this.rovingTabindexController.clearElementCache();\n }\n }\n}\n"]}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export * from './Swatch.js';
|
|
13
|
+
export * from './SwatchGroup.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["index.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nexport * from './Swatch.js';\nexport * from './SwatchGroup.js';\n"],
|
|
5
|
-
"mappings": "AAWA;AACA;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC","sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nexport * from './Swatch.js';\nexport * from './SwatchGroup.js';\n"]}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { css } from '@spectrum-web-components/base';
|
|
13
|
+
const styles = css `
|
|
3
14
|
:host{align-items:flex-start;display:inline-flex;flex-direction:row;flex-wrap:wrap;gap:var(--spectrum-global-dimension-size-50);justify-content:flex-start}:host([density=compact]){gap:var(
|
|
4
15
|
--spectrum-global-dimension-size-25
|
|
5
16
|
)}:host([density=spacious]){gap:var(
|
|
@@ -7,4 +18,4 @@ const styles = css`
|
|
|
7
18
|
)}
|
|
8
19
|
`;
|
|
9
20
|
export default styles;
|
|
10
|
-
//# sourceMappingURL=spectrum-swatch-group.css.js.map
|
|
21
|
+
//# sourceMappingURL=spectrum-swatch-group.css.js.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["spectrum-swatch-group.css.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{align-items:flex-start;display:inline-flex;flex-direction:row;flex-wrap:wrap;gap:var(--spectrum-global-dimension-size-50);justify-content:flex-start}:host([density=compact]){gap:var(\n--spectrum-global-dimension-size-25\n)}:host([density=spacious]){gap:var(\n--spectrum-global-dimension-size-100\n)}\n`;\nexport default styles;"],
|
|
5
|
-
"mappings": "AAWA;AACA,MAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOf,eAAe;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"spectrum-swatch-group.css.js","sourceRoot":"","sources":["spectrum-swatch-group.css.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AACpD,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;CAMjB,CAAC;AACF,eAAe,MAAM,CAAC","sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{align-items:flex-start;display:inline-flex;flex-direction:row;flex-wrap:wrap;gap:var(--spectrum-global-dimension-size-50);justify-content:flex-start}:host([density=compact]){gap:var(\n--spectrum-global-dimension-size-25\n)}:host([density=spacious]){gap:var(\n--spectrum-global-dimension-size-100\n)}\n`;\nexport default styles;"]}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { css } from '@spectrum-web-components/base';
|
|
13
|
+
const styles = css `
|
|
3
14
|
:host{--spectrum-swatch-size-xs:var(
|
|
4
15
|
--spectrum-global-dimension-size-200
|
|
5
16
|
);--spectrum-swatch-size-s:var(--spectrum-global-dimension-size-300);--spectrum-swatch-size-m:var(--spectrum-global-dimension-size-400);--spectrum-swatch-size-l:var(--spectrum-global-dimension-size-500);--spectrum-swatch-disabled-icon-size-xs:var(
|
|
@@ -63,4 +74,4 @@ const styles = css`
|
|
|
63
74
|
)}:host([shape=rectangle][size=xs]){width:calc(var(--spectrum-swatch-size-xs)*2)}:host([shape=rectangle][size=s]){width:calc(var(--spectrum-swatch-size-s)*2)}:host([shape=rectangle][size=m]){width:calc(var(--spectrum-swatch-size-m)*2)}:host([shape=rectangle][size=l]){width:calc(var(--spectrum-swatch-size-l)*2)}:host([rounding=none]),:host([rounding=none]) .fill,:host([rounding=none]) .fill:before,:host([rounding=none]):after,:host([rounding=none]):before,:host([rounding=none][selected]) .fill,:host([rounding=none][selected]) .fill:before{border-radius:0}:host([rounding=full]:not([shape=rectangle])),:host([rounding=full]:not([shape=rectangle])) .fill,:host([rounding=full]:not([shape=rectangle])) .fill:before,:host([rounding=full]:not([shape=rectangle])):after,:host([rounding=full]:not([shape=rectangle])):before,:host([rounding=full][selected]:not([shape=rectangle])) .fill,:host([rounding=full][selected]:not([shape=rectangle])) .fill:before{border-radius:100%}::slotted([slot=image]){height:100%;object-fit:contain;transition:width var(--spectrum-global-animation-duration-100,.13s) ease-in-out,height var(--spectrum-global-animation-duration-100,.13s) ease-in-out;width:100%}
|
|
64
75
|
`;
|
|
65
76
|
export default styles;
|
|
66
|
-
//# sourceMappingURL=spectrum-swatch.css.js.map
|
|
77
|
+
//# sourceMappingURL=spectrum-swatch.css.js.map
|