@fluid-topics/ftds-card 2.1.0

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,19 @@
1
+ The design system card component
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ npm install @fluid-topics/ftds-card
7
+ yarn add @fluid-topics/ftds-card
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```typescript
13
+ import { html } from "lit"
14
+ import "@fluid-topics/ftds-card"
15
+
16
+ function render() {
17
+ return html` <ftds-card foo="bar"></ftds-card> `
18
+ }
19
+ ```
@@ -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,9 @@
1
+ import { FtdsCardUserInfo } from "./ftds-card-user-info";
2
+ import { FtdsCard } from "./ftds-card";
3
+ import { FtdsCardLabelledInfo } from "./ftds-card-labelled-info";
4
+ declare const _default: {
5
+ "ftds-card": typeof FtdsCard;
6
+ "ftds-card-user-info": typeof FtdsCardUserInfo;
7
+ "ftds-card-labelled-info": typeof FtdsCardLabelledInfo;
8
+ };
9
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import { FtdsCardUserInfo } from "./ftds-card-user-info";
2
+ import { FtdsCard } from "./ftds-card";
3
+ import { FtdsCardLabelledInfo } from "./ftds-card-labelled-info";
4
+ export default {
5
+ "ftds-card": FtdsCard,
6
+ "ftds-card-user-info": FtdsCardUserInfo,
7
+ "ftds-card-labelled-info": FtdsCardLabelledInfo,
8
+ };
@@ -0,0 +1,9 @@
1
+ import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
2
+ import { FtdsCardLabelledInfoProperties } from "./ftds-card-labelled-info.properties";
3
+ export declare class FtdsCardLabelledInfo extends FtLitElement implements FtdsCardLabelledInfoProperties {
4
+ static elementDefinitions: ElementDefinitionsMap;
5
+ static styles: import("lit").CSSResult;
6
+ label: string;
7
+ info: string;
8
+ protected render(): import("lit-html").TemplateResult<1>;
9
+ }
@@ -0,0 +1,40 @@
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 { FtLitElement, } from "@fluid-topics/ft-wc-utils";
8
+ import { html } from "lit";
9
+ import { property } from "lit/decorators.js";
10
+ import { FtdsTypography, FtdsTypographyVariants, } from "@fluid-topics/ftds-typography";
11
+ import { labelledInfoStyles } from "./ftds-card-labelled-info.styles";
12
+ export class FtdsCardLabelledInfo extends FtLitElement {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.label = "";
16
+ this.info = "";
17
+ }
18
+ render() {
19
+ return html `
20
+ <div id="container">
21
+ <ftds-typography class="label" variant="${FtdsTypographyVariants.caption2medium}">
22
+ ${this.label}
23
+ </ftds-typography>
24
+ <ftds-typography class="info" variant="${FtdsTypographyVariants.body2medium}">
25
+ ${this.info}
26
+ </ftds-typography>
27
+ </div>
28
+ `;
29
+ }
30
+ }
31
+ FtdsCardLabelledInfo.elementDefinitions = {
32
+ "ftds-typography": FtdsTypography,
33
+ };
34
+ FtdsCardLabelledInfo.styles = labelledInfoStyles;
35
+ __decorate([
36
+ property()
37
+ ], FtdsCardLabelledInfo.prototype, "label", void 0);
38
+ __decorate([
39
+ property()
40
+ ], FtdsCardLabelledInfo.prototype, "info", void 0);
@@ -0,0 +1,4 @@
1
+ export interface FtdsCardLabelledInfoProperties {
2
+ label: string;
3
+ info: string;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const labelledInfoStyles: import("lit").CSSResult;
@@ -0,0 +1,21 @@
1
+ import { css } from "lit";
2
+ import { foundation, semantic, } from "@fluid-topics/ft-wc-utils";
3
+ // language=CSS
4
+ export const labelledInfoStyles = css `
5
+ :host {
6
+ }
7
+
8
+ #container {
9
+ display: flex;
10
+ flex-direction: column;
11
+ gap: ${foundation.spacing1};
12
+ }
13
+
14
+ .label {
15
+ color: ${semantic.contentGlobalSecondary};
16
+ }
17
+
18
+ .info {
19
+ color: ${semantic.contentGlobalPrimary};
20
+ }
21
+ `;
@@ -0,0 +1,8 @@
1
+ import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
2
+ import { CardUserProfile, FtdsCardUserInfoProperties } from "./ftds-card-user-info.properties";
3
+ export declare class FtdsCardUserInfo extends FtLitElement implements FtdsCardUserInfoProperties {
4
+ static elementDefinitions: ElementDefinitionsMap;
5
+ static styles: import("lit").CSSResult;
6
+ user?: CardUserProfile;
7
+ protected render(): import("lit-html").TemplateResult<1>;
8
+ }
@@ -0,0 +1,38 @@
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 { FtLitElement, } from "@fluid-topics/ft-wc-utils";
8
+ import { html } from "lit";
9
+ import { property } from "lit/decorators.js";
10
+ import { userInfoStyles } from "./ftds-card-user-info.styles";
11
+ import { FtdsIcon, FtdsIcons, } from "@fluid-topics/ftds-icon";
12
+ import { FtdsTypography, FtdsTypographyVariants, } from "@fluid-topics/ftds-typography";
13
+ export class FtdsCardUserInfo extends FtLitElement {
14
+ render() {
15
+ var _a, _b;
16
+ return html `
17
+ <div id="container">
18
+ <ftds-icon icon="${FtdsIcons.USER}"></ftds-icon>
19
+ <div id="info">
20
+ <ftds-typography class="name" variant="${FtdsTypographyVariants.caption1medium}">
21
+ ${(_a = this.user) === null || _a === void 0 ? void 0 : _a.displayName}
22
+ </ftds-typography>
23
+ <ftds-typography class="mail" variant="${FtdsTypographyVariants.caption1medium}">
24
+ ${(_b = this.user) === null || _b === void 0 ? void 0 : _b.emailAddress}
25
+ </ftds-typography>
26
+ </div>
27
+ </div>
28
+ `;
29
+ }
30
+ }
31
+ FtdsCardUserInfo.elementDefinitions = {
32
+ "ftds-typography": FtdsTypography,
33
+ "ftds-icon": FtdsIcon,
34
+ };
35
+ FtdsCardUserInfo.styles = userInfoStyles;
36
+ __decorate([
37
+ property({ attribute: false })
38
+ ], FtdsCardUserInfo.prototype, "user", void 0);
@@ -0,0 +1,5 @@
1
+ import { FtUserProfile } from "@fluid-topics/public-api";
2
+ export type CardUserProfile = Pick<FtUserProfile, "displayName" | "emailAddress">;
3
+ export interface FtdsCardUserInfoProperties {
4
+ user?: CardUserProfile;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const userInfoStyles: import("lit").CSSResult;
@@ -0,0 +1,31 @@
1
+ import { css } from "lit";
2
+ import { foundation, semantic, } from "@fluid-topics/ft-wc-utils";
3
+ import { FtdsIconCssVariables } from "@fluid-topics/ftds-icon";
4
+ // language=CSS
5
+ export const userInfoStyles = css `
6
+ :host {
7
+ }
8
+
9
+ #container {
10
+ display: flex;
11
+ align-items: center;
12
+ gap: ${foundation.spacing2};
13
+ }
14
+
15
+ ftds-icon {
16
+ ${FtdsIconCssVariables.size.set(foundation.iconSize5)};
17
+ }
18
+
19
+ #info {
20
+ display: flex;
21
+ flex-direction: column;
22
+
23
+ .name {
24
+ color: ${semantic.contentGlobalPrimary};
25
+ }
26
+
27
+ .mail {
28
+ color: ${semantic.contentGlobalSecondary};
29
+ }
30
+ }
31
+ `;
@@ -0,0 +1,30 @@
1
+ import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
2
+ import { FtdsCardProperties } from "./ftds-card.properties";
3
+ export declare class FtdsCard extends FtLitElement implements FtdsCardProperties {
4
+ static elementDefinitions: ElementDefinitionsMap;
5
+ static styles: import("lit").CSSResult;
6
+ headerText?: string;
7
+ headerBorder: boolean;
8
+ headerHref?: string;
9
+ selectable: boolean;
10
+ selected: boolean;
11
+ private hasHeader;
12
+ private hasHeaderActions;
13
+ private hasBody;
14
+ private hasFooter;
15
+ private hasFooterActions;
16
+ private hasSideBar;
17
+ private headerContent;
18
+ private headerActionsContent;
19
+ private bodyContent?;
20
+ private footerContent;
21
+ private footerActionsContent;
22
+ private sideBarContent;
23
+ private get isClickable();
24
+ protected render(): import("lit-html").TemplateResult<1>;
25
+ private renderHeaderText;
26
+ private onKeydown;
27
+ private onKeyup;
28
+ private onClick;
29
+ private onSlotchange;
30
+ }
@@ -0,0 +1,180 @@
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 { FtLitElement, unslotText, } from "@fluid-topics/ft-wc-utils";
8
+ import { FtdsTypography } from "@fluid-topics/ftds-typography";
9
+ import { designSystemStyles, FtdsCardTypographies, } from "./ftds-card.styles";
10
+ import { property, query, queryAssignedNodes, state, } from "lit/decorators.js";
11
+ import { html, nothing, } from "lit";
12
+ import { when } from "lit/directives/when.js";
13
+ import { classMap } from "lit/directives/class-map.js";
14
+ import { FtRipple } from "@fluid-topics/ft-ripple";
15
+ export class FtdsCard extends FtLitElement {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.headerBorder = false;
19
+ this.selectable = false;
20
+ this.selected = false;
21
+ this.hasHeader = true;
22
+ this.hasHeaderActions = false;
23
+ this.hasBody = true;
24
+ this.hasFooter = true;
25
+ this.hasFooterActions = false;
26
+ this.hasSideBar = false;
27
+ }
28
+ get isClickable() {
29
+ return this.selectable || !!this.headerHref;
30
+ }
31
+ render() {
32
+ const classes = {
33
+ "ftds-card--clickable": this.isClickable,
34
+ "ftds-card--selected": this.selected,
35
+ "ftds-card--selectable": this.selectable,
36
+ "ftds-card--header-border": this.headerBorder,
37
+ "ftds-card--no-header": !this.hasHeader,
38
+ "ftds-card--no-header-actions": !this.hasHeaderActions,
39
+ "ftds-card--no-body": !this.hasBody,
40
+ "ftds-card--no-footer": !this.hasFooter,
41
+ "ftds-card--no-footer-actions": !this.hasFooterActions,
42
+ "ftds-card--no-side-bar": !this.hasSideBar,
43
+ };
44
+ return html `
45
+ <div id="container"
46
+ role="${this.selectable ? "checkbox" : nothing}"
47
+ aria-checked="${this.selectable ? this.selected.toString() : nothing}"
48
+ aria-labelledby="${this.selectable ? "header-title" : nothing}"
49
+ tabindex="${this.selectable ? 0 : nothing}"
50
+ class="${classMap(classes)}"
51
+ @keydown=${this.onKeydown}
52
+ @keyup=${this.onKeyup}
53
+ @click=${this.onClick}
54
+ >
55
+ ${when(!!this.headerHref || this.selectable, () => html `
56
+ <ft-ripple ?selected=${this.selected}></ft-ripple>
57
+ `)}
58
+ <div id="main">
59
+ <div id="image">
60
+ <slot name="image" @slotchange=${this.onSlotchange}></slot>
61
+ </div>
62
+ <div id="header">
63
+ <div id="header-title">
64
+ ${when(!!this.headerHref, () => html `
65
+ <a href="${this.headerHref}">
66
+ ${this.renderHeaderText()}
67
+ </a>
68
+ `, () => html `
69
+ ${this.renderHeaderText()}
70
+ `)}
71
+ <slot name="header" @slotchange=${this.onSlotchange}></slot>
72
+ </div>
73
+ <div id="header-actions">
74
+ <slot name="header-actions" @slotchange=${this.onSlotchange}></slot>
75
+ </div>
76
+ </div>
77
+ <div id="body">
78
+ <slot @slotchange=${this.onSlotchange}></slot>
79
+ </div>
80
+ <div id="footer">
81
+ <div id="footer-text">
82
+ <slot name="footer" @slotchange=${this.onSlotchange}></slot>
83
+ </div>
84
+ <div id="footer-actions">
85
+ <slot name="footer-actions" @slotchange=${this.onSlotchange}></slot>
86
+ </div>
87
+ </div>
88
+ </div>
89
+ <div id="side-bar">
90
+ <slot name="side-bar" @slotchange=${this.onSlotchange}></slot>
91
+ </div>
92
+ </div>
93
+ `;
94
+ }
95
+ renderHeaderText() {
96
+ return html `
97
+ <ftds-typography variant="${FtdsCardTypographies.header}">${this.headerText}</ftds-typography>
98
+ `;
99
+ }
100
+ onKeydown(event) {
101
+ if (this.selectable && event.code === "Space") {
102
+ event.preventDefault();
103
+ }
104
+ }
105
+ onKeyup(event) {
106
+ if (this.selectable && event.code === "Space") {
107
+ this.dispatchEvent(new CustomEvent("change", { detail: !this.selected }));
108
+ }
109
+ }
110
+ onClick() {
111
+ if (this.selectable) {
112
+ this.dispatchEvent(new CustomEvent("change", { detail: !this.selected }));
113
+ }
114
+ }
115
+ onSlotchange() {
116
+ var _a, _b;
117
+ this.hasHeader = this.headerContent.length > 0 || !!this.headerText;
118
+ this.hasHeaderActions = this.headerActionsContent.length > 0;
119
+ this.hasBody = unslotText(this.bodyContent).trim().length > 0 || ((_b = (_a = this.bodyContent) === null || _a === void 0 ? void 0 : _a.assignedElements()) !== null && _b !== void 0 ? _b : []).length > 0;
120
+ this.hasFooter = this.footerContent.length > 0;
121
+ this.hasFooterActions = this.footerActionsContent.length > 0;
122
+ this.hasSideBar = this.sideBarContent.length > 0;
123
+ }
124
+ }
125
+ FtdsCard.elementDefinitions = {
126
+ "ftds-typography": FtdsTypography,
127
+ "ft-ripple": FtRipple,
128
+ };
129
+ FtdsCard.styles = designSystemStyles;
130
+ __decorate([
131
+ property()
132
+ ], FtdsCard.prototype, "headerText", void 0);
133
+ __decorate([
134
+ property({ type: Boolean })
135
+ ], FtdsCard.prototype, "headerBorder", void 0);
136
+ __decorate([
137
+ property()
138
+ ], FtdsCard.prototype, "headerHref", void 0);
139
+ __decorate([
140
+ property({ type: Boolean })
141
+ ], FtdsCard.prototype, "selectable", void 0);
142
+ __decorate([
143
+ property({ type: Boolean })
144
+ ], FtdsCard.prototype, "selected", void 0);
145
+ __decorate([
146
+ state()
147
+ ], FtdsCard.prototype, "hasHeader", void 0);
148
+ __decorate([
149
+ state()
150
+ ], FtdsCard.prototype, "hasHeaderActions", void 0);
151
+ __decorate([
152
+ state()
153
+ ], FtdsCard.prototype, "hasBody", void 0);
154
+ __decorate([
155
+ state()
156
+ ], FtdsCard.prototype, "hasFooter", void 0);
157
+ __decorate([
158
+ state()
159
+ ], FtdsCard.prototype, "hasFooterActions", void 0);
160
+ __decorate([
161
+ state()
162
+ ], FtdsCard.prototype, "hasSideBar", void 0);
163
+ __decorate([
164
+ queryAssignedNodes({ slot: "header" })
165
+ ], FtdsCard.prototype, "headerContent", void 0);
166
+ __decorate([
167
+ queryAssignedNodes({ slot: "header-actions" })
168
+ ], FtdsCard.prototype, "headerActionsContent", void 0);
169
+ __decorate([
170
+ query("#body slot")
171
+ ], FtdsCard.prototype, "bodyContent", void 0);
172
+ __decorate([
173
+ queryAssignedNodes({ slot: "footer" })
174
+ ], FtdsCard.prototype, "footerContent", void 0);
175
+ __decorate([
176
+ queryAssignedNodes({ slot: "footer-actions" })
177
+ ], FtdsCard.prototype, "footerActionsContent", void 0);
178
+ __decorate([
179
+ queryAssignedNodes({ slot: "side-bar" })
180
+ ], FtdsCard.prototype, "sideBarContent", void 0);