@schukai/monster 3.67.0 → 3.68.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/CHANGELOG.md +18 -11
- package/package.json +1 -1
- package/source/components/form/field-set.mjs +274 -204
- package/source/components/form/style/field-set.pcss +9 -2
- package/source/components/form/style/toggle-switch.pcss +2 -8
- package/source/components/form/stylesheet/field-set.mjs +8 -17
- package/source/components/form/stylesheet/toggle-switch.mjs +8 -17
- package/source/components/form/toggle-switch.mjs +330 -321
- package/source/components/host/toggle-button.mjs +1 -3
- package/test/cases/components/form/toggle-switch.mjs +2 -0
|
@@ -12,43 +12,32 @@
|
|
|
12
12
|
* SPDX-License-Identifier: AGPL-3.0
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
15
|
+
import {instanceSymbol} from "../../constants.mjs";
|
|
16
|
+
import {internalSymbol} from "../../constants.mjs";
|
|
17
|
+
import {CustomControl} from "../../dom/customcontrol.mjs";
|
|
18
|
+
import {Observer} from "../../types/observer.mjs";
|
|
19
|
+
import {ProxyObserver} from "../../types/proxyobserver.mjs";
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import {addAttributeToken} from "../../dom/attributes.mjs";
|
|
22
22
|
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
assembleMethodSymbol,
|
|
24
|
+
registerCustomElement,
|
|
25
|
+
updaterTransformerMethodsSymbol,
|
|
26
26
|
} from "../../dom/customelement.mjs";
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
27
|
+
import {isObject, isFunction} from "../../types/is.mjs";
|
|
28
|
+
import {ToggleSwitchStyleSheet} from "./stylesheet/toggle-switch.mjs";
|
|
29
29
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
ATTRIBUTE_ERRORMESSAGE,
|
|
31
|
+
ATTRIBUTE_ROLE,
|
|
32
32
|
} from "../../dom/constants.mjs";
|
|
33
|
-
export { ToggleSwitch };
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
* @private
|
|
37
|
-
* @type {symbol}
|
|
38
|
-
*/
|
|
39
|
-
const switchElementSymbol = Symbol("switchElement");
|
|
34
|
+
export {ToggleSwitch};
|
|
40
35
|
|
|
41
36
|
/**
|
|
42
37
|
* @private
|
|
43
38
|
* @type {symbol}
|
|
44
39
|
*/
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @private
|
|
49
|
-
* @type {symbol}
|
|
50
|
-
*/
|
|
51
|
-
const switchElementSymbolOff = Symbol("switchElementOff");
|
|
40
|
+
const switchElementSymbol = Symbol("switchElement");
|
|
52
41
|
|
|
53
42
|
/**
|
|
54
43
|
* @type {string}
|
|
@@ -80,324 +69,344 @@ export const STATE_OFF = "off";
|
|
|
80
69
|
* @summary A simple toggle switch
|
|
81
70
|
*/
|
|
82
71
|
class ToggleSwitch extends CustomControl {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
72
|
+
/**
|
|
73
|
+
* To set the options via the html tag the attribute `data-monster-options` must be used.
|
|
74
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
|
75
|
+
*
|
|
76
|
+
* The individual configuration values can be found in the table.
|
|
77
|
+
*
|
|
78
|
+
* @property {string} value=current value of the element
|
|
79
|
+
* @property {Boolean} disabled=disabled=false Disabled state
|
|
80
|
+
* @property {Object} classes
|
|
81
|
+
* @property {string} classes.on=specifies the class for the on state.
|
|
82
|
+
* @property {string} classes.off=specifies the class for the off state.
|
|
83
|
+
* @property {Object} values
|
|
84
|
+
* @property {string} values.off=specifies the value of the element if it is not selected
|
|
85
|
+
* @property {Object} labels
|
|
86
|
+
* @property {string} labels.on=specifies the label for the on state.
|
|
87
|
+
* @property {string} labels.off=specifies the label for the off state.
|
|
88
|
+
* @property {string} actions
|
|
89
|
+
* @property {string} actions.on=specifies the action for the on state.
|
|
90
|
+
* @property {string} actions.off=specifies the action for the off state.
|
|
91
|
+
* @property {Object} templates
|
|
92
|
+
* @property {string} templates.main=specifies the main template used by the control.
|
|
93
|
+
*
|
|
94
|
+
* @since 3.57.0
|
|
95
|
+
*/
|
|
96
|
+
get defaults() {
|
|
97
|
+
return Object.assign({}, super.defaults, {
|
|
98
|
+
value: null,
|
|
99
|
+
disabled: false,
|
|
100
|
+
classes: {
|
|
101
|
+
on: "monster-theme-on",
|
|
102
|
+
off: "monster-theme-off",
|
|
103
|
+
handle: "monster-theme-primary-1",
|
|
104
|
+
},
|
|
105
|
+
values: {
|
|
106
|
+
on: "on",
|
|
107
|
+
off: "off",
|
|
108
|
+
},
|
|
109
|
+
labels: {
|
|
110
|
+
"toggle-switch-on": "ON",
|
|
111
|
+
"toggle-switch-off": "OFF",
|
|
112
|
+
},
|
|
113
|
+
templates: {
|
|
114
|
+
main: getTemplate(),
|
|
115
|
+
},
|
|
116
|
+
actions: {
|
|
117
|
+
on: () => {
|
|
118
|
+
throw new Error("the on action is not defined");
|
|
119
|
+
},
|
|
120
|
+
off: () => {
|
|
121
|
+
throw new Error("the off action is not defined");
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @return {ToggleSwitch}
|
|
129
|
+
*/
|
|
130
|
+
[assembleMethodSymbol]() {
|
|
131
|
+
const self = this;
|
|
132
|
+
super[assembleMethodSymbol]();
|
|
133
|
+
initControlReferences.call(this);
|
|
134
|
+
initEventHandler.call(this);
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* init value to off
|
|
138
|
+
* if the value was not defined before inserting it into the HTML
|
|
139
|
+
*/
|
|
140
|
+
if (self.getOption("value") === null) {
|
|
141
|
+
self.setOption("value", self.getOption("values.off"));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* value from attribute
|
|
146
|
+
*/
|
|
147
|
+
if (self.hasAttribute("value")) {
|
|
148
|
+
self.setOption("value", self.getAttribute("value"));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* validate value
|
|
153
|
+
*/
|
|
154
|
+
validateAndSetValue.call(self);
|
|
155
|
+
|
|
156
|
+
if (this.state === STATE_ON) {
|
|
157
|
+
toggleClassOn.call(self);
|
|
158
|
+
} else {
|
|
159
|
+
toggleClassOff.call(self);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* is called when options changed
|
|
164
|
+
*/
|
|
165
|
+
self[internalSymbol].attachObserver(
|
|
166
|
+
new Observer(function () {
|
|
167
|
+
if (isObject(this) && this instanceof ProxyObserver) {
|
|
168
|
+
validateAndSetValue.call(self);
|
|
169
|
+
toggleClass.call(self);
|
|
170
|
+
}
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* updater transformer methods for pipe
|
|
179
|
+
*
|
|
180
|
+
* @return {function}
|
|
181
|
+
*/
|
|
182
|
+
[updaterTransformerMethodsSymbol]() {
|
|
183
|
+
return {
|
|
184
|
+
"state-callback": (Wert) => {
|
|
185
|
+
return this.state;
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @return [CSSStyleSheet]
|
|
192
|
+
*/
|
|
193
|
+
static getCSSStyleSheet() {
|
|
194
|
+
return [ToggleSwitchStyleSheet];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* toggle switch
|
|
199
|
+
*
|
|
200
|
+
* ```
|
|
201
|
+
* e = document.querySelector('monster-toggle-switch');
|
|
202
|
+
* e.click()
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
click() {
|
|
206
|
+
toggleValues.call(this);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* toggle switch on/off
|
|
211
|
+
*
|
|
212
|
+
* ```
|
|
213
|
+
* e = document.querySelector('monster-toggle-switch');
|
|
214
|
+
* e.toggle()
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @return {ToggleSwitch}
|
|
218
|
+
*/
|
|
219
|
+
toggle() {
|
|
220
|
+
this.click();
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* toggle switch on
|
|
226
|
+
*
|
|
227
|
+
* ```
|
|
228
|
+
* e = document.querySelector('monster-toggle-switch');
|
|
229
|
+
* e.toggleOn()
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @return {ToggleSwitch}
|
|
233
|
+
*/
|
|
234
|
+
toggleOn() {
|
|
235
|
+
this.setOption("value", this.getOption("values.on"));
|
|
236
|
+
return this;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* toggle switch off
|
|
241
|
+
*
|
|
242
|
+
* ```
|
|
243
|
+
* e = document.querySelector('monster-toggle-switch');
|
|
244
|
+
* e.toggleOff()
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @return {ToggleSwitch}
|
|
248
|
+
*/
|
|
249
|
+
toggleOff() {
|
|
250
|
+
this.setOption("value", this.getOption("values.off"));
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* returns the status of the element
|
|
256
|
+
*
|
|
257
|
+
* ```
|
|
258
|
+
* e = document.querySelector('monster-toggle-switch');
|
|
259
|
+
* console.log(e.state)
|
|
260
|
+
* // ↦ off
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @return {string}
|
|
264
|
+
*/
|
|
265
|
+
get state() {
|
|
266
|
+
return this.getOption("value") === this.getOption("values.on")
|
|
267
|
+
? STATE_ON
|
|
268
|
+
: STATE_OFF;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The current value of the Switch
|
|
273
|
+
*
|
|
274
|
+
* ```
|
|
275
|
+
* e = document.querySelector('monster-toggle-switch');
|
|
276
|
+
* console.log(e.value)
|
|
277
|
+
* // ↦ on
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @return {string}
|
|
281
|
+
*/
|
|
282
|
+
get value() {
|
|
283
|
+
return this.state === STATE_ON
|
|
284
|
+
? this.getOption("values.on")
|
|
285
|
+
: this.getOption("values.off");
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Set value
|
|
290
|
+
*
|
|
291
|
+
* ```
|
|
292
|
+
* e = document.querySelector('monster-toggle-switch');
|
|
293
|
+
* e.value="on"
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @property {string} value
|
|
297
|
+
*/
|
|
298
|
+
set value(value) {
|
|
299
|
+
this.setOption("value", value);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* This method is called by the `instanceof` operator.
|
|
304
|
+
* @returns {symbol}
|
|
305
|
+
* @since 2.1.0
|
|
306
|
+
*/
|
|
307
|
+
static get [instanceSymbol]() {
|
|
308
|
+
return Symbol.for(
|
|
309
|
+
"@schukai/monster/components/form/toggle-switch@@instance",
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
static getTag() {
|
|
314
|
+
return "monster-toggle-switch";
|
|
315
|
+
}
|
|
317
316
|
}
|
|
318
317
|
|
|
319
318
|
/**
|
|
320
319
|
* @private
|
|
321
320
|
*/
|
|
322
321
|
function initControlReferences() {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
322
|
+
this[switchElementSymbol] = this.shadowRoot.querySelector(
|
|
323
|
+
`[${ATTRIBUTE_ROLE}=switch]`,
|
|
324
|
+
);
|
|
326
325
|
}
|
|
327
326
|
|
|
328
327
|
/**
|
|
329
328
|
* @private
|
|
330
329
|
*/
|
|
331
330
|
function toggleClassOn() {
|
|
332
|
-
|
|
333
|
-
|
|
331
|
+
this[switchElementSymbol].classList.remove(this.getOption("classes.off")); // change color
|
|
332
|
+
this[switchElementSymbol].classList.add(this.getOption("classes.on")); // change color
|
|
334
333
|
}
|
|
335
334
|
|
|
336
335
|
/**
|
|
337
336
|
* @private
|
|
338
337
|
*/
|
|
339
338
|
function toggleClassOff() {
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
this[switchElementSymbol].classList.remove(this.getOption("classes.on")); // change color
|
|
340
|
+
this[switchElementSymbol].classList.add(this.getOption("classes.off")); // change color
|
|
342
341
|
}
|
|
343
342
|
|
|
344
343
|
/**
|
|
345
344
|
* @private
|
|
346
345
|
*/
|
|
347
346
|
function toggleClass() {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
347
|
+
if (this.getOption("value") === this.getOption("values.on")) {
|
|
348
|
+
toggleClassOn.call(this);
|
|
349
|
+
} else {
|
|
350
|
+
toggleClassOff.call(this);
|
|
351
|
+
}
|
|
353
352
|
}
|
|
354
353
|
|
|
355
354
|
/**
|
|
356
355
|
* @private
|
|
357
356
|
*/
|
|
358
357
|
function toggleValues() {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
358
|
+
if (this.getOption("disabled") === true) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
let callback, value;
|
|
363
|
+
|
|
364
|
+
if (this.getOption("value") === this.getOption("values.on")) {
|
|
365
|
+
value = this.getOption("values.off");
|
|
366
|
+
callback = this.getOption("actions.off");
|
|
367
|
+
} else {
|
|
368
|
+
value = this.getOption("values.on");
|
|
369
|
+
callback = this.getOption("actions.on");
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
this.setOption("value", value);
|
|
373
|
+
this?.setFormValue(value);
|
|
374
|
+
|
|
375
|
+
if (isFunction(callback)) {
|
|
376
|
+
callback.call(this)();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
this.setOption("state", this.state);
|
|
372
381
|
}
|
|
373
382
|
|
|
374
383
|
/**
|
|
375
384
|
* @private
|
|
376
385
|
*/
|
|
377
386
|
function validateAndSetValue() {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
387
|
+
const value = this.getOption("value");
|
|
388
|
+
|
|
389
|
+
const validatedValues = [];
|
|
390
|
+
validatedValues.push(this.getOption("values.on"));
|
|
391
|
+
validatedValues.push(this.getOption("values.off"));
|
|
392
|
+
|
|
393
|
+
if (validatedValues.includes(value) === false) {
|
|
394
|
+
addAttributeToken(
|
|
395
|
+
this,
|
|
396
|
+
ATTRIBUTE_ERRORMESSAGE,
|
|
397
|
+
'The value "' +
|
|
398
|
+
value +
|
|
399
|
+
'" must be "' +
|
|
400
|
+
this.getOption("values.on") +
|
|
401
|
+
'" or "' +
|
|
402
|
+
this.getOption("values.off"),
|
|
403
|
+
);
|
|
404
|
+
this.setOption("disabled", true);
|
|
405
|
+
this.formDisabledCallback(true);
|
|
406
|
+
} else {
|
|
407
|
+
this.setOption("disabled", false);
|
|
408
|
+
this.formDisabledCallback(false);
|
|
409
|
+
}
|
|
401
410
|
}
|
|
402
411
|
|
|
403
412
|
/**
|
|
@@ -405,16 +414,16 @@ function validateAndSetValue() {
|
|
|
405
414
|
* @return {initEventHandler}
|
|
406
415
|
*/
|
|
407
416
|
function initEventHandler() {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
417
|
+
const self = this;
|
|
418
|
+
self.addEventListener("keyup", function (event) {
|
|
419
|
+
if (event.code === "Space") {
|
|
420
|
+
self[switchElementSymbol].click();
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
self.addEventListener("click", function (event) {
|
|
424
|
+
toggleValues.call(self);
|
|
425
|
+
});
|
|
426
|
+
return this;
|
|
418
427
|
}
|
|
419
428
|
|
|
420
429
|
/**
|
|
@@ -422,10 +431,10 @@ function initEventHandler() {
|
|
|
422
431
|
* @return {string}
|
|
423
432
|
*/
|
|
424
433
|
function getTemplate() {
|
|
425
|
-
|
|
426
|
-
|
|
434
|
+
// language=HTML
|
|
435
|
+
return `
|
|
427
436
|
<div data-monster-role="control" part="control" tabindex="0">
|
|
428
|
-
|
|
437
|
+
<div class="switch" data-monster-role="switch"
|
|
429
438
|
data-monster-attributes="data-monster-state path:value | call:state-callback">
|
|
430
439
|
<div class="label on" data-monster-replace="path:labels.toggle-switch-on"></div>
|
|
431
440
|
<div class="label off" data-monster-replace="path:labels.toggle-switch-off"></div>
|