@devschile/chucao 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/chucao/chucao.css +2 -2
- package/dist/chucao/chucao.esm.js +1 -1
- package/dist/chucao/index.esm.js +1 -1
- package/dist/chucao/index.esm.js.map +1 -1
- package/dist/chucao/p-1f47dd08.entry.js +2 -0
- package/dist/chucao/p-1f47dd08.entry.js.map +1 -0
- package/dist/chucao/p-438e1401.entry.js +2 -0
- package/dist/chucao/p-438e1401.entry.js.map +1 -0
- package/dist/chucao/p-7413b8c3.entry.js +2 -0
- package/dist/chucao/p-7413b8c3.entry.js.map +1 -0
- package/dist/chucao/p-90db80a2.entry.js +2 -0
- package/dist/chucao/p-90db80a2.entry.js.map +1 -0
- package/dist/chucao/p-Bk9pvIKL.js +3 -0
- package/dist/chucao/p-Bk9pvIKL.js.map +1 -0
- package/dist/chucao/p-faa21ce0.entry.js +2 -0
- package/dist/chucao/p-faa21ce0.entry.js.map +1 -0
- package/dist/cjs/ch-badge_5.cjs.entry.js +57 -9
- package/dist/cjs/ch-badge_5.cjs.entry.js.map +1 -1
- package/dist/cjs/ch-checkbox.cjs.entry.js +80 -0
- package/dist/cjs/ch-checkbox.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-radio.cjs.entry.js +83 -0
- package/dist/cjs/ch-radio.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-switch.cjs.entry.js +80 -0
- package/dist/cjs/ch-switch.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-textarea.cjs.entry.js +94 -0
- package/dist/cjs/ch-textarea.cjs.entry.js.map +1 -0
- package/dist/cjs/chucao.cjs.js +2 -2
- package/dist/cjs/{index-Tiana_FZ.js → index-DX3RZKi8.js} +6 -3
- package/dist/cjs/index-DX3RZKi8.js.map +1 -0
- package/dist/cjs/index.cjs.js +148 -7
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/collection/collection-manifest.json +5 -1
- package/dist/collection/components/ch-badge/ch-badge.css +5 -5
- package/dist/collection/components/ch-button/ch-button.css +19 -19
- package/dist/collection/components/ch-card/ch-card.css +10 -10
- package/dist/collection/components/ch-card/ch-card.js +1 -1
- package/dist/collection/components/ch-checkbox/ch-checkbox.css +79 -0
- package/dist/collection/components/ch-checkbox/ch-checkbox.js +276 -0
- package/dist/collection/components/ch-checkbox/ch-checkbox.js.map +1 -0
- package/dist/collection/components/ch-input/ch-input.css +30 -10
- package/dist/collection/components/ch-input/ch-input.js +83 -1
- package/dist/collection/components/ch-input/ch-input.js.map +1 -1
- package/dist/collection/components/ch-radio/ch-radio.css +89 -0
- package/dist/collection/components/ch-radio/ch-radio.js +282 -0
- package/dist/collection/components/ch-radio/ch-radio.js.map +1 -0
- package/dist/collection/components/ch-select/ch-select.css +30 -10
- package/dist/collection/components/ch-select/ch-select.js +83 -1
- package/dist/collection/components/ch-select/ch-select.js.map +1 -1
- package/dist/collection/components/ch-switch/ch-switch.css +92 -0
- package/dist/collection/components/ch-switch/ch-switch.js +276 -0
- package/dist/collection/components/ch-switch/ch-switch.js.map +1 -0
- package/dist/collection/components/ch-textarea/ch-textarea.css +66 -0
- package/dist/collection/components/ch-textarea/ch-textarea.js +323 -0
- package/dist/collection/components/ch-textarea/ch-textarea.js.map +1 -0
- package/dist/collection/tokens/tokens.js +108 -6
- package/dist/collection/tokens/tokens.js.map +1 -1
- package/dist/collection/tokens/types.js.map +1 -1
- package/dist/components/ch-badge.js +1 -1
- package/dist/components/ch-badge.js.map +1 -1
- package/dist/components/ch-button.js +1 -1
- package/dist/components/ch-button.js.map +1 -1
- package/dist/components/ch-card.js +1 -1
- package/dist/components/ch-card.js.map +1 -1
- package/dist/components/ch-checkbox.d.ts +11 -0
- package/dist/components/ch-checkbox.js +2 -0
- package/dist/components/ch-checkbox.js.map +1 -0
- package/dist/components/ch-input.js +1 -1
- package/dist/components/ch-input.js.map +1 -1
- package/dist/components/ch-radio.d.ts +11 -0
- package/dist/components/ch-radio.js +2 -0
- package/dist/components/ch-radio.js.map +1 -0
- package/dist/components/ch-select.js +1 -1
- package/dist/components/ch-select.js.map +1 -1
- package/dist/components/ch-switch.d.ts +11 -0
- package/dist/components/ch-switch.js +2 -0
- package/dist/components/ch-switch.js.map +1 -0
- package/dist/components/ch-textarea.d.ts +11 -0
- package/dist/components/ch-textarea.js +2 -0
- package/dist/components/ch-textarea.js.map +1 -0
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/p-CcEsJ4Ml.js +2 -0
- package/dist/components/p-CcEsJ4Ml.js.map +1 -0
- package/dist/esm/ch-badge_5.entry.js +57 -9
- package/dist/esm/ch-badge_5.entry.js.map +1 -1
- package/dist/esm/ch-checkbox.entry.js +78 -0
- package/dist/esm/ch-checkbox.entry.js.map +1 -0
- package/dist/esm/ch-radio.entry.js +81 -0
- package/dist/esm/ch-radio.entry.js.map +1 -0
- package/dist/esm/ch-switch.entry.js +78 -0
- package/dist/esm/ch-switch.entry.js.map +1 -0
- package/dist/esm/ch-textarea.entry.js +92 -0
- package/dist/esm/ch-textarea.entry.js.map +1 -0
- package/dist/esm/chucao.js +3 -3
- package/dist/esm/{index-CuWheDah.js → index-Bk9pvIKL.js} +6 -3
- package/dist/esm/index-Bk9pvIKL.js.map +1 -0
- package/dist/esm/index.js +109 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/loader.js +3 -3
- package/dist/types/components/ch-checkbox/ch-checkbox.d.ts +51 -0
- package/dist/types/components/ch-input/ch-input.d.ts +16 -0
- package/dist/types/components/ch-radio/ch-radio.d.ts +58 -0
- package/dist/types/components/ch-select/ch-select.d.ts +16 -0
- package/dist/types/components/ch-switch/ch-switch.d.ts +51 -0
- package/dist/types/components/ch-textarea/ch-textarea.d.ts +60 -0
- package/dist/types/components.d.ts +571 -0
- package/dist/types/tokens/tokens.d.ts +104 -2
- package/dist/types/tokens/types.d.ts +13 -4
- package/dist-react/components.d.ts +22 -1
- package/dist-react/components.js +39 -0
- package/dist-react/components.ts +55 -1
- package/dist-vue/index.d.ts +4 -0
- package/dist-vue/index.js +69 -0
- package/dist-vue/index.ts +77 -0
- package/package.json +2 -1
- package/dist/chucao/p-035c479d.entry.js +0 -2
- package/dist/chucao/p-035c479d.entry.js.map +0 -1
- package/dist/chucao/p-CuWheDah.js +0 -3
- package/dist/chucao/p-CuWheDah.js.map +0 -1
- package/dist/cjs/index-Tiana_FZ.js.map +0 -1
- package/dist/components/p-DXg-7eP0.js +0 -2
- package/dist/components/p-DXg-7eP0.js.map +0 -1
- package/dist/esm/index-CuWheDah.js.map +0 -1
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { Host, h } from "@stencil/core";
|
|
2
|
+
let radioIds = 0;
|
|
3
|
+
export class ChRadio {
|
|
4
|
+
groupId = `ch-radio-${++radioIds}`;
|
|
5
|
+
labelId = `${this.groupId}-label`;
|
|
6
|
+
hintId = `${this.groupId}-hint`;
|
|
7
|
+
errorId = `${this.groupId}-error`;
|
|
8
|
+
/**
|
|
9
|
+
* Visible label describing the radio group, associated with it via
|
|
10
|
+
* `aria-labelledby`.
|
|
11
|
+
*/
|
|
12
|
+
label;
|
|
13
|
+
/**
|
|
14
|
+
* The list of options rendered as radio inputs.
|
|
15
|
+
*/
|
|
16
|
+
options = [];
|
|
17
|
+
/**
|
|
18
|
+
* The value of the selected option.
|
|
19
|
+
*/
|
|
20
|
+
value;
|
|
21
|
+
/**
|
|
22
|
+
* The name shared by all radio inputs in the group. Defaults to an
|
|
23
|
+
* auto-generated group name so options are mutually exclusive out of the box.
|
|
24
|
+
*/
|
|
25
|
+
name;
|
|
26
|
+
/**
|
|
27
|
+
* Whether all radios in the group are disabled.
|
|
28
|
+
*/
|
|
29
|
+
disabled = false;
|
|
30
|
+
/**
|
|
31
|
+
* Whether a value is required.
|
|
32
|
+
*/
|
|
33
|
+
required = false;
|
|
34
|
+
/**
|
|
35
|
+
* Helper text rendered below the radio group, associated via `aria-describedby`.
|
|
36
|
+
* Replaced by `errorMessage` when the group is invalid.
|
|
37
|
+
*/
|
|
38
|
+
hint;
|
|
39
|
+
/**
|
|
40
|
+
* Error message rendered below the radio group when it is invalid.
|
|
41
|
+
*/
|
|
42
|
+
errorMessage;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the radio group is in an invalid state; toggles `aria-invalid` and error styling.
|
|
45
|
+
*/
|
|
46
|
+
invalid = false;
|
|
47
|
+
/**
|
|
48
|
+
* Emitted when a new option is selected, with the selected value.
|
|
49
|
+
*/
|
|
50
|
+
chChange;
|
|
51
|
+
handleChange = (ev) => {
|
|
52
|
+
this.value = ev.target.value;
|
|
53
|
+
this.chChange.emit(this.value);
|
|
54
|
+
};
|
|
55
|
+
get describedBy() {
|
|
56
|
+
if (this.invalid && this.errorMessage) {
|
|
57
|
+
return this.errorId;
|
|
58
|
+
}
|
|
59
|
+
if (this.hint) {
|
|
60
|
+
return this.hintId;
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
render() {
|
|
65
|
+
const groupName = this.name || `${this.groupId}-group`;
|
|
66
|
+
return (h(Host, { key: '78354233a89d8f4320ffdeb4e69b5dd1d91fdaad' }, this.label && (h("span", { key: '6cf69bc65e3bca7a05b27f381e867d0c6d6b7e6f', class: "group-label", id: this.labelId }, this.label)), h("div", { key: '94b72878f2c8a88ed9a7a5b6fe0a295f8211b177', 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: '90e59f8b755d6ab2495ebd8c03ceb8f66bba8b0b', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: 'e521768e3a0649406e559865ab4f7f58bbfacadc', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
|
|
67
|
+
}
|
|
68
|
+
static get is() { return "ch-radio"; }
|
|
69
|
+
static get encapsulation() { return "shadow"; }
|
|
70
|
+
static get originalStyleUrls() {
|
|
71
|
+
return {
|
|
72
|
+
"$": ["ch-radio.css"]
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
static get styleUrls() {
|
|
76
|
+
return {
|
|
77
|
+
"$": ["ch-radio.css"]
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
static get properties() {
|
|
81
|
+
return {
|
|
82
|
+
"label": {
|
|
83
|
+
"type": "string",
|
|
84
|
+
"mutable": false,
|
|
85
|
+
"complexType": {
|
|
86
|
+
"original": "string",
|
|
87
|
+
"resolved": "string",
|
|
88
|
+
"references": {}
|
|
89
|
+
},
|
|
90
|
+
"required": false,
|
|
91
|
+
"optional": true,
|
|
92
|
+
"docs": {
|
|
93
|
+
"tags": [],
|
|
94
|
+
"text": "Visible label describing the radio group, associated with it via\n`aria-labelledby`."
|
|
95
|
+
},
|
|
96
|
+
"getter": false,
|
|
97
|
+
"setter": false,
|
|
98
|
+
"reflect": false,
|
|
99
|
+
"attribute": "label"
|
|
100
|
+
},
|
|
101
|
+
"options": {
|
|
102
|
+
"type": "unknown",
|
|
103
|
+
"mutable": false,
|
|
104
|
+
"complexType": {
|
|
105
|
+
"original": "ChRadioOption[]",
|
|
106
|
+
"resolved": "ChRadioOption[]",
|
|
107
|
+
"references": {
|
|
108
|
+
"ChRadioOption": {
|
|
109
|
+
"location": "local",
|
|
110
|
+
"path": "/home/runner/work/chucao/chucao/src/components/ch-radio/ch-radio.tsx",
|
|
111
|
+
"id": "src/components/ch-radio/ch-radio.tsx::ChRadioOption"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"required": false,
|
|
116
|
+
"optional": false,
|
|
117
|
+
"docs": {
|
|
118
|
+
"tags": [],
|
|
119
|
+
"text": "The list of options rendered as radio inputs."
|
|
120
|
+
},
|
|
121
|
+
"getter": false,
|
|
122
|
+
"setter": false,
|
|
123
|
+
"defaultValue": "[]"
|
|
124
|
+
},
|
|
125
|
+
"value": {
|
|
126
|
+
"type": "string",
|
|
127
|
+
"mutable": true,
|
|
128
|
+
"complexType": {
|
|
129
|
+
"original": "string",
|
|
130
|
+
"resolved": "string",
|
|
131
|
+
"references": {}
|
|
132
|
+
},
|
|
133
|
+
"required": false,
|
|
134
|
+
"optional": true,
|
|
135
|
+
"docs": {
|
|
136
|
+
"tags": [],
|
|
137
|
+
"text": "The value of the selected option."
|
|
138
|
+
},
|
|
139
|
+
"getter": false,
|
|
140
|
+
"setter": false,
|
|
141
|
+
"reflect": false,
|
|
142
|
+
"attribute": "value"
|
|
143
|
+
},
|
|
144
|
+
"name": {
|
|
145
|
+
"type": "string",
|
|
146
|
+
"mutable": false,
|
|
147
|
+
"complexType": {
|
|
148
|
+
"original": "string",
|
|
149
|
+
"resolved": "string",
|
|
150
|
+
"references": {}
|
|
151
|
+
},
|
|
152
|
+
"required": false,
|
|
153
|
+
"optional": true,
|
|
154
|
+
"docs": {
|
|
155
|
+
"tags": [],
|
|
156
|
+
"text": "The name shared by all radio inputs in the group. Defaults to an\nauto-generated group name so options are mutually exclusive out of the box."
|
|
157
|
+
},
|
|
158
|
+
"getter": false,
|
|
159
|
+
"setter": false,
|
|
160
|
+
"reflect": false,
|
|
161
|
+
"attribute": "name"
|
|
162
|
+
},
|
|
163
|
+
"disabled": {
|
|
164
|
+
"type": "boolean",
|
|
165
|
+
"mutable": false,
|
|
166
|
+
"complexType": {
|
|
167
|
+
"original": "boolean",
|
|
168
|
+
"resolved": "boolean",
|
|
169
|
+
"references": {}
|
|
170
|
+
},
|
|
171
|
+
"required": false,
|
|
172
|
+
"optional": false,
|
|
173
|
+
"docs": {
|
|
174
|
+
"tags": [],
|
|
175
|
+
"text": "Whether all radios in the group are disabled."
|
|
176
|
+
},
|
|
177
|
+
"getter": false,
|
|
178
|
+
"setter": false,
|
|
179
|
+
"reflect": false,
|
|
180
|
+
"attribute": "disabled",
|
|
181
|
+
"defaultValue": "false"
|
|
182
|
+
},
|
|
183
|
+
"required": {
|
|
184
|
+
"type": "boolean",
|
|
185
|
+
"mutable": false,
|
|
186
|
+
"complexType": {
|
|
187
|
+
"original": "boolean",
|
|
188
|
+
"resolved": "boolean",
|
|
189
|
+
"references": {}
|
|
190
|
+
},
|
|
191
|
+
"required": false,
|
|
192
|
+
"optional": false,
|
|
193
|
+
"docs": {
|
|
194
|
+
"tags": [],
|
|
195
|
+
"text": "Whether a value is required."
|
|
196
|
+
},
|
|
197
|
+
"getter": false,
|
|
198
|
+
"setter": false,
|
|
199
|
+
"reflect": false,
|
|
200
|
+
"attribute": "required",
|
|
201
|
+
"defaultValue": "false"
|
|
202
|
+
},
|
|
203
|
+
"hint": {
|
|
204
|
+
"type": "string",
|
|
205
|
+
"mutable": false,
|
|
206
|
+
"complexType": {
|
|
207
|
+
"original": "string",
|
|
208
|
+
"resolved": "string",
|
|
209
|
+
"references": {}
|
|
210
|
+
},
|
|
211
|
+
"required": false,
|
|
212
|
+
"optional": true,
|
|
213
|
+
"docs": {
|
|
214
|
+
"tags": [],
|
|
215
|
+
"text": "Helper text rendered below the radio group, associated via `aria-describedby`.\nReplaced by `errorMessage` when the group is invalid."
|
|
216
|
+
},
|
|
217
|
+
"getter": false,
|
|
218
|
+
"setter": false,
|
|
219
|
+
"reflect": false,
|
|
220
|
+
"attribute": "hint"
|
|
221
|
+
},
|
|
222
|
+
"errorMessage": {
|
|
223
|
+
"type": "string",
|
|
224
|
+
"mutable": false,
|
|
225
|
+
"complexType": {
|
|
226
|
+
"original": "string",
|
|
227
|
+
"resolved": "string",
|
|
228
|
+
"references": {}
|
|
229
|
+
},
|
|
230
|
+
"required": false,
|
|
231
|
+
"optional": true,
|
|
232
|
+
"docs": {
|
|
233
|
+
"tags": [],
|
|
234
|
+
"text": "Error message rendered below the radio group when it is invalid."
|
|
235
|
+
},
|
|
236
|
+
"getter": false,
|
|
237
|
+
"setter": false,
|
|
238
|
+
"reflect": false,
|
|
239
|
+
"attribute": "error-message"
|
|
240
|
+
},
|
|
241
|
+
"invalid": {
|
|
242
|
+
"type": "boolean",
|
|
243
|
+
"mutable": false,
|
|
244
|
+
"complexType": {
|
|
245
|
+
"original": "boolean",
|
|
246
|
+
"resolved": "boolean",
|
|
247
|
+
"references": {}
|
|
248
|
+
},
|
|
249
|
+
"required": false,
|
|
250
|
+
"optional": false,
|
|
251
|
+
"docs": {
|
|
252
|
+
"tags": [],
|
|
253
|
+
"text": "Whether the radio group is in an invalid state; toggles `aria-invalid` and error styling."
|
|
254
|
+
},
|
|
255
|
+
"getter": false,
|
|
256
|
+
"setter": false,
|
|
257
|
+
"reflect": false,
|
|
258
|
+
"attribute": "invalid",
|
|
259
|
+
"defaultValue": "false"
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
static get events() {
|
|
264
|
+
return [{
|
|
265
|
+
"method": "chChange",
|
|
266
|
+
"name": "chChange",
|
|
267
|
+
"bubbles": true,
|
|
268
|
+
"cancelable": true,
|
|
269
|
+
"composed": true,
|
|
270
|
+
"docs": {
|
|
271
|
+
"tags": [],
|
|
272
|
+
"text": "Emitted when a new option is selected, with the selected value."
|
|
273
|
+
},
|
|
274
|
+
"complexType": {
|
|
275
|
+
"original": "string",
|
|
276
|
+
"resolved": "string",
|
|
277
|
+
"references": {}
|
|
278
|
+
}
|
|
279
|
+
}];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=ch-radio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ch-radio.js","sourceRoot":"","sources":["../../../../src/components/ch-radio/ch-radio.tsx"],"names":[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AG,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 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"]}
|
|
@@ -5,37 +5,46 @@
|
|
|
5
5
|
|
|
6
6
|
.label {
|
|
7
7
|
display: block;
|
|
8
|
-
margin-bottom:
|
|
9
|
-
font-size:
|
|
10
|
-
font-weight:
|
|
8
|
+
margin-bottom: var(--spacing-sm);
|
|
9
|
+
font-size: var(--typography-size-sm);
|
|
10
|
+
font-weight: var(--typography-weight-semibold);
|
|
11
11
|
color: var(--text);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
.select {
|
|
15
15
|
box-sizing: border-box;
|
|
16
16
|
width: 100%;
|
|
17
|
-
padding:
|
|
17
|
+
padding: var(--spacing-xl) var(--spacing-3xl);
|
|
18
18
|
border-radius: var(--radius);
|
|
19
|
-
border:
|
|
19
|
+
border: var(--border-width) solid var(--border);
|
|
20
20
|
background: var(--surface);
|
|
21
21
|
color: var(--text);
|
|
22
|
-
backdrop-filter: blur(
|
|
22
|
+
backdrop-filter: blur(var(--effect-blur));
|
|
23
23
|
font-family: inherit;
|
|
24
24
|
font-size: inherit;
|
|
25
25
|
cursor: pointer;
|
|
26
26
|
transition:
|
|
27
|
-
border-color
|
|
28
|
-
box-shadow
|
|
27
|
+
border-color var(--duration-normal) var(--easing-default),
|
|
28
|
+
box-shadow var(--duration-normal) var(--easing-default);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
.select:focus {
|
|
32
32
|
border-color: var(--accent);
|
|
33
|
-
box-shadow:
|
|
33
|
+
box-shadow: var(--shadow-focus-ring);
|
|
34
34
|
outline: none;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
.select--invalid {
|
|
38
|
+
border-color: var(--color-status-warning);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.select--invalid:focus {
|
|
42
|
+
border-color: var(--color-status-warning);
|
|
43
|
+
box-shadow: 0 0 0 3px var(--color-status-warning-background);
|
|
44
|
+
}
|
|
45
|
+
|
|
37
46
|
.select:disabled {
|
|
38
|
-
opacity:
|
|
47
|
+
opacity: var(--opacity-disabled);
|
|
39
48
|
cursor: not-allowed;
|
|
40
49
|
}
|
|
41
50
|
|
|
@@ -43,3 +52,14 @@
|
|
|
43
52
|
background: var(--bg);
|
|
44
53
|
color: var(--text);
|
|
45
54
|
}
|
|
55
|
+
|
|
56
|
+
.hint,
|
|
57
|
+
.error {
|
|
58
|
+
margin: var(--spacing-sm) 0 0;
|
|
59
|
+
font-size: var(--typography-size-sm);
|
|
60
|
+
color: var(--text-muted);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.error {
|
|
64
|
+
color: var(--color-status-warning);
|
|
65
|
+
}
|
|
@@ -2,6 +2,8 @@ import { Host, h } from "@stencil/core";
|
|
|
2
2
|
let selectIds = 0;
|
|
3
3
|
export class ChSelect {
|
|
4
4
|
selectId = `ch-select-${++selectIds}`;
|
|
5
|
+
hintId = `${this.selectId}-hint`;
|
|
6
|
+
errorId = `${this.selectId}-error`;
|
|
5
7
|
/**
|
|
6
8
|
* Visible label rendered above the select and associated with it via
|
|
7
9
|
* `for`/`id`, so assistive technology announces the select's purpose.
|
|
@@ -31,6 +33,19 @@ export class ChSelect {
|
|
|
31
33
|
* Whether a value is required.
|
|
32
34
|
*/
|
|
33
35
|
required = false;
|
|
36
|
+
/**
|
|
37
|
+
* Helper text rendered below the select, associated via `aria-describedby`.
|
|
38
|
+
* Replaced by `errorMessage` when the select is invalid.
|
|
39
|
+
*/
|
|
40
|
+
hint;
|
|
41
|
+
/**
|
|
42
|
+
* Error message rendered below the select when it is invalid.
|
|
43
|
+
*/
|
|
44
|
+
errorMessage;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the select is in an invalid state; toggles `aria-invalid` and error styling.
|
|
47
|
+
*/
|
|
48
|
+
invalid = false;
|
|
34
49
|
/**
|
|
35
50
|
* Emitted when the selected option changes, with the new value.
|
|
36
51
|
*/
|
|
@@ -39,8 +54,17 @@ export class ChSelect {
|
|
|
39
54
|
this.value = ev.target.value;
|
|
40
55
|
this.chChange.emit(this.value);
|
|
41
56
|
};
|
|
57
|
+
get describedBy() {
|
|
58
|
+
if (this.invalid && this.errorMessage) {
|
|
59
|
+
return this.errorId;
|
|
60
|
+
}
|
|
61
|
+
if (this.hint) {
|
|
62
|
+
return this.hintId;
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
42
66
|
render() {
|
|
43
|
-
return (h(Host, { key: '
|
|
67
|
+
return (h(Host, { key: '7a316b55bd8d0d4607d1a9aff7819e499e415f13' }, this.label && (h("label", { key: 'e2c68bb372d2dd88777246f8d6120b8012a42da3', class: "label", htmlFor: this.selectId }, this.label)), h("select", { key: '711f8c5b9d3cd982d8c8c15c8d08f565420095cd', 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: 'a53a31954fa04883146a398d6f9915f3ee11a980', 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: 'b9fa0075f675cd50ab2a858a6ab8a39147b107cb', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '33292fc016300df2a1716390fd7920c9c7d1dd5c', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
|
|
44
68
|
}
|
|
45
69
|
static get is() { return "ch-select"; }
|
|
46
70
|
static get encapsulation() { return "shadow"; }
|
|
@@ -195,6 +219,64 @@ export class ChSelect {
|
|
|
195
219
|
"reflect": false,
|
|
196
220
|
"attribute": "required",
|
|
197
221
|
"defaultValue": "false"
|
|
222
|
+
},
|
|
223
|
+
"hint": {
|
|
224
|
+
"type": "string",
|
|
225
|
+
"mutable": false,
|
|
226
|
+
"complexType": {
|
|
227
|
+
"original": "string",
|
|
228
|
+
"resolved": "string",
|
|
229
|
+
"references": {}
|
|
230
|
+
},
|
|
231
|
+
"required": false,
|
|
232
|
+
"optional": true,
|
|
233
|
+
"docs": {
|
|
234
|
+
"tags": [],
|
|
235
|
+
"text": "Helper text rendered below the select, associated via `aria-describedby`.\nReplaced by `errorMessage` when the select is invalid."
|
|
236
|
+
},
|
|
237
|
+
"getter": false,
|
|
238
|
+
"setter": false,
|
|
239
|
+
"reflect": false,
|
|
240
|
+
"attribute": "hint"
|
|
241
|
+
},
|
|
242
|
+
"errorMessage": {
|
|
243
|
+
"type": "string",
|
|
244
|
+
"mutable": false,
|
|
245
|
+
"complexType": {
|
|
246
|
+
"original": "string",
|
|
247
|
+
"resolved": "string",
|
|
248
|
+
"references": {}
|
|
249
|
+
},
|
|
250
|
+
"required": false,
|
|
251
|
+
"optional": true,
|
|
252
|
+
"docs": {
|
|
253
|
+
"tags": [],
|
|
254
|
+
"text": "Error message rendered below the select when it is invalid."
|
|
255
|
+
},
|
|
256
|
+
"getter": false,
|
|
257
|
+
"setter": false,
|
|
258
|
+
"reflect": false,
|
|
259
|
+
"attribute": "error-message"
|
|
260
|
+
},
|
|
261
|
+
"invalid": {
|
|
262
|
+
"type": "boolean",
|
|
263
|
+
"mutable": false,
|
|
264
|
+
"complexType": {
|
|
265
|
+
"original": "boolean",
|
|
266
|
+
"resolved": "boolean",
|
|
267
|
+
"references": {}
|
|
268
|
+
},
|
|
269
|
+
"required": false,
|
|
270
|
+
"optional": false,
|
|
271
|
+
"docs": {
|
|
272
|
+
"tags": [],
|
|
273
|
+
"text": "Whether the select is in an invalid state; toggles `aria-invalid` and error styling."
|
|
274
|
+
},
|
|
275
|
+
"getter": false,
|
|
276
|
+
"setter": false,
|
|
277
|
+
"reflect": false,
|
|
278
|
+
"attribute": "invalid",
|
|
279
|
+
"defaultValue": "false"
|
|
198
280
|
}
|
|
199
281
|
};
|
|
200
282
|
}
|
|
@@ -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;I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AAC,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"]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.control {
|
|
6
|
+
position: relative;
|
|
7
|
+
display: inline-flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
gap: var(--spacing-lg);
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.control--disabled {
|
|
14
|
+
opacity: var(--opacity-disabled);
|
|
15
|
+
cursor: not-allowed;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.input {
|
|
19
|
+
position: absolute;
|
|
20
|
+
inset: 0;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
margin: 0;
|
|
24
|
+
opacity: 0;
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.input:focus-visible ~ .track {
|
|
29
|
+
outline: var(--focus-outline-width) solid var(--accent);
|
|
30
|
+
outline-offset: var(--focus-outline-offset);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.track {
|
|
34
|
+
position: relative;
|
|
35
|
+
box-sizing: border-box;
|
|
36
|
+
width: var(--spacing-6xl);
|
|
37
|
+
height: var(--spacing-5xl);
|
|
38
|
+
flex-shrink: 0;
|
|
39
|
+
border: var(--border-width) solid var(--border);
|
|
40
|
+
border-radius: var(--radius-pill);
|
|
41
|
+
background: var(--surface);
|
|
42
|
+
transition:
|
|
43
|
+
border-color var(--duration-normal) var(--easing-default),
|
|
44
|
+
background-color var(--duration-normal) var(--easing-default);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.thumb {
|
|
48
|
+
position: absolute;
|
|
49
|
+
top: 50%;
|
|
50
|
+
left: var(--spacing-2xs);
|
|
51
|
+
width: var(--spacing-2xl);
|
|
52
|
+
height: var(--spacing-2xl);
|
|
53
|
+
border-radius: 50%;
|
|
54
|
+
background: var(--text-muted);
|
|
55
|
+
transform: translateY(-50%);
|
|
56
|
+
transition:
|
|
57
|
+
left var(--duration-normal) var(--easing-default),
|
|
58
|
+
background-color var(--duration-normal) var(--easing-default);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.input:checked ~ .track {
|
|
62
|
+
border-color: var(--accent);
|
|
63
|
+
background: var(--accent);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.input:checked ~ .track + .thumb {
|
|
67
|
+
left: calc(100% - var(--spacing-2xl) - var(--spacing-2xs));
|
|
68
|
+
background: var(--color-accent-text);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.input--invalid ~ .track {
|
|
72
|
+
border-color: var(--color-status-warning);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.input--invalid:focus-visible ~ .track {
|
|
76
|
+
outline-color: var(--color-status-warning);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.label-text {
|
|
80
|
+
color: var(--text);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.hint,
|
|
84
|
+
.error {
|
|
85
|
+
margin: var(--spacing-sm) 0 0;
|
|
86
|
+
font-size: var(--typography-size-sm);
|
|
87
|
+
color: var(--text-muted);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.error {
|
|
91
|
+
color: var(--color-status-warning);
|
|
92
|
+
}
|