|
1 | 1 | <script lang='ts' setup name="demo-block">
|
| 2 | +import { Icon } from '@iconify/vue' |
2 | 3 | import { useClipboard, useToggle } from '@vueuse/core'
|
3 |
| -import { computed } from 'vue' |
4 |
| -import DotPattern from '../../../../components/DotPattern/DotPattern.vue' |
5 |
| -import { cn } from '../../../../lib/utils' |
| 4 | +import { computed, ref } from 'vue' |
| 5 | +import { MagicString } from 'vue/compiler-sfc' |
| 6 | +import DotPattern from '../../../../src/components/spark-ui/DotPattern/DotPattern.vue' |
| 7 | +import { cn } from '../../../../src/lib/utils' |
6 | 8 | import { demoProps } from './index'
|
7 | 9 |
|
8 | 10 | const props = defineProps(demoProps)
|
9 | 11 |
|
10 |
| -const decodedHighlightedCode = computed(() => |
11 |
| - decodeURIComponent(props.highlightedCode), |
12 |
| -) |
| 12 | +const decodedHighlightedCode = computed(() => { |
| 13 | + try { |
| 14 | + const decodeHighlightedCode = decodeURIComponent(props.highlightedCode) |
| 15 | + const updatedCode = updateImportPaths(decodeHighlightedCode) |
| 16 | + return updatedCode |
| 17 | + } |
| 18 | + catch (error) { |
| 19 | + console.error('Error decoding highlighted code:', error) |
| 20 | + return props.highlightedCode |
| 21 | + } |
| 22 | +}) |
| 23 | +
|
| 24 | +function updateImportPaths(code: string): string { |
| 25 | + const magicString = new MagicString(code) |
| 26 | +
|
| 27 | + magicString.replaceAll('../../components/spark-ui/', '@/components/') |
| 28 | + magicString.replaceAll('../../../lib/utils', '@/libs/utils') |
| 29 | +
|
| 30 | + return magicString.toString() |
| 31 | +} |
13 | 32 | const { copy, copied } = useClipboard({ source: decodeURIComponent(props.code) })
|
14 | 33 | const [value, toggle] = useToggle()
|
| 34 | +const refreshKey = ref(0) |
| 35 | +function handleRefreshComponent() { |
| 36 | + refreshKey.value += 1 |
| 37 | +} |
15 | 38 | </script>
|
16 | 39 |
|
17 | 40 | <template>
|
18 |
| - <div class="mt-6"> |
| 41 | + <div class="mt-6 relative"> |
19 | 42 | <div
|
20 |
| - class="relative flex h-96 w-full bg-[#fffefe] p-6 flex-col items-center justify-center overflow-hidden rounded-lg border-parent dark:border-none bg-background md:shadow-md c-#282f38 overflow-x-scroll dark:bg-[#000000] flex-wrap [&:o-button-base]:!c-context vp-raw bg" |
| 43 | + class="relative flex h-[600px] w-full bg-[#fffefe] p-6 flex-col items-center justify-center overflow-hidden rounded-lg border-parent dark:border-none bg-background md:shadow-md c-#282f38 overflow-x-scroll dark:bg-[#000000] flex-wrap [&:o-button-base]:!c-context vp-raw bg" |
21 | 44 | >
|
22 |
| - <div class="w-full py-6 h-full"> |
23 |
| - <div class="border-child relative rounded-md w-full h-full flex items-center justify-center dark:border-none"> |
24 |
| - <p |
25 |
| - class="z-10 whitespace-pre-wrap text-center text-5xl font-medium tracking-tighter text-black dark:text-white" |
26 |
| - > |
27 |
| - <slot /> |
| 45 | + <DotPattern |
| 46 | + class="absolute inset-0 size-full" :class="cn( |
| 47 | + '[mask-image:radial-gradient(600px_circle_at_center,white,transparent)]', |
| 48 | + )" |
| 49 | + /> |
| 50 | + <button type="button" class="absolute right-6 text-black top-2 hover:bg-[#F4F4F5] dark:hover:bg-[#27272A] p-2 rounded-md" @click="handleRefreshComponent"> |
| 51 | + <Icon |
| 52 | + icon="ic:round-replay" class="text-black w-5 h-5 dark:text-white" |
| 53 | + /> |
| 54 | + </button> |
| 55 | + <div class="w-3/4 py-6"> |
| 56 | + <div class="border-child bg-white shadow-lg dark:bg-black relative rounded-md w-full h-full flex items-center justify-center dark:border-none"> |
| 57 | + <p class="z-10"> |
| 58 | + <slot :key="refreshKey" /> |
28 | 59 | </p>
|
29 |
| - <DotPattern |
30 |
| - :class="cn( |
31 |
| - '[mask-image:radial-gradient(300px_circle_at_center,white,transparent)]', |
32 |
| - )" |
33 |
| - /> |
34 | 60 | </div>
|
35 | 61 | <div class="relative">
|
36 | 62 | <div class="flex justify-end pt-3 gap-2">
|
@@ -108,4 +134,12 @@ const [value, toggle] = useToggle()
|
108 | 134 | .border-child {
|
109 | 135 | border: 1px solid rgb(239, 239, 239);
|
110 | 136 | }
|
| 137 | +
|
| 138 | +.rotate-0 { |
| 139 | + transform: rotate(0deg); |
| 140 | +} |
| 141 | +
|
| 142 | +.rotate-45 { |
| 143 | + transform: rotate(45deg); |
| 144 | +} |
111 | 145 | </style>
|
0 commit comments