@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
@@ -10,14 +10,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { html } from 'lit';
11
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 './toggle.styles';
15
14
  import FormfieldWrapper from '../formfieldwrapper';
16
- import { ValueMixin } from '../../utils/mixins/ValueMixin';
17
- import { NameMixin } from '../../utils/mixins/NameMixin';
18
15
  import { DEFAULTS as FORMFIELD_DEFAULTS } from '../formfieldwrapper/formfieldwrapper.constants';
19
16
  import { DEFAULTS, ICON_NAME, ICON_SIZE_IN_REM, TOGGLE_SIZE } from './toggle.constants';
20
17
  import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
18
+ import { FormInternalsMixin } from '../../utils/mixins/FormInternalsMixin';
21
19
  /**
22
20
  * Toggle Component is an interactive control used to switch between two mutually exclusive options,
23
21
  * such as On/Off, Active/Inactive. These are commonly used in settings panels, forms, and preference selections
@@ -54,11 +52,7 @@ import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
54
52
  * @cssproperty --mdc-toggle-label-color-disabled - color of the toggle label and help text in disabled state
55
53
  *
56
54
  */
57
- class Toggle extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper))) {
58
- /** @internal */
59
- get form() {
60
- return this.internals.form;
61
- }
55
+ class Toggle extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
62
56
  constructor() {
63
57
  super();
64
58
  /**
@@ -73,50 +67,98 @@ class Toggle extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)))
73
67
  * @default default
74
68
  */
75
69
  this.size = DEFAULTS.SIZE;
76
- /** @internal */
77
- this.internals = this.attachInternals();
70
+ /**
71
+ * Automatically focus on the element when the page loads.
72
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus)
73
+ * @default false
74
+ */
75
+ this.autofocus = false;
78
76
  // Toggle does not contain helpTextType property.
79
77
  this.helpTextType = undefined;
80
- this.id = `mdc-input-${uuidv4()}`;
78
+ }
79
+ /** @internal
80
+ * Resets the checkbox to its initial state.
81
+ * The checked property is set to false.
82
+ */
83
+ formResetCallback() {
84
+ this.checked = false;
85
+ }
86
+ /** @internal */
87
+ formStateRestoreCallback(state) {
88
+ if (state) {
89
+ this.checked = true;
90
+ }
91
+ }
92
+ /**
93
+ * Manages the required state of the checkbox.
94
+ * If the checkbox is not checked and the requiredLabel property is set, then the checkbox is invalid.
95
+ */
96
+ manageRequired() {
97
+ if (!this.checked && this.requiredLabel) {
98
+ if (this.validationMessage) {
99
+ this.inputElement.setCustomValidity(this.validationMessage);
100
+ }
101
+ else {
102
+ this.inputElement.setCustomValidity('');
103
+ }
104
+ this.setValidity();
105
+ }
106
+ else {
107
+ this.internals.setValidity({});
108
+ }
81
109
  }
82
110
  /**
83
- * Updates the form value to reflect the current state of the toggle.
84
- * If toggle is switched on, the value is set to either the user-provided value or 'isActive' if no value is provided.
85
- * If toggle is switched off, the value is set to null.
86
- */
111
+ * Updates the form value to reflect the current state of the toggle.
112
+ * If toggle is switched on, the value is set to either the user-provided value or 'isActive' if no value is provided.
113
+ * If toggle is switched off, the value is set to null.
114
+ */
87
115
  setFormValue() {
88
116
  let actualValue = null;
89
117
  if (this.checked) {
90
118
  actualValue = !this.value ? 'isActive' : this.value;
91
119
  }
120
+ else {
121
+ actualValue = null;
122
+ }
123
+ this.manageRequired();
92
124
  this.internals.setFormValue(actualValue);
93
125
  }
94
126
  /**
95
- * Toggles the state of the toggle element.
96
- * If the element is not disabled, then the checked property is toggled.
97
- */
127
+ * Toggles the state of the toggle element.
128
+ * If the element is not disabled, then the checked property is toggled.
129
+ */
98
130
  toggleState() {
99
131
  if (!this.disabled) {
100
132
  this.checked = !this.checked;
101
133
  }
102
134
  }
103
135
  /**
104
- * Toggles the state of the toggle element.
105
- * and dispatch the new change event.
106
- */
136
+ * Handles the keydown event on the toggle element.
137
+ * When the user presses Enter, the form is submitted.
138
+ * @param event - The keyboard event.
139
+ */
140
+ handleKeyDown(event) {
141
+ var _a;
142
+ if (event.key === 'Enter') {
143
+ (_a = this.form) === null || _a === void 0 ? void 0 : _a.requestSubmit();
144
+ }
145
+ }
146
+ /**
147
+ * Toggles the state of the toggle element.
148
+ * and dispatch the new change event.
149
+ */
107
150
  handleChange(event) {
108
151
  this.toggleState();
109
- // Re-dispatch the existing event instead of creating a new one since change event doesn't bubble out of shadow dom
110
152
  const EventConstructor = event.constructor;
111
153
  this.dispatchEvent(new EventConstructor(event.type, event));
112
154
  }
113
155
  /**
114
- * Sets the size attribute for the toggle component.
115
- * If the provided size is not included in the TOGGLE_SIZE,
116
- * it defaults to the value specified in DEFAULTS.SIZE.
117
- *
118
- * @param size - The size to set.
119
- */
156
+ * Sets the size attribute for the toggle component.
157
+ * If the provided size is not included in the TOGGLE_SIZE,
158
+ * it defaults to the value specified in DEFAULTS.SIZE.
159
+ *
160
+ * @param size - The size to set.
161
+ */
120
162
  setToggleSize(size) {
121
163
  this.setAttribute('size', Object.values(TOGGLE_SIZE).includes(size) ? size : DEFAULTS.SIZE);
122
164
  }
@@ -138,14 +180,18 @@ class Toggle extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)))
138
180
  type="checkbox"
139
181
  class="mdc-toggle__input"
140
182
  role="switch"
183
+ ?autofocus="${this.autofocus}"
184
+ ?required="${!!this.requiredLabel}"
141
185
  name="${ifDefined(this.name)}"
142
186
  value="${ifDefined(this.value)}"
143
187
  .checked="${this.checked}"
188
+ aria-checked="${this.checked}"
144
189
  .disabled="${this.disabled}"
145
- aria-describedby="${FORMFIELD_DEFAULTS.HELPER_TEXT_ID}"
190
+ aria-describedby="${ifDefined(this.helpText ? FORMFIELD_DEFAULTS.HELPER_TEXT_ID : '')}"
146
191
  aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
147
192
  tabindex="${this.disabled ? -1 : 0}"
148
193
  @change="${this.handleChange}"
194
+ @keydown="${this.handleKeyDown}"
149
195
  />
150
196
  <div class="mdc-toggle__slider">
151
197
  <mdc-icon
@@ -161,8 +207,6 @@ class Toggle extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)))
161
207
  `;
162
208
  }
163
209
  }
164
- /** @internal */
165
- Toggle.formAssociated = true;
166
210
  Toggle.styles = [...FormfieldWrapper.styles, ...styles];
167
211
  __decorate([
168
212
  property({ type: Boolean, reflect: true }),
@@ -172,4 +216,8 @@ __decorate([
172
216
  property({ type: String, reflect: true }),
173
217
  __metadata("design:type", String)
174
218
  ], Toggle.prototype, "size", void 0);
219
+ __decorate([
220
+ property({ type: Boolean, reflect: true }),
221
+ __metadata("design:type", Object)
222
+ ], Toggle.prototype, "autofocus", void 0);
175
223
  export default Toggle;
@@ -13,5 +13,6 @@ declare const ICON_SIZE_IN_REM: {
13
13
  };
14
14
  declare const DEFAULTS: {
15
15
  readonly SIZE: "default";
16
+ readonly VALIDATION_MESSAGE: "Please toggle this switch if you want to proceed.";
16
17
  };
17
18
  export { TAG_NAME, DEFAULTS, TOGGLE_SIZE, ICON_NAME, ICON_SIZE_IN_REM };
@@ -14,5 +14,6 @@ const ICON_SIZE_IN_REM = {
14
14
  };
15
15
  const DEFAULTS = {
16
16
  SIZE: TOGGLE_SIZE.DEFAULT,
17
+ VALIDATION_MESSAGE: 'Please toggle this switch if you want to proceed.',
17
18
  };
18
19
  export { TAG_NAME, DEFAULTS, TOGGLE_SIZE, ICON_NAME, ICON_SIZE_IN_REM };