index.vue 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <script setup lang="ts">
  2. defineOptions({
  3. name: 'SearchBar',
  4. })
  5. withDefaults(
  6. defineProps<{
  7. showToggle?: boolean
  8. background?: boolean
  9. }>(),
  10. {
  11. showToggle: true,
  12. background: false,
  13. },
  14. )
  15. const emits = defineEmits<{
  16. toggle: [
  17. value: boolean,
  18. ]
  19. }>()
  20. const fold = defineModel<boolean>('fold', {
  21. default: true,
  22. })
  23. function toggle() {
  24. fold.value = !fold.value
  25. emits('toggle', fold.value)
  26. }
  27. </script>
  28. <template>
  29. <div
  30. class="relative" :class="{
  31. 'py-4': showToggle,
  32. 'px-4 bg-[var(--g-bg)] transition': background,
  33. }"
  34. >
  35. <slot :fold="fold" :toggle="toggle" />
  36. <div v-if="showToggle" class="absolute bottom-0 left-0 w-full translate-y-1/2 text-center">
  37. <button class="h-5 inline-flex cursor-pointer select-none items-center border-size-0 rounded bg-[var(--g-bg)] px-2 text-xs font-medium outline-none" @click="toggle">
  38. <SvgIcon :name="fold ? 'i-ep:caret-bottom' : 'i-ep:caret-top' " />
  39. </button>
  40. </div>
  41. </div>
  42. </template>