Skip to content

Commit

Permalink
feat: add error toggle (#98)
Browse files Browse the repository at this point in the history
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
  • Loading branch information
Blackman99 and sxzz committed Jun 24, 2023
1 parent 5f543da commit 51819cc
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/editor/CodeMirrorEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { computed } from 'vue'
import type { PreviewMode } from './types'
defineOptions({
editorType: 'monaco',
editorType: 'codemirror',
})
const props = defineProps<{
Expand Down
15 changes: 10 additions & 5 deletions src/editor/EditorContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
import FileSelector from './FileSelector.vue'
import Message from '../Message.vue'
import { debounce } from '../utils'
import { inject } from 'vue'
import { inject, ref } from 'vue'
import { Store } from '../store'
import MessageToggle from './MessageToggle.vue'
import type { EditorComponentType } from './types'
const props = defineProps<{
editorComponent: EditorComponentType
}>()
const store = inject('store') as Store
const showMessage = ref(true)
const onChange = debounce((code: string) => {
store.state.activeFile.code = code
Expand All @@ -25,10 +27,13 @@ const onChange = debounce((code: string) => {
:value="store.state.activeFile.code"
:filename="store.state.activeFile.filename"
/>
<Message
v-if="props.editorComponent.editorType !== 'monaco'"
:err="store.state.errors[0]"
/>
<template v-if="editorComponent.editorType !== 'monaco'">
<Message
v-show="showMessage"
:err="store.state.errors[0]"
/>
<MessageToggle v-model="showMessage" />
</template>
</div>
</template>

Expand Down
67 changes: 67 additions & 0 deletions src/editor/MessageToggle.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<script setup lang="ts">
withDefaults(
defineProps<{
modelValue?: boolean
}>(),
{
modelValue: false,
}
)
defineEmits<{
(e: 'update:modelValue', value: boolean): void
}>()
</script>
<template>
<div class="wrapper" @click="$emit('update:modelValue', !modelValue)">
<span>Show Error</span>
<div class="toggle" :class="[{ active: modelValue }]">
<div class="indicator" />
</div>
</div>
</template>
<style scoped>
.wrapper {
position: absolute;
bottom: 8px;
right: 12px;
z-index: 11;
display: flex;
align-items: center;
background-color: var(--bg);
color: var(--text-light);
cursor: pointer;
padding: 4px 8px;
border-radius: 2px;
user-select: none;
}
.toggle {
display: inline-block;
margin-left: 4px;
width: 32px;
height: 18px;
border-radius: 12px;
position: relative;
background-color: var(--border);
}
.indicator {
font-size: 12px;
background-color: var(--text-light);
width: 14px;
height: 14px;
border-radius: 50%;
transition: transform ease-in-out 0.2s;
position: absolute;
left: 2px;
top: 2px;
color: var(--bg);
text-align: center;
}
.active .indicator {
background-color: var(--color-branding);
transform: translateX(14px);
color: white;
}
</style>

0 comments on commit 51819cc

Please sign in to comment.