Toggle.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <div
  3. class="cursor-pointer flex-nowrap transition inline-flex items-center justify-center group hover:text-secondaryDark"
  4. @click="$emit('change')"
  5. >
  6. <label ref="toggle" class="toggle" :class="{ on: on }">
  7. <span class="handle"></span>
  8. </label>
  9. <label class="cursor-pointer font-semibold pl-0 align-middle">
  10. <slot></slot>
  11. </label>
  12. </div>
  13. </template>
  14. <script>
  15. import { defineComponent } from "@nuxtjs/composition-api"
  16. export default defineComponent({
  17. props: {
  18. on: {
  19. type: Boolean,
  20. default: false,
  21. },
  22. },
  23. })
  24. </script>
  25. <style scoped lang="scss">
  26. $useBorder: true;
  27. $borderColor: var(--divider-color);
  28. $activeColor: var(--divider-dark-color);
  29. $inactiveColor: var(--divider-color);
  30. $inactiveHandleColor: var(--secondary-light-color);
  31. $activeHandleColor: var(--accent-color);
  32. $width: 1.6rem;
  33. $height: 0.6rem;
  34. $indicatorHeight: 0.4rem;
  35. $indicatorWidth: 0.4rem;
  36. $handleSpacing: 0.1rem;
  37. $transition: all 0.2s ease-in-out;
  38. .toggle {
  39. @apply relative;
  40. @apply flex;
  41. @apply items-center;
  42. @apply justify-center;
  43. @apply rounded-full;
  44. @apply p-0;
  45. @apply mr-4;
  46. @apply cursor-pointer;
  47. @apply flex-shrink-0;
  48. @apply group-hover:border-accentDark;
  49. @apply transition;
  50. width: $width;
  51. height: $height;
  52. border: if($useBorder, 2px solid $borderColor, none);
  53. background-color: if($useBorder, transparent, $inactiveColor);
  54. box-sizing: initial;
  55. .handle {
  56. @apply absolute;
  57. @apply flex;
  58. @apply flex-shrink-0;
  59. @apply inset-0;
  60. @apply rounded-full;
  61. @apply pointer-events-none;
  62. transition: $transition;
  63. margin: $handleSpacing;
  64. background-color: $inactiveHandleColor;
  65. width: $indicatorWidth;
  66. height: $indicatorHeight;
  67. }
  68. &.on {
  69. // background-color: $activeColor;
  70. border-color: $activeColor;
  71. .handle {
  72. background-color: $activeHandleColor;
  73. left: #{$width - $height};
  74. }
  75. }
  76. }
  77. </style>