shadcn-vue/apps/www/.vitepress/theme/components/Stackblitz.vue
zernonia 72f9bd5ef5
refactor: code preview (#411)
* feat: generate code dynamically

* chore: cleanup and transform path on component

* feat: create config sheet

* feat: code wrapper

* fix: not acting immediately

* chore: add key to vnode

* chore: add vue-sonner to demos dependencies, add placeholder for codeConfigs

* chore: fix wrong icons

* chore: improve crawling logic

---------

Co-authored-by: Sadegh Barati <sadeghbaratiwork@gmail.com>
2024-03-14 18:28:13 +08:00

39 lines
908 B
Vue

<script setup lang="ts">
import { onMounted, ref, toRefs, watch } from 'vue'
import { Icon } from '@iconify/vue'
import { makeStackblitzParams } from '../utils/codeeditor'
import Tooltip from './Tooltip.vue'
import { Button } from '@/lib/registry/new-york/ui/button'
import type { Style } from '@/lib/registry/styles'
const props = defineProps<{
name: string
code: string
style: Style
}>()
const { code } = toRefs(props)
const sources = ref<Record<string, string>>({})
onMounted(() => {
})
watch(code, () => {
sources.value['App.vue'] = code.value
})
function handleClick() {
makeStackblitzParams(props.name, props.style, sources.value)
}
</script>
<template>
<div>
<Tooltip :content="`Open ${name} in Stackblitz`">
<Button :variant="'ghost'" :size="'icon'" @click="handleClick">
<Icon icon="simple-icons:stackblitz" />
</Button>
</Tooltip>
</div>
</template>