Select.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div class="flex flex-col gap-4">
  3. <template v-if="id && name">
  4. <div
  5. v-for="part in data"
  6. :key="part[id]"
  7. @click="selected = part[id]"
  8. class="flex gap-2"
  9. >
  10. <svg
  11. width="32"
  12. height="32"
  13. viewBox="0 0 32 32"
  14. fill="none"
  15. xmlns="http://www.w3.org/2000/svg"
  16. >
  17. <path
  18. class="duration-200"
  19. :stroke="selected === part[id] ? '#FF4646' : '#ffffff'"
  20. d="M27.9999 16C27.9999 22.6275 22.6273 28 15.9999 28C9.37246 28 3.99988 22.6275 3.99988 16C3.99988 9.37259 9.37246 4 15.9999 4C22.6273 4 27.9999 9.37259 27.9999 16Z"
  21. stroke-width="2.66667"
  22. />
  23. <path
  24. v-if="selected === part[id]"
  25. :stroke="selected === part[id] ? '#FF4646' : '#ffffff'"
  26. class="zoom-show duration-200"
  27. d="M11.9999 15.9999L14.2436 18.2437C14.4772 18.4773 14.8559 18.4773 15.0895 18.2437L19.9999 13.3333"
  28. stroke-width="2.66667"
  29. stroke-linecap="round"
  30. stroke-linejoin="round"
  31. />
  32. </svg>
  33. <p
  34. class="text-xl duration-150"
  35. :class="{
  36. 'text-primary': selected === part[id],
  37. }"
  38. >
  39. {{ part[name] }}
  40. </p>
  41. </div>
  42. </template>
  43. <template v-else>
  44. <div
  45. v-for="(text, idx) in data"
  46. :key="idx"
  47. @click="selected = text"
  48. class="flex gap-2"
  49. >
  50. <svg
  51. width="32"
  52. height="32"
  53. viewBox="0 0 32 32"
  54. fill="none"
  55. xmlns="http://www.w3.org/2000/svg"
  56. >
  57. <path
  58. class="duration-200"
  59. d="M27.9999 16C27.9999 22.6275 22.6273 28 15.9999 28C9.37246 28 3.99988 22.6275 3.99988 16C3.99988 9.37259 9.37246 4 15.9999 4C22.6273 4 27.9999 9.37259 27.9999 16Z"
  60. :stroke="selected === text ? '#FF4646' : '#ffffff'"
  61. stroke-width="2.66667"
  62. />
  63. <path
  64. v-if="selected === text"
  65. class="zoom-show duration-200"
  66. d="M11.9999 15.9999L14.2436 18.2437C14.4772 18.4773 14.8559 18.4773 15.0895 18.2437L19.9999 13.3333"
  67. :stroke="selected === text ? '#FF4646' : '#ffffff'"
  68. stroke-width="2.66667"
  69. stroke-linecap="round"
  70. stroke-linejoin="round"
  71. />
  72. </svg>
  73. <p
  74. class="text-xl duration-150"
  75. :class="{
  76. 'text-primary': selected === text,
  77. }"
  78. >
  79. {{ text }}
  80. </p>
  81. </div>
  82. </template>
  83. </div>
  84. </template>
  85. <script setup lang="ts">
  86. defineProps<{
  87. id?: string;
  88. name?: string;
  89. data: object[] | string[];
  90. }>();
  91. const selected = defineModel("selected", {
  92. default: undefined,
  93. type: String || null,
  94. });
  95. </script>
  96. <style scoped>
  97. @keyframes zoomShow {
  98. 0% {
  99. opacity: 0;
  100. transform: scale(0.5);
  101. }
  102. 100% {
  103. opacity: 1;
  104. transform: scale(1);
  105. }
  106. }
  107. .zoom-show {
  108. animation: zoomShow ease-in-out 200ms;
  109. }
  110. </style>