@spectrum-web-components/swatch 0.41.1 → 0.42.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/custom-elements.json +30 -15
- package/package.json +10 -10
- package/src/SwatchGroup.d.ts +5 -2
- package/src/SwatchGroup.dev.js +53 -21
- package/src/SwatchGroup.dev.js.map +2 -2
- package/src/SwatchGroup.js +2 -2
- package/src/SwatchGroup.js.map +3 -3
- package/src/spectrum-swatch-group.css.dev.js +1 -7
- package/src/spectrum-swatch-group.css.dev.js.map +2 -2
- package/src/spectrum-swatch-group.css.js +1 -7
- package/src/spectrum-swatch-group.css.js.map +2 -2
- package/src/spectrum-swatch.css.dev.js +1 -111
- package/src/spectrum-swatch.css.dev.js.map +2 -2
- package/src/spectrum-swatch.css.js +1 -111
- package/src/spectrum-swatch.css.js.map +2 -2
- package/src/swatch-group.css.dev.js +1 -7
- package/src/swatch-group.css.dev.js.map +2 -2
- package/src/swatch-group.css.js +1 -7
- package/src/swatch-group.css.js.map +2 -2
- package/src/swatch.css.dev.js +1 -111
- package/src/swatch.css.dev.js.map +2 -2
- package/src/swatch.css.js +1 -111
- package/src/swatch.css.js.map +2 -2
- package/stories/swatch-group.stories.js +18 -18
- package/stories/swatch-group.stories.js.map +2 -2
- package/test/swatch-group.test.js +44 -2
- package/test/swatch-group.test.js.map +2 -2
package/custom-elements.json
CHANGED
|
@@ -390,6 +390,16 @@
|
|
|
390
390
|
"attribute": "border",
|
|
391
391
|
"reflects": true
|
|
392
392
|
},
|
|
393
|
+
{
|
|
394
|
+
"kind": "field",
|
|
395
|
+
"name": "density",
|
|
396
|
+
"type": {
|
|
397
|
+
"text": "'compact' | 'spacious' | undefined"
|
|
398
|
+
},
|
|
399
|
+
"privacy": "public",
|
|
400
|
+
"attribute": "density",
|
|
401
|
+
"reflects": true
|
|
402
|
+
},
|
|
393
403
|
{
|
|
394
404
|
"kind": "field",
|
|
395
405
|
"name": "rounding",
|
|
@@ -407,9 +417,17 @@
|
|
|
407
417
|
"text": "string[]"
|
|
408
418
|
},
|
|
409
419
|
"privacy": "public",
|
|
410
|
-
"default": "[]",
|
|
411
420
|
"attribute": "selected"
|
|
412
421
|
},
|
|
422
|
+
{
|
|
423
|
+
"kind": "field",
|
|
424
|
+
"name": "_selected",
|
|
425
|
+
"type": {
|
|
426
|
+
"text": "string[]"
|
|
427
|
+
},
|
|
428
|
+
"privacy": "private",
|
|
429
|
+
"default": "[]"
|
|
430
|
+
},
|
|
413
431
|
{
|
|
414
432
|
"kind": "field",
|
|
415
433
|
"name": "selects",
|
|
@@ -437,18 +455,16 @@
|
|
|
437
455
|
},
|
|
438
456
|
{
|
|
439
457
|
"kind": "field",
|
|
440
|
-
"name": "
|
|
458
|
+
"name": "swatches",
|
|
441
459
|
"type": {
|
|
442
|
-
"text": "
|
|
460
|
+
"text": "Swatch[]"
|
|
443
461
|
},
|
|
444
|
-
"privacy": "public"
|
|
445
|
-
"attribute": "density",
|
|
446
|
-
"reflects": true
|
|
462
|
+
"privacy": "public"
|
|
447
463
|
},
|
|
448
464
|
{
|
|
449
465
|
"kind": "field",
|
|
450
466
|
"name": "rovingTabindexController",
|
|
451
|
-
"default": "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: () =>
|
|
467
|
+
"default": "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.swatches,\n isFocusableElement: (el: Swatch) => !el.disabled,\n })"
|
|
452
468
|
},
|
|
453
469
|
{
|
|
454
470
|
"kind": "method",
|
|
@@ -545,6 +561,13 @@
|
|
|
545
561
|
},
|
|
546
562
|
"fieldName": "border"
|
|
547
563
|
},
|
|
564
|
+
{
|
|
565
|
+
"name": "density",
|
|
566
|
+
"type": {
|
|
567
|
+
"text": "'compact' | 'spacious' | undefined"
|
|
568
|
+
},
|
|
569
|
+
"fieldName": "density"
|
|
570
|
+
},
|
|
548
571
|
{
|
|
549
572
|
"name": "rounding",
|
|
550
573
|
"type": {
|
|
@@ -557,7 +580,6 @@
|
|
|
557
580
|
"type": {
|
|
558
581
|
"text": "string[]"
|
|
559
582
|
},
|
|
560
|
-
"default": "[]",
|
|
561
583
|
"fieldName": "selected"
|
|
562
584
|
},
|
|
563
585
|
{
|
|
@@ -573,13 +595,6 @@
|
|
|
573
595
|
"text": "SwatchShape"
|
|
574
596
|
},
|
|
575
597
|
"fieldName": "shape"
|
|
576
|
-
},
|
|
577
|
-
{
|
|
578
|
-
"name": "density",
|
|
579
|
-
"type": {
|
|
580
|
-
"text": "'compact' | 'spacious' | undefined"
|
|
581
|
-
},
|
|
582
|
-
"fieldName": "density"
|
|
583
598
|
}
|
|
584
599
|
],
|
|
585
600
|
"mixins": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/swatch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -67,16 +67,16 @@
|
|
|
67
67
|
],
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@lit-labs/observers": "^2.0.0",
|
|
70
|
-
"@spectrum-web-components/base": "^0.
|
|
71
|
-
"@spectrum-web-components/icon": "^0.
|
|
72
|
-
"@spectrum-web-components/icons-ui": "^0.
|
|
73
|
-
"@spectrum-web-components/opacity-checkerboard": "^0.
|
|
74
|
-
"@spectrum-web-components/reactive-controllers": "^0.
|
|
75
|
-
"@spectrum-web-components/shared": "^0.
|
|
70
|
+
"@spectrum-web-components/base": "^0.42.0",
|
|
71
|
+
"@spectrum-web-components/icon": "^0.42.0",
|
|
72
|
+
"@spectrum-web-components/icons-ui": "^0.42.0",
|
|
73
|
+
"@spectrum-web-components/opacity-checkerboard": "^0.42.0",
|
|
74
|
+
"@spectrum-web-components/reactive-controllers": "^0.42.0",
|
|
75
|
+
"@spectrum-web-components/shared": "^0.42.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@spectrum-css/swatch": "^5.1.
|
|
79
|
-
"@spectrum-css/swatchgroup": "^2.1.
|
|
78
|
+
"@spectrum-css/swatch": "^5.1.4",
|
|
79
|
+
"@spectrum-css/swatchgroup": "^2.1.4"
|
|
80
80
|
},
|
|
81
81
|
"types": "./src/index.d.ts",
|
|
82
82
|
"customElements": "custom-elements.json",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"./sp-*.js",
|
|
85
85
|
"./**/*.dev.js"
|
|
86
86
|
],
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "9b3bd55ff8e8f9438817255976e77fd456b19d72"
|
|
88
88
|
}
|
package/src/SwatchGroup.d.ts
CHANGED
|
@@ -15,12 +15,15 @@ declare const SwatchGroup_base: typeof SpectrumElement & {
|
|
|
15
15
|
export declare class SwatchGroup extends SwatchGroup_base {
|
|
16
16
|
static get styles(): CSSResultArray;
|
|
17
17
|
border: SwatchBorder;
|
|
18
|
+
density: 'compact' | 'spacious' | undefined;
|
|
18
19
|
rounding: SwatchRounding;
|
|
19
|
-
selected: string[];
|
|
20
|
+
get selected(): string[];
|
|
21
|
+
set selected(selected: string[]);
|
|
22
|
+
private _selected;
|
|
20
23
|
selects: SwatchSelects;
|
|
21
24
|
private selectedSet;
|
|
22
25
|
shape: SwatchShape;
|
|
23
|
-
|
|
26
|
+
swatches: Swatch[];
|
|
24
27
|
constructor();
|
|
25
28
|
rovingTabindexController: RovingTabindexController<Swatch>;
|
|
26
29
|
focus(options?: FocusOptions): void;
|
package/src/SwatchGroup.dev.js
CHANGED
|
@@ -15,7 +15,10 @@ import {
|
|
|
15
15
|
SizedMixin,
|
|
16
16
|
SpectrumElement
|
|
17
17
|
} from "@spectrum-web-components/base";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
property,
|
|
20
|
+
queryAssignedElements
|
|
21
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
|
19
22
|
import { RovingTabindexController } from "@spectrum-web-components/reactive-controllers/src/RovingTabindex.js";
|
|
20
23
|
import { MutationController } from "@lit-labs/observers/mutation-controller.js";
|
|
21
24
|
import styles from "./swatch-group.css.js";
|
|
@@ -25,7 +28,9 @@ export class SwatchGroup extends SizedMixin(SpectrumElement, {
|
|
|
25
28
|
}) {
|
|
26
29
|
constructor() {
|
|
27
30
|
super();
|
|
28
|
-
this
|
|
31
|
+
// Specifically surface `_selected` internally so that change can be made to this value internally
|
|
32
|
+
// without triggering the update lifecycle directly.
|
|
33
|
+
this._selected = [];
|
|
29
34
|
this.selectedSet = /* @__PURE__ */ new Set();
|
|
30
35
|
this.rovingTabindexController = new RovingTabindexController(this, {
|
|
31
36
|
focusInIndex: (elements) => {
|
|
@@ -38,14 +43,14 @@ export class SwatchGroup extends SizedMixin(SpectrumElement, {
|
|
|
38
43
|
});
|
|
39
44
|
return elements[firstSelectedIndex] ? firstSelectedIndex : firstEnabledIndex;
|
|
40
45
|
},
|
|
41
|
-
elements: () =>
|
|
46
|
+
elements: () => this.swatches,
|
|
42
47
|
isFocusableElement: (el) => !el.disabled
|
|
43
48
|
});
|
|
44
|
-
this.manageChange = () => {
|
|
49
|
+
this.manageChange = async () => {
|
|
45
50
|
const presentSet = /* @__PURE__ */ new Set();
|
|
46
51
|
this.selectedSet = new Set(this.selected);
|
|
47
|
-
|
|
48
|
-
swatches.forEach((swatch) => {
|
|
52
|
+
await Promise.all(this.swatches.map((swatch) => swatch.updateComplete));
|
|
53
|
+
this.swatches.forEach((swatch) => {
|
|
49
54
|
presentSet.add(swatch.value);
|
|
50
55
|
if (swatch.selected) {
|
|
51
56
|
this.selectedSet.add(swatch.value);
|
|
@@ -56,7 +61,8 @@ export class SwatchGroup extends SizedMixin(SpectrumElement, {
|
|
|
56
61
|
this.selectedSet.delete(value);
|
|
57
62
|
}
|
|
58
63
|
});
|
|
59
|
-
this.
|
|
64
|
+
this._selected = [...this.selectedSet];
|
|
65
|
+
this.rovingTabindexController.clearElementCache();
|
|
60
66
|
};
|
|
61
67
|
new MutationController(this, {
|
|
62
68
|
config: {
|
|
@@ -72,6 +78,16 @@ export class SwatchGroup extends SizedMixin(SpectrumElement, {
|
|
|
72
78
|
static get styles() {
|
|
73
79
|
return [styles];
|
|
74
80
|
}
|
|
81
|
+
get selected() {
|
|
82
|
+
return this._selected;
|
|
83
|
+
}
|
|
84
|
+
set selected(selected) {
|
|
85
|
+
if (selected === this.selected)
|
|
86
|
+
return;
|
|
87
|
+
const oldSelected = this.selected;
|
|
88
|
+
this._selected = selected;
|
|
89
|
+
this.requestUpdate("selected", oldSelected);
|
|
90
|
+
}
|
|
75
91
|
focus(options) {
|
|
76
92
|
this.rovingTabindexController.focus(options);
|
|
77
93
|
}
|
|
@@ -104,7 +120,7 @@ export class SwatchGroup extends SizedMixin(SpectrumElement, {
|
|
|
104
120
|
this.selectedSet.delete(target.value);
|
|
105
121
|
}
|
|
106
122
|
}
|
|
107
|
-
this.
|
|
123
|
+
this._selected = [...this.selectedSet];
|
|
108
124
|
const applyDefault = this.dispatchEvent(
|
|
109
125
|
new Event("change", {
|
|
110
126
|
cancelable: true,
|
|
@@ -112,7 +128,7 @@ export class SwatchGroup extends SizedMixin(SpectrumElement, {
|
|
|
112
128
|
})
|
|
113
129
|
);
|
|
114
130
|
if (!applyDefault) {
|
|
115
|
-
this.
|
|
131
|
+
this._selected = oldSelected;
|
|
116
132
|
event.preventDefault();
|
|
117
133
|
}
|
|
118
134
|
}
|
|
@@ -195,7 +211,7 @@ export class SwatchGroup extends SizedMixin(SpectrumElement, {
|
|
|
195
211
|
...this.getPassthroughSwatchActions(changes),
|
|
196
212
|
...this.getSelectionSwatchActions(changes)
|
|
197
213
|
];
|
|
198
|
-
|
|
214
|
+
let nextSelected = new Set(this.selected);
|
|
199
215
|
const currentValues = /* @__PURE__ */ new Set();
|
|
200
216
|
if (changes.has("selected")) {
|
|
201
217
|
swatchActions.push((swatch) => {
|
|
@@ -207,28 +223,44 @@ export class SwatchGroup extends SizedMixin(SpectrumElement, {
|
|
|
207
223
|
}
|
|
208
224
|
});
|
|
209
225
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
226
|
+
const doActions = () => {
|
|
227
|
+
nextSelected = new Set(this.selected);
|
|
228
|
+
this.swatches.forEach((swatch) => {
|
|
229
|
+
swatchActions.forEach((action) => {
|
|
230
|
+
action(swatch);
|
|
231
|
+
});
|
|
213
232
|
});
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
233
|
+
if (changes.has("selected")) {
|
|
234
|
+
this._selected = [...nextSelected.values()].filter(
|
|
235
|
+
(selectedValue) => currentValues.has(selectedValue)
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
if (this.hasUpdated) {
|
|
240
|
+
doActions();
|
|
241
|
+
} else {
|
|
242
|
+
this.shadowRoot.addEventListener(
|
|
243
|
+
"slotchange",
|
|
244
|
+
() => {
|
|
245
|
+
requestAnimationFrame(doActions);
|
|
246
|
+
},
|
|
247
|
+
{ once: true }
|
|
218
248
|
);
|
|
219
|
-
this.rovingTabindexController.clearElementCache();
|
|
220
249
|
}
|
|
221
250
|
}
|
|
222
251
|
}
|
|
223
252
|
__decorateClass([
|
|
224
253
|
property({ reflect: true })
|
|
225
254
|
], SwatchGroup.prototype, "border", 2);
|
|
255
|
+
__decorateClass([
|
|
256
|
+
property({ reflect: true })
|
|
257
|
+
], SwatchGroup.prototype, "density", 2);
|
|
226
258
|
__decorateClass([
|
|
227
259
|
property({ reflect: true })
|
|
228
260
|
], SwatchGroup.prototype, "rounding", 2);
|
|
229
261
|
__decorateClass([
|
|
230
262
|
property({ type: Array })
|
|
231
|
-
], SwatchGroup.prototype, "selected",
|
|
263
|
+
], SwatchGroup.prototype, "selected", 1);
|
|
232
264
|
__decorateClass([
|
|
233
265
|
property()
|
|
234
266
|
], SwatchGroup.prototype, "selects", 2);
|
|
@@ -236,6 +268,6 @@ __decorateClass([
|
|
|
236
268
|
property({ reflect: true })
|
|
237
269
|
], SwatchGroup.prototype, "shape", 2);
|
|
238
270
|
__decorateClass([
|
|
239
|
-
|
|
240
|
-
], SwatchGroup.prototype, "
|
|
271
|
+
queryAssignedElements({ flatten: true })
|
|
272
|
+
], SwatchGroup.prototype, "swatches", 2);
|
|
241
273
|
//# sourceMappingURL=SwatchGroup.dev.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 { 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.dev.js'\n\nexport type SwatchGroupSizes = Exclude<ElementSize, 'xxs' | 'xl' | 'xxl'>;\nexport type SwatchSelects = 'single' | 'multiple' | undefined;\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 noDefaultSize: true,\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 selected: string[] = [];\n\n @property()\n public selects: SwatchSelects;\n\n private selectedSet = new Set<string>();\n\n @property({ reflect: true })\n public shape: SwatchShape;\n\n @property({ reflect: true })\n public density: 'compact' | 'spacious' | undefined;\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 target.selected = true;\n if (this.selectedSet.has(target.value)) {\n return;\n }\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 selects?: SwatchSelects;\n } = {};\n if (\n changes.has('selects') &&\n (this.selects || typeof changes.get('selects') !== 'undefined')\n ) {\n targetValues.selects = this.selects;\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 !== 'm' || 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 (window.__swc.DEBUG) {\n if (\n 'selects' in targetValues &&\n targetValues.selects !== 'multiple' &&\n swatch.mixedValue\n ) {\n window.__swc.warn(\n this,\n `<sp-swatch> elements can only leverage the \"mixed-value\" attribute when their <sp-swatch-group> parent element is also leveraging \"selects=\"multiple\"\"`,\n 'https://opensource.adobe.com/spectrum-web-components/components/swatch-group/#multiple',\n {\n type: 'accessibility',\n }\n );\n }\n }\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 (\n nextSelected.has(swatch.value) ||\n (!this.hasUpdated && swatch.selected)\n ) {\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,EAGI;AAAA,EAEA;AAAA,EACA;AAAA,OAEG;AACP,
|
|
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 {\n property,\n queryAssignedElements,\n} 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.dev.js'\n\nexport type SwatchGroupSizes = Exclude<ElementSize, 'xxs' | 'xl' | 'xxl'>;\nexport type SwatchSelects = 'single' | 'multiple' | undefined;\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 noDefaultSize: true,\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 density: 'compact' | 'spacious' | undefined;\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\n const oldSelected = this.selected;\n this._selected = selected;\n this.requestUpdate('selected', oldSelected);\n }\n\n // Specifically surface `_selected` internally so that change can be made to this value internally\n // without triggering the update lifecycle directly.\n private _selected: string[] = [];\n\n @property()\n public selects: SwatchSelects;\n\n private selectedSet = new Set<string>();\n\n @property({ reflect: true })\n public shape: SwatchShape;\n\n @queryAssignedElements({ flatten: true })\n public swatches!: Swatch[];\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.swatches,\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 target.selected = true;\n if (this.selectedSet.has(target.value)) {\n return;\n }\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 = async (): Promise<void> => {\n const presentSet = new Set();\n this.selectedSet = new Set(this.selected);\n await Promise.all(this.swatches.map((swatch) => swatch.updateComplete));\n this.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 this.rovingTabindexController.clearElementCache();\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 selects?: SwatchSelects;\n } = {};\n if (\n changes.has('selects') &&\n (this.selects || typeof changes.get('selects') !== 'undefined')\n ) {\n targetValues.selects = this.selects;\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 !== 'm' || 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 (window.__swc.DEBUG) {\n if (\n 'selects' in targetValues &&\n targetValues.selects !== 'multiple' &&\n swatch.mixedValue\n ) {\n window.__swc.warn(\n this,\n `<sp-swatch> elements can only leverage the \"mixed-value\" attribute when their <sp-swatch-group> parent element is also leveraging \"selects=\"multiple\"\"`,\n 'https://opensource.adobe.com/spectrum-web-components/components/swatch-group/#multiple',\n {\n type: 'accessibility',\n }\n );\n }\n }\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 let 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 (\n nextSelected.has(swatch.value) ||\n (!this.hasUpdated && swatch.selected)\n ) {\n swatch.selected = true;\n } else {\n swatch.selected = false;\n }\n });\n }\n\n const doActions = (): void => {\n nextSelected = new Set(this.selected);\n\n // Do Swatch actions to each Swatch in the collection.\n this.swatches.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.values()].filter(\n (selectedValue) => currentValues.has(selectedValue)\n );\n }\n };\n\n if (this.hasUpdated) {\n // Do actions immediately when the element has already updated.\n doActions();\n } else {\n // On first update wait for a `slotchange` event, which is not currently managed\n // by the element lifecycle before allowing Swatch actions to be commited.\n this.shadowRoot.addEventListener(\n 'slotchange',\n () => {\n requestAnimationFrame(doActions);\n },\n { once: true }\n );\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAGI;AAAA,EAEA;AAAA,EACA;AAAA,OAEG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,gCAAgC;AACzC,SAAS,0BAA0B;AAEnC,OAAO,YAAY;AAgBZ,aAAM,oBAAoB,WAAW,iBAAiB;AAAA,EACzD,YAAY,CAAC,MAAM,KAAK,KAAK,GAAG;AAAA,EAChC,eAAe;AACnB,CAAC,EAAE;AAAA,EA0CC,cAAc;AACV,UAAM;AAdV;AAAA;AAAA,SAAQ,YAAsB,CAAC;AAK/B,SAAQ,cAAc,oBAAI,IAAY;AAuBtC,oCAA2B,IAAI,yBAAiC,MAAM;AAAA,MAClE,cAAc,CAAC,aAAuB;AAClC,YAAI,oBAAoB;AACxB,cAAM,qBAAqB,SAAS,UAAU,CAAC,IAAI,UAAU;AACzD,cAAI,CAAC,SAAS,iBAAiB,KAAK,CAAC,GAAG,UAAU;AAC9C,gCAAoB;AAAA,UACxB;AACA,iBAAO,GAAG,YAAY,CAAC,GAAG;AAAA,QAC9B,CAAC;AACD,eAAO,SAAS,kBAAkB,IAC5B,qBACA;AAAA,MACV;AAAA,MACA,UAAU,MAAM,KAAK;AAAA,MACrB,oBAAoB,CAAC,OAAe,CAAC,GAAG;AAAA,IAC5C,CAAC;AA+CD,SAAQ,eAAe,YAA2B;AAC9C,YAAM,aAAa,oBAAI,IAAI;AAC3B,WAAK,cAAc,IAAI,IAAI,KAAK,QAAQ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eF;AAGI;AAAA,EADV,SAAS,EAAE,MAAM,MAAM,CAAC;AAAA,GAjBhB,YAkBE;AAiBJ;AAAA,EADN,SAAS;AAAA,GAlCD,YAmCF;AAKA;AAAA,EADN,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,GAvClB,YAwCF;AAGA;AAAA,EADN,sBAAsB,EAAE,SAAS,KAAK,CAAC;AAAA,GA1C/B,YA2CF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/SwatchGroup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var a=(n,o,t,e)=>{for(var i=e>1?void 0:e?u(o,t):o,s=n.length-1,r;s>=0;s--)(r=n[s])&&(i=(e?r(o,t,i):r(i))||i);return e&&i&&h(o,t,i),i};import{html as p,SizedMixin as f,SpectrumElement as S}from"@spectrum-web-components/base";import{property as c,queryAssignedElements as g}from"@spectrum-web-components/base/src/decorators.js";import{RovingTabindexController as w}from"@spectrum-web-components/reactive-controllers/src/RovingTabindex.js";import{MutationController as m}from"@lit-labs/observers/mutation-controller.js";import b from"./swatch-group.css.js";export class SwatchGroup extends f(S,{validSizes:["xs","s","m","l"],noDefaultSize:!0}){constructor(){super();this._selected=[];this.selectedSet=new Set;this.rovingTabindexController=new w(this,{focusInIndex:t=>{let e=-1;const i=t.findIndex((s,r)=>(!t[e]&&!s.disabled&&(e=r),s.selected&&!s.disabled));return t[i]?i:e},elements:()=>this.swatches,isFocusableElement:t=>!t.disabled});this.manageChange=async()=>{const t=new Set;this.selectedSet=new Set(this.selected),await Promise.all(this.swatches.map(e=>e.updateComplete)),this.swatches.forEach(e=>{t.add(e.value),e.selected&&this.selectedSet.add(e.value)}),this.selectedSet.forEach(e=>{t.has(e)||this.selectedSet.delete(e)}),this._selected=[...this.selectedSet],this.rovingTabindexController.clearElementCache()};new m(this,{config:{attributes:!0,childList:!0,subtree:!0},callback:()=>{this.manageChange()}})}static get styles(){return[b]}get selected(){return this._selected}set selected(t){if(t===this.selected)return;const e=this.selected;this._selected=t,this.requestUpdate("selected",e)}focus(t){this.rovingTabindexController.focus(t)}handleChange(t){t.stopPropagation();const e=this.selected;if(!this.selects){t.preventDefault();return}if(this.selects==="single"){const{target:s}=t;if(s.tabIndex=0,s.selected=!0,this.selectedSet.has(s.value))return;this.selectedSet.clear(),this.selectedSet.add(s.value),this.rovingTabindexController.elements.forEach(r=>{r!==s&&(r.selected=!1)})}else if(this.selects==="multiple"){const{target:s}=t;s.selected?this.selectedSet.add(s.value):this.selectedSet.delete(s.value)}this._selected=[...this.selectedSet],this.dispatchEvent(new Event("change",{cancelable:!0,bubbles:!0}))||(this._selected=e,t.preventDefault())}getPassthroughSwatchActions(t){const e={};t.has("selects")&&(this.selects||typeof t.get("selects")!="undefined")&&(e.selects=this.selects),t.has("border")&&(this.border||typeof t.get("border")!="undefined")&&(e.border=this.border),t.has("rounding")&&(this.rounding||typeof t.get("rounding")!="undefined")&&(e.rounding=this.rounding),t.has("size")&&(this.size!=="m"||typeof t.get("size")!="undefined")&&(e.size=this.size),t.has("shape")&&(this.shape||typeof t.get("shape")!="undefined")&&(e.shape=this.shape);const i=[];return Object.keys(e).length&&i.push(s=>{"border"in e&&(s.border=e.border),"rounding"in e&&(s.rounding=e.rounding),"shape"in e&&(s.shape=e.shape),"size"in e&&(s.size=e.size)}),i}getSelectionSwatchActions(t){const e=[];if(!t.has("selects"))return e;this.selects?this.setAttribute("role",this.selects==="single"?"radiogroup":"group"):this.removeAttribute("role");const i={single:"radio",multiple:"checkbox"},s=this.selects?i[this.selects]:"button";return e.push(r=>{r.setAttribute("role",s)}),e}render(){return p`
|
|
2
2
|
<slot
|
|
3
3
|
@change=${this.handleChange}
|
|
4
4
|
@slotchange=${this.manageChange}
|
|
5
5
|
></slot>
|
|
6
|
-
`}willUpdate(
|
|
6
|
+
`}willUpdate(t){const e=[...this.getPassthroughSwatchActions(t),...this.getSelectionSwatchActions(t)];let i=new Set(this.selected);const s=new Set;t.has("selected")&&e.push(l=>{s.add(l.value),i.has(l.value)||!this.hasUpdated&&l.selected?l.selected=!0:l.selected=!1});const r=()=>{i=new Set(this.selected),this.swatches.forEach(l=>{e.forEach(d=>{d(l)})}),t.has("selected")&&(this._selected=[...i.values()].filter(l=>s.has(l)))};this.hasUpdated?r():this.shadowRoot.addEventListener("slotchange",()=>{requestAnimationFrame(r)},{once:!0})}}a([c({reflect:!0})],SwatchGroup.prototype,"border",2),a([c({reflect:!0})],SwatchGroup.prototype,"density",2),a([c({reflect:!0})],SwatchGroup.prototype,"rounding",2),a([c({type:Array})],SwatchGroup.prototype,"selected",1),a([c()],SwatchGroup.prototype,"selects",2),a([c({reflect:!0})],SwatchGroup.prototype,"shape",2),a([g({flatten:!0})],SwatchGroup.prototype,"swatches",2);
|
|
7
7
|
//# sourceMappingURL=SwatchGroup.js.map
|
package/src/SwatchGroup.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 { 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'>;\nexport type SwatchSelects = 'single' | 'multiple' | undefined;\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 noDefaultSize: true,\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 selected: string[] = [];\n\n @property()\n public selects: SwatchSelects;\n\n private selectedSet = new Set<string>();\n\n @property({ reflect: true })\n public shape: SwatchShape;\n\n @property({ reflect: true })\n public density: 'compact' | 'spacious' | undefined;\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 target.selected = true;\n if (this.selectedSet.has(target.value)) {\n return;\n }\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 selects?: SwatchSelects;\n } = {};\n if (\n changes.has('selects') &&\n (this.selects || typeof changes.get('selects') !== 'undefined')\n ) {\n targetValues.selects = this.selects;\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 !== 'm' || 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 (window.__swc.DEBUG) {\n if (\n 'selects' in targetValues &&\n targetValues.selects !== 'multiple' &&\n swatch.mixedValue\n ) {\n window.__swc.warn(\n this,\n `<sp-swatch> elements can only leverage the \"mixed-value\" attribute when their <sp-swatch-group> parent element is also leveraging \"selects=\"multiple\"\"`,\n 'https://opensource.adobe.com/spectrum-web-components/components/swatch-group/#multiple',\n {\n type: 'accessibility',\n }\n );\n }\n }\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 (\n nextSelected.has(swatch.value) ||\n (!this.hasUpdated && swatch.selected)\n ) {\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": "qNAYA,OAGI,QAAAA,EAEA,cAAAC,EACA,mBAAAC,MAEG,gCACP,
|
|
6
|
-
"names": ["html", "SizedMixin", "SpectrumElement", "property", "RovingTabindexController", "MutationController", "styles", "elements", "firstEnabledIndex", "firstSelectedIndex", "el", "index", "presentSet", "swatch", "value", "
|
|
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 {\n property,\n queryAssignedElements,\n} 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'>;\nexport type SwatchSelects = 'single' | 'multiple' | undefined;\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 noDefaultSize: true,\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 density: 'compact' | 'spacious' | undefined;\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\n const oldSelected = this.selected;\n this._selected = selected;\n this.requestUpdate('selected', oldSelected);\n }\n\n // Specifically surface `_selected` internally so that change can be made to this value internally\n // without triggering the update lifecycle directly.\n private _selected: string[] = [];\n\n @property()\n public selects: SwatchSelects;\n\n private selectedSet = new Set<string>();\n\n @property({ reflect: true })\n public shape: SwatchShape;\n\n @queryAssignedElements({ flatten: true })\n public swatches!: Swatch[];\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.swatches,\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 target.selected = true;\n if (this.selectedSet.has(target.value)) {\n return;\n }\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 = async (): Promise<void> => {\n const presentSet = new Set();\n this.selectedSet = new Set(this.selected);\n await Promise.all(this.swatches.map((swatch) => swatch.updateComplete));\n this.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 this.rovingTabindexController.clearElementCache();\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 selects?: SwatchSelects;\n } = {};\n if (\n changes.has('selects') &&\n (this.selects || typeof changes.get('selects') !== 'undefined')\n ) {\n targetValues.selects = this.selects;\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 !== 'm' || 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 (window.__swc.DEBUG) {\n if (\n 'selects' in targetValues &&\n targetValues.selects !== 'multiple' &&\n swatch.mixedValue\n ) {\n window.__swc.warn(\n this,\n `<sp-swatch> elements can only leverage the \"mixed-value\" attribute when their <sp-swatch-group> parent element is also leveraging \"selects=\"multiple\"\"`,\n 'https://opensource.adobe.com/spectrum-web-components/components/swatch-group/#multiple',\n {\n type: 'accessibility',\n }\n );\n }\n }\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 let 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 (\n nextSelected.has(swatch.value) ||\n (!this.hasUpdated && swatch.selected)\n ) {\n swatch.selected = true;\n } else {\n swatch.selected = false;\n }\n });\n }\n\n const doActions = (): void => {\n nextSelected = new Set(this.selected);\n\n // Do Swatch actions to each Swatch in the collection.\n this.swatches.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.values()].filter(\n (selectedValue) => currentValues.has(selectedValue)\n );\n }\n };\n\n if (this.hasUpdated) {\n // Do actions immediately when the element has already updated.\n doActions();\n } else {\n // On first update wait for a `slotchange` event, which is not currently managed\n // by the element lifecycle before allowing Swatch actions to be commited.\n this.shadowRoot.addEventListener(\n 'slotchange',\n () => {\n requestAnimationFrame(doActions);\n },\n { once: true }\n );\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "qNAYA,OAGI,QAAAA,EAEA,cAAAC,EACA,mBAAAC,MAEG,gCACP,OACI,YAAAC,EACA,yBAAAC,MACG,kDACP,OAAS,4BAAAC,MAAgC,sEACzC,OAAS,sBAAAC,MAA0B,6CAEnC,OAAOC,MAAY,wBAgBZ,aAAM,oBAAoBN,EAAWC,EAAiB,CACzD,WAAY,CAAC,KAAM,IAAK,IAAK,GAAG,EAChC,cAAe,EACnB,CAAC,CAAE,CA0CC,aAAc,CACV,MAAM,EAdV,KAAQ,UAAsB,CAAC,EAK/B,KAAQ,YAAc,IAAI,IAuB1B,8BAA2B,IAAIG,EAAiC,KAAM,CAClE,aAAeG,GAAuB,CAClC,IAAIC,EAAoB,GACxB,MAAMC,EAAqBF,EAAS,UAAU,CAACG,EAAIC,KAC3C,CAACJ,EAASC,CAAiB,GAAK,CAACE,EAAG,WACpCF,EAAoBG,GAEjBD,EAAG,UAAY,CAACA,EAAG,SAC7B,EACD,OAAOH,EAASE,CAAkB,EAC5BA,EACAD,CACV,EACA,SAAU,IAAM,KAAK,SACrB,mBAAqBE,GAAe,CAACA,EAAG,QAC5C,CAAC,EA+CD,KAAQ,aAAe,SAA2B,CAC9C,MAAME,EAAa,IAAI,IACvB,KAAK,YAAc,IAAI,IAAI,KAAK,QAAQ,EACxC,MAAM,QAAQ,IAAI,KAAK,SA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ApSWG,EAAA,CADN/B,EAAS,CAAE,QAAS,EAAK,CAAC,GARlB,YASF,sBAGA+B,EAAA,CADN/B,EAAS,CAAE,QAAS,EAAK,CAAC,GAXlB,YAYF,uBAGA+B,EAAA,CADN/B,EAAS,CAAE,QAAS,EAAK,CAAC,GAdlB,YAeF,wBAGI+B,EAAA,CADV/B,EAAS,CAAE,KAAM,KAAM,CAAC,GAjBhB,YAkBE,wBAiBJ+B,EAAA,CADN/B,EAAS,GAlCD,YAmCF,uBAKA+B,EAAA,CADN/B,EAAS,CAAE,QAAS,EAAK,CAAC,GAvClB,YAwCF,qBAGA+B,EAAA,CADN9B,EAAsB,CAAE,QAAS,EAAK,CAAC,GA1C/B,YA2CF",
|
|
6
|
+
"names": ["html", "SizedMixin", "SpectrumElement", "property", "queryAssignedElements", "RovingTabindexController", "MutationController", "styles", "elements", "firstEnabledIndex", "firstSelectedIndex", "el", "index", "presentSet", "swatch", "value", "selected", "oldSelected", "options", "event", "target", "child", "changes", "targetValues", "passThroughSwatchActions", "selectionSwatchActions", "swatchRoles", "swatchRole", "swatchActions", "nextSelected", "currentValues", "doActions", "action", "selectedValue", "__decorateClass"]
|
|
7
7
|
}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { css } from "@spectrum-web-components/base";
|
|
3
3
|
const styles = css`
|
|
4
|
-
:host{--spectrum-swatchgroup-spacing-compact:var(--spectrum-spacing-50);--spectrum-swatchgroup-spacing-regular:var(--spectrum-spacing-75);--spectrum-swatchgroup-spacing-spacious:var(--spectrum-spacing-100);align-items:flex-start;
|
|
5
|
-
--mod-swatchgroup-spacing-regular,var(--spectrum-swatchgroup-spacing-regular)
|
|
6
|
-
);justify-content:flex-start}:host([density=compact]){gap:var(
|
|
7
|
-
--mod-swatchgroup-spacing-compact,var(--spectrum-swatchgroup-spacing-compact)
|
|
8
|
-
)}:host([density=spacious]){gap:var(
|
|
9
|
-
--mod-swatchgroup-spacing-spacious,var(--spectrum-swatchgroup-spacing-spacious)
|
|
10
|
-
)}
|
|
4
|
+
:host{--spectrum-swatchgroup-spacing-compact:var(--spectrum-spacing-50);--spectrum-swatchgroup-spacing-regular:var(--spectrum-spacing-75);--spectrum-swatchgroup-spacing-spacious:var(--spectrum-spacing-100);justify-content:flex-start;align-items:flex-start;gap:var(--mod-swatchgroup-spacing-regular,var(--spectrum-swatchgroup-spacing-regular));flex-flow:wrap;display:inline-flex}:host([density=compact]){gap:var(--mod-swatchgroup-spacing-compact,var(--spectrum-swatchgroup-spacing-compact))}:host([density=spacious]){gap:var(--mod-swatchgroup-spacing-spacious,var(--spectrum-swatchgroup-spacing-spacious))}
|
|
11
5
|
`;
|
|
12
6
|
export default styles;
|
|
13
7
|
//# sourceMappingURL=spectrum-swatch-group.css.dev.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["spectrum-swatch-group.css.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2024 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{--spectrum-swatchgroup-spacing-compact:var(--spectrum-spacing-50);--spectrum-swatchgroup-spacing-regular:var(--spectrum-spacing-75);--spectrum-swatchgroup-spacing-spacious:var(--spectrum-spacing-100);
|
|
5
|
-
"mappings": ";AAWA,SAAS,WAAW;AACpB,MAAM,SAAS;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2024 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{--spectrum-swatchgroup-spacing-compact:var(--spectrum-spacing-50);--spectrum-swatchgroup-spacing-regular:var(--spectrum-spacing-75);--spectrum-swatchgroup-spacing-spacious:var(--spectrum-spacing-100);justify-content:flex-start;align-items:flex-start;gap:var(--mod-swatchgroup-spacing-regular,var(--spectrum-swatchgroup-spacing-regular));flex-flow:wrap;display:inline-flex}:host([density=compact]){gap:var(--mod-swatchgroup-spacing-compact,var(--spectrum-swatchgroup-spacing-compact))}:host([density=spacious]){gap:var(--mod-swatchgroup-spacing-spacious,var(--spectrum-swatchgroup-spacing-spacious))}\n`;\nexport default styles;"],
|
|
5
|
+
"mappings": ";AAWA,SAAS,WAAW;AACpB,MAAM,SAAS;AAAA;AAAA;AAGf,eAAe;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
"use strict";import{css as s}from"@spectrum-web-components/base";const a=s`
|
|
2
|
-
:host{--spectrum-swatchgroup-spacing-compact:var(--spectrum-spacing-50);--spectrum-swatchgroup-spacing-regular:var(--spectrum-spacing-75);--spectrum-swatchgroup-spacing-spacious:var(--spectrum-spacing-100);align-items:flex-start;
|
|
3
|
-
--mod-swatchgroup-spacing-regular,var(--spectrum-swatchgroup-spacing-regular)
|
|
4
|
-
);justify-content:flex-start}:host([density=compact]){gap:var(
|
|
5
|
-
--mod-swatchgroup-spacing-compact,var(--spectrum-swatchgroup-spacing-compact)
|
|
6
|
-
)}:host([density=spacious]){gap:var(
|
|
7
|
-
--mod-swatchgroup-spacing-spacious,var(--spectrum-swatchgroup-spacing-spacious)
|
|
8
|
-
)}
|
|
2
|
+
:host{--spectrum-swatchgroup-spacing-compact:var(--spectrum-spacing-50);--spectrum-swatchgroup-spacing-regular:var(--spectrum-spacing-75);--spectrum-swatchgroup-spacing-spacious:var(--spectrum-spacing-100);justify-content:flex-start;align-items:flex-start;gap:var(--mod-swatchgroup-spacing-regular,var(--spectrum-swatchgroup-spacing-regular));flex-flow:wrap;display:inline-flex}:host([density=compact]){gap:var(--mod-swatchgroup-spacing-compact,var(--spectrum-swatchgroup-spacing-compact))}:host([density=spacious]){gap:var(--mod-swatchgroup-spacing-spacious,var(--spectrum-swatchgroup-spacing-spacious))}
|
|
9
3
|
`;export default a;
|
|
10
4
|
//# sourceMappingURL=spectrum-swatch-group.css.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["spectrum-swatch-group.css.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2024 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{--spectrum-swatchgroup-spacing-compact:var(--spectrum-spacing-50);--spectrum-swatchgroup-spacing-regular:var(--spectrum-spacing-75);--spectrum-swatchgroup-spacing-spacious:var(--spectrum-spacing-100);
|
|
5
|
-
"mappings": "aAWA,OAAS,OAAAA,MAAW,gCACpB,MAAMC,EAASD;AAAA;AAAA
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2024 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{--spectrum-swatchgroup-spacing-compact:var(--spectrum-spacing-50);--spectrum-swatchgroup-spacing-regular:var(--spectrum-spacing-75);--spectrum-swatchgroup-spacing-spacious:var(--spectrum-spacing-100);justify-content:flex-start;align-items:flex-start;gap:var(--mod-swatchgroup-spacing-regular,var(--spectrum-swatchgroup-spacing-regular));flex-flow:wrap;display:inline-flex}:host([density=compact]){gap:var(--mod-swatchgroup-spacing-compact,var(--spectrum-swatchgroup-spacing-compact))}:host([density=spacious]){gap:var(--mod-swatchgroup-spacing-spacious,var(--spectrum-swatchgroup-spacing-spacious))}\n`;\nexport default styles;"],
|
|
5
|
+
"mappings": "aAWA,OAAS,OAAAA,MAAW,gCACpB,MAAMC,EAASD;AAAA;AAAA,EAGf,eAAeC",
|
|
6
6
|
"names": ["css", "styles"]
|
|
7
7
|
}
|