@momentum-design/components 0.28.1 → 0.28.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.
Files changed (35) hide show
  1. package/dist/browser/index.js +148 -122
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/components/buttonsimple/buttonsimple.component.d.ts +1 -7
  4. package/dist/components/buttonsimple/buttonsimple.component.js +6 -13
  5. package/dist/components/checkbox/checkbox.component.d.ts +26 -13
  6. package/dist/components/checkbox/checkbox.component.js +62 -22
  7. package/dist/components/formfieldgroup/formfieldgroup.component.js +2 -1
  8. package/dist/components/input/input.component.d.ts +59 -72
  9. package/dist/components/input/input.component.js +85 -100
  10. package/dist/components/radio/radio.component.d.ts +51 -36
  11. package/dist/components/radio/radio.component.js +126 -46
  12. package/dist/components/radio/radio.styles.js +4 -0
  13. package/dist/components/radiogroup/radiogroup.component.d.ts +7 -2
  14. package/dist/components/radiogroup/radiogroup.component.js +26 -3
  15. package/dist/components/themeprovider/themeprovider.component.d.ts +8 -0
  16. package/dist/components/themeprovider/themeprovider.component.js +8 -0
  17. package/dist/components/themeprovider/themeprovider.styles.js +12 -0
  18. package/dist/components/toggle/toggle.component.d.ts +43 -24
  19. package/dist/components/toggle/toggle.component.js +79 -31
  20. package/dist/components/toggle/toggle.constants.d.ts +1 -0
  21. package/dist/components/toggle/toggle.constants.js +1 -0
  22. package/dist/custom-elements.json +1343 -422
  23. package/dist/react/themeprovider/index.d.ts +8 -0
  24. package/dist/react/themeprovider/index.js +8 -0
  25. package/dist/utils/mixins/FormInternalsMixin.d.ts +38 -0
  26. package/dist/utils/mixins/FormInternalsMixin.js +79 -0
  27. package/package.json +1 -1
  28. package/dist/utils/mixins/NameMixin.d.ts +0 -6
  29. package/dist/utils/mixins/NameMixin.js +0 -29
  30. package/dist/utils/mixins/ReadonlyMixin.d.ts +0 -6
  31. package/dist/utils/mixins/ReadonlyMixin.js +0 -29
  32. package/dist/utils/mixins/RequiredMixin.d.ts +0 -6
  33. package/dist/utils/mixins/RequiredMixin.js +0 -29
  34. package/dist/utils/mixins/ValueMixin.d.ts +0 -6
  35. package/dist/utils/mixins/ValueMixin.js +0 -28
@@ -8,16 +8,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { html, nothing } from 'lit';
11
- import { property, query } from 'lit/decorators.js';
11
+ import { property } from 'lit/decorators.js';
12
12
  import { ifDefined } from 'lit/directives/if-defined.js';
13
- import { v4 as uuidv4 } from 'uuid';
14
13
  import styles from './input.styles';
15
14
  import FormfieldWrapper from '../formfieldwrapper';
16
- import { NameMixin } from '../../utils/mixins/NameMixin';
17
15
  import { AUTO_CAPITALIZE, DEFAULTS, PREFIX_TEXT_OPTIONS } from './input.constants';
18
16
  import { DEFAULTS as FORMFIELD_DEFAULTS } from '../formfieldwrapper/formfieldwrapper.constants';
19
- import { ValueMixin } from '../../utils/mixins/ValueMixin';
20
17
  import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
18
+ import { FormInternalsMixin } from '../../utils/mixins/FormInternalsMixin';
21
19
  /**
22
20
  * mdc-input is a component that allows users to input text.
23
21
  * It contains:
@@ -59,21 +57,9 @@ import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
59
57
  * @cssproperty --mdc-input-primary-border-color - Border color for the input container when primary
60
58
  *
61
59
  */
62
- class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper))) {
63
- checkValidity() {
64
- this.setValidityFromInput();
65
- return this.internals.checkValidity();
66
- }
67
- reportValidity() {
68
- this.setValidityFromInput();
69
- return this.internals.reportValidity();
70
- }
71
- /** @internal */
72
- get form() {
73
- return this.internals.form;
74
- }
60
+ class Input extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
75
61
  constructor() {
76
- super();
62
+ super(...arguments);
77
63
  /**
78
64
  * The placeholder text that is displayed when the input field is empty.
79
65
  */
@@ -107,16 +93,13 @@ class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper)))
107
93
  * @default ''
108
94
  */
109
95
  this.clearAriaLabel = '';
110
- /** @internal */
111
- this.internals = this.attachInternals();
112
- this.id = `mdc-input-${uuidv4()}`;
113
96
  }
114
97
  connectedCallback() {
115
98
  super.connectedCallback();
116
99
  this.updateComplete.then(() => {
117
100
  if (this.inputElement) {
118
101
  this.inputElement.checkValidity();
119
- this.setValidityFromInput();
102
+ this.setInputValidity();
120
103
  this.internals.setFormValue(this.inputElement.value);
121
104
  }
122
105
  }).catch((error) => {
@@ -125,35 +108,52 @@ class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper)))
125
108
  }
126
109
  });
127
110
  }
128
- updated(changedProperties) {
129
- super.updated(changedProperties);
130
- if (changedProperties.has('value')) {
131
- this.handleValueChange();
132
- }
111
+ /** @internal */
112
+ formResetCallback() {
113
+ this.value = '';
114
+ this.requestUpdate();
115
+ }
116
+ /** @internal */
117
+ formStateRestoreCallback(state) {
118
+ this.value = state;
133
119
  }
134
120
  /**
135
- * Handles the value change of the input field.
136
- * Sets the form value and updates the validity of the input field.
137
- * @returns void
138
- */
121
+ * Handles the value change of the input field.
122
+ * Sets the form value and updates the validity of the input field.
123
+ * @returns void
124
+ */
139
125
  handleValueChange() {
140
- this.internals.setFormValue(this.value);
141
126
  this.updateComplete.then(() => {
142
- this.setValidityFromInput();
127
+ this.setInputValidity();
143
128
  }).catch((error) => {
144
129
  if (this.onerror) {
145
130
  this.onerror(error);
146
131
  }
147
132
  });
148
133
  }
134
+ updated(changedProperties) {
135
+ super.updated(changedProperties);
136
+ if (changedProperties.has('value')) {
137
+ this.handleValueChange();
138
+ }
139
+ }
140
+ setInputValidity() {
141
+ if (this.validationMessage && this.value === '') {
142
+ this.inputElement.setCustomValidity(this.validationMessage);
143
+ }
144
+ else {
145
+ this.inputElement.setCustomValidity('');
146
+ }
147
+ this.setValidity();
148
+ }
149
149
  /**
150
- * This function is called when the attribute changes.
151
- * It updates the validity of the input field based on the input field's validity.
152
- *
153
- * @param name - attribute name
154
- * @param old - old value
155
- * @param value - new value
156
- */
150
+ * This function is called when the attribute changes.
151
+ * It updates the validity of the input field based on the input field's validity.
152
+ *
153
+ * @param name - attribute name
154
+ * @param old - old value
155
+ * @param value - new value
156
+ */
157
157
  attributeChangedCallback(name, old, value) {
158
158
  super.attributeChangedCallback(name, old, value);
159
159
  const validationRelatedAttributes = [
@@ -164,7 +164,7 @@ class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper)))
164
164
  ];
165
165
  if (validationRelatedAttributes.includes(name)) {
166
166
  this.updateComplete.then(() => {
167
- this.setValidityFromInput();
167
+ this.setInputValidity();
168
168
  }).catch((error) => {
169
169
  if (this.onerror) {
170
170
  this.onerror(error);
@@ -173,65 +173,56 @@ class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper)))
173
173
  }
174
174
  }
