index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <div class="dropdown-wrap">
  3. <div
  4. class="btn"
  5. @click="emits('update:modelValue', !modelValue)"
  6. >
  7. <slot name="btn"></slot>
  8. </div>
  9. <div
  10. class="container"
  11. :style="{
  12. display: !isMobile() ? 'auto' : modelValue ? 'block' : 'none',
  13. }"
  14. >
  15. <div class="wrap">
  16. <slot name="list"></slot>
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. <script lang="ts" setup>
  22. import { isMobile } from 'billd-utils';
  23. const props = defineProps({
  24. modelValue: { type: Boolean, default: false },
  25. });
  26. const emits = defineEmits(['update:modelValue']);
  27. </script>
  28. <style lang="scss" scoped>
  29. .dropdown-wrap {
  30. position: relative;
  31. &:hover {
  32. .container {
  33. display: block;
  34. }
  35. }
  36. .btn {
  37. cursor: pointer;
  38. user-select: none;
  39. }
  40. .container {
  41. position: absolute;
  42. top: 100%;
  43. right: 0;
  44. z-index: 3;
  45. display: none;
  46. .wrap {
  47. box-sizing: border-box;
  48. margin-top: 5px;
  49. padding: 10px 0;
  50. border-radius: 5px;
  51. background-color: #fff;
  52. box-shadow:
  53. 0 12px 32px rgba(0, 0, 0, 0.1),
  54. 0 2px 6px rgba(0, 0, 0, 0.08);
  55. color: black;
  56. font-size: 14px;
  57. }
  58. }
  59. }
  60. </style>