Sharkey/src/client/components/debobigego/switch.vue

132 lines
2.1 KiB
Vue
Raw Normal View History

2021-09-29 18:50:45 +03:00
<template>
<div class="ijnpvmgr _debobigegoItem">
<div class="main _debobigegoPanel _debobigegoClickable"
:class="{ disabled, checked }"
:aria-checked="checked"
:aria-disabled="disabled"
@click.prevent="toggle"
>
<input
type="checkbox"
ref="input"
:disabled="disabled"
@keydown.enter="toggle"
>
<span class="button" v-tooltip="checked ? $ts.itsOn : $ts.itsOff">
2021-09-29 19:13:54 +03:00
<span class="handle"></span>
2021-09-29 18:50:45 +03:00
</span>
<span class="label">
<span><slot></slot></span>
</span>
</div>
<div class="_debobigegoCaption"><slot name="desc"></slot></div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import './debobigego.scss';
export default defineComponent({
props: {
modelValue: {
type: Boolean,
default: false
},
disabled: {
type: Boolean,
default: false
}
},
computed: {
checked(): boolean {
return this.modelValue;
}
},
methods: {
toggle() {
if (this.disabled) return;
this.$emit('update:modelValue', !this.checked);
}
}
});
</script>
<style lang="scss" scoped>
.ijnpvmgr {
> .main {
position: relative;
display: flex;
padding: 14px 16px;
cursor: pointer;
> * {
user-select: none;
}
> input {
position: absolute;
width: 0;
height: 0;
opacity: 0;
margin: 0;
}
> .button {
position: relative;
display: inline-block;
flex-shrink: 0;
2021-09-29 19:13:54 +03:00
margin: 0;
2021-09-29 18:50:45 +03:00
width: 34px;
2021-09-29 19:13:54 +03:00
height: 22px;
background: var(--switchBg);
2021-09-29 18:50:45 +03:00
outline: none;
2021-09-29 19:13:54 +03:00
border-radius: 999px;
2021-09-29 18:50:45 +03:00
transition: all 0.3s;
cursor: pointer;
2021-09-29 19:13:54 +03:00
> .handle {
2021-09-29 18:50:45 +03:00
position: absolute;
2021-09-29 19:13:54 +03:00
top: 0;
left: 3px;
bottom: 0;
margin: auto 0;
2021-09-29 18:50:45 +03:00
border-radius: 100%;
transition: background-color 0.3s, transform 0.3s;
2021-09-29 19:13:54 +03:00
width: 16px;
height: 16px;
2021-09-29 18:50:45 +03:00
background-color: #fff;
}
}
> .label {
margin-left: 12px;
display: block;
transition: inherit;
color: var(--fg);
> span {
display: block;
line-height: 20px;
transition: inherit;
}
}
2021-09-29 19:13:54 +03:00
&.disabled {
opacity: 0.6;
cursor: not-allowed;
}
&.checked {
> .button {
background-color: var(--accent);
> .handle {
transform: translateX(12px);
}
}
}
2021-09-29 18:50:45 +03:00
}
}
</style>