@devschile/chucao 1.8.0 → 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.
Files changed (158) hide show
  1. package/README.md +3 -0
  2. package/dist/chucao/chucao.esm.js +1 -1
  3. package/dist/chucao/chucao.esm.js.map +1 -1
  4. package/dist/chucao/{p-e8fe65bb.entry.js → p-04dbcfa0.entry.js} +2 -2
  5. package/dist/chucao/p-11083711.entry.js +2 -0
  6. package/dist/chucao/p-11083711.entry.js.map +1 -0
  7. package/dist/chucao/{p-cfb6db53.entry.js → p-121fbfc8.entry.js} +2 -2
  8. package/dist/chucao/p-1b1e56cd.entry.js +2 -0
  9. package/dist/chucao/p-1b1e56cd.entry.js.map +1 -0
  10. package/dist/chucao/{p-df73f786.entry.js → p-2ab4a6a8.entry.js} +2 -2
  11. package/dist/chucao/p-4bc8e098.entry.js +2 -0
  12. package/dist/chucao/p-4bc8e098.entry.js.map +1 -0
  13. package/dist/chucao/p-5fe8bfff.entry.js +2 -0
  14. package/dist/chucao/p-5fe8bfff.entry.js.map +1 -0
  15. package/dist/chucao/p-9bb81a65.entry.js +2 -0
  16. package/dist/chucao/p-9bb81a65.entry.js.map +1 -0
  17. package/dist/chucao/p-DWC12BJ-.js +3 -0
  18. package/dist/chucao/p-DWC12BJ-.js.map +1 -0
  19. package/dist/chucao/{p-2d7e81b2.entry.js → p-a955eebf.entry.js} +2 -2
  20. package/dist/chucao/{p-cbb2b478.entry.js → p-d5a9e340.entry.js} +2 -2
  21. package/dist/chucao/{p-1cc7042e.entry.js → p-ff5f5c1f.entry.js} +2 -2
  22. package/dist/cjs/ch-accordion.cjs.entry.js +1 -1
  23. package/dist/cjs/ch-alert_8.cjs.entry.js +186 -9
  24. package/dist/cjs/ch-alert_8.cjs.entry.js.map +1 -1
  25. package/dist/cjs/ch-checkbox.cjs.entry.js +62 -3
  26. package/dist/cjs/ch-checkbox.cjs.entry.js.map +1 -1
  27. package/dist/cjs/ch-divider.cjs.entry.js +1 -1
  28. package/dist/cjs/ch-emoji.cjs.entry.js +104 -0
  29. package/dist/cjs/ch-emoji.cjs.entry.js.map +1 -0
  30. package/dist/cjs/ch-link.cjs.entry.js +1 -1
  31. package/dist/cjs/ch-modal.cjs.entry.js +2 -2
  32. package/dist/cjs/ch-radio.cjs.entry.js +62 -3
  33. package/dist/cjs/ch-radio.cjs.entry.js.map +1 -1
  34. package/dist/cjs/ch-tabs.cjs.entry.js +2 -2
  35. package/dist/cjs/ch-textarea.cjs.entry.js +62 -3
  36. package/dist/cjs/ch-textarea.cjs.entry.js.map +1 -1
  37. package/dist/cjs/ch-tooltip.cjs.entry.js +2 -2
  38. package/dist/cjs/chucao.cjs.js +3 -3
  39. package/dist/cjs/chucao.cjs.js.map +1 -1
  40. package/dist/cjs/{index-DMeDkSQU.js → index-C9cpLteP.js} +71 -12
  41. package/dist/cjs/index-C9cpLteP.js.map +1 -0
  42. package/dist/cjs/loader.cjs.js +2 -2
  43. package/dist/collection/collection-manifest.json +2 -1
  44. package/dist/collection/components/ch-card/ch-card.js +1 -1
  45. package/dist/collection/components/ch-checkbox/ch-checkbox.css +10 -0
  46. package/dist/collection/components/ch-checkbox/ch-checkbox.js +64 -4
  47. package/dist/collection/components/ch-checkbox/ch-checkbox.js.map +1 -1
  48. package/dist/collection/components/ch-emoji/ch-emoji.css +33 -0
  49. package/dist/collection/components/ch-emoji/ch-emoji.js +151 -0
  50. package/dist/collection/components/ch-emoji/ch-emoji.js.map +1 -0
  51. package/dist/collection/components/ch-input/ch-input.css +11 -0
  52. package/dist/collection/components/ch-input/ch-input.js +64 -4
  53. package/dist/collection/components/ch-input/ch-input.js.map +1 -1
  54. package/dist/collection/components/ch-modal/ch-modal.js +1 -1
  55. package/dist/collection/components/ch-radio/ch-radio.css +10 -0
  56. package/dist/collection/components/ch-radio/ch-radio.js +64 -4
  57. package/dist/collection/components/ch-radio/ch-radio.js.map +1 -1
  58. package/dist/collection/components/ch-select/ch-select.css +11 -0
  59. package/dist/collection/components/ch-select/ch-select.js +64 -4
  60. package/dist/collection/components/ch-select/ch-select.js.map +1 -1
  61. package/dist/collection/components/ch-spinner/ch-spinner.js +1 -1
  62. package/dist/collection/components/ch-switch/ch-switch.css +10 -0
  63. package/dist/collection/components/ch-switch/ch-switch.js +64 -4
  64. package/dist/collection/components/ch-switch/ch-switch.js.map +1 -1
  65. package/dist/collection/components/ch-tabs/ch-tabs.js +1 -1
  66. package/dist/collection/components/ch-textarea/ch-textarea.css +11 -0
  67. package/dist/collection/components/ch-textarea/ch-textarea.js +64 -4
  68. package/dist/collection/components/ch-textarea/ch-textarea.js.map +1 -1
  69. package/dist/collection/components/ch-tooltip/ch-tooltip.js +1 -1
  70. package/dist/components/ch-accordion.js +1 -1
  71. package/dist/components/ch-alert.js +1 -1
  72. package/dist/components/ch-badge.js +1 -1
  73. package/dist/components/ch-button.js +1 -1
  74. package/dist/components/ch-card.js +1 -1
  75. package/dist/components/ch-checkbox.js +1 -1
  76. package/dist/components/ch-checkbox.js.map +1 -1
  77. package/dist/components/ch-divider.js +1 -1
  78. package/dist/components/ch-emoji.d.ts +11 -0
  79. package/dist/components/ch-emoji.js +2 -0
  80. package/dist/components/ch-emoji.js.map +1 -0
  81. package/dist/components/ch-input.js +1 -1
  82. package/dist/components/ch-input.js.map +1 -1
  83. package/dist/components/ch-link.js +1 -1
  84. package/dist/components/ch-modal.js +1 -1
  85. package/dist/components/ch-radio.js +1 -1
  86. package/dist/components/ch-radio.js.map +1 -1
  87. package/dist/components/ch-select.js +1 -1
  88. package/dist/components/ch-select.js.map +1 -1
  89. package/dist/components/ch-spinner.js +1 -1
  90. package/dist/components/ch-switch.js +1 -1
  91. package/dist/components/ch-switch.js.map +1 -1
  92. package/dist/components/ch-tabs.js +1 -1
  93. package/dist/components/ch-textarea.js +1 -1
  94. package/dist/components/ch-textarea.js.map +1 -1
  95. package/dist/components/ch-tooltip.js +1 -1
  96. package/dist/components/index.js +1 -1
  97. package/dist/components/p-BhAZrOxf.js +2 -0
  98. package/dist/components/p-BhAZrOxf.js.map +1 -0
  99. package/dist/esm/ch-accordion.entry.js +1 -1
  100. package/dist/esm/ch-alert_8.entry.js +186 -9
  101. package/dist/esm/ch-alert_8.entry.js.map +1 -1
  102. package/dist/esm/ch-checkbox.entry.js +62 -3
  103. package/dist/esm/ch-checkbox.entry.js.map +1 -1
  104. package/dist/esm/ch-divider.entry.js +1 -1
  105. package/dist/esm/ch-emoji.entry.js +102 -0
  106. package/dist/esm/ch-emoji.entry.js.map +1 -0
  107. package/dist/esm/ch-link.entry.js +1 -1
  108. package/dist/esm/ch-modal.entry.js +2 -2
  109. package/dist/esm/ch-radio.entry.js +62 -3
  110. package/dist/esm/ch-radio.entry.js.map +1 -1
  111. package/dist/esm/ch-tabs.entry.js +2 -2
  112. package/dist/esm/ch-textarea.entry.js +62 -3
  113. package/dist/esm/ch-textarea.entry.js.map +1 -1
  114. package/dist/esm/ch-tooltip.entry.js +2 -2
  115. package/dist/esm/chucao.js +4 -4
  116. package/dist/esm/chucao.js.map +1 -1
  117. package/dist/esm/{index-Bvah_WQV.js → index-DWC12BJ-.js} +71 -12
  118. package/dist/esm/index-DWC12BJ-.js.map +1 -0
  119. package/dist/esm/loader.js +3 -3
  120. package/dist/types/components/ch-checkbox/ch-checkbox.d.ts +9 -0
  121. package/dist/types/components/ch-emoji/ch-emoji.d.ts +32 -0
  122. package/dist/types/components/ch-input/ch-input.d.ts +9 -0
  123. package/dist/types/components/ch-radio/ch-radio.d.ts +9 -0
  124. package/dist/types/components/ch-select/ch-select.d.ts +9 -0
  125. package/dist/types/components/ch-switch/ch-switch.d.ts +9 -0
  126. package/dist/types/components/ch-textarea/ch-textarea.d.ts +9 -0
  127. package/dist/types/components.d.ts +96 -0
  128. package/dist/types/stencil-public-runtime.d.ts +1 -0
  129. package/dist-react/components.d.ts +3 -0
  130. package/dist-react/components.js +9 -0
  131. package/dist-react/components.ts +12 -0
  132. package/dist-vue/index.d.ts +1 -0
  133. package/dist-vue/index.js +6 -0
  134. package/dist-vue/index.ts +8 -0
  135. package/hydrate/index.js +555 -63
  136. package/hydrate/index.mjs +555 -63
  137. package/loader/index.d.ts +1 -1
  138. package/package.json +5 -1
  139. package/dist/chucao/p-13ab5f9a.entry.js +0 -2
  140. package/dist/chucao/p-13ab5f9a.entry.js.map +0 -1
  141. package/dist/chucao/p-23c5220b.entry.js +0 -2
  142. package/dist/chucao/p-23c5220b.entry.js.map +0 -1
  143. package/dist/chucao/p-421cda05.entry.js +0 -2
  144. package/dist/chucao/p-421cda05.entry.js.map +0 -1
  145. package/dist/chucao/p-Bvah_WQV.js +0 -3
  146. package/dist/chucao/p-Bvah_WQV.js.map +0 -1
  147. package/dist/chucao/p-c16b18b7.entry.js +0 -2
  148. package/dist/chucao/p-c16b18b7.entry.js.map +0 -1
  149. package/dist/cjs/index-DMeDkSQU.js.map +0 -1
  150. package/dist/components/p-hyy-cLgi.js +0 -2
  151. package/dist/components/p-hyy-cLgi.js.map +0 -1
  152. package/dist/esm/index-Bvah_WQV.js.map +0 -1
  153. /package/dist/chucao/{p-e8fe65bb.entry.js.map → p-04dbcfa0.entry.js.map} +0 -0
  154. /package/dist/chucao/{p-cfb6db53.entry.js.map → p-121fbfc8.entry.js.map} +0 -0
  155. /package/dist/chucao/{p-df73f786.entry.js.map → p-2ab4a6a8.entry.js.map} +0 -0
  156. /package/dist/chucao/{p-2d7e81b2.entry.js.map → p-a955eebf.entry.js.map} +0 -0
  157. /package/dist/chucao/{p-cbb2b478.entry.js.map → p-d5a9e340.entry.js.map} +0 -0
  158. /package/dist/chucao/{p-1cc7042e.entry.js.map → p-ff5f5c1f.entry.js.map} +0 -0
@@ -5,6 +5,10 @@ export class ChRadio {
5
5
  labelId = `${this.groupId}-label`;
6
6
  hintId = `${this.groupId}-hint`;
7
7
  errorId = `${this.groupId}-error`;
8
+ initialValue;
9
+ internals;
10
+ formDisabled = false;
11
+ host;
8
12
  /**
9
13
  * Visible label describing the radio group, associated with it via
10
14
  * `aria-labelledby`.
@@ -52,6 +56,39 @@ export class ChRadio {
52
56
  this.value = ev.target.value;
53
57
  this.chChange.emit(this.value);
54
58
  };
59
+ syncForm() {
60
+ const internals = this.internals;
61
+ if (typeof internals?.setFormValue !== 'function') {
62
+ return;
63
+ }
64
+ internals.setFormValue(this.value ?? null);
65
+ const flags = {};
66
+ let message;
67
+ if (this.required && !this.value) {
68
+ flags.valueMissing = true;
69
+ }
70
+ if (this.invalid && this.errorMessage) {
71
+ flags.customError = true;
72
+ }
73
+ message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);
74
+ internals.setValidity(flags, message);
75
+ }
76
+ componentDidLoad() {
77
+ this.initialValue = this.value;
78
+ this.syncForm();
79
+ this.host.addEventListener('change', this.markTouched);
80
+ this.host.addEventListener('focusout', this.markTouched);
81
+ this.host.addEventListener('invalid', this.markTouched);
82
+ }
83
+ markTouched = () => {
84
+ this.host.setAttribute('data-touched', '');
85
+ };
86
+ formResetCallback() {
87
+ this.value = this.initialValue;
88
+ }
89
+ formDisabledCallback(isDisabled) {
90
+ this.formDisabled = isDisabled;
91
+ }
55
92
  get describedBy() {
56
93
  if (this.invalid && this.errorMessage) {
57
94
  return this.errorId;
@@ -63,10 +100,11 @@ export class ChRadio {
63
100
  }
64
101
  render() {
65
102
  const groupName = this.name || `${this.groupId}-group`;
66
- return (h(Host, { key: '68ce563b4a03669b76ff3822705b1ff92c4c02f2' }, this.label && (h("span", { key: '1887f5b70a5bf9f049495d76588458181d3f7735', class: "group-label", id: this.labelId }, this.label)), h("div", { key: 'c38ee340f9527e16c5587f2309f91ea463bb7cad', class: "radio-group", role: "radiogroup", "aria-labelledby": this.label ? this.labelId : undefined }, this.options.map(option => (h("label", { class: { 'control': true, 'control--disabled': this.disabled || option.disabled } }, h("input", { class: { 'input': true, 'input--invalid': this.invalid }, type: "radio", name: groupName, value: option.value, checked: option.value === this.value, disabled: this.disabled || option.disabled, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }), h("span", { class: "mark" }), h("span", { class: "label-text" }, option.label))))), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: 'ad60ce772279809ee334fc30182be1d0350d5586', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '316c911f9e1a29d17cc2d6b0e60ed35755420ae2', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
103
+ return (h(Host, { key: '2d0f02cbeae89b8c60664825f3885bbeeafd896a' }, this.label && (h("span", { key: 'c32fd25be5eaf0d05c2d8d6aae01dda281f4b952', class: "group-label", id: this.labelId }, this.label)), h("div", { key: 'bd05a360ad1fd794c95d8066dbb93300152a88dc', class: "radio-group", role: "radiogroup", "aria-labelledby": this.label ? this.labelId : undefined }, this.options.map(option => (h("label", { class: { 'control': true, 'control--disabled': this.disabled || this.formDisabled || option.disabled } }, h("input", { class: { 'input': true, 'input--invalid': this.invalid }, type: "radio", name: groupName, value: option.value, checked: option.value === this.value, disabled: this.disabled || this.formDisabled || option.disabled, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }), h("span", { class: "mark" }), h("span", { class: "label-text" }, option.label))))), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '8c451f8d166c6002a4f30bfb72acd6b863ec38c2', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '8ac12f60e463c908dff76d64d7ae0e216ed51489', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
67
104
  }
68
105
  static get is() { return "ch-radio"; }
69
106
  static get encapsulation() { return "shadow"; }
107
+ static get formAssociated() { return true; }
70
108
  static get originalStyleUrls() {
71
109
  return {
72
110
  "$": ["ch-radio.css"]
@@ -157,7 +195,7 @@ export class ChRadio {
157
195
  },
158
196
  "getter": false,
159
197
  "setter": false,
160
- "reflect": false,
198
+ "reflect": true,
161
199
  "attribute": "name"
162
200
  },
163
201
  "disabled": {
@@ -176,7 +214,7 @@ export class ChRadio {
176
214
  },
177
215
  "getter": false,
178
216
  "setter": false,
179
- "reflect": false,
217
+ "reflect": true,
180
218
  "attribute": "disabled",
181
219
  "defaultValue": "false"
182
220
  },
@@ -196,7 +234,7 @@ export class ChRadio {
196
234
  },
197
235
  "getter": false,
198
236
  "setter": false,
199
- "reflect": false,
237
+ "reflect": true,
200
238
  "attribute": "required",
201
239
  "defaultValue": "false"
202
240
  },
@@ -260,6 +298,11 @@ export class ChRadio {
260
298
  }
261
299
  };
262
300
  }
301
+ static get states() {
302
+ return {
303
+ "formDisabled": {}
304
+ };
305
+ }
263
306
  static get events() {
264
307
  return [{
265
308
  "method": "chChange",
@@ -278,5 +321,22 @@ export class ChRadio {
278
321
  }
279
322
  }];
280
323
  }
324
+ static get elementRef() { return "host"; }
325
+ static get watchers() {
326
+ return [{
327
+ "propName": "value",
328
+ "methodName": "syncForm"
329
+ }, {
330
+ "propName": "required",
331
+ "methodName": "syncForm"
332
+ }, {
333
+ "propName": "invalid",
334
+ "methodName": "syncForm"
335
+ }, {
336
+ "propName": "errorMessage",
337
+ "methodName": "syncForm"
338
+ }];
339
+ }
340
+ static get attachInternalsMemberName() { return "internals"; }
281
341
  }
282
342
  //# sourceMappingURL=ch-radio.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ch-radio.js","sourceRoot":"","sources":["../../../../src/components/ch-radio/ch-radio.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAQnF,IAAI,QAAQ,GAAG,CAAC,CAAC;AAOjB,MAAM,OAAO,OAAO;IACD,OAAO,GAAG,YAAY,EAAE,QAAQ,EAAE,CAAC;IACnC,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,QAAQ,CAAC;IAClC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,OAAO,CAAC;IAChC,OAAO,GAAG,GAAG,IAAI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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Event, type EventEmitter, Host, Prop, h } from '@stencil/core';\n\nexport interface ChRadioOption {\n label: string;\n value: string;\n disabled?: boolean;\n}\n\nlet radioIds = 0;\n\n@Component({\n tag: 'ch-radio',\n styleUrl: 'ch-radio.css',\n shadow: true,\n})\nexport class ChRadio {\n private readonly groupId = `ch-radio-${++radioIds}`;\n private readonly labelId = `${this.groupId}-label`;\n private readonly hintId = `${this.groupId}-hint`;\n private readonly errorId = `${this.groupId}-error`;\n\n /**\n * Visible label describing the radio group, associated with it via\n * `aria-labelledby`.\n */\n @Prop() label?: string;\n\n /**\n * The list of options rendered as radio inputs.\n */\n @Prop() options: ChRadioOption[] = [];\n\n /**\n * The value of the selected option.\n */\n @Prop({ mutable: true }) value?: string;\n\n /**\n * The name shared by all radio inputs in the group. Defaults to an\n * auto-generated group name so options are mutually exclusive out of the box.\n */\n @Prop() name?: string;\n\n /**\n * Whether all radios in the group are disabled.\n */\n @Prop() disabled = false;\n\n /**\n * Whether a value is required.\n */\n @Prop() required = false;\n\n /**\n * Helper text rendered below the radio group, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the group is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the radio group when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the radio group is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted when a new option is selected, with the selected value.\n */\n @Event() chChange: EventEmitter<string>;\n\n private handleChange = (ev: Event) => {\n this.value = (ev.target as HTMLInputElement).value;\n this.chChange.emit(this.value);\n };\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n const groupName = this.name || `${this.groupId}-group`;\n return (\n <Host>\n {this.label && (\n <span class=\"group-label\" id={this.labelId}>\n {this.label}\n </span>\n )}\n <div class=\"radio-group\" role=\"radiogroup\" aria-labelledby={this.label ? this.labelId : undefined}>\n {this.options.map(option => (\n <label class={{ 'control': true, 'control--disabled': this.disabled || option.disabled }}>\n <input\n class={{ 'input': true, 'input--invalid': this.invalid }}\n type=\"radio\"\n name={groupName}\n value={option.value}\n checked={option.value === this.value}\n disabled={this.disabled || option.disabled}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onChange={this.handleChange}\n />\n <span class=\"mark\"></span>\n <span class=\"label-text\">{option.label}</span>\n </label>\n ))}\n </div>\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"ch-radio.js","sourceRoot":"","sources":["../../../../src/components/ch-radio/ch-radio.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAQ3H,IAAI,QAAQ,GAAG,CAAC,CAAC;AAQjB,MAAM,OAAO,OAAO;IACD,OAAO,GAAG,YAAY,EAAE,QAAQ,EAAE,CAAC;IACnC,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,QAAQ,CAAC;IAClC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,OAAO,CAAC;IAChC,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,QAAQ,CAAC;IAC3C,YAAY,CAAqB;IAEtB,SAAS,CAAoB;I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CAAC,YAAY,IAAI,CACpC,0DAAG,KAAK,EAAC,OAAO,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAC,OAAO,IAC5C,IAAI,CAAC,YAAY,CAChB,CACL,CACI,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { AttachInternals, Component, Element, Event, type EventEmitter, Host, Prop, State, Watch, h } from '@stencil/core';\n\nexport interface ChRadioOption {\n label: string;\n value: string;\n disabled?: boolean;\n}\n\nlet radioIds = 0;\n\n@Component({\n tag: 'ch-radio',\n styleUrl: 'ch-radio.css',\n shadow: true,\n formAssociated: true,\n})\nexport class ChRadio {\n private readonly groupId = `ch-radio-${++radioIds}`;\n private readonly labelId = `${this.groupId}-label`;\n private readonly hintId = `${this.groupId}-hint`;\n private readonly errorId = `${this.groupId}-error`;\n private initialValue: string | undefined;\n\n @AttachInternals() internals!: ElementInternals;\n @State() formDisabled = false;\n @Element() private host!: HTMLElement;\n\n /**\n * Visible label describing the radio group, associated with it via\n * `aria-labelledby`.\n */\n @Prop() label?: string;\n\n /**\n * The list of options rendered as radio inputs.\n */\n @Prop() options: ChRadioOption[] = [];\n\n /**\n * The value of the selected option.\n */\n @Prop({ mutable: true }) value?: string;\n\n /**\n * The name shared by all radio inputs in the group. Defaults to an\n * auto-generated group name so options are mutually exclusive out of the box.\n */\n @Prop({ reflect: true }) name?: string;\n\n /**\n * Whether all radios in the group are disabled.\n */\n @Prop({ reflect: true }) disabled = false;\n\n /**\n * Whether a value is required.\n */\n @Prop({ reflect: true }) required = false;\n\n /**\n * Helper text rendered below the radio group, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the group is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the radio group when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the radio group is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted when a new option is selected, with the selected value.\n */\n @Event() chChange: EventEmitter<string>;\n\n private handleChange = (ev: Event) => {\n this.value = (ev.target as HTMLInputElement).value;\n this.chChange.emit(this.value);\n };\n\n @Watch('value')\n @Watch('required')\n @Watch('invalid')\n @Watch('errorMessage')\n protected syncForm(): void {\n const internals = this.internals;\n if (typeof internals?.setFormValue !== 'function') {\n return;\n }\n internals.setFormValue(this.value ?? null);\n const flags: ValidityStateFlags = {};\n let message: string | undefined;\n if (this.required && !this.value) {\n flags.valueMissing = true;\n }\n if (this.invalid && this.errorMessage) {\n flags.customError = true;\n }\n message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);\n internals.setValidity(flags, message);\n }\n\n componentDidLoad() {\n this.initialValue = this.value;\n this.syncForm();\n this.host.addEventListener('change', this.markTouched);\n this.host.addEventListener('focusout', this.markTouched);\n this.host.addEventListener('invalid', this.markTouched);\n }\n\n private markTouched = (): void => {\n this.host.setAttribute('data-touched', '');\n };\n\n formResetCallback(): void {\n this.value = this.initialValue;\n }\n\n formDisabledCallback(isDisabled: boolean): void {\n this.formDisabled = isDisabled;\n }\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n const groupName = this.name || `${this.groupId}-group`;\n return (\n <Host>\n {this.label && (\n <span class=\"group-label\" id={this.labelId}>\n {this.label}\n </span>\n )}\n <div class=\"radio-group\" role=\"radiogroup\" aria-labelledby={this.label ? this.labelId : undefined}>\n {this.options.map(option => (\n <label class={{ 'control': true, 'control--disabled': this.disabled || this.formDisabled || option.disabled }}>\n <input\n class={{ 'input': true, 'input--invalid': this.invalid }}\n type=\"radio\"\n name={groupName}\n value={option.value}\n checked={option.value === this.value}\n disabled={this.disabled || this.formDisabled || option.disabled}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onChange={this.handleChange}\n />\n <span class=\"mark\"></span>\n <span class=\"label-text\">{option.label}</span>\n </label>\n ))}\n </div>\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
@@ -43,6 +43,17 @@
43
43
  box-shadow: 0 0 0 3px var(--color-status-warning-background);
44
44
  }
45
45
 
46
+ :host([data-touched]:invalid) .select,
47
+ :host(:user-invalid) .select {
48
+ border-color: var(--color-status-warning);
49
+ }
50
+
51
+ :host([data-touched]:invalid) .select:focus,
52
+ :host(:user-invalid) .select:focus {
53
+ border-color: var(--color-status-warning);
54
+ box-shadow: 0 0 0 3px var(--color-status-warning-background);
55
+ }
56
+
46
57
  .select:disabled {
47
58
  opacity: var(--opacity-disabled);
48
59
  cursor: not-allowed;
@@ -4,6 +4,10 @@ export class ChSelect {
4
4
  selectId = `ch-select-${++selectIds}`;
5
5
  hintId = `${this.selectId}-hint`;
6
6
  errorId = `${this.selectId}-error`;
7
+ initialValue;
8
+ internals;
9
+ formDisabled = false;
10
+ host;
7
11
  /**
8
12
  * Visible label rendered above the select and associated with it via
9
13
  * `for`/`id`, so assistive technology announces the select's purpose.
@@ -54,6 +58,39 @@ export class ChSelect {
54
58
  this.value = ev.target.value;
55
59
  this.chChange.emit(this.value);
56
60
  };
61
+ syncForm() {
62
+ const internals = this.internals;
63
+ if (typeof internals?.setFormValue !== 'function') {
64
+ return;
65
+ }
66
+ internals.setFormValue(this.value ?? '');
67
+ const flags = {};
68
+ let message;
69
+ if (this.required && !this.value) {
70
+ flags.valueMissing = true;
71
+ }
72
+ if (this.invalid && this.errorMessage) {
73
+ flags.customError = true;
74
+ }
75
+ message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);
76
+ internals.setValidity(flags, message);
77
+ }
78
+ componentDidLoad() {
79
+ this.initialValue = this.value;
80
+ this.syncForm();
81
+ this.host.addEventListener('change', this.markTouched);
82
+ this.host.addEventListener('focusout', this.markTouched);
83
+ this.host.addEventListener('invalid', this.markTouched);
84
+ }
85
+ markTouched = () => {
86
+ this.host.setAttribute('data-touched', '');
87
+ };
88
+ formResetCallback() {
89
+ this.value = this.initialValue;
90
+ }
91
+ formDisabledCallback(isDisabled) {
92
+ this.formDisabled = isDisabled;
93
+ }
57
94
  get describedBy() {
58
95
  if (this.invalid && this.errorMessage) {
59
96
  return this.errorId;
@@ -64,10 +101,11 @@ export class ChSelect {
64
101
  return undefined;
65
102
  }
66
103
  render() {
67
- return (h(Host, { key: '90aaf1fa70da54071539de8a22ebe9373f2ae90a' }, this.label && (h("label", { key: '8b14b4deb611c4f1eb496c6f0d3fa58b7c4342b6', class: "label", htmlFor: this.selectId }, this.label)), h("select", { key: 'c93b4ba079e9e61ef5bb2392256545af73263665', id: this.label ? this.selectId : undefined, class: { 'select': true, 'select--invalid': this.invalid }, name: this.name, disabled: this.disabled, required: this.required, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }, this.placeholder && (h("option", { key: 'df8e97bdb0bd3e5426558027d34c1eb63ee76f1e', value: "", disabled: true, hidden: true, selected: !this.value }, this.placeholder)), this.options.map(option => (h("option", { value: option.value, disabled: option.disabled, selected: option.value === this.value }, option.label)))), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '6b6078e31a1a2f183951f5ada63a5e7e7f582f96', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: 'f7791b37b8660441a43a6b45d99472b2df7df0ab', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
104
+ return (h(Host, { key: 'ffca23504c723f60f7430e6db2e1fa00db1fd4d8' }, this.label && (h("label", { key: '697998ec67f01f3ca2849b1fb2aa88790d98010b', class: "label", htmlFor: this.selectId }, this.label)), h("select", { key: 'f344d240f38dd123bdfd2d34cd15fbc7b5ae0a2c', id: this.label ? this.selectId : undefined, class: { 'select': true, 'select--invalid': this.invalid }, name: this.name, disabled: this.disabled || this.formDisabled, required: this.required, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }, this.placeholder && (h("option", { key: '34200e96dad92ed55632f0430abde5bc34cf6e6a', value: "", disabled: true, hidden: true, selected: !this.value }, this.placeholder)), this.options.map(option => (h("option", { value: option.value, disabled: option.disabled, selected: option.value === this.value }, option.label)))), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '55690dbf57cad7c974d0bf1b8eedb733ddc5b571', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '7d4598b112d21ebc96ac04bca553f63dd5825996', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
68
105
  }
69
106
  static get is() { return "ch-select"; }
70
107
  static get encapsulation() { return "shadow"; }
108
+ static get formAssociated() { return true; }
71
109
  static get originalStyleUrls() {
72
110
  return {
73
111
  "$": ["ch-select.css"]
@@ -177,7 +215,7 @@ export class ChSelect {
177
215
  },
178
216
  "getter": false,
179
217
  "setter": false,
180
- "reflect": false,
218
+ "reflect": true,
181
219
  "attribute": "name"
182
220
  },
183
221
  "disabled": {
@@ -196,7 +234,7 @@ export class ChSelect {
196
234
  },
197
235
  "getter": false,
198
236
  "setter": false,
199
- "reflect": false,
237
+ "reflect": true,
200
238
  "attribute": "disabled",
201
239
  "defaultValue": "false"
202
240
  },
@@ -216,7 +254,7 @@ export class ChSelect {
216
254
  },
217
255
  "getter": false,
218
256
  "setter": false,
219
- "reflect": false,
257
+ "reflect": true,
220
258
  "attribute": "required",
221
259
  "defaultValue": "false"
222
260
  },
@@ -280,6 +318,11 @@ export class ChSelect {
280
318
  }
281
319
  };
282
320
  }
321
+ static get states() {
322
+ return {
323
+ "formDisabled": {}
324
+ };
325
+ }
283
326
  static get events() {
284
327
  return [{
285
328
  "method": "chChange",
@@ -298,5 +341,22 @@ export class ChSelect {
298
341
  }
299
342
  }];
300
343
  }
344
+ static get elementRef() { return "host"; }
345
+ static get watchers() {
346
+ return [{
347
+ "propName": "value",
348
+ "methodName": "syncForm"
349
+ }, {
350
+ "propName": "required",
351
+ "methodName": "syncForm"
352
+ }, {
353
+ "propName": "invalid",
354
+ "methodName": "syncForm"
355
+ }, {
356
+ "propName": "errorMessage",
357
+ "methodName": "syncForm"
358
+ }];
359
+ }
360
+ static get attachInternalsMemberName() { return "internals"; }
301
361
  }
302
362
  //# sourceMappingURL=ch-select.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ch-select.js","sourceRoot":"","sources":["../../../../src/components/ch-select/ch-select.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAQnF,IAAI,SAAS,GAAG,CAAC,CAAC;AAOlB,MAAM,OAAO,QAAQ;IACF,QAAQ,GAAG,aAAa,EAAE,SAAS,EAAE,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,OAAO,CAAC;IACjC,OAAO,GAAG,GAAG,IAAI,CAAC,QAAQ,QAAQ,CAAC;IAEpD;;;OAGG;IACK,KAAK,CAAU;IAEvB;;OAEG;IACK,OAAO,GAAqB,EAAE,CAAC;IAEvC;;OAEG;IACsB,KAAK,CAAU;IAExC;;OAEG;IACK,WAAW,CAAU;IAE7B;;OAEG;IACK,IAAI,CAAU;IAEtB;;OAEG;IACK,QAAQ,GAAG,KAAK,CAAC;IAEzB;;OAEG;IACK,QAAQ,GAAG,KAAK,CAAC;IAEzB;;;OAGG;IACK,IAAI,CAAU;IAE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AE,EAAC,QAAQ,QAAC,MAAM,QAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,KAAK,IACnD,IAAI,CAAC,WAAW,CACV,CACV;gBACA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAC1B,cAAQ,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAC1F,MAAM,CAAC,KAAK,CACN,CACV,CAAC,CACK;YACR,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CACpD,0DAAG,KAAK,EAAC,MAAM,EAAC,EAAE,EAAE,IAAI,CAAC,MAAM,IAC5B,IAAI,CAAC,IAAI,CACR,CACL;YACA,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,IAAI,CACpC,0DAAG,KAAK,EAAC,OAAO,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAC,OAAO,IAC5C,IAAI,CAAC,YAAY,CAChB,CACL,CACI,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Event, type EventEmitter, Host, Prop, h } from '@stencil/core';\n\nexport interface ChSelectOption {\n label: string;\n value: string;\n disabled?: boolean;\n}\n\nlet selectIds = 0;\n\n@Component({\n tag: 'ch-select',\n styleUrl: 'ch-select.css',\n shadow: true,\n})\nexport class ChSelect {\n private readonly selectId = `ch-select-${++selectIds}`;\n private readonly hintId = `${this.selectId}-hint`;\n private readonly errorId = `${this.selectId}-error`;\n\n /**\n * Visible label rendered above the select and associated with it via\n * `for`/`id`, so assistive technology announces the select's purpose.\n */\n @Prop() label?: string;\n\n /**\n * The list of options rendered inside the select.\n */\n @Prop() options: ChSelectOption[] = [];\n\n /**\n * The value of the selected option.\n */\n @Prop({ mutable: true }) value?: string;\n\n /**\n * Placeholder shown as a disabled, hidden first option when no value is selected.\n */\n @Prop() placeholder?: string;\n\n /**\n * The name of the select, submitted with form data.\n */\n @Prop() name?: string;\n\n /**\n * Whether the select is disabled.\n */\n @Prop() disabled = false;\n\n /**\n * Whether a value is required.\n */\n @Prop() required = false;\n\n /**\n * Helper text rendered below the select, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the select is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the select when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the select is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted when the selected option changes, with the new value.\n */\n @Event() chChange: EventEmitter<string>;\n\n private handleChange = (ev: Event) => {\n this.value = (ev.target as HTMLSelectElement).value;\n this.chChange.emit(this.value);\n };\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n return (\n <Host>\n {this.label && (\n <label class=\"label\" htmlFor={this.selectId}>\n {this.label}\n </label>\n )}\n <select\n id={this.label ? this.selectId : undefined}\n class={{ 'select': true, 'select--invalid': this.invalid }}\n name={this.name}\n disabled={this.disabled}\n required={this.required}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onChange={this.handleChange}\n >\n {this.placeholder && (\n <option value=\"\" disabled hidden selected={!this.value}>\n {this.placeholder}\n </option>\n )}\n {this.options.map(option => (\n <option value={option.value} disabled={option.disabled} selected={option.value === this.value}>\n {option.label}\n </option>\n ))}\n </select>\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"ch-select.js","sourceRoot":"","sources":["../../../../src/components/ch-select/ch-select.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAQ3H,IAAI,SAAS,GAAG,CAAC,CAAC;AAQlB,MAAM,OAAO,QAAQ;IACF,QAAQ,GAAG,aAAa,EAAE,SAAS,EAAE,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,OAAO,CAAC;IACjC,OAAO,GAAG,GAAG,IAAI,CAAC,QAAQ,QAAQ,CAAC;IAC5C,YAAY,CAAqB;IAEtB,SAAS,CAAoB;IACvC,YAAY,GAAG,KAAK,CAAC;IACX,IAAI,CAAe;IAEtC;;;OAGG;IACK,KAAK,CAAU;IAEvB;;OAEG;IACK,OAAO,GAAqB,EAAE,CAAC;IAEvC;;OAEG;IACsB,KAAK,CAAU;IAExC;;OAEG;IACK,WAAW,CAAU;IAE7B;;OAEG;IACsB,IAAI,CAAU;IAEvC;;OAEG;IACsB,QAAQ,GAAG,KAAK,CAAC;IAE1C;;OAEG;IACsB,QAAQ,GAAG,KAAK,CAAC;IAE1C;;;OAGG;IACK,IAAI,CAAU;IAEtB;;OAEG;IACK,YAAY,CAAU;IAE9B;;OAEG;IACK,OAAO,GAAG,KAAK,CAAC;IAExB;;OAEG;IACM,QAAQ,CAAuB;IAEhC,YAAY,GAAG,CAAC,EAAS,EAAE,EAAE;QACnC,IAAI,CAAC,KAAK,GA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EAAC,EAAE,EAAC,QAAQ,QAAC,MAAM,QAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,KAAK,IACnD,IAAI,CAAC,WAAW,CACV,CACV;gBACA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAC1B,cAAQ,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAC1F,MAAM,CAAC,KAAK,CACN,CACV,CAAC,CACK;YACR,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CACpD,0DAAG,KAAK,EAAC,MAAM,EAAC,EAAE,EAAE,IAAI,CAAC,MAAM,IAC5B,IAAI,CAAC,IAAI,CACR,CACL;YACA,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,IAAI,CACpC,0DAAG,KAAK,EAAC,OAAO,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAC,OAAO,IAC5C,IAAI,CAAC,YAAY,CAChB,CACL,CACI,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { AttachInternals, Component, Element, Event, type EventEmitter, Host, Prop, State, Watch, h } from '@stencil/core';\n\nexport interface ChSelectOption {\n label: string;\n value: string;\n disabled?: boolean;\n}\n\nlet selectIds = 0;\n\n@Component({\n tag: 'ch-select',\n styleUrl: 'ch-select.css',\n shadow: true,\n formAssociated: true,\n})\nexport class ChSelect {\n private readonly selectId = `ch-select-${++selectIds}`;\n private readonly hintId = `${this.selectId}-hint`;\n private readonly errorId = `${this.selectId}-error`;\n private initialValue: string | undefined;\n\n @AttachInternals() internals!: ElementInternals;\n @State() formDisabled = false;\n @Element() private host!: HTMLElement;\n\n /**\n * Visible label rendered above the select and associated with it via\n * `for`/`id`, so assistive technology announces the select's purpose.\n */\n @Prop() label?: string;\n\n /**\n * The list of options rendered inside the select.\n */\n @Prop() options: ChSelectOption[] = [];\n\n /**\n * The value of the selected option.\n */\n @Prop({ mutable: true }) value?: string;\n\n /**\n * Placeholder shown as a disabled, hidden first option when no value is selected.\n */\n @Prop() placeholder?: string;\n\n /**\n * The name of the select, submitted with form data.\n */\n @Prop({ reflect: true }) name?: string;\n\n /**\n * Whether the select is disabled.\n */\n @Prop({ reflect: true }) disabled = false;\n\n /**\n * Whether a value is required.\n */\n @Prop({ reflect: true }) required = false;\n\n /**\n * Helper text rendered below the select, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the select is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the select when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the select is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted when the selected option changes, with the new value.\n */\n @Event() chChange: EventEmitter<string>;\n\n private handleChange = (ev: Event) => {\n this.value = (ev.target as HTMLSelectElement).value;\n this.chChange.emit(this.value);\n };\n\n @Watch('value')\n @Watch('required')\n @Watch('invalid')\n @Watch('errorMessage')\n protected syncForm(): void {\n const internals = this.internals;\n if (typeof internals?.setFormValue !== 'function') {\n return;\n }\n internals.setFormValue(this.value ?? '');\n const flags: ValidityStateFlags = {};\n let message: string | undefined;\n if (this.required && !this.value) {\n flags.valueMissing = true;\n }\n if (this.invalid && this.errorMessage) {\n flags.customError = true;\n }\n message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);\n internals.setValidity(flags, message);\n }\n\n componentDidLoad() {\n this.initialValue = this.value;\n this.syncForm();\n this.host.addEventListener('change', this.markTouched);\n this.host.addEventListener('focusout', this.markTouched);\n this.host.addEventListener('invalid', this.markTouched);\n }\n\n private markTouched = (): void => {\n this.host.setAttribute('data-touched', '');\n };\n\n formResetCallback(): void {\n this.value = this.initialValue;\n }\n\n formDisabledCallback(isDisabled: boolean): void {\n this.formDisabled = isDisabled;\n }\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n return (\n <Host>\n {this.label && (\n <label class=\"label\" htmlFor={this.selectId}>\n {this.label}\n </label>\n )}\n <select\n id={this.label ? this.selectId : undefined}\n class={{ 'select': true, 'select--invalid': this.invalid }}\n name={this.name}\n disabled={this.disabled || this.formDisabled}\n required={this.required}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onChange={this.handleChange}\n >\n {this.placeholder && (\n <option value=\"\" disabled hidden selected={!this.value}>\n {this.placeholder}\n </option>\n )}\n {this.options.map(option => (\n <option value={option.value} disabled={option.disabled} selected={option.value === this.value}>\n {option.label}\n </option>\n ))}\n </select>\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
@@ -23,7 +23,7 @@ export class ChSpinner {
23
23
  label;
24
24
  render() {
25
25
  const labelled = Boolean(this.label);
26
- return (h(Host, { key: 'dc7c7e19f6a6878680555b0d7dbd84f5dc5774c8' }, h("span", { key: 'd29d5f3344ae578d2a28382b13b45b901d41e52b', class: { spinner: true, [`spinner--${this.size}`]: true }, role: labelled ? 'status' : undefined, "aria-label": labelled ? this.label : undefined, "aria-hidden": labelled ? undefined : 'true' })));
26
+ return (h(Host, { key: '9182eecf066be099714a870fa601f744362e697d' }, h("span", { key: 'd67f2572ab80facadd4d49043a892b16816b4fef', class: { spinner: true, [`spinner--${this.size}`]: true }, role: labelled ? 'status' : undefined, "aria-label": labelled ? this.label : undefined, "aria-hidden": labelled ? undefined : 'true' })));
27
27
  }
28
28
  static get is() { return "ch-spinner"; }
29
29
  static get encapsulation() { return "shadow"; }
@@ -76,6 +76,16 @@
76
76
  outline-color: var(--color-status-warning);
77
77
  }
78
78
 
79
+ :host([data-touched]:invalid) .track,
80
+ :host(:user-invalid) .track {
81
+ border-color: var(--color-status-warning);
82
+ }
83
+
84
+ :host([data-touched]:invalid) .input:focus-visible ~ .track,
85
+ :host(:user-invalid) .input:focus-visible ~ .track {
86
+ outline-color: var(--color-status-warning);
87
+ }
88
+
79
89
  .label-text {
80
90
  color: var(--text);
81
91
  }
@@ -4,6 +4,10 @@ export class ChSwitch {
4
4
  switchId = `ch-switch-${++switchIds}`;
5
5
  hintId = `${this.switchId}-hint`;
6
6
  errorId = `${this.switchId}-error`;
7
+ initialChecked = false;
8
+ internals;
9
+ formDisabled = false;
10
+ host;
7
11
  /**
8
12
  * Visible label rendered next to the switch, associated with it via
9
13
  * `for`/`id`, so assistive technology announces the switch's purpose.
@@ -50,6 +54,39 @@ export class ChSwitch {
50
54
  this.checked = ev.target.checked;
51
55
  this.chChange.emit(this.checked);
52
56
  };
57
+ syncForm() {
58
+ const internals = this.internals;
59
+ if (typeof internals?.setFormValue !== 'function') {
60
+ return;
61
+ }
62
+ internals.setFormValue(this.checked ? this.value : null);
63
+ const flags = {};
64
+ let message;
65
+ if (this.required && !this.checked) {
66
+ flags.valueMissing = true;
67
+ }
68
+ if (this.invalid && this.errorMessage) {
69
+ flags.customError = true;
70
+ }
71
+ message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);
72
+ internals.setValidity(flags, message);
73
+ }
74
+ componentDidLoad() {
75
+ this.initialChecked = this.checked;
76
+ this.syncForm();
77
+ this.host.addEventListener('change', this.markTouched);
78
+ this.host.addEventListener('focusout', this.markTouched);
79
+ this.host.addEventListener('invalid', this.markTouched);
80
+ }
81
+ markTouched = () => {
82
+ this.host.setAttribute('data-touched', '');
83
+ };
84
+ formResetCallback() {
85
+ this.checked = this.initialChecked;
86
+ }
87
+ formDisabledCallback(isDisabled) {
88
+ this.formDisabled = isDisabled;
89
+ }
53
90
  get describedBy() {
54
91
  if (this.invalid && this.errorMessage) {
55
92
  return this.errorId;
@@ -60,10 +97,11 @@ export class ChSwitch {
60
97
  return undefined;
61
98
  }
62
99
  render() {
63
- return (h(Host, { key: 'f95f9b724e37771ea3949ff569881dc1eff370a1' }, h("label", { key: '878c3c47e380356a3b79e79fdd135df627ce37a6', class: { 'control': true, 'control--disabled': this.disabled }, htmlFor: this.switchId }, h("input", { key: '14ee6041b8aeb4115db1f7ca9c542314651f34ea', id: this.switchId, class: { 'input': true, 'input--invalid': this.invalid }, type: "checkbox", role: "switch", name: this.name, value: this.value, checked: this.checked, disabled: this.disabled, required: this.required, "aria-checked": this.checked ? 'true' : 'false', "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }), h("span", { key: '0d58863f220b6e9f04babd6231a35dea039a41a2', class: "track" }, h("span", { key: '588617f6bb1c61168b860c4b2863892828fd5df5', class: "thumb" })), this.label && h("span", { key: '530e64cc85761e91a019431f977bb9d2d8e86e27', class: "label-text" }, this.label)), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '71ffd6b56a753673f9d5663054a217e250363ce1', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '63f9965c30d8cd2820554de31ac7edc364aee22b', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
100
+ return (h(Host, { key: 'c1a98e9b04710ed014a8c18d6591fee427df0033' }, h("label", { key: '4b14ec7d7709090235b0e9b74a45d4c76dd52f25', class: { 'control': true, 'control--disabled': this.disabled || this.formDisabled }, htmlFor: this.switchId }, h("input", { key: '4f2c9472b3bf34db582a94e307cc8b47b5dfcd38', id: this.switchId, class: { 'input': true, 'input--invalid': this.invalid }, type: "checkbox", role: "switch", name: this.name, value: this.value, checked: this.checked, disabled: this.disabled || this.formDisabled, required: this.required, "aria-checked": this.checked ? 'true' : 'false', "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }), h("span", { key: '6b2c20c6242178bba39f105a535bb12fc5198cd0', class: "track" }, h("span", { key: '4ae0e675ce335417b867f6b688ec5545769b2d2c', class: "thumb" })), this.label && h("span", { key: 'd5383fac3349441104c0926a6c88078b85bda05c', class: "label-text" }, this.label)), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '41ed07a95f8d627fb4ed8c903b6ba5ee39baa6a5', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '71cf8526dec44e2099235e3bc744db2aa53d70f0', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
64
101
  }
65
102
  static get is() { return "ch-switch"; }
66
103
  static get encapsulation() { return "shadow"; }
104
+ static get formAssociated() { return true; }
67
105
  static get originalStyleUrls() {
68
106
  return {
69
107
  "$": ["ch-switch.css"]
@@ -111,7 +149,7 @@ export class ChSwitch {
111
149
  },
112
150
  "getter": false,
113
151
  "setter": false,
114
- "reflect": false,
152
+ "reflect": true,
115
153
  "attribute": "name"
116
154
  },
117
155
  "value": {
@@ -170,7 +208,7 @@ export class ChSwitch {
170
208
  },
171
209
  "getter": false,
172
210
  "setter": false,
173
- "reflect": false,
211
+ "reflect": true,
174
212
  "attribute": "disabled",
175
213
  "defaultValue": "false"
176
214
  },
@@ -190,7 +228,7 @@ export class ChSwitch {
190
228
  },
191
229
  "getter": false,
192
230
  "setter": false,
193
- "reflect": false,
231
+ "reflect": true,
194
232
  "attribute": "required",
195
233
  "defaultValue": "false"
196
234
  },
@@ -254,6 +292,11 @@ export class ChSwitch {
254
292
  }
255
293
  };
256
294
  }
295
+ static get states() {
296
+ return {
297
+ "formDisabled": {}
298
+ };
299
+ }
257
300
  static get events() {
258
301
  return [{
259
302
  "method": "chChange",
@@ -272,5 +315,22 @@ export class ChSwitch {
272
315
  }
273
316
  }];
274
317
  }
318
+ static get elementRef() { return "host"; }
319
+ static get watchers() {
320
+ return [{
321
+ "propName": "checked",
322
+ "methodName": "syncForm"
323
+ }, {
324
+ "propName": "required",
325
+ "methodName": "syncForm"
326
+ }, {
327
+ "propName": "invalid",
328
+ "methodName": "syncForm"
329
+ }, {
330
+ "propName": "errorMessage",
331
+ "methodName": "syncForm"
332
+ }];
333
+ }
334
+ static get attachInternalsMemberName() { return "internals"; }
275
335
  }
276
336
  //# sourceMappingURL=ch-switch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ch-switch.js","sourceRoot":"","sources":["../../../../src/components/ch-switch/ch-switch.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAEnF,IAAI,SAAS,GAAG,CAAC,CAAC;AAOlB,MAAM,OAAO,QAAQ;IACF,QAAQ,GAAG,aAAa,EAAE,SAAS,EAAE,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,OAAO,CAAC;IACjC,OAAO,GAAG,GAAG,IAAI,CAAC,QAAQ,QAAQ,CAAC;IAEpD;;;OAGG;IACK,KAAK,CAAU;IAEvB;;OAEG;IACK,IAAI,CAAU;IAEtB;;OAEG;IACK,KAAK,GAAG,IAAI,CAAC;IAErB;;OAEG;IACsB,OAAO,GAAG,KAAK,CAAC;IAEzC;;OAEG;IACK,QAAQ,GAAG,KAAK,CAAC;IAEzB;;OAEG;IACK,QAAQ,GAAG,KAAK,CAAC;IAEzB;;;OAGG;IACK,IAAI,CAAU;IAEtB;;OAEG;IACK,YAAY,CAAU;IAE9B;;OAEG;IACK,OAAO,GAAG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AI,CAAC,YAAY,GAC3B;gBACF,6DAAM,KAAK,EAAC,OAAO;oBACjB,6DAAM,KAAK,EAAC,OAAO,GAAQ,CACtB;gBACN,IAAI,CAAC,KAAK,IAAI,6DAAM,KAAK,EAAC,YAAY,IAAE,IAAI,CAAC,KAAK,CAAQ,CACrD;YACP,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CACpD,0DAAG,KAAK,EAAC,MAAM,EAAC,EAAE,EAAE,IAAI,CAAC,MAAM,IAC5B,IAAI,CAAC,IAAI,CACR,CACL;YACA,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,IAAI,CACpC,0DAAG,KAAK,EAAC,OAAO,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAC,OAAO,IAC5C,IAAI,CAAC,YAAY,CAChB,CACL,CACI,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Event, type EventEmitter, Host, Prop, h } from '@stencil/core';\n\nlet switchIds = 0;\n\n@Component({\n tag: 'ch-switch',\n styleUrl: 'ch-switch.css',\n shadow: true,\n})\nexport class ChSwitch {\n private readonly switchId = `ch-switch-${++switchIds}`;\n private readonly hintId = `${this.switchId}-hint`;\n private readonly errorId = `${this.switchId}-error`;\n\n /**\n * Visible label rendered next to the switch, associated with it via\n * `for`/`id`, so assistive technology announces the switch's purpose.\n */\n @Prop() label?: string;\n\n /**\n * The name of the switch, submitted with form data.\n */\n @Prop() name?: string;\n\n /**\n * The value of the switch, submitted with form data.\n */\n @Prop() value = 'on';\n\n /**\n * Whether the switch is on.\n */\n @Prop({ mutable: true }) checked = false;\n\n /**\n * Whether the switch is disabled.\n */\n @Prop() disabled = false;\n\n /**\n * Whether the switch is required.\n */\n @Prop() required = false;\n\n /**\n * Helper text rendered below the switch, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the switch is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the switch when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the switch is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted when the switch is toggled, with the new on/off state.\n */\n @Event() chChange: EventEmitter<boolean>;\n\n private handleChange = (ev: Event) => {\n this.checked = (ev.target as HTMLInputElement).checked;\n this.chChange.emit(this.checked);\n };\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n return (\n <Host>\n <label class={{ 'control': true, 'control--disabled': this.disabled }} htmlFor={this.switchId}>\n <input\n id={this.switchId}\n class={{ 'input': true, 'input--invalid': this.invalid }}\n type=\"checkbox\"\n role=\"switch\"\n name={this.name}\n value={this.value}\n checked={this.checked}\n disabled={this.disabled}\n required={this.required}\n aria-checked={this.checked ? 'true' : 'false'}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onChange={this.handleChange}\n />\n <span class=\"track\">\n <span class=\"thumb\"></span>\n </span>\n {this.label && <span class=\"label-text\">{this.label}</span>}\n </label>\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"ch-switch.js","sourceRoot":"","sources":["../../../../src/components/ch-switch/ch-switch.tsx"],"names":[],"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AC,KAAK,CAAQ,CACrD;YACP,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CACpD,0DAAG,KAAK,EAAC,MAAM,EAAC,EAAE,EAAE,IAAI,CAAC,MAAM,IAC5B,IAAI,CAAC,IAAI,CACR,CACL;YACA,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,IAAI,CACpC,0DAAG,KAAK,EAAC,OAAO,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAC,OAAO,IAC5C,IAAI,CAAC,YAAY,CAChB,CACL,CACI,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { AttachInternals, Component, Element, Event, type EventEmitter, Host, Prop, State, Watch, h } from '@stencil/core';\n\nlet switchIds = 0;\n\n@Component({\n tag: 'ch-switch',\n styleUrl: 'ch-switch.css',\n shadow: true,\n formAssociated: true,\n})\nexport class ChSwitch {\n private readonly switchId = `ch-switch-${++switchIds}`;\n private readonly hintId = `${this.switchId}-hint`;\n private readonly errorId = `${this.switchId}-error`;\n private initialChecked = false;\n\n @AttachInternals() internals!: ElementInternals;\n @State() formDisabled = false;\n @Element() private host!: HTMLElement;\n\n /**\n * Visible label rendered next to the switch, associated with it via\n * `for`/`id`, so assistive technology announces the switch's purpose.\n */\n @Prop() label?: string;\n\n /**\n * The name of the switch, submitted with form data.\n */\n @Prop({ reflect: true }) name?: string;\n\n /**\n * The value of the switch, submitted with form data.\n */\n @Prop() value = 'on';\n\n /**\n * Whether the switch is on.\n */\n @Prop({ mutable: true }) checked = false;\n\n /**\n * Whether the switch is disabled.\n */\n @Prop({ reflect: true }) disabled = false;\n\n /**\n * Whether the switch is required.\n */\n @Prop({ reflect: true }) required = false;\n\n /**\n * Helper text rendered below the switch, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the switch is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the switch when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the switch is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted when the switch is toggled, with the new on/off state.\n */\n @Event() chChange: EventEmitter<boolean>;\n\n private handleChange = (ev: Event) => {\n this.checked = (ev.target as HTMLInputElement).checked;\n this.chChange.emit(this.checked);\n };\n\n @Watch('checked')\n @Watch('required')\n @Watch('invalid')\n @Watch('errorMessage')\n protected syncForm(): void {\n const internals = this.internals;\n if (typeof internals?.setFormValue !== 'function') {\n return;\n }\n internals.setFormValue(this.checked ? this.value : null);\n const flags: ValidityStateFlags = {};\n let message: string | undefined;\n if (this.required && !this.checked) {\n flags.valueMissing = true;\n }\n if (this.invalid && this.errorMessage) {\n flags.customError = true;\n }\n message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);\n internals.setValidity(flags, message);\n }\n\n componentDidLoad() {\n this.initialChecked = this.checked;\n this.syncForm();\n this.host.addEventListener('change', this.markTouched);\n this.host.addEventListener('focusout', this.markTouched);\n this.host.addEventListener('invalid', this.markTouched);\n }\n\n private markTouched = (): void => {\n this.host.setAttribute('data-touched', '');\n };\n\n formResetCallback(): void {\n this.checked = this.initialChecked;\n }\n\n formDisabledCallback(isDisabled: boolean): void {\n this.formDisabled = isDisabled;\n }\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n return (\n <Host>\n <label class={{ 'control': true, 'control--disabled': this.disabled || this.formDisabled }} htmlFor={this.switchId}>\n <input\n id={this.switchId}\n class={{ 'input': true, 'input--invalid': this.invalid }}\n type=\"checkbox\"\n role=\"switch\"\n name={this.name}\n value={this.value}\n checked={this.checked}\n disabled={this.disabled || this.formDisabled}\n required={this.required}\n aria-checked={this.checked ? 'true' : 'false'}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onChange={this.handleChange}\n />\n <span class=\"track\">\n <span class=\"thumb\"></span>\n </span>\n {this.label && <span class=\"label-text\">{this.label}</span>}\n </label>\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
@@ -77,7 +77,7 @@ export class ChTabs {
77
77
  }
78
78
  render() {
79
79
  const active = this.activeValue;
80
- return (h(Host, { key: '0467e7ea24884d4c19c33b736a07303569dfaa3b' }, h("div", { key: '8ad451816ef31809c82486f3c9dd36b6e89e77e5', class: "tablist", role: "tablist", "aria-label": this.label, onKeyDown: this.handleKeyDown, ref: el => (this.tablistEl = el) }, this.tabs.map(tab => {
80
+ return (h(Host, { key: '7c6b34c34e73f034eb03473ad9941eade91317c3' }, h("div", { key: '601bae37f4fb3e5e0d07fb7a91968171b0bd18a3', class: "tablist", role: "tablist", "aria-label": this.label, onKeyDown: this.handleKeyDown, ref: el => (this.tablistEl = el) }, this.tabs.map(tab => {
81
81
  const selected = tab.value === active;
82
82
  return (h("button", { key: tab.value, type: "button", class: { 'tab': true, 'tab--active': selected, 'tab--disabled': Boolean(tab.disabled) }, role: "tab", id: this.tabId(tab.value), "data-value": tab.value, "aria-selected": selected ? 'true' : 'false', "aria-controls": this.panelId(tab.value), tabIndex: selected ? FIRST_TAB_INDEX : LAST_TAB_INDEX, disabled: tab.disabled, onClick: () => this.select(tab.value) }, tab.label));
83
83
  })), this.tabs.map(tab => (h("div", { key: `${tab.value}-panel`, class: "tabpanel", id: this.panelId(tab.value), role: "tabpanel", "aria-labelledby": this.tabId(tab.value), tabIndex: FIRST_TAB_INDEX, hidden: tab.value !== active }, h("slot", { name: `panel-${tab.value}` }))))));
@@ -49,6 +49,17 @@
49
49
  box-shadow: 0 0 0 3px var(--color-status-warning-background);
50
50
  }
51
51
 
52
+ :host([data-touched]:invalid) .textarea,
53
+ :host(:user-invalid) .textarea {
54
+ border-color: var(--color-status-warning);
55
+ }
56
+
57
+ :host([data-touched]:invalid) .textarea:focus,
58
+ :host(:user-invalid) .textarea:focus {
59
+ border-color: var(--color-status-warning);
60
+ box-shadow: 0 0 0 3px var(--color-status-warning-background);
61
+ }
62
+
52
63
  .textarea:disabled {
53
64
  opacity: var(--opacity-disabled);
54
65
  cursor: not-allowed;