@spectrum-web-components/action-button 0.9.2-devmode2.0 → 0.10.1
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 +25 -1
- package/package.json +7 -7
- package/sp-action-button.dev.js +1 -0
- package/sp-action-button.dev.js.map +1 -1
- package/sp-action-button.js +1 -2
- package/sp-action-button.js.map +2 -2
- package/src/ActionButton.d.ts +1 -0
- package/src/ActionButton.dev.js +32 -20
- package/src/ActionButton.dev.js.map +2 -2
- package/src/ActionButton.js +3 -169
- package/src/ActionButton.js.map +3 -3
- package/src/action-button.css.dev.js +1 -0
- package/src/action-button.css.dev.js.map +1 -1
- package/src/action-button.css.js +2 -4
- package/src/action-button.css.js.map +2 -2
- package/src/index.dev.js +1 -0
- package/src/index.dev.js.map +1 -1
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/src/spectrum-action-button.css.dev.js +1 -0
- package/src/spectrum-action-button.css.dev.js.map +1 -1
- package/src/spectrum-action-button.css.js +2 -4
- package/src/spectrum-action-button.css.js.map +2 -2
- package/stories/action-button-black-quiet.stories.js +1 -0
- package/stories/action-button-black-quiet.stories.js.map +1 -1
- package/stories/action-button-black.stories.js +1 -0
- package/stories/action-button-black.stories.js.map +1 -1
- package/stories/action-button-emphasized-quiet.stories.js +1 -0
- package/stories/action-button-emphasized-quiet.stories.js.map +1 -1
- package/stories/action-button-emphasized.stories.js +1 -0
- package/stories/action-button-emphasized.stories.js.map +1 -1
- package/stories/action-button-quiet.stories.js +1 -0
- package/stories/action-button-quiet.stories.js.map +1 -1
- package/stories/action-button-standard.stories.js +1 -0
- package/stories/action-button-standard.stories.js.map +1 -1
- package/stories/action-button-white-quiet.stories.js +1 -0
- package/stories/action-button-white-quiet.stories.js.map +1 -1
- package/stories/action-button-white.stories.js +1 -0
- package/stories/action-button-white.stories.js.map +1 -1
- package/stories/action-button.stories.js +1 -0
- package/stories/action-button.stories.js.map +1 -1
- package/stories/index.js +1 -0
- package/stories/index.js.map +1 -1
- package/test/action-button-black-quiet.test-vrt.js +1 -0
- package/test/action-button-black-quiet.test-vrt.js.map +1 -1
- package/test/action-button-black.test-vrt.js +1 -0
- package/test/action-button-black.test-vrt.js.map +1 -1
- package/test/action-button-emphasized-quiet.test-vrt.js +1 -0
- package/test/action-button-emphasized-quiet.test-vrt.js.map +1 -1
- package/test/action-button-emphasized.test-vrt.js +1 -0
- package/test/action-button-emphasized.test-vrt.js.map +1 -1
- package/test/action-button-quiet.test-vrt.js +1 -0
- package/test/action-button-quiet.test-vrt.js.map +1 -1
- package/test/action-button-standard.test-vrt.js +1 -0
- package/test/action-button-standard.test-vrt.js.map +1 -1
- package/test/action-button-white-quiet.test-vrt.js +1 -0
- package/test/action-button-white-quiet.test-vrt.js.map +1 -1
- package/test/action-button-white.test-vrt.js +1 -0
- package/test/action-button-white.test-vrt.js.map +1 -1
- package/test/action-button.test-vrt.js +1 -0
- package/test/action-button.test-vrt.js.map +1 -1
- package/test/action-button.test.js +60 -18
- package/test/action-button.test.js.map +2 -2
- package/test/benchmark/basic-test.js +1 -0
- package/test/benchmark/basic-test.js.map +1 -1
package/custom-elements.json
CHANGED
|
@@ -21,6 +21,14 @@
|
|
|
21
21
|
"kind": "javascript-module",
|
|
22
22
|
"path": "src/ActionButton.js",
|
|
23
23
|
"declarations": [
|
|
24
|
+
{
|
|
25
|
+
"kind": "variable",
|
|
26
|
+
"name": "LONGPRESS_DURATION",
|
|
27
|
+
"type": {
|
|
28
|
+
"text": "number"
|
|
29
|
+
},
|
|
30
|
+
"default": "300"
|
|
31
|
+
},
|
|
24
32
|
{
|
|
25
33
|
"kind": "class",
|
|
26
34
|
"description": "",
|
|
@@ -153,7 +161,15 @@
|
|
|
153
161
|
"type": {
|
|
154
162
|
"text": "void"
|
|
155
163
|
}
|
|
156
|
-
}
|
|
164
|
+
},
|
|
165
|
+
"parameters": [
|
|
166
|
+
{
|
|
167
|
+
"name": "event",
|
|
168
|
+
"type": {
|
|
169
|
+
"text": "PointerEvent"
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
]
|
|
157
173
|
},
|
|
158
174
|
{
|
|
159
175
|
"kind": "method",
|
|
@@ -304,6 +320,14 @@
|
|
|
304
320
|
}
|
|
305
321
|
],
|
|
306
322
|
"exports": [
|
|
323
|
+
{
|
|
324
|
+
"kind": "js",
|
|
325
|
+
"name": "LONGPRESS_DURATION",
|
|
326
|
+
"declaration": {
|
|
327
|
+
"name": "LONGPRESS_DURATION",
|
|
328
|
+
"module": "src/ActionButton.js"
|
|
329
|
+
}
|
|
330
|
+
},
|
|
307
331
|
{
|
|
308
332
|
"kind": "js",
|
|
309
333
|
"name": "ActionButton",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/action-button",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
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.
|
|
60
|
+
"@spectrum-web-components/base": "^0.7.0",
|
|
61
|
+
"@spectrum-web-components/button": "^0.19.1",
|
|
62
|
+
"@spectrum-web-components/icon": "^0.12.0",
|
|
63
|
+
"@spectrum-web-components/icons-ui": "^0.9.0",
|
|
64
64
|
"tslib": "^2.0.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@spectrum-css/actionbutton": "^2.1.
|
|
67
|
+
"@spectrum-css/actionbutton": "^2.1.3"
|
|
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": "1cfea66c39440232b9982509573801b8e3a9f692"
|
|
76
76
|
}
|
package/sp-action-button.dev.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["sp-action-button.ts"],
|
|
4
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 { ActionButton } from './src/ActionButton.dev.js'\n\ncustomElements.define('sp-action-button', ActionButton);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-action-button': ActionButton;\n }\n}\n"],
|
|
5
|
-
"mappings": "AAYA;
|
|
5
|
+
"mappings": ";AAYA,SAAS,oBAAoB;AAE7B,eAAe,OAAO,oBAAoB,YAAY;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/sp-action-button.js
CHANGED
package/sp-action-button.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["sp-action-button.ts"],
|
|
4
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 { ActionButton } from './src/ActionButton.js';\n\ncustomElements.define('sp-action-button', ActionButton);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-action-button': ActionButton;\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "aAYA,OAAS,gBAAAA,MAAoB,wBAE7B,eAAe,OAAO,mBAAoBA,CAAY",
|
|
6
|
+
"names": ["ActionButton"]
|
|
7
7
|
}
|
package/src/ActionButton.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CSSResultArray, PropertyValues, TemplateResult } from '@spectrum-web-components/base';
|
|
2
2
|
import { ButtonBase } from '@spectrum-web-components/button';
|
|
3
3
|
import '@spectrum-web-components/icons-ui/icons/sp-icon-corner-triangle300.js';
|
|
4
|
+
export declare const LONGPRESS_DURATION = 300;
|
|
4
5
|
export declare type LongpressEvent = {
|
|
5
6
|
source: 'pointer' | 'keyboard';
|
|
6
7
|
};
|
package/src/ActionButton.dev.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
@@ -24,7 +25,7 @@ const holdAffordanceClass = {
|
|
|
24
25
|
l: "spectrum-UIIcon-CornerTriangle200",
|
|
25
26
|
xl: "spectrum-UIIcon-CornerTriangle300"
|
|
26
27
|
};
|
|
27
|
-
const LONGPRESS_DURATION = 300;
|
|
28
|
+
export const LONGPRESS_DURATION = 300;
|
|
28
29
|
let LONGPRESS_TIMEOUT;
|
|
29
30
|
export class ActionButton extends SizedMixin(ButtonBase) {
|
|
30
31
|
constructor() {
|
|
@@ -41,9 +42,11 @@ export class ActionButton extends SizedMixin(ButtonBase) {
|
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
44
|
this.selected = !this.selected;
|
|
44
|
-
const applyDefault = this.dispatchEvent(
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
const applyDefault = this.dispatchEvent(
|
|
46
|
+
new Event("change", {
|
|
47
|
+
cancelable: true
|
|
48
|
+
})
|
|
49
|
+
);
|
|
47
50
|
if (!applyDefault) {
|
|
48
51
|
this.selected = !this.selected;
|
|
49
52
|
}
|
|
@@ -71,17 +74,21 @@ export class ActionButton extends SizedMixin(ButtonBase) {
|
|
|
71
74
|
get itemText() {
|
|
72
75
|
return (this.textContent || "").trim();
|
|
73
76
|
}
|
|
74
|
-
onPointerdown() {
|
|
77
|
+
onPointerdown(event) {
|
|
78
|
+
if (event.button !== 0)
|
|
79
|
+
return;
|
|
75
80
|
this.addEventListener("pointerup", this.onPointerup);
|
|
76
81
|
this.addEventListener("pointercancel", this.onPointerup);
|
|
77
82
|
LONGPRESS_TIMEOUT = setTimeout(() => {
|
|
78
|
-
this.dispatchEvent(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
this.dispatchEvent(
|
|
84
|
+
new CustomEvent("longpress", {
|
|
85
|
+
bubbles: true,
|
|
86
|
+
composed: true,
|
|
87
|
+
detail: {
|
|
88
|
+
source: "pointer"
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
);
|
|
85
92
|
}, LONGPRESS_DURATION);
|
|
86
93
|
}
|
|
87
94
|
onPointerup() {
|
|
@@ -111,13 +118,15 @@ export class ActionButton extends SizedMixin(ButtonBase) {
|
|
|
111
118
|
const { code, altKey } = event;
|
|
112
119
|
if (code === "Space" || altKey && code === "ArrowDown") {
|
|
113
120
|
event.stopPropagation();
|
|
114
|
-
this.dispatchEvent(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
this.dispatchEvent(
|
|
122
|
+
new CustomEvent("longpress", {
|
|
123
|
+
bubbles: true,
|
|
124
|
+
composed: true,
|
|
125
|
+
detail: {
|
|
126
|
+
source: "keyboard"
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
);
|
|
121
130
|
this.active = false;
|
|
122
131
|
}
|
|
123
132
|
}
|
|
@@ -138,7 +147,10 @@ export class ActionButton extends SizedMixin(ButtonBase) {
|
|
|
138
147
|
const canBePressed = isButton && (this.selected || this.toggles);
|
|
139
148
|
if (changes.has("selected") || changes.has("role")) {
|
|
140
149
|
if (canBePressed) {
|
|
141
|
-
this.setAttribute(
|
|
150
|
+
this.setAttribute(
|
|
151
|
+
"aria-pressed",
|
|
152
|
+
this.selected ? "true" : "false"
|
|
153
|
+
);
|
|
142
154
|
} else {
|
|
143
155
|
this.removeAttribute("aria-pressed");
|
|
144
156
|
}
|
|
@@ -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 s: 'spectrum-UIIcon-CornerTriangle75',\n m: 'spectrum-UIIcon-CornerTriangle100',\n l: 'spectrum-UIIcon-CornerTriangle200',\n xl: 'spectrum-UIIcon-CornerTriangle300',\n};\n\
|
|
5
|
-
"mappings": "
|
|
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 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 public static override get styles(): CSSResultArray {\n return [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 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 = isButton && (this.selected || this.toggles);\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 }\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,SAA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CHANGED
|
@@ -1,172 +1,6 @@
|
|
|
1
|
-
var
|
|
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
|
-
SizedMixin
|
|
15
|
-
} from "@spectrum-web-components/base";
|
|
16
|
-
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
|
17
|
-
import { ButtonBase } from "@spectrum-web-components/button";
|
|
18
|
-
import buttonStyles from "./action-button.css.js";
|
|
19
|
-
import cornerTriangleStyles from "@spectrum-web-components/icon/src/spectrum-icon-corner-triangle.css.js";
|
|
20
|
-
import "@spectrum-web-components/icons-ui/icons/sp-icon-corner-triangle300.js";
|
|
21
|
-
const holdAffordanceClass = {
|
|
22
|
-
s: "spectrum-UIIcon-CornerTriangle75",
|
|
23
|
-
m: "spectrum-UIIcon-CornerTriangle100",
|
|
24
|
-
l: "spectrum-UIIcon-CornerTriangle200",
|
|
25
|
-
xl: "spectrum-UIIcon-CornerTriangle300"
|
|
26
|
-
};
|
|
27
|
-
const LONGPRESS_DURATION = 300;
|
|
28
|
-
let LONGPRESS_TIMEOUT;
|
|
29
|
-
export class ActionButton extends SizedMixin(ButtonBase) {
|
|
30
|
-
constructor() {
|
|
31
|
-
super();
|
|
32
|
-
this.emphasized = false;
|
|
33
|
-
this.holdAffordance = false;
|
|
34
|
-
this.quiet = false;
|
|
35
|
-
this.role = "button";
|
|
36
|
-
this.selected = false;
|
|
37
|
-
this.toggles = false;
|
|
38
|
-
this._value = "";
|
|
39
|
-
this.onClick = () => {
|
|
40
|
-
if (!this.toggles) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
this.selected = !this.selected;
|
|
44
|
-
const applyDefault = this.dispatchEvent(new Event("change", {
|
|
45
|
-
cancelable: true
|
|
46
|
-
}));
|
|
47
|
-
if (!applyDefault) {
|
|
48
|
-
this.selected = !this.selected;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
this.addEventListener("click", this.onClick);
|
|
52
|
-
this.addEventListener("pointerdown", this.onPointerdown);
|
|
53
|
-
}
|
|
54
|
-
static get styles() {
|
|
55
|
-
return [buttonStyles, cornerTriangleStyles];
|
|
56
|
-
}
|
|
57
|
-
get value() {
|
|
58
|
-
return this._value || this.itemText;
|
|
59
|
-
}
|
|
60
|
-
set value(value) {
|
|
61
|
-
if (value === this._value) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
this._value = value || "";
|
|
65
|
-
if (this._value) {
|
|
66
|
-
this.setAttribute("value", this._value);
|
|
67
|
-
} else {
|
|
68
|
-
this.removeAttribute("value");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
get itemText() {
|
|
72
|
-
return (this.textContent || "").trim();
|
|
73
|
-
}
|
|
74
|
-
onPointerdown() {
|
|
75
|
-
this.addEventListener("pointerup", this.onPointerup);
|
|
76
|
-
this.addEventListener("pointercancel", this.onPointerup);
|
|
77
|
-
LONGPRESS_TIMEOUT = setTimeout(() => {
|
|
78
|
-
this.dispatchEvent(new CustomEvent("longpress", {
|
|
79
|
-
bubbles: true,
|
|
80
|
-
composed: true,
|
|
81
|
-
detail: {
|
|
82
|
-
source: "pointer"
|
|
83
|
-
}
|
|
84
|
-
}));
|
|
85
|
-
}, LONGPRESS_DURATION);
|
|
86
|
-
}
|
|
87
|
-
onPointerup() {
|
|
88
|
-
clearTimeout(LONGPRESS_TIMEOUT);
|
|
89
|
-
this.removeEventListener("pointerup", this.onPointerup);
|
|
90
|
-
this.removeEventListener("pointercancel", this.onPointerup);
|
|
91
|
-
}
|
|
92
|
-
handleKeydown(event) {
|
|
93
|
-
if (!this.holdAffordance) {
|
|
94
|
-
return super.handleKeydown(event);
|
|
95
|
-
}
|
|
96
|
-
const { code, altKey } = event;
|
|
97
|
-
if (code === "Space" || altKey && code === "ArrowDown") {
|
|
98
|
-
event.preventDefault();
|
|
99
|
-
if (code === "ArrowDown") {
|
|
100
|
-
event.stopPropagation();
|
|
101
|
-
event.stopImmediatePropagation();
|
|
102
|
-
}
|
|
103
|
-
this.addEventListener("keyup", this.handleKeyup);
|
|
104
|
-
this.active = true;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
handleKeyup(event) {
|
|
108
|
-
if (!this.holdAffordance) {
|
|
109
|
-
return super.handleKeyup(event);
|
|
110
|
-
}
|
|
111
|
-
const { code, altKey } = event;
|
|
112
|
-
if (code === "Space" || altKey && code === "ArrowDown") {
|
|
113
|
-
event.stopPropagation();
|
|
114
|
-
this.dispatchEvent(new CustomEvent("longpress", {
|
|
115
|
-
bubbles: true,
|
|
116
|
-
composed: true,
|
|
117
|
-
detail: {
|
|
118
|
-
source: "keyboard"
|
|
119
|
-
}
|
|
120
|
-
}));
|
|
121
|
-
this.active = false;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
get buttonContent() {
|
|
125
|
-
const buttonContent = super.buttonContent;
|
|
126
|
-
if (this.holdAffordance) {
|
|
127
|
-
buttonContent.unshift(html`
|
|
1
|
+
"use strict";var u=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var o=(n,i,e,r)=>{for(var t=r>1?void 0:r?c(i,e):i,l=n.length-1,a;l>=0;l--)(a=n[l])&&(t=(r?a(i,e,t):a(t))||t);return r&&t&&u(i,e,t),t};import{html as d,SizedMixin as h}from"@spectrum-web-components/base";import{property as s}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 m 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 b={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){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[v,m]}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:r,altKey:t}=e;(r==="Space"||t&&r==="ArrowDown")&&(e.preventDefault(),r==="ArrowDown"&&(e.stopPropagation(),e.stopImmediatePropagation()),this.addEventListener("keyup",this.handleKeyup),this.active=!0)}handleKeyup(e){if(!this.holdAffordance)return super.handleKeyup(e);const{code:r,altKey:t}=e;(r==="Space"||t&&r==="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(d`
|
|
128
2
|
<sp-icon-corner-triangle300
|
|
129
|
-
class="hold-affordance ${
|
|
3
|
+
class="hold-affordance ${b[this.size]}"
|
|
130
4
|
></sp-icon-corner-triangle300>
|
|
131
|
-
`);
|
|
132
|
-
}
|
|
133
|
-
return buttonContent;
|
|
134
|
-
}
|
|
135
|
-
updated(changes) {
|
|
136
|
-
super.updated(changes);
|
|
137
|
-
const isButton = this.role === "button";
|
|
138
|
-
const canBePressed = isButton && (this.selected || this.toggles);
|
|
139
|
-
if (changes.has("selected") || changes.has("role")) {
|
|
140
|
-
if (canBePressed) {
|
|
141
|
-
this.setAttribute("aria-pressed", this.selected ? "true" : "false");
|
|
142
|
-
} else {
|
|
143
|
-
this.removeAttribute("aria-pressed");
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
__decorateClass([
|
|
149
|
-
property({ type: Boolean, reflect: true })
|
|
150
|
-
], ActionButton.prototype, "emphasized", 2);
|
|
151
|
-
__decorateClass([
|
|
152
|
-
property({ type: Boolean, reflect: true, attribute: "hold-affordance" })
|
|
153
|
-
], ActionButton.prototype, "holdAffordance", 2);
|
|
154
|
-
__decorateClass([
|
|
155
|
-
property({ type: Boolean, reflect: true })
|
|
156
|
-
], ActionButton.prototype, "quiet", 2);
|
|
157
|
-
__decorateClass([
|
|
158
|
-
property({ reflect: true })
|
|
159
|
-
], ActionButton.prototype, "role", 2);
|
|
160
|
-
__decorateClass([
|
|
161
|
-
property({ type: Boolean, reflect: true })
|
|
162
|
-
], ActionButton.prototype, "selected", 2);
|
|
163
|
-
__decorateClass([
|
|
164
|
-
property({ type: Boolean, reflect: true })
|
|
165
|
-
], ActionButton.prototype, "toggles", 2);
|
|
166
|
-
__decorateClass([
|
|
167
|
-
property({ reflect: true })
|
|
168
|
-
], ActionButton.prototype, "variant", 2);
|
|
169
|
-
__decorateClass([
|
|
170
|
-
property({ type: String })
|
|
171
|
-
], ActionButton.prototype, "value", 1);
|
|
5
|
+
`),e}updated(e){super.updated(e);const t=this.role==="button"&&(this.selected||this.toggles);(e.has("selected")||e.has("role"))&&(t?this.setAttribute("aria-pressed",this.selected?"true":"false"):this.removeAttribute("aria-pressed"))}}o([s({type:Boolean,reflect:!0})],ActionButton.prototype,"emphasized",2),o([s({type:Boolean,reflect:!0,attribute:"hold-affordance"})],ActionButton.prototype,"holdAffordance",2),o([s({type:Boolean,reflect:!0})],ActionButton.prototype,"quiet",2),o([s({reflect:!0})],ActionButton.prototype,"role",2),o([s({type:Boolean,reflect:!0})],ActionButton.prototype,"selected",2),o([s({type:Boolean,reflect:!0})],ActionButton.prototype,"toggles",2),o([s({reflect:!0})],ActionButton.prototype,"variant",2),o([s({type:String})],ActionButton.prototype,"value",1);
|
|
172
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 s: 'spectrum-UIIcon-CornerTriangle75',\n m: 'spectrum-UIIcon-CornerTriangle100',\n l: 'spectrum-UIIcon-CornerTriangle200',\n xl: 'spectrum-UIIcon-CornerTriangle300',\n};\n\
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
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 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 public static override get styles(): CSSResultArray {\n return [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 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 = isButton && (this.selected || this.toggles);\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 }\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,cA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EAAK,CAAC,GALjC,aAMF,0BAGAa,EAAA,CADNb,EAAS,CAAE,KAAM,QAAS,QAAS,GAAM,UAAW,iBAAkB,CAAC,GAR/D,aASF,8BAGAa,EAAA,CADNb,EAAS,CAAE,KAAM,QAAS,QAAS,EAAK,CAAC,GAXjC,aAYF,qBAGAa,EAAA,CADNb,EAAS,CAAE,QAAS,EAAK,CAAC,GAdlB,aAeF,oBAOAa,EAAA,CADNb,EAAS,CAAE,KAAM,QAAS,QAAS,EAAK,CAAC,GArBjC,aAsBF,wBAQAa,EAAA,CADNb,EAAS,CAAE,KAAM,QAAS,QAAS,EAAK,CAAC,GA7BjC,aA8BF,uBAGAa,EAAA,CADNb,EAAS,CAAE,QAAS,EAAK,CAAC,GAhClB,aAiCF,uBAGIa,EAAA,CADVb,EAAS,CAAE,KAAM,MAAO,CAAC,GAnCjB,aAoCE",
|
|
6
|
+
"names": ["html", "SizedMixin", "property", "ButtonBase", "buttonStyles", "cornerTriangleStyles", "holdAffordanceClass", "LONGPRESS_TIMEOUT", "value", "event", "code", "altKey", "buttonContent", "changes", "canBePressed", "__decorateClass"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { css } from "@spectrum-web-components/base";
|
|
2
3
|
const styles = css`
|
|
3
4
|
:host{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;align-items:center;-webkit-appearance:button;border-style:solid;box-sizing:border-box;cursor:pointer;font-family:var(--spectrum-font-family-base);justify-content:center;line-height:var(--spectrum-line-height-small);margin:0;overflow:visible;text-decoration:none;text-transform:none;transition:background var(--spectrum-animation-duration-100) ease-out,border-color var(--spectrum-animation-duration-100) ease-out,color var(--spectrum-animation-duration-100) ease-out,box-shadow var(--spectrum-animation-duration-100) ease-out;user-select:none;-webkit-user-select:none;vertical-align:top}:host(:focus){outline:none}:host(::-moz-focus-inner){border:0;border-style:none;margin-block-end:-2px;margin-block-start:-2px;padding:0}:host([disabled]){cursor:default}::slotted([slot=icon]){max-block-size:100%}#label{align-self:center;justify-self:center;text-align:center}#label:empty{display:none}:host{--spectrum-actionbutton-animation-duration:var(
|