refactor: toggle button component
This commit is contained in:
parent
6b7e943f68
commit
0869ff10e0
2 changed files with 77 additions and 0 deletions
76
src/components/button/ToggleButton.vue
Normal file
76
src/components/button/ToggleButton.vue
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<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>
|
||||
|
|
@ -5,3 +5,4 @@ export { default as EditButton } from './EditButton.vue';
|
|||
export { default as DeleteButton } from './DeleteButton.vue';
|
||||
export { default as BackButton } from './BackButton.vue';
|
||||
export { default as UndoButton } from './UndoButton.vue';
|
||||
export { default as ToggleButton } from './ToggleButton.vue';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue