2019-08-29 21:55:06 +00:00
|
|
|
<template>
|
2020-12-11 16:54:34 +00:00
|
|
|
<div @click="toggle()" class="inline-block cursor-pointer">
|
2019-11-12 04:52:50 +00:00
|
|
|
<label class="toggle" :class="{ on: on }" ref="toggle">
|
2019-08-29 21:55:06 +00:00
|
|
|
<span class="handle"></span>
|
|
|
|
|
</label>
|
2020-12-11 16:54:34 +00:00
|
|
|
<label class="pl-0 align-middle cursor-pointer">
|
2019-10-25 08:14:34 +00:00
|
|
|
<slot />
|
2019-10-06 02:16:48 +00:00
|
|
|
</label>
|
2019-08-29 21:55:06 +00:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2019-12-06 01:41:38 +00:00
|
|
|
<style scoped lang="scss">
|
2019-11-02 05:32:21 +00:00
|
|
|
$useBorder: false;
|
|
|
|
|
$borderColor: var(--fg-light-color);
|
|
|
|
|
$activeColor: var(--ac-color);
|
|
|
|
|
$inactiveColor: var(--fg-light-color);
|
|
|
|
|
$inactiveHandleColor: var(--bg-color);
|
|
|
|
|
$activeHandleColor: var(--act-color);
|
|
|
|
|
$width: 32px;
|
|
|
|
|
$height: 16px;
|
|
|
|
|
$handleSpacing: 4px;
|
|
|
|
|
$transition: all 0.2s ease-in-out;
|
2019-08-29 21:55:06 +00:00
|
|
|
|
2020-12-11 16:54:34 +00:00
|
|
|
.toggle {
|
2020-09-22 17:06:37 +00:00
|
|
|
@apply relative;
|
|
|
|
|
@apply inline-block;
|
|
|
|
|
@apply align-middle;
|
|
|
|
|
@apply rounded-full;
|
|
|
|
|
@apply p-0;
|
2020-12-11 16:54:34 +00:00
|
|
|
@apply m-4;
|
2020-09-22 17:06:37 +00:00
|
|
|
@apply cursor-pointer;
|
2020-12-12 13:46:37 +00:00
|
|
|
@apply flex-shrink-0;
|
2020-10-16 01:40:07 +00:00
|
|
|
|
2019-11-02 05:32:21 +00:00
|
|
|
width: $width;
|
|
|
|
|
height: $height;
|
|
|
|
|
border: if($useBorder, 2px solid $borderColor, none);
|
|
|
|
|
background-color: if($useBorder, transparent, $inactiveColor);
|
|
|
|
|
transition: $transition;
|
|
|
|
|
box-sizing: initial;
|
2019-08-29 21:55:06 +00:00
|
|
|
|
2019-11-02 05:32:21 +00:00
|
|
|
.handle {
|
2020-09-22 17:06:37 +00:00
|
|
|
@apply absolute;
|
|
|
|
|
@apply inline-block;
|
|
|
|
|
@apply inset-0;
|
|
|
|
|
@apply rounded-full;
|
|
|
|
|
@apply pointer-events-none;
|
2020-10-16 01:40:07 +00:00
|
|
|
|
2020-09-22 17:06:37 +00:00
|
|
|
transition: $transition;
|
2019-11-02 05:32:21 +00:00
|
|
|
margin: $handleSpacing;
|
|
|
|
|
background-color: $inactiveHandleColor;
|
|
|
|
|
width: #{$height - ($handleSpacing * 2)};
|
|
|
|
|
height: #{$height - ($handleSpacing * 2)};
|
|
|
|
|
}
|
2019-08-29 21:55:06 +00:00
|
|
|
|
2019-11-02 05:32:21 +00:00
|
|
|
&.on {
|
|
|
|
|
background-color: $activeColor;
|
|
|
|
|
border-color: $activeColor;
|
2019-08-29 21:55:06 +00:00
|
|
|
|
2019-11-02 05:32:21 +00:00
|
|
|
.handle {
|
|
|
|
|
background-color: $activeHandleColor;
|
|
|
|
|
left: #{$width - $height};
|
2019-08-29 21:55:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-11-02 05:32:21 +00:00
|
|
|
}
|
2019-08-29 21:55:06 +00:00
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<script>
|
2019-11-02 05:32:21 +00:00
|
|
|
export default {
|
|
|
|
|
props: {
|
|
|
|
|
on: {
|
|
|
|
|
type: Boolean,
|
2020-02-24 18:44:50 +00:00
|
|
|
default: false,
|
|
|
|
|
},
|
2019-11-02 05:32:21 +00:00
|
|
|
},
|
2019-08-30 10:07:51 +00:00
|
|
|
|
2019-11-02 05:32:21 +00:00
|
|
|
methods: {
|
|
|
|
|
toggle() {
|
2020-02-25 02:06:23 +00:00
|
|
|
const containsOnClass = this.$refs.toggle.classList.toggle("on")
|
|
|
|
|
this.$emit("change", containsOnClass)
|
2020-02-24 18:44:50 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
2019-08-29 21:55:06 +00:00
|
|
|
</script>
|