@spectrum-web-components/picker 0.11.5 → 0.11.6-devmode.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/package.json +38 -21
- package/sp-picker.dev.js +3 -0
- package/sp-picker.dev.js.map +7 -0
- package/sp-picker.js +3 -14
- package/sp-picker.js.map +7 -1
- package/src/Picker.dev.js +501 -0
- package/src/Picker.dev.js.map +7 -0
- package/src/Picker.js +405 -434
- package/src/Picker.js.map +7 -1
- package/src/index.dev.js +2 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -13
- package/src/index.js.map +7 -1
- package/src/picker.css.dev.js +304 -0
- package/src/picker.css.dev.js.map +7 -0
- package/src/picker.css.js +3 -14
- package/src/picker.css.js.map +7 -1
- package/src/spectrum-picker.css.dev.js +300 -0
- package/src/spectrum-picker.css.dev.js.map +7 -0
- package/src/spectrum-picker.css.js +3 -14
- package/src/spectrum-picker.css.js.map +7 -1
- package/stories/picker-sizes.stories.js +22 -30
- package/stories/picker-sizes.stories.js.map +7 -1
- package/stories/picker.stories.js +84 -95
- package/stories/picker.stories.js.map +7 -1
- package/stories/states.js +225 -236
- package/stories/states.js.map +7 -1
- package/sync/index.dev.js +8 -0
- package/sync/index.dev.js.map +7 -0
- package/sync/index.js +6 -15
- package/sync/index.js.map +7 -1
- package/sync/sp-picker.dev.js +3 -0
- package/sync/sp-picker.dev.js.map +7 -0
- package/sync/sp-picker.js +3 -14
- package/sync/sp-picker.js.map +7 -1
- package/test/benchmark/basic-test.js +256 -267
- package/test/benchmark/basic-test.js.map +7 -1
- package/test/index.js +830 -844
- package/test/index.js.map +7 -1
- package/test/picker-reparenting.test.js +71 -76
- package/test/picker-reparenting.test.js.map +7 -1
- package/test/picker-responsive.test.js +41 -53
- package/test/picker-responsive.test.js.map +7 -1
- package/test/picker-sizes.test-vrt.js +4 -15
- package/test/picker-sizes.test-vrt.js.map +7 -1
- package/test/picker-sync.test.js +5 -16
- package/test/picker-sync.test.js.map +7 -1
- package/test/picker.test-vrt.js +4 -15
- package/test/picker.test-vrt.js.map +7 -1
- package/test/picker.test.js +5 -16
- package/test/picker.test.js.map +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/picker",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.6-devmode.0+07474d44f",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -20,15 +20,32 @@
|
|
|
20
20
|
"module": "src/index.js",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
|
-
".":
|
|
24
|
-
|
|
23
|
+
".": {
|
|
24
|
+
"development": "./src/index.dev.js",
|
|
25
|
+
"default": "./src/index.js"
|
|
26
|
+
},
|
|
25
27
|
"./package.json": "./package.json",
|
|
26
|
-
"./
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"./
|
|
31
|
-
|
|
28
|
+
"./src/Picker.js": {
|
|
29
|
+
"development": "./src/Picker.dev.js",
|
|
30
|
+
"default": "./src/Picker.js"
|
|
31
|
+
},
|
|
32
|
+
"./src/index.js": {
|
|
33
|
+
"development": "./src/index.dev.js",
|
|
34
|
+
"default": "./src/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./src/picker.css.js": "./src/picker.css.js",
|
|
37
|
+
"./sync/index.js": {
|
|
38
|
+
"development": "./sync/index.dev.js",
|
|
39
|
+
"default": "./sync/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./sync/sp-picker.js": {
|
|
42
|
+
"development": "./sync/sp-picker.dev.js",
|
|
43
|
+
"default": "./sync/sp-picker.js"
|
|
44
|
+
},
|
|
45
|
+
"./sp-picker.js": {
|
|
46
|
+
"development": "./sp-picker.dev.js",
|
|
47
|
+
"default": "./sp-picker.js"
|
|
48
|
+
}
|
|
32
49
|
},
|
|
33
50
|
"scripts": {
|
|
34
51
|
"test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
|
|
@@ -48,17 +65,17 @@
|
|
|
48
65
|
"lit-html"
|
|
49
66
|
],
|
|
50
67
|
"dependencies": {
|
|
51
|
-
"@spectrum-web-components/base": "^0.5.
|
|
52
|
-
"@spectrum-web-components/button": "^0.18.0",
|
|
53
|
-
"@spectrum-web-components/icon": "^0.11.
|
|
54
|
-
"@spectrum-web-components/icons-ui": "^0.8.
|
|
55
|
-
"@spectrum-web-components/icons-workflow": "^0.8.
|
|
56
|
-
"@spectrum-web-components/menu": "^0.14.
|
|
57
|
-
"@spectrum-web-components/overlay": "^0.16.
|
|
58
|
-
"@spectrum-web-components/popover": "^0.11.
|
|
59
|
-
"@spectrum-web-components/reactive-controllers": "^0.2.
|
|
60
|
-
"@spectrum-web-components/shared": "^0.14.
|
|
61
|
-
"@spectrum-web-components/tray": "^0.3.
|
|
68
|
+
"@spectrum-web-components/base": "^0.5.9-devmode.24+07474d44f",
|
|
69
|
+
"@spectrum-web-components/button": "^0.18.1-devmode.0+07474d44f",
|
|
70
|
+
"@spectrum-web-components/icon": "^0.11.12-devmode.0+07474d44f",
|
|
71
|
+
"@spectrum-web-components/icons-ui": "^0.8.12-devmode.0+07474d44f",
|
|
72
|
+
"@spectrum-web-components/icons-workflow": "^0.8.12-devmode.0+07474d44f",
|
|
73
|
+
"@spectrum-web-components/menu": "^0.14.5-devmode.0+07474d44f",
|
|
74
|
+
"@spectrum-web-components/overlay": "^0.16.6-devmode.0+07474d44f",
|
|
75
|
+
"@spectrum-web-components/popover": "^0.11.17-devmode.0+07474d44f",
|
|
76
|
+
"@spectrum-web-components/reactive-controllers": "^0.2.5-devmode.79+07474d44f",
|
|
77
|
+
"@spectrum-web-components/shared": "^0.14.5-devmode.0+07474d44f",
|
|
78
|
+
"@spectrum-web-components/tray": "^0.3.12-devmode.0+07474d44f",
|
|
62
79
|
"tslib": "^2.0.0"
|
|
63
80
|
},
|
|
64
81
|
"devDependencies": {
|
|
@@ -71,5 +88,5 @@
|
|
|
71
88
|
"./sync/index.js",
|
|
72
89
|
"./sync/sp-*.js"
|
|
73
90
|
],
|
|
74
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "07474d44f6cee1db241b9ccf3dc812514ffbe7fa"
|
|
75
92
|
}
|
package/sp-picker.dev.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-picker.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 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 { Picker } from './src/Picker.dev.js'\n\ncustomElements.define('sp-picker', Picker);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-picker': Picker;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAYA;AAEA,eAAe,OAAO,aAAa,MAAM;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-picker.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 { Picker } from './src/Picker.js';
|
|
13
|
-
customElements.define('sp-picker', Picker);
|
|
14
|
-
//# sourceMappingURL=sp-picker.js.map
|
|
1
|
+
import { Picker } from "./src/Picker.js";
|
|
2
|
+
customElements.define("sp-picker", Picker);
|
|
3
|
+
//# sourceMappingURL=sp-picker.js.map
|
package/sp-picker.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-picker.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 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 { Picker } from './src/Picker.js';\n\ncustomElements.define('sp-picker', Picker);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-picker': Picker;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAYA;AAEA,eAAe,OAAO,aAAa,MAAM;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
html,
|
|
14
|
+
nothing,
|
|
15
|
+
render,
|
|
16
|
+
SizedMixin
|
|
17
|
+
} from "@spectrum-web-components/base";
|
|
18
|
+
import { classMap } from "@spectrum-web-components/base/src/directives.js";
|
|
19
|
+
import {
|
|
20
|
+
property,
|
|
21
|
+
query
|
|
22
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
|
23
|
+
import pickerStyles from "./picker.css.js";
|
|
24
|
+
import chevronStyles from "@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";
|
|
25
|
+
import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
|
|
26
|
+
import { reparentChildren } from "@spectrum-web-components/shared/src/reparent-children.js";
|
|
27
|
+
import "@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js";
|
|
28
|
+
import "@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js";
|
|
29
|
+
import "@spectrum-web-components/menu/sp-menu.js";
|
|
30
|
+
import "@spectrum-web-components/tray/sp-tray.js";
|
|
31
|
+
import "@spectrum-web-components/popover/sp-popover.js";
|
|
32
|
+
import {
|
|
33
|
+
openOverlay
|
|
34
|
+
} from "@spectrum-web-components/overlay";
|
|
35
|
+
import {
|
|
36
|
+
IS_MOBILE,
|
|
37
|
+
MatchMediaController
|
|
38
|
+
} from "@spectrum-web-components/reactive-controllers/src/MatchMedia.js";
|
|
39
|
+
const chevronClass = {
|
|
40
|
+
s: "spectrum-UIIcon-ChevronDown75",
|
|
41
|
+
m: "spectrum-UIIcon-ChevronDown100",
|
|
42
|
+
l: "spectrum-UIIcon-ChevronDown200",
|
|
43
|
+
xl: "spectrum-UIIcon-ChevronDown300"
|
|
44
|
+
};
|
|
45
|
+
export class PickerBase extends SizedMixin(Focusable) {
|
|
46
|
+
constructor() {
|
|
47
|
+
super();
|
|
48
|
+
this.isMobile = new MatchMediaController(this, IS_MOBILE);
|
|
49
|
+
this.disabled = false;
|
|
50
|
+
this.focused = false;
|
|
51
|
+
this.invalid = false;
|
|
52
|
+
this.open = false;
|
|
53
|
+
this.readonly = false;
|
|
54
|
+
this.selects = "single";
|
|
55
|
+
this.menuItems = [];
|
|
56
|
+
this.placement = "bottom-start";
|
|
57
|
+
this.quiet = false;
|
|
58
|
+
this.value = "";
|
|
59
|
+
this.listRole = "listbox";
|
|
60
|
+
this.itemRole = "option";
|
|
61
|
+
this.onKeydown = (event) => {
|
|
62
|
+
this.focused = true;
|
|
63
|
+
if (event.code !== "ArrowDown" && event.code !== "ArrowUp") {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
this.toggle(true);
|
|
68
|
+
};
|
|
69
|
+
this.overlayOpenCallback = async () => {
|
|
70
|
+
this.updateMenuItems();
|
|
71
|
+
await this.itemsUpdated;
|
|
72
|
+
await this.optionsMenu.updateComplete;
|
|
73
|
+
requestAnimationFrame(() => this.menuStateResolver());
|
|
74
|
+
};
|
|
75
|
+
this.overlayCloseCallback = async () => {
|
|
76
|
+
if (this.restoreChildren) {
|
|
77
|
+
this.restoreChildren();
|
|
78
|
+
this.restoreChildren = void 0;
|
|
79
|
+
}
|
|
80
|
+
this.close();
|
|
81
|
+
requestAnimationFrame(() => this.menuStateResolver());
|
|
82
|
+
};
|
|
83
|
+
this._willUpdateItems = false;
|
|
84
|
+
this.itemsUpdated = Promise.resolve();
|
|
85
|
+
this.menuStatePromise = Promise.resolve();
|
|
86
|
+
this.selectionPromise = Promise.resolve();
|
|
87
|
+
this.onKeydown = this.onKeydown.bind(this);
|
|
88
|
+
}
|
|
89
|
+
get target() {
|
|
90
|
+
return this.button;
|
|
91
|
+
}
|
|
92
|
+
get focusElement() {
|
|
93
|
+
if (this.open) {
|
|
94
|
+
return this.optionsMenu;
|
|
95
|
+
}
|
|
96
|
+
return this.button;
|
|
97
|
+
}
|
|
98
|
+
forceFocusVisible() {
|
|
99
|
+
this.focused = true;
|
|
100
|
+
}
|
|
101
|
+
onButtonBlur() {
|
|
102
|
+
this.focused = false;
|
|
103
|
+
this.target.removeEventListener("keydown", this.onKeydown);
|
|
104
|
+
}
|
|
105
|
+
onButtonClick() {
|
|
106
|
+
this.toggle();
|
|
107
|
+
}
|
|
108
|
+
focus(options) {
|
|
109
|
+
super.focus(options);
|
|
110
|
+
if (!this.disabled && this.focusElement) {
|
|
111
|
+
this.focused = this.hasVisibleFocusInTree();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
onHelperFocus() {
|
|
115
|
+
this.focused = true;
|
|
116
|
+
this.button.focus();
|
|
117
|
+
}
|
|
118
|
+
onButtonFocus() {
|
|
119
|
+
this.target.addEventListener("keydown", this.onKeydown);
|
|
120
|
+
}
|
|
121
|
+
handleChange(event) {
|
|
122
|
+
event.stopPropagation();
|
|
123
|
+
const target = event.target;
|
|
124
|
+
const [selected] = target.selectedItems;
|
|
125
|
+
this.setValueFromItem(selected, event);
|
|
126
|
+
}
|
|
127
|
+
async setValueFromItem(item, menuChangeEvent) {
|
|
128
|
+
const oldSelectedItem = this.selectedItem;
|
|
129
|
+
const oldValue = this.value;
|
|
130
|
+
this.selectedItem = item;
|
|
131
|
+
this.value = item.value;
|
|
132
|
+
this.open = false;
|
|
133
|
+
await this.updateComplete;
|
|
134
|
+
const applyDefault = this.dispatchEvent(new Event("change", {
|
|
135
|
+
bubbles: true,
|
|
136
|
+
cancelable: true,
|
|
137
|
+
composed: true
|
|
138
|
+
}));
|
|
139
|
+
if (!applyDefault) {
|
|
140
|
+
if (menuChangeEvent) {
|
|
141
|
+
menuChangeEvent.preventDefault();
|
|
142
|
+
}
|
|
143
|
+
this.selectedItem.selected = false;
|
|
144
|
+
if (oldSelectedItem) {
|
|
145
|
+
oldSelectedItem.selected = true;
|
|
146
|
+
}
|
|
147
|
+
this.selectedItem = oldSelectedItem;
|
|
148
|
+
this.value = oldValue;
|
|
149
|
+
this.open = true;
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (oldSelectedItem) {
|
|
153
|
+
oldSelectedItem.selected = false;
|
|
154
|
+
}
|
|
155
|
+
item.selected = !!this.selects;
|
|
156
|
+
}
|
|
157
|
+
toggle(target) {
|
|
158
|
+
if (this.readonly) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.open = typeof target !== "undefined" ? target : !this.open;
|
|
162
|
+
}
|
|
163
|
+
close() {
|
|
164
|
+
if (this.readonly) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
this.open = false;
|
|
168
|
+
}
|
|
169
|
+
async generatePopover(deprecatedMenu) {
|
|
170
|
+
if (!this.popoverFragment) {
|
|
171
|
+
this.popoverFragment = document.createDocumentFragment();
|
|
172
|
+
}
|
|
173
|
+
render(this.renderPopover, this.popoverFragment, { host: this });
|
|
174
|
+
this.popover = this.popoverFragment.children[0];
|
|
175
|
+
this.optionsMenu = this.popover.children[1];
|
|
176
|
+
if (true) {
|
|
177
|
+
if (deprecatedMenu) {
|
|
178
|
+
const { localName } = this;
|
|
179
|
+
window.__swc.issueWarning(`${localName}:api:deprecation`, `You no longer need to provide an sp-menu child to ${localName}. Any styling or attributes on the sp-menu will be ignored.`, "https://opensource.adobe.com/spectrum-web-components/components/picker/#sizes");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async openMenu() {
|
|
184
|
+
let reparentableChildren = [];
|
|
185
|
+
const deprecatedMenu = this.querySelector(":scope > sp-menu");
|
|
186
|
+
await this.generatePopover(deprecatedMenu);
|
|
187
|
+
if (deprecatedMenu) {
|
|
188
|
+
reparentableChildren = Array.from(deprecatedMenu.children);
|
|
189
|
+
} else {
|
|
190
|
+
reparentableChildren = Array.from(this.children).filter((element) => {
|
|
191
|
+
return !element.hasAttribute("slot");
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (reparentableChildren.length === 0) {
|
|
195
|
+
this.menuStateResolver();
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
this.restoreChildren = reparentChildren(reparentableChildren, this.optionsMenu, {
|
|
199
|
+
position: "beforeend",
|
|
200
|
+
prepareCallback: (el) => {
|
|
201
|
+
if (this.value === el.value) {
|
|
202
|
+
el.selected = true;
|
|
203
|
+
}
|
|
204
|
+
return (el2) => {
|
|
205
|
+
if (typeof el2.focused !== "undefined") {
|
|
206
|
+
el2.focused = false;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
this.sizePopover(this.popover);
|
|
212
|
+
this.closeOverlay = Picker.openOverlay(this, "modal", this.popover, {
|
|
213
|
+
placement: this.isMobile.matches ? "none" : this.placement,
|
|
214
|
+
receivesFocus: "auto"
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
sizePopover(popover) {
|
|
218
|
+
if (this.isMobile.matches) {
|
|
219
|
+
popover.style.setProperty("--swc-menu-width", `100%`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (this.quiet)
|
|
223
|
+
return;
|
|
224
|
+
popover.style.setProperty("min-width", `${this.offsetWidth}px`);
|
|
225
|
+
}
|
|
226
|
+
async closeMenu() {
|
|
227
|
+
if (this.closeOverlay) {
|
|
228
|
+
const closeOverlay = this.closeOverlay;
|
|
229
|
+
delete this.closeOverlay;
|
|
230
|
+
(await closeOverlay)();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
get selectedItemContent() {
|
|
234
|
+
if (this.selectedItem) {
|
|
235
|
+
return this.selectedItem.itemChildren;
|
|
236
|
+
}
|
|
237
|
+
return { icon: [], content: [] };
|
|
238
|
+
}
|
|
239
|
+
renderLabelContent(content) {
|
|
240
|
+
if (this.value && this.selectedItem) {
|
|
241
|
+
return content;
|
|
242
|
+
}
|
|
243
|
+
return html`
|
|
244
|
+
<slot name="label">${this.label}</slot>
|
|
245
|
+
`;
|
|
246
|
+
}
|
|
247
|
+
get buttonContent() {
|
|
248
|
+
const labelClasses = {
|
|
249
|
+
"visually-hidden": this.icons === "only" && !!this.value,
|
|
250
|
+
placeholder: !this.value
|
|
251
|
+
};
|
|
252
|
+
return [
|
|
253
|
+
html`
|
|
254
|
+
<span id="icon" ?hidden=${this.icons === "none"}>
|
|
255
|
+
${this.selectedItemContent.icon}
|
|
256
|
+
</span>
|
|
257
|
+
<span id="label" class=${classMap(labelClasses)}>
|
|
258
|
+
${this.renderLabelContent(this.selectedItemContent.content)}
|
|
259
|
+
</span>
|
|
260
|
+
${this.invalid ? html`
|
|
261
|
+
<sp-icon-alert
|
|
262
|
+
class="validation-icon"
|
|
263
|
+
></sp-icon-alert>
|
|
264
|
+
` : nothing}
|
|
265
|
+
<sp-icon-chevron100
|
|
266
|
+
class="picker ${chevronClass[this.size]}"
|
|
267
|
+
></sp-icon-chevron100>
|
|
268
|
+
`
|
|
269
|
+
];
|
|
270
|
+
}
|
|
271
|
+
render() {
|
|
272
|
+
return html`
|
|
273
|
+
<span
|
|
274
|
+
id="focus-helper"
|
|
275
|
+
tabindex="${this.focused ? "-1" : "0"}"
|
|
276
|
+
@focus=${this.onHelperFocus}
|
|
277
|
+
></span>
|
|
278
|
+
<button
|
|
279
|
+
aria-haspopup="true"
|
|
280
|
+
aria-expanded=${this.open ? "true" : "false"}
|
|
281
|
+
aria-labelledby="button icon label"
|
|
282
|
+
id="button"
|
|
283
|
+
class="button"
|
|
284
|
+
@blur=${this.onButtonBlur}
|
|
285
|
+
@click=${this.onButtonClick}
|
|
286
|
+
@focus=${this.onButtonFocus}
|
|
287
|
+
?disabled=${this.disabled}
|
|
288
|
+
tabindex="-1"
|
|
289
|
+
>
|
|
290
|
+
${this.buttonContent}
|
|
291
|
+
</button>
|
|
292
|
+
`;
|
|
293
|
+
}
|
|
294
|
+
update(changes) {
|
|
295
|
+
if (this.selects) {
|
|
296
|
+
this.selects = "single";
|
|
297
|
+
}
|
|
298
|
+
if (changes.has("disabled") && this.disabled) {
|
|
299
|
+
this.open = false;
|
|
300
|
+
}
|
|
301
|
+
if (changes.has("open") && (this.open || typeof changes.get("open") !== "undefined")) {
|
|
302
|
+
this.menuStatePromise = new Promise((res) => this.menuStateResolver = res);
|
|
303
|
+
if (this.open) {
|
|
304
|
+
this.openMenu();
|
|
305
|
+
} else {
|
|
306
|
+
this.closeMenu();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (changes.has("value") && !changes.has("selectedItem")) {
|
|
310
|
+
this.updateMenuItems();
|
|
311
|
+
}
|
|
312
|
+
super.update(changes);
|
|
313
|
+
}
|
|
314
|
+
get dismissHelper() {
|
|
315
|
+
return html`
|
|
316
|
+
<div class="visually-hidden">
|
|
317
|
+
<button
|
|
318
|
+
tabindex="-1"
|
|
319
|
+
arial-label="Dismiss"
|
|
320
|
+
@click=${this.close}
|
|
321
|
+
></button>
|
|
322
|
+
</div>
|
|
323
|
+
`;
|
|
324
|
+
}
|
|
325
|
+
get renderPopover() {
|
|
326
|
+
const content = html`
|
|
327
|
+
${this.dismissHelper}
|
|
328
|
+
<sp-menu
|
|
329
|
+
id="menu"
|
|
330
|
+
role="${this.listRole}"
|
|
331
|
+
@change=${this.handleChange}
|
|
332
|
+
.selects=${this.selects}
|
|
333
|
+
></sp-menu>
|
|
334
|
+
${this.dismissHelper}
|
|
335
|
+
`;
|
|
336
|
+
if (this.isMobile.matches) {
|
|
337
|
+
return html`
|
|
338
|
+
<sp-tray
|
|
339
|
+
id="popover"
|
|
340
|
+
role="dialog"
|
|
341
|
+
@sp-menu-item-added-or-updated=${this.updateMenuItems}
|
|
342
|
+
.overlayOpenCallback=${this.overlayOpenCallback}
|
|
343
|
+
.overlayCloseCallback=${this.overlayCloseCallback}
|
|
344
|
+
>
|
|
345
|
+
${content}
|
|
346
|
+
</sp-tray>
|
|
347
|
+
`;
|
|
348
|
+
}
|
|
349
|
+
return html`
|
|
350
|
+
<sp-popover
|
|
351
|
+
id="popover"
|
|
352
|
+
role="dialog"
|
|
353
|
+
@sp-menu-item-added-or-updated=${this.updateMenuItems}
|
|
354
|
+
.overlayOpenCallback=${this.overlayOpenCallback}
|
|
355
|
+
.overlayCloseCallback=${this.overlayCloseCallback}
|
|
356
|
+
>
|
|
357
|
+
${content}
|
|
358
|
+
</sp-popover>
|
|
359
|
+
`;
|
|
360
|
+
}
|
|
361
|
+
updateMenuItems(event) {
|
|
362
|
+
if (this.open && (event == null ? void 0 : event.type) === "sp-menu-item-removed")
|
|
363
|
+
return;
|
|
364
|
+
if (this._willUpdateItems)
|
|
365
|
+
return;
|
|
366
|
+
this._willUpdateItems = true;
|
|
367
|
+
if ((event == null ? void 0 : event.item) === this.selectedItem) {
|
|
368
|
+
this.requestUpdate();
|
|
369
|
+
}
|
|
370
|
+
let resolve = () => {
|
|
371
|
+
return;
|
|
372
|
+
};
|
|
373
|
+
this.itemsUpdated = new Promise((res) => resolve = res);
|
|
374
|
+
window.requestAnimationFrame(async () => {
|
|
375
|
+
if (this.open) {
|
|
376
|
+
await this.optionsMenu.updateComplete;
|
|
377
|
+
this.menuItems = this.optionsMenu.childItems;
|
|
378
|
+
} else {
|
|
379
|
+
this.menuItems = [
|
|
380
|
+
...this.querySelectorAll("sp-menu-item")
|
|
381
|
+
];
|
|
382
|
+
}
|
|
383
|
+
this.manageSelection();
|
|
384
|
+
resolve();
|
|
385
|
+
this._willUpdateItems = false;
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
async manageSelection() {
|
|
389
|
+
await this.menuStatePromise;
|
|
390
|
+
this.selectionPromise = new Promise((res) => this.selectionResolver = res);
|
|
391
|
+
let selectedItem;
|
|
392
|
+
this.menuItems.forEach((item) => {
|
|
393
|
+
if (this.value === item.value && !item.disabled) {
|
|
394
|
+
selectedItem = item;
|
|
395
|
+
} else {
|
|
396
|
+
item.selected = false;
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
if (selectedItem) {
|
|
400
|
+
selectedItem.selected = !!this.selects;
|
|
401
|
+
this.selectedItem = selectedItem;
|
|
402
|
+
} else {
|
|
403
|
+
this.value = "";
|
|
404
|
+
this.selectedItem = void 0;
|
|
405
|
+
}
|
|
406
|
+
if (this.open) {
|
|
407
|
+
await this.optionsMenu.updateComplete;
|
|
408
|
+
this.optionsMenu.updateSelectedItemIndex();
|
|
409
|
+
}
|
|
410
|
+
this.selectionResolver();
|
|
411
|
+
}
|
|
412
|
+
async getUpdateComplete() {
|
|
413
|
+
const complete = await super.getUpdateComplete();
|
|
414
|
+
await this.menuStatePromise;
|
|
415
|
+
await this.itemsUpdated;
|
|
416
|
+
await this.selectionPromise;
|
|
417
|
+
return complete;
|
|
418
|
+
}
|
|
419
|
+
connectedCallback() {
|
|
420
|
+
this.updateMenuItems();
|
|
421
|
+
this.addEventListener("sp-menu-item-added-or-updated", this.updateMenuItems);
|
|
422
|
+
this.addEventListener("sp-menu-item-removed", this.updateMenuItems);
|
|
423
|
+
super.connectedCallback();
|
|
424
|
+
}
|
|
425
|
+
disconnectedCallback() {
|
|
426
|
+
this.close();
|
|
427
|
+
super.disconnectedCallback();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
PickerBase.openOverlay = async (target, interaction, content, options) => {
|
|
431
|
+
return await openOverlay(target, interaction, content, options);
|
|
432
|
+
};
|
|
433
|
+
__decorateClass([
|
|
434
|
+
query("#button")
|
|
435
|
+
], PickerBase.prototype, "button", 2);
|
|
436
|
+
__decorateClass([
|
|
437
|
+
property({ type: Boolean, reflect: true })
|
|
438
|
+
], PickerBase.prototype, "disabled", 2);
|
|
439
|
+
__decorateClass([
|
|
440
|
+
property({ type: Boolean, reflect: true })
|
|
441
|
+
], PickerBase.prototype, "focused", 2);
|
|
442
|
+
__decorateClass([
|
|
443
|
+
property({ type: String, reflect: true })
|
|
444
|
+
], PickerBase.prototype, "icons", 2);
|
|
445
|
+
__decorateClass([
|
|
446
|
+
property({ type: Boolean, reflect: true })
|
|
447
|
+
], PickerBase.prototype, "invalid", 2);
|
|
448
|
+
__decorateClass([
|
|
449
|
+
property()
|
|
450
|
+
], PickerBase.prototype, "label", 2);
|
|
451
|
+
__decorateClass([
|
|
452
|
+
property({ type: Boolean, reflect: true })
|
|
453
|
+
], PickerBase.prototype, "open", 2);
|
|
454
|
+
__decorateClass([
|
|
455
|
+
property({ type: Boolean, reflect: true })
|
|
456
|
+
], PickerBase.prototype, "readonly", 2);
|
|
457
|
+
__decorateClass([
|
|
458
|
+
property()
|
|
459
|
+
], PickerBase.prototype, "placement", 2);
|
|
460
|
+
__decorateClass([
|
|
461
|
+
property({ type: Boolean, reflect: true })
|
|
462
|
+
], PickerBase.prototype, "quiet", 2);
|
|
463
|
+
__decorateClass([
|
|
464
|
+
property({ type: String })
|
|
465
|
+
], PickerBase.prototype, "value", 2);
|
|
466
|
+
__decorateClass([
|
|
467
|
+
property({ attribute: false })
|
|
468
|
+
], PickerBase.prototype, "selectedItem", 2);
|
|
469
|
+
export class Picker extends PickerBase {
|
|
470
|
+
constructor() {
|
|
471
|
+
super(...arguments);
|
|
472
|
+
this.onKeydown = (event) => {
|
|
473
|
+
const { code } = event;
|
|
474
|
+
this.focused = true;
|
|
475
|
+
if (!code.startsWith("Arrow") || this.readonly) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
event.preventDefault();
|
|
479
|
+
if (code === "ArrowUp" || code === "ArrowDown") {
|
|
480
|
+
this.toggle(true);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const selectedIndex = this.selectedItem ? this.menuItems.indexOf(this.selectedItem) : -1;
|
|
484
|
+
const nextOffset = !this.value || code === "ArrowRight" ? 1 : -1;
|
|
485
|
+
let nextIndex = selectedIndex + nextOffset;
|
|
486
|
+
while (this.menuItems[nextIndex] && this.menuItems[nextIndex].disabled) {
|
|
487
|
+
nextIndex += nextOffset;
|
|
488
|
+
}
|
|
489
|
+
if (!this.menuItems[nextIndex] || this.menuItems[nextIndex].disabled) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (!this.value || nextIndex !== selectedIndex) {
|
|
493
|
+
this.setValueFromItem(this.menuItems[nextIndex]);
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
static get styles() {
|
|
498
|
+
return [pickerStyles, chevronStyles];
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
//# sourceMappingURL=Picker.dev.js.map
|