-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlightable.js
59 lines (52 loc) · 2.27 KB
/
highlightable.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
'use strict';
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var Highlightable = _react2['default'].createClass({
displayName: 'Highlightable',
PropTypes: {
highlightOnMount: _react2['default'].PropTypes.bool,
background: _react2['default'].PropTypes.string,
padding: _react2['default'].PropTypes.number,
color: _react2['default'].PropTypes.string,
borderRadius: _react2['default'].PropTypes.number,
transition: _react2['default'].PropTypes.string,
highlightDelay: _react2['default'].PropTypes.number
},
getDefaultProps: function getDefaultProps() {
return {
highlightOnMount: false,
background: '#ae2240',
padding: 2,
color: '#f2f2f2',
borderRadius: 2,
transition: 'all .3s ease',
highlightDelay: 300
};
},
componentWillUpdate: function componentWillUpdate(nextProps, nextState) {
if (this.props.highlightOnMount == false && !this.props.children) return;
var highlightedStyle = 'padding: ' + this.props.padding + 'px; transition: ' + this.props.transition + '; background: ' + this.props.background + '; color: ' + this.props.color + '; border-radius: ' + this.props.borderRadius + 'px';
this.refs.highlightable.getDOMNode().setAttribute('style', highlightedStyle);
},
componentDidUpdate: function componentDidUpdate(prevProps, prevState) {
var _this = this;
if (prevProps.highlightOnMount == false && !prevProps.children) return;
var style = 'padding: ' + this.props.padding + 'px; transition: ' + this.props.transition;
setTimeout(function () {
return _this.refs.highlightable.getDOMNode().setAttribute('style', style);
}, this.props.highlightDelay);
},
render: function render() {
var mountStyle = {
padding: this.props.padding,
transition: this.props.transition
};
return _react2['default'].createElement(
'span',
{ ref: 'highlightable', style: mountStyle },
this.props.children
);
}
});
module.exports = Highlightable;