@fluid-topics/ftds-checkbox 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 checkbox component
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ npm install @fluid-topics/ftds-checkbox
7
+ yarn add @fluid-topics/ftds-checkbox
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```typescript
13
+ import { html } from "lit"
14
+ import "@fluid-topics/ftds-checkbox"
15
+
16
+ function render() {
17
+ return html` <ftds-checkbox foo="bar"></ftds-checkbox> `
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,5 @@
1
+ import { FtdsCheckbox } from "./ftds-checkbox";
2
+ declare const _default: {
3
+ "ftds-checkbox": typeof FtdsCheckbox;
4
+ };
5
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { FtdsCheckbox } from "./ftds-checkbox";
2
+ export default {
3
+ "ftds-checkbox": FtdsCheckbox,
4
+ };
@@ -0,0 +1,46 @@
1
+ import { nothing, PropertyValues } from "lit";
2
+ import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
3
+ import { ClassInfo } from "lit/directives/class-map.js";
4
+ import { FtdsCheckboxProperties } from "./ftds-checkbox.properties";
5
+ import { DesignSystemFamily } from "@fluid-topics/design-system-variables";
6
+ export declare class FtdsCheckboxChangeEvent extends CustomEvent<{
7
+ value: string;
8
+ checked: boolean;
9
+ }> {
10
+ constructor(value: string, checked: boolean);
11
+ }
12
+ declare const FtdsCheckbox_base: import("@fluid-topics/ft-wc-utils").FtdsBaseType<typeof FtLitElement>;
13
+ export declare class FtdsCheckbox extends FtdsCheckbox_base implements FtdsCheckboxProperties {
14
+ static elementDefinitions: ElementDefinitionsMap;
15
+ static styles: import("lit").CSSResult[];
16
+ name: string;
17
+ value: string;
18
+ label: string;
19
+ helper: string;
20
+ checked: boolean;
21
+ indeterminate: boolean;
22
+ disabled: boolean;
23
+ error: boolean;
24
+ legendColor: string;
25
+ private container?;
26
+ private ripple?;
27
+ private input;
28
+ family: DesignSystemFamily;
29
+ get checkboxClasses(): ClassInfo;
30
+ get checkboxHelperClasses(): ClassInfo;
31
+ protected renderBoxContainer(): import("lit-html").TemplateResult<1>;
32
+ protected render(): import("lit-html").TemplateResult<1>;
33
+ protected renderBoxIcon(): any;
34
+ protected renderSlotBody(): import("lit-html").TemplateResult<1> | typeof nothing;
35
+ protected renderLegendColor(): import("lit-html").TemplateResult<1> | typeof nothing;
36
+ protected renderHelper(): import("lit-html").TemplateResult<1> | typeof nothing;
37
+ protected renderPopover(): import("lit-html").TemplateResult<1>;
38
+ protected onSlotchange(): void;
39
+ protected willUpdate(changedProperties: PropertyValues): void;
40
+ protected onChange(event: Event): void;
41
+ protected contentAvailableCallback(props: PropertyValues): void;
42
+ click(): void;
43
+ focus(): void;
44
+ private notNullOrBlank;
45
+ }
46
+ export {};
@@ -0,0 +1,220 @@
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, nothing, } from "lit";
8
+ import { property, query, } from "lit/decorators.js";
9
+ import { FtLitElement, safariEllipsisFix, toFtdsBase, } from "@fluid-topics/ft-wc-utils";
10
+ import { classMap, } from "lit/directives/class-map.js";
11
+ import { FtRipple } from "@fluid-topics/ft-ripple";
12
+ import { FtdsTypography, FtdsTypographyVariants, } from "@fluid-topics/ftds-typography";
13
+ import { FtdsPopover } from "@fluid-topics/ftds-popover";
14
+ import { FtdsLink } from "@fluid-topics/ftds-link";
15
+ import { FtdsIcon, FtdsIcons, FtdsIconVariants, } from "@fluid-topics/ftds-icon";
16
+ import { styles } from "./ftds-checkbox.styles";
17
+ import { DesignSystemFamily } from "@fluid-topics/design-system-variables";
18
+ export class FtdsCheckboxChangeEvent extends CustomEvent {
19
+ constructor(value, checked) {
20
+ super("change", { detail: { value: value, checked: checked }, bubbles: true, composed: true });
21
+ }
22
+ }
23
+ export class FtdsCheckbox extends toFtdsBase(FtLitElement) {
24
+ constructor() {
25
+ super(...arguments);
26
+ this.name = "";
27
+ this.value = "";
28
+ this.label = "";
29
+ this.helper = "";
30
+ this.checked = false;
31
+ this.indeterminate = false;
32
+ this.disabled = false;
33
+ this.error = false;
34
+ this.legendColor = "";
35
+ this.family = DesignSystemFamily.brand;
36
+ }
37
+ get checkboxClasses() {
38
+ return {
39
+ "ftds-checkbox": true,
40
+ "ftds-checkbox--error": this.error,
41
+ "ftds-checkbox--checked": this.indeterminate ? false : this.checked,
42
+ "ftds-checkbox--indeterminate": this.indeterminate,
43
+ "ftds-checkbox--disabled": this.disabled,
44
+ ...this.getDesignSystemBaseClasses(),
45
+ };
46
+ }
47
+ get checkboxHelperClasses() {
48
+ return {
49
+ "ftds-checkbox-helper--disabled": this.disabled,
50
+ "ftds-checkbox-helper--error": this.error,
51
+ "ftds-checkbox-helper--checked": this.indeterminate ? false : this.checked,
52
+ "ftds-checkbox-helper--indeterminate": this.indeterminate,
53
+ "ftds-checkbox-helper--legend-color-displayed": this.legendColor && this.legendColor.trim().length > 0,
54
+ };
55
+ }
56
+ renderBoxContainer() {
57
+ return html `
58
+ <div class="ftds-checkbox--box-container" part="checkbox-box-container">
59
+ <ft-ripple part="checkbox-ripple"
60
+ ?disabled=${this.disabled}
61
+ ?primary=${this.checked || this.indeterminate}
62
+ ?unbounded=${false}>
63
+ </ft-ripple>
64
+ <div class="ftds-checkbox--box" part="checkbox-box">
65
+ ${this.renderBoxIcon()}
66
+ </div>
67
+ <input type="checkbox"
68
+ id="checkbox-input"
69
+ part="checkbox-input"
70
+ name="${this.name}"
71
+ aria-checked="${this.indeterminate ? "mixed" : (this.checked ? "true" : "false")}"
72
+ role="checkbox"
73
+ .checked=${this.indeterminate ? false : this.checked}
74
+ .indeterminate=${this.indeterminate}
75
+ .disabled=${this.disabled}
76
+ @change=${this.onChange}
77
+ >
78
+ </div>
79
+ `;
80
+ }
81
+ render() {
82
+ return html `
83
+ <div part="checkbox-and-popover">
84
+ <div part="checkbox-label-and-helper">
85
+ <label class="${classMap(this.checkboxClasses)}" for="checkbox-input" part="checkbox-label">
86
+ ${this.renderBoxContainer()}
87
+ ${this.renderLegendColor()}
88
+ ${this.renderSlotBody()}
89
+ </label>
90
+ ${this.renderHelper()}
91
+ </div>
92
+ ${this.renderPopover()}
93
+ </div>
94
+ `;
95
+ }
96
+ renderBoxIcon() {
97
+ if (this.indeterminate) {
98
+ return html `
99
+ <ftds-icon part="checkbox-icon" icon="${FtdsIcons.HYPHEN}" variant="${FtdsIconVariants.regular}"></ftds-icon>`;
100
+ }
101
+ if (this.checked) {
102
+ return html `
103
+ <ftds-icon part="checkbox-icon" icon="${FtdsIcons.CHECK}"></ftds-icon>`;
104
+ }
105
+ return nothing;
106
+ }
107
+ renderSlotBody() {
108
+ return this.notNullOrBlank(this.label)
109
+ ? html `
110
+ <ftds-typography variant="${FtdsTypographyVariants.body2medium}"
111
+ part="checkbox-body">${this.label}
112
+ </ftds-typography>`
113
+ : nothing;
114
+ }
115
+ renderLegendColor() {
116
+ return this.notNullOrBlank(this.legendColor)
117
+ ? html `
118
+ <div part="checkbox-legend-color"
119
+ style="background-color: ${this.legendColor}">
120
+ </div>`
121
+ : nothing;
122
+ }
123
+ renderHelper() {
124
+ return this.notNullOrBlank(this.helper)
125
+ ? html `
126
+ <ftds-typography class="${classMap(this.checkboxHelperClasses)}"
127
+ variant="${FtdsTypographyVariants.caption1medium}"
128
+ part="checkbox-helper">${this.helper}
129
+ </ftds-typography>`
130
+ : nothing;
131
+ }
132
+ renderPopover() {
133
+ return html `
134
+ <div part="checkbox-popover">
135
+ <div part="checkbox-popover-wrapper">
136
+ <slot @slotchange=${this.onSlotchange}></slot>
137
+ </div>
138
+ </div>`;
139
+ }
140
+ onSlotchange() {
141
+ this.requestUpdate();
142
+ }
143
+ willUpdate(changedProperties) {
144
+ super.willUpdate(changedProperties);
145
+ if (changedProperties.has("checked")) {
146
+ this.ariaChecked = this.checked ? "true" : "false";
147
+ }
148
+ }
149
+ onChange(event) {
150
+ event.stopPropagation();
151
+ this.checked = event.target.checked;
152
+ this.indeterminate = false;
153
+ this.dispatchEvent(new FtdsCheckboxChangeEvent(this.value, this.checked));
154
+ }
155
+ contentAvailableCallback(props) {
156
+ var _a;
157
+ super.contentAvailableCallback(props);
158
+ (_a = this.ripple) === null || _a === void 0 ? void 0 : _a.setupFor(this.container);
159
+ }
160
+ click() {
161
+ this.input.click();
162
+ }
163
+ focus() {
164
+ this.input.focus();
165
+ setTimeout(() => {
166
+ var _a;
167
+ (_a = this.ripple) === null || _a === void 0 ? void 0 : _a.forceFocusUpdate();
168
+ }, 0);
169
+ }
170
+ notNullOrBlank(field) {
171
+ return field && field.trim().length > 0;
172
+ }
173
+ }
174
+ FtdsCheckbox.elementDefinitions = {
175
+ "ft-ripple": FtRipple,
176
+ "ftds-popover": FtdsPopover,
177
+ "ftds-link": FtdsLink,
178
+ "ftds-typography": FtdsTypography,
179
+ "ftds-icon": FtdsIcon,
180
+ };
181
+ FtdsCheckbox.styles = [
182
+ safariEllipsisFix,
183
+ styles,
184
+ ];
185
+ __decorate([
186
+ property()
187
+ ], FtdsCheckbox.prototype, "name", void 0);
188
+ __decorate([
189
+ property()
190
+ ], FtdsCheckbox.prototype, "value", void 0);
191
+ __decorate([
192
+ property()
193
+ ], FtdsCheckbox.prototype, "label", void 0);
194
+ __decorate([
195
+ property()
196
+ ], FtdsCheckbox.prototype, "helper", void 0);
197
+ __decorate([
198
+ property({ type: Boolean, reflect: true })
199
+ ], FtdsCheckbox.prototype, "checked", void 0);
200
+ __decorate([
201
+ property({ type: Boolean })
202
+ ], FtdsCheckbox.prototype, "indeterminate", void 0);
203
+ __decorate([
204
+ property({ type: Boolean })
205
+ ], FtdsCheckbox.prototype, "disabled", void 0);
206
+ __decorate([
207
+ property({ type: Boolean })
208
+ ], FtdsCheckbox.prototype, "error", void 0);
209
+ __decorate([
210
+ property()
211
+ ], FtdsCheckbox.prototype, "legendColor", void 0);
212
+ __decorate([
213
+ query(".ftds-checkbox")
214
+ ], FtdsCheckbox.prototype, "container", void 0);
215
+ __decorate([
216
+ query("ft-ripple")
217
+ ], FtdsCheckbox.prototype, "ripple", void 0);
218
+ __decorate([
219
+ query("input")
220
+ ], FtdsCheckbox.prototype, "input", void 0);