jws-frontend/src/components/button/ToggleButton.vue

77 lines
1.3 KiB
Vue
Raw Normal View History

2024-08-13 08:55:49 +00:00
<script lang="ts" setup>
defineEmits<{
(e: 'click'): void;
}>();
defineProps<{
twoWay?: boolean;
color?: string;
}>();
const model = defineModel<boolean>({ default: false });
</script>
<template>
<label class="switch" @click="$emit('click')">
<input type="checkbox" :disabled="twoWay" v-model="model" />
<div class="slider round"></div>
</label>
</template>
<style lang="scss" scoped>
.switch {
position: relative;
display: inline-block;
width: 42px;
height: 25px;
}
.switch input {
display: none;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: hsl(var(--text-mute));
-webkit-transition: 0.3s;
transition: 0.3s;
}
.slider:before {
position: absolute;
content: '';
height: 18px;
width: 18px;
left: 3.5px;
bottom: 3.5px;
background-color: white;
-webkit-transition: 0.3s;
transition: 0.3s;
}
input:checked + .slider {
background-color: hsl(var(--positive-bg));
}
input:focus + .slider {
box-shadow: 0 0 1px #101010;
}
input:checked + .slider:before {
-webkit-transform: translateX(17px);
-ms-transform: translateX(17px);
transform: translateX(17px);
}
.slider.round {
border-radius: 20px;
}
.slider.round:before {
border-radius: 50%;
}
</style>