@m3e/expansion-panel 1.0.0-rc.1 → 1.0.0-rc.3

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.
@@ -1,9 +1,8 @@
1
1
  import { CSSResultGroup, LitElement } from "lit";
2
2
  import { ExpansionTogglePosition } from "./ExpansionTogglePosition";
3
3
  import { ExpansionToggleDirection } from "./ExpansionToggleDirection";
4
- declare const M3eExpansionPanelElement_base: import("node_modules/@m3e/core/dist/src/shared/mixins/Constructor").Constructor<import("@m3e/core").DisabledMixin> & import("node_modules/@m3e/core/dist/src/shared/mixins/Constructor").Constructor<import("@m3e/core").AttachInternalsMixin> & import("node_modules/@m3e/core/dist/src/shared/mixins/Constructor").Constructor & typeof LitElement;
4
+ declare const M3eExpansionPanelElement_base: import("node_modules/@m3e/core/dist/src/shared/mixins/Constructor").Constructor<import("@m3e/core").DisabledMixin> & import("node_modules/@m3e/core/dist/src/shared/mixins/Constructor").Constructor<import("@m3e/core").AttachInternalsMixin> & typeof LitElement;
5
5
  /**
6
- * @summary
7
6
  * An expandable details-summary view.
8
7
  *
9
8
  * @description
@@ -32,7 +31,7 @@ declare const M3eExpansionPanelElement_base: import("node_modules/@m3e/core/dist
32
31
  * @tag m3e-expansion-panel
33
32
  *
34
33
  * @slot - Renders the detail of the panel.
35
- * @slot actions- Renders the actions bar of the panel.
34
+ * @slot actions - Renders the actions bar of the panel.
36
35
  * @slot header - Renders the header content.
37
36
  * @slot toggle-icon - Renders the expansion toggle icon.
38
37
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ExpansionPanelElement.d.ts","sourceRoot":"","sources":["../../src/ExpansionPanelElement.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAQ,UAAU,EAAE,MAAM,KAAK,CAAC;AAKvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;;AAKtE;;;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wBAAwB;IACvC,gBAAgB,CAAC,CAAC,SAAS,MAAM,gCAAgC,EAC/D,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,IAAI,EAAE,wBAAwB,EAAE,EAAE,EAAE,gCAAgC,CAAC,CAAC,CAAC,KAAK,IAAI,EAC3F,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAC1C,IAAI,CAAC;IAER,gBAAgB,CACd,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,EAC5C,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAC1C,IAAI,CAAC;IAER,mBAAmB,CAAC,CAAC,SAAS,MAAM,gCAAgC,EAClE,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,IAAI,EAAE,wBAAwB,EAAE,EAAE,EAAE,gCAAgC,CAAC,CAAC,CAAC,KAAK,IAAI,EAC3F,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACvC,IAAI,CAAC;IAER,mBAAmB,CACjB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,EAC5C,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACvC,IAAI,CAAC;CACT;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,qBAAqB,EAAE,wBAAwB,CAAC;KACjD;CACF"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@m3e/expansion-panel",
3
- "version": "1.0.0-rc.1",
3
+ "version": "1.0.0-rc.3",
4
4
  "description": "Expansion Panel for M3E",
5
5
  "author": "matraic <matraic@yahoo.com>",
6
6
  "license": "MIT",
7
- "homepage": "https://matraic.github.io/m3e/",
7
+ "homepage": "https://matraic.github.io/m3e/#/components/expansion-panel.html",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/matraic/m3e.git"
@@ -28,7 +28,7 @@
28
28
  "clean": "rimraf dist"
29
29
  },
30
30
  "peerDependencies": {
31
- "@m3e/core": "1.0.0-rc.1",
31
+ "@m3e/core": "1.0.0-rc.3",
32
32
  "lit": "^3.3.0"
33
33
  },
34
34
  "devDependencies": {
package/cem.config.mjs DELETED
@@ -1,16 +0,0 @@
1
- import { customElementVsCodePlugin } from "custom-element-vs-code-integration";
2
-
3
- export default {
4
- globs: ["src/**/*.ts"],
5
- exclude: ["src/**/*.spec.ts"],
6
- packagejson: true,
7
- outdir: "dist",
8
- litelement: true,
9
- plugins: [
10
- customElementVsCodePlugin({
11
- outdir: "dist",
12
- htmlFileName: "html-custom-data.json",
13
- cssFileName: "css-custom-data.json",
14
- }),
15
- ],
16
- };
package/demo/index.html DELETED
@@ -1,60 +0,0 @@
1
- <!doctype html>
2
- <html lang="en" style="overflow-y: auto">
3
- <head>
4
- <title>Expansion Panel for M3E</title>
5
- <meta charset="utf-8" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1" />
7
- <meta name="description" content="Expansion Panel for M3E" />
8
- <base href="./" />
9
- <link rel="preconnect" href="https://fonts.googleapis.com" />
10
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
11
- <link
12
- href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap"
13
- rel="stylesheet"
14
- />
15
- <link
16
- href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0..1,0"
17
- rel="stylesheet"
18
- />
19
- <script type="importmap">
20
- {
21
- "imports": {
22
- "lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
23
- "@m3e/core": "../../core/dist/index.min.js"
24
- }
25
- }
26
- </script>
27
- <script type="module" src="../../button/dist/index.min.js"></script>
28
- <script type="module" src="../../theme/dist/index.min.js"></script>
29
- <script type="module" src="../dist/index.min.js"></script>
30
- <style>
31
- body {
32
- font-family: "Roboto";
33
- }
34
- *:not(:defined) {
35
- display: none;
36
- }
37
- </style>
38
- </head>
39
- <body>
40
- <m3e-theme strong-focus>
41
- <m3e-accordion>
42
- <m3e-expansion-panel>
43
- <span slot="header">Expansion panel 1 title</span>
44
- <div>I am content for the first expansion panel</div>
45
- </m3e-expansion-panel>
46
- <m3e-expansion-panel disabled>
47
- <span slot="header">Expansion panel 2 title</span>
48
- <div>I am content for the second expansion panel</div>
49
- </m3e-expansion-panel>
50
- <m3e-expansion-panel>
51
- <span slot="header">Expansion panel 2 title</span>
52
- <div>I am content for the third expansion panel</div>
53
- <div slot="actions">
54
- <m3e-button>Action</m3e-button>
55
- </div>
56
- </m3e-expansion-panel>
57
- </m3e-accordion>
58
- </m3e-theme>
59
- </body>
60
- </html>
package/eslint.config.mjs DELETED
@@ -1,13 +0,0 @@
1
- import eslint from "@eslint/js";
2
- import tseslint from "typescript-eslint";
3
- import { fileURLToPath } from "url";
4
- import { dirname } from "path";
5
-
6
- export default tseslint.config(eslint.configs.recommended, tseslint.configs.recommended, {
7
- languageOptions: {
8
- parserOptions: {
9
- project: true,
10
- tsconfigRootDir: dirname(fileURLToPath(import.meta.url)),
11
- },
12
- },
13
- });
package/rollup.config.js DELETED
@@ -1,32 +0,0 @@
1
- import resolve from "@rollup/plugin-node-resolve";
2
- import terser from "@rollup/plugin-terser";
3
- import typescript from "@rollup/plugin-typescript";
4
-
5
- const banner = `/**
6
- * @license MIT
7
- * Copyright (c) 2025 matraic
8
- * See LICENSE file in the project root for full license text.
9
- */`;
10
-
11
- export default [
12
- {
13
- input: "src/index.ts",
14
- output: [
15
- {
16
- file: "dist/index.js",
17
- format: "esm",
18
- sourcemap: true,
19
- banner: banner,
20
- },
21
- {
22
- file: "dist/index.min.js",
23
- format: "esm",
24
- sourcemap: true,
25
- banner: banner,
26
- plugins: [terser({ mangle: true })],
27
- },
28
- ],
29
- external: ["@m3e/core", "lit"],
30
- plugins: [resolve(), typescript()],
31
- },
32
- ];
@@ -1,115 +0,0 @@
1
- import { css, CSSResultGroup, html, LitElement } from "lit";
2
- import { customElement, property } from "lit/decorators.js";
3
-
4
- import { DesignToken, Role } from "@m3e/core";
5
-
6
- import { M3eExpansionPanelElement } from "./ExpansionPanelElement";
7
-
8
- /**
9
- * @summary
10
- * Combines multiple expansion panels in to an accordion.
11
- *
12
- * @description
13
- * The `m3e-accordion` component organizes multiple expansion panels into a coordinated, accessible group.
14
- * It supports single or multiple open panels via the `multi` attribute, and provides expressive theming
15
- * and shape control for grouped layouts. The accordion manages open/close state across its child panels,
16
- * enabling interactive disclosure patterns for complex content.
17
- *
18
- * @example
19
- * The following example illustrates the basic use of the `m3e-accordion` and `m3e-expansion-panel` components.
20
- *
21
- * ```html
22
- * <m3e-accordion>
23
- * <m3e-expansion-panel>
24
- * <span slot="header">Panel 1</span>
25
- * I am content for the first expansion panel
26
- * </m3e-expansion-panel>
27
- * <m3e-expansion-panel>
28
- * <span slot="header">Panel 2</span>
29
- * I am content for the second expansion panel
30
- * </m3e-expansion-panel>
31
- * </m3e-accordion>
32
- * ```
33
- *
34
- * @tag m3e-accordion
35
- *
36
- * @slot - Renders the panels of the accordion.
37
- *
38
- * @attr multi - Whether multiple expansion panels can be open at the same time.
39
- */
40
- @customElement("m3e-accordion")
41
- export class M3eAccordionElement extends Role(LitElement, "none") {
42
- /** The styles of the element. */
43
- static override styles: CSSResultGroup = css`
44
- :host {
45
- display: block;
46
- }
47
- ::slotted(m3e-expansion-panel) {
48
- --m3e-expansion-panel-container-color: ${DesignToken.color.surfaceContainerLow};
49
- --m3e-expansion-panel-elevation: ${DesignToken.elevation.level2};
50
- --m3e-expansion-panel-open-shape: ${DesignToken.shape.corner.medium};
51
- --_expansion-panel-open-spacing: 1rem;
52
- }
53
- ::slotted(m3e-expansion-panel:first-of-type:last-of-type) {
54
- --m3e-expansion-panel-shape: ${DesignToken.shape.corner.medium};
55
- }
56
- ::slotted(m3e-expansion-panel:first-of-type:not(:last-of-type)) {
57
- --m3e-expansion-panel-shape: ${DesignToken.shape.corner.value.medium} ${DesignToken.shape.corner.value.medium}
58
- ${DesignToken.shape.corner.value.none} ${DesignToken.shape.corner.value.none};
59
- }
60
- ::slotted(m3e-expansion-panel:last-of-type:not(:first-of-type)) {
61
- --m3e-expansion-panel-shape: ${DesignToken.shape.corner.value.none} ${DesignToken.shape.corner.value.none}
62
- ${DesignToken.shape.corner.value.medium} ${DesignToken.shape.corner.value.medium};
63
- }
64
- `;
65
-
66
- /** @private */ #panels: Array<M3eExpansionPanelElement> = [];
67
-
68
- /**
69
- * Whether multiple expansion panels can be open at the same time.
70
- * @default false
71
- */
72
- @property({ type: Boolean }) multi = false;
73
-
74
- /** The panels of the accordion. */
75
- get panels() {
76
- return this.#panels;
77
- }
78
-
79
- /** @inheritdoc */
80
- protected override render(): unknown {
81
- return html`<slot @slotchange="${this.#handleSlotChange}" @opening="${this.#handleOpening}"></slot>`;
82
- }
83
-
84
- /** @private */
85
- #handleSlotChange() {
86
- this.#panels = [...this.querySelectorAll("m3e-expansion-panel")];
87
-
88
- if (this.multi) {
89
- return;
90
- }
91
-
92
- let alreadyOpen = false;
93
- for (const panel of this.#panels.filter((x) => !x.open)) {
94
- if (alreadyOpen) {
95
- panel.open = false;
96
- }
97
- alreadyOpen = true;
98
- }
99
- }
100
-
101
- /** @private */
102
- #handleOpening(e: Event): void {
103
- if (!this.multi) {
104
- for (const panel of this.#panels.filter((x) => x !== e.target && x.open)) {
105
- panel.open = false;
106
- }
107
- }
108
- }
109
- }
110
-
111
- declare global {
112
- interface HTMLElementTagNameMap {
113
- "m3e-accordion": M3eAccordionElement;
114
- }
115
- }
@@ -1,99 +0,0 @@
1
- import { CSSResultGroup, html, LitElement, nothing, PropertyValues } from "lit";
2
- import { customElement, property, query } from "lit/decorators.js";
3
-
4
- import {
5
- AttachInternals,
6
- Disabled,
7
- Focusable,
8
- KeyboardClick,
9
- M3eFocusRingElement,
10
- M3eStateLayerElement,
11
- Role,
12
- } from "@m3e/core";
13
-
14
- import { ExpansionTogglePosition } from "./ExpansionTogglePosition";
15
- import { ExpansionToggleDirection } from "./ExpansionToggleDirection";
16
-
17
- import { ExpansionHeaderStyle } from "./styles";
18
-
19
- /**
20
- * A button used to toggle the expanded state of an expansion panel.
21
- *
22
- * @tag m3e-expansion-header
23
- *
24
- * @slot - Renders the content of the header.
25
- * @slot toggle-icon - Renders the icon of the expansion toggle.
26
- *
27
- * @attr hide-toggle - Whether to hide the expansion toggle.
28
- * @attr toggle-direction - The direction of the expansion toggle.
29
- * @attr toggle-position - The position of the expansion toggle.
30
- *
31
- * @cssprop --m3e-expansion-header-collapsed-height - Height of the header when the panel is collapsed.
32
- * @cssprop --m3e-expansion-header-expanded-height - Height of the header when the panel is expanded.
33
- * @cssprop --m3e-expansion-header-padding-left - Left padding inside the header.
34
- * @cssprop --m3e-expansion-header-padding-right - Right padding inside the header.
35
- * @cssprop --m3e-expansion-header-spacing - Spacing between header elements.
36
- * @cssprop --m3e-expansion-header-toggle-icon-size - Size of the toggle icon (e.g. chevron).
37
- * @cssprop --m3e-expansion-header-font-size - The font size of the header text.
38
- * @cssprop --m3e-expansion-header-font-weight - The font weight of the header text.
39
- * @cssprop --m3e-expansion-header-line-height - The line height of the header text.
40
- * @cssprop --m3e-expansion-header-tracking - Letter spacing (tracking) of the header text.
41
- */
42
- @customElement("m3e-expansion-header")
43
- export class M3eExpansionHeaderElement extends KeyboardClick(
44
- Focusable(Disabled(AttachInternals(Role(LitElement, "button"), true)))
45
- ) {
46
- /** The styles of the element. */
47
- static override styles: CSSResultGroup = ExpansionHeaderStyle;
48
-
49
- /** @private */ @query(".focus-ring") private readonly _focusRing?: M3eFocusRingElement;
50
- /** @private */ @query(".state-layer") private readonly _stateLayer?: M3eStateLayerElement;
51
-
52
- /**
53
- * The direction of the expansion toggle.
54
- * @default "vertical"
55
- */
56
- @property({ attribute: "toggle-direction", reflect: true }) toggleDirection: ExpansionToggleDirection = "vertical";
57
-
58
- /**
59
- * The position of the expansion toggle.
60
- * @default "after"
61
- */
62
- @property({ attribute: "toggle-position", reflect: true }) togglePosition: ExpansionTogglePosition = "after";
63
-
64
- /**
65
- * Whether to hide the expansion toggle.
66
- * @default false
67
- */
68
- @property({ attribute: "hide-toggle", type: Boolean, reflect: true }) hideToggle = false;
69
-
70
- /** @inheritdoc */
71
- protected override firstUpdated(_changedProperties: PropertyValues<this>): void {
72
- super.firstUpdated(_changedProperties);
73
- [this._focusRing, this._stateLayer].forEach((x) => x?.attach(this));
74
- }
75
-
76
- /** @inheritdoc */
77
- protected override render(): unknown {
78
- return html`<m3e-focus-ring class="focus-ring" ?disabled="${this.disabled}"></m3e-focus-ring>
79
- <m3e-state-layer class="state-layer" ?disabled="${this.disabled}"></m3e-state-layer>
80
- ${this.togglePosition === "before" ? this.#renderToggle() : nothing}
81
- <div class="content">
82
- <slot></slot>
83
- </div>
84
- ${this.togglePosition === "after" ? this.#renderToggle() : nothing}`;
85
- }
86
-
87
- /** @private */
88
- #renderToggle(): unknown {
89
- return html`<div class="toggle" aria-hidden="true">
90
- <slot name="toggle-icon"></slot>
91
- </div>`;
92
- }
93
- }
94
-
95
- declare global {
96
- interface HTMLElementTagNameMap {
97
- "m3e-expansion-header": M3eExpansionHeaderElement;
98
- }
99
- }
@@ -1,260 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
2
-
3
- import { CSSResultGroup, html, LitElement } from "lit";
4
- import { customElement, property, query } from "lit/decorators.js";
5
-
6
- import { AttachInternals, Disabled, EventAttribute, Role } from "@m3e/core";
7
-
8
- import { ExpansionTogglePosition } from "./ExpansionTogglePosition";
9
- import { ExpansionToggleDirection } from "./ExpansionToggleDirection";
10
-
11
- import { ExpansionPanelStyle } from "./styles";
12
- import { M3eExpansionHeaderElement } from "./ExpansionHeaderElement";
13
-
14
- /**
15
- * @summary
16
- * An expandable details-summary view.
17
- *
18
- * @description
19
- * The `m3e-expansion-panel` component provides an accessible, animated details-summary view for
20
- * organizing content in collapsible sections. It supports custom header, content, actions, and
21
- * toggle icon slots, and offers configurable toggle position and direction. The panel responds to
22
- * open/close states, emits lifecycle events, and supports rich theming via CSS custom properties
23
- * for elevation, shape, spacing, and color.
24
- *
25
- * @example
26
- * The following example illustrates the basic use of the `m3e-accordion` and `m3e-expansion-panel` components.
27
- *
28
- * ```html
29
- * <m3e-accordion>
30
- * <m3e-expansion-panel>
31
- * <span slot="header">Panel 1</span>
32
- * I am content for the first expansion panel
33
- * </m3e-expansion-panel>
34
- * <m3e-expansion-panel>
35
- * <span slot="header">Panel 2</span>
36
- * I am content for the second expansion panel
37
- * </m3e-expansion-panel>
38
- * </m3e-accordion>
39
- * ```
40
- *
41
- * @tag m3e-expansion-panel
42
- *
43
- * @slot - Renders the detail of the panel.
44
- * @slot actions- Renders the actions bar of the panel.
45
- * @slot header - Renders the header content.
46
- * @slot toggle-icon - Renders the expansion toggle icon.
47
- *
48
- * @attr disabled - Whether the element is disabled.
49
- * @attr hide-toggle - Whether to hide the expansion toggle.
50
- * @attr open - Whether the panel is expanded.
51
- * @attr toggle-direction - The direction of the expansion toggle.
52
- * @attr toggle-position - The position of the expansion toggle.
53
- *
54
- * @fires opening - Emitted when the expansion panel begins to open.
55
- * @fires opened - Emitted when the expansion panel has opened.
56
- * @fires closing - Emitted when the expansion panel begins to close.
57
- * @fires closed - Emitted when the expansion panel has closed.
58
- *
59
- * @cssprop --m3e-expansion-header-collapsed-height - Height of the header when the panel is collapsed.
60
- * @cssprop --m3e-expansion-header-expanded-height - Height of the header when the panel is expanded.
61
- * @cssprop --m3e-expansion-header-padding-left - Left padding inside the header.
62
- * @cssprop --m3e-expansion-header-padding-right - Right padding inside the header.
63
- * @cssprop --m3e-expansion-header-spacing - Spacing between header elements.
64
- * @cssprop --m3e-expansion-header-toggle-icon-size - Size of the toggle icon (e.g. chevron).
65
- * @cssprop --m3e-expansion-header-font-size - The font size of the header text.
66
- * @cssprop --m3e-expansion-header-font-weight - The font weight of the header text.
67
- * @cssprop --m3e-expansion-header-line-height - The line height of the header text.
68
- * @cssprop --m3e-expansion-header-tracking - Letter spacing (tracking) of the header text.
69
- * @cssprop --m3e-expansion-panel-text-color - Color of the panel's text content.
70
- * @cssprop --m3e-expansion-panel-disabled-text-color - Color of the panel's text content, when disabled.
71
- * @cssprop --m3e-expansion-panel-disabled-text-opacity - Opacity of the panel's text content, when disabled.
72
- * @cssprop --m3e-expansion-panel-container-color - Background color of the panel container.
73
- * @cssprop --m3e-expansion-panel-elevation - Elevation level when the panel is collapsed.
74
- * @cssprop --m3e-expansion-panel-shape - Shape (e.g. border radius) of the panel when collapsed.
75
- * @cssprop --m3e-expansion-panel-open-elevation - Elevation level when the panel is expanded.
76
- * @cssprop --m3e-expansion-panel-open-shape - Shape (e.g. border radius) of the panel when expanded.
77
- * @cssprop --m3e-expansion-panel-content-padding - Padding around the panel's content area.
78
- * @cssprop --m3e-expansion-panel-actions-spacing - Spacing between action buttons or elements.
79
- * @cssprop --m3e-expansion-panel-actions-padding - Padding around the actions section.
80
- * @cssprop --m3e-expansion-panel-actions-divider-thickness - Thickness of the divider above actions.
81
- * @cssprop --m3e-expansion-panel-actions-divider-color - Color of the divider above actions.
82
- */
83
- @customElement("m3e-expansion-panel")
84
- export class M3eExpansionPanelElement extends EventAttribute(
85
- Disabled(AttachInternals(Role(LitElement, "none"), true)),
86
- "opening",
87
- "opened",
88
- "closing",
89
- "closed"
90
- ) {
91
- /** The styles of the element. */
92
- static override styles: CSSResultGroup = ExpansionPanelStyle;
93
-
94
- /** @private */ private static __nextId = 0;
95
- /** @private */ #id = M3eExpansionPanelElement.__nextId++;
96
- /** @private */ #contentId = `m3e-expansion-panel-${this.#id}-content`;
97
- /** @private */ #headerId = `m3e-expansion-panel-${this.#id}-header`;
98
-
99
- /** @private */ @query("m3e-expansion-header") private readonly _header?: M3eExpansionHeaderElement;
100
-
101
- /**
102
- * Whether the panel is expanded.
103
- * @default false
104
- */
105
- @property({ type: Boolean, reflect: true }) open = false;
106
-
107
- /**
108
- * The direction of the expansion toggle.
109
- * @default "vertical"
110
- */
111
- @property({ attribute: "toggle-direction", reflect: true }) toggleDirection: ExpansionToggleDirection = "vertical";
112
-
113
- /**
114
- * The position of the expansion toggle.
115
- * @default "after"
116
- */
117
- @property({ attribute: "toggle-position", reflect: true }) togglePosition: ExpansionTogglePosition = "after";
118
-
119
- /**
120
- * Whether to hide the expansion toggle.
121
- * @default false
122
- */
123
- @property({ attribute: "hide-toggle", type: Boolean, reflect: true }) hideToggle = false;
124
-
125
- /** @inheritdoc */
126
- protected override render(): unknown {
127
- return html` <m3e-expansion-header
128
- id="${this.#headerId}"
129
- toggle-direction="${this.toggleDirection}"
130
- toggle-position="${this.togglePosition}"
131
- ?hide-toggle="${this.hideToggle}"
132
- ?disabled="${this.disabled}"
133
- aria-expanded="${this.open}"
134
- aria-controls="${this.#contentId}"
135
- @click="${this.#handleHeaderClick}"
136
- @keydown="${this.#handleKeyDown}"
137
- >
138
- <div slot="toggle-icon" class="toggle">
139
- <slot name="toggle-icon">${this.#renderToggleIcon()}</slot>
140
- </div>
141
- <slot name="header"></slot>
142
- </m3e-expansion-header>
143
- <m3e-collapsible
144
- id="${this.#contentId}"
145
- role="region"
146
- aria-labelledby="${this.#headerId}"
147
- aria-hidden="${!this.open}"
148
- ?open="${this.open}"
149
- @opening="${this.#handleCollapsibleEvent}"
150
- @opened="${this.#handleCollapsibleEvent}"
151
- @closing="${this.#handleCollapsibleEvent}"
152
- @closed="${this.#handleCollapsibleEvent}"
153
- >
154
- <div class="content">
155
- <slot></slot>
156
- </div>
157
- <slot name="actions"></slot>
158
- </m3e-collapsible>`;
159
- }
160
-
161
- /** @private */
162
- #renderToggleIcon(): unknown {
163
- return this.toggleDirection === "vertical"
164
- ? html`<svg viewBox="0 -960 960 960" fill="currentColor">
165
- <path d="M480-344 240-584l56-56 184 184 184-184 56 56-240 240Z" />
166
- </svg>`
167
- : html`<svg viewBox="0 -960 960 960" fill="currentColor">
168
- <path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z" />
169
- </svg>`;
170
- }
171
-
172
- /** @private */
173
- #handleHeaderClick() {
174
- this.open = !this.open;
175
- }
176
-
177
- /** @private */
178
- #handleKeyDown(e: KeyboardEvent): void {
179
- switch (e.key) {
180
- case "ArrowUp":
181
- {
182
- e.preventDefault();
183
- const accordion = this.closest("m3e-accordion");
184
- if (accordion) {
185
- const panels = [...accordion.panels].reverse();
186
- const index = panels.indexOf(this);
187
- (
188
- panels.find((x, i) => !x.disabled && i > index) ?? panels.find((x, i) => !x.disabled && i < index)
189
- )?._header?.focus();
190
- } else {
191
- this.open = false;
192
- }
193
- }
194
-
195
- break;
196
-
197
- case "ArrowDown":
198
- {
199
- e.preventDefault();
200
- const accordion = this.closest("m3e-accordion");
201
- if (accordion) {
202
- const index = accordion.panels.indexOf(this);
203
- (
204
- accordion.panels.find((x, i) => !x.disabled && i > index) ??
205
- accordion.panels.find((x, i) => !x.disabled && i < index)
206
- )?._header?.focus();
207
- } else {
208
- this.open = true;
209
- }
210
- }
211
-
212
- break;
213
- }
214
- }
215
-
216
- /** @private */
217
- #handleCollapsibleEvent(e: Event): void {
218
- e.stopPropagation();
219
- this.dispatchEvent(new Event(e.type, { bubbles: true }));
220
- }
221
- }
222
-
223
- interface M3eExpansionPanelElementEventMap extends HTMLElementEventMap {
224
- opening: Event;
225
- opened: Event;
226
- closing: Event;
227
- closed: Event;
228
- }
229
-
230
- export interface M3eExpansionPanelElement {
231
- addEventListener<K extends keyof M3eExpansionPanelElementEventMap>(
232
- type: K,
233
- listener: (this: M3eExpansionPanelElement, ev: M3eExpansionPanelElementEventMap[K]) => void,
234
- options?: boolean | AddEventListenerOptions
235
- ): void;
236
-
237
- addEventListener(
238
- type: string,
239
- listener: EventListenerOrEventListenerObject,
240
- options?: boolean | AddEventListenerOptions
241
- ): void;
242
-
243
- removeEventListener<K extends keyof M3eExpansionPanelElementEventMap>(
244
- type: K,
245
- listener: (this: M3eExpansionPanelElement, ev: M3eExpansionPanelElementEventMap[K]) => void,
246
- options?: boolean | EventListenerOptions
247
- ): void;
248
-
249
- removeEventListener(
250
- type: string,
251
- listener: EventListenerOrEventListenerObject,
252
- options?: boolean | EventListenerOptions
253
- ): void;
254
- }
255
-
256
- declare global {
257
- interface HTMLElementTagNameMap {
258
- "m3e-expansion-panel": M3eExpansionPanelElement;
259
- }
260
- }
@@ -1,2 +0,0 @@
1
- /** Specifies the possible directions of an expansion toggle. */
2
- export type ExpansionToggleDirection = "vertical" | "horizontal";
@@ -1,2 +0,0 @@
1
- /** Specifies the possible positions of an expansion toggle. */
2
- export type ExpansionTogglePosition = "before" | "after";
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from "./AccordionElement";
2
- export * from "./ExpansionHeaderElement";
3
- export * from "./ExpansionPanelElement";
4
- export * from "./ExpansionToggleDirection";
5
- export * from "./ExpansionTogglePosition";