useSlideBackgroundStyle.ts 857 B

1234567891011121314151617181920212223242526272829303132
  1. import { Ref, computed } from 'vue'
  2. import { SlideBackground } from '@/types/slides'
  3. export default (background: Ref<SlideBackground | undefined>) => {
  4. const backgroundStyle = computed(() => {
  5. if(!background.value) return { backgroundColor: '#fff' }
  6. const { type, value, size } = background.value
  7. if(type === 'solid') return { backgroundColor: value }
  8. else if(type === 'image') {
  9. if(!value) return { backgroundColor: '#fff' }
  10. if(size === 'repeat') {
  11. return {
  12. backgroundImage: `url(${value}`,
  13. backgroundRepeat: 'repeat',
  14. backgroundSize: 'initial',
  15. }
  16. }
  17. return {
  18. backgroundImage: `url(${value}`,
  19. backgroundRepeat: 'no-repeat',
  20. backgroundSize: size,
  21. }
  22. }
  23. return { backgroundColor: '#fff' }
  24. })
  25. return {
  26. backgroundStyle,
  27. }
  28. }