|
1 | 1 | <script setup lang="ts">
|
2 |
| - import { ref, computed } from 'vue' |
3 |
| - import { useCopyCode } from '../composables/useCopyCode' |
4 |
| -
|
5 |
| - import { |
6 |
| - TransitionRoot, |
7 |
| - TransitionChild, |
8 |
| - Dialog, |
9 |
| - DialogPanel, |
10 |
| - DialogTitle, |
11 |
| - } from '@headlessui/vue' |
12 |
| -
|
13 |
| - type TransitionClass = { |
14 |
| - enter: string |
15 |
| - enterFrom: string |
16 |
| - enterTo: string |
17 |
| - leave: string |
18 |
| - leaveFrom: string |
19 |
| - leaveTo: string |
20 |
| - } |
21 |
| -
|
22 |
| - const transitionList = ref<string[]>([ |
23 |
| - 'fade', |
24 |
| - 'slideInRight', |
25 |
| - 'slideInDown', |
26 |
| - 'pop' |
27 |
| - ]) |
28 |
| -
|
29 |
| - const showCheckIcon = ref(false) |
30 |
| - const currentTransition = ref(transitionList.value[0]) |
31 |
| - const isOpen = ref(false) |
32 |
| -
|
33 |
| - const transitionClass = computed<TransitionClass>(() => { |
34 |
| -
|
35 |
| - if (currentTransition.value === 'slideInRight') { |
36 |
| - return { |
37 |
| - enter: 'transition-transform transition-opacity duration-500 ease-out', |
38 |
| - enterFrom: 'opacity-0 translate-x-full', |
39 |
| - enterTo: 'opacity-100 translate-x-0', |
40 |
| - leave: 'transition-transform transition-opacity duration-500 ease-out', |
41 |
| - leaveFrom: 'opacity-100 translate-x-0', |
42 |
| - leaveTo: 'opacity-0 translate-x-full', |
43 |
| - } |
44 |
| - } |
45 |
| -
|
46 |
| - if (currentTransition.value === 'slideInDown') { |
47 |
| - return { |
48 |
| - enter: 'transition-transform transition-opacity duration-500 ease-out', |
49 |
| - enterFrom: 'opacity-0 -translate-y-full', |
50 |
| - enterTo: 'opacity-100 translate-y-0', |
51 |
| - leave: 'transition-transform transition-opacity duration-500 ease-out', |
52 |
| - leaveFrom: 'opacity-100 translate-y-0', |
53 |
| - leaveTo: 'opacity-0 -translate-y-full', |
54 |
| - } |
| 2 | +import { |
| 3 | + Dialog, |
| 4 | + DialogPanel, |
| 5 | + DialogTitle, |
| 6 | + TransitionChild, |
| 7 | + TransitionRoot, |
| 8 | +} from '@headlessui/vue' |
| 9 | +import { computed, ref } from 'vue' |
| 10 | +
|
| 11 | +import { useCopyCode } from '../composables/useCopyCode' |
| 12 | +
|
| 13 | +interface TransitionClass { |
| 14 | + enter: string |
| 15 | + enterFrom: string |
| 16 | + enterTo: string |
| 17 | + leave: string |
| 18 | + leaveFrom: string |
| 19 | + leaveTo: string |
| 20 | +} |
| 21 | +
|
| 22 | +const transitionList = ref<string[]>([ |
| 23 | + 'fade', |
| 24 | + 'slideInRight', |
| 25 | + 'slideInDown', |
| 26 | + 'pop', |
| 27 | +]) |
| 28 | +
|
| 29 | +const showCheckIcon = ref(false) |
| 30 | +const currentTransition = ref(transitionList.value[0]) |
| 31 | +const isOpen = ref(false) |
| 32 | +
|
| 33 | +const transitionClass = computed<TransitionClass>(() => { |
| 34 | + if (currentTransition.value === 'slideInRight') { |
| 35 | + return { |
| 36 | + enter: 'transition-transform transition-opacity duration-500 ease-out', |
| 37 | + enterFrom: 'opacity-0 translate-x-full', |
| 38 | + enterTo: 'opacity-100 translate-x-0', |
| 39 | + leave: 'transition-transform transition-opacity duration-500 ease-out', |
| 40 | + leaveFrom: 'opacity-100 translate-x-0', |
| 41 | + leaveTo: 'opacity-0 translate-x-full', |
55 | 42 | }
|
| 43 | + } |
56 | 44 |
|
57 |
| - if (currentTransition.value === 'pop') { |
58 |
| - return { |
59 |
| - enter: 'transition-transform duration-300', |
60 |
| - enterFrom: 'transform scale-0', |
61 |
| - enterTo: 'transform scale-100', |
62 |
| - leave: 'transition-transform duration-300', |
63 |
| - leaveFrom: 'transform scale-100', |
64 |
| - leaveTo: 'transform scale-0', |
65 |
| - } |
| 45 | + if (currentTransition.value === 'slideInDown') { |
| 46 | + return { |
| 47 | + enter: 'transition-transform transition-opacity duration-500 ease-out', |
| 48 | + enterFrom: 'opacity-0 -translate-y-full', |
| 49 | + enterTo: 'opacity-100 translate-y-0', |
| 50 | + leave: 'transition-transform transition-opacity duration-500 ease-out', |
| 51 | + leaveFrom: 'opacity-100 translate-y-0', |
| 52 | + leaveTo: 'opacity-0 -translate-y-full', |
66 | 53 | }
|
| 54 | + } |
67 | 55 |
|
| 56 | + if (currentTransition.value === 'pop') { |
68 | 57 | return {
|
69 |
| - enter: 'transition-opacity duration-300', |
70 |
| - enterFrom: 'opacity-0', |
71 |
| - enterTo: 'opacity-100', |
72 |
| - leave: 'transition-opacity duration-300', |
73 |
| - leaveFrom: 'opacity-100', |
74 |
| - leaveTo: 'opacity-0', |
| 58 | + enter: 'transition-transform duration-300', |
| 59 | + enterFrom: 'transform scale-0', |
| 60 | + enterTo: 'transform scale-100', |
| 61 | + leave: 'transition-transform duration-300', |
| 62 | + leaveFrom: 'transform scale-100', |
| 63 | + leaveTo: 'transform scale-0', |
75 | 64 | }
|
76 |
| - }) |
| 65 | + } |
77 | 66 |
|
78 |
| - const renderedCode = computed(() => { |
79 |
| - return ` |
| 67 | + return { |
| 68 | + enter: 'transition-opacity duration-300', |
| 69 | + enterFrom: 'opacity-0', |
| 70 | + enterTo: 'opacity-100', |
| 71 | + leave: 'transition-opacity duration-300', |
| 72 | + leaveFrom: 'opacity-100', |
| 73 | + leaveTo: 'opacity-0', |
| 74 | + } |
| 75 | +}) |
| 76 | +
|
| 77 | +const renderedCode = computed(() => { |
| 78 | + return ` |
80 | 79 | <TransitionRoot appear :show="isOpen">
|
81 | 80 | <Dialog :open="isOpen" @close="setIsOpen" class="relative z-50">
|
82 | 81 | <div class="fixed inset-0 bg-black/30" aria-hidden="true" />
|
|
104 | 103 | </Dialog>
|
105 | 104 | </TransitionRoot>
|
106 | 105 | `
|
107 |
| - }) |
| 106 | +}) |
108 | 107 |
|
109 |
| - function setIsOpen(value: boolean) { |
110 |
| - isOpen.value = value |
111 |
| - } |
| 108 | +function setIsOpen(value: boolean) { |
| 109 | + isOpen.value = value |
| 110 | +} |
112 | 111 |
|
113 |
| - function handleClick(trans: string) { |
114 |
| - setIsOpen(true) |
115 |
| - currentTransition.value = trans |
116 |
| - } |
| 112 | +function handleClick(trans: string) { |
| 113 | + setIsOpen(true) |
| 114 | + currentTransition.value = trans |
| 115 | +} |
117 | 116 |
|
118 |
| - async function handleCopyCode() { |
119 |
| - await useCopyCode({ code: renderedCode.value, checkIconRef: showCheckIcon }) |
120 |
| - } |
| 117 | +async function handleCopyCode() { |
| 118 | + await useCopyCode({ code: renderedCode.value, checkIconRef: showCheckIcon }) |
| 119 | +} |
121 | 120 | </script>
|
122 | 121 |
|
123 | 122 | <template>
|
|
162 | 161 | </div>
|
163 | 162 |
|
164 | 163 | <div class="flex flex-col gap-4">
|
165 |
| - |
166 | 164 | <TransitionRoot
|
167 | 165 | appear
|
168 | 166 | :show="isOpen"
|
169 | 167 | >
|
170 |
| - <Dialog :open="isOpen" @close="setIsOpen" class="relative z-50"> |
| 168 | + <Dialog :open="isOpen" class="relative z-50" @close="setIsOpen"> |
171 | 169 | <div class="fixed inset-0 bg-black/30" aria-hidden="true" />
|
172 | 170 |
|
173 |
| - |
174 |
| - <div class="fixed inset-0 flex w-screen items-center justify-center p-4"> |
175 |
| - |
| 171 | + <div class="fixed inset-0 w-screen flex items-center justify-center p-4"> |
176 | 172 | <TransitionChild
|
177 | 173 | :enter="transitionClass.enter"
|
178 | 174 | :enter-from="transitionClass.enterFrom"
|
|
181 | 177 | :leave-from="transitionClass.leaveFrom"
|
182 | 178 | :leave-to="transitionClass.leaveTo"
|
183 | 179 | >
|
184 |
| - <DialogPanel class="w-full max-w-sm rounded bg-white p-5"> |
| 180 | + <DialogPanel class="max-w-sm w-full rounded bg-white p-5"> |
185 | 181 | <DialogTitle>Complete your order</DialogTitle>
|
186 | 182 |
|
187 | 183 | <div class="mt-4">
|
|
0 commit comments