mirror of
https://github.com/heyman/heynote.git
synced 2025-01-22 22:08:35 +01:00
Add ability to toggle dark/light theme
This commit is contained in:
parent
fc59c84764
commit
7595d3fc86
@ -47,6 +47,7 @@
|
|||||||
:language="language"
|
:language="language"
|
||||||
:languageAuto="languageAuto"
|
:languageAuto="languageAuto"
|
||||||
:theme="theme"
|
:theme="theme"
|
||||||
|
@toggleTheme="theme = theme === 'dark' ? 'light' : 'dark'"
|
||||||
class="status"
|
class="status"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
@ -17,13 +17,19 @@
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const editor = new HeynoteEditor({
|
this.editor = new HeynoteEditor({
|
||||||
element: this.$refs.editor,
|
element: this.$refs.editor,
|
||||||
//content: "\n∞∞∞text\n",
|
//content: "\n∞∞∞text\n",
|
||||||
content: initialData,
|
content: initialData,
|
||||||
theme: this.theme,
|
theme: this.theme,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
theme(newTheme) {
|
||||||
|
this.editor.setTheme(newTheme)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -44,7 +44,8 @@
|
|||||||
Col <span class="num">{{ column }}</span>
|
Col <span class="num">{{ column }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="spacer"></div>
|
<div class="spacer"></div>
|
||||||
<div class="status-block lang">
|
<div class="status-block theme clickable" @click="$emit('toggleTheme')">{{ theme }}</div>
|
||||||
|
<div class="status-block lang clickable">
|
||||||
{{ languageName }}
|
{{ languageName }}
|
||||||
<span v-if="languageAuto" class="auto">(auto)</span>
|
<span v-if="languageAuto" class="auto">(auto)</span>
|
||||||
</div>
|
</div>
|
||||||
@ -82,15 +83,16 @@
|
|||||||
.status-block
|
.status-block
|
||||||
padding: 2px 12px
|
padding: 2px 12px
|
||||||
cursor: default
|
cursor: default
|
||||||
|
&.clickable
|
||||||
|
cursor: pointer
|
||||||
|
&:hover
|
||||||
|
background: rgba(255,255,255, 0.1)
|
||||||
&.line-number
|
&.line-number
|
||||||
color: rgba(255, 255, 255, 0.7)
|
color: rgba(255, 255, 255, 0.7)
|
||||||
.num
|
.num
|
||||||
color: rgba(255, 255, 255, 1.0)
|
color: rgba(255, 255, 255, 1.0)
|
||||||
&.lang
|
&.lang
|
||||||
cursor: pointer
|
|
||||||
.auto
|
.auto
|
||||||
color: rgba(255, 255, 255, 0.7)
|
color: rgba(255, 255, 255, 0.7)
|
||||||
&:hover
|
|
||||||
background: rgba(255,255,255, 0.1)
|
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
@ -14,16 +14,17 @@ import { languageDetection } from "./language-detection/autodetect.js"
|
|||||||
|
|
||||||
export class HeynoteEditor {
|
export class HeynoteEditor {
|
||||||
constructor({element, content, focus=true, theme="light"}) {
|
constructor({element, content, focus=true, theme="light"}) {
|
||||||
|
this.theme = new Compartment
|
||||||
|
|
||||||
this.state = EditorState.create({
|
this.state = EditorState.create({
|
||||||
doc: content || "",
|
doc: content || "",
|
||||||
extensions: [
|
extensions: [
|
||||||
heynoteKeymap,
|
heynoteKeymap,
|
||||||
|
|
||||||
//minimalSetup,
|
//minimalSetup,
|
||||||
|
|
||||||
customSetup,
|
customSetup,
|
||||||
|
|
||||||
theme === "dark" ? heynoteDark : heynoteLight,
|
this.theme.of("dark" ? heynoteDark : heynoteLight),
|
||||||
heynoteBase,
|
heynoteBase,
|
||||||
indentUnit.of(" "),
|
indentUnit.of(" "),
|
||||||
EditorView.scrollMargins.of(f => {
|
EditorView.scrollMargins.of(f => {
|
||||||
@ -56,6 +57,12 @@ export class HeynoteEditor {
|
|||||||
this.view.focus()
|
this.view.focus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTheme(theme) {
|
||||||
|
this.view.dispatch({
|
||||||
|
effects: this.theme.reconfigure(theme === "dark" ? heynoteDark : heynoteLight),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user