index.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <div
  3. class="slider-box"
  4. :class="[isSliderOpen && 'slider-open']"
  5. @click="toggleSlider"
  6. >
  7. <span class="slider-block" />
  8. </div>
  9. </template>
  10. <script lang="ts" setup>
  11. import { ref, watchEffect } from '../../../adapter-vue';
  12. const props = defineProps({
  13. open: {
  14. type: Boolean,
  15. default: false,
  16. },
  17. });
  18. const isSliderOpen = ref(false);
  19. const emits = defineEmits(['change']);
  20. watchEffect(() => {
  21. isSliderOpen.value = props.open;
  22. });
  23. const toggleSlider = () => {
  24. isSliderOpen.value = !isSliderOpen.value;
  25. emits('change', isSliderOpen.value);
  26. };
  27. </script>
  28. <style lang="scss" scoped>
  29. @import "../../../assets/styles/common";
  30. .slider {
  31. &-box {
  32. display: flex;
  33. align-items: center;
  34. width: 40px;
  35. height: 20px;
  36. border-radius: 10px;
  37. background: #e1e1e3;
  38. }
  39. &-open {
  40. background: #006eff !important;
  41. justify-content: flex-end;
  42. }
  43. &-block {
  44. display: inline-block;
  45. width: 16px;
  46. height: 16px;
  47. border-radius: 8px;
  48. margin: 0 2px;
  49. background: #fff;
  50. border: 0 solid rgba(0, 0, 0, 0.85);
  51. box-shadow: 0 2px 4px 0 #d1d1d1;
  52. }
  53. }
  54. </style>