@spectrum-web-components/action-button 0.35.1-rc.41 → 0.36.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 +361 -0
- package/package.json +8 -8
- package/src/ActionButton.d.ts +2 -2
- package/src/ActionButton.dev.js +7 -29
- package/src/ActionButton.dev.js.map +2 -2
- package/src/ActionButton.js +2 -2
- package/src/ActionButton.js.map +2 -2
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": "1.0.0",
|
|
3
|
+
"readme": "",
|
|
4
|
+
"modules": [
|
|
5
|
+
{
|
|
6
|
+
"kind": "javascript-module",
|
|
7
|
+
"path": "sp-action-button.js",
|
|
8
|
+
"declarations": [],
|
|
9
|
+
"exports": [
|
|
10
|
+
{
|
|
11
|
+
"kind": "custom-element-definition",
|
|
12
|
+
"name": "sp-action-button",
|
|
13
|
+
"declaration": {
|
|
14
|
+
"name": "ActionButton",
|
|
15
|
+
"module": "/src/ActionButton.js"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"kind": "javascript-module",
|
|
22
|
+
"path": "src/ActionButton.js",
|
|
23
|
+
"declarations": [
|
|
24
|
+
{
|
|
25
|
+
"kind": "variable",
|
|
26
|
+
"name": "LONGPRESS_DURATION",
|
|
27
|
+
"type": {
|
|
28
|
+
"text": "number"
|
|
29
|
+
},
|
|
30
|
+
"default": "300"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"kind": "class",
|
|
34
|
+
"description": "",
|
|
35
|
+
"name": "ActionButton",
|
|
36
|
+
"slots": [
|
|
37
|
+
{
|
|
38
|
+
"description": "text label of the Action Button",
|
|
39
|
+
"name": ""
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"description": "The icon to use for Action Button",
|
|
43
|
+
"name": "icon"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"members": [
|
|
47
|
+
{
|
|
48
|
+
"kind": "field",
|
|
49
|
+
"name": "emphasized",
|
|
50
|
+
"type": {
|
|
51
|
+
"text": "boolean"
|
|
52
|
+
},
|
|
53
|
+
"privacy": "public",
|
|
54
|
+
"default": "false",
|
|
55
|
+
"attribute": "emphasized",
|
|
56
|
+
"reflects": true
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"kind": "field",
|
|
60
|
+
"name": "holdAffordance",
|
|
61
|
+
"type": {
|
|
62
|
+
"text": "boolean"
|
|
63
|
+
},
|
|
64
|
+
"privacy": "public",
|
|
65
|
+
"default": "false",
|
|
66
|
+
"attribute": "hold-affordance",
|
|
67
|
+
"reflects": true
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"kind": "field",
|
|
71
|
+
"name": "quiet",
|
|
72
|
+
"type": {
|
|
73
|
+
"text": "boolean"
|
|
74
|
+
},
|
|
75
|
+
"privacy": "public",
|
|
76
|
+
"default": "false",
|
|
77
|
+
"attribute": "quiet",
|
|
78
|
+
"reflects": true
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"kind": "field",
|
|
82
|
+
"name": "role",
|
|
83
|
+
"type": {
|
|
84
|
+
"text": "string"
|
|
85
|
+
},
|
|
86
|
+
"privacy": "public",
|
|
87
|
+
"default": "'button'",
|
|
88
|
+
"attribute": "role",
|
|
89
|
+
"reflects": true
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"kind": "field",
|
|
93
|
+
"name": "selected",
|
|
94
|
+
"type": {
|
|
95
|
+
"text": "boolean"
|
|
96
|
+
},
|
|
97
|
+
"privacy": "public",
|
|
98
|
+
"default": "false",
|
|
99
|
+
"description": "Whether an Action Button with `role='button'`\nshould also be `aria-pressed='true'`",
|
|
100
|
+
"attribute": "selected",
|
|
101
|
+
"reflects": true
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"kind": "field",
|
|
105
|
+
"name": "toggles",
|
|
106
|
+
"type": {
|
|
107
|
+
"text": "boolean"
|
|
108
|
+
},
|
|
109
|
+
"privacy": "public",
|
|
110
|
+
"default": "false",
|
|
111
|
+
"description": "Whether to automatically manage the `selected`\nattribute on interaction and whether `aria-pressed=\"false\"`\nshould be used when `selected === false`",
|
|
112
|
+
"attribute": "toggles",
|
|
113
|
+
"reflects": true
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"kind": "field",
|
|
117
|
+
"name": "static",
|
|
118
|
+
"type": {
|
|
119
|
+
"text": "'white' | 'black' | undefined"
|
|
120
|
+
},
|
|
121
|
+
"privacy": "public",
|
|
122
|
+
"attribute": "static",
|
|
123
|
+
"reflects": true
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"kind": "field",
|
|
127
|
+
"name": "variant",
|
|
128
|
+
"type": {
|
|
129
|
+
"text": "'white' | 'black' | undefined"
|
|
130
|
+
},
|
|
131
|
+
"privacy": "public",
|
|
132
|
+
"attribute": "variant",
|
|
133
|
+
"reflects": true
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"kind": "field",
|
|
137
|
+
"name": "value",
|
|
138
|
+
"type": {
|
|
139
|
+
"text": "string"
|
|
140
|
+
},
|
|
141
|
+
"privacy": "public",
|
|
142
|
+
"attribute": "value"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"kind": "field",
|
|
146
|
+
"name": "_value",
|
|
147
|
+
"type": {
|
|
148
|
+
"text": "string"
|
|
149
|
+
},
|
|
150
|
+
"privacy": "private",
|
|
151
|
+
"default": "''"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"kind": "field",
|
|
155
|
+
"name": "itemText",
|
|
156
|
+
"type": {
|
|
157
|
+
"text": "string"
|
|
158
|
+
},
|
|
159
|
+
"privacy": "private",
|
|
160
|
+
"readonly": true
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"kind": "field",
|
|
164
|
+
"name": "onClick",
|
|
165
|
+
"privacy": "private"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"kind": "method",
|
|
169
|
+
"name": "onPointerdown",
|
|
170
|
+
"privacy": "private",
|
|
171
|
+
"return": {
|
|
172
|
+
"type": {
|
|
173
|
+
"text": "void"
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
"parameters": [
|
|
177
|
+
{
|
|
178
|
+
"name": "event",
|
|
179
|
+
"type": {
|
|
180
|
+
"text": "PointerEvent"
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"kind": "method",
|
|
187
|
+
"name": "onPointerup",
|
|
188
|
+
"privacy": "private",
|
|
189
|
+
"return": {
|
|
190
|
+
"type": {
|
|
191
|
+
"text": "void"
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"kind": "method",
|
|
197
|
+
"name": "handleKeydown",
|
|
198
|
+
"privacy": "private",
|
|
199
|
+
"return": {
|
|
200
|
+
"type": {
|
|
201
|
+
"text": "void"
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
"parameters": [
|
|
205
|
+
{
|
|
206
|
+
"name": "event",
|
|
207
|
+
"type": {
|
|
208
|
+
"text": "KeyboardEvent"
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"kind": "method",
|
|
215
|
+
"name": "handleKeyup",
|
|
216
|
+
"privacy": "protected",
|
|
217
|
+
"return": {
|
|
218
|
+
"type": {
|
|
219
|
+
"text": "void"
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
"parameters": [
|
|
223
|
+
{
|
|
224
|
+
"name": "event",
|
|
225
|
+
"type": {
|
|
226
|
+
"text": "KeyboardEvent"
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
"kind": "field",
|
|
233
|
+
"name": "buttonContent",
|
|
234
|
+
"type": {
|
|
235
|
+
"text": "TemplateResult[]"
|
|
236
|
+
},
|
|
237
|
+
"privacy": "protected",
|
|
238
|
+
"readonly": true
|
|
239
|
+
}
|
|
240
|
+
],
|
|
241
|
+
"events": [
|
|
242
|
+
{
|
|
243
|
+
"name": "longpress",
|
|
244
|
+
"type": {
|
|
245
|
+
"text": "CustomEvent"
|
|
246
|
+
},
|
|
247
|
+
"description": "Synthesizes a \"longpress\" interaction that signifies a `pointerdown` event that is >=300ms or a keyboard event wher code is `Space` or code is `ArrowDown` while `altKey===true`."
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"description": "Announces a change in the `selected` property of an action button",
|
|
251
|
+
"name": "change"
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
"attributes": [
|
|
255
|
+
{
|
|
256
|
+
"name": "emphasized",
|
|
257
|
+
"type": {
|
|
258
|
+
"text": "boolean"
|
|
259
|
+
},
|
|
260
|
+
"default": "false",
|
|
261
|
+
"fieldName": "emphasized"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"name": "hold-affordance",
|
|
265
|
+
"type": {
|
|
266
|
+
"text": "boolean"
|
|
267
|
+
},
|
|
268
|
+
"default": "false",
|
|
269
|
+
"fieldName": "holdAffordance"
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
"name": "quiet",
|
|
273
|
+
"type": {
|
|
274
|
+
"text": "boolean"
|
|
275
|
+
},
|
|
276
|
+
"default": "false",
|
|
277
|
+
"fieldName": "quiet"
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
"name": "role",
|
|
281
|
+
"type": {
|
|
282
|
+
"text": "string"
|
|
283
|
+
},
|
|
284
|
+
"default": "'button'",
|
|
285
|
+
"fieldName": "role"
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"name": "selected",
|
|
289
|
+
"type": {
|
|
290
|
+
"text": "boolean"
|
|
291
|
+
},
|
|
292
|
+
"default": "false",
|
|
293
|
+
"description": "Whether an Action Button with `role='button'`\nshould also be `aria-pressed='true'`",
|
|
294
|
+
"fieldName": "selected"
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
"name": "toggles",
|
|
298
|
+
"type": {
|
|
299
|
+
"text": "boolean"
|
|
300
|
+
},
|
|
301
|
+
"default": "false",
|
|
302
|
+
"description": "Whether to automatically manage the `selected`\nattribute on interaction and whether `aria-pressed=\"false\"`\nshould be used when `selected === false`",
|
|
303
|
+
"fieldName": "toggles"
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
"name": "static",
|
|
307
|
+
"type": {
|
|
308
|
+
"text": "'white' | 'black' | undefined"
|
|
309
|
+
},
|
|
310
|
+
"fieldName": "static"
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
"name": "variant",
|
|
314
|
+
"type": {
|
|
315
|
+
"text": "'white' | 'black' | undefined"
|
|
316
|
+
},
|
|
317
|
+
"fieldName": "variant"
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
"name": "value",
|
|
321
|
+
"type": {
|
|
322
|
+
"text": "string"
|
|
323
|
+
},
|
|
324
|
+
"fieldName": "value"
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
"mixins": [
|
|
328
|
+
{
|
|
329
|
+
"name": "SizedMixin",
|
|
330
|
+
"package": "@spectrum-web-components/base"
|
|
331
|
+
}
|
|
332
|
+
],
|
|
333
|
+
"superclass": {
|
|
334
|
+
"name": "ButtonBase",
|
|
335
|
+
"package": "@spectrum-web-components/button"
|
|
336
|
+
},
|
|
337
|
+
"tagName": "sp-action-button",
|
|
338
|
+
"customElement": true
|
|
339
|
+
}
|
|
340
|
+
],
|
|
341
|
+
"exports": [
|
|
342
|
+
{
|
|
343
|
+
"kind": "js",
|
|
344
|
+
"name": "LONGPRESS_DURATION",
|
|
345
|
+
"declaration": {
|
|
346
|
+
"name": "LONGPRESS_DURATION",
|
|
347
|
+
"module": "src/ActionButton.js"
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
"kind": "js",
|
|
352
|
+
"name": "ActionButton",
|
|
353
|
+
"declaration": {
|
|
354
|
+
"name": "ActionButton",
|
|
355
|
+
"module": "src/ActionButton.js"
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
]
|
|
359
|
+
}
|
|
360
|
+
]
|
|
361
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/action-button",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -57,14 +57,14 @@
|
|
|
57
57
|
"lit-html"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@spectrum-web-components/base": "^0.
|
|
61
|
-
"@spectrum-web-components/button": "^0.
|
|
62
|
-
"@spectrum-web-components/icon": "^0.
|
|
63
|
-
"@spectrum-web-components/icons-ui": "^0.
|
|
64
|
-
"@spectrum-web-components/shared": "^0.
|
|
60
|
+
"@spectrum-web-components/base": "^0.36.0",
|
|
61
|
+
"@spectrum-web-components/button": "^0.36.0",
|
|
62
|
+
"@spectrum-web-components/icon": "^0.36.0",
|
|
63
|
+
"@spectrum-web-components/icons-ui": "^0.36.0",
|
|
64
|
+
"@spectrum-web-components/shared": "^0.36.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@spectrum-css/actionbutton": "^4.0.
|
|
67
|
+
"@spectrum-css/actionbutton": "^4.0.13"
|
|
68
68
|
},
|
|
69
69
|
"types": "./src/index.d.ts",
|
|
70
70
|
"customElements": "custom-elements.json",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"./sp-*.js",
|
|
73
73
|
"./**/*.dev.js"
|
|
74
74
|
],
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "a532ff8a410abeefb54d9638a2316ae82570566e"
|
|
76
76
|
}
|
package/src/ActionButton.d.ts
CHANGED
|
@@ -47,8 +47,8 @@ export declare class ActionButton extends ActionButton_base {
|
|
|
47
47
|
get itemText(): string;
|
|
48
48
|
constructor();
|
|
49
49
|
private onClick;
|
|
50
|
-
private
|
|
51
|
-
private
|
|
50
|
+
private onPointerdown;
|
|
51
|
+
private onPointerup;
|
|
52
52
|
/**
|
|
53
53
|
* @private
|
|
54
54
|
*/
|
package/src/ActionButton.dev.js
CHANGED
|
@@ -55,6 +55,7 @@ export class ActionButton extends SizedMixin(ButtonBase, {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
this.addEventListener("click", this.onClick);
|
|
58
|
+
this.addEventListener("pointerdown", this.onPointerdown);
|
|
58
59
|
}
|
|
59
60
|
static get styles() {
|
|
60
61
|
return [...super.styles, buttonStyles, cornerTriangleStyles];
|
|
@@ -80,14 +81,11 @@ export class ActionButton extends SizedMixin(ButtonBase, {
|
|
|
80
81
|
return (this.textContent || /* c8 ignore next */
|
|
81
82
|
"").trim();
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
+
onPointerdown(event) {
|
|
84
85
|
if (event.button !== 0)
|
|
85
86
|
return;
|
|
86
|
-
this.addEventListener("pointerup", this.
|
|
87
|
-
this.addEventListener(
|
|
88
|
-
"pointercancel",
|
|
89
|
-
this.handlePointerupHoldAffordance
|
|
90
|
-
);
|
|
87
|
+
this.addEventListener("pointerup", this.onPointerup);
|
|
88
|
+
this.addEventListener("pointercancel", this.onPointerup);
|
|
91
89
|
LONGPRESS_TIMEOUT = setTimeout(() => {
|
|
92
90
|
this.dispatchEvent(
|
|
93
91
|
new CustomEvent("longpress", {
|
|
@@ -100,16 +98,10 @@ export class ActionButton extends SizedMixin(ButtonBase, {
|
|
|
100
98
|
);
|
|
101
99
|
}, LONGPRESS_DURATION);
|
|
102
100
|
}
|
|
103
|
-
|
|
101
|
+
onPointerup() {
|
|
104
102
|
clearTimeout(LONGPRESS_TIMEOUT);
|
|
105
|
-
this.removeEventListener(
|
|
106
|
-
|
|
107
|
-
this.handlePointerupHoldAffordance
|
|
108
|
-
);
|
|
109
|
-
this.removeEventListener(
|
|
110
|
-
"pointercancel",
|
|
111
|
-
this.handlePointerupHoldAffordance
|
|
112
|
-
);
|
|
103
|
+
this.removeEventListener("pointerup", this.onPointerup);
|
|
104
|
+
this.removeEventListener("pointercancel", this.onPointerup);
|
|
113
105
|
}
|
|
114
106
|
/**
|
|
115
107
|
* @private
|
|
@@ -189,20 +181,6 @@ export class ActionButton extends SizedMixin(ButtonBase, {
|
|
|
189
181
|
);
|
|
190
182
|
}
|
|
191
183
|
}
|
|
192
|
-
if (changes.has("holdAffordance")) {
|
|
193
|
-
if (this.holdAffordance) {
|
|
194
|
-
this.addEventListener(
|
|
195
|
-
"pointerdown",
|
|
196
|
-
this.handlePointerdownHoldAffordance
|
|
197
|
-
);
|
|
198
|
-
} else {
|
|
199
|
-
this.removeEventListener(
|
|
200
|
-
"pointerdown",
|
|
201
|
-
this.handlePointerdownHoldAffordance
|
|
202
|
-
);
|
|
203
|
-
this.handlePointerupHoldAffordance();
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
184
|
}
|
|
207
185
|
}
|
|
208
186
|
__decorateClass([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["ActionButton.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 {\n CSSResultArray,\n DefaultElementSize,\n html,\n PropertyValues,\n SizedMixin,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { ButtonBase } from '@spectrum-web-components/button';\nimport buttonStyles from './action-button.css.js';\nimport cornerTriangleStyles from '@spectrum-web-components/icon/src/spectrum-icon-corner-triangle.css.js';\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-corner-triangle300.js';\n\nconst holdAffordanceClass = {\n xs: 'spectrum-UIIcon-CornerTriangle75',\n s: 'spectrum-UIIcon-CornerTriangle75',\n m: 'spectrum-UIIcon-CornerTriangle100',\n l: 'spectrum-UIIcon-CornerTriangle200',\n xl: 'spectrum-UIIcon-CornerTriangle300',\n};\n\nexport const LONGPRESS_DURATION = 300;\nlet LONGPRESS_TIMEOUT: ReturnType<typeof setTimeout>;\n\nexport type LongpressEvent = {\n source: 'pointer' | 'keyboard';\n};\n\n/**\n * @element sp-action-button\n *\n * @slot - text label of the Action Button\n * @slot icon - The icon to use for Action Button\n * @fires change - Announces a change in the `selected` property of an action button\n * @fires longpress - Synthesizes a \"longpress\" interaction that signifies a\n * `pointerdown` event that is >=300ms or a keyboard event wher code is `Space` or code is `ArrowDown`\n * while `altKey===true`.\n */\nexport class ActionButton extends SizedMixin(ButtonBase, {\n validSizes: ['xs', 's', 'm', 'l', 'xl'],\n}) {\n public static override get styles(): CSSResultArray {\n return [...super.styles, buttonStyles, cornerTriangleStyles];\n }\n\n @property({ type: Boolean, reflect: true })\n public emphasized = false;\n\n @property({ type: Boolean, reflect: true, attribute: 'hold-affordance' })\n public holdAffordance = false;\n\n @property({ type: Boolean, reflect: true })\n public quiet = false;\n\n @property({ reflect: true })\n public role = 'button';\n\n /**\n * Whether an Action Button with `role='button'`\n * should also be `aria-pressed='true'`\n */\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n /**\n * Whether to automatically manage the `selected`\n * attribute on interaction and whether `aria-pressed=\"false\"`\n * should be used when `selected === false`\n */\n @property({ type: Boolean, reflect: true })\n public toggles = false;\n\n @property({ reflect: true })\n public static?: 'white' | 'black';\n\n @property({ reflect: true })\n public variant?: 'white' | 'black';\n\n @property({ type: String })\n public get value(): string {\n return this._value || this.itemText;\n }\n public set value(value: string) {\n if (value === this._value) {\n return;\n }\n this._value = value || '';\n if (this._value) {\n this.setAttribute('value', this._value);\n } else {\n this.removeAttribute('value');\n }\n }\n private _value = '';\n\n /**\n * @private\n */\n public get itemText(): string {\n return (this.textContent || /* c8 ignore next */ '').trim();\n }\n\n constructor() {\n super();\n this.addEventListener('click', this.onClick);\n }\n\n private onClick = (): void => {\n if (!this.toggles) {\n return;\n }\n this.selected = !this.selected;\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n cancelable: true,\n })\n );\n if (!applyDefault) {\n this.selected = !this.selected;\n }\n };\n\n private
|
|
5
|
-
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAGI;AAAA,EAEA;AAAA,OAEG;AACP,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,OAAO,kBAAkB;AACzB,OAAO,0BAA0B;AACjC,OAAO;AAEP,MAAM,sBAAsB;AAAA,EACxB,IAAI;AAAA,EACJ,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,IAAI;AACR;AAEO,aAAM,qBAAqB;AAClC,IAAI;AAgBG,aAAM,qBAAqB,WAAW,YAAY;AAAA,EACrD,YAAY,CAAC,MAAM,KAAK,KAAK,KAAK,IAAI;AAC1C,CAAC,EAAE;AAAA,EA8DC,cAAc;AACV,UAAM;AAzDV,SAAO,aAAa;AAGpB,SAAO,iBAAiB;AAGxB,SAAO,QAAQ;AAGf,SAAO,OAAO;AAOd,SAAO,WAAW;AAQlB,SAAO,UAAU;AAuBjB,SAAQ,SAAS;
|
|
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 {\n CSSResultArray,\n DefaultElementSize,\n html,\n PropertyValues,\n SizedMixin,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { ButtonBase } from '@spectrum-web-components/button';\nimport buttonStyles from './action-button.css.js';\nimport cornerTriangleStyles from '@spectrum-web-components/icon/src/spectrum-icon-corner-triangle.css.js';\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-corner-triangle300.js';\n\nconst holdAffordanceClass = {\n xs: 'spectrum-UIIcon-CornerTriangle75',\n s: 'spectrum-UIIcon-CornerTriangle75',\n m: 'spectrum-UIIcon-CornerTriangle100',\n l: 'spectrum-UIIcon-CornerTriangle200',\n xl: 'spectrum-UIIcon-CornerTriangle300',\n};\n\nexport const LONGPRESS_DURATION = 300;\nlet LONGPRESS_TIMEOUT: ReturnType<typeof setTimeout>;\n\nexport type LongpressEvent = {\n source: 'pointer' | 'keyboard';\n};\n\n/**\n * @element sp-action-button\n *\n * @slot - text label of the Action Button\n * @slot icon - The icon to use for Action Button\n * @fires change - Announces a change in the `selected` property of an action button\n * @fires longpress - Synthesizes a \"longpress\" interaction that signifies a\n * `pointerdown` event that is >=300ms or a keyboard event wher code is `Space` or code is `ArrowDown`\n * while `altKey===true`.\n */\nexport class ActionButton extends SizedMixin(ButtonBase, {\n validSizes: ['xs', 's', 'm', 'l', 'xl'],\n}) {\n public static override get styles(): CSSResultArray {\n return [...super.styles, buttonStyles, cornerTriangleStyles];\n }\n\n @property({ type: Boolean, reflect: true })\n public emphasized = false;\n\n @property({ type: Boolean, reflect: true, attribute: 'hold-affordance' })\n public holdAffordance = false;\n\n @property({ type: Boolean, reflect: true })\n public quiet = false;\n\n @property({ reflect: true })\n public role = 'button';\n\n /**\n * Whether an Action Button with `role='button'`\n * should also be `aria-pressed='true'`\n */\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n /**\n * Whether to automatically manage the `selected`\n * attribute on interaction and whether `aria-pressed=\"false\"`\n * should be used when `selected === false`\n */\n @property({ type: Boolean, reflect: true })\n public toggles = false;\n\n @property({ reflect: true })\n public static?: 'white' | 'black';\n\n @property({ reflect: true })\n public variant?: 'white' | 'black';\n\n @property({ type: String })\n public get value(): string {\n return this._value || this.itemText;\n }\n public set value(value: string) {\n if (value === this._value) {\n return;\n }\n this._value = value || '';\n if (this._value) {\n this.setAttribute('value', this._value);\n } else {\n this.removeAttribute('value');\n }\n }\n private _value = '';\n\n /**\n * @private\n */\n public get itemText(): string {\n return (this.textContent || /* c8 ignore next */ '').trim();\n }\n\n constructor() {\n super();\n this.addEventListener('click', this.onClick);\n this.addEventListener('pointerdown', this.onPointerdown);\n }\n\n private onClick = (): void => {\n if (!this.toggles) {\n return;\n }\n this.selected = !this.selected;\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n cancelable: true,\n })\n );\n if (!applyDefault) {\n this.selected = !this.selected;\n }\n };\n\n private onPointerdown(event: PointerEvent): void {\n if (event.button !== 0) return;\n this.addEventListener('pointerup', this.onPointerup);\n this.addEventListener('pointercancel', this.onPointerup);\n LONGPRESS_TIMEOUT = setTimeout(() => {\n this.dispatchEvent(\n new CustomEvent<LongpressEvent>('longpress', {\n bubbles: true,\n composed: true,\n detail: {\n source: 'pointer',\n },\n })\n );\n }, LONGPRESS_DURATION);\n }\n\n private onPointerup(): void {\n clearTimeout(LONGPRESS_TIMEOUT);\n this.removeEventListener('pointerup', this.onPointerup);\n this.removeEventListener('pointercancel', this.onPointerup);\n }\n\n /**\n * @private\n */\n protected override handleKeydown(event: KeyboardEvent): void {\n if (!this.holdAffordance) {\n return super.handleKeydown(event);\n }\n const { code, altKey } = event;\n if (code === 'Space' || (altKey && code === 'ArrowDown')) {\n event.preventDefault();\n if (code === 'ArrowDown') {\n event.stopPropagation();\n event.stopImmediatePropagation();\n }\n this.addEventListener('keyup', this.handleKeyup);\n this.active = true;\n }\n }\n\n protected override handleKeyup(event: KeyboardEvent): void {\n if (!this.holdAffordance) {\n return super.handleKeyup(event);\n }\n const { code, altKey } = event;\n if (code === 'Space' || (altKey && code === 'ArrowDown')) {\n event.stopPropagation();\n this.dispatchEvent(\n new CustomEvent<LongpressEvent>('longpress', {\n bubbles: true,\n composed: true,\n detail: {\n source: 'keyboard',\n },\n })\n );\n this.active = false;\n }\n }\n\n protected override get buttonContent(): TemplateResult[] {\n const buttonContent = super.buttonContent;\n if (this.holdAffordance) {\n buttonContent.unshift(html`\n <sp-icon-corner-triangle300\n class=\"hold-affordance ${holdAffordanceClass[\n this.size as DefaultElementSize\n ]}\"\n ></sp-icon-corner-triangle300>\n `);\n }\n return buttonContent;\n }\n\n protected override updated(changes: PropertyValues): void {\n super.updated(changes);\n const isButton = this.role === 'button';\n const canBePressed =\n isButton &&\n (this.selected || this.toggles) &&\n !(\n this.hasAttribute('aria-haspopup') &&\n this.hasAttribute('aria-expanded')\n );\n if (changes.has('selected') || changes.has('role')) {\n // When role !== 'button' then the Action Button is within\n // an Action Group that manages selects which means the\n // Action Button is a \"checkbox\" or \"radio\" and cannot\n // accept the `aria-pressed` attribute.\n if (canBePressed) {\n this.setAttribute(\n 'aria-pressed',\n this.selected ? 'true' : 'false'\n );\n } else {\n // When !this.toggles the lack of \"aria-pressed\" is inconsequential.\n this.removeAttribute('aria-pressed');\n if (\n isButton &&\n this.toggles &&\n this.hasAttribute('aria-expanded')\n ) {\n this.setAttribute(\n 'aria-expanded',\n this.selected ? 'true' : 'false'\n );\n }\n }\n }\n if (\n changes.has('variant') &&\n (this.variant || typeof changes.get('variant'))\n ) {\n this.static = this.variant;\n if (window.__swc.DEBUG) {\n window.__swc.warn(\n this,\n `The \"variant\" attribute/property of <${this.localName}> have been deprecated. Use \"static\" with any of the same values instead. \"variant\" will be removed in a future release.`,\n 'https://opensource.adobe.com/spectrum-web-components/components/badge/#fixed'\n );\n }\n }\n }\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n longpress: CustomEvent<LongpressEvent>;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAGI;AAAA,EAEA;AAAA,OAEG;AACP,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,OAAO,kBAAkB;AACzB,OAAO,0BAA0B;AACjC,OAAO;AAEP,MAAM,sBAAsB;AAAA,EACxB,IAAI;AAAA,EACJ,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,IAAI;AACR;AAEO,aAAM,qBAAqB;AAClC,IAAI;AAgBG,aAAM,qBAAqB,WAAW,YAAY;AAAA,EACrD,YAAY,CAAC,MAAM,KAAK,KAAK,KAAK,IAAI;AAC1C,CAAC,EAAE;AAAA,EA8DC,cAAc;AACV,UAAM;AAzDV,SAAO,aAAa;AAGpB,SAAO,iBAAiB;AAGxB,SAAO,QAAQ;AAGf,SAAO,OAAO;AAOd,SAAO,WAAW;AAQlB,SAAO,UAAU;AAuBjB,SAAQ,SAAS;AAejB,SAAQ,UAAU,MAAY;AAC1B,UAAI,CAAC,KAAK,SAAS;AACf;AAAA,MACJ;AACA,WAAK,WAAW,CAAC,KAAK;AACtB,YAAM,eAAe,KAAK;AAAA,QACtB,IAAI,MAAM,UAAU;AAAA,UAChB,YAAY;AAAA,QAChB,CAAC;AAAA,MACL;AACA,UAAI,CAAC,cAAc;AACf,aAAK,WAAW,CAAC,KAAK;AAAA,MAC1B;AAAA,IACJ;AAjBI,SAAK,iBAAiB,SAAS,KAAK,OAAO;AAC3C,SAAK,iBAAiB,eAAe,KAAK,aAAa;AAAA,EAC3D;AAAA,EAjEA,WAA2B,SAAyB;AAChD,WAAO,CAAC,GAAG,MAAM,QAAQ,cAAc,oBAAoB;AAAA,EAC/D;AAAA,EAoCA,IAAW,QAAgB;AACvB,WAA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ACpB,eAAO,MAAM;AAAA,UACT;AAAA,UACA,wCAAwC,KAAK,SAAS;AAAA,UACtD;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;AA1MW;AAAA,EADN,SAAS,EAAE,MAAM,SAAS,SAAS,KAAK,CAAC;AAAA,GAPjC,aAQF;AAGA;AAAA,EADN,SAAS,EAAE,MAAM,SAAS,SAAS,MAAM,WAAW,kBAAkB,CAAC;AAAA,GAV/D,aAWF;AAGA;AAAA,EADN,SAAS,EAAE,MAAM,SAAS,SAAS,KAAK,CAAC;AAAA,GAbjC,aAcF;AAGA;AAAA,EADN,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,GAhBlB,aAiBF;AAOA;AAAA,EADN,SAAS,EAAE,MAAM,SAAS,SAAS,KAAK,CAAC;AAAA,GAvBjC,aAwBF;AAQA;AAAA,EADN,SAAS,EAAE,MAAM,SAAS,SAAS,KAAK,CAAC;AAAA,GA/BjC,aAgCF;AAGA;AAAA,EADN,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,GAlClB,aAmCF;AAGA;AAAA,EADN,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,GArClB,aAsCF;AAGI;AAAA,EADV,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAxCjB,aAyCE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/ActionButton.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var s=(n,o,e,t)=>{for(var r=t>1?void 0:t?d(o,e):o,a=n.length-1,l;a>=0;a--)(l=n[a])&&(r=(t?l(o,e,r):l(r))||r);return t&&r&&u(o,e,r),r};import{html as c,SizedMixin as h}from"@spectrum-web-components/base";import{property as i}from"@spectrum-web-components/base/src/decorators.js";import{ButtonBase as f}from"@spectrum-web-components/button";import v from"./action-button.css.js";import b from"@spectrum-web-components/icon/src/spectrum-icon-corner-triangle.css.js";import"@spectrum-web-components/icons-ui/icons/sp-icon-corner-triangle300.js";const m={xs:"spectrum-UIIcon-CornerTriangle75",s:"spectrum-UIIcon-CornerTriangle75",m:"spectrum-UIIcon-CornerTriangle100",l:"spectrum-UIIcon-CornerTriangle200",xl:"spectrum-UIIcon-CornerTriangle300"};export const LONGPRESS_DURATION=300;let p;export class ActionButton extends h(f,{validSizes:["xs","s","m","l","xl"]}){constructor(){super();this.emphasized=!1;this.holdAffordance=!1;this.quiet=!1;this.role="button";this.selected=!1;this.toggles=!1;this._value="";this.onClick=()=>{if(!this.toggles)return;this.selected=!this.selected,this.dispatchEvent(new Event("change",{cancelable:!0}))||(this.selected=!this.selected)};this.addEventListener("click",this.onClick),this.addEventListener("pointerdown",this.onPointerdown)}static get styles(){return[...super.styles,v,b]}get value(){return this._value||this.itemText}set value(e){e!==this._value&&(this._value=e||"",this._value?this.setAttribute("value",this._value):this.removeAttribute("value"))}get itemText(){return(this.textContent||"").trim()}onPointerdown(e){e.button===0&&(this.addEventListener("pointerup",this.onPointerup),this.addEventListener("pointercancel",this.onPointerup),p=setTimeout(()=>{this.dispatchEvent(new CustomEvent("longpress",{bubbles:!0,composed:!0,detail:{source:"pointer"}}))},LONGPRESS_DURATION))}onPointerup(){clearTimeout(p),this.removeEventListener("pointerup",this.onPointerup),this.removeEventListener("pointercancel",this.onPointerup)}handleKeydown(e){if(!this.holdAffordance)return super.handleKeydown(e);const{code:t,altKey:r}=e;(t==="Space"||r&&t==="ArrowDown")&&(e.preventDefault(),t==="ArrowDown"&&(e.stopPropagation(),e.stopImmediatePropagation()),this.addEventListener("keyup",this.handleKeyup),this.active=!0)}handleKeyup(e){if(!this.holdAffordance)return super.handleKeyup(e);const{code:t,altKey:r}=e;(t==="Space"||r&&t==="ArrowDown")&&(e.stopPropagation(),this.dispatchEvent(new CustomEvent("longpress",{bubbles:!0,composed:!0,detail:{source:"keyboard"}})),this.active=!1)}get buttonContent(){const e=super.buttonContent;return this.holdAffordance&&e.unshift(c`
|
|
2
2
|
<sp-icon-corner-triangle300
|
|
3
3
|
class="hold-affordance ${m[this.size]}"
|
|
4
4
|
></sp-icon-corner-triangle300>
|
|
5
|
-
`),e}updated(e){super.updated(e);const t=this.role==="button",r=t&&(this.selected||this.toggles)&&!(this.hasAttribute("aria-haspopup")&&this.hasAttribute("aria-expanded"));(e.has("selected")||e.has("role"))&&(r?this.setAttribute("aria-pressed",this.selected?"true":"false"):(this.removeAttribute("aria-pressed"),t&&this.toggles&&this.hasAttribute("aria-expanded")&&this.setAttribute("aria-expanded",this.selected?"true":"false"))),e.has("variant")&&(this.variant||typeof e.get("variant"))&&(this.static=this.variant)
|
|
5
|
+
`),e}updated(e){super.updated(e);const t=this.role==="button",r=t&&(this.selected||this.toggles)&&!(this.hasAttribute("aria-haspopup")&&this.hasAttribute("aria-expanded"));(e.has("selected")||e.has("role"))&&(r?this.setAttribute("aria-pressed",this.selected?"true":"false"):(this.removeAttribute("aria-pressed"),t&&this.toggles&&this.hasAttribute("aria-expanded")&&this.setAttribute("aria-expanded",this.selected?"true":"false"))),e.has("variant")&&(this.variant||typeof e.get("variant"))&&(this.static=this.variant)}}s([i({type:Boolean,reflect:!0})],ActionButton.prototype,"emphasized",2),s([i({type:Boolean,reflect:!0,attribute:"hold-affordance"})],ActionButton.prototype,"holdAffordance",2),s([i({type:Boolean,reflect:!0})],ActionButton.prototype,"quiet",2),s([i({reflect:!0})],ActionButton.prototype,"role",2),s([i({type:Boolean,reflect:!0})],ActionButton.prototype,"selected",2),s([i({type:Boolean,reflect:!0})],ActionButton.prototype,"toggles",2),s([i({reflect:!0})],ActionButton.prototype,"static",2),s([i({reflect:!0})],ActionButton.prototype,"variant",2),s([i({type:String})],ActionButton.prototype,"value",1);
|
|
6
6
|
//# sourceMappingURL=ActionButton.js.map
|
package/src/ActionButton.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["ActionButton.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 {\n CSSResultArray,\n DefaultElementSize,\n html,\n PropertyValues,\n SizedMixin,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { ButtonBase } from '@spectrum-web-components/button';\nimport buttonStyles from './action-button.css.js';\nimport cornerTriangleStyles from '@spectrum-web-components/icon/src/spectrum-icon-corner-triangle.css.js';\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-corner-triangle300.js';\n\nconst holdAffordanceClass = {\n xs: 'spectrum-UIIcon-CornerTriangle75',\n s: 'spectrum-UIIcon-CornerTriangle75',\n m: 'spectrum-UIIcon-CornerTriangle100',\n l: 'spectrum-UIIcon-CornerTriangle200',\n xl: 'spectrum-UIIcon-CornerTriangle300',\n};\n\nexport const LONGPRESS_DURATION = 300;\nlet LONGPRESS_TIMEOUT: ReturnType<typeof setTimeout>;\n\nexport type LongpressEvent = {\n source: 'pointer' | 'keyboard';\n};\n\n/**\n * @element sp-action-button\n *\n * @slot - text label of the Action Button\n * @slot icon - The icon to use for Action Button\n * @fires change - Announces a change in the `selected` property of an action button\n * @fires longpress - Synthesizes a \"longpress\" interaction that signifies a\n * `pointerdown` event that is >=300ms or a keyboard event wher code is `Space` or code is `ArrowDown`\n * while `altKey===true`.\n */\nexport class ActionButton extends SizedMixin(ButtonBase, {\n validSizes: ['xs', 's', 'm', 'l', 'xl'],\n}) {\n public static override get styles(): CSSResultArray {\n return [...super.styles, buttonStyles, cornerTriangleStyles];\n }\n\n @property({ type: Boolean, reflect: true })\n public emphasized = false;\n\n @property({ type: Boolean, reflect: true, attribute: 'hold-affordance' })\n public holdAffordance = false;\n\n @property({ type: Boolean, reflect: true })\n public quiet = false;\n\n @property({ reflect: true })\n public role = 'button';\n\n /**\n * Whether an Action Button with `role='button'`\n * should also be `aria-pressed='true'`\n */\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n /**\n * Whether to automatically manage the `selected`\n * attribute on interaction and whether `aria-pressed=\"false\"`\n * should be used when `selected === false`\n */\n @property({ type: Boolean, reflect: true })\n public toggles = false;\n\n @property({ reflect: true })\n public static?: 'white' | 'black';\n\n @property({ reflect: true })\n public variant?: 'white' | 'black';\n\n @property({ type: String })\n public get value(): string {\n return this._value || this.itemText;\n }\n public set value(value: string) {\n if (value === this._value) {\n return;\n }\n this._value = value || '';\n if (this._value) {\n this.setAttribute('value', this._value);\n } else {\n this.removeAttribute('value');\n }\n }\n private _value = '';\n\n /**\n * @private\n */\n public get itemText(): string {\n return (this.textContent || /* c8 ignore next */ '').trim();\n }\n\n constructor() {\n super();\n this.addEventListener('click', this.onClick);\n }\n\n private onClick = (): void => {\n if (!this.toggles) {\n return;\n }\n this.selected = !this.selected;\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n cancelable: true,\n })\n );\n if (!applyDefault) {\n this.selected = !this.selected;\n }\n };\n\n private
|
|
5
|
-
"mappings": "qNAYA,OAGI,QAAAA,EAEA,cAAAC,MAEG,gCACP,OAAS,YAAAC,MAAgB,kDACzB,OAAS,cAAAC,MAAkB,kCAC3B,OAAOC,MAAkB,yBACzB,OAAOC,MAA0B,yEACjC,MAAO,wEAEP,MAAMC,EAAsB,CACxB,GAAI,mCACJ,EAAG,mCACH,EAAG,oCACH,EAAG,oCACH,GAAI,mCACR,EAEO,aAAM,mBAAqB,IAClC,IAAIC,EAgBG,aAAM,qBAAqBN,EAAWE,EAAY,CACrD,WAAY,CAAC,KAAM,IAAK,IAAK,IAAK,IAAI,CAC1C,CAAC,CAAE,CA8DC,aAAc,CACV,MAAM,EAzDV,KAAO,WAAa,GAGpB,KAAO,eAAiB,GAGxB,KAAO,MAAQ,GAGf,KAAO,KAAO,SAOd,KAAO,SAAW,GAQlB,KAAO,QAAU,GAuBjB,KAAQ,OAAS,
|
|
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 {\n CSSResultArray,\n DefaultElementSize,\n html,\n PropertyValues,\n SizedMixin,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { ButtonBase } from '@spectrum-web-components/button';\nimport buttonStyles from './action-button.css.js';\nimport cornerTriangleStyles from '@spectrum-web-components/icon/src/spectrum-icon-corner-triangle.css.js';\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-corner-triangle300.js';\n\nconst holdAffordanceClass = {\n xs: 'spectrum-UIIcon-CornerTriangle75',\n s: 'spectrum-UIIcon-CornerTriangle75',\n m: 'spectrum-UIIcon-CornerTriangle100',\n l: 'spectrum-UIIcon-CornerTriangle200',\n xl: 'spectrum-UIIcon-CornerTriangle300',\n};\n\nexport const LONGPRESS_DURATION = 300;\nlet LONGPRESS_TIMEOUT: ReturnType<typeof setTimeout>;\n\nexport type LongpressEvent = {\n source: 'pointer' | 'keyboard';\n};\n\n/**\n * @element sp-action-button\n *\n * @slot - text label of the Action Button\n * @slot icon - The icon to use for Action Button\n * @fires change - Announces a change in the `selected` property of an action button\n * @fires longpress - Synthesizes a \"longpress\" interaction that signifies a\n * `pointerdown` event that is >=300ms or a keyboard event wher code is `Space` or code is `ArrowDown`\n * while `altKey===true`.\n */\nexport class ActionButton extends SizedMixin(ButtonBase, {\n validSizes: ['xs', 's', 'm', 'l', 'xl'],\n}) {\n public static override get styles(): CSSResultArray {\n return [...super.styles, buttonStyles, cornerTriangleStyles];\n }\n\n @property({ type: Boolean, reflect: true })\n public emphasized = false;\n\n @property({ type: Boolean, reflect: true, attribute: 'hold-affordance' })\n public holdAffordance = false;\n\n @property({ type: Boolean, reflect: true })\n public quiet = false;\n\n @property({ reflect: true })\n public role = 'button';\n\n /**\n * Whether an Action Button with `role='button'`\n * should also be `aria-pressed='true'`\n */\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n /**\n * Whether to automatically manage the `selected`\n * attribute on interaction and whether `aria-pressed=\"false\"`\n * should be used when `selected === false`\n */\n @property({ type: Boolean, reflect: true })\n public toggles = false;\n\n @property({ reflect: true })\n public static?: 'white' | 'black';\n\n @property({ reflect: true })\n public variant?: 'white' | 'black';\n\n @property({ type: String })\n public get value(): string {\n return this._value || this.itemText;\n }\n public set value(value: string) {\n if (value === this._value) {\n return;\n }\n this._value = value || '';\n if (this._value) {\n this.setAttribute('value', this._value);\n } else {\n this.removeAttribute('value');\n }\n }\n private _value = '';\n\n /**\n * @private\n */\n public get itemText(): string {\n return (this.textContent || /* c8 ignore next */ '').trim();\n }\n\n constructor() {\n super();\n this.addEventListener('click', this.onClick);\n this.addEventListener('pointerdown', this.onPointerdown);\n }\n\n private onClick = (): void => {\n if (!this.toggles) {\n return;\n }\n this.selected = !this.selected;\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n cancelable: true,\n })\n );\n if (!applyDefault) {\n this.selected = !this.selected;\n }\n };\n\n private onPointerdown(event: PointerEvent): void {\n if (event.button !== 0) return;\n this.addEventListener('pointerup', this.onPointerup);\n this.addEventListener('pointercancel', this.onPointerup);\n LONGPRESS_TIMEOUT = setTimeout(() => {\n this.dispatchEvent(\n new CustomEvent<LongpressEvent>('longpress', {\n bubbles: true,\n composed: true,\n detail: {\n source: 'pointer',\n },\n })\n );\n }, LONGPRESS_DURATION);\n }\n\n private onPointerup(): void {\n clearTimeout(LONGPRESS_TIMEOUT);\n this.removeEventListener('pointerup', this.onPointerup);\n this.removeEventListener('pointercancel', this.onPointerup);\n }\n\n /**\n * @private\n */\n protected override handleKeydown(event: KeyboardEvent): void {\n if (!this.holdAffordance) {\n return super.handleKeydown(event);\n }\n const { code, altKey } = event;\n if (code === 'Space' || (altKey && code === 'ArrowDown')) {\n event.preventDefault();\n if (code === 'ArrowDown') {\n event.stopPropagation();\n event.stopImmediatePropagation();\n }\n this.addEventListener('keyup', this.handleKeyup);\n this.active = true;\n }\n }\n\n protected override handleKeyup(event: KeyboardEvent): void {\n if (!this.holdAffordance) {\n return super.handleKeyup(event);\n }\n const { code, altKey } = event;\n if (code === 'Space' || (altKey && code === 'ArrowDown')) {\n event.stopPropagation();\n this.dispatchEvent(\n new CustomEvent<LongpressEvent>('longpress', {\n bubbles: true,\n composed: true,\n detail: {\n source: 'keyboard',\n },\n })\n );\n this.active = false;\n }\n }\n\n protected override get buttonContent(): TemplateResult[] {\n const buttonContent = super.buttonContent;\n if (this.holdAffordance) {\n buttonContent.unshift(html`\n <sp-icon-corner-triangle300\n class=\"hold-affordance ${holdAffordanceClass[\n this.size as DefaultElementSize\n ]}\"\n ></sp-icon-corner-triangle300>\n `);\n }\n return buttonContent;\n }\n\n protected override updated(changes: PropertyValues): void {\n super.updated(changes);\n const isButton = this.role === 'button';\n const canBePressed =\n isButton &&\n (this.selected || this.toggles) &&\n !(\n this.hasAttribute('aria-haspopup') &&\n this.hasAttribute('aria-expanded')\n );\n if (changes.has('selected') || changes.has('role')) {\n // When role !== 'button' then the Action Button is within\n // an Action Group that manages selects which means the\n // Action Button is a \"checkbox\" or \"radio\" and cannot\n // accept the `aria-pressed` attribute.\n if (canBePressed) {\n this.setAttribute(\n 'aria-pressed',\n this.selected ? 'true' : 'false'\n );\n } else {\n // When !this.toggles the lack of \"aria-pressed\" is inconsequential.\n this.removeAttribute('aria-pressed');\n if (\n isButton &&\n this.toggles &&\n this.hasAttribute('aria-expanded')\n ) {\n this.setAttribute(\n 'aria-expanded',\n this.selected ? 'true' : 'false'\n );\n }\n }\n }\n if (\n changes.has('variant') &&\n (this.variant || typeof changes.get('variant'))\n ) {\n this.static = this.variant;\n if (window.__swc.DEBUG) {\n window.__swc.warn(\n this,\n `The \"variant\" attribute/property of <${this.localName}> have been deprecated. Use \"static\" with any of the same values instead. \"variant\" will be removed in a future release.`,\n 'https://opensource.adobe.com/spectrum-web-components/components/badge/#fixed'\n );\n }\n }\n }\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n longpress: CustomEvent<LongpressEvent>;\n }\n}\n"],
|
|
5
|
+
"mappings": "qNAYA,OAGI,QAAAA,EAEA,cAAAC,MAEG,gCACP,OAAS,YAAAC,MAAgB,kDACzB,OAAS,cAAAC,MAAkB,kCAC3B,OAAOC,MAAkB,yBACzB,OAAOC,MAA0B,yEACjC,MAAO,wEAEP,MAAMC,EAAsB,CACxB,GAAI,mCACJ,EAAG,mCACH,EAAG,oCACH,EAAG,oCACH,GAAI,mCACR,EAEO,aAAM,mBAAqB,IAClC,IAAIC,EAgBG,aAAM,qBAAqBN,EAAWE,EAAY,CACrD,WAAY,CAAC,KAAM,IAAK,IAAK,IAAK,IAAI,CAC1C,CAAC,CAAE,CA8DC,aAAc,CACV,MAAM,EAzDV,KAAO,WAAa,GAGpB,KAAO,eAAiB,GAGxB,KAAO,MAAQ,GAGf,KAAO,KAAO,SAOd,KAAO,SAAW,GAQlB,KAAO,QAAU,GAuBjB,KAAQ,OAAS,GAejB,KAAQ,QAAU,IAAY,CAC1B,GAAI,CAAC,KAAK,QACN,OAEJ,KAAK,SAAW,CAAC,KAAK,SACD,KAAK,cACtB,IAAI,MAAM,SAAU,CAChB,WAAY,EAChB,CAAC,CACL,IAEI,KAAK,SAAW,CAAC,KAAK,SAE9B,EAjBI,KAAK,iBAAiB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AAK,CAAC,GAvBjC,aAwBF,wBAQAc,EAAA,CADNd,EAAS,CAAE,KAAM,QAAS,QAAS,EAAK,CAAC,GA/BjC,aAgCF,uBAGAc,EAAA,CADNd,EAAS,CAAE,QAAS,EAAK,CAAC,GAlClB,aAmCF,sBAGAc,EAAA,CADNd,EAAS,CAAE,QAAS,EAAK,CAAC,GArClB,aAsCF,uBAGIc,EAAA,CADVd,EAAS,CAAE,KAAM,MAAO,CAAC,GAxCjB,aAyCE",
|
|
6
6
|
"names": ["html", "SizedMixin", "property", "ButtonBase", "buttonStyles", "cornerTriangleStyles", "holdAffordanceClass", "LONGPRESS_TIMEOUT", "value", "event", "code", "altKey", "buttonContent", "changes", "isButton", "canBePressed", "__decorateClass"]
|
|
7
7
|
}
|