Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"presets": ["env", "react"],
"plugins": ["transform-object-rest-spread"]
"presets": [
[
"env",
{
"modules": false
}
],
"react"
],
"plugins": [
"transform-object-rest-spread"
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"javascript.validate.enable": false
}
87 changes: 87 additions & 0 deletions dist/index.cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var hoistNonReactStatics = _interopDefault(require('hoist-non-react-statics'));
var react = _interopDefault(require('react'));
var reactDom = _interopDefault(require('react-dom'));

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

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; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }





function enhanceWithClickOutside(Component) {
var componentName = Component.displayName || Component.name;

var EnhancedComponent = function (_React$Component) {
_inherits(EnhancedComponent, _React$Component);

function EnhancedComponent(props) {
_classCallCheck(this, EnhancedComponent);

var _this = _possibleConstructorReturn(this, (EnhancedComponent.__proto__ || Object.getPrototypeOf(EnhancedComponent)).call(this, props));

_this.handleClickOutside = _this.handleClickOutside.bind(_this);
return _this;
}

_createClass(EnhancedComponent, [{
key: 'componentDidMount',
value: function componentDidMount() {
document.addEventListener('click', this.handleClickOutside, true);
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
document.removeEventListener('click', this.handleClickOutside, true);
}
}, {
key: 'handleClickOutside',
value: function handleClickOutside(e) {
var domNode = this.__domNode;
if ((!domNode || !domNode.contains(e.target)) && this.__wrappedInstance && typeof this.__wrappedInstance.handleClickOutside === 'function') {
this.__wrappedInstance.handleClickOutside(e);
}
}
}, {
key: 'render',
value: function render() {
var _this2 = this;

var _props = this.props,
wrappedRef = _props.wrappedRef,
rest = _objectWithoutProperties(_props, ['wrappedRef']);

return react.createElement(Component, _extends({}, rest, {
ref: function ref(c) {
_this2.__wrappedInstance = c;
_this2.__domNode = reactDom.findDOMNode(c);
wrappedRef && wrappedRef(c);
}
}));
}
}]);

return EnhancedComponent;
}(react.Component);

EnhancedComponent.displayName = 'clickOutside(' + componentName + ')';

return hoistNonReactStatics(EnhancedComponent, Component);
}

var reactClickOutside = enhanceWithClickOutside;

module.exports = reactClickOutside;
22 changes: 13 additions & 9 deletions dist/index.js → dist/index.es.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
import hoistNonReactStatics from 'hoist-non-react-statics';
import react from 'react';
import reactDom from 'react-dom';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

Expand All @@ -12,9 +14,9 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var hoistNonReactStatic = require('hoist-non-react-statics');
var React = require('react');
var ReactDOM = require('react-dom');




function enhanceWithClickOutside(Component) {
var componentName = Component.displayName || Component.name;
Expand Down Expand Up @@ -58,22 +60,24 @@ function enhanceWithClickOutside(Component) {
wrappedRef = _props.wrappedRef,
rest = _objectWithoutProperties(_props, ['wrappedRef']);

return React.createElement(Component, _extends({}, rest, {
return react.createElement(Component, _extends({}, rest, {
ref: function ref(c) {
_this2.__wrappedInstance = c;
_this2.__domNode = ReactDOM.findDOMNode(c);
_this2.__domNode = reactDom.findDOMNode(c);
wrappedRef && wrappedRef(c);
}
}));
}
}]);

return EnhancedComponent;
}(React.Component);
}(react.Component);

EnhancedComponent.displayName = 'clickOutside(' + componentName + ')';

return hoistNonReactStatic(EnhancedComponent, Component);
return hoistNonReactStatics(EnhancedComponent, Component);
}

module.exports = enhanceWithClickOutside;
var reactClickOutside = enhanceWithClickOutside;

