-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresponsive-contentful-visual.vue
43 lines (34 loc) · 1.23 KB
/
responsive-contentful-visual.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!-- Conditionally render landscape or portrait visual instances -->
<script lang='coffee'>
import responsiveVisualMixin from '../mixins/visual/responsive-visual'
import ContentfulVisual, { makeSrcset } from './contentful-visual'
import { ucFirst } from '../services/helpers'
export default
name: 'ResponsiveContentfulVisual'
mixins: [ responsiveVisualMixin ]
methods:
# Get the specified asset
# mediaType: image|video
# viewportType: portrait|landscape
getAsset: (mediaType, viewportType) ->
@[viewportType + ucFirst(mediaType)]
# Passthru the logic that makes a srceset from the passed in prop
makeSrcset: makeSrcset
# Make the appropriate visual instance
render: (create) ->
# Create visual for the current viewport width
if @landscape || @portrait
unless @isResponsive
then create ContentfulVisual, @landscape || @portrait, @$slots.default
else create ContentfulVisual, {
...@responsiveConfig
scopedSlots: ['image-source']: =>
@responsiveSources.map (data) -> create 'source', data
}, @$slots.default
# No assets were discovered, so explicitly clear the asset props
else create ContentfulVisual, { props: {
...@$props
image: undefined
video: undefined
}}, @$slots.default
</script>