api-client/components/smart/Toggle.vue

85 lines
1.8 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>
2021-08-29 11:41:37 +00:00
<label class="cursor-pointer pl-0 align-middle">
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>
2021-08-24 03:44:46 +00:00
import { defineComponent } from "@nuxtjs/composition-api"
export default defineComponent({
2021-05-18 09:27:29 +00:00
props: {
on: {
type: Boolean,
default: false,
},
},
2021-08-24 03:44:46 +00:00
})
2021-05-18 09:27:29 +00:00
</script>
2019-12-06 01:41:38 +00:00
<style scoped lang="scss">
2021-08-28 00:17:33 +00:00
$useBorder: true;
$borderColor: var(--divider-color);
2021-08-28 00:17:33 +00:00
$activeColor: var(--divider-color);
$inactiveColor: var(--divider-color);
2021-08-28 00:17:33 +00:00
$inactiveHandleColor: var(--secondary-light-color);
$activeHandleColor: var(--accent-color);
$width: 1.6rem;
2021-08-28 00:17:33 +00:00
$height: 0.6rem;
$indicatorHeight: 0.4rem;
$indicatorWidth: 0.4rem;
$handleSpacing: 0.1rem;
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;
2021-08-28 00:17:33 +00:00
@apply 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);
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;
2021-08-28 00:17:33 +00:00
@apply flex;
@apply flex-shrink-0;
2020-09-22 17:06:37 +00:00
@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;
2021-08-28 00:17:33 +00:00
width: $indicatorWidth;
height: $indicatorHeight;
2019-11-02 05:32:21 +00:00
}
2019-08-29 21:55:06 +00:00
2019-11-02 05:32:21 +00:00
&.on {
2021-08-28 00:17:33 +00:00
// background-color: $activeColor;
2019-11-02 05:32:21 +00:00
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>