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

92 lines
1.6 KiB
Vue
Raw Normal View History

2024-08-13 08:55:49 +00:00
<script lang="ts" setup>
2024-08-13 08:55:49 +00:00
const emit = defineEmits<{
2024-08-13 08:55:49 +00:00
(e: 'click'): void;
}>();
2024-08-13 08:55:49 +00:00
const props = defineProps<{
2024-08-13 08:55:49 +00:00
twoWay?: boolean;
color?: string;
2024-08-13 08:55:49 +00:00
disable?: boolean;
2024-08-13 08:55:49 +00:00
}>();
const model = defineModel<boolean>({ default: false });
2024-08-13 08:55:49 +00:00
function handleClick() {
if (props.disable) return;
emit('click');
}
2024-08-13 08:55:49 +00:00
</script>
<template>
2024-08-13 08:55:49 +00:00
<label class="switch" @click.stop="handleClick">
<input type="checkbox" :disabled="twoWay || disable" v-model="model" />
<div class="slider round" :class="{ disable: disable }"></div>
2024-08-13 08:55:49 +00:00
</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;
2024-08-13 08:55:49 +00:00
&.disable {
cursor: not-allowed !important;
background-color: var(--stone-4);
}
2024-08-13 08:55:49 +00:00
}
.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));
2024-08-13 08:55:49 +00:00
&.disable {
2024-09-05 15:25:35 +07:00
// background-color: var(--stone-4);
2024-08-13 08:55:49 +00:00
}
2024-08-13 08:55:49 +00:00
}
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>