@spectrum-web-components/accordion 0.6.13 → 0.6.15-devmode.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +34 -13
- package/sp-accordion-item.dev.js +3 -0
- package/sp-accordion-item.dev.js.map +7 -0
- package/sp-accordion-item.js +3 -14
- package/sp-accordion-item.js.map +7 -1
- package/sp-accordion.dev.js +3 -0
- package/sp-accordion.dev.js.map +7 -0
- package/sp-accordion.js +3 -14
- package/sp-accordion.js.map +7 -1
- package/src/Accordion.dev.js +75 -0
- package/src/Accordion.dev.js.map +7 -0
- package/src/Accordion.js +66 -74
- package/src/Accordion.js.map +7 -1
- package/src/AccordionItem.dev.js +91 -0
- package/src/AccordionItem.dev.js.map +7 -0
- package/src/AccordionItem.js +68 -74
- package/src/AccordionItem.js.map +7 -1
- package/src/accordion-item.css.dev.js +97 -0
- package/src/accordion-item.css.dev.js.map +7 -0
- package/src/accordion-item.css.js +3 -14
- package/src/accordion-item.css.js.map +7 -1
- package/src/accordion.css.dev.js +10 -0
- package/src/accordion.css.dev.js.map +7 -0
- package/src/accordion.css.js +3 -14
- package/src/accordion.css.js.map +7 -1
- package/src/index.dev.js +3 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +3 -14
- package/src/index.js.map +7 -1
- package/src/spectrum-accordion-item.css.dev.js +94 -0
- package/src/spectrum-accordion-item.css.dev.js.map +7 -0
- package/src/spectrum-accordion-item.css.js +3 -14
- package/src/spectrum-accordion-item.css.js.map +7 -1
- package/src/spectrum-accordion.css.dev.js +10 -0
- package/src/spectrum-accordion.css.dev.js.map +7 -0
- package/src/spectrum-accordion.css.js +3 -14
- package/src/spectrum-accordion.css.js.map +7 -1
- package/stories/accordion.stories.js +33 -44
- package/stories/accordion.stories.js.map +7 -1
- package/test/accordion-item.test.js +95 -106
- package/test/accordion-item.test.js.map +7 -1
- package/test/accordion.test-vrt.js +4 -15
- package/test/accordion.test-vrt.js.map +7 -1
- package/test/accordion.test.js +171 -182
- package/test/accordion.test.js.map +7 -1
- package/test/benchmark/basic-test.js +6 -17
- package/test/benchmark/basic-test.js.map +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/accordion",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.15-devmode.7+8303f3a2a",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -20,13 +20,33 @@
|
|
|
20
20
|
"module": "./src/index.js",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
|
-
".":
|
|
24
|
-
|
|
23
|
+
".": {
|
|
24
|
+
"development": "./src/index.dev.js",
|
|
25
|
+
"default": "./src/index.js"
|
|
26
|
+
},
|
|
25
27
|
"./package.json": "./package.json",
|
|
26
|
-
"./
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
"./src/Accordion.js": {
|
|
29
|
+
"development": "./src/Accordion.dev.js",
|
|
30
|
+
"default": "./src/Accordion.js"
|
|
31
|
+
},
|
|
32
|
+
"./src/AccordionItem.js": {
|
|
33
|
+
"development": "./src/AccordionItem.dev.js",
|
|
34
|
+
"default": "./src/AccordionItem.js"
|
|
35
|
+
},
|
|
36
|
+
"./src/accordion-item.css.js": "./src/accordion-item.css.js",
|
|
37
|
+
"./src/accordion.css.js": "./src/accordion.css.js",
|
|
38
|
+
"./src/index.js": {
|
|
39
|
+
"development": "./src/index.dev.js",
|
|
40
|
+
"default": "./src/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./sp-accordion.js": {
|
|
43
|
+
"development": "./sp-accordion.dev.js",
|
|
44
|
+
"default": "./sp-accordion.js"
|
|
45
|
+
},
|
|
46
|
+
"./sp-accordion-item.js": {
|
|
47
|
+
"development": "./sp-accordion-item.dev.js",
|
|
48
|
+
"default": "./sp-accordion-item.js"
|
|
49
|
+
}
|
|
30
50
|
},
|
|
31
51
|
"scripts": {
|
|
32
52
|
"test": "karma start --coverage"
|
|
@@ -46,19 +66,20 @@
|
|
|
46
66
|
"lit-html"
|
|
47
67
|
],
|
|
48
68
|
"dependencies": {
|
|
49
|
-
"@spectrum-web-components/base": "^0.5.
|
|
50
|
-
"@spectrum-web-components/icon": "^0.11.
|
|
51
|
-
"@spectrum-web-components/icons-ui": "^0.8.
|
|
52
|
-
"@spectrum-web-components/
|
|
69
|
+
"@spectrum-web-components/base": "^0.5.9-devmode.31+8303f3a2a",
|
|
70
|
+
"@spectrum-web-components/icon": "^0.11.12-devmode.7+8303f3a2a",
|
|
71
|
+
"@spectrum-web-components/icons-ui": "^0.8.12-devmode.7+8303f3a2a",
|
|
72
|
+
"@spectrum-web-components/reactive-controllers": "^0.2.5-devmode.86+8303f3a2a",
|
|
73
|
+
"@spectrum-web-components/shared": "^0.14.5-devmode.7+8303f3a2a",
|
|
53
74
|
"tslib": "^2.0.0"
|
|
54
75
|
},
|
|
55
76
|
"devDependencies": {
|
|
56
|
-
"@spectrum-css/accordion": "^3.0.
|
|
77
|
+
"@spectrum-css/accordion": "^3.0.24"
|
|
57
78
|
},
|
|
58
79
|
"types": "./src/index.d.ts",
|
|
59
80
|
"customElements": "custom-elements.json",
|
|
60
81
|
"sideEffects": [
|
|
61
82
|
"./sp-*.js"
|
|
62
83
|
],
|
|
63
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "8303f3a2a90b0aedc15158797662ccfa8f4a2031"
|
|
64
85
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-accordion-item.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*/\nimport { AccordionItem } from './src/AccordionItem.dev.js'\n\ncustomElements.define('sp-accordion-item', AccordionItem);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-accordion-item': AccordionItem;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAWA;AAEA,eAAe,OAAO,qBAAqB,aAAa;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-accordion-item.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
import { AccordionItem } from './src/AccordionItem.js';
|
|
13
|
-
customElements.define('sp-accordion-item', AccordionItem);
|
|
14
|
-
//# sourceMappingURL=sp-accordion-item.js.map
|
|
1
|
+
import { AccordionItem } from "./src/AccordionItem.js";
|
|
2
|
+
customElements.define("sp-accordion-item", AccordionItem);
|
|
3
|
+
//# sourceMappingURL=sp-accordion-item.js.map
|
package/sp-accordion-item.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-accordion-item.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*/\nimport { AccordionItem } from './src/AccordionItem.js';\n\ncustomElements.define('sp-accordion-item', AccordionItem);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-accordion-item': AccordionItem;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAWA;AAEA,eAAe,OAAO,qBAAqB,aAAa;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-accordion.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*/\nimport { Accordion } from './src/Accordion.dev.js'\n\ncustomElements.define('sp-accordion', Accordion);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-accordion': Accordion;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAWA;AAEA,eAAe,OAAO,gBAAgB,SAAS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-accordion.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
import { Accordion } from './src/Accordion.js';
|
|
13
|
-
customElements.define('sp-accordion', Accordion);
|
|
14
|
-
//# sourceMappingURL=sp-accordion.js.map
|
|
1
|
+
import { Accordion } from "./src/Accordion.js";
|
|
2
|
+
customElements.define("sp-accordion", Accordion);
|
|
3
|
+
//# sourceMappingURL=sp-accordion.js.map
|
package/sp-accordion.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-accordion.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*/\nimport { Accordion } from './src/Accordion.js';\n\ncustomElements.define('sp-accordion', Accordion);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-accordion': Accordion;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAWA;AAEA,eAAe,OAAO,gBAAgB,SAAS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
html,
|
|
14
|
+
SpectrumElement
|
|
15
|
+
} from "@spectrum-web-components/base";
|
|
16
|
+
import {
|
|
17
|
+
property,
|
|
18
|
+
queryAssignedNodes
|
|
19
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
|
20
|
+
import { FocusGroupController } from "@spectrum-web-components/reactive-controllers/src/FocusGroup.js";
|
|
21
|
+
import styles from "./accordion.css.js";
|
|
22
|
+
export class Accordion extends SpectrumElement {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.allowMultiple = false;
|
|
26
|
+
this.focusGroupController = new FocusGroupController(this, {
|
|
27
|
+
direction: "vertical",
|
|
28
|
+
elements: () => this.items,
|
|
29
|
+
isFocusableElement: (el) => !el.disabled
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
static get styles() {
|
|
33
|
+
return [styles];
|
|
34
|
+
}
|
|
35
|
+
get items() {
|
|
36
|
+
return [...this.defaultNodes || []].filter((node) => typeof node.tagName !== "undefined");
|
|
37
|
+
}
|
|
38
|
+
focus() {
|
|
39
|
+
this.focusGroupController.focus();
|
|
40
|
+
}
|
|
41
|
+
async onToggle(event) {
|
|
42
|
+
const target = event.target;
|
|
43
|
+
await 0;
|
|
44
|
+
if (this.allowMultiple || event.defaultPrevented) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const items = [...this.items];
|
|
48
|
+
if (items && !items.length) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
items.forEach((item) => {
|
|
52
|
+
if (item !== target) {
|
|
53
|
+
item.open = false;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
handleSlotchange() {
|
|
58
|
+
this.focusGroupController.clearElementCache();
|
|
59
|
+
}
|
|
60
|
+
render() {
|
|
61
|
+
return html`
|
|
62
|
+
<slot
|
|
63
|
+
@slotchange=${this.handleSlotchange}
|
|
64
|
+
@sp-accordion-item-toggle=${this.onToggle}
|
|
65
|
+
></slot>
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
__decorateClass([
|
|
70
|
+
property({ type: Boolean, reflect: true, attribute: "allow-multiple" })
|
|
71
|
+
], Accordion.prototype, "allowMultiple", 2);
|
|
72
|
+
__decorateClass([
|
|
73
|
+
queryAssignedNodes()
|
|
74
|
+
], Accordion.prototype, "defaultNodes", 2);
|
|
75
|
+
//# sourceMappingURL=Accordion.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["Accordion.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 html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n queryAssignedNodes,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { FocusGroupController } from '@spectrum-web-components/reactive-controllers/src/FocusGroup.js';\n\nimport { AccordionItem } from './AccordionItem.dev.js'\n\nimport styles from './accordion.css.js';\n\n/**\n * @element sp-accordion\n * @slot - The sp-accordion-item children to display.\n */\nexport class Accordion extends SpectrumElement {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n /**\n * Allows multiple accordion items to be opened at the same time\n */\n @property({ type: Boolean, reflect: true, attribute: 'allow-multiple' })\n public allowMultiple = false;\n\n @queryAssignedNodes()\n private defaultNodes!: NodeListOf<AccordionItem>;\n\n private get items(): AccordionItem[] {\n return [...(this.defaultNodes || [])].filter(\n (node: HTMLElement) => typeof node.tagName !== 'undefined'\n ) as AccordionItem[];\n }\n\n focusGroupController = new FocusGroupController<AccordionItem>(this, {\n direction: 'vertical',\n elements: () => this.items,\n isFocusableElement: (el: AccordionItem) => !el.disabled,\n });\n\n public override focus(): void {\n this.focusGroupController.focus();\n }\n\n private async onToggle(event: Event): Promise<void> {\n const target = event.target as AccordionItem;\n // Let the event pass through the DOM so that it can be\n // prevented from the outside if a user so desires.\n await 0;\n if (this.allowMultiple || event.defaultPrevented) {\n // No toggling when `allowMultiple` or the user prevents it.\n return;\n }\n const items = [...this.items] as AccordionItem[];\n /* c8 ignore next 3 */\n if (items && !items.length) {\n // no toggling when there aren't items.\n return;\n }\n items.forEach((item) => {\n if (item !== target) {\n // Close all the items that didn't dispatch the event.\n item.open = false;\n }\n });\n }\n\n private handleSlotchange(): void {\n this.focusGroupController.clearElementCache();\n }\n\n protected override render(): TemplateResult {\n return html`\n <slot\n @slotchange=${this.handleSlotchange}\n @sp-accordion-item-toggle=${this.onToggle}\n ></slot>\n `;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAYA;AAAA;AAAA;AAAA;AAMA;AAAA;AAAA;AAAA;AAIA;AAIA;AAMO,aAAM,kBAAkB,gBAAgB;AAAA,EAAxC;AAAA;AASI,yBAAgB;AAWvB,gCAAuB,IAAI,qBAAoC,MAAM;AAAA,MACjE,WAAW;AAAA,MACX,UAAU,MAAM,KAAK;AAAA,MACrB,oBAAoB,CAAC,OAAsB,CAAC,GAAG;AAAA,IACnD,CAAC;AAAA;AAAA,aAvB0B,SAAyB;AAChD,WAAO,CAAC,MAAM;AAAA,EAClB;AAAA,MAWY,QAAyB;AACjC,WAAO,CAAC,GAAI,KAAK,gBAAgB,CAAC,CAAE,EAAE,OAClC,CAAC,SAAsB,OAAO,KAAK,YAAY,WACnD;AAAA,EACJ;AAAA,EAQgB,QAAc;AAC1B,SAAK,qBAAqB,MAAM;AAAA,EACpC;AAAA,QAEc,SAAS,OAA6B;AAChD,UAAM,SAAS,MAAM;AAGrB,UAAM;AACN,QAAI,KAAK,iBAAiB,MAAM,kBAAkB;AAE9C;AAAA,IACJ;AACA,UAAM,QAAQ,CAAC,GAAG,KAAK,KAAK;AAE5B,QAAI,SAAS,CAAC,MAAM,QAAQ;AAExB;AAAA,IACJ;AACA,UAAM,QAAQ,CAAC,SAAS;AACpB,UAAI,SAAS,QAAQ;AAEjB,aAAK,OAAO;AAAA,MAChB;AAAA,IACJ,CAAC;AAAA,EACL;AAAA,EAEQ,mBAAyB;AAC7B,SAAK,qBAAqB,kBAAkB;AAAA,EAChD;AAAA,EAEmB,SAAyB;AACxC,WAAO;AAAA;AAAA,8BAEe,KAAK;AAAA,4CACS,KAAK;AAAA;AAAA;AAAA,EAG7C;AACJ;AAxDW;AAAA,EADP,AAAC,SAAS,EAAE,MAAM,SAAS,SAAS,MAAM,WAAW,iBAAiB,CAAC;AAAA,GAChE,AATJ,UASI;AAGC;AAAA,EADR,AAAC,mBAAmB;AAAA,GACZ,AAZL,UAYK;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/Accordion.js
CHANGED
|
@@ -1,83 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
html,
|
|
14
|
+
SpectrumElement
|
|
15
|
+
} from "@spectrum-web-components/base";
|
|
16
|
+
import {
|
|
17
|
+
property,
|
|
18
|
+
queryAssignedNodes
|
|
19
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
|
20
|
+
import { FocusGroupController } from "@spectrum-web-components/reactive-controllers/src/FocusGroup.js";
|
|
21
|
+
import styles from "./accordion.css.js";
|
|
21
22
|
export class Accordion extends SpectrumElement {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.allowMultiple = false;
|
|
26
|
+
this.focusGroupController = new FocusGroupController(this, {
|
|
27
|
+
direction: "vertical",
|
|
28
|
+
elements: () => this.items,
|
|
29
|
+
isFocusableElement: (el) => !el.disabled
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
static get styles() {
|
|
33
|
+
return [styles];
|
|
34
|
+
}
|
|
35
|
+
get items() {
|
|
36
|
+
return [...this.defaultNodes || []].filter((node) => typeof node.tagName !== "undefined");
|
|
37
|
+
}
|
|
38
|
+
focus() {
|
|
39
|
+
this.focusGroupController.focus();
|
|
40
|
+
}
|
|
41
|
+
async onToggle(event) {
|
|
42
|
+
const target = event.target;
|
|
43
|
+
await 0;
|
|
44
|
+
if (this.allowMultiple || event.defaultPrevented) {
|
|
45
|
+
return;
|
|
33
46
|
}
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
const items = [...this.items];
|
|
48
|
+
if (items && !items.length) {
|
|
49
|
+
return;
|
|
36
50
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (this.allowMultiple || event.defaultPrevented) {
|
|
49
|
-
// No toggling when `allowMultiple` or the user prevents it.
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const items = [...this.items];
|
|
53
|
-
/* c8 ignore next 3 */
|
|
54
|
-
if (items && !items.length) {
|
|
55
|
-
// no toggling when there aren't items.
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
items.forEach((item) => {
|
|
59
|
-
if (item !== target) {
|
|
60
|
-
// Close all the items that didn't dispatch the event.
|
|
61
|
-
item.open = false;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
handleSlotchange() {
|
|
66
|
-
this.focusGroupController.clearElementCache();
|
|
67
|
-
}
|
|
68
|
-
render() {
|
|
69
|
-
return html `
|
|
51
|
+
items.forEach((item) => {
|
|
52
|
+
if (item !== target) {
|
|
53
|
+
item.open = false;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
handleSlotchange() {
|
|
58
|
+
this.focusGroupController.clearElementCache();
|
|
59
|
+
}
|
|
60
|
+
render() {
|
|
61
|
+
return html`
|
|
70
62
|
<slot
|
|
71
63
|
@slotchange=${this.handleSlotchange}
|
|
72
64
|
@sp-accordion-item-toggle=${this.onToggle}
|
|
73
65
|
></slot>
|
|
74
66
|
`;
|
|
75
|
-
|
|
67
|
+
}
|
|
76
68
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
], Accordion.prototype, "allowMultiple",
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
], Accordion.prototype, "defaultNodes",
|
|
83
|
-
//# sourceMappingURL=Accordion.js.map
|
|
69
|
+
__decorateClass([
|
|
70
|
+
property({ type: Boolean, reflect: true, attribute: "allow-multiple" })
|
|
71
|
+
], Accordion.prototype, "allowMultiple", 2);
|
|
72
|
+
__decorateClass([
|
|
73
|
+
queryAssignedNodes()
|
|
74
|
+
], Accordion.prototype, "defaultNodes", 2);
|
|
75
|
+
//# sourceMappingURL=Accordion.js.map
|
package/src/Accordion.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["Accordion.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 html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n queryAssignedNodes,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { FocusGroupController } from '@spectrum-web-components/reactive-controllers/src/FocusGroup.js';\n\nimport { AccordionItem } from './AccordionItem.js';\n\nimport styles from './accordion.css.js';\n\n/**\n * @element sp-accordion\n * @slot - The sp-accordion-item children to display.\n */\nexport class Accordion extends SpectrumElement {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n /**\n * Allows multiple accordion items to be opened at the same time\n */\n @property({ type: Boolean, reflect: true, attribute: 'allow-multiple' })\n public allowMultiple = false;\n\n @queryAssignedNodes()\n private defaultNodes!: NodeListOf<AccordionItem>;\n\n private get items(): AccordionItem[] {\n return [...(this.defaultNodes || [])].filter(\n (node: HTMLElement) => typeof node.tagName !== 'undefined'\n ) as AccordionItem[];\n }\n\n focusGroupController = new FocusGroupController<AccordionItem>(this, {\n direction: 'vertical',\n elements: () => this.items,\n isFocusableElement: (el: AccordionItem) => !el.disabled,\n });\n\n public override focus(): void {\n this.focusGroupController.focus();\n }\n\n private async onToggle(event: Event): Promise<void> {\n const target = event.target as AccordionItem;\n // Let the event pass through the DOM so that it can be\n // prevented from the outside if a user so desires.\n await 0;\n if (this.allowMultiple || event.defaultPrevented) {\n // No toggling when `allowMultiple` or the user prevents it.\n return;\n }\n const items = [...this.items] as AccordionItem[];\n /* c8 ignore next 3 */\n if (items && !items.length) {\n // no toggling when there aren't items.\n return;\n }\n items.forEach((item) => {\n if (item !== target) {\n // Close all the items that didn't dispatch the event.\n item.open = false;\n }\n });\n }\n\n private handleSlotchange(): void {\n this.focusGroupController.clearElementCache();\n }\n\n protected override render(): TemplateResult {\n return html`\n <slot\n @slotchange=${this.handleSlotchange}\n @sp-accordion-item-toggle=${this.onToggle}\n ></slot>\n `;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAYA;AAAA;AAAA;AAAA;AAMA;AAAA;AAAA;AAAA;AAIA;AAIA;AAMO,aAAM,kBAAkB,gBAAgB;AAAA,EAAxC;AAAA;AASI,yBAAgB;AAWvB,gCAAuB,IAAI,qBAAoC,MAAM;AAAA,MACjE,WAAW;AAAA,MACX,UAAU,MAAM,KAAK;AAAA,MACrB,oBAAoB,CAAC,OAAsB,CAAC,GAAG;AAAA,IACnD,CAAC;AAAA;AAAA,aAvB0B,SAAyB;AAChD,WAAO,CAAC,MAAM;AAAA,EAClB;AAAA,MAWY,QAAyB;AACjC,WAAO,CAAC,GAAI,KAAK,gBAAgB,CAAC,CAAE,EAAE,OAClC,CAAC,SAAsB,OAAO,KAAK,YAAY,WACnD;AAAA,EACJ;AAAA,EAQgB,QAAc;AAC1B,SAAK,qBAAqB,MAAM;AAAA,EACpC;AAAA,QAEc,SAAS,OAA6B;AAChD,UAAM,SAAS,MAAM;AAGrB,UAAM;AACN,QAAI,KAAK,iBAAiB,MAAM,kBAAkB;AAE9C;AAAA,IACJ;AACA,UAAM,QAAQ,CAAC,GAAG,KAAK,KAAK;AAE5B,QAAI,SAAS,CAAC,MAAM,QAAQ;AAExB;AAAA,IACJ;AACA,UAAM,QAAQ,CAAC,SAAS;AACpB,UAAI,SAAS,QAAQ;AAEjB,aAAK,OAAO;AAAA,MAChB;AAAA,IACJ,CAAC;AAAA,EACL;AAAA,EAEQ,mBAAyB;AAC7B,SAAK,qBAAqB,kBAAkB;AAAA,EAChD;AAAA,EAEmB,SAAyB;AACxC,WAAO;AAAA;AAAA,8BAEe,KAAK;AAAA,4CACS,KAAK;AAAA;AAAA;AAAA,EAG7C;AACJ;AAxDW;AAAA,EADP,AAAC,SAAS,EAAE,MAAM,SAAS,SAAS,MAAM,WAAW,iBAAiB,CAAC;AAAA,GAChE,AATJ,UASI;AAGC;AAAA,EADR,AAAC,mBAAmB;AAAA,GACZ,AAZL,UAYK;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
html
|
|
14
|
+
} from "@spectrum-web-components/base";
|
|
15
|
+
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
|
16
|
+
import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
|
|
17
|
+
import "@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js";
|
|
18
|
+
import chevronIconStyles from "@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";
|
|
19
|
+
import styles from "./accordion-item.css.js";
|
|
20
|
+
export class AccordionItem extends Focusable {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(...arguments);
|
|
23
|
+
this.open = false;
|
|
24
|
+
this.label = "";
|
|
25
|
+
this.disabled = false;
|
|
26
|
+
}
|
|
27
|
+
static get styles() {
|
|
28
|
+
return [styles, chevronIconStyles];
|
|
29
|
+
}
|
|
30
|
+
get focusElement() {
|
|
31
|
+
return this.shadowRoot.querySelector("#header");
|
|
32
|
+
}
|
|
33
|
+
onClick() {
|
|
34
|
+
if (this.disabled) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.toggle();
|
|
38
|
+
}
|
|
39
|
+
toggle() {
|
|
40
|
+
this.open = !this.open;
|
|
41
|
+
const applyDefault = this.dispatchEvent(new CustomEvent("sp-accordion-item-toggle", {
|
|
42
|
+
bubbles: true,
|
|
43
|
+
composed: true,
|
|
44
|
+
cancelable: true
|
|
45
|
+
}));
|
|
46
|
+
if (!applyDefault) {
|
|
47
|
+
this.open = !this.open;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
render() {
|
|
51
|
+
return html`
|
|
52
|
+
<h3 id="heading">
|
|
53
|
+
<button
|
|
54
|
+
id="header"
|
|
55
|
+
@click=${this.onClick}
|
|
56
|
+
aria-expanded=${this.open}
|
|
57
|
+
aria-controls="content"
|
|
58
|
+
?disabled=${this.disabled}
|
|
59
|
+
>
|
|
60
|
+
${this.label}
|
|
61
|
+
</button>
|
|
62
|
+
<sp-icon-chevron100
|
|
63
|
+
class="indicator spectrum-UIIcon-ChevronRight100"
|
|
64
|
+
></sp-icon-chevron100>
|
|
65
|
+
</h3>
|
|
66
|
+
<div id="content" role="region" aria-labelledby="header">
|
|
67
|
+
<slot></slot>
|
|
68
|
+
</div>
|
|
69
|
+
`;
|
|
70
|
+
}
|
|
71
|
+
updated(changes) {
|
|
72
|
+
super.updated(changes);
|
|
73
|
+
if (changes.has("disabled")) {
|
|
74
|
+
if (this.disabled) {
|
|
75
|
+
this.setAttribute("aria-disabled", "true");
|
|
76
|
+
} else {
|
|
77
|
+
this.removeAttribute("aria-disabled");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
__decorateClass([
|
|
83
|
+
property({ type: Boolean, reflect: true })
|
|
84
|
+
], AccordionItem.prototype, "open", 2);
|
|
85
|
+
__decorateClass([
|
|
86
|
+
property({ type: String, reflect: true })
|
|
87
|
+
], AccordionItem.prototype, "label", 2);
|
|
88
|
+
__decorateClass([
|
|
89
|
+
property({ type: Boolean, reflect: true })
|
|
90
|
+
], AccordionItem.prototype, "disabled", 2);
|
|
91
|
+
//# sourceMappingURL=AccordionItem.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["AccordionItem.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 html,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js';\nimport chevronIconStyles from '@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js';\n\nimport styles from './accordion-item.css.js';\n\n/**\n * @element sp-accordion-item\n * @slot - The content of the item that is hidden when the item is not open\n * @fires sp-accordion-item-toggle - Announce that an accordion item has been toggled while allowing the event to be cancelled.\n */\nexport class AccordionItem extends Focusable {\n public static override get styles(): CSSResultArray {\n return [styles, chevronIconStyles];\n }\n\n @property({ type: Boolean, reflect: true })\n public open = false;\n\n @property({ type: String, reflect: true })\n public label = '';\n\n @property({ type: Boolean, reflect: true })\n public override disabled = false;\n\n public override get focusElement(): HTMLElement {\n return this.shadowRoot.querySelector('#header') as HTMLElement;\n }\n\n private onClick(): void {\n /* c8 ignore next 3 */\n if (this.disabled) {\n return;\n }\n this.toggle();\n }\n\n private toggle(): void {\n this.open = !this.open;\n const applyDefault = this.dispatchEvent(\n new CustomEvent('sp-accordion-item-toggle', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n if (!applyDefault) {\n this.open = !this.open;\n }\n }\n\n protected override render(): TemplateResult {\n return html`\n <h3 id=\"heading\">\n <button\n id=\"header\"\n @click=${this.onClick}\n aria-expanded=${this.open}\n aria-controls=\"content\"\n ?disabled=${this.disabled}\n >\n ${this.label}\n </button>\n <sp-icon-chevron100\n class=\"indicator spectrum-UIIcon-ChevronRight100\"\n ></sp-icon-chevron100>\n </h3>\n <div id=\"content\" role=\"region\" aria-labelledby=\"header\">\n <slot></slot>\n </div>\n `;\n }\n\n protected override updated(changes: PropertyValues): void {\n super.updated(changes);\n if (changes.has('disabled')) {\n if (this.disabled) {\n this.setAttribute('aria-disabled', 'true');\n } else {\n this.removeAttribute('aria-disabled');\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAYA;AAAA;AAAA;AAMA;AACA;AACA;AACA;AAEA;AAOO,aAAM,sBAAsB,UAAU;AAAA,EAAtC;AAAA;AAMI,gBAAO;AAGP,iBAAQ;AAGC,oBAAW;AAAA;AAAA,aAXA,SAAyB;AAChD,WAAO,CAAC,QAAQ,iBAAiB;AAAA,EACrC;AAAA,MAWoB,eAA4B;AAC5C,WAAO,KAAK,WAAW,cAAc,SAAS;AAAA,EAClD;AAAA,EAEQ,UAAgB;AAEpB,QAAI,KAAK,UAAU;AACf;AAAA,IACJ;AACA,SAAK,OAAO;AAAA,EAChB;AAAA,EAEQ,SAAe;AACnB,SAAK,OAAO,CAAC,KAAK;AAClB,UAAM,eAAe,KAAK,cACtB,IAAI,YAAY,4BAA4B;AAAA,MACxC,SAAS;AAAA,MACT,UAAU;AAAA,MACV,YAAY;AAAA,IAChB,CAAC,CACL;AACA,QAAI,CAAC,cAAc;AACf,WAAK,OAAO,CAAC,KAAK;AAAA,IACtB;AAAA,EACJ;AAAA,EAEmB,SAAyB;AACxC,WAAO;AAAA;AAAA;AAAA;AAAA,6BAIc,KAAK;AAAA,oCACE,KAAK;AAAA;AAAA,gCAET,KAAK;AAAA;AAAA,sBAEf,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUvB;AAAA,EAEmB,QAAQ,SAA+B;AACtD,UAAM,QAAQ,OAAO;AACrB,QAAI,QAAQ,IAAI,UAAU,GAAG;AACzB,UAAI,KAAK,UAAU;AACf,aAAK,aAAa,iBAAiB,MAAM;AAAA,MAC7C,OAAO;AACH,aAAK,gBAAgB,eAAe;AAAA,MACxC;AAAA,IACJ;AAAA,EACJ;AACJ;AAlEW;AAAA,EADP,AAAC,SAAS,EAAE,MAAM,SAAS,SAAS,KAAK,CAAC;AAAA,GACnC,AANJ,cAMI;AAGA;AAAA,EADP,AAAC,SAAS,EAAE,MAAM,QAAQ,SAAS,KAAK,CAAC;AAAA,GAClC,AATJ,cASI;AAGS;AAAA,EADhB,AAAC,SAAS,EAAE,MAAM,SAAS,SAAS,KAAK,CAAC;AAAA,GAC1B,AAZb,cAYa;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|