forked from unovue/reka-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStackblitz.vue
37 lines (32 loc) · 935 Bytes
/
Stackblitz.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { makeStackblitzParams } from '../codeeditor'
import Tooltip from './Tooltip.vue'
import { Icon } from '@iconify/vue'
const props = defineProps<{
name: string
files: string[]
}>()
const sources = ref<Record<string, string>>({})
onMounted(() => {
props.files?.forEach((file) => {
const [folder, fileName] = file.split('/')
const extension = file.split('.').pop()
import(`../components/demo/${props.name}/${folder}/${fileName.replace(`.${extension}`, '')}.${extension}?raw`).then(
res => (sources.value[fileName] = res.default),
)
})
})
function handleClick() {
makeStackblitzParams(props.name, sources.value)
}
</script>
<template>
<div>
<Tooltip :content="`Open ${name} in Stackblitz`">
<button @click="handleClick">
<Icon icon="simple-icons:stackblitz" />
</button>
</Tooltip>
</div>
</template>