-
Notifications
You must be signed in to change notification settings - Fork 90
/
getComponent.js
78 lines (67 loc) · 2.36 KB
/
getComponent.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
var createReactClass = require('create-react-class');
var PropTypes = require('prop-types');
var React = require('react');
var touchStyles = require('./touchStyles');
/**
* Tappable Component
* ==================
*/
module.exports = function (mixins) {
return createReactClass({
displayName: 'Tappable',
mixins: mixins,
propTypes: {
component: PropTypes.any, // component to create
className: PropTypes.string, // optional className
classBase: PropTypes.string, // base for generated classNames
classes: PropTypes.object, // object containing the active and inactive class names
style: PropTypes.object, // additional style properties for the component
disabled: PropTypes.bool // only applies to buttons
},
getDefaultProps: function () {
return {
component: 'span',
classBase: 'Tappable'
};
},
render: function () {
var props = this.props;
var className = props.classBase + (this.state.isActive ? '-active' : '-inactive');
if (props.className) {
className += ' ' + props.className;
}
if (props.classes) {
className += ' ' + (this.state.isActive ? props.classes.active : props.classes.inactive);
}
var style = {};
Object.assign(style, touchStyles, props.style);
var newComponentProps = Object.assign({}, props, {
style: style,
className: className,
disabled: props.disabled,
handlers: this.handlers
}, this.handlers());
delete newComponentProps.activeDelay;
delete newComponentProps.allowReactivation;
delete newComponentProps.classBase;
delete newComponentProps.classes;
delete newComponentProps.handlers;
delete newComponentProps.onTap;
delete newComponentProps.onPress;
delete newComponentProps.onPinchStart;
delete newComponentProps.onPinchMove;
delete newComponentProps.onPinchEnd;
delete newComponentProps.onDeactivate;
delete newComponentProps.onReactivate;
delete newComponentProps.moveThreshold;
delete newComponentProps.moveXThreshold;
delete newComponentProps.moveYThreshold;
delete newComponentProps.pressDelay;
delete newComponentProps.pressMoveThreshold;
delete newComponentProps.preventDefault;
delete newComponentProps.stopPropagation;
delete newComponentProps.component;
return React.createElement(props.component, newComponentProps, props.children);
}
});
};