-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimage.js
More file actions
34 lines (30 loc) · 1.04 KB
/
image.js
File metadata and controls
34 lines (30 loc) · 1.04 KB
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
var addhttp = require('addhttp')
var extend = require('xtend')
var createClassName = require('./utils/classname')
var defaultProps = {
tagName: 'input',
editable: true,
size: 'normal',
attributes: {}
}
/**
* Render a virtual-dom image data-field.
* @param {function} h virtual-dom `h` function
* @param {Object} options options object for `h`
* @param {Boolean} options.display false for static mode, default is true for editable mode
* @param {String} options.value any image url
* @returns virtual-dom tree
* @name createImageField
* @example
* var createImageField = require('data-field-image')
* var field = createImageField(h, { value: 'http://example.com/example.jpg' })
*/
module.exports = function createImageField (h, options, value) {
options = extend(defaultProps, options)
options.dataType = 'image'
options.src = addhttp(value || options.src || options.value)
options.className = createClassName(options)
delete options.size
if (!options.editable) options.tagName = 'img'
return h(options.tagName, options, options.src)
}