-
Notifications
You must be signed in to change notification settings - Fork 13
/
input.js
122 lines (111 loc) · 3.94 KB
/
input.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var reactPolymer = require('./')
var React = require('react')
var ReactUpdates = require('react-dom/lib/ReactUpdates')
var PropTypes = require('prop-types')
var assign = require('object-assign')
reactPolymer.registerEvent('change', 'onChange')
reactPolymer.registerEvent('immediate-value-change', 'onImmediateValueChange')
reactPolymer.registerEvent('iron-select', 'onIronSelect')
function createToggleClass (PolymerToggle, displayName) {
function Toggle () {
const c = new React.Component()
function onChange (event) {
if (c.props.onChange) c.props.onChange.call(undefined, event)
if (c.props.checked != null) event.target.checked = c.props.checked
}
const props = {onChange}
c.render = () => React.createElement(PolymerToggle, assign({}, c.props, props))
return c
}
Toggle.displayName = displayName
Toggle.propTypes = {
onChange: PropTypes.func,
checked: PropTypes.bool
}
return Toggle
}
exports.PaperCheckbox = createToggleClass('paper-checkbox', 'PaperCheckbox')
exports.PaperToggleButton = createToggleClass('paper-toggle-button', 'PaperToggleButton')
function createTextClass (PolymerText, displayName) {
function Text () {
const c = new React.Component()
function onChange (event) {
if (c.props.onChange) c.props.onChange.call(undefined, event)
var target = event.currentTarget
ReactUpdates.asap(() => {
if (c.props.value == null) return
if (PolymerText === 'iron-autogrow-textarea') {
target.bindValue = c.props.value
} else {
target.value = c.props.value
}
})
}
var props = {
onChange: null,
onInput: onChange
}
c.render = () => {
if (PolymerText === 'iron-autogrow-textarea') {
props.value = null
props['bind-value'] = c.props.value
}
return React.createElement(PolymerText, assign({}, c.props, props))
}
return c
}
Text.displayName = displayName
Text.propTypes = {
onChange: PropTypes.func,
value: PropTypes.string
}
return Text
}
exports.IronAutogrowTextarea = createTextClass('iron-autogrow-textarea', 'IronAutogrowTextarea')
exports.PaperInput = createTextClass('paper-input', 'PaperInput')
exports.PaperTextarea = createTextClass('paper-textarea', 'PaperTextarea')
function PaperSlider () {
const c = new React.Component()
function onChange (event) {
var target = event.target
target.value = target.immediateValue
if (c.props.onChange) c.props.onChange.call(undefined, event)
ReactUpdates.asap(() => {
if (c.props.value != null) target.value = c.props.value
})
}
const props = {onChange, onImmediateValueChange: onChange}
c.render = () => React.createElement('paper-slider', assign({}, c.props, props))
return c
}
PaperSlider.displayName = 'PaperSlider'
PaperSlider.propTypes = {
onChange: PropTypes.func,
value: PropTypes.number
}
exports.PaperSlider = PaperSlider
function createSelectorClass (PolymerSelector, displayName) {
function Selector () {
const c = new React.Component()
function onChange (event) {
var target = event.target
if (c.props.onChange && c.props.selected !== target.selected) c.props.onChange.call(undefined, event)
ReactUpdates.asap(() => {
if (c.props.selected != null) target.selected = c.props.selected
})
}
const props = {onChange: null, onIronSelect: onChange}
c.render = () => React.createElement(PolymerSelector, assign({}, c.props, props))
return c
}
Selector.displayName = displayName
Selector.propTypes = {
onChange: PropTypes.func,
selected: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
}
return Selector
}
exports.PaperListbox = createSelectorClass('paper-listbox', 'PaperListbox')
exports.PaperRadioGroup = createSelectorClass('paper-radio-group', 'PaperRadioGroup')
exports.PaperTabs = createSelectorClass('paper-tabs', 'PaperTabs')
exports.IronSelector = createSelectorClass('iron-selector', 'IronSelector')