@spectrum-web-components/action-button 0.6.0 → 0.7.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 -2
- package/package.json +7 -7
- package/src/ActionButton.d.ts +10 -0
- package/src/ActionButton.js +29 -3
- package/src/ActionButton.js.map +1 -1
- package/src/action-button.css.js +217 -117
- package/src/action-button.css.js.map +1 -1
- package/src/spectrum-action-button.css.js +217 -117
- package/src/spectrum-action-button.css.js.map +1 -1
- package/stories/action-button.stories.js +3 -3
- package/stories/action-button.stories.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/action-button",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -44,19 +44,19 @@
|
|
|
44
44
|
"lit-html"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@spectrum-web-components/base": "^0.
|
|
48
|
-
"@spectrum-web-components/button": "^0.
|
|
49
|
-
"@spectrum-web-components/icon": "^0.
|
|
50
|
-
"@spectrum-web-components/icons-ui": "^0.
|
|
47
|
+
"@spectrum-web-components/base": "^0.5.1",
|
|
48
|
+
"@spectrum-web-components/button": "^0.16.1",
|
|
49
|
+
"@spectrum-web-components/icon": "^0.11.1",
|
|
50
|
+
"@spectrum-web-components/icons-ui": "^0.8.1",
|
|
51
51
|
"tslib": "^2.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@spectrum-css/actionbutton": "^1.0.
|
|
54
|
+
"@spectrum-css/actionbutton": "^1.0.10"
|
|
55
55
|
},
|
|
56
56
|
"types": "./src/index.d.ts",
|
|
57
57
|
"customElements": "custom-elements.json",
|
|
58
58
|
"sideEffects": [
|
|
59
59
|
"./sp-*.js"
|
|
60
60
|
],
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "df3f333ee26a45f9fc247716b6e8ef051dca630b"
|
|
62
62
|
}
|
package/src/ActionButton.d.ts
CHANGED
|
@@ -23,7 +23,17 @@ export declare class ActionButton extends ActionButton_base {
|
|
|
23
23
|
emphasized: boolean;
|
|
24
24
|
holdAffordance: boolean;
|
|
25
25
|
quiet: boolean;
|
|
26
|
+
role: string;
|
|
27
|
+
/**
|
|
28
|
+
* Whether an Action Button with `role='button'`
|
|
29
|
+
* should also be `aria-pressed='true'`
|
|
30
|
+
*/
|
|
26
31
|
selected: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether to automatically manage the `selected`
|
|
34
|
+
* attribute on interaction and whether `aria-pressed="false"`
|
|
35
|
+
* should be used when `selected === false`
|
|
36
|
+
*/
|
|
27
37
|
toggles: boolean;
|
|
28
38
|
get value(): string;
|
|
29
39
|
set value(value: string);
|
package/src/ActionButton.js
CHANGED
|
@@ -10,7 +10,8 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import { __decorate } from "tslib";
|
|
13
|
-
import { html,
|
|
13
|
+
import { html, SizedMixin, } from '@spectrum-web-components/base';
|
|
14
|
+
import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
14
15
|
import { ButtonBase } from '@spectrum-web-components/button';
|
|
15
16
|
import buttonStyles from './action-button.css.js';
|
|
16
17
|
import cornerTriangleStyles from '@spectrum-web-components/icon/src/spectrum-icon-corner-triangle.css.js';
|
|
@@ -39,7 +40,17 @@ export class ActionButton extends SizedMixin(ButtonBase) {
|
|
|
39
40
|
this.emphasized = false;
|
|
40
41
|
this.holdAffordance = false;
|
|
41
42
|
this.quiet = false;
|
|
43
|
+
this.role = 'button';
|
|
44
|
+
/**
|
|
45
|
+
* Whether an Action Button with `role='button'`
|
|
46
|
+
* should also be `aria-pressed='true'`
|
|
47
|
+
*/
|
|
42
48
|
this.selected = false;
|
|
49
|
+
/**
|
|
50
|
+
* Whether to automatically manage the `selected`
|
|
51
|
+
* attribute on interaction and whether `aria-pressed="false"`
|
|
52
|
+
* should be used when `selected === false`
|
|
53
|
+
*/
|
|
43
54
|
this.toggles = false;
|
|
44
55
|
this._value = '';
|
|
45
56
|
this.onClick = () => {
|
|
@@ -148,8 +159,20 @@ export class ActionButton extends SizedMixin(ButtonBase) {
|
|
|
148
159
|
}
|
|
149
160
|
updated(changes) {
|
|
150
161
|
super.updated(changes);
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
const isButton = this.role === 'button';
|
|
163
|
+
const canBePressed = isButton && (this.selected || this.toggles);
|
|
164
|
+
if (changes.has('selected') || changes.has('role')) {
|
|
165
|
+
// When role !== 'button' then the Action Button is within
|
|
166
|
+
// an Action Group that manages selects which means the
|
|
167
|
+
// Action Button is a "checkbox" or "radio" and cannot
|
|
168
|
+
// accept the `aria-pressed` attribute.
|
|
169
|
+
if (canBePressed) {
|
|
170
|
+
this.setAttribute('aria-pressed', this.selected ? 'true' : 'false');
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// When !this.toggles the lack of "aria-pressed" is inconsequential.
|
|
174
|
+
this.removeAttribute('aria-pressed');
|
|
175
|
+
}
|
|
153
176
|
}
|
|
154
177
|
}
|
|
155
178
|
}
|
|
@@ -162,6 +185,9 @@ __decorate([
|
|
|
162
185
|
__decorate([
|
|
163
186
|
property({ type: Boolean, reflect: true })
|
|
164
187
|
], ActionButton.prototype, "quiet", void 0);
|
|
188
|
+
__decorate([
|
|
189
|
+
property({ reflect: true })
|
|
190
|
+
], ActionButton.prototype, "role", void 0);
|
|
165
191
|
__decorate([
|
|
166
192
|
property({ type: Boolean, reflect: true })
|
|
167
193
|
], ActionButton.prototype, "selected", void 0);
|
package/src/ActionButton.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionButton.js","sourceRoot":"","sources":["ActionButton.ts"],"names":[],"mapp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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 html,\n property,\n PropertyValues,\n TemplateResult,\n SizedMixin,\n ElementSize,\n} from '@spectrum-web-components/base';\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\nconst LONGPRESS_DURATION = 300;\nlet LONGPRESS_TIMEOUT: ReturnType<typeof setTimeout>;\n\nexport type LongpressEvent = {\n source: 'pointer' | 'keyboard';\n};\n\ntype ActionButtonSize = Exclude<ElementSize, 'xxl'>;\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 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({ type: Boolean, reflect: true })\n public selected = false;\n\n @property({ type: Boolean, reflect: true })\n public toggles = false;\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(): void {\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 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 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 get buttonContent(): TemplateResult[] {\n const buttonContent = super.buttonContent;\n if (this.holdAffordance) {\n buttonContent.unshift(html`\n <sp-icon-corner-triangle300\n id=\"hold-affordance\"\n class=\"${holdAffordanceClass[\n this.size as ActionButtonSize\n ]}\"\n ></sp-icon-corner-triangle300>\n `);\n }\n return buttonContent;\n }\n\n protected updated(changes: PropertyValues): void {\n super.updated(changes);\n if (this.toggles && changes.has('selected')) {\n this.focusElement.setAttribute(\n 'aria-pressed',\n this.selected ? 'true' : 'false'\n );\n }\n }\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n longpress: CustomEvent<LongpressEvent>;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ActionButton.js","sourceRoot":"","sources":["ActionButton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAGH,IAAI,EAEJ,UAAU,GAEb,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAClD,OAAO,oBAAoB,MAAM,wEAAwE,CAAC;AAC1G,OAAO,uEAAuE,CAAC;AAE/E,MAAM,mBAAmB,GAAG;IACxB,CAAC,EAAE,kCAAkC;IACrC,CAAC,EAAE,mCAAmC;IACtC,CAAC,EAAE,mCAAmC;IACtC,EAAE,EAAE,mCAAmC;CAC1C,CAAC;AAEF,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,IAAI,iBAAgD,CAAC;AAMrD;;;;;;;;;GASG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU,CAAC,UAAU,CAAC;IAwDpD;QACI,KAAK,EAAE,CAAC;QAnDL,eAAU,GAAG,KAAK,CAAC;QAGnB,mBAAc,G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,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAChD,0DAA0D;YAC1D,uDAAuD;YACvD,sDAAsD;YACtD,uCAAuC;YACvC,IAAI,YAAY,EAAE;gBACd,IAAI,CAAC,YAAY,CACb,cAAc,EACd,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CACnC,CAAC;aACL;iBAAM;gBACH,oEAAoE;gBACpE,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;aACxC;SACJ;IACL,CAAC;CACJ;AAvKG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gDACjB;AAG1B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC;oDAC3C;AAG9B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;2CACtB;AAGrB;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;0CACL;AAOvB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;8CACnB;AAQxB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;6CACpB;AAGvB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yCAG1B","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\nconst 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 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({ 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(): void {\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 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 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 get buttonContent(): TemplateResult[] {\n const buttonContent = super.buttonContent;\n if (this.holdAffordance) {\n buttonContent.unshift(html`\n <sp-icon-corner-triangle300\n id=\"hold-affordance\"\n class=\"${holdAffordanceClass[\n this.size as DefaultElementSize\n ]}\"\n ></sp-icon-corner-triangle300>\n `);\n }\n return buttonContent;\n }\n\n protected 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"]}
|