export default reactClickOutside;
157 changes: 157 additions & 0 deletions dist/index.umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('react-dom')) :
typeof define === 'function' && define.amd ? define(['react', 'react-dom'], factory) :
(global.ReactClickOutside = factory(global.React,global.ReactDOM));
}(this, (function (react,reactDom) { 'use strict';

react = react && react.hasOwnProperty('default') ? react['default'] : react;
reactDom = reactDom && reactDom.hasOwnProperty('default') ? reactDom['default'] : reactDom;

/**
* Copyright 2015, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/

var REACT_STATICS = {
childContextTypes: true,
contextTypes: true,
defaultProps: true,
displayName: true,
getDefaultProps: true,
mixins: true,
propTypes: true,
type: true
};

var KNOWN_STATICS = {
name: true,
length: true,
prototype: true,
caller: true,
callee: true,
arguments: true,
arity: true
};

var defineProperty = Object.defineProperty;
var getOwnPropertyNames = Object.getOwnPropertyNames;
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
var getPrototypeOf = Object.getPrototypeOf;
var objectPrototype = getPrototypeOf && getPrototypeOf(Object);

var hoistNonReactStatics = function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
if (typeof sourceComponent !== 'string') {
// don't hoist over string (html) components

if (objectPrototype) {
var inheritedComponent = getPrototypeOf(sourceComponent);
if (inheritedComponent && inheritedComponent !== objectPrototype) {
hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
}
}

var keys = getOwnPropertyNames(sourceComponent);

if (getOwnPropertySymbols) {
keys = keys.concat(getOwnPropertySymbols(sourceComponent));
}

for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
if (!REACT_STATICS[key] && !KNOWN_STATICS[key] && (!blacklist || !blacklist[key])) {
var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
try {
// Avoid failures from read-only properties
defineProperty(targetComponent, key, descriptor);
} catch (e) {}
}
}

return targetComponent;
}

return targetComponent;
};

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

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; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }





function enhanceWithClickOutside(Component) {
var componentName = Component.displayName || Component.name;

var EnhancedComponent = function (_React$Component) {
_inherits(EnhancedComponent, _React$Component);

function EnhancedComponent(props) {
_classCallCheck(this, EnhancedComponent);

var _this = _possibleConstructorReturn(this, (EnhancedComponent.__proto__ || Object.getPrototypeOf(EnhancedComponent)).call(this, props));

_this.handleClickOutside = _this.handleClickOutside.bind(_this);
return _this;
}

_createClass(EnhancedComponent, [{
key: 'componentDidMount',
value: function componentDidMount() {
document.addEventListener('click', this.handleClickOutside, true);
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
document.removeEventListener('click', this.handleClickOutside, true);
}
}, {
key: 'handleClickOutside',
value: function handleClickOutside(e) {
var domNode = this.__domNode;
if ((!domNode || !domNode.contains(e.target)) && this.__wrappedInstance && typeof this.__wrappedInstance.handleClickOutside === 'function') {
this.__wrappedInstance.handleClickOutside(e);
}
}
}, {
key: 'render',
value: function render() {
var _this2 = this;

var _props = this.props,
wrappedRef = _props.wrappedRef,
rest = _objectWithoutProperties(_props, ['wrappedRef']);

return react.createElement(Component, _extends({}, rest, {
ref: function ref(c) {
_this2.__wrappedInstance = c;
_this2.__domNode = reactDom.findDOMNode(c);
wrappedRef && wrappedRef(c);
}
}));
}
}]);

return EnhancedComponent;
}(react.Component);

EnhancedComponent.displayName = 'clickOutside(' + componentName + ')';

return hoistNonReactStatics(EnhancedComponent, Component);
}

var reactClickOutside = enhanceWithClickOutside;

return reactClickOutside;

})));
1 change: 1 addition & 0 deletions dist/index.umd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"name": "react-click-outside",
"version": "3.0.1",
"description": "A component wrapper that provides click outside detection.",
"main": "dist/index.js",
"main": "dist/index.cjs.js",
"unpkg": "dist/index.umd.js",
"module": "dist/index.es.js",
"scripts": {
"build": "npm test && babel -d dist index.js",
"build": "npm test && rollup -c",
"demo": "budo demo/app.js -- -t babelify",
"lint": "eslint .",
"test": "jest",
Expand All @@ -28,6 +30,7 @@
"homepage": "https://github.com/kentor/react-click-outside",
"devDependencies": {
"babel-cli": "6.26.0",
"babel-core": "6.26.0",
"babel-eslint": "8.2.1",
"babel-jest": "21.2.0",
"babel-plugin-transform-object-rest-spread": "6.26.0",
Expand All @@ -45,7 +48,12 @@
"jest": "21.2.1",
"react": "16.0.0",
"react-dom": "16.0.0",
"react-test-renderer": "16.0.0"
"react-test-renderer": "16.0.0",
"rollup": "^0.62.0",
"rollup-plugin-babel": "^3.0.7",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-uglify": "^4.0.0"
},
"dependencies": {
"hoist-non-react-statics": "^2.1.1"
Expand Down
Loading