Skip to content

Commit 024dfa5

Browse files
feat(snippets): create screenshot of snippets (#115)
1 parent c6c4675 commit 024dfa5

File tree

15 files changed

+528
-18
lines changed

15 files changed

+528
-18
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"electron-store": "^8.0.1",
4646
"fs-extra": "^10.0.1",
4747
"highlight.js": "^11.5.1",
48+
"html2canvas": "^1.4.1",
4849
"interactjs": "^1.10.11",
4950
"lodash": "^4.17.21",
5051
"lowdb": "^3.0.0",

pnpm-lock.yaml

Lines changed: 45 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/store/module/preferences.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ export default new Store<PreferencesStore>({
2727
theme: 'chrome',
2828
highlightLine: false,
2929
highlightGutter: false
30+
},
31+
screenshot: {
32+
background: false,
33+
gradient: ['#D02F98', '#9439CA'],
34+
darkMode: true,
35+
width: 600
3036
}
3137
}
3238
})

src/renderer/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const init = () => {
5757
5858
appStore.sizes.sidebar = store.app.get('sidebarWidth')
5959
appStore.sizes.snippetList = store.app.get('snippetListWidth')
60+
appStore.screenshot = store.preferences.get('screenshot')
6061
6162
snippetStore.sort = store.app.get('sort')
6263
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<template>
2+
<div class="screenshot-palette">
3+
<div
4+
v-for="(i, index) in palette"
5+
:key="index"
6+
class="item"
7+
:class="{ 'is-selected': index === selected }"
8+
:style="{ backgroundImage: `linear-gradient(45deg, ${i[0]}, ${i[1]})` }"
9+
@click="onSelect(i)"
10+
/>
11+
</div>
12+
</template>
13+
14+
<script setup lang="ts">
15+
import { useAppStore } from '@/store/app'
16+
import { computed } from 'vue'
17+
18+
interface Props {
19+
modelValue: [string, string]
20+
}
21+
22+
interface Emits {
23+
(e: 'update:modelValue', value: [string, string]): void
24+
}
25+
26+
const emit = defineEmits<Emits>()
27+
28+
const props = defineProps<Props>()
29+
30+
const appStore = useAppStore()
31+
32+
const palette: [string, string][] = [
33+
['#D02F98', '#9439CA'],
34+
['#A58EFB', '#CEABF9'],
35+
['#FFE623', '#FFE623'],
36+
['#4169E1', '#4169E1'],
37+
['#FC3CAD', '#FC3CAD'],
38+
['#8E00A7', '#8E00A7']
39+
]
40+
41+
const selected = computed(() =>
42+
palette.findIndex(i => i.every((c, idx) => c === props.modelValue[idx]))
43+
)
44+
45+
const onSelect = (value: [string, string]) => {
46+
emit('update:modelValue', value)
47+
}
48+
49+
const itemBorderColor = computed(() =>
50+
appStore.isLightTheme ? '#fff' : 'var(--color-contrast-high'
51+
)
52+
</script>
53+
54+
<style lang="scss" scoped>
55+
.screenshot-palette {
56+
display: flex;
57+
gap: var(--spacing-xs);
58+
.item {
59+
padding: 2px;
60+
border: 2px solid v-bind(itemBorderColor);
61+
width: 18px;
62+
height: 18px;
63+
border-radius: 4px;
64+
outline: 1px solid var(--color-border);
65+
&.is-selected {
66+
outline-color: var(--color-primary);
67+
}
68+
}
69+
}
70+
</style>

0 commit comments

Comments
 (0)