Skip to content
Snippets Groups Projects
Verified Commit 32c9247e authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: add on/off action to toggle switch #207

parent c8cf9782
No related branches found
No related tags found
No related merge requests found
...@@ -10,24 +10,21 @@ ...@@ -10,24 +10,21 @@
margin: 0; margin: 0;
outline: none; outline: none;
box-sizing: border-box; box-sizing: border-box;
&:focus { &:focus {
outline: 1px dashed var(--monster-color-selection-3); outline: 1px dashed var(--monster-color-selection-3);
outline-offset: 2px; outline-offset: 2px;
} }
& .switch { & .switch {
position: relative; position: relative;
height: 2.5em; border-width: var(--monster-border-width);
border-width: thin;
border-style: var(--monster-border-style); border-style: var(--monster-border-style);
transition: background-color 0.2s; transition: background-color 0.2s;
display: inline-grid; display: inline-grid;
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 100%;
} }
& .label { & .label {
...@@ -35,10 +32,8 @@ ...@@ -35,10 +32,8 @@
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
height: 2.5em;
display: block; display: block;
text-align: center; text-align: center;
line-height: 2.5em;
user-select: none; user-select: none;
padding: 0 0.2em; padding: 0 0.2em;
} }
...@@ -69,7 +64,6 @@ ...@@ -69,7 +64,6 @@
visibility: hidden; visibility: hidden;
} }
& .switch[data-monster-state="on"] .switch-slider { & .switch[data-monster-state="on"] .switch-slider {
transform: translateX(100%); transform: translateX(100%);
......
This diff is collapsed.
...@@ -38,18 +38,6 @@ export { ToggleSwitch }; ...@@ -38,18 +38,6 @@ export { ToggleSwitch };
*/ */
const switchElementSymbol = Symbol("switchElement"); const switchElementSymbol = Symbol("switchElement");
/**
* @private
* @type {symbol}
*/
const switchElementSymbolOn = Symbol("switchElementOn");
/**
* @private
* @type {symbol}
*/
const switchElementSymbolOff = Symbol("switchElementOff");
/** /**
* @type {string} * @type {string}
*/ */
...@@ -96,6 +84,9 @@ class ToggleSwitch extends CustomControl { ...@@ -96,6 +84,9 @@ class ToggleSwitch extends CustomControl {
* @property {Object} labels * @property {Object} labels
* @property {string} labels.on=specifies the label for the on state. * @property {string} labels.on=specifies the label for the on state.
* @property {string} labels.off=specifies the label for the off state. * @property {string} labels.off=specifies the label for the off state.
* @property {string} actions
* @property {string} actions.on=specifies the action for the on state.
* @property {string} actions.off=specifies the action for the off state.
* @property {Object} templates * @property {Object} templates
* @property {string} templates.main=specifies the main template used by the control. * @property {string} templates.main=specifies the main template used by the control.
* *
...@@ -121,12 +112,19 @@ class ToggleSwitch extends CustomControl { ...@@ -121,12 +112,19 @@ class ToggleSwitch extends CustomControl {
templates: { templates: {
main: getTemplate(), main: getTemplate(),
}, },
actions: {
on: () => {
throw new Error("the on action is not defined");
},
off: () => {
throw new Error("the off action is not defined");
},
}
}); });
} }
/** /**
* * @return {ToggleSwitch}
* @return {Monster.Components.Form.ToggleSwitch}
*/ */
[assembleMethodSymbol]() { [assembleMethodSymbol]() {
const self = this; const self = this;
...@@ -363,9 +361,11 @@ function toggleValues() { ...@@ -363,9 +361,11 @@ function toggleValues() {
if (this.getOption("value") === this.getOption("values.on")) { if (this.getOption("value") === this.getOption("values.on")) {
this.setOption("value", this.getOption("values.off")); this.setOption("value", this.getOption("values.off"));
this?.setFormValue(this.getOption("value")); // set form value this?.setFormValue(this.getOption("value")); // set form value
this.getOption("actions.off")?.call(this);
} else { } else {
this.setOption("value", this.getOption("values.on")); this.setOption("value", this.getOption("values.on"));
this?.setFormValue(this.getOption("values.off")); // set form value this?.setFormValue(this.getOption("values.off")); // set form value
this.getOption("actions.on")?.call(this);
} }
this.setOption("state", this.state); this.setOption("state", this.state);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment