@fluid-topics/ftds-collapsible-block 2.1.8

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/README.md ADDED
@@ -0,0 +1,23 @@
1
+ A collapsible block
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ npm install @fluid-topics/ftds-collapsible-block
7
+ yarn add @fluid-topics/ftds-collapsible-block
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```typescript
13
+ import { html } from "lit"
14
+ import "@fluid-topics/ftds-collapsible-block"
15
+
16
+ function render() {
17
+ return html`
18
+ <ftds-collapsible-block headerText="This is will appear in the header.">
19
+ This will appear in the body.
20
+ </ftds-collapsible-block>
21
+ `
22
+ }
23
+ ```
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { customElements } from "@fluid-topics/ft-wc-utils";
2
+ import definitions from "./definitions";
3
+ customElements(definitions);
@@ -0,0 +1,5 @@
1
+ import { FtdsCollapsibleBlock } from "./ftds-collapsible-block";
2
+ declare const _default: {
3
+ "ftds-collapsible-block": typeof FtdsCollapsibleBlock;
4
+ };
5
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { FtdsCollapsibleBlock } from "./ftds-collapsible-block";
2
+ export default {
3
+ "ftds-collapsible-block": FtdsCollapsibleBlock,
4
+ };
@@ -0,0 +1,10 @@
1
+ import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
2
+ export declare class FtdsCollapsibleBlock extends FtLitElement {
3
+ static elementDefinitions: ElementDefinitionsMap;
4
+ static styles: import("lit").CSSResult[];
5
+ collapsed: boolean;
6
+ headerBorder: boolean;
7
+ headerText?: string;
8
+ protected render(): import("lit-html").TemplateResult<1>;
9
+ private onKeydown;
10
+ }
@@ -0,0 +1,85 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html } from "lit";
8
+ import { property } from "lit/decorators.js";
9
+ import { FtLitElement } from "@fluid-topics/ft-wc-utils";
10
+ import { designSystemStyles, FtdsCard } from "@fluid-topics/ftds-card";
11
+ import { FtdsIcon, FtdsIcons } from "@fluid-topics/ftds-icon";
12
+ import { FtdsTypography } from "@fluid-topics/ftds-typography";
13
+ import { FtRipple } from "@fluid-topics/ft-ripple";
14
+ import { when } from "lit/directives/when.js";
15
+ import { ftdsCollapsibleBlockStyles } from "./ftds-collapsible-block.styles";
16
+ import { renderCardHeaderContent } from "@fluid-topics/ftds-card/build/helpers";
17
+ import { classMap } from "lit/directives/class-map.js";
18
+ export class FtdsCollapsibleBlock extends FtLitElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.collapsed = false;
22
+ this.headerBorder = true;
23
+ }
24
+ render() {
25
+ return html `
26
+ <ftds-card>
27
+ <div slot="header-wrapper"
28
+ class="${classMap({
29
+ "ftds-card--header-border": this.headerBorder && !this.collapsed,
30
+ })}">
31
+ <div id="header"
32
+ role="button"
33
+ tabindex="0"
34
+ aria-controls="collapsible-body, collapsible-footer"
35
+ aria-expanded="${(!this.collapsed).toString()}"
36
+ @click=${() => this.collapsed = !this.collapsed}
37
+ @keydown=${this.onKeydown}>
38
+
39
+ <ft-ripple></ft-ripple>
40
+ ${renderCardHeaderContent({
41
+ headerText: this.headerText,
42
+ headerActions: html `
43
+ <ftds-icon
44
+ icon="${this.collapsed ? FtdsIcons.ANGLE_DOWN : FtdsIcons.ANGLE_UP}">
45
+ </ftds-icon>`,
46
+ })}
47
+ </div>
48
+ </div>
49
+
50
+ ${when(!this.collapsed, () => html `
51
+ <div id="collapsible-body"
52
+ aria-hidden="${(this.collapsed).toString()}">
53
+ <slot></slot>
54
+ </div>
55
+ <slot id="collapsible-footer"
56
+ aria-hidden="${(this.collapsed).toString()}"
57
+ name="footer"
58
+ slot="footer"></slot>
59
+ `)}
60
+ </ftds-card>
61
+ `;
62
+ }
63
+ onKeydown(event) {
64
+ if (event.code === "Enter" || event.code === "Space") {
65
+ event.preventDefault();
66
+ this.collapsed = !this.collapsed;
67
+ }
68
+ }
69
+ }
70
+ FtdsCollapsibleBlock.elementDefinitions = {
71
+ "ftds-card": FtdsCard,
72
+ "ftds-icon": FtdsIcon,
73
+ "ftds-typography": FtdsTypography,
74
+ "ft-ripple": FtRipple,
75
+ };
76
+ FtdsCollapsibleBlock.styles = [designSystemStyles, ftdsCollapsibleBlockStyles];
77
+ __decorate([
78
+ property({ type: Boolean, reflect: true })
79
+ ], FtdsCollapsibleBlock.prototype, "collapsed", void 0);
80
+ __decorate([
81
+ property({ type: Boolean, reflect: true })
82
+ ], FtdsCollapsibleBlock.prototype, "headerBorder", void 0);
83
+ __decorate([
84
+ property()
85
+ ], FtdsCollapsibleBlock.prototype, "headerText", void 0);