@govtechsg/sgds-web-component 1.3.0 → 1.3.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/components/Accordion/index.umd.js +41 -16
- package/components/Accordion/index.umd.js.map +1 -1
- package/components/Accordion/sgds-accordion-item.cjs.js +31 -10
- package/components/Accordion/sgds-accordion-item.cjs.js.map +1 -1
- package/components/Accordion/sgds-accordion-item.cjs2.js +1 -1
- package/components/Accordion/sgds-accordion-item.js +31 -10
- package/components/Accordion/sgds-accordion-item.js.map +1 -1
- package/components/Accordion/sgds-accordion-item2.js +1 -1
- package/components/Accordion/sgds-accordion.cjs.js +9 -5
- package/components/Accordion/sgds-accordion.cjs.js.map +1 -1
- package/components/Accordion/sgds-accordion.d.ts +2 -1
- package/components/Accordion/sgds-accordion.js +9 -5
- package/components/Accordion/sgds-accordion.js.map +1 -1
- package/components/index.umd.js +41 -16
- package/components/index.umd.js.map +1 -1
- package/index.umd.js +41 -16
- package/index.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -40,8 +40,8 @@ class SgdsAccordionItem extends sgdsElement["default"] {
|
|
|
40
40
|
this.open = false;
|
|
41
41
|
}
|
|
42
42
|
firstUpdated() {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
if (!this.open)
|
|
44
|
+
this.body.classList.add("hidden");
|
|
45
45
|
}
|
|
46
46
|
handleSummaryClick() {
|
|
47
47
|
if (this.open) {
|
|
@@ -80,10 +80,9 @@ class SgdsAccordionItem extends sgdsElement["default"] {
|
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
82
|
await animate.stopAnimations(this.body);
|
|
83
|
-
this.body.hidden
|
|
83
|
+
this.body.classList.remove("hidden");
|
|
84
84
|
const { keyframes, options } = animationRegistry.getAnimation(this, "accordion.show");
|
|
85
85
|
await animate.animateTo(this.body, animate.shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
|
|
86
|
-
this.body.style.height = "auto";
|
|
87
86
|
this.emit("sgds-after-show");
|
|
88
87
|
}
|
|
89
88
|
else {
|
|
@@ -95,9 +94,13 @@ class SgdsAccordionItem extends sgdsElement["default"] {
|
|
|
95
94
|
}
|
|
96
95
|
await animate.stopAnimations(this.body);
|
|
97
96
|
const { keyframes, options } = animationRegistry.getAnimation(this, "accordion.hide");
|
|
97
|
+
const animationDuration = options.duration;
|
|
98
|
+
// Workaround to fix GSIB delay after animateTo.
|
|
99
|
+
//Setting a timeout of duration slightly less than animation's duraton to prevent case where animation runs faster than .hidden class is added
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
this.body.classList.add("hidden");
|
|
102
|
+
}, animationDuration - 20);
|
|
98
103
|
await animate.animateTo(this.body, animate.shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
|
|
99
|
-
this.body.hidden = true;
|
|
100
|
-
this.body.style.height = "auto";
|
|
101
104
|
this.emit("sgds-after-hide");
|
|
102
105
|
}
|
|
103
106
|
}
|
|
@@ -123,7 +126,8 @@ class SgdsAccordionItem extends sgdsElement["default"] {
|
|
|
123
126
|
part="base"
|
|
124
127
|
class=${classMap_js.classMap({
|
|
125
128
|
"sgds accordion-item": true,
|
|
126
|
-
[`${this.accordionItemClasses}`]: this.accordionItemClasses
|
|
129
|
+
[`${this.accordionItemClasses}`]: this.accordionItemClasses,
|
|
130
|
+
show: this.open
|
|
127
131
|
})}
|
|
128
132
|
>
|
|
129
133
|
<button
|
|
@@ -140,8 +144,25 @@ class SgdsAccordionItem extends sgdsElement["default"] {
|
|
|
140
144
|
@keydown=${this.handleSummaryKeyDown}
|
|
141
145
|
>
|
|
142
146
|
<slot name="accordion-header"></slot>
|
|
147
|
+
<svg
|
|
148
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
149
|
+
width="16"
|
|
150
|
+
height="16"
|
|
151
|
+
fill="currentColor"
|
|
152
|
+
class="bi bi-chevron-down"
|
|
153
|
+
viewBox="0 0 16 16"
|
|
154
|
+
>
|
|
155
|
+
<path
|
|
156
|
+
fill-rule="evenodd"
|
|
157
|
+
d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"
|
|
158
|
+
/>
|
|
159
|
+
</svg>
|
|
143
160
|
</button>
|
|
144
|
-
<div
|
|
161
|
+
<div
|
|
162
|
+
class=${classMap_js.classMap({
|
|
163
|
+
"accordion-body": true
|
|
164
|
+
})}
|
|
165
|
+
>
|
|
145
166
|
<slot name="accordion-content" class="accordion-content" role="region" aria-labelledby="header"></slot>
|
|
146
167
|
</div>
|
|
147
168
|
</div>
|
|
@@ -172,14 +193,14 @@ animationRegistry.setDefaultAnimation("accordion.show", {
|
|
|
172
193
|
{ height: "0", opacity: "0" },
|
|
173
194
|
{ height: "auto", opacity: "1" }
|
|
174
195
|
],
|
|
175
|
-
options: { duration:
|
|
196
|
+
options: { duration: 350, easing: "ease-in-out" }
|
|
176
197
|
});
|
|
177
198
|
animationRegistry.setDefaultAnimation("accordion.hide", {
|
|
178
199
|
keyframes: [
|
|
179
200
|
{ height: "auto", opacity: "1" },
|
|
180
201
|
{ height: "0", opacity: "0" }
|
|
181
202
|
],
|
|
182
|
-
options: { duration:
|
|
203
|
+
options: { duration: 350, easing: "ease-in-out" }
|
|
183
204
|
});
|
|
184
205
|
|
|
185
206
|
exports.SgdsAccordionItem = SgdsAccordionItem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sgds-accordion-item.cjs.js","sources":["../../../src/components/Accordion/sgds-accordion-item.ts"],"sourcesContent":["import { html } from \"lit\";\nimport { property, query } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport { animateTo, shimKeyframesHeightAuto, stopAnimations } from \"../../utils/animate\";\nimport { getAnimation, setDefaultAnimation } from \"../../utils/animation-registry\";\nimport { waitForEvent } from \"../../utils/event\";\nimport { watch } from \"../../utils/watch\";\nimport styles from \"./sgds-accordion-item.scss\";\n\n/**\n *\n * @event sgds-show - Emitted on show.\n * @event sgds-after-show - Emitted on show after animation has completed.\n * @event sgds-hide - Emitted on hide.\n * @event sgds-after-hide - Emitted on hide after animation has completed.\n *\n * @csspart base - The accordion-item base wrapper.\n * @csspart header - The accordion-item button header.\n * @csspart content - The accordion-item content.\n *\n * @slot accordion-header - The accordion-item button header slot.\n * @slot accordion-content - The accordion-item content slot.\n *\n * @cssprop --accordion-item-padding-y - The top and bottom padding for the container of accordion item's content\n * @cssprop --accordion-item-padding-x - The right and left padding for the container of accordion item's content\n * @cssprop --accordion-item-border-radius - The border radius of the accordion item\n * @cssprop --accordion-item-font-weight - The font weight of accordion-button when it is not collapsed\n * @cssprop --accordion-item-line-height - The line height of accordion\n */\nexport class SgdsAccordionItem extends SgdsElement {\n static styles = [SgdsElement.styles, styles];\n /** @internal */\n @query(\".accordion-item\") accordion: HTMLElement;\n /** @internal */\n @query(\".accordion-button\") header: HTMLElement;\n /** @internal */\n @query(\".accordion-body\") body: HTMLElement;\n\n /** Controls whether accordion-item is open or close */\n @property({ type: Boolean, reflect: true }) open = false;\n\n /** Optional for accordion item. Can be used to insert any utility classes such as `me-auto` */\n @property({ reflect: true }) accordionItemClasses: string;\n\n firstUpdated() {\n this.body.hidden = !this.open;\n this.body.style.height = this.open ? \"auto\" : \"0\";\n }\n\n private handleSummaryClick() {\n if (this.open) {\n this.hide();\n } else {\n this.show();\n }\n\n this.header.focus();\n }\n\n private handleSummaryKeyDown(event: KeyboardEvent) {\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n\n if (this.open) {\n this.hide();\n } else {\n this.show();\n }\n }\n\n if (event.key === \"ArrowUp\" || event.key === \"ArrowLeft\") {\n event.preventDefault();\n this.hide();\n }\n\n if (event.key === \"ArrowDown\" || event.key === \"ArrowRight\") {\n event.preventDefault();\n this.show();\n }\n }\n\n @watch(\"open\", { waitUntilFirstUpdate: true })\n async handleOpenChange() {\n if (this.open) {\n // Show\n const sgdsShow = this.emit(\"sgds-show\", { cancelable: true });\n if (sgdsShow.defaultPrevented) {\n this.open = false;\n return;\n }\n\n await stopAnimations(this.body);\n this.body.hidden = false;\n\n const { keyframes, options } = getAnimation(this, \"accordion.show\");\n await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);\n this.body.style.height = \"auto\";\n\n this.emit(\"sgds-after-show\");\n } else {\n // Hide\n const slHide = this.emit(\"sgds-hide\", { cancelable: true });\n if (slHide.defaultPrevented) {\n this.open = true;\n return;\n }\n\n await stopAnimations(this.body);\n\n const { keyframes, options } = getAnimation(this, \"accordion.hide\");\n await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);\n this.body.hidden = true;\n this.body.style.height = \"auto\";\n\n this.emit(\"sgds-after-hide\");\n }\n }\n\n /** Shows the accordion. */\n public async show() {\n if (this.open) {\n return;\n }\n\n this.open = true;\n return waitForEvent(this, \"sgds-after-show\");\n }\n\n /** Hide the accordion */\n public async hide() {\n if (!this.open) {\n return;\n }\n this.open = false;\n return waitForEvent(this, \"sgds-after-hide\");\n }\n\n render() {\n return html`\n <div\n part=\"base\"\n class=${classMap({\n \"sgds accordion-item\": true,\n [`${this.accordionItemClasses}`]: this.accordionItemClasses\n })}\n >\n <button\n class=${classMap({\n \"accordion-button\": true,\n collapsed: !this.open\n })}\n part=\"header\"\n role=\"button\"\n aria-expanded=${this.open ? \"true\" : \"false\"}\n aria-controls=\"content\"\n tabindex=\"0\"\n @click=${this.handleSummaryClick}\n @keydown=${this.handleSummaryKeyDown}\n >\n <slot name=\"accordion-header\"></slot>\n </button>\n <div class=\"accordion-body\">\n <slot name=\"accordion-content\" class=\"accordion-content\" role=\"region\" aria-labelledby=\"header\"></slot>\n </div>\n </div>\n `;\n }\n}\n\nsetDefaultAnimation(\"accordion.show\", {\n keyframes: [\n { height: \"0\", opacity: \"0\" },\n { height: \"auto\", opacity: \"1\" }\n ],\n options: { duration: 200, easing: \"ease-in-out\" }\n});\n\nsetDefaultAnimation(\"accordion.hide\", {\n keyframes: [\n { height: \"auto\", opacity: \"1\" },\n { height: \"0\", opacity: \"0\" }\n ],\n options: { duration: 200, easing: \"ease-in-out\" }\n});\n\nexport default SgdsAccordionItem;\n"],"names":["SgdsElement","stopAnimations","getAnimation","animateTo","shimKeyframesHeightAuto","waitForEvent","html","classMap","styles","__decorate","query","property","watch","setDefaultAnimation"],"mappings":";;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;AAmBG;AACG,MAAO,iBAAkB,SAAQA,sBAAW,CAAA;AAAlD,IAAA,WAAA,GAAA;;;QAU8C,IAAI,CAAA,IAAA,GAAG,KAAK,CAAC;KAgI1D;IA3HC,YAAY,GAAA;QACV,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;AAC9B,QAAA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,GAAG,MAAM,GAAG,GAAG,CAAC;KACnD;IAEO,kBAAkB,GAAA;AACxB,QAAA,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,CAAC,IAAI,EAAE,CAAC;SACb;aAAM;YACL,IAAI,CAAC,IAAI,EAAE,CAAC;SACb;AAED,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KACrB;AAEO,IAAA,oBAAoB,CAAC,KAAoB,EAAA;AAC/C,QAAA,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG,EAAE;YAC9C,KAAK,CAAC,cAAc,EAAE,CAAC;AAEvB,YAAA,IAAI,IAAI,CAAC,IAAI,EAAE;gBACb,IAAI,CAAC,IAAI,EAAE,CAAC;aACb;iBAAM;gBACL,IAAI,CAAC,IAAI,EAAE,CAAC;aACb;SACF;AAED,QAAA,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,IA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E,IAAI,EAAE,CAAC;AAmC7C,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA,CAAA;AAqDHC,qCAAmB,CAAC,gBAAgB,EAAE;AACpC,IAAA,SAAS,EAAE;AACT,QAAA,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;AAC7B,QAAA,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE;AACjC,KAAA;IACD,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE;AAClD,CAAA,CAAC,CAAC;AAEHA,qCAAmB,CAAC,gBAAgB,EAAE;AACpC,IAAA,SAAS,EAAE;AACT,QAAA,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE;AAChC,QAAA,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;AAC9B,KAAA;IACD,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE;AAClD,CAAA,CAAC;;;;;"}
|
|
1
|
+
{"version":3,"file":"sgds-accordion-item.cjs.js","sources":["../../../src/components/Accordion/sgds-accordion-item.ts"],"sourcesContent":["import { html } from \"lit\";\nimport { property, query } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport { animateTo, shimKeyframesHeightAuto, stopAnimations } from \"../../utils/animate\";\nimport { getAnimation, setDefaultAnimation } from \"../../utils/animation-registry\";\nimport { waitForEvent } from \"../../utils/event\";\nimport { watch } from \"../../utils/watch\";\nimport styles from \"./sgds-accordion-item.scss\";\n\n/**\n *\n * @event sgds-show - Emitted on show.\n * @event sgds-after-show - Emitted on show after animation has completed.\n * @event sgds-hide - Emitted on hide.\n * @event sgds-after-hide - Emitted on hide after animation has completed.\n *\n * @csspart base - The accordion-item base wrapper.\n * @csspart header - The accordion-item button header.\n * @csspart content - The accordion-item content.\n *\n * @slot accordion-header - The accordion-item button header slot.\n * @slot accordion-content - The accordion-item content slot.\n *\n * @cssprop --accordion-item-padding-y - The top and bottom padding for the container of accordion item's content\n * @cssprop --accordion-item-padding-x - The right and left padding for the container of accordion item's content\n * @cssprop --accordion-item-border-radius - The border radius of the accordion item\n * @cssprop --accordion-item-font-weight - The font weight of accordion-button when it is not collapsed\n * @cssprop --accordion-item-line-height - The line height of accordion\n */\nexport class SgdsAccordionItem extends SgdsElement {\n static styles = [SgdsElement.styles, styles];\n /** @internal */\n @query(\".accordion-item\") accordion: HTMLElement;\n /** @internal */\n @query(\".accordion-button\") header: HTMLElement;\n /** @internal */\n @query(\".accordion-body\") body: HTMLElement;\n\n /** Controls whether accordion-item is open or close */\n @property({ type: Boolean, reflect: true }) open = false;\n\n /** Optional for accordion item. Can be used to insert any utility classes such as `me-auto` */\n @property({ reflect: true }) accordionItemClasses: string;\n\n firstUpdated() {\n if (!this.open) this.body.classList.add(\"hidden\");\n }\n\n private handleSummaryClick() {\n if (this.open) {\n this.hide();\n } else {\n this.show();\n }\n\n this.header.focus();\n }\n\n private handleSummaryKeyDown(event: KeyboardEvent) {\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n\n if (this.open) {\n this.hide();\n } else {\n this.show();\n }\n }\n\n if (event.key === \"ArrowUp\" || event.key === \"ArrowLeft\") {\n event.preventDefault();\n this.hide();\n }\n\n if (event.key === \"ArrowDown\" || event.key === \"ArrowRight\") {\n event.preventDefault();\n this.show();\n }\n }\n\n @watch(\"open\", { waitUntilFirstUpdate: true })\n async handleOpenChange() {\n if (this.open) {\n // Show\n const sgdsShow = this.emit(\"sgds-show\", { cancelable: true });\n if (sgdsShow.defaultPrevented) {\n this.open = false;\n return;\n }\n\n await stopAnimations(this.body);\n this.body.classList.remove(\"hidden\");\n\n const { keyframes, options } = getAnimation(this, \"accordion.show\");\n await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);\n this.emit(\"sgds-after-show\");\n } else {\n // Hide\n const slHide = this.emit(\"sgds-hide\", { cancelable: true });\n if (slHide.defaultPrevented) {\n this.open = true;\n return;\n }\n\n await stopAnimations(this.body);\n\n const { keyframes, options } = getAnimation(this, \"accordion.hide\");\n const animationDuration = options.duration as number;\n // Workaround to fix GSIB delay after animateTo.\n //Setting a timeout of duration slightly less than animation's duraton to prevent case where animation runs faster than .hidden class is added\n setTimeout(() => {\n this.body.classList.add(\"hidden\");\n }, animationDuration - 20);\n\n await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);\n this.emit(\"sgds-after-hide\");\n }\n }\n\n /** Shows the accordion. */\n public async show() {\n if (this.open) {\n return;\n }\n\n this.open = true;\n return waitForEvent(this, \"sgds-after-show\");\n }\n\n /** Hide the accordion */\n public async hide() {\n if (!this.open) {\n return;\n }\n this.open = false;\n return waitForEvent(this, \"sgds-after-hide\");\n }\n\n render() {\n return html`\n <div\n part=\"base\"\n class=${classMap({\n \"sgds accordion-item\": true,\n [`${this.accordionItemClasses}`]: this.accordionItemClasses,\n show: this.open\n })}\n >\n <button\n class=${classMap({\n \"accordion-button\": true,\n collapsed: !this.open\n })}\n part=\"header\"\n role=\"button\"\n aria-expanded=${this.open ? \"true\" : \"false\"}\n aria-controls=\"content\"\n tabindex=\"0\"\n @click=${this.handleSummaryClick}\n @keydown=${this.handleSummaryKeyDown}\n >\n <slot name=\"accordion-header\"></slot>\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n fill=\"currentColor\"\n class=\"bi bi-chevron-down\"\n viewBox=\"0 0 16 16\"\n >\n <path\n fill-rule=\"evenodd\"\n d=\"M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z\"\n />\n </svg>\n </button>\n <div\n class=${classMap({\n \"accordion-body\": true\n })}\n >\n <slot name=\"accordion-content\" class=\"accordion-content\" role=\"region\" aria-labelledby=\"header\"></slot>\n </div>\n </div>\n `;\n }\n}\n\nsetDefaultAnimation(\"accordion.show\", {\n keyframes: [\n { height: \"0\", opacity: \"0\" },\n { height: \"auto\", opacity: \"1\" }\n ],\n options: { duration: 350, easing: \"ease-in-out\" }\n});\n\nsetDefaultAnimation(\"accordion.hide\", {\n keyframes: [\n { height: \"auto\", opacity: \"1\" },\n { height: \"0\", opacity: \"0\" }\n ],\n options: { duration: 350, easing: \"ease-in-out\" }\n});\n\nexport default SgdsAccordionItem;\n"],"names":["SgdsElement","stopAnimations","getAnimation","animateTo","shimKeyframesHeightAuto","waitForEvent","html","classMap","styles","__decorate","query","property","watch","setDefaultAnimation"],"mappings":";;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;AAmBG;AACG,MAAO,iBAAkB,SAAQA,sBAAW,CAAA;AAAlD,IAAA,WAAA,GAAA;;;QAU8C,IAAI,CAAA,IAAA,GAAG,KAAK,CAAC;KAmJ1D;IA9IC,YAAY,GAAA;QACV,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;KACnD;IAEO,kBAAkB,GAAA;AACxB,QAAA,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,CAAC,IAAI,EAAE,CAAC;SACb;aAAM;YACL,IAAI,CAAC,IAAI,EAAE,CAAC;SACb;AAED,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KACrB;AAEO,IAAA,oBAAoB,CAAC,KAAoB,EAAA;AAC/C,QAAA,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG,EAAE;YAC9C,KAAK,CAAC,cAAc,EAAE,CAAC;AAEvB,YAAA,IAAI,IAAI,CAAC,IAAI,EAAE;gBACb,IAAI,CAAC,IAAI,EA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,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAG5BF,gBAAA,CAAA;AAA5B,IAAAE,sBAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAA8B,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,sBAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAuCpDF,gBAAA,CAAA;IADLG,WAAK,CAAC,MAAM,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;AAqC7C,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA,CAAA;AAuEHC,qCAAmB,CAAC,gBAAgB,EAAE;AACpC,IAAA,SAAS,EAAE;AACT,QAAA,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;AAC7B,QAAA,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE;AACjC,KAAA;IACD,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE;AAClD,CAAA,CAAC,CAAC;AAEHA,qCAAmB,CAAC,gBAAgB,EAAE;AACpC,IAAA,SAAS,EAAE;AACT,QAAA,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE;AAChC,QAAA,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;AAC9B,KAAA;IACD,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE;AAClD,CAAA,CAAC;;;;;"}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var lit = require('lit');
|
|
6
6
|
|
|
7
|
-
var css_248z = lit.css`:host{--accordion-item-padding-y:1rem;--accordion-item-padding-x:1.5rem;--accordion-item-border-radius:0.25rem;--accordion-item-font-weight:700;--accordion-item-line-height:2rem}.accordion-body{line-height:var(--accordion-item-line-height);overflow:hidden;padding:0}.accordion-content{display:block;padding:0 var(--accordion-item-padding-x) var(--accordion-item-padding-y)}.accordion-button{line-height:var(--accordion-item-line-height)}.accordion-button:not(.collapsed){
|
|
7
|
+
var css_248z = lit.css`:host{--accordion-item-padding-y:1rem;--accordion-item-padding-x:1.5rem;--accordion-item-border-radius:0.25rem;--accordion-item-font-weight:700;--accordion-item-line-height:2rem}.accordion-body{line-height:var(--accordion-item-line-height);overflow:hidden;padding:0}.accordion-content{display:block;padding:0 var(--accordion-item-padding-x) var(--accordion-item-padding-y)}.accordion-button{line-height:var(--accordion-item-line-height)}.accordion-button:not(.collapsed){color:var(--accordion-active-color)}.accordion-button svg.bi-chevron-down{height:1.3rem;margin-left:auto;transition:transform .2s ease-in-out;width:1.3rem}.accordion-button:not(.collapsed){box-shadow:none;font-weight:var(--accordion-item-font-weight)}.accordion-button:not(.collapsed) svg.bi-chevron-down{transform:rotate(-180deg)}.accordion-button:after{content:unset}:host([first-of-type]) .accordion-item{border-radius:var(--accordion-item-border-radius) var(--accordion-item-border-radius) 0 0}:host([nth-of-type]) .accordion-item{border-radius:0;border-top:0}:host([last-of-type]) .accordion-item{border-radius:0 0 var(--accordion-item-border-radius) var(--accordion-item-border-radius);border-top:0}.hidden{display:none}`;
|
|
8
8
|
|
|
9
9
|
exports["default"] = css_248z;
|
|
10
10
|
//# sourceMappingURL=sgds-accordion-item.cjs2.js.map
|
|
@@ -36,8 +36,8 @@ class SgdsAccordionItem extends SgdsElement {
|
|
|
36
36
|
this.open = false;
|
|
37
37
|
}
|
|
38
38
|
firstUpdated() {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
if (!this.open)
|
|
40
|
+
this.body.classList.add("hidden");
|
|
41
41
|
}
|
|
42
42
|
handleSummaryClick() {
|
|
43
43
|
if (this.open) {
|
|
@@ -76,10 +76,9 @@ class SgdsAccordionItem extends SgdsElement {
|
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
await stopAnimations(this.body);
|
|
79
|
-
this.body.hidden
|
|
79
|
+
this.body.classList.remove("hidden");
|
|
80
80
|
const { keyframes, options } = getAnimation(this, "accordion.show");
|
|
81
81
|
await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
|
|
82
|
-
this.body.style.height = "auto";
|
|
83
82
|
this.emit("sgds-after-show");
|
|
84
83
|
}
|
|
85
84
|
else {
|
|
@@ -91,9 +90,13 @@ class SgdsAccordionItem extends SgdsElement {
|
|
|
91
90
|
}
|
|
92
91
|
await stopAnimations(this.body);
|
|
93
92
|
const { keyframes, options } = getAnimation(this, "accordion.hide");
|
|
93
|
+
const animationDuration = options.duration;
|
|
94
|
+
// Workaround to fix GSIB delay after animateTo.
|
|
95
|
+
//Setting a timeout of duration slightly less than animation's duraton to prevent case where animation runs faster than .hidden class is added
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
this.body.classList.add("hidden");
|
|
98
|
+
}, animationDuration - 20);
|
|
94
99
|
await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
|
|
95
|
-
this.body.hidden = true;
|
|
96
|
-
this.body.style.height = "auto";
|
|
97
100
|
this.emit("sgds-after-hide");
|
|
98
101
|
}
|
|
99
102
|
}
|
|
@@ -119,7 +122,8 @@ class SgdsAccordionItem extends SgdsElement {
|
|
|
119
122
|
part="base"
|
|
120
123
|
class=${classMap({
|
|
121
124
|
"sgds accordion-item": true,
|
|
122
|
-
[`${this.accordionItemClasses}`]: this.accordionItemClasses
|
|
125
|
+
[`${this.accordionItemClasses}`]: this.accordionItemClasses,
|
|
126
|
+
show: this.open
|
|
123
127
|
})}
|
|
124
128
|
>
|
|
125
129
|
<button
|
|
@@ -136,8 +140,25 @@ class SgdsAccordionItem extends SgdsElement {
|
|
|
136
140
|
@keydown=${this.handleSummaryKeyDown}
|
|
137
141
|
>
|
|
138
142
|
<slot name="accordion-header"></slot>
|
|
143
|
+
<svg
|
|
144
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
145
|
+
width="16"
|
|
146
|
+
height="16"
|
|
147
|
+
fill="currentColor"
|
|
148
|
+
class="bi bi-chevron-down"
|
|
149
|
+
viewBox="0 0 16 16"
|
|
150
|
+
>
|
|
151
|
+
<path
|
|
152
|
+
fill-rule="evenodd"
|
|
153
|
+
d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"
|
|
154
|
+
/>
|
|
155
|
+
</svg>
|
|
139
156
|
</button>
|
|
140
|
-
<div
|
|
157
|
+
<div
|
|
158
|
+
class=${classMap({
|
|
159
|
+
"accordion-body": true
|
|
160
|
+
})}
|
|
161
|
+
>
|
|
141
162
|
<slot name="accordion-content" class="accordion-content" role="region" aria-labelledby="header"></slot>
|
|
142
163
|
</div>
|
|
143
164
|
</div>
|
|
@@ -168,14 +189,14 @@ setDefaultAnimation("accordion.show", {
|
|
|
168
189
|
{ height: "0", opacity: "0" },
|
|
169
190
|
{ height: "auto", opacity: "1" }
|
|
170
191
|
],
|
|
171
|
-
options: { duration:
|
|
192
|
+
options: { duration: 350, easing: "ease-in-out" }
|
|
172
193
|
});
|
|
173
194
|
setDefaultAnimation("accordion.hide", {
|
|
174
195
|
keyframes: [
|
|
175
196
|
{ height: "auto", opacity: "1" },
|
|
176
197
|
{ height: "0", opacity: "0" }
|
|
177
198
|
],
|
|
178
|
-
options: { duration:
|
|
199
|
+
options: { duration: 350, easing: "ease-in-out" }
|
|
179
200
|
});
|
|
180
201
|
|
|
181
202
|
export { SgdsAccordionItem, SgdsAccordionItem as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sgds-accordion-item.js","sources":["../../../src/components/Accordion/sgds-accordion-item.ts"],"sourcesContent":["import { html } from \"lit\";\nimport { property, query } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport { animateTo, shimKeyframesHeightAuto, stopAnimations } from \"../../utils/animate\";\nimport { getAnimation, setDefaultAnimation } from \"../../utils/animation-registry\";\nimport { waitForEvent } from \"../../utils/event\";\nimport { watch } from \"../../utils/watch\";\nimport styles from \"./sgds-accordion-item.scss\";\n\n/**\n *\n * @event sgds-show - Emitted on show.\n * @event sgds-after-show - Emitted on show after animation has completed.\n * @event sgds-hide - Emitted on hide.\n * @event sgds-after-hide - Emitted on hide after animation has completed.\n *\n * @csspart base - The accordion-item base wrapper.\n * @csspart header - The accordion-item button header.\n * @csspart content - The accordion-item content.\n *\n * @slot accordion-header - The accordion-item button header slot.\n * @slot accordion-content - The accordion-item content slot.\n *\n * @cssprop --accordion-item-padding-y - The top and bottom padding for the container of accordion item's content\n * @cssprop --accordion-item-padding-x - The right and left padding for the container of accordion item's content\n * @cssprop --accordion-item-border-radius - The border radius of the accordion item\n * @cssprop --accordion-item-font-weight - The font weight of accordion-button when it is not collapsed\n * @cssprop --accordion-item-line-height - The line height of accordion\n */\nexport class SgdsAccordionItem extends SgdsElement {\n static styles = [SgdsElement.styles, styles];\n /** @internal */\n @query(\".accordion-item\") accordion: HTMLElement;\n /** @internal */\n @query(\".accordion-button\") header: HTMLElement;\n /** @internal */\n @query(\".accordion-body\") body: HTMLElement;\n\n /** Controls whether accordion-item is open or close */\n @property({ type: Boolean, reflect: true }) open = false;\n\n /** Optional for accordion item. Can be used to insert any utility classes such as `me-auto` */\n @property({ reflect: true }) accordionItemClasses: string;\n\n firstUpdated() {\n this.body.hidden = !this.open;\n this.body.style.height = this.open ? \"auto\" : \"0\";\n }\n\n private handleSummaryClick() {\n if (this.open) {\n this.hide();\n } else {\n this.show();\n }\n\n this.header.focus();\n }\n\n private handleSummaryKeyDown(event: KeyboardEvent) {\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n\n if (this.open) {\n this.hide();\n } else {\n this.show();\n }\n }\n\n if (event.key === \"ArrowUp\" || event.key === \"ArrowLeft\") {\n event.preventDefault();\n this.hide();\n }\n\n if (event.key === \"ArrowDown\" || event.key === \"ArrowRight\") {\n event.preventDefault();\n this.show();\n }\n }\n\n @watch(\"open\", { waitUntilFirstUpdate: true })\n async handleOpenChange() {\n if (this.open) {\n // Show\n const sgdsShow = this.emit(\"sgds-show\", { cancelable: true });\n if (sgdsShow.defaultPrevented) {\n this.open = false;\n return;\n }\n\n await stopAnimations(this.body);\n this.body.hidden = false;\n\n const { keyframes, options } = getAnimation(this, \"accordion.show\");\n await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);\n this.body.style.height = \"auto\";\n\n this.emit(\"sgds-after-show\");\n } else {\n // Hide\n const slHide = this.emit(\"sgds-hide\", { cancelable: true });\n if (slHide.defaultPrevented) {\n this.open = true;\n return;\n }\n\n await stopAnimations(this.body);\n\n const { keyframes, options } = getAnimation(this, \"accordion.hide\");\n await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);\n this.body.hidden = true;\n this.body.style.height = \"auto\";\n\n this.emit(\"sgds-after-hide\");\n }\n }\n\n /** Shows the accordion. */\n public async show() {\n if (this.open) {\n return;\n }\n\n this.open = true;\n return waitForEvent(this, \"sgds-after-show\");\n }\n\n /** Hide the accordion */\n public async hide() {\n if (!this.open) {\n return;\n }\n this.open = false;\n return waitForEvent(this, \"sgds-after-hide\");\n }\n\n render() {\n return html`\n <div\n part=\"base\"\n class=${classMap({\n \"sgds accordion-item\": true,\n [`${this.accordionItemClasses}`]: this.accordionItemClasses\n })}\n >\n <button\n class=${classMap({\n \"accordion-button\": true,\n collapsed: !this.open\n })}\n part=\"header\"\n role=\"button\"\n aria-expanded=${this.open ? \"true\" : \"false\"}\n aria-controls=\"content\"\n tabindex=\"0\"\n @click=${this.handleSummaryClick}\n @keydown=${this.handleSummaryKeyDown}\n >\n <slot name=\"accordion-header\"></slot>\n </button>\n <div class=\"accordion-body\">\n <slot name=\"accordion-content\" class=\"accordion-content\" role=\"region\" aria-labelledby=\"header\"></slot>\n </div>\n </div>\n `;\n }\n}\n\nsetDefaultAnimation(\"accordion.show\", {\n keyframes: [\n { height: \"0\", opacity: \"0\" },\n { height: \"auto\", opacity: \"1\" }\n ],\n options: { duration: 200, easing: \"ease-in-out\" }\n});\n\nsetDefaultAnimation(\"accordion.hide\", {\n keyframes: [\n { height: \"auto\", opacity: \"1\" },\n { height: \"0\", opacity: \"0\" }\n ],\n options: { duration: 200, easing: \"ease-in-out\" }\n});\n\nexport default SgdsAccordionItem;\n"],"names":["styles"],"mappings":";;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;AAmBG;AACG,MAAO,iBAAkB,SAAQ,WAAW,CAAA;AAAlD,IAAA,WAAA,GAAA;;;QAU8C,IAAI,CAAA,IAAA,GAAG,KAAK,CAAC;KAgI1D;IA3HC,YAAY,GAAA;QACV,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;AAC9B,QAAA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,GAAG,MAAM,GAAG,GAAG,CAAC;KACnD;IAEO,kBAAkB,GAAA;AACxB,QAAA,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,CAAC,IAAI,EAAE,CAAC;SACb;aAAM;YACL,IAAI,CAAC,IAAI,EAAE,CAAC;SACb;AAED,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KACrB;AAEO,IAAA,oBAAoB,CAAC,KAAoB,EAAA;AAC/C,QAAA,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG,EAAE;YAC9C,KAAK,CAAC,cAAc,EAAE,CAAC;AAEvB,YAAA,IAAI,IAAI,CAAC,IAAI,EAAE;gBACb,IAAI,CAAC,IAAI,EAAE,CAAC;aACb;iBAAM;gBACL,IAAI,CAAC,IAAI,EAAE,CAAC;aACb;SACF;AAED,QAAA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;AAmC7C,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA,CAAA;AAqDH,mBAAmB,CAAC,gBAAgB,EAAE;AACpC,IAAA,SAAS,EAAE;AACT,QAAA,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;AAC7B,QAAA,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE;AACjC,KAAA;IACD,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE;AAClD,CAAA,CAAC,CAAC;AAEH,mBAAmB,CAAC,gBAAgB,EAAE;AACpC,IAAA,SAAS,EAAE;AACT,QAAA,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE;AAChC,QAAA,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;AAC9B,KAAA;IACD,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE;AAClD,CAAA,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"sgds-accordion-item.js","sources":["../../../src/components/Accordion/sgds-accordion-item.ts"],"sourcesContent":["import { html } from \"lit\";\nimport { property, query } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport { animateTo, shimKeyframesHeightAuto, stopAnimations } from \"../../utils/animate\";\nimport { getAnimation, setDefaultAnimation } from \"../../utils/animation-registry\";\nimport { waitForEvent } from \"../../utils/event\";\nimport { watch } from \"../../utils/watch\";\nimport styles from \"./sgds-accordion-item.scss\";\n\n/**\n *\n * @event sgds-show - Emitted on show.\n * @event sgds-after-show - Emitted on show after animation has completed.\n * @event sgds-hide - Emitted on hide.\n * @event sgds-after-hide - Emitted on hide after animation has completed.\n *\n * @csspart base - The accordion-item base wrapper.\n * @csspart header - The accordion-item button header.\n * @csspart content - The accordion-item content.\n *\n * @slot accordion-header - The accordion-item button header slot.\n * @slot accordion-content - The accordion-item content slot.\n *\n * @cssprop --accordion-item-padding-y - The top and bottom padding for the container of accordion item's content\n * @cssprop --accordion-item-padding-x - The right and left padding for the container of accordion item's content\n * @cssprop --accordion-item-border-radius - The border radius of the accordion item\n * @cssprop --accordion-item-font-weight - The font weight of accordion-button when it is not collapsed\n * @cssprop --accordion-item-line-height - The line height of accordion\n */\nexport class SgdsAccordionItem extends SgdsElement {\n static styles = [SgdsElement.styles, styles];\n /** @internal */\n @query(\".accordion-item\") accordion: HTMLElement;\n /** @internal */\n @query(\".accordion-button\") header: HTMLElement;\n /** @internal */\n @query(\".accordion-body\") body: HTMLElement;\n\n /** Controls whether accordion-item is open or close */\n @property({ type: Boolean, reflect: true }) open = false;\n\n /** Optional for accordion item. Can be used to insert any utility classes such as `me-auto` */\n @property({ reflect: true }) accordionItemClasses: string;\n\n firstUpdated() {\n if (!this.open) this.body.classList.add(\"hidden\");\n }\n\n private handleSummaryClick() {\n if (this.open) {\n this.hide();\n } else {\n this.show();\n }\n\n this.header.focus();\n }\n\n private handleSummaryKeyDown(event: KeyboardEvent) {\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n\n if (this.open) {\n this.hide();\n } else {\n this.show();\n }\n }\n\n if (event.key === \"ArrowUp\" || event.key === \"ArrowLeft\") {\n event.preventDefault();\n this.hide();\n }\n\n if (event.key === \"ArrowDown\" || event.key === \"ArrowRight\") {\n event.preventDefault();\n this.show();\n }\n }\n\n @watch(\"open\", { waitUntilFirstUpdate: true })\n async handleOpenChange() {\n if (this.open) {\n // Show\n const sgdsShow = this.emit(\"sgds-show\", { cancelable: true });\n if (sgdsShow.defaultPrevented) {\n this.open = false;\n return;\n }\n\n await stopAnimations(this.body);\n this.body.classList.remove(\"hidden\");\n\n const { keyframes, options } = getAnimation(this, \"accordion.show\");\n await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);\n this.emit(\"sgds-after-show\");\n } else {\n // Hide\n const slHide = this.emit(\"sgds-hide\", { cancelable: true });\n if (slHide.defaultPrevented) {\n this.open = true;\n return;\n }\n\n await stopAnimations(this.body);\n\n const { keyframes, options } = getAnimation(this, \"accordion.hide\");\n const animationDuration = options.duration as number;\n // Workaround to fix GSIB delay after animateTo.\n //Setting a timeout of duration slightly less than animation's duraton to prevent case where animation runs faster than .hidden class is added\n setTimeout(() => {\n this.body.classList.add(\"hidden\");\n }, animationDuration - 20);\n\n await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);\n this.emit(\"sgds-after-hide\");\n }\n }\n\n /** Shows the accordion. */\n public async show() {\n if (this.open) {\n return;\n }\n\n this.open = true;\n return waitForEvent(this, \"sgds-after-show\");\n }\n\n /** Hide the accordion */\n public async hide() {\n if (!this.open) {\n return;\n }\n this.open = false;\n return waitForEvent(this, \"sgds-after-hide\");\n }\n\n render() {\n return html`\n <div\n part=\"base\"\n class=${classMap({\n \"sgds accordion-item\": true,\n [`${this.accordionItemClasses}`]: this.accordionItemClasses,\n show: this.open\n })}\n >\n <button\n class=${classMap({\n \"accordion-button\": true,\n collapsed: !this.open\n })}\n part=\"header\"\n role=\"button\"\n aria-expanded=${this.open ? \"true\" : \"false\"}\n aria-controls=\"content\"\n tabindex=\"0\"\n @click=${this.handleSummaryClick}\n @keydown=${this.handleSummaryKeyDown}\n >\n <slot name=\"accordion-header\"></slot>\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n fill=\"currentColor\"\n class=\"bi bi-chevron-down\"\n viewBox=\"0 0 16 16\"\n >\n <path\n fill-rule=\"evenodd\"\n d=\"M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z\"\n />\n </svg>\n </button>\n <div\n class=${classMap({\n \"accordion-body\": true\n })}\n >\n <slot name=\"accordion-content\" class=\"accordion-content\" role=\"region\" aria-labelledby=\"header\"></slot>\n </div>\n </div>\n `;\n }\n}\n\nsetDefaultAnimation(\"accordion.show\", {\n keyframes: [\n { height: \"0\", opacity: \"0\" },\n { height: \"auto\", opacity: \"1\" }\n ],\n options: { duration: 350, easing: \"ease-in-out\" }\n});\n\nsetDefaultAnimation(\"accordion.hide\", {\n keyframes: [\n { height: \"auto\", opacity: \"1\" },\n { height: \"0\", opacity: \"0\" }\n ],\n options: { duration: 350, easing: \"ease-in-out\" }\n});\n\nexport default SgdsAccordionItem;\n"],"names":["styles"],"mappings":";;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;AAmBG;AACG,MAAO,iBAAkB,SAAQ,WAAW,CAAA;AAAlD,IAAA,WAAA,GAAA;;;QAU8C,IAAI,CAAA,IAAA,GAAG,KAAK,CAAC;KAmJ1D;IA9IC,YAAY,GAAA;QACV,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;KACnD;IAEO,kBAAkB,GAAA;AACxB,QAAA,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,CAAC,IAAI,EAAE,CAAC;SACb;aAAM;YACL,IAAI,CAAC,IAAI,EAAE,CAAC;SACb;AAED,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KACrB;AAEO,IAAA,oBAAoB,CAAC,KAAoB,EAAA;AAC/C,QAAA,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG,EAAE;YAC9C,KAAK,CAAC,cAAc,EAAE,CAAC;AAEvB,YAAA,IAAI,IAAI,CAAC,IAAI,EAAE;gBACb,IAAI,CAAC,IAAI,EAAE,CAAC;aACb;iBAAM;gBACL,IAAI,CAAC,IAAI,EAAE,CAAC;aACb;SACF;AAED,QAAA,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,IAAI,KA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,EAAA,KAAA,CAAA,CAAA,CAAA;AAuCpD,UAAA,CAAA;IADL,KAAK,CAAC,MAAM,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;AAqC7C,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA,CAAA;AAuEH,mBAAmB,CAAC,gBAAgB,EAAE;AACpC,IAAA,SAAS,EAAE;AACT,QAAA,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;AAC7B,QAAA,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE;AACjC,KAAA;IACD,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE;AAClD,CAAA,CAAC,CAAC;AAEH,mBAAmB,CAAC,gBAAgB,EAAE;AACpC,IAAA,SAAS,EAAE;AACT,QAAA,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE;AAChC,QAAA,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;AAC9B,KAAA;IACD,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE;AAClD,CAAA,CAAC;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { css } from 'lit';
|
|
2
2
|
|
|
3
|
-
var css_248z = css`:host{--accordion-item-padding-y:1rem;--accordion-item-padding-x:1.5rem;--accordion-item-border-radius:0.25rem;--accordion-item-font-weight:700;--accordion-item-line-height:2rem}.accordion-body{line-height:var(--accordion-item-line-height);overflow:hidden;padding:0}.accordion-content{display:block;padding:0 var(--accordion-item-padding-x) var(--accordion-item-padding-y)}.accordion-button{line-height:var(--accordion-item-line-height)}.accordion-button:not(.collapsed){
|
|
3
|
+
var css_248z = css`:host{--accordion-item-padding-y:1rem;--accordion-item-padding-x:1.5rem;--accordion-item-border-radius:0.25rem;--accordion-item-font-weight:700;--accordion-item-line-height:2rem}.accordion-body{line-height:var(--accordion-item-line-height);overflow:hidden;padding:0}.accordion-content{display:block;padding:0 var(--accordion-item-padding-x) var(--accordion-item-padding-y)}.accordion-button{line-height:var(--accordion-item-line-height)}.accordion-button:not(.collapsed){color:var(--accordion-active-color)}.accordion-button svg.bi-chevron-down{height:1.3rem;margin-left:auto;transition:transform .2s ease-in-out;width:1.3rem}.accordion-button:not(.collapsed){box-shadow:none;font-weight:var(--accordion-item-font-weight)}.accordion-button:not(.collapsed) svg.bi-chevron-down{transform:rotate(-180deg)}.accordion-button:after{content:unset}:host([first-of-type]) .accordion-item{border-radius:var(--accordion-item-border-radius) var(--accordion-item-border-radius) 0 0}:host([nth-of-type]) .accordion-item{border-radius:0;border-top:0}:host([last-of-type]) .accordion-item{border-radius:0 0 var(--accordion-item-border-radius) var(--accordion-item-border-radius);border-top:0}.hidden{display:none}`;
|
|
4
4
|
|
|
5
5
|
export { css_248z as default };
|
|
6
6
|
//# sourceMappingURL=sgds-accordion-item2.js.map
|
|
@@ -9,6 +9,7 @@ var classMap_js = require('lit/directives/class-map.js');
|
|
|
9
9
|
var sgdsElement = require('../../base/sgds-element.cjs.js');
|
|
10
10
|
var sgdsAccordion = require('./sgds-accordion.cjs2.js');
|
|
11
11
|
|
|
12
|
+
const VALID_KEYS = ["Enter", "ArrowUp", "ArrowLeft", "ArrowDown", "ArrowRight"];
|
|
12
13
|
/**
|
|
13
14
|
* @summary A dropdown mechanism that allow users to either show or hide related content. `SgdsAccordion` is a wrapper to manage the behaviour for multiple `SgdsAccordionItems`
|
|
14
15
|
* @slot default - slot for accordion-item
|
|
@@ -43,10 +44,8 @@ class SgdsAccordion extends sgdsElement["default"] {
|
|
|
43
44
|
}
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
|
-
async
|
|
47
|
-
|
|
48
|
-
// prevented from the outside if a user so desires.
|
|
49
|
-
if (this.allowMultiple || event.defaultPrevented) {
|
|
47
|
+
async _onToggle(event) {
|
|
48
|
+
if (this.allowMultiple) {
|
|
50
49
|
// No toggling when `allowMultiple` or the user prevents it.
|
|
51
50
|
return;
|
|
52
51
|
}
|
|
@@ -63,6 +62,11 @@ class SgdsAccordion extends sgdsElement["default"] {
|
|
|
63
62
|
}
|
|
64
63
|
});
|
|
65
64
|
}
|
|
65
|
+
async _onKeyboardToggle(event) {
|
|
66
|
+
if (!VALID_KEYS.includes(event.key))
|
|
67
|
+
return;
|
|
68
|
+
return this._onToggle(event);
|
|
69
|
+
}
|
|
66
70
|
render() {
|
|
67
71
|
return lit.html `
|
|
68
72
|
<div
|
|
@@ -71,7 +75,7 @@ class SgdsAccordion extends sgdsElement["default"] {
|
|
|
71
75
|
[`${this.accordionClasses}`]: this.accordionClasses
|
|
72
76
|
})}
|
|
73
77
|
>
|
|
74
|
-
<slot @click=${this.
|
|
78
|
+
<slot @click=${this._onToggle} @keydown=${this._onKeyboardToggle}></slot>
|
|
75
79
|
</div>
|
|
76
80
|
`;
|
|
77
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sgds-accordion.cjs.js","sources":["../../../src/components/Accordion/sgds-accordion.ts"],"sourcesContent":["import { html } from \"lit\";\nimport { property, queryAssignedNodes } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport type SgdsAccordionItem from \"./sgds-accordion-item\";\nimport styles from \"./sgds-accordion.scss\";\n\n/**\n * @summary A dropdown mechanism that allow users to either show or hide related content. `SgdsAccordion` is a wrapper to manage the behaviour for multiple `SgdsAccordionItems`\n * @slot default - slot for accordion-item\n *\n * @cssprop --accordion-active-color - The text color of all accordion buttons to indicate its active state\n *\n */\n\nexport class SgdsAccordion extends SgdsElement {\n static styles = [SgdsElement.styles, styles];\n\n /** Allows multiple accordion items to be opened at the same time */\n @property({ type: Boolean, reflect: true }) allowMultiple = false;\n\n /** Optional for accordion wrapper. Can be used to insert any utility classes such as me-auto */\n @property({ reflect: true }) accordionClasses: string;\n\n /** @internal */\n @queryAssignedNodes()\n private defaultNodes!: NodeListOf<SgdsAccordionItem>;\n\n /** @internal */\n get items(): SgdsAccordionItem[] {\n return [...(this.defaultNodes || [])].filter(\n (node: HTMLElement) => typeof node.tagName !== \"undefined\"\n ) as SgdsAccordionItem[];\n }\n\n firstUpdated() {\n const items = [...this.items] as SgdsAccordionItem[];\n items.forEach((item, index) => {\n if (items.length > 1) {\n switch (index) {\n case 0:\n item.setAttribute(\"first-of-type\", \"\");\n break;\n\n case items.length - 1:\n item.setAttribute(\"last-of-type\", \"\");\n break;\n\n default:\n item.setAttribute(\"nth-of-type\", \"\");\n }\n }\n });\n }\n\n async
|
|
1
|
+
{"version":3,"file":"sgds-accordion.cjs.js","sources":["../../../src/components/Accordion/sgds-accordion.ts"],"sourcesContent":["import { html } from \"lit\";\nimport { property, queryAssignedNodes } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport type SgdsAccordionItem from \"./sgds-accordion-item\";\nimport styles from \"./sgds-accordion.scss\";\n\nconst VALID_KEYS = [\"Enter\", \"ArrowUp\", \"ArrowLeft\", \"ArrowDown\", \"ArrowRight\"];\n\n/**\n * @summary A dropdown mechanism that allow users to either show or hide related content. `SgdsAccordion` is a wrapper to manage the behaviour for multiple `SgdsAccordionItems`\n * @slot default - slot for accordion-item\n *\n * @cssprop --accordion-active-color - The text color of all accordion buttons to indicate its active state\n *\n */\n\nexport class SgdsAccordion extends SgdsElement {\n static styles = [SgdsElement.styles, styles];\n\n /** Allows multiple accordion items to be opened at the same time */\n @property({ type: Boolean, reflect: true }) allowMultiple = false;\n\n /** Optional for accordion wrapper. Can be used to insert any utility classes such as me-auto */\n @property({ reflect: true }) accordionClasses: string;\n\n /** @internal */\n @queryAssignedNodes()\n private defaultNodes!: NodeListOf<SgdsAccordionItem>;\n\n /** @internal */\n get items(): SgdsAccordionItem[] {\n return [...(this.defaultNodes || [])].filter(\n (node: HTMLElement) => typeof node.tagName !== \"undefined\"\n ) as SgdsAccordionItem[];\n }\n\n firstUpdated() {\n const items = [...this.items] as SgdsAccordionItem[];\n items.forEach((item, index) => {\n if (items.length > 1) {\n switch (index) {\n case 0:\n item.setAttribute(\"first-of-type\", \"\");\n break;\n\n case items.length - 1:\n item.setAttribute(\"last-of-type\", \"\");\n break;\n\n default:\n item.setAttribute(\"nth-of-type\", \"\");\n }\n }\n });\n }\n\n private async _onToggle(event: Event) {\n if (this.allowMultiple) {\n // No toggling when `allowMultiple` or the user prevents it.\n return;\n }\n const items = [...this.items] as SgdsAccordionItem[];\n if (items && !items.length) {\n // no toggling when there aren't items.\n return;\n }\n items.forEach(item => {\n // Covers all elements within accordion-item\n if (!event.composedPath().includes(item)) {\n // Close all the items that didn't dispatch the event.\n item.open = false;\n }\n });\n }\n\n private async _onKeyboardToggle(event: KeyboardEvent) {\n if (!VALID_KEYS.includes(event.key)) return;\n return this._onToggle(event);\n }\n\n render() {\n return html`\n <div\n class=${classMap({\n \"sgds accordion\": true,\n [`${this.accordionClasses}`]: this.accordionClasses\n })}\n >\n <slot @click=${this._onToggle} @keydown=${this._onKeyboardToggle}></slot>\n </div>\n `;\n }\n}\n\nexport default SgdsAccordion;\n"],"names":["SgdsElement","html","classMap","styles","__decorate","property","queryAssignedNodes"],"mappings":";;;;;;;;;;;AAOA,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;AAEhF;;;;;;AAMG;AAEG,MAAO,aAAc,SAAQA,sBAAW,CAAA;AAA9C,IAAA,WAAA,GAAA;;;QAI8C,IAAa,CAAA,aAAA,GAAG,KAAK,CAAC;KAwEnE;;AA9DC,IAAA,IAAI,KAAK,GAAA;QACP,OAAO,CAAC,IAAI,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAC1C,CAAC,IAAiB,KAAK,OAAO,IAAI,C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,KAAK,CAAC,CAAC;KAC9B;IAED,MAAM,GAAA;AACJ,QAAA,OAAOC,QAAI,CAAA,CAAA;;AAEC,cAAA,EAAAC,oBAAQ,CAAC;AACf,YAAA,gBAAgB,EAAE,IAAI;YACtB,CAAC,CAAA,EAAG,IAAI,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,gBAAgB;SACpD,CAAC,CAAA;;AAEa,qBAAA,EAAA,IAAI,CAAC,SAAS,CAAa,UAAA,EAAA,IAAI,CAAC,iBAAiB,CAAA;;KAEnE,CAAC;KACH;;AA1EM,aAAM,CAAA,MAAA,GAAG,CAACF,sBAAW,CAAC,MAAM,EAAEG,wBAAM,CAA9B,CAAgC;AAGDC,gBAAA,CAAA;IAA3CC,sBAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAAuB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,eAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAGrCD,gBAAA,CAAA;AAA5B,IAAAC,sBAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAA0B,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAI9CD,gBAAA,CAAA;AADP,IAAAE,gCAAkB,EAAE;AACgC,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,cAAA,EAAA,KAAA,CAAA,CAAA;;;;;"}
|
|
@@ -18,7 +18,8 @@ export declare class SgdsAccordion extends SgdsElement {
|
|
|
18
18
|
/** @internal */
|
|
19
19
|
get items(): SgdsAccordionItem[];
|
|
20
20
|
firstUpdated(): void;
|
|
21
|
-
|
|
21
|
+
private _onToggle;
|
|
22
|
+
private _onKeyboardToggle;
|
|
22
23
|
render(): import("lit-html").TemplateResult<1>;
|
|
23
24
|
}
|
|
24
25
|
export default SgdsAccordion;
|
|
@@ -5,6 +5,7 @@ import { classMap } from 'lit/directives/class-map.js';
|
|
|
5
5
|
import SgdsElement from '../../base/sgds-element.js';
|
|
6
6
|
import css_248z from './sgds-accordion2.js';
|
|
7
7
|
|
|
8
|
+
const VALID_KEYS = ["Enter", "ArrowUp", "ArrowLeft", "ArrowDown", "ArrowRight"];
|
|
8
9
|
/**
|
|
9
10
|
* @summary A dropdown mechanism that allow users to either show or hide related content. `SgdsAccordion` is a wrapper to manage the behaviour for multiple `SgdsAccordionItems`
|
|
10
11
|
* @slot default - slot for accordion-item
|
|
@@ -39,10 +40,8 @@ class SgdsAccordion extends SgdsElement {
|
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
|
-
async
|
|
43
|
-
|
|
44
|
-
// prevented from the outside if a user so desires.
|
|
45
|
-
if (this.allowMultiple || event.defaultPrevented) {
|
|
43
|
+
async _onToggle(event) {
|
|
44
|
+
if (this.allowMultiple) {
|
|
46
45
|
// No toggling when `allowMultiple` or the user prevents it.
|
|
47
46
|
return;
|
|
48
47
|
}
|
|
@@ -59,6 +58,11 @@ class SgdsAccordion extends SgdsElement {
|
|
|
59
58
|
}
|
|
60
59
|
});
|
|
61
60
|
}
|
|
61
|
+
async _onKeyboardToggle(event) {
|
|
62
|
+
if (!VALID_KEYS.includes(event.key))
|
|
63
|
+
return;
|
|
64
|
+
return this._onToggle(event);
|
|
65
|
+
}
|
|
62
66
|
render() {
|
|
63
67
|
return html `
|
|
64
68
|
<div
|
|
@@ -67,7 +71,7 @@ class SgdsAccordion extends SgdsElement {
|
|
|
67
71
|
[`${this.accordionClasses}`]: this.accordionClasses
|
|
68
72
|
})}
|
|
69
73
|
>
|
|
70
|
-
<slot @click=${this.
|
|
74
|
+
<slot @click=${this._onToggle} @keydown=${this._onKeyboardToggle}></slot>
|
|
71
75
|
</div>
|
|
72
76
|
`;
|
|
73
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sgds-accordion.js","sources":["../../../src/components/Accordion/sgds-accordion.ts"],"sourcesContent":["import { html } from \"lit\";\nimport { property, queryAssignedNodes } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport type SgdsAccordionItem from \"./sgds-accordion-item\";\nimport styles from \"./sgds-accordion.scss\";\n\n/**\n * @summary A dropdown mechanism that allow users to either show or hide related content. `SgdsAccordion` is a wrapper to manage the behaviour for multiple `SgdsAccordionItems`\n * @slot default - slot for accordion-item\n *\n * @cssprop --accordion-active-color - The text color of all accordion buttons to indicate its active state\n *\n */\n\nexport class SgdsAccordion extends SgdsElement {\n static styles = [SgdsElement.styles, styles];\n\n /** Allows multiple accordion items to be opened at the same time */\n @property({ type: Boolean, reflect: true }) allowMultiple = false;\n\n /** Optional for accordion wrapper. Can be used to insert any utility classes such as me-auto */\n @property({ reflect: true }) accordionClasses: string;\n\n /** @internal */\n @queryAssignedNodes()\n private defaultNodes!: NodeListOf<SgdsAccordionItem>;\n\n /** @internal */\n get items(): SgdsAccordionItem[] {\n return [...(this.defaultNodes || [])].filter(\n (node: HTMLElement) => typeof node.tagName !== \"undefined\"\n ) as SgdsAccordionItem[];\n }\n\n firstUpdated() {\n const items = [...this.items] as SgdsAccordionItem[];\n items.forEach((item, index) => {\n if (items.length > 1) {\n switch (index) {\n case 0:\n item.setAttribute(\"first-of-type\", \"\");\n break;\n\n case items.length - 1:\n item.setAttribute(\"last-of-type\", \"\");\n break;\n\n default:\n item.setAttribute(\"nth-of-type\", \"\");\n }\n }\n });\n }\n\n async
|
|
1
|
+
{"version":3,"file":"sgds-accordion.js","sources":["../../../src/components/Accordion/sgds-accordion.ts"],"sourcesContent":["import { html } from \"lit\";\nimport { property, queryAssignedNodes } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport type SgdsAccordionItem from \"./sgds-accordion-item\";\nimport styles from \"./sgds-accordion.scss\";\n\nconst VALID_KEYS = [\"Enter\", \"ArrowUp\", \"ArrowLeft\", \"ArrowDown\", \"ArrowRight\"];\n\n/**\n * @summary A dropdown mechanism that allow users to either show or hide related content. `SgdsAccordion` is a wrapper to manage the behaviour for multiple `SgdsAccordionItems`\n * @slot default - slot for accordion-item\n *\n * @cssprop --accordion-active-color - The text color of all accordion buttons to indicate its active state\n *\n */\n\nexport class SgdsAccordion extends SgdsElement {\n static styles = [SgdsElement.styles, styles];\n\n /** Allows multiple accordion items to be opened at the same time */\n @property({ type: Boolean, reflect: true }) allowMultiple = false;\n\n /** Optional for accordion wrapper. Can be used to insert any utility classes such as me-auto */\n @property({ reflect: true }) accordionClasses: string;\n\n /** @internal */\n @queryAssignedNodes()\n private defaultNodes!: NodeListOf<SgdsAccordionItem>;\n\n /** @internal */\n get items(): SgdsAccordionItem[] {\n return [...(this.defaultNodes || [])].filter(\n (node: HTMLElement) => typeof node.tagName !== \"undefined\"\n ) as SgdsAccordionItem[];\n }\n\n firstUpdated() {\n const items = [...this.items] as SgdsAccordionItem[];\n items.forEach((item, index) => {\n if (items.length > 1) {\n switch (index) {\n case 0:\n item.setAttribute(\"first-of-type\", \"\");\n break;\n\n case items.length - 1:\n item.setAttribute(\"last-of-type\", \"\");\n break;\n\n default:\n item.setAttribute(\"nth-of-type\", \"\");\n }\n }\n });\n }\n\n private async _onToggle(event: Event) {\n if (this.allowMultiple) {\n // No toggling when `allowMultiple` or the user prevents it.\n return;\n }\n const items = [...this.items] as SgdsAccordionItem[];\n if (items && !items.length) {\n // no toggling when there aren't items.\n return;\n }\n items.forEach(item => {\n // Covers all elements within accordion-item\n if (!event.composedPath().includes(item)) {\n // Close all the items that didn't dispatch the event.\n item.open = false;\n }\n });\n }\n\n private async _onKeyboardToggle(event: KeyboardEvent) {\n if (!VALID_KEYS.includes(event.key)) return;\n return this._onToggle(event);\n }\n\n render() {\n return html`\n <div\n class=${classMap({\n \"sgds accordion\": true,\n [`${this.accordionClasses}`]: this.accordionClasses\n })}\n >\n <slot @click=${this._onToggle} @keydown=${this._onKeyboardToggle}></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AA;AADP,IAAA,kBAAkB,EAAE;AACgC,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,cAAA,EAAA,KAAA,CAAA,CAAA;;;;"}
|
package/components/index.umd.js
CHANGED
|
@@ -3310,6 +3310,7 @@
|
|
|
3310
3310
|
|
|
3311
3311
|
var css_248z$E = css`:host{--accordion-active-color:var(--sgds-primary)}`;
|
|
3312
3312
|
|
|
3313
|
+
const VALID_KEYS = ["Enter", "ArrowUp", "ArrowLeft", "ArrowDown", "ArrowRight"];
|
|
3313
3314
|
/**
|
|
3314
3315
|
* @summary A dropdown mechanism that allow users to either show or hide related content. `SgdsAccordion` is a wrapper to manage the behaviour for multiple `SgdsAccordionItems`
|
|
3315
3316
|
* @slot default - slot for accordion-item
|
|
@@ -3344,10 +3345,8 @@
|
|
|
3344
3345
|
}
|
|
3345
3346
|
});
|
|
3346
3347
|
}
|
|
3347
|
-
async
|
|
3348
|
-
|
|
3349
|
-
// prevented from the outside if a user so desires.
|
|
3350
|
-
if (this.allowMultiple || event.defaultPrevented) {
|
|
3348
|
+
async _onToggle(event) {
|
|
3349
|
+
if (this.allowMultiple) {
|
|
3351
3350
|
// No toggling when `allowMultiple` or the user prevents it.
|
|
3352
3351
|
return;
|
|
3353
3352
|
}
|
|
@@ -3364,6 +3363,11 @@
|
|
|
3364
3363
|
}
|
|
3365
3364
|
});
|
|
3366
3365
|
}
|
|
3366
|
+
async _onKeyboardToggle(event) {
|
|
3367
|
+
if (!VALID_KEYS.includes(event.key))
|
|
3368
|
+
return;
|
|
3369
|
+
return this._onToggle(event);
|
|
3370
|
+
}
|
|
3367
3371
|
render() {
|
|
3368
3372
|
return html$1 `
|
|
3369
3373
|
<div
|
|
@@ -3372,7 +3376,7 @@
|
|
|
3372
3376
|
[`${this.accordionClasses}`]: this.accordionClasses
|
|
3373
3377
|
})}
|
|
3374
3378
|
>
|
|
3375
|
-
<slot @click=${this.
|
|
3379
|
+
<slot @click=${this._onToggle} @keydown=${this._onKeyboardToggle}></slot>
|
|
3376
3380
|
</div>
|
|
3377
3381
|
`;
|
|
3378
3382
|
}
|
|
@@ -3517,7 +3521,7 @@
|
|
|
3517
3521
|
};
|
|
3518
3522
|
}
|
|
3519
3523
|
|
|
3520
|
-
var css_248z$D = css`:host{--accordion-item-padding-y:1rem;--accordion-item-padding-x:1.5rem;--accordion-item-border-radius:0.25rem;--accordion-item-font-weight:700;--accordion-item-line-height:2rem}.accordion-body{line-height:var(--accordion-item-line-height);overflow:hidden;padding:0}.accordion-content{display:block;padding:0 var(--accordion-item-padding-x) var(--accordion-item-padding-y)}.accordion-button{line-height:var(--accordion-item-line-height)}.accordion-button:not(.collapsed){
|
|
3524
|
+
var css_248z$D = css`:host{--accordion-item-padding-y:1rem;--accordion-item-padding-x:1.5rem;--accordion-item-border-radius:0.25rem;--accordion-item-font-weight:700;--accordion-item-line-height:2rem}.accordion-body{line-height:var(--accordion-item-line-height);overflow:hidden;padding:0}.accordion-content{display:block;padding:0 var(--accordion-item-padding-x) var(--accordion-item-padding-y)}.accordion-button{line-height:var(--accordion-item-line-height)}.accordion-button:not(.collapsed){color:var(--accordion-active-color)}.accordion-button svg.bi-chevron-down{height:1.3rem;margin-left:auto;transition:transform .2s ease-in-out;width:1.3rem}.accordion-button:not(.collapsed){box-shadow:none;font-weight:var(--accordion-item-font-weight)}.accordion-button:not(.collapsed) svg.bi-chevron-down{transform:rotate(-180deg)}.accordion-button:after{content:unset}:host([first-of-type]) .accordion-item{border-radius:var(--accordion-item-border-radius) var(--accordion-item-border-radius) 0 0}:host([nth-of-type]) .accordion-item{border-radius:0;border-top:0}:host([last-of-type]) .accordion-item{border-radius:0 0 var(--accordion-item-border-radius) var(--accordion-item-border-radius);border-top:0}.hidden{display:none}`;
|
|
3521
3525
|
|
|
3522
3526
|
/**
|
|
3523
3527
|
*
|
|
@@ -3546,8 +3550,8 @@
|
|
|
3546
3550
|
this.open = false;
|
|
3547
3551
|
}
|
|
3548
3552
|
firstUpdated() {
|
|
3549
|
-
|
|
3550
|
-
|
|
3553
|
+
if (!this.open)
|
|
3554
|
+
this.body.classList.add("hidden");
|
|
3551
3555
|
}
|
|
3552
3556
|
handleSummaryClick() {
|
|
3553
3557
|
if (this.open) {
|
|
@@ -3586,10 +3590,9 @@
|
|
|
3586
3590
|
return;
|
|
3587
3591
|
}
|
|
3588
3592
|
await stopAnimations(this.body);
|
|
3589
|
-
this.body.hidden
|
|
3593
|
+
this.body.classList.remove("hidden");
|
|
3590
3594
|
const { keyframes, options } = getAnimation(this, "accordion.show");
|
|
3591
3595
|
await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
|
|
3592
|
-
this.body.style.height = "auto";
|
|
3593
3596
|
this.emit("sgds-after-show");
|
|
3594
3597
|
}
|
|
3595
3598
|
else {
|
|
@@ -3601,9 +3604,13 @@
|
|
|
3601
3604
|
}
|
|
3602
3605
|
await stopAnimations(this.body);
|
|
3603
3606
|
const { keyframes, options } = getAnimation(this, "accordion.hide");
|
|
3607
|
+
const animationDuration = options.duration;
|
|
3608
|
+
// Workaround to fix GSIB delay after animateTo.
|
|
3609
|
+
//Setting a timeout of duration slightly less than animation's duraton to prevent case where animation runs faster than .hidden class is added
|
|
3610
|
+
setTimeout(() => {
|
|
3611
|
+
this.body.classList.add("hidden");
|
|
3612
|
+
}, animationDuration - 20);
|
|
3604
3613
|
await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
|
|
3605
|
-
this.body.hidden = true;
|
|
3606
|
-
this.body.style.height = "auto";
|
|
3607
3614
|
this.emit("sgds-after-hide");
|
|
3608
3615
|
}
|
|
3609
3616
|
}
|
|
@@ -3629,7 +3636,8 @@
|
|
|
3629
3636
|
part="base"
|
|
3630
3637
|
class=${classMap({
|
|
3631
3638
|
"sgds accordion-item": true,
|
|
3632
|
-
[`${this.accordionItemClasses}`]: this.accordionItemClasses
|
|
3639
|
+
[`${this.accordionItemClasses}`]: this.accordionItemClasses,
|
|
3640
|
+
show: this.open
|
|
3633
3641
|
})}
|
|
3634
3642
|
>
|
|
3635
3643
|
<button
|
|
@@ -3646,8 +3654,25 @@
|
|
|
3646
3654
|
@keydown=${this.handleSummaryKeyDown}
|
|
3647
3655
|
>
|
|
3648
3656
|
<slot name="accordion-header"></slot>
|
|
3657
|
+
<svg
|
|
3658
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
3659
|
+
width="16"
|
|
3660
|
+
height="16"
|
|
3661
|
+
fill="currentColor"
|
|
3662
|
+
class="bi bi-chevron-down"
|
|
3663
|
+
viewBox="0 0 16 16"
|
|
3664
|
+
>
|
|
3665
|
+
<path
|
|
3666
|
+
fill-rule="evenodd"
|
|
3667
|
+
d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"
|
|
3668
|
+
/>
|
|
3669
|
+
</svg>
|
|
3649
3670
|
</button>
|
|
3650
|
-
<div
|
|
3671
|
+
<div
|
|
3672
|
+
class=${classMap({
|
|
3673
|
+
"accordion-body": true
|
|
3674
|
+
})}
|
|
3675
|
+
>
|
|
3651
3676
|
<slot name="accordion-content" class="accordion-content" role="region" aria-labelledby="header"></slot>
|
|
3652
3677
|
</div>
|
|
3653
3678
|
</div>
|
|
@@ -3678,14 +3703,14 @@
|
|
|
3678
3703
|
{ height: "0", opacity: "0" },
|
|
3679
3704
|
{ height: "auto", opacity: "1" }
|
|
3680
3705
|
],
|
|
3681
|
-
options: { duration:
|
|
3706
|
+
options: { duration: 350, easing: "ease-in-out" }
|
|
3682
3707
|
});
|
|
3683
3708
|
setDefaultAnimation("accordion.hide", {
|
|
3684
3709
|
keyframes: [
|
|
3685
3710
|
{ height: "auto", opacity: "1" },
|
|
3686
3711
|
{ height: "0", opacity: "0" }
|
|
3687
3712
|
],
|
|
3688
|
-
options: { duration:
|
|
3713
|
+
options: { duration: 350, easing: "ease-in-out" }
|
|
3689
3714
|
});
|
|
3690
3715
|
|
|
3691
3716
|
const appliedClassMixins = new WeakMap();
|