api-client/components/toggle.vue

99 lines
1.8 KiB
Vue
Raw Normal View History

2019-08-29 21:55:06 +00:00
<template>
<div @click="toggle()">
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>
<label class="caption">
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);
2019-08-29 21:55:06 +00:00
2019-11-02 05:32:21 +00:00
$inactiveHandleColor: var(--bg-color);
$activeHandleColor: var(--act-color);
2019-08-29 21:55:06 +00:00
2019-11-02 05:32:21 +00:00
$width: 32px;
$height: 16px;
$handleSpacing: 4px;
2019-08-29 21:55:06 +00:00
2019-11-02 05:32:21 +00:00
$transition: all 0.2s ease-in-out;
2019-08-29 21:55:06 +00:00
2019-11-02 05:32:21 +00:00
div {
display: inline-block;
cursor: pointer;
}
2019-08-29 21:55:06 +00:00
2019-11-02 05:32:21 +00:00
label.caption {
vertical-align: middle;
cursor: pointer;
}
2019-08-29 21:55:06 +00:00
2019-11-02 05:32:21 +00:00
label.toggle {
position: relative;
display: inline-block;
width: $width;
height: $height;
border: if($useBorder, 2px solid $borderColor, none);
background-color: if($useBorder, transparent, $inactiveColor);
vertical-align: middle;
2019-08-29 21:55:06 +00:00
2019-11-02 05:32:21 +00:00
border-radius: 32px;
transition: $transition;
box-sizing: initial;
padding: 0;
margin: 8px 4px;
cursor: pointer;
2019-08-29 21:55:06 +00:00
2019-11-02 05:32:21 +00:00
.handle {
position: absolute;
display: inline-block;
top: 0;
bottom: 0;
left: 0;
margin: $handleSpacing;
background-color: $inactiveHandleColor;
2019-08-29 21:55:06 +00:00
2019-11-02 05:32:21 +00:00
width: #{$height - ($handleSpacing * 2)};
height: #{$height - ($handleSpacing * 2)};
border-radius: 100px;
2019-08-29 21:55:06 +00:00
2019-11-02 05:32:21 +00:00
pointer-events: none;
transition: $transition;
}
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,
default: false
}
},
2019-11-02 05:32:21 +00:00
methods: {
toggle() {
const containsOnClass = this.$refs.toggle.classList.toggle("on");
this.$emit("change", containsOnClass);
}
2019-11-02 05:32:21 +00:00
}
};
2019-08-29 21:55:06 +00:00
</script>