Created
July 27, 2018 22:33
-
-
Save nabrown/1dcd5cca2abc0c20a65b1f5872cd91e4 to your computer and use it in GitHub Desktop.
A functional component using a render function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
functional: true, | |
props: { | |
src: { | |
required: true, | |
type: String | |
}, | |
type: { | |
required: true, | |
type: String | |
}, | |
tags: { | |
required: false, | |
type: Array | |
} | |
}, | |
render(createElement, {props, listeners, slots}){ | |
const img = createElement( | |
'img', | |
{ | |
'attrs': { | |
'src': props.src | |
} | |
} | |
) | |
const caption = slots().default ? createElement( | |
'figcaption', | |
[ createElement('span', slots().default) ] | |
) : '' | |
const tags = props.tags && (props.type != 'framed') ? createElement( | |
'div', | |
{'class' : 'tags'}, | |
props.tags.map(function (tag) { | |
return createElement('span', tag) | |
}) | |
) : '' | |
return createElement( | |
'figure', | |
{ | |
'class': props.type, | |
'on' : { | |
'click': listeners.click | |
} | |
}, | |
[img, caption, tags] | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment