-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathurl.js
More file actions
35 lines (31 loc) · 1.12 KB
/
url.js
File metadata and controls
35 lines (31 loc) · 1.12 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
35
var createClassName = require('./utils/classname')
var extend = require('xtend')
var addhttp = require('addhttp')
var defaultProps = {
tagName: 'input',
editable: true,
size: 'normal',
attributes: {}
}
/**
* Create a virtual-dom url data-field for use with [data-ui](https://github.com/editdata/data-ui).
* @param {Object} options an options object, including any properties you can pass to virtual-dom/h
* @param {Boolean} options.display true for display mode, default is false for input mode
* @returns field
* @name createURLField
* @example
* var createURLField = require('data-field-url')
* var field = createURLField()
* var vtree = field.render(h, {}, 'http://example.com')
*/
module.exports = function URLField (h, options, value) {
options = extend(defaultProps, options)
options.value = value || options.value
options.dataType = 'url'
options.href = options.value ? addhttp(options.href || options.value) : null
options.value = options.href
options.className = createClassName(options)
delete options.size
if (!options.editable) options.tagName = 'a'
return h(options.tagName, options, options.href)
}