diff --git a/src/hooks/useSlideBackgroundStyle.ts b/src/hooks/useSlideBackgroundStyle.ts new file mode 100644 index 00000000..758ace17 --- /dev/null +++ b/src/hooks/useSlideBackgroundStyle.ts @@ -0,0 +1,17 @@ +import { Ref, computed } from 'vue' + +export default (background: Ref<[string, string] | undefined>) => { + const backgroundStyle = computed(() => { + if(!background.value) return { backgroundColor: '#fff' } + + const [type, value] = background.value + if(type === 'solid') return { backgroundColor: value } + else if(type === 'image') return { backgroundImage: `url(${value}` } + + return { backgroundColor: '#fff' } + }) + + return { + backgroundStyle, + } +} \ No newline at end of file diff --git a/src/views/Editor/Canvas/SlideBackground.vue b/src/views/Editor/Canvas/SlideBackground.vue index c29b25fb..1234c6e3 100644 --- a/src/views/Editor/Canvas/SlideBackground.vue +++ b/src/views/Editor/Canvas/SlideBackground.vue @@ -14,8 +14,8 @@ import { Ref, computed, defineComponent } from 'vue' import { useStore } from 'vuex' import { State } from '@/store' -import { Slide } from '@/types/slides' import GridLines from './GridLines.vue' +import useSlideBackgroundStyle from '@/hooks/useSlideBackgroundStyle' export default defineComponent({ name: 'slide-background', @@ -25,17 +25,9 @@ export default defineComponent({ setup() { const store = useStore() const showGridLines = computed(() => store.state.showGridLines) - const currentSlide: Ref = computed(() => store.getters.currentSlide) + const background: Ref<[string, string] | undefined> = computed(() => store.getters.currentSlide.background) - const backgroundStyle = computed(() => { - if(!currentSlide.value.background) return { backgroundColor: '#fff' } - - const [type, value] = currentSlide.value.background - if(type === 'solid') return { backgroundColor: value } - else if(type === 'image') return { backgroundImage: `url(${value}` } - - return { backgroundColor: '#fff' } - }) + const { backgroundStyle } = useSlideBackgroundStyle(background) return { showGridLines, diff --git a/src/views/Editor/Thumbnails/index.vue b/src/views/Editor/Thumbnails/index.vue index 269c77aa..e6116b65 100644 --- a/src/views/Editor/Thumbnails/index.vue +++ b/src/views/Editor/Thumbnails/index.vue @@ -16,7 +16,7 @@ @end="handleDragEnd" itemKey="id" > -