Skip to content

Commit 7453752

Browse files
committed
add support for playground link
1 parent 5bbc595 commit 7453752

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

packages/docs/src/components/app/Markup.vue

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@
5353
<v-btn
5454
v-if="isHovering"
5555
:key="icon"
56+
:icon="props.openInPlayground ? '$vuetify-play' : '$vuetify-bin'"
5657
class="text-disabled me-12 mt-2 app-markup-btn position-absolute right-0 top-0"
5758
density="comfortable"
58-
icon="$vuetify-bin"
5959
size="small"
6060
v-bind="activatorProps"
6161
variant="text"
62-
@click="bin"
62+
@click="openCode"
6363
/>
6464
</v-fade-transition>
6565
</template>
6666

67-
<span>{{ t('open-in-vuetify-bin') }}</span>
67+
<span>{{ openInPlayground ? t('open-in-playground') : t('open-in-vuetify-bin') }}</span>
6868
</v-tooltip>
6969

7070
<div class="pa-4 pe-12">
@@ -107,6 +107,11 @@
107107
type: Boolean,
108108
default: true,
109109
},
110+
section: {
111+
type: String,
112+
default: 'template',
113+
},
114+
openInPlayground: Boolean,
110115
})
111116
112117
// Transform inline links in typescript into actual links
@@ -137,7 +142,15 @@
137142
const className = computed(() => `language-${props.language}`)
138143
const icon = computed(() => clicked.value ? 'mdi-check' : 'mdi-clipboard-text-outline')
139144
140-
async function bin () {
145+
function openCode () {
146+
if (props.openInPlayground) {
147+
openPlayground()
148+
} else {
149+
openBin()
150+
}
151+
}
152+
153+
async function openBin () {
141154
const el = root.value?.$el.querySelector('code')
142155
const code = props.code || el?.innerText || ''
143156
const language = props.language || 'markdown'
@@ -148,6 +161,16 @@
148161
window.open(compressed, '_blank')
149162
}
150163
164+
async function openPlayground () {
165+
const url = usePlayground([{
166+
name: props.section,
167+
language: props.language,
168+
content: props.code,
169+
}])
170+
171+
window.open(url, '_blank')
172+
}
173+
151174
async function copy () {
152175
const el = root.value?.$el.querySelector('code')
153176

packages/docs/src/components/home/Entry.vue

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@
9393

9494
<v-col class="d-md-block d-none" cols="12" md="6">
9595
<v-sheet class="rounded-lg bg-surface elevation-10">
96-
<AppMarkup :code="code" class="bg-black rounded-lg" />
96+
<AppMarkup
97+
:code="code"
98+
class="bg-black rounded-lg pa-5"
99+
open-in-playground
100+
/>
97101
</v-sheet>
98102
</v-col>
99103
</v-row>
@@ -106,17 +110,15 @@
106110
</template>
107111

108112
<script setup>
109-
const code = `
110-
<template>
111-
<v-app>
112-
<v-container>
113-
<v-btn color="primary">
114-
Hello Vuetify!
115-
</v-btn>
116-
</v-container>
117-
</v-app>
118-
</template>
119-
`
113+
const code = `<template>
114+
<v-app>
115+
<v-container>
116+
<v-btn color="primary">
117+
Hello Vuetify!
118+
</v-btn>
119+
</v-container>
120+
</v-app>
121+
</template>`
120122
121123
const isCopying = shallowRef(false)
122124

packages/docs/src/i18n/messages/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
"discord": "Discord",
139139
"done": "All done",
140140
"edit-in-playground": "Edit in Vuetify Playground",
141+
"open-in-playground": "Open in Vuetify Playground",
141142
"edit-this-page": "Edit this page on",
142143
"edit": "Edit",
143144
"enable-banners": "Enable banners",

0 commit comments

Comments
 (0)