| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,15 @@ |
| 1 |
+import { LitElement, html, css } from 'lit';
|
|
| 2 |
+ |
|
| 3 |
+export class ToggleSwitch extends LitElement {
|
|
| 4 |
+ static properties = { checked: { type: Boolean } };
|
|
| 5 |
+ static styles = css` |
|
| 6 |
+ .switch { position: relative; display: inline-block; width: 44px; height: 24px; }
|
|
| 7 |
+ .switch input { opacity: 0; width: 0; height: 0; }
|
|
| 8 |
+ .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ddd; transition: .4s; border-radius: 24px; }
|
|
| 9 |
+ .slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: var(--bg-white); transition: .4s; border-radius: 50%; }
|
|
| 10 |
+ input:checked + .slider { background-color: var(--primary-color); }
|
|
| 11 |
+ input:checked + .slider:before { transform: translateX(20px); }
|
|
| 12 |
+ `; |
|
| 13 |
+ render() { return html`<label class="switch"><input type="checkbox" ?checked="${this.checked}" @change="${e => this.checked = e.target.checked}"><span class="slider"></span></label>`; }
|
|
| 14 |
+} |
|
| 15 |
+customElements.define('toggle-switch', ToggleSwitch);
|