api-client/components/smart/Toggle.vue

81 lines
1.7 KiB
Vue
Raw Normal View History

2019-08-29 21:55:06 +00:00
<template>
<div
class="cursor-pointer flex-nowrap inline-flex items-center justify-center"
@click="$emit('change')"
>
2021-05-18 09:27:29 +00:00
<label ref="toggle" class="toggle" :class="{ on: on }">
2019-08-29 21:55:06 +00:00
<span class="handle"></span>
</label>
<label class="cursor-pointer font-semibold pl-0 align-middle truncate">
2021-05-18 09:27:29 +00:00
<slot></slot>
2019-10-06 02:16:48 +00:00
</label>
2019-08-29 21:55:06 +00:00
</div>
</template>
2021-05-18 09:27:29 +00:00
<script>
export default {
props: {
on: {
type: Boolean,
default: false,
},
},
}
</script>
2019-12-06 01:41:38 +00:00
<style scoped lang="scss">
2019-11-02 05:32:21 +00:00
$useBorder: false;
$borderColor: var(--divider-color);
2021-06-12 16:46:17 +00:00
$activeColor: var(--accent-color);
$inactiveColor: var(--divider-color);
2021-06-12 16:46:17 +00:00
$inactiveHandleColor: var(--primary-color);
$activeHandleColor: var(--primary-color);
$width: 1.6rem;
$height: 0.78rem;
$handleSpacing: 0.2rem;
2019-11-02 05:32:21 +00:00
$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-flex;
@apply items-center;
@apply justify-center;
2020-09-22 17:06:37 +00:00
@apply rounded-full;
@apply p-0;
@apply mr-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>