175
175
  /**
176
- * Sets the validity of the input field based on the input field's validity.
177
- * @returns void
178
- */
179
- setValidityFromInput() {
180
- if (this.inputElement) {
181
- this.internals.setValidity(this.inputElement.validity, this.inputElement.validationMessage, this.inputElement);
182
- }
183
- }
184
- /**
185
- * Updates the value of the input field.
186
- * Sets the form value.
187
- * @returns void
188
- */
176
+ * Updates the value of the input field.
177
+ * Sets the form value.
178
+ * @returns void
179
+ */
189
180
  updateValue() {
190
181
  this.value = this.inputElement.value;
191
182
  this.internals.setFormValue(this.inputElement.value);
192
183
  }
193
184
  /**
194
- * Handles the input event of the input field.
195
- * Updates the value and sets the validity of the input field.
196
- *
197
- */
185
+ * Handles the input event of the input field.
186
+ * Updates the value and sets the validity of the input field.
187
+ *
188
+ */
198
189
  onInput() {
199
190
  this.updateValue();
200
- this.setValidityFromInput();
191
+ this.setInputValidity();
201
192
  }
202
193
  /**
203
- * Handles the change event of the input field.
204
- * Updates the value and sets the validity of the input field.
205
- *
206
- * The 'change' event does not bubble up through the shadow DOM as it was not composed.
207
- * Therefore, we need to re-dispatch the same event to ensure it is propagated correctly.
208
- * Read more: https://developer.mozilla.org/en-US/docs/Web/API/Event/composed
209
- *
210
- * @param event - Event which contains information about the value change.
211
- */
194
+ * Handles the change event of the input field.
195
+ * Updates the value and sets the validity of the input field.
196
+ *
197
+ * The 'change' event does not bubble up through the shadow DOM as it was not composed.
198
+ * Therefore, we need to re-dispatch the same event to ensure it is propagated correctly.
199
+ * Read more: https://developer.mozilla.org/en-US/docs/Web/API/Event/composed
200
+ *
201
+ * @param event - Event which contains information about the value change.
202
+ */
212
203
  onChange(event) {
213
204
  this.updateValue();
214
- this.setValidityFromInput();
205
+ this.setInputValidity();
215
206
  const EventConstructor = event.constructor;
216
207
  this.dispatchEvent(new EventConstructor(event.type, event));
217
208
  }
218
209
  /**
219
- * Handles the keydown event of the input field.
220
- * If the key pressed is 'Enter', it submits the form.
221
- * @param event - Keyboard event
222
- */
210
+ * Handles the keydown event of the input field.
211
+ * If the key pressed is 'Enter', it submits the form.
212
+ * @param event - Keyboard event
213
+ */
223
214
  handleKeyDown(event) {
224
215
  var _a;
225
216
  if (event.key === 'Enter') {
226
- (_a = this.internals.form) === null || _a === void 0 ? void 0 : _a.requestSubmit();
217
+ (_a = this.form) === null || _a === void 0 ? void 0 : _a.requestSubmit();
227
218
  }
228
219
  }
229
220
  /**
230
- * Renders the leading icon before the input field.
231
- * If the leading icon is not set, it will not be displayed.
232
- *
233
- * @returns void
234
- */
221
+ * Renders the leading icon before the input field.
222
+ * If the leading icon is not set, it will not be displayed.
223
+ *
224
+ * @returns void
225
+ */
235
226
  renderLeadingIcon() {
236
227
  if (!this.leadingIcon) {
237
228
  return nothing;
@@ -247,15 +238,15 @@ class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper)))
247
238
  `;
248
239
  }
249
240
  /**
250
- * Renders the prefix text before the input field.
251
- * If the prefix text is more than 10 characters,
252
- * - it will not be displayed.
253
- * - the validation messsage will be displayed.
254
- *
255
- * Note: We are setting aria-hidden so that the screen reader does not read the prefix text.
256
- * The consumers should set the appropriate aria-label for the input field using 'data-aria-label' attribute.
257
- * @returns void
258
- */
241
+ * Renders the prefix text before the input field.
242
+ * If the prefix text is more than 10 characters,
243
+ * - it will not be displayed.
244
+ * - the validation messsage will be displayed.
245
+ *
246
+ * Note: We are setting aria-hidden so that the screen reader does not read the prefix text.
247
+ * The consumers should set the appropriate aria-label for the input field using 'data-aria-label' attribute.
248
+ * @returns void
249
+ */
259
250
  renderPrefixText() {
260
251
  if (!this.prefixText) {
261
252
  return nothing;
@@ -272,8 +263,8 @@ class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper)))
272
263
  `;
273
264
  }
274
265
  /**
275
- * Clears the input field.
276
- */
266
+ * Clears the input field.
267
+ */
277
268
  clearInputText() {
278
269
  var _a;
279
270
  this.value = '';
@@ -281,9 +272,9 @@ class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper)))
281
272
  (_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.focus();
282
273
  }
283
274
  /**
284
- * Renders the trailing button to clear the input field if the trailingButton is set to true.
285
- * @returns void
286
- */
275
+ * Renders the trailing button to clear the input field if the trailingButton is set to true.
276
+ * @returns void
277
+ */
287
278
  renderTrailingButton() {
288
279
  if (!this.trailingButton) {
289
280
  return nothing;
@@ -321,7 +312,7 @@ class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper)))
321
312
  ?readonly="${this.readonly}"
322
313
  ?required="${!!this.requiredLabel}"
323
314
  type="text"
324
- aria-describedby="${FORMFIELD_DEFAULTS.HELPER_TEXT_ID}"
315
+ aria-describedby="${ifDefined(this.helpText ? FORMFIELD_DEFAULTS.HELPER_TEXT_ID : '')}"
325
316
  placeholder=${ifDefined(this.placeholder)}
326
317
  minlength=${ifDefined(this.minlength)}
327
318
  maxlength=${ifDefined(this.maxlength)}
@@ -344,8 +335,6 @@ class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper)))
344
335
  `;
345
336
  }
346
337
  }
347
- /** @internal */
348
- Input.formAssociated = true;
349
338
  Input.styles = [...FormfieldWrapper.styles, ...styles];
350
339
  __decorate([
351
340
  property({ type: String }),
@@ -407,8 +396,4 @@ __decorate([
407
396
  property({ type: String, attribute: 'clear-aria-label' }),
408
397
  __metadata("design:type", Object)
409
398
  ], Input.prototype, "clearAriaLabel", void 0);
410
- __decorate([
411
- query('input'),
412
- __metadata("design:type", HTMLInputElement)
413
- ], Input.prototype, "inputElement", void 0);
414
399
  export default Input;
@@ -1,6 +1,7 @@
1
1
  import { CSSResult, PropertyValues } from 'lit';
2
2
  import FormfieldWrapper from '../formfieldwrapper/formfieldwrapper.component';
3
- declare const Radio_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;
3
+ import { AssociatedFormControl } from '../../utils/mixins/FormInternalsMixin';
4
+ declare const Radio_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/FormInternalsMixin").FormInternalsMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & typeof FormfieldWrapper;
4
5
  /**
5
6
  * Radio allow users to select single options from a list or turn an item/feature on or off.
6
7
  * These are often used in forms, settings, and selection in lists.
@@ -31,7 +32,7 @@ declare const Radio_base: import("../../utils/mixins/index.types").Constructor<i
31
32
  * when active and disabled
32
33
  *
33
34
  */
34
- declare class Radio extends Radio_base {
35
+ declare class Radio extends Radio_base implements AssociatedFormControl {
35
36
  /**
36
37
  * Determines whether the radio is selected or unselected.
37
38
  *
@@ -44,54 +45,68 @@ declare class Radio extends Radio_base {
44
45
  * @default false
45
46
  */
46
47
  readonly: boolean;
47
- /** @internal */
48
- private internals;
49
- /** @internal */
50
- static formAssociated: boolean;
51
- /** @internal */
52
- get form(): HTMLFormElement | null;
53
- constructor();
54
48
  /**
55
- * Updates the form value to reflect the current state of the radio.
56
- * If checked, the value is set to the user-provided value.
57
- * If unchecked, the value is set to null.
58
- */
59
- private setFormValue;
49
+ * Automatically focus on the element when the page loads.
50
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus)
51
+ * @default false
52
+ */
53
+ autofocus: boolean;
54
+ constructor();
60
55
  firstUpdated(): void;
61
56
  /**
62
- * Returns all radios within the same group (name).
63
- */
57
+ * Returns all radios within the same group (name).
58
+ */
64
59
  private getAllRadiosWithinSameGroup;
65
60
  /**
66
- * The 'change' event does not bubble up through the shadow DOM as it was not composed.
67
- * Therefore, we need to re-dispatch the same event to ensure it is propagated correctly.
68
- * Read more: https://developer.mozilla.org/en-US/docs/Web/API/Event/composed
69
- */
61
+ * The 'change' event does not bubble up through the shadow DOM as it was not composed.
62
+ * Therefore, we need to re-dispatch the same event to ensure it is propagated correctly.
63
+ * Read more: https://developer.mozilla.org/en-US/docs/Web/API/Event/composed
64
+ */
70
65
  private dispatchChangeEvent;
66
+ /** @internal */
67
+ formResetCallback(): void;
68
+ /** @internal */
69
+ formStateRestoreCallback(state: string): void;
71
70
  /**
72
- * Handles the change event on the radio element.
73
- * This will toggle the state of the radio element.
74
- * Dispatches the change event.
71
+ * @internal
72
+ */
73
+ setComponentValidity(isValid: boolean): void;
74
+ /**
75
+ * Sets the validity of the group of radios.
76
+ * @param radios - Array of radios of the same group
77
+ * @param isValid - Boolean value to set the validity of the group
75
78
  */
79
+ private setGroupValidity;
80
+ /**
81
+ * Updates the form value to reflect the current state of the radio.
82
+ * If checked, the value is set to the user-provided value.
83
+ * If unchecked, the value is set to null.
84
+ */
85
+ private setActualFormValue;
86
+ /**
87
+ * Handles the change event on the radio element.
88
+ * This will toggle the state of the radio element.
89
+ * Dispatches the change event.
90
+ */
76
91
  private handleChange;
77
92
  /**
78
- * Updates the state of the radio button at the specified index within the enabled radios.
79
- * Focuses the radio button and triggers the change event if the radio button is not read-only.
80
- *
81
- * @param enabledRadios - An array of enabled radio buttons within the same group.
82
- * @param index - The index of the radio button to be updated within the enabled radios array.
83
- * @param event - The event that triggered the update.
84
- */
93
+ * Updates the state of the radio button at the specified index within the enabled radios.
94
+ * Focuses the radio button and triggers the change event if the radio button is not read-only.
95
+ *
96
+ * @param enabledRadios - An array of enabled radio buttons within the same group.
97
+ * @param index - The index of the radio button to be updated within the enabled radios array.
98
+ * @param event - The event that triggered the update.
99
+ */
85
100
  private updateRadio;
86
101
  /**
87
- * Handles the keydown event (Arrow Up/Down/Left/Right) on the radio element.
88
- */
102
+ * Handles the keydown event (Arrow Up/Down/Left/Right) on the radio element.
103
+ */
89
104
  private handleKeyDown;
90
105
  /**
91
- * Update tab index for all radios in the same group (name)
92
- * If any radio group is checked, it will have a tab index of 0
93
- * If no radio group is checked, the first enabled radio will have a tab index of 0
94
- */
106
+ * Update tab index for all radios in the same group (name)
107
+ * If any radio group is checked, it will have a tab index of 0
108
+ * If no radio group is checked, the first enabled radio will have a tab index of 0
109
+ */
95
110
  private updateTabIndex;
96
111
  update(changedProperties: PropertyValues): void;
97
112
  render(): import("lit-html").TemplateResult<1>;