Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81165 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule ReactDOMButton
10
*/
11
12
"use strict";
13
14
var AutoFocusMixin = require('AutoFocusMixin');
15
var ReactBrowserComponentMixin = require('ReactBrowserComponentMixin');
16
var ReactCompositeComponent = require('ReactCompositeComponent');
17
var ReactElement = require('ReactElement');
18
var ReactDOM = require('ReactDOM');
19
20
var keyMirror = require('keyMirror');
21
22
// Store a reference to the <button> `ReactDOMComponent`. TODO: use string
23
var button = ReactElement.createFactory(ReactDOM.button.type);
24
25
var mouseListenerNames = keyMirror({
26
onClick: true,
27
onDoubleClick: true,
28
onMouseDown: true,
29
onMouseMove: true,
30
onMouseUp: true,
31
onClickCapture: true,
32
onDoubleClickCapture: true,
33
onMouseDownCapture: true,
34
onMouseMoveCapture: true,
35
onMouseUpCapture: true
36
});
37
38
/**
39
* Implements a <button> native component that does not receive mouse events
40
* when `disabled` is set.
41
*/
42
var ReactDOMButton = ReactCompositeComponent.createClass({
43
displayName: 'ReactDOMButton',
44
45
mixins: [AutoFocusMixin, ReactBrowserComponentMixin],
46
47
render: function() {
48
var props = {};
49
50
// Copy the props; except the mouse listeners if we're disabled
51
for (var key in this.props) {
52
if (this.props.hasOwnProperty(key) &&
53
(!this.props.disabled || !mouseListenerNames[key])) {
54
props[key] = this.props[key];
55
}
56
}
57
58
return button(props, this.props.children);
59
}
60
61
});
62
63
module.exports = ReactDOMButton;
64
65