From feb8b69d2a2062a0aa2402f2d969003d287e6359 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Thu, 26 Mar 2015 13:23:10 -0400 Subject: [PATCH] add classnames to replace deprecated usage of classSet --- lib/LinkMixin.js | 2 +- lib/MenuItemLink.js | 24 ++-- lib/ReactRouterBootstrap.js | 247 ++++---------------------------- lib/ReactRouterBootstrap.min.js | 2 +- package.json | 4 +- src/LinkMixin.js | 2 +- src/MenuItemLink.js | 2 +- 7 files changed, 47 insertions(+), 236 deletions(-) diff --git a/lib/LinkMixin.js b/lib/LinkMixin.js index 3f6087e..75c765d 100644 --- a/lib/LinkMixin.js +++ b/lib/LinkMixin.js @@ -1,5 +1,5 @@ var React = require('react'); -var classSet = require('react/lib/cx'); +var classSet = require('classnames'); function isLeftClickEvent(event) { return event.button === 0; diff --git a/lib/MenuItemLink.js b/lib/MenuItemLink.js index 9efa51a..d919487 100644 --- a/lib/MenuItemLink.js +++ b/lib/MenuItemLink.js @@ -1,5 +1,5 @@ var React = require('react'); -var classSet = require('react/lib/cx'); +var classSet = require('classnames'); var MenuItem = require('react-bootstrap/lib/MenuItem'); var LinkMixin = require('./LinkMixin'); @@ -16,12 +16,12 @@ var MenuItemLink = React.createClass({displayName: "MenuItemLink", render: function() { var $__0= - - - - - - + + + + + + this.props,to=$__0.to,params=$__0.params,query=$__0.query,active=$__0.active,className=$__0.className,onSelect=$__0.onSelect,props=(function(source, exclusion) {var rest = {};var hasOwn = Object.prototype.hasOwnProperty;if (source == null) {throw new TypeError();}for (var key in source) {if (hasOwn.call(source, key) && !hasOwn.call(exclusion, key)) {rest[key] = source[key];}}return rest;})($__0,{to:1,params:1,query:1,active:1,className:1,onSelect:1}); if (this.props.active === undefined) { @@ -29,11 +29,11 @@ var MenuItemLink = React.createClass({displayName: "MenuItemLink", } return ( - React.createElement(MenuItem, React.__spread({}, props, - {href: this.getHref(), - className: joinClasses(className, classSet({ active: active })), - onClick: this.handleRouteTo, - ref: "menuItem"}), + React.createElement(MenuItem, React.__spread({}, props, + {href: this.getHref(), + className: joinClasses(className, classSet({ active: active })), + onClick: this.handleRouteTo, + ref: "menuItem"}), this.props.children ) ); diff --git a/lib/ReactRouterBootstrap.js b/lib/ReactRouterBootstrap.js index dd80f1c..251b4ee 100644 --- a/lib/ReactRouterBootstrap.js +++ b/lib/ReactRouterBootstrap.js @@ -314,60 +314,37 @@ return /******/ (function(modules) { // webpackBootstrap /* 9 */ /***/ function(module, exports, __webpack_require__) { - /* WEBPACK VAR INJECTION */(function(process) {/** - * Copyright 2013-2015, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule cx - */ - - /** - * This function is used to mark string literals representing CSS class names - * so that they can be transformed statically. This allows for modularization - * and minification of CSS class names. - * - * In static_upstream, this function is actually implemented, but it should - * eventually be replaced with something more descriptive, and the transform - * that is used in the main stack should be ported for use elsewhere. - * - * @param string|object className to modularize, or an object of key/values. - * In the object case, the values are conditions that - * determine if the className keys should be included. - * @param [string ...] Variable list of classNames in the string case. - * @return string Renderable space-separated CSS className. - */ - - 'use strict'; - var warning = __webpack_require__(11); - - var warned = false; - - function cx(classNames) { - if ("production" !== process.env.NODE_ENV) { - ("production" !== process.env.NODE_ENV ? warning( - warned, - 'React.addons.classSet will be deprecated in a future version. See ' + - 'http://fb.me/react-addons-classset' - ) : null); - warned = true; - } - - if (typeof classNames == 'object') { - return Object.keys(classNames).filter(function(className) { - return classNames[className]; - }).join(' '); - } else { - return Array.prototype.join.call(arguments, ' '); - } + function classNames() { + var classes = ''; + var arg; + + for (var i = 0; i < arguments.length; i++) { + arg = arguments[i]; + if (!arg) { + continue; + } + + if ('string' === typeof arg || 'number' === typeof arg) { + classes += ' ' + arg; + } else if (Object.prototype.toString.call(arg) === '[object Array]') { + classes += ' ' + classNames.apply(null, arg); + } else if ('object' === typeof arg) { + for (var key in arg) { + if (!arg.hasOwnProperty(key) || !arg[key]) { + continue; + } + classes += ' ' + key; + } + } + } + return classes.substr(1); } - module.exports = cx; + // safely export classNames in case the script is included directly on a page + if (typeof module !== 'undefined' && module.exports) { + module.exports = classNames; + } - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(12))) /***/ }, /* 10 */ @@ -414,174 +391,6 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = joinClasses; -/***/ }, -/* 11 */ -/***/ function(module, exports, __webpack_require__) { - - /* WEBPACK VAR INJECTION */(function(process) {/** - * Copyright 2014-2015, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule warning - */ - - "use strict"; - - var emptyFunction = __webpack_require__(13); - - /** - * Similar to invariant but only logs a warning if the condition is not met. - * This can be used to log issues in development environments in critical - * paths. Removing the logging code for production environments will keep the - * same logic and follow the same code paths. - */ - - var warning = emptyFunction; - - if ("production" !== process.env.NODE_ENV) { - warning = function(condition, format ) {for (var args=[],$__0=2,$__1=arguments.length;$__0<$__1;$__0++) args.push(arguments[$__0]); - if (format === undefined) { - throw new Error( - '`warning(condition, format, ...args)` requires a warning ' + - 'message argument' - ); - } - - if (format.length < 10 || /^[s\W]*$/.test(format)) { - throw new Error( - 'The warning format should be able to uniquely identify this ' + - 'warning. Please, use a more descriptive format than: ' + format - ); - } - - if (format.indexOf('Failed Composite propType: ') === 0) { - return; // Ignore CompositeComponent proptype check. - } - - if (!condition) { - var argIndex = 0; - var message = 'Warning: ' + format.replace(/%s/g, function() {return args[argIndex++];}); - console.warn(message); - try { - // --- Welcome to debugging React --- - // This error was thrown as a convenience so that you can use this stack - // to find the callsite that caused this warning to fire. - throw new Error(message); - } catch(x) {} - } - }; - } - - module.exports = warning; - - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(12))) - -/***/ }, -/* 12 */ -/***/ function(module, exports, __webpack_require__) { - - // shim for using process in browser - - var process = module.exports = {}; - var queue = []; - var draining = false; - - function drainQueue() { - if (draining) { - return; - } - draining = true; - var currentQueue; - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - var i = -1; - while (++i < len) { - currentQueue[i](); - } - len = queue.length; - } - draining = false; - } - process.nextTick = function (fun) { - queue.push(fun); - if (!draining) { - setTimeout(drainQueue, 0); - } - }; - - process.title = 'browser'; - process.browser = true; - process.env = {}; - process.argv = []; - process.version = ''; // empty string to avoid regexp issues - process.versions = {}; - - function noop() {} - - process.on = noop; - process.addListener = noop; - process.once = noop; - process.off = noop; - process.removeListener = noop; - process.removeAllListeners = noop; - process.emit = noop; - - process.binding = function (name) { - throw new Error('process.binding is not supported'); - }; - - // TODO(shtylman) - process.cwd = function () { return '/' }; - process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); - }; - process.umask = function() { return 0; }; - - -/***/ }, -/* 13 */ -/***/ function(module, exports, __webpack_require__) { - - /** - * Copyright 2013-2015, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule emptyFunction - */ - - function makeEmptyFunction(arg) { - return function() { - return arg; - }; - } - - /** - * This function accepts and discards inputs; it has no side effects. This is - * primarily useful idiomatically for overridable function endpoints which - * always need to be callable, since JS lacks a null-call idiom ala Cocoa. - */ - function emptyFunction() {} - - emptyFunction.thatReturns = makeEmptyFunction; - emptyFunction.thatReturnsFalse = makeEmptyFunction(false); - emptyFunction.thatReturnsTrue = makeEmptyFunction(true); - emptyFunction.thatReturnsNull = makeEmptyFunction(null); - emptyFunction.thatReturnsThis = function() { return this; }; - emptyFunction.thatReturnsArgument = function(arg) { return arg; }; - - module.exports = emptyFunction; - - /***/ } /******/ ]) }); diff --git a/lib/ReactRouterBootstrap.min.js b/lib/ReactRouterBootstrap.min.js index 6a1d2c2..5f04bf5 100644 --- a/lib/ReactRouterBootstrap.min.js +++ b/lib/ReactRouterBootstrap.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react"),require("react-bootstrap/lib/MenuItem"),require("react-bootstrap/lib/Button"),require("react-bootstrap/lib/NavItem")):"function"==typeof define&&define.amd?define(["react","react-bootstrap/lib/MenuItem","react-bootstrap/lib/Button","react-bootstrap/lib/NavItem"],e):"object"==typeof exports?exports.ReactRouterBootstrap=e(require("react"),require("react-bootstrap/lib/MenuItem"),require("react-bootstrap/lib/Button"),require("react-bootstrap/lib/NavItem")):t.ReactRouterBootstrap=e(t.React,t.ReactBootstrap.MenuItem,t.ReactBootstrap.Button,t.ReactBootstrap.NavItem)}(this,function(t,e,r,o){return function(t){function e(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return t[o].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){var o=r(1),n=r(2),i=r(3);t.exports={ButtonLink:o,MenuItemLink:n,NavItemLink:i}},function(t,e,r){var o=r(4),n=r(6),i=r(8),s=o.createClass({displayName:"ButtonLink",mixins:[i],contextTypes:{router:o.PropTypes.func.isRequired},render:function(){var t=this.props,e=t.to,r=t.params,i=t.query,s=t.active,a=function(t,e){var r={},o=Object.prototype.hasOwnProperty;if(null==t)throw new TypeError;for(var n in t)o.call(t,n)&&!o.call(e,n)&&(r[n]=t[n]);return r}(t,{to:1,params:1,query:1,active:1});return void 0===this.props.active&&(s=this.context.router.isActive(e,r,i)),o.createElement(n,o.__spread({},a,{href:this.getHref(),active:s,onClick:this.handleRouteTo,ref:"button"}),this.props.children)}});t.exports=s},function(t,e,r){var o=r(4),n=r(9),i=r(5),s=r(8),a=r(10),u=o.createClass({displayName:"MenuItemLink",mixins:[s],contextTypes:{router:o.PropTypes.func.isRequired},render:function(){var t=this.props,e=t.to,r=t.params,s=t.query,u=t.active,c=t.className,p=(t.onSelect,function(t,e){var r={},o=Object.prototype.hasOwnProperty;if(null==t)throw new TypeError;for(var n in t)o.call(t,n)&&!o.call(e,n)&&(r[n]=t[n]);return r}(t,{to:1,params:1,query:1,active:1,className:1,onSelect:1}));return void 0===this.props.active&&(u=this.context.router.isActive(e,r,s)),o.createElement(i,o.__spread({},p,{href:this.getHref(),className:a(c,n({active:u})),onClick:this.handleRouteTo,ref:"menuItem"}),this.props.children)}});t.exports=u},function(t,e,r){var o=r(4),n=r(7),i=r(8),s=o.createClass({displayName:"NavItemLink",mixins:[i],contextTypes:{router:o.PropTypes.func.isRequired},render:function(){var t=this.props,e=t.to,r=t.params,i=t.query,s=t.active,a=function(t,e){var r={},o=Object.prototype.hasOwnProperty;if(null==t)throw new TypeError;for(var n in t)o.call(t,n)&&!o.call(e,n)&&(r[n]=t[n]);return r}(t,{to:1,params:1,query:1,active:1});return void 0===this.props.active&&(s=this.context.router.isActive(e,r,i)),o.createElement(n,o.__spread({},a,{href:this.getHref(),active:s,onClick:this.handleRouteTo,ref:"navItem"}),this.props.children)}});t.exports=s},function(e){e.exports=t},function(t){t.exports=e},function(t){t.exports=r},function(t){t.exports=o},function(t,e,r){function o(t){return 0===t.button}function n(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}var i=r(4),s=r(9);t.exports={propTypes:{activeClassName:i.PropTypes.string.isRequired,to:i.PropTypes.string.isRequired,params:i.PropTypes.object,query:i.PropTypes.object,onClick:i.PropTypes.func},contextTypes:{router:i.PropTypes.func.isRequired},getDefaultProps:function(){return{activeClassName:"active"}},getHref:function(){return this.context.router.makeHref(this.props.to,this.props.params,this.props.query)},getClassName:function(){var t={};return this.props.className&&(t[this.props.className]=!0),this.context.router.isActive(this.props.to,this.props.params,this.props.query)&&(t[this.props.activeClassName]=!0),s(t)},handleRouteTo:function(t){var e,r=!0;this.props.onClick&&(e=this.props.onClick(t)),!n(t)&&o(t)&&((e===!1||t.defaultPrevented===!0)&&(r=!1),t.preventDefault(),r&&this.context.router.transitionTo(this.props.to,this.props.params,this.props.query))}}},function(t,e,r){(function(e){"use strict";function o(t){return"production"!==e.env.NODE_ENV&&("production"!==e.env.NODE_ENV?n(i,"React.addons.classSet will be deprecated in a future version. See http://fb.me/react-addons-classset"):null,i=!0),"object"==typeof t?Object.keys(t).filter(function(e){return t[e]}).join(" "):Array.prototype.join.call(arguments," ")}var n=r(11),i=!1;t.exports=o}).call(e,r(12))},function(t){"use strict";function e(t){t||(t="");var e,r=arguments.length;if(r>1)for(var o=1;r>o;o++)e=arguments[o],e&&(t=(t?t+" ":"")+e);return t}t.exports=e},function(t,e,r){(function(e){"use strict";var o=r(13),n=o;"production"!==e.env.NODE_ENV&&(n=function(t,e){for(var r=[],o=2,n=arguments.length;n>o;o++)r.push(arguments[o]);if(void 0===e)throw new Error("`warning(condition, format, ...args)` requires a warning message argument");if(e.length<10||/^[s\W]*$/.test(e))throw new Error("The warning format should be able to uniquely identify this warning. Please, use a more descriptive format than: "+e);if(0!==e.indexOf("Failed Composite propType: ")&&!t){var i=0,s="Warning: "+e.replace(/%s/g,function(){return r[i++]});console.warn(s);try{throw new Error(s)}catch(a){}}}),t.exports=n}).call(e,r(12))},function(t){function e(){if(!i){i=!0;for(var t,e=n.length;e;){t=n,n=[];for(var r=-1;++r1)for(var o=1;r>o;o++)e=arguments[o],e&&(t=(t?t+" ":"")+e);return t}t.exports=e}])}); \ No newline at end of file diff --git a/package.json b/package.json index f75cbc7..d95dc76 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "homepage": "https://github.com/mtscout6/react-router-bootstrap", "peerDependencies": { "react-bootstrap": ">=0.15", - "react-router": ">=0.13.1" + "react-router": ">=0.13.1", + "classnames": ">=1.2.0" }, "devDependencies": { "bootstrap": "^3.3.1", @@ -53,6 +54,7 @@ "react": "*", "react-bootstrap": ">=0.15", "react-router": ">=0.13.1", + "classnames": ">=1.2.0", "react-tools": "^0.12.1", "style-loader": "^0.8.2", "url-loader": "^0.5.5", diff --git a/src/LinkMixin.js b/src/LinkMixin.js index 3f6087e..75c765d 100644 --- a/src/LinkMixin.js +++ b/src/LinkMixin.js @@ -1,5 +1,5 @@ var React = require('react'); -var classSet = require('react/lib/cx'); +var classSet = require('classnames'); function isLeftClickEvent(event) { return event.button === 0; diff --git a/src/MenuItemLink.js b/src/MenuItemLink.js index 9906853..3964b63 100644 --- a/src/MenuItemLink.js +++ b/src/MenuItemLink.js @@ -1,5 +1,5 @@ var React = require('react'); -var classSet = require('react/lib/cx'); +var classSet = require('classnames'); var MenuItem = require('react-bootstrap/lib/MenuItem'); var LinkMixin = require('./LinkMixin');