@momentum-design/components 0.18.4 → 0.18.5

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.
@@ -0,0 +1,71 @@
1
+ import { CSSResult, PropertyValues } from 'lit';
2
+ import FormfieldWrapper from '../formfieldwrapper/formfieldwrapper.component';
3
+ declare const Checkbox_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/NameMixin").NameMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/ValueMixin").ValueMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & typeof FormfieldWrapper;
4
+ /**
5
+ * Checkboxes allow users to select multiple options from a list or turn an item/feature on or off.
6
+ * These are often used in forms, settings, and selections in lists.
7
+ *
8
+ * A checkbox component contains an optional label and an optional helper text.
9
+ *
10
+ * @dependency mdc-icon
11
+ *
12
+ * @tagname mdc-checkbox
13
+ *
14
+ * @cssproperty --mdc-checkbox-background-color-hover - Allows customization of the background color on hover.
15
+ * @cssproperty --mdc-checkbox-border-color - Border color in high contrast.
16
+ * @cssproperty --mdc-checkbox-checked-background-color - Background color for a selected checkbox.
17
+ * @cssproperty --mdc-checkbox-checked-background-color-hover - Background color for a selected checkbox when hovered.
18
+ * @cssproperty --mdc-checkbox-checked-pressed-icon-color - Background color for a selected checkbox when pressed.
19
+ * @cssproperty --mdc-checkbox-disabled-background-color - Background color for a disabled checkbox.
20
+ * @cssproperty --mdc-checkbox-disabled-border-color - Border color for a disabled checkbox.
21
+ * @cssproperty --mdc-checkbox-disabled-checked-icon-color - Background color for a disabled, selected checkbox.
22
+ * @cssproperty --mdc-checkbox-disabled-icon-color - Icon color for a disabled checkbox.
23
+ * @cssproperty --mdc-checkbox-icon-background-color - Background color for an unselected checkbox.
24
+ * @cssproperty --mdc-checkbox-icon-border-color - Default background color for an unselected checkbox.
25
+ * @cssproperty --mdc-checkbox-icon-color - Icon color for an unselected checkbox.
26
+ * @cssproperty --mdc-checkbox-pressed-icon-color - Background color for a selected checkbox when pressed.
27
+ */
28
+ declare class Checkbox extends Checkbox_base {
29
+ /**
30
+ * Determines whether the checkbox is selected or unselected.
31
+ *
32
+ * @default false
33
+ */
34
+ checked: boolean;
35
+ /**
36
+ * This property is used to determine the parent checkbox in a nested checkbox group.
37
+ * If any one of the children is unselected, then the parent checkbox will be indeterminate.
38
+ * If all children are either selected or unselected, then the parent checkbox will not be indeterminate.
39
+ *
40
+ * @default false
41
+ */
42
+ indeterminate: boolean;
43
+ /** @internal */
44
+ private internals;
45
+ /** @internal */
46
+ static formAssociated: boolean;
47
+ /** @internal */
48
+ get form(): HTMLFormElement | null;
49
+ constructor();
50
+ /**
51
+ * Updates the form value to reflect the current state of the checkbox.
52
+ * If checked, the value is set to either the user-provided value or 'on' if no value is provided.
53
+ * If unchecked, the value is set to null.
54
+ */
55
+ private setFormValue;
56
+ /**
57
+ * Toggles the state of the checkbox element.
58
+ * If the element is not disabled, then
59
+ * the checked property is toggled and the indeterminate property is set to false.
60
+ */
61
+ private toggleState;
62
+ /**
63
+ * Toggles the state of the checkbox element.
64
+ * and dispatch the new event.
65
+ */
66
+ handleChange(event: Event): void;
67
+ update(changedProperties: PropertyValues): void;
68
+ render(): import("lit-html").TemplateResult<1>;
69
+ static styles: Array<CSSResult>;
70
+ }
71
+ export default Checkbox;
@@ -0,0 +1,150 @@
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
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { html, nothing } from 'lit';
11
+ import { property } from 'lit/decorators.js';
12
+ import { ifDefined } from 'lit/directives/if-defined.js';
13
+ import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
14
+ import { NameMixin } from '../../utils/mixins/NameMixin';
15
+ import { ValueMixin } from '../../utils/mixins/ValueMixin';
16
+ import FormfieldWrapper from '../formfieldwrapper/formfieldwrapper.component';
17
+ import { ICON_NAME } from './checkbox.constants';
18
+ import styles from './checkbox.styles';
19
+ /**
20
+ * Checkboxes allow users to select multiple options from a list or turn an item/feature on or off.
21
+ * These are often used in forms, settings, and selections in lists.
22
+ *
23
+ * A checkbox component contains an optional label and an optional helper text.
24
+ *
25
+ * @dependency mdc-icon
26
+ *
27
+ * @tagname mdc-checkbox
28
+ *
29
+ * @cssproperty --mdc-checkbox-background-color-hover - Allows customization of the background color on hover.
30
+ * @cssproperty --mdc-checkbox-border-color - Border color in high contrast.
31
+ * @cssproperty --mdc-checkbox-checked-background-color - Background color for a selected checkbox.
32
+ * @cssproperty --mdc-checkbox-checked-background-color-hover - Background color for a selected checkbox when hovered.
33
+ * @cssproperty --mdc-checkbox-checked-pressed-icon-color - Background color for a selected checkbox when pressed.
34
+ * @cssproperty --mdc-checkbox-disabled-background-color - Background color for a disabled checkbox.
35
+ * @cssproperty --mdc-checkbox-disabled-border-color - Border color for a disabled checkbox.
36
+ * @cssproperty --mdc-checkbox-disabled-checked-icon-color - Background color for a disabled, selected checkbox.
37
+ * @cssproperty --mdc-checkbox-disabled-icon-color - Icon color for a disabled checkbox.
38
+ * @cssproperty --mdc-checkbox-icon-background-color - Background color for an unselected checkbox.
39
+ * @cssproperty --mdc-checkbox-icon-border-color - Default background color for an unselected checkbox.
40
+ * @cssproperty --mdc-checkbox-icon-color - Icon color for an unselected checkbox.
41
+ * @cssproperty --mdc-checkbox-pressed-icon-color - Background color for a selected checkbox when pressed.
42
+ */
43
+ class Checkbox extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper))) {
44
+ /** @internal */
45
+ get form() {
46
+ return this.internals.form;
47
+ }
48
+ constructor() {
49
+ super();
50
+ /**
51
+ * Determines whether the checkbox is selected or unselected.
52
+ *
53
+ * @default false
54
+ */
55
+ this.checked = false;
56
+ /**
57
+ * This property is used to determine the parent checkbox in a nested checkbox group.
58
+ * If any one of the children is unselected, then the parent checkbox will be indeterminate.
59
+ * If all children are either selected or unselected, then the parent checkbox will not be indeterminate.
60
+ *
61
+ * @default false
62
+ */
63
+ this.indeterminate = false;
64
+ this.internals = this.attachInternals();
65
+ // Checkbox does not contain helpTextType property.
66
+ this.helpTextType = undefined;
67
+ }
68
+ /**
69
+ * Updates the form value to reflect the current state of the checkbox.
70
+ * If checked, the value is set to either the user-provided value or 'on' if no value is provided.
71
+ * If unchecked, the value is set to null.
72
+ */
73
+ setFormValue() {
74
+ let actualValue = null;
75
+ if (this.checked) {
76
+ actualValue = !this.value ? 'on' : this.value;
77
+ }
78
+ this.internals.setFormValue(actualValue);
79
+ }
80
+ /**
81
+ * Toggles the state of the checkbox element.
82
+ * If the element is not disabled, then
83
+ * the checked property is toggled and the indeterminate property is set to false.
84
+ */
85
+ toggleState() {
86
+ if (!this.disabled) {
87
+ this.checked = !this.checked;
88
+ this.indeterminate = false;
89
+ }
90
+ }
91
+ /**
92
+ * Toggles the state of the checkbox element.
93
+ * and dispatch the new event.
94
+ */
95
+ handleChange(event) {
96
+ this.toggleState();
97
+ this.dispatchEvent(new Event(event.type, event));
98
+ }
99
+ update(changedProperties) {
100
+ super.update(changedProperties);
101
+ if (changedProperties.has('checked')) {
102
+ this.setFormValue();
103
+ }
104
+ }
105
+ render() {
106
+ var _a;
107
+ const checkboxIconContent = (this.checked || this.indeterminate) ? html `
108
+ <mdc-icon
109
+ class="icon"
110
+ name="${this.indeterminate ? ICON_NAME.INDETERMINATE : ICON_NAME.CHECKED}"
111
+ size="1"
112
+ length-unit="rem"
113
+ ></mdc-icon>
114
+ ` : nothing;
115
+ const helpTextContent = this.helpText ? this.renderHelperText() : nothing;
116
+ return html `
117
+ <div class="container mdc-focus-ring">
118
+ <input
119
+ id="${this.id}"
120
+ type="checkbox"
121
+ class="input"
122
+ name="${ifDefined(this.name)}"
123
+ value="${ifDefined(this.value)}"
124
+ .checked="${this.checked}"
125
+ .indeterminate="${this.indeterminate}"
126
+ .disabled="${this.disabled}"
127
+ aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
128
+ @change=${this.handleChange}
129
+ />
130
+ <div class="icon-container">${checkboxIconContent}</div>
131
+ </div>
132
+ <div class="text-container">
133
+ ${this.renderLabel()}
134
+ ${helpTextContent}
135
+ </div>
136
+ `;
137
+ }
138
+ }
139
+ /** @internal */
140
+ Checkbox.formAssociated = true;
141
+ Checkbox.styles = [...FormfieldWrapper.styles, ...styles];
142
+ __decorate([
143
+ property({ type: Boolean, reflect: true }),
144
+ __metadata("design:type", Object)
145
+ ], Checkbox.prototype, "checked", void 0);
146
+ __decorate([
147
+ property({ type: Boolean, reflect: true }),
148
+ __metadata("design:type", Object)
149
+ ], Checkbox.prototype, "indeterminate", void 0);
150
+ export default Checkbox;
@@ -0,0 +1,6 @@
1
+ declare const TAG_NAME: "mdc-checkbox";
2
+ declare const ICON_NAME: {
3
+ readonly CHECKED: "check-bold";
4
+ readonly INDETERMINATE: "minus-bold";
5
+ };
6
+ export { TAG_NAME, ICON_NAME };
@@ -0,0 +1,7 @@
1
+ import utils from '../../utils/tag-name';
2
+ const TAG_NAME = utils.constructTagName('checkbox');
3
+ const ICON_NAME = {
4
+ CHECKED: 'check-bold',
5
+ INDETERMINATE: 'minus-bold',
6
+ };
7
+ export { TAG_NAME, ICON_NAME };
@@ -0,0 +1,2 @@
1
+ declare const styles: import("lit").CSSResult[];
2
+ export default styles;
@@ -0,0 +1,106 @@
1
+ import { css } from 'lit';
2
+ import { hostFocusRingStyles } from '../../utils/styles';
3
+ const styles = [css `
4
+ :host {
5
+ --mdc-checkbox-background-color-hover: var(--mds-color-theme-control-inactive-hover);
6
+ --mdc-checkbox-border-color: var(--mds-color-theme-outline-button-normal);
7
+ --mdc-checkbox-checked-background-color-hover: var(--mds-color-theme-control-active-hover);
8
+ --mdc-checkbox-checked-background-color: var(--mds-color-theme-control-active-normal);
9
+ --mdc-checkbox-checked-pressed-icon-color: var(--mds-color-theme-control-active-pressed);
10
+ --mdc-checkbox-disabled-background-color: var(--mds-color-theme-control-inactive-disabled);
11
+ --mdc-checkbox-disabled-border-color: var(--mds-color-theme-outline-primary-disabled);
12
+ --mdc-checkbox-disabled-checked-icon-color: var(--mds-color-theme-control-active-disabled);
13
+ --mdc-checkbox-disabled-icon-color: var(--mds-color-theme-text-primary-disabled);
14
+ --mdc-checkbox-icon-background-color: var(--mds-color-theme-control-inactive-normal);
15
+ --mdc-checkbox-icon-border-color: var(--mds-color-theme-outline-input-normal);
16
+ --mdc-checkbox-icon-color: var(--mds-color-theme-inverted-text-primary-normal);
17
+ --mdc-checkbox-pressed-icon-color: var(--mds-color-theme-control-inactive-pressed);
18
+
19
+ flex-direction: row;
20
+ align-items: flex-start;
21
+ }
22
+ .mdc-label, .input {
23
+ cursor: pointer;
24
+ }
25
+ :host([checked]) .icon-container,
26
+ :host([indeterminate]) .icon-container {
27
+ background: var(--mdc-checkbox-checked-background-color);
28
+ border: unset;
29
+ }
30
+ :host([checked]) .container:hover .icon-container,
31
+ :host([indeterminate]) .container:hover .icon-container {
32
+ background: var(--mdc-checkbox-checked-background-color-hover);
33
+ }
34
+ :host([checked]) .container:active .icon-container,
35
+ :host([indeterminate]) .container:active .icon-container {
36
+ background: var(--mdc-checkbox-checked-pressed-icon-color);
37
+ }
38
+ :host([disabled]) .mdc-label,
39
+ :host([disabled]) .input {
40
+ cursor: default;
41
+ }
42
+ :host([disabled]) .container:hover {
43
+ background: unset;
44
+ }
45
+ :host([disabled]) .icon-container {
46
+ border-color: var(--mdc-checkbox-disabled-border-color);
47
+ background: var(--mdc-checkbox-disabled-background-color);
48
+ }
49
+ :host([disabled]) .icon {
50
+ --mdc-icon-fill-color: var(--mdc-checkbox-disabled-icon-color);
51
+ }
52
+ :host([disabled][checked]) .icon-container,
53
+ :host([disabled][indeterminate]) .icon-container {
54
+ background: var(--mdc-checkbox-disabled-checked-icon-color);
55
+ border: 0.0625rem solid var(--mdc-checkbox-disabled-border-color);
56
+ }
57
+ .input {
58
+ margin: 0;
59
+ padding: 0;
60
+ position: absolute;
61
+ opacity: 0.1%;
62
+ overflow: visible;
63
+ z-index: 1;
64
+ }
65
+ .icon-container {
66
+ display: flex;
67
+ align-items: center;
68
+ border: 0.0625rem solid var(--mdc-checkbox-icon-border-color);
69
+ background: var(--mdc-checkbox-icon-background-color);
70
+ }
71
+ .container:hover {
72
+ background: var(--mdc-checkbox-background-color-hover);
73
+ }
74
+ .container:active {
75
+ background: var(--mdc-checkbox-pressed-icon-color);
76
+ }
77
+ .input, .icon-container {
78
+ width: 1rem;
79
+ height: 1rem;
80
+ }
81
+ .input,
82
+ .icon-container,
83
+ .container {
84
+ border-radius: 0.125rem;
85
+ }
86
+ .icon {
87
+ --mdc-icon-fill-color: var(--mdc-checkbox-icon-color);
88
+ }
89
+ .container {
90
+ margin: 0.125rem 0;
91
+ }
92
+ .text-container {
93
+ display: flex;
94
+ flex-direction: column;
95
+ gap: 0.25rem;
96
+ }
97
+
98
+ /* High Contrast Mode */
99
+ @media (forced-colors: active) {
100
+ :host([checked]) .icon-container,
101
+ :host([indeterminate]) .icon-container {
102
+ border: 0.0625rem solid var(--mdc-checkbox-border-color);
103
+ }
104
+ }
105
+ `, ...hostFocusRingStyles(true)];
106
+ export default styles;
@@ -0,0 +1,8 @@
1
+ import Checkbox from './checkbox.component';
2
+ import '../icon';
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ ['mdc-checkbox']: Checkbox;
6
+ }
7
+ }
8
+ export default Checkbox;
@@ -0,0 +1,5 @@
1
+ import Checkbox from './checkbox.component';
2
+ import { TAG_NAME } from './checkbox.constants';
3
+ import '../icon';
4
+ Checkbox.register(TAG_NAME);
5
+ export default Checkbox;