Skip to content

Commit 8c951b3

Browse files
author
Jimmy Jia
committed
0.17.0
1 parent 415edfe commit 8c951b3

9 files changed

+63
-293
lines changed

lib/ButtonLink.js

+1-22
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
88

99
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1010

11-
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
12-
1311
var _react = require('react');
1412

1513
var _react2 = _interopRequireDefault(_react);
@@ -26,30 +24,11 @@ var ButtonLink = _react2['default'].createClass({
2624
displayName: 'ButtonLink',
2725

2826
mixins: [_LinkMixin2['default']],
29-
contextTypes: {
30-
router: _react2['default'].PropTypes.func.isRequired
31-
},
3227

3328
render: function render() {
34-
var _props = this.props;
35-
var to = _props.to;
36-
var params = _props.params;
37-
var query = _props.query;
38-
var active = _props.active;
39-
40-
var props = _objectWithoutProperties(_props, ['to', 'params', 'query', 'active']);
41-
42-
if (this.props.active === undefined) {
43-
active = this.context.router.isActive(to, params, query);
44-
}
45-
4629
return _react2['default'].createElement(
4730
_reactBootstrapLibButton2['default'],
48-
_extends({}, props, {
49-
href: this.getHref(),
50-
active: active,
51-
onClick: this.handleRouteTo,
52-
ref: 'button' }),
31+
_extends({}, this.getLinkProps(), { ref: 'button' }),
5332
this.props.children
5433
);
5534
}

lib/LinkMixin.js

+19-20
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ Object.defineProperty(exports, '__esModule', {
66

77
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
88

9+
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
10+
911
var _react = require('react');
1012

1113
var _react2 = _interopRequireDefault(_react);
1214

13-
var _classnames = require('classnames');
14-
15-
var _classnames2 = _interopRequireDefault(_classnames);
16-
1715
function isLeftClickEvent(event) {
1816
return event.button === 0;
1917
}
@@ -24,6 +22,7 @@ function isModifiedEvent(event) {
2422

2523
exports['default'] = {
2624
propTypes: {
25+
active: _react2['default'].PropTypes.bool,
2726
activeClassName: _react2['default'].PropTypes.string.isRequired,
2827
disabled: _react2['default'].PropTypes.bool,
2928
to: _react2['default'].PropTypes.string.isRequired,
@@ -42,28 +41,28 @@ exports['default'] = {
4241
},
4342

4443
/**
45-
* Returns the value of the "href" attribute to use on the DOM element.
44+
* Returns props except those used by this Mixin
45+
* Gets "active" from router if needed.
46+
* Gets the value of the "href" attribute to use on the DOM element.
47+
* Sets "onClick" to "handleRouteTo".
4648
*/
47-
getHref: function getHref() {
48-
return this.context.router.makeHref(this.props.to, this.props.params, this.props.query);
49-
},
49+
getLinkProps: function getLinkProps() {
50+
var _props = this.props;
51+
var to = _props.to;
52+
var params = _props.params;
53+
var query = _props.query;
5054

51-
/**
52-
* Returns the value of the "class" attribute to use on the DOM element, which contains
53-
* the value of the activeClassName property when this <Link> is active.
54-
*/
55-
getClassName: function getClassName() {
56-
var classSet = {};
55+
var props = _objectWithoutProperties(_props, ['to', 'params', 'query']);
5756

58-
if (this.props.className) {
59-
classSet[this.props.className] = true;
57+
if (this.props.active === undefined) {
58+
props.active = this.context.router.isActive(to, params, query);
6059
}
6160

62-
if (this.context.router.isActive(this.props.to, this.props.params, this.props.query)) {
63-
_classnames2['default'][this.props.activeClassName] = true;
64-
}
61+
props.href = this.context.router.makeHref(to, params, query);
62+
63+
props.onClick = this.handleRouteTo;
6564

66-
return (0, _classnames2['default'])(classSet);
65+
return props;
6766
},
6867

6968
handleRouteTo: function handleRouteTo(event) {

lib/ListGroupItemLink.js

+1-22
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
88

99
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1010

11-
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
12-
1311
var _react = require('react');
1412

1513
var _react2 = _interopRequireDefault(_react);
@@ -26,30 +24,11 @@ var LinkGroupItemLink = _react2['default'].createClass({
2624
displayName: 'LinkGroupItemLink',
2725

2826
mixins: [_LinkMixin2['default']],
29-
contextTypes: {
30-
router: _react2['default'].PropTypes.func.isRequired
31-
},
3227

3328
render: function render() {
34-
var _props = this.props;
35-
var to = _props.to;
36-
var params = _props.params;
37-
var query = _props.query;
38-
var active = _props.active;
39-
40-
var props = _objectWithoutProperties(_props, ['to', 'params', 'query', 'active']);
41-
42-
if (this.props.active === undefined) {
43-
active = this.context.router.isActive(to, params, query);
44-
}
45-
4629
return _react2['default'].createElement(
4730
_reactBootstrapLibListGroupItem2['default'],
48-
_extends({}, props, {
49-
href: this.getHref(),
50-
active: active,
51-
onClick: this.handleRouteTo,
52-
ref: 'listGroupItem' }),
31+
_extends({}, this.getLinkProps(), { ref: 'listGroupItem' }),
5332
this.props.children
5433
);
5534
}

lib/MenuItemLink.js

+4-25
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
88

99
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1010

11-
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
12-
1311
var _react = require('react');
1412

1513
var _react2 = _interopRequireDefault(_react);
@@ -26,37 +24,18 @@ var MenuItemLink = _react2['default'].createClass({
2624
displayName: 'MenuItemLink',
2725

2826
mixins: [_LinkMixin2['default']],
29-
contextTypes: {
30-
router: _react2['default'].PropTypes.func.isRequired
31-
},
3227

3328
render: function render() {
34-
var _props = this.props;
35-
var to = _props.to;
36-
var params = _props.params;
37-
var query = _props.query;
38-
var active = _props.active;
39-
var onSelect = _props.onSelect;
40-
41-
var props = _objectWithoutProperties(_props, ['to', 'params', 'query', 'active', 'onSelect']);
42-
43-
if (active === undefined) {
44-
active = this.context.router.isActive(to, params, query);
45-
}
29+
var props = this.getLinkProps();
30+
delete props.onSelect; // this is done on the copy of this.props
4631

4732
return _react2['default'].createElement(
4833
_reactBootstrapLibMenuItem2['default'],
49-
_extends({}, props, {
50-
href: this.getHref(),
51-
active: active,
52-
onClick: this.handleRouteTo,
53-
ref: 'menuItem'
54-
}),
34+
_extends({}, props, { ref: 'menuItem' }),
5535
this.props.children
5636
);
5737
}
5838
});
5939

6040
exports['default'] = MenuItemLink;
61-
module.exports = exports['default'];
62-
// eslint-disable-line no-unused-vars
41+
module.exports = exports['default'];

lib/NavItemLink.js

+1-22
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
88

99
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1010

11-
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
12-
1311
var _react = require('react');
1412

1513
var _react2 = _interopRequireDefault(_react);
@@ -26,30 +24,11 @@ var NavItemLink = _react2['default'].createClass({
2624
displayName: 'NavItemLink',
2725

2826
mixins: [_LinkMixin2['default']],
29-
contextTypes: {
30-
router: _react2['default'].PropTypes.func.isRequired
31-
},
3227

3328
render: function render() {
34-
var _props = this.props;
35-
var to = _props.to;
36-
var params = _props.params;
37-
var query = _props.query;
38-
var active = _props.active;
39-
40-
var props = _objectWithoutProperties(_props, ['to', 'params', 'query', 'active']);
41-
42-
if (this.props.active === undefined) {
43-
active = this.context.router.isActive(to, params, query);
44-
}
45-
4629
return _react2['default'].createElement(
4730
_reactBootstrapLibNavItem2['default'],
48-
_extends({}, props, {
49-
href: this.getHref(),
50-
active: active,
51-
onClick: this.handleRouteTo,
52-
ref: 'navItem' }),
31+
_extends({}, this.getLinkProps(), { ref: 'navItem' }),
5332
this.props.children
5433
);
5534
}

0 commit comments

Comments
 (0)