Skip to content

Commit 7c94c27

Browse files
committed
Implementing layout toggle for vertical/horizontal
1 parent 1ebcbc6 commit 7c94c27

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/App.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ import { onMounted, ref } from 'vue';
99
import YVHeader from './YvHeader.vue';
1010
1111
const preferDark = useStorage('vue-sfc-playground-prefer-dark', true);
12-
1312
const theme = ref<'dark' | 'light'>('dark');
1413
function setTheme(newTheme: 'dark' | 'light') {
1514
theme.value = newTheme;
1615
preferDark.value = newTheme === 'dark';
1716
}
1817
18+
const layout = useStorage<'horizontal' | 'vertical'>('yehyecoa-vue-layout', 'horizontal');
19+
function toggleLayout() {
20+
layout.value = layout.value === 'horizontal' ? 'vertical' : 'horizontal';
21+
}
22+
1923
function setVH() {
2024
document.documentElement.style.setProperty('--vh', `${window.innerHeight}px`);
2125
}
@@ -62,13 +66,15 @@ onMounted(async () => {
6266
<YVHeader
6367
:theme="theme"
6468
@set-theme="setTheme"
69+
@toggle-layout="toggleLayout"
6570
/>
6671
<Repl
6772
:editor="Monaco"
6873
:show-compile-output="false"
6974
:show-import-map="false"
7075
:show-ts-config="false"
71-
:theme="theme"
76+
:theme
77+
:layout
7278
:editor-options="{
7379
autoSaveText: false,
7480
}"

src/YvHeader.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
<script setup lang="ts">
2+
import { useStorage } from '@vueuse/core';
23
import { onMounted } from 'vue';
34
45
defineProps<{
56
theme: 'dark' | 'light';
67
}>();
78
89
// TODO: implement the download functionality, just like the official playground
9-
const emit = defineEmits(['set-theme']);
10+
const emit = defineEmits({
11+
'set-theme': (theme: 'dark' | 'light') => theme,
12+
'toggle-layout': () => true,
13+
});
1014
const cls = document.documentElement.classList;
1115
1216
function setTheme() {
1317
cls.toggle('dark');
1418
emit('set-theme', cls.contains('dark') ? 'dark' : 'light');
1519
}
1620
21+
const layout = useStorage<'horizontal' | 'vertical'>('yehyecoa-vue-layout', 'horizontal');
22+
function toggleLayout() {
23+
emit('toggle-layout');
24+
}
25+
1726
onMounted(() => {
1827
emit('set-theme', cls.contains('dark') ? 'dark' : 'light');
1928
});
@@ -35,6 +44,9 @@ onMounted(() => {
3544
<span uno-hidden sm:inline-block>yehyecoa-vue</span>
3645
</h1>
3746
<div flex gap-2 text-neutral-500>
47+
<button toolbar-btn @click="toggleLayout">
48+
<div :class="layout === 'vertical' ? 'i-mynaui:rectangle' : 'i-mynaui:rectangle-vertical'" />
49+
</button>
3850
<button
3951
toolbar-btn
4052
:title="`Switch to ${theme === 'dark' ? 'light' : 'dark'} theme`"

0 commit comments

Comments
 (0)