@devschile/chucao 1.3.0 → 1.5.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 +3 -0
- package/dist/chucao/chucao.esm.js +1 -1
- package/dist/chucao/p-12e02f8e.entry.js +2 -0
- package/dist/chucao/p-12e02f8e.entry.js.map +1 -0
- package/dist/chucao/p-21fa1897.entry.js +2 -0
- package/dist/chucao/p-21fa1897.entry.js.map +1 -0
- package/dist/chucao/p-5c5048cf.entry.js +2 -0
- package/dist/chucao/p-5c5048cf.entry.js.map +1 -0
- package/dist/chucao/p-5df14f4b.entry.js +2 -0
- package/dist/chucao/p-5df14f4b.entry.js.map +1 -0
- package/dist/chucao/p-5e0ba154.entry.js +2 -0
- package/dist/chucao/p-5e0ba154.entry.js.map +1 -0
- package/dist/chucao/p-C_GZnvOi.js +3 -0
- package/dist/chucao/p-C_GZnvOi.js.map +1 -0
- package/dist/chucao/p-bd015077.entry.js +2 -0
- package/dist/chucao/p-bd015077.entry.js.map +1 -0
- package/dist/chucao/p-ca96fa8a.entry.js +2 -0
- package/dist/chucao/p-ca96fa8a.entry.js.map +1 -0
- package/dist/chucao/p-ccae6c46.entry.js +2 -0
- package/dist/chucao/p-ccae6c46.entry.js.map +1 -0
- package/dist/chucao/p-ecf098bb.entry.js +2 -0
- package/dist/chucao/p-ecf098bb.entry.js.map +1 -0
- package/dist/cjs/ch-accordion.cjs.entry.js +48 -0
- package/dist/cjs/ch-accordion.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-badge_5.cjs.entry.js +56 -8
- 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-divider.cjs.entry.js +24 -0
- package/dist/cjs/ch-divider.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-link.cjs.entry.js +49 -0
- package/dist/cjs/ch-link.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-tabs.cjs.entry.js +100 -0
- package/dist/cjs/ch-tabs.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-yB1Ik3Sa.js → index-Ha3VDOML.js} +35 -3
- package/dist/cjs/index-Ha3VDOML.js.map +1 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/collection/collection-manifest.json +9 -1
- package/dist/collection/components/ch-accordion/ch-accordion.css +72 -0
- package/dist/collection/components/ch-accordion/ch-accordion.js +111 -0
- package/dist/collection/components/ch-accordion/ch-accordion.js.map +1 -0
- package/dist/collection/components/ch-badge/ch-badge.js +1 -1
- package/dist/collection/components/ch-button/ch-button.js +1 -1
- 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-divider/ch-divider.css +25 -0
- package/dist/collection/components/ch-divider/ch-divider.js +53 -0
- package/dist/collection/components/ch-divider/ch-divider.js.map +1 -0
- package/dist/collection/components/ch-input/ch-input.css +20 -0
- 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-link/ch-link.css +40 -0
- package/dist/collection/components/ch-link/ch-link.js +158 -0
- package/dist/collection/components/ch-link/ch-link.js.map +1 -0
- 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 +20 -0
- 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-tabs/ch-tabs.css +69 -0
- package/dist/collection/components/ch-tabs/ch-tabs.js +182 -0
- package/dist/collection/components/ch-tabs/ch-tabs.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/components/ch-accordion.d.ts +11 -0
- package/dist/components/ch-accordion.js +2 -0
- package/dist/components/ch-accordion.js.map +1 -0
- package/dist/components/ch-badge.js +1 -1
- package/dist/components/ch-button.js +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-divider.d.ts +11 -0
- package/dist/components/ch-divider.js +2 -0
- package/dist/components/ch-divider.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-link.d.ts +11 -0
- package/dist/components/ch-link.js +2 -0
- package/dist/components/ch-link.js.map +1 -0
- 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-tabs.d.ts +11 -0
- package/dist/components/ch-tabs.js +2 -0
- package/dist/components/ch-tabs.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/p-C3Jfy_hI.js +2 -0
- package/dist/components/p-C3Jfy_hI.js.map +1 -0
- package/dist/esm/ch-accordion.entry.js +46 -0
- package/dist/esm/ch-accordion.entry.js.map +1 -0
- package/dist/esm/ch-badge_5.entry.js +56 -8
- 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-divider.entry.js +22 -0
- package/dist/esm/ch-divider.entry.js.map +1 -0
- package/dist/esm/ch-link.entry.js +47 -0
- package/dist/esm/ch-link.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-tabs.entry.js +98 -0
- package/dist/esm/ch-tabs.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-COo5t8-6.js → index-C_GZnvOi.js} +35 -3
- package/dist/esm/index-C_GZnvOi.js.map +1 -0
- package/dist/esm/loader.js +3 -3
- package/dist/types/components/ch-accordion/ch-accordion.d.ts +25 -0
- package/dist/types/components/ch-checkbox/ch-checkbox.d.ts +51 -0
- package/dist/types/components/ch-divider/ch-divider.d.ts +8 -0
- package/dist/types/components/ch-input/ch-input.d.ts +16 -0
- package/dist/types/components/ch-link/ch-link.d.ts +28 -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-tabs/ch-tabs.d.ts +34 -0
- package/dist/types/components/ch-textarea/ch-textarea.d.ts +60 -0
- package/dist/types/components.d.ts +794 -0
- package/dist-react/components.d.ts +40 -1
- package/dist-react/components.js +75 -0
- package/dist-react/components.ts +103 -1
- package/dist-vue/index.d.ts +8 -0
- package/dist-vue/index.js +100 -0
- package/dist-vue/index.ts +116 -0
- package/package.json +1 -1
- package/dist/chucao/p-94a2b1be.entry.js +0 -2
- package/dist/chucao/p-94a2b1be.entry.js.map +0 -1
- package/dist/chucao/p-COo5t8-6.js +0 -3
- package/dist/chucao/p-COo5t8-6.js.map +0 -1
- package/dist/cjs/index-yB1Ik3Sa.js.map +0 -1
- package/dist/components/p-DCKzDjxR.js +0 -2
- package/dist/components/p-DCKzDjxR.js.map +0 -1
- package/dist/esm/index-COo5t8-6.js.map +0 -1
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { Host, h } from "@stencil/core";
|
|
2
|
+
let switchIds = 0;
|
|
3
|
+
export class ChSwitch {
|
|
4
|
+
switchId = `ch-switch-${++switchIds}`;
|
|
5
|
+
hintId = `${this.switchId}-hint`;
|
|
6
|
+
errorId = `${this.switchId}-error`;
|
|
7
|
+
/**
|
|
8
|
+
* Visible label rendered next to the switch, associated with it via
|
|
9
|
+
* `for`/`id`, so assistive technology announces the switch's purpose.
|
|
10
|
+
*/
|
|
11
|
+
label;
|
|
12
|
+
/**
|
|
13
|
+
* The name of the switch, submitted with form data.
|
|
14
|
+
*/
|
|
15
|
+
name;
|
|
16
|
+
/**
|
|
17
|
+
* The value of the switch, submitted with form data.
|
|
18
|
+
*/
|
|
19
|
+
value = 'on';
|
|
20
|
+
/**
|
|
21
|
+
* Whether the switch is on.
|
|
22
|
+
*/
|
|
23
|
+
checked = false;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the switch is disabled.
|
|
26
|
+
*/
|
|
27
|
+
disabled = false;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the switch is required.
|
|
30
|
+
*/
|
|
31
|
+
required = false;
|
|
32
|
+
/**
|
|
33
|
+
* Helper text rendered below the switch, associated via `aria-describedby`.
|
|
34
|
+
* Replaced by `errorMessage` when the switch is invalid.
|
|
35
|
+
*/
|
|
36
|
+
hint;
|
|
37
|
+
/**
|
|
38
|
+
* Error message rendered below the switch when it is invalid.
|
|
39
|
+
*/
|
|
40
|
+
errorMessage;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the switch is in an invalid state; toggles `aria-invalid` and error styling.
|
|
43
|
+
*/
|
|
44
|
+
invalid = false;
|
|
45
|
+
/**
|
|
46
|
+
* Emitted when the switch is toggled, with the new on/off state.
|
|
47
|
+
*/
|
|
48
|
+
chChange;
|
|
49
|
+
handleChange = (ev) => {
|
|
50
|
+
this.checked = ev.target.checked;
|
|
51
|
+
this.chChange.emit(this.checked);
|
|
52
|
+
};
|
|
53
|
+
get describedBy() {
|
|
54
|
+
if (this.invalid && this.errorMessage) {
|
|
55
|
+
return this.errorId;
|
|
56
|
+
}
|
|
57
|
+
if (this.hint) {
|
|
58
|
+
return this.hintId;
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
render() {
|
|
63
|
+
return (h(Host, { key: 'a2872e01803daa52a44e9ffe16e5c57ebd8f2a93' }, h("label", { key: 'fb94e4de3381b617a17b8aec2342ee5c72be775a', class: { 'control': true, 'control--disabled': this.disabled }, htmlFor: this.switchId }, h("input", { key: '4861655716af08d93965d78d98fe09a871ab409b', 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: 'e94675c142dd85c09d1e188a80cffc6978e98369', class: "track" }), h("span", { key: 'efe2a5e5123d47f9b0eafa88f8da49db64064205', class: "thumb" }), this.label && h("span", { key: '25813b7563ba7c4591ed06e95231977cb0c97147', class: "label-text" }, this.label)), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '00919d4ddc1e00b634dc917cdbe8fc68f1229a7f', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '799a59b00f93534a01b6eb0da04bf6457c8df725', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
|
|
64
|
+
}
|
|
65
|
+
static get is() { return "ch-switch"; }
|
|
66
|
+
static get encapsulation() { return "shadow"; }
|
|
67
|
+
static get originalStyleUrls() {
|
|
68
|
+
return {
|
|
69
|
+
"$": ["ch-switch.css"]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
static get styleUrls() {
|
|
73
|
+
return {
|
|
74
|
+
"$": ["ch-switch.css"]
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
static get properties() {
|
|
78
|
+
return {
|
|
79
|
+
"label": {
|
|
80
|
+
"type": "string",
|
|
81
|
+
"mutable": false,
|
|
82
|
+
"complexType": {
|
|
83
|
+
"original": "string",
|
|
84
|
+
"resolved": "string",
|
|
85
|
+
"references": {}
|
|
86
|
+
},
|
|
87
|
+
"required": false,
|
|
88
|
+
"optional": true,
|
|
89
|
+
"docs": {
|
|
90
|
+
"tags": [],
|
|
91
|
+
"text": "Visible label rendered next to the switch, associated with it via\n`for`/`id`, so assistive technology announces the switch's purpose."
|
|
92
|
+
},
|
|
93
|
+
"getter": false,
|
|
94
|
+
"setter": false,
|
|
95
|
+
"reflect": false,
|
|
96
|
+
"attribute": "label"
|
|
97
|
+
},
|
|
98
|
+
"name": {
|
|
99
|
+
"type": "string",
|
|
100
|
+
"mutable": false,
|
|
101
|
+
"complexType": {
|
|
102
|
+
"original": "string",
|
|
103
|
+
"resolved": "string",
|
|
104
|
+
"references": {}
|
|
105
|
+
},
|
|
106
|
+
"required": false,
|
|
107
|
+
"optional": true,
|
|
108
|
+
"docs": {
|
|
109
|
+
"tags": [],
|
|
110
|
+
"text": "The name of the switch, submitted with form data."
|
|
111
|
+
},
|
|
112
|
+
"getter": false,
|
|
113
|
+
"setter": false,
|
|
114
|
+
"reflect": false,
|
|
115
|
+
"attribute": "name"
|
|
116
|
+
},
|
|
117
|
+
"value": {
|
|
118
|
+
"type": "string",
|
|
119
|
+
"mutable": false,
|
|
120
|
+
"complexType": {
|
|
121
|
+
"original": "string",
|
|
122
|
+
"resolved": "string",
|
|
123
|
+
"references": {}
|
|
124
|
+
},
|
|
125
|
+
"required": false,
|
|
126
|
+
"optional": false,
|
|
127
|
+
"docs": {
|
|
128
|
+
"tags": [],
|
|
129
|
+
"text": "The value of the switch, submitted with form data."
|
|
130
|
+
},
|
|
131
|
+
"getter": false,
|
|
132
|
+
"setter": false,
|
|
133
|
+
"reflect": false,
|
|
134
|
+
"attribute": "value",
|
|
135
|
+
"defaultValue": "'on'"
|
|
136
|
+
},
|
|
137
|
+
"checked": {
|
|
138
|
+
"type": "boolean",
|
|
139
|
+
"mutable": true,
|
|
140
|
+
"complexType": {
|
|
141
|
+
"original": "boolean",
|
|
142
|
+
"resolved": "boolean",
|
|
143
|
+
"references": {}
|
|
144
|
+
},
|
|
145
|
+
"required": false,
|
|
146
|
+
"optional": false,
|
|
147
|
+
"docs": {
|
|
148
|
+
"tags": [],
|
|
149
|
+
"text": "Whether the switch is on."
|
|
150
|
+
},
|
|
151
|
+
"getter": false,
|
|
152
|
+
"setter": false,
|
|
153
|
+
"reflect": false,
|
|
154
|
+
"attribute": "checked",
|
|
155
|
+
"defaultValue": "false"
|
|
156
|
+
},
|
|
157
|
+
"disabled": {
|
|
158
|
+
"type": "boolean",
|
|
159
|
+
"mutable": false,
|
|
160
|
+
"complexType": {
|
|
161
|
+
"original": "boolean",
|
|
162
|
+
"resolved": "boolean",
|
|
163
|
+
"references": {}
|
|
164
|
+
},
|
|
165
|
+
"required": false,
|
|
166
|
+
"optional": false,
|
|
167
|
+
"docs": {
|
|
168
|
+
"tags": [],
|
|
169
|
+
"text": "Whether the switch is disabled."
|
|
170
|
+
},
|
|
171
|
+
"getter": false,
|
|
172
|
+
"setter": false,
|
|
173
|
+
"reflect": false,
|
|
174
|
+
"attribute": "disabled",
|
|
175
|
+
"defaultValue": "false"
|
|
176
|
+
},
|
|
177
|
+
"required": {
|
|
178
|
+
"type": "boolean",
|
|
179
|
+
"mutable": false,
|
|
180
|
+
"complexType": {
|
|
181
|
+
"original": "boolean",
|
|
182
|
+
"resolved": "boolean",
|
|
183
|
+
"references": {}
|
|
184
|
+
},
|
|
185
|
+
"required": false,
|
|
186
|
+
"optional": false,
|
|
187
|
+
"docs": {
|
|
188
|
+
"tags": [],
|
|
189
|
+
"text": "Whether the switch is required."
|
|
190
|
+
},
|
|
191
|
+
"getter": false,
|
|
192
|
+
"setter": false,
|
|
193
|
+
"reflect": false,
|
|
194
|
+
"attribute": "required",
|
|
195
|
+
"defaultValue": "false"
|
|
196
|
+
},
|
|
197
|
+
"hint": {
|
|
198
|
+
"type": "string",
|
|
199
|
+
"mutable": false,
|
|
200
|
+
"complexType": {
|
|
201
|
+
"original": "string",
|
|
202
|
+
"resolved": "string",
|
|
203
|
+
"references": {}
|
|
204
|
+
},
|
|
205
|
+
"required": false,
|
|
206
|
+
"optional": true,
|
|
207
|
+
"docs": {
|
|
208
|
+
"tags": [],
|
|
209
|
+
"text": "Helper text rendered below the switch, associated via `aria-describedby`.\nReplaced by `errorMessage` when the switch is invalid."
|
|
210
|
+
},
|
|
211
|
+
"getter": false,
|
|
212
|
+
"setter": false,
|
|
213
|
+
"reflect": false,
|
|
214
|
+
"attribute": "hint"
|
|
215
|
+
},
|
|
216
|
+
"errorMessage": {
|
|
217
|
+
"type": "string",
|
|
218
|
+
"mutable": false,
|
|
219
|
+
"complexType": {
|
|
220
|
+
"original": "string",
|
|
221
|
+
"resolved": "string",
|
|
222
|
+
"references": {}
|
|
223
|
+
},
|
|
224
|
+
"required": false,
|
|
225
|
+
"optional": true,
|
|
226
|
+
"docs": {
|
|
227
|
+
"tags": [],
|
|
228
|
+
"text": "Error message rendered below the switch when it is invalid."
|
|
229
|
+
},
|
|
230
|
+
"getter": false,
|
|
231
|
+
"setter": false,
|
|
232
|
+
"reflect": false,
|
|
233
|
+
"attribute": "error-message"
|
|
234
|
+
},
|
|
235
|
+
"invalid": {
|
|
236
|
+
"type": "boolean",
|
|
237
|
+
"mutable": false,
|
|
238
|
+
"complexType": {
|
|
239
|
+
"original": "boolean",
|
|
240
|
+
"resolved": "boolean",
|
|
241
|
+
"references": {}
|
|
242
|
+
},
|
|
243
|
+
"required": false,
|
|
244
|
+
"optional": false,
|
|
245
|
+
"docs": {
|
|
246
|
+
"tags": [],
|
|
247
|
+
"text": "Whether the switch is in an invalid state; toggles `aria-invalid` and error styling."
|
|
248
|
+
},
|
|
249
|
+
"getter": false,
|
|
250
|
+
"setter": false,
|
|
251
|
+
"reflect": false,
|
|
252
|
+
"attribute": "invalid",
|
|
253
|
+
"defaultValue": "false"
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
static get events() {
|
|
258
|
+
return [{
|
|
259
|
+
"method": "chChange",
|
|
260
|
+
"name": "chChange",
|
|
261
|
+
"bubbles": true,
|
|
262
|
+
"cancelable": true,
|
|
263
|
+
"composed": true,
|
|
264
|
+
"docs": {
|
|
265
|
+
"tags": [],
|
|
266
|
+
"text": "Emitted when the switch is toggled, with the new on/off state."
|
|
267
|
+
},
|
|
268
|
+
"complexType": {
|
|
269
|
+
"original": "boolean",
|
|
270
|
+
"resolved": "boolean",
|
|
271
|
+
"references": {}
|
|
272
|
+
}
|
|
273
|
+
}];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=ch-switch.js.map
|
|
@@ -0,0 +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,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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\"></span>\n <span class=\"thumb\"></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"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.tablist {
|
|
6
|
+
display: flex;
|
|
7
|
+
gap: var(--spacing-2xl);
|
|
8
|
+
border-bottom: var(--border-width) solid var(--border);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.tab {
|
|
12
|
+
appearance: none;
|
|
13
|
+
position: relative;
|
|
14
|
+
background: transparent;
|
|
15
|
+
border: none;
|
|
16
|
+
padding: var(--spacing-md) 0 var(--spacing-xl);
|
|
17
|
+
margin-bottom: calc(-1 * var(--border-width));
|
|
18
|
+
color: var(--text-muted);
|
|
19
|
+
font-family: inherit;
|
|
20
|
+
font-size: inherit;
|
|
21
|
+
font-weight: var(--typography-weight-semibold);
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
transition:
|
|
24
|
+
color var(--duration-normal) var(--easing-default),
|
|
25
|
+
border-color var(--duration-normal) var(--easing-default);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.tab::after {
|
|
29
|
+
content: '';
|
|
30
|
+
position: absolute;
|
|
31
|
+
left: 0;
|
|
32
|
+
right: 0;
|
|
33
|
+
bottom: 0;
|
|
34
|
+
height: var(--border-accent-bar);
|
|
35
|
+
background: var(--accent);
|
|
36
|
+
opacity: 0;
|
|
37
|
+
transition: opacity var(--duration-normal) var(--easing-default);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.tab:hover {
|
|
41
|
+
color: var(--text);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.tab:focus-visible {
|
|
45
|
+
outline: var(--focus-outline-width) solid var(--accent);
|
|
46
|
+
outline-offset: var(--focus-outline-offset);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.tab--active {
|
|
50
|
+
color: var(--text);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.tab--active::after {
|
|
54
|
+
opacity: 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.tab--disabled {
|
|
58
|
+
opacity: var(--opacity-disabled);
|
|
59
|
+
cursor: not-allowed;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.tabpanel {
|
|
63
|
+
padding-top: var(--spacing-2xl);
|
|
64
|
+
color: var(--text);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.tabpanel[hidden] {
|
|
68
|
+
display: none;
|
|
69
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Host, h } from "@stencil/core";
|
|
2
|
+
const FIRST_TAB_INDEX = 0;
|
|
3
|
+
const LAST_TAB_INDEX = -1;
|
|
4
|
+
const NEXT_TAB_OFFSET = 1;
|
|
5
|
+
const PREVIOUS_TAB_OFFSET = -1;
|
|
6
|
+
let tabsIds = 0;
|
|
7
|
+
export class ChTabs {
|
|
8
|
+
baseId = `ch-tabs-${++tabsIds}`;
|
|
9
|
+
tablistEl;
|
|
10
|
+
/**
|
|
11
|
+
* The list of tabs, each with a `label`, a `value`, and an optional `disabled` flag.
|
|
12
|
+
*/
|
|
13
|
+
tabs = [];
|
|
14
|
+
/**
|
|
15
|
+
* The value of the active tab. Defaults to the first enabled tab.
|
|
16
|
+
*/
|
|
17
|
+
value;
|
|
18
|
+
/**
|
|
19
|
+
* Accessible label for the tablist, set as `aria-label`.
|
|
20
|
+
*/
|
|
21
|
+
label;
|
|
22
|
+
/**
|
|
23
|
+
* Emitted when the active tab changes, with the new value.
|
|
24
|
+
*/
|
|
25
|
+
chChange;
|
|
26
|
+
tabId(value) {
|
|
27
|
+
return `${this.baseId}-${value}`;
|
|
28
|
+
}
|
|
29
|
+
panelId(value) {
|
|
30
|
+
return `${this.baseId}-${value}-panel`;
|
|
31
|
+
}
|
|
32
|
+
get activeValue() {
|
|
33
|
+
if (this.value && this.tabs.some(tab => !tab.disabled && tab.value === this.value)) {
|
|
34
|
+
return this.value;
|
|
35
|
+
}
|
|
36
|
+
return this.tabs.find(tab => !tab.disabled)?.value;
|
|
37
|
+
}
|
|
38
|
+
select = (value) => {
|
|
39
|
+
this.value = value;
|
|
40
|
+
this.chChange.emit(this.value);
|
|
41
|
+
};
|
|
42
|
+
focusTab(value) {
|
|
43
|
+
this.tablistEl?.querySelectorAll('[role="tab"]').forEach(button => {
|
|
44
|
+
if (button.dataset.value === value) {
|
|
45
|
+
button.focus();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
handleKeyDown = (ev) => {
|
|
50
|
+
const enabled = this.tabs.filter(tab => !tab.disabled);
|
|
51
|
+
if (!enabled.length) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const target = this.targetFor(ev.key, enabled);
|
|
55
|
+
if (!target) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
ev.preventDefault();
|
|
59
|
+
this.select(target);
|
|
60
|
+
this.focusTab(target);
|
|
61
|
+
};
|
|
62
|
+
targetFor(key, enabled) {
|
|
63
|
+
const current = enabled.findIndex(tab => tab.value === this.activeValue);
|
|
64
|
+
if (key === 'ArrowRight') {
|
|
65
|
+
return enabled[(current + NEXT_TAB_OFFSET) % enabled.length]?.value;
|
|
66
|
+
}
|
|
67
|
+
if (key === 'ArrowLeft') {
|
|
68
|
+
return enabled[(current + PREVIOUS_TAB_OFFSET + enabled.length) % enabled.length]?.value;
|
|
69
|
+
}
|
|
70
|
+
if (key === 'Home') {
|
|
71
|
+
return enabled[FIRST_TAB_INDEX]?.value;
|
|
72
|
+
}
|
|
73
|
+
if (key === 'End') {
|
|
74
|
+
return enabled[enabled.length + LAST_TAB_INDEX]?.value;
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
render() {
|
|
79
|
+
const active = this.activeValue;
|
|
80
|
+
return (h(Host, { key: '76a7f50b0cfa62b3a9a97114c99ab217da83aeb3' }, h("div", { key: '544691573ac6940ec8406e8377ac0ed5fd95140e', class: "tablist", role: "tablist", "aria-label": this.label, onKeyDown: this.handleKeyDown, ref: el => (this.tablistEl = el) }, this.tabs.map(tab => {
|
|
81
|
+
const selected = tab.value === active;
|
|
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
|
+
})), 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}` }))))));
|
|
84
|
+
}
|
|
85
|
+
static get is() { return "ch-tabs"; }
|
|
86
|
+
static get encapsulation() { return "shadow"; }
|
|
87
|
+
static get originalStyleUrls() {
|
|
88
|
+
return {
|
|
89
|
+
"$": ["ch-tabs.css"]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
static get styleUrls() {
|
|
93
|
+
return {
|
|
94
|
+
"$": ["ch-tabs.css"]
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
static get properties() {
|
|
98
|
+
return {
|
|
99
|
+
"tabs": {
|
|
100
|
+
"type": "unknown",
|
|
101
|
+
"mutable": false,
|
|
102
|
+
"complexType": {
|
|
103
|
+
"original": "ChTab[]",
|
|
104
|
+
"resolved": "ChTab[]",
|
|
105
|
+
"references": {
|
|
106
|
+
"ChTab": {
|
|
107
|
+
"location": "local",
|
|
108
|
+
"path": "/home/runner/work/chucao/chucao/src/components/ch-tabs/ch-tabs.tsx",
|
|
109
|
+
"id": "src/components/ch-tabs/ch-tabs.tsx::ChTab"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"required": false,
|
|
114
|
+
"optional": false,
|
|
115
|
+
"docs": {
|
|
116
|
+
"tags": [],
|
|
117
|
+
"text": "The list of tabs, each with a `label`, a `value`, and an optional `disabled` flag."
|
|
118
|
+
},
|
|
119
|
+
"getter": false,
|
|
120
|
+
"setter": false,
|
|
121
|
+
"defaultValue": "[]"
|
|
122
|
+
},
|
|
123
|
+
"value": {
|
|
124
|
+
"type": "string",
|
|
125
|
+
"mutable": true,
|
|
126
|
+
"complexType": {
|
|
127
|
+
"original": "string",
|
|
128
|
+
"resolved": "string",
|
|
129
|
+
"references": {}
|
|
130
|
+
},
|
|
131
|
+
"required": false,
|
|
132
|
+
"optional": true,
|
|
133
|
+
"docs": {
|
|
134
|
+
"tags": [],
|
|
135
|
+
"text": "The value of the active tab. Defaults to the first enabled tab."
|
|
136
|
+
},
|
|
137
|
+
"getter": false,
|
|
138
|
+
"setter": false,
|
|
139
|
+
"reflect": false,
|
|
140
|
+
"attribute": "value"
|
|
141
|
+
},
|
|
142
|
+
"label": {
|
|
143
|
+
"type": "string",
|
|
144
|
+
"mutable": false,
|
|
145
|
+
"complexType": {
|
|
146
|
+
"original": "string",
|
|
147
|
+
"resolved": "string",
|
|
148
|
+
"references": {}
|
|
149
|
+
},
|
|
150
|
+
"required": false,
|
|
151
|
+
"optional": true,
|
|
152
|
+
"docs": {
|
|
153
|
+
"tags": [],
|
|
154
|
+
"text": "Accessible label for the tablist, set as `aria-label`."
|
|
155
|
+
},
|
|
156
|
+
"getter": false,
|
|
157
|
+
"setter": false,
|
|
158
|
+
"reflect": false,
|
|
159
|
+
"attribute": "label"
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
static get events() {
|
|
164
|
+
return [{
|
|
165
|
+
"method": "chChange",
|
|
166
|
+
"name": "chChange",
|
|
167
|
+
"bubbles": true,
|
|
168
|
+
"cancelable": true,
|
|
169
|
+
"composed": true,
|
|
170
|
+
"docs": {
|
|
171
|
+
"tags": [],
|
|
172
|
+
"text": "Emitted when the active tab changes, with the new value."
|
|
173
|
+
},
|
|
174
|
+
"complexType": {
|
|
175
|
+
"original": "string",
|
|
176
|
+
"resolved": "string",
|
|
177
|
+
"references": {}
|
|
178
|
+
}
|
|
179
|
+
}];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=ch-tabs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ch-tabs.js","sourceRoot":"","sources":["../../../../src/components/ch-tabs/ch-tabs.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAQnF,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,cAAc,GAAG,CAAC,CAAC,CAAC;AAC1B,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,mBAAmB,GAAG,CAAC,CAAC,CAAC;AAE/B,IAAI,OAAO,GAAG,CAAC,CAAC;AAOhB,MAAM,OAAO,MAAM;IACA,MAAM,GAAG,WAAW,EAAE,OAAO,EAAE,CAAC;IACzC,SAAS,CAAkB;I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,QAAQ,EACzB,KAAK,EAAC,UAAU,EAChB,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAC3B,IAAI,EAAC,UAAU,qBACE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EACtC,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,GAAG,CAAC,KAAK,KAAK,MAAM;gBAE5B,YAAM,IAAI,EAAE,SAAS,GAAG,CAAC,KAAK,EAAE,GAAS,CACrC,CACP,CAAC,CACG,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Event, type EventEmitter, Host, Prop, h } from '@stencil/core';\n\nexport interface ChTab {\n label: string;\n value: string;\n disabled?: boolean;\n}\n\nconst FIRST_TAB_INDEX = 0;\nconst LAST_TAB_INDEX = -1;\nconst NEXT_TAB_OFFSET = 1;\nconst PREVIOUS_TAB_OFFSET = -1;\n\nlet tabsIds = 0;\n\n@Component({\n tag: 'ch-tabs',\n styleUrl: 'ch-tabs.css',\n shadow: true,\n})\nexport class ChTabs {\n private readonly baseId = `ch-tabs-${++tabsIds}`;\n private tablistEl?: HTMLDivElement;\n\n /**\n * The list of tabs, each with a `label`, a `value`, and an optional `disabled` flag.\n */\n @Prop() tabs: ChTab[] = [];\n\n /**\n * The value of the active tab. Defaults to the first enabled tab.\n */\n @Prop({ mutable: true }) value?: string;\n\n /**\n * Accessible label for the tablist, set as `aria-label`.\n */\n @Prop() label?: string;\n\n /**\n * Emitted when the active tab changes, with the new value.\n */\n @Event() chChange: EventEmitter<string>;\n\n private tabId(value: string) {\n return `${this.baseId}-${value}`;\n }\n\n private panelId(value: string) {\n return `${this.baseId}-${value}-panel`;\n }\n\n private get activeValue(): string | undefined {\n if (this.value && this.tabs.some(tab => !tab.disabled && tab.value === this.value)) {\n return this.value;\n }\n return this.tabs.find(tab => !tab.disabled)?.value;\n }\n\n private select = (value: string) => {\n this.value = value;\n this.chChange.emit(this.value);\n };\n\n private focusTab(value: string) {\n this.tablistEl?.querySelectorAll<HTMLButtonElement>('[role=\"tab\"]').forEach(button => {\n if (button.dataset.value === value) {\n button.focus();\n }\n });\n }\n\n private handleKeyDown = (ev: KeyboardEvent) => {\n const enabled = this.tabs.filter(tab => !tab.disabled);\n if (!enabled.length) {\n return;\n }\n const target = this.targetFor(ev.key, enabled);\n if (!target) {\n return;\n }\n ev.preventDefault();\n this.select(target);\n this.focusTab(target);\n };\n\n private targetFor(key: string, enabled: ChTab[]): string | undefined {\n const current = enabled.findIndex(tab => tab.value === this.activeValue);\n if (key === 'ArrowRight') {\n return enabled[(current + NEXT_TAB_OFFSET) % enabled.length]?.value;\n }\n if (key === 'ArrowLeft') {\n return enabled[(current + PREVIOUS_TAB_OFFSET + enabled.length) % enabled.length]?.value;\n }\n if (key === 'Home') {\n return enabled[FIRST_TAB_INDEX]?.value;\n }\n if (key === 'End') {\n return enabled[enabled.length + LAST_TAB_INDEX]?.value;\n }\n return undefined;\n }\n\n render() {\n const active = this.activeValue;\n return (\n <Host>\n <div class=\"tablist\" role=\"tablist\" aria-label={this.label} onKeyDown={this.handleKeyDown} ref={el => (this.tablistEl = el)}>\n {this.tabs.map(tab => {\n const selected = tab.value === active;\n return (\n <button\n key={tab.value}\n type=\"button\"\n class={{ 'tab': true, 'tab--active': selected, 'tab--disabled': Boolean(tab.disabled) }}\n role=\"tab\"\n id={this.tabId(tab.value)}\n data-value={tab.value}\n aria-selected={selected ? 'true' : 'false'}\n aria-controls={this.panelId(tab.value)}\n tabIndex={selected ? FIRST_TAB_INDEX : LAST_TAB_INDEX}\n disabled={tab.disabled}\n onClick={() => this.select(tab.value)}\n >\n {tab.label}\n </button>\n );\n })}\n </div>\n {this.tabs.map(tab => (\n <div\n key={`${tab.value}-panel`}\n class=\"tabpanel\"\n id={this.panelId(tab.value)}\n role=\"tabpanel\"\n aria-labelledby={this.tabId(tab.value)}\n tabIndex={FIRST_TAB_INDEX}\n hidden={tab.value !== active}\n >\n <slot name={`panel-${tab.value}`}></slot>\n </div>\n ))}\n </Host>\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
width: 100%;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.label {
|
|
7
|
+
display: block;
|
|
8
|
+
margin-bottom: var(--spacing-sm);
|
|
9
|
+
font-size: var(--typography-size-sm);
|
|
10
|
+
font-weight: var(--typography-weight-semibold);
|
|
11
|
+
color: var(--text);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.textarea {
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
width: 100%;
|
|
17
|
+
min-height: var(--spacing-6xl);
|
|
18
|
+
padding: var(--spacing-xl) var(--spacing-3xl);
|
|
19
|
+
border-radius: var(--radius);
|
|
20
|
+
border: var(--border-width) solid var(--border);
|
|
21
|
+
background: var(--surface);
|
|
22
|
+
color: var(--text);
|
|
23
|
+
backdrop-filter: blur(var(--effect-blur));
|
|
24
|
+
font-family: inherit;
|
|
25
|
+
font-size: inherit;
|
|
26
|
+
line-height: var(--spacing-5xl);
|
|
27
|
+
resize: vertical;
|
|
28
|
+
transition:
|
|
29
|
+
border-color var(--duration-normal) var(--easing-default),
|
|
30
|
+
box-shadow var(--duration-normal) var(--easing-default);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.textarea::placeholder {
|
|
34
|
+
color: var(--text-muted);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.textarea:focus {
|
|
38
|
+
border-color: var(--accent);
|
|
39
|
+
box-shadow: var(--shadow-focus-ring);
|
|
40
|
+
outline: none;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.textarea--invalid {
|
|
44
|
+
border-color: var(--color-status-warning);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.textarea--invalid:focus {
|
|
48
|
+
border-color: var(--color-status-warning);
|
|
49
|
+
box-shadow: 0 0 0 3px var(--color-status-warning-background);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.textarea:disabled {
|
|
53
|
+
opacity: var(--opacity-disabled);
|
|
54
|
+
cursor: not-allowed;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.hint,
|
|
58
|
+
.error {
|
|
59
|
+
margin: var(--spacing-sm) 0 0;
|
|
60
|
+
font-size: var(--typography-size-sm);
|
|
61
|
+
color: var(--text-muted);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.error {
|
|
65
|
+
color: var(--color-status-warning);
|
|
66
|
+
}
|