Skip to content

Add Linting #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 31, 2016
Merged
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
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["es2015", "react"]
}
"presets": ["react", "latest", "stage-2"]
}
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
"env": {
"es6": true,
"browser": true
},
"extends": "airbnb",
"parserOptions": {
"ecmaVersion": 7,
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"parser": "babel-eslint",
rules: {
"comma-dangle": [2, "only-multiline"],
"max-len": [1, {"code": 140}],
"no-continue": [0],
"no-plusplus": [0],
"space-before-function-paren": [2, "always"],
"import/no-extraneous-dependencies": [2, {"devDependencies": true}],
"react/jsx-filename-extension": ["error", {"extensions": [".js"]}]
},
};
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ node_js:
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
script: npm run test:full
cache: yarn
18 changes: 0 additions & 18 deletions eslint.json

This file was deleted.

165 changes: 82 additions & 83 deletions lib/components/Modal.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
var React = require('react');
var ReactDOM = require('react-dom');
var ExecutionEnvironment = require('exenv');
var ModalPortal = React.createFactory(require('./ModalPortal'));
var ariaAppHider = require('../helpers/ariaAppHider');
var elementClass = require('element-class');
var renderSubtreeIntoContainer = require("react-dom").unstable_renderSubtreeIntoContainer;
var Assign = require('lodash.assign');

var SafeHTMLElement = ExecutionEnvironment.canUseDOM ? window.HTMLElement : {};
var AppElement = ExecutionEnvironment.canUseDOM ? document.body : {appendChild: function() {}};

function getParentElement(parentSelector) {
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import ExecutionEnvironment from 'exenv';
import elementClass from 'element-class';
import ModalPortal from './ModalPortal';
import ariaAppHider from '../helpers/ariaAppHider';

const renderSubtreeIntoContainer = ReactDOM.unstable_renderSubtreeIntoContainer;

const SafeHTMLElement = ExecutionEnvironment.canUseDOM ? window.HTMLElement : {};

function getParentElement (parentSelector) {
return parentSelector();
}

var Modal = React.createClass({

displayName: 'Modal',
statics: {
setAppElement: function(element) {
AppElement = ariaAppHider.setElement(element);
},
injectCSS: function() {
"production" !== process.env.NODE_ENV
&& console.warn('React-Modal: injectCSS has been deprecated ' +
'and no longer has any effect. It will be removed in a later version');
}
},
export default class Modal extends Component {

propTypes: {
/* eslint-disable react/no-unused-prop-types */
static propTypes = {
isOpen: React.PropTypes.bool.isRequired,
style: React.PropTypes.shape({
content: React.PropTypes.object,
Expand All @@ -44,52 +32,86 @@ var Modal = React.createClass({
parentSelector: React.PropTypes.func,
role: React.PropTypes.string,
contentLabel: React.PropTypes.string.isRequired
},

getDefaultProps: function () {
return {
isOpen: false,
portalClassName: 'ReactModalPortal',
ariaHideApp: true,
closeTimeoutMS: 0,
shouldCloseOnOverlayClick: true,
parentSelector: function () { return document.body; }
};
},

componentDidMount: function() {
};
/* eslint-enable react/no-unused-prop-types */

static defaultProps = {
isOpen: false,
portalClassName: 'ReactModalPortal',
ariaHideApp: true,
closeTimeoutMS: 0,
shouldCloseOnOverlayClick: true,
parentSelector () { return document.body; }
};

static defaultStyles = {
overlay: {
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'rgba(255, 255, 255, 0.75)'
},
content: {
position: 'absolute',
top: '40px',
left: '40px',
right: '40px',
bottom: '40px',
border: '1px solid #ccc',
background: '#fff',
overflow: 'auto',
WebkitOverflowScrolling: 'touch',
borderRadius: '4px',
outline: 'none',
padding: '20px'
}
};

static setAppElement (element) {
ariaAppHider.setElement(element);
}

static injectCSS () {
return process.env.NODE_ENV !== 'production'
&& console.warn('React-Modal: injectCSS has been deprecated ' +
'and no longer has any effect. It will be removed in a later version');
}

componentDidMount () {
this.node = document.createElement('div');
this.node.className = this.props.portalClassName;

var parent = getParentElement(this.props.parentSelector);
const parent = getParentElement(this.props.parentSelector);
parent.appendChild(this.node);
this.renderPortal(this.props);
},
}

componentWillReceiveProps: function(newProps) {
var currentParent = getParentElement(this.props.parentSelector);
var newParent = getParentElement(newProps.parentSelector);
componentWillReceiveProps (newProps) {
const currentParent = getParentElement(this.props.parentSelector);
const newParent = getParentElement(newProps.parentSelector);

if(newParent !== currentParent) {
if (newParent !== currentParent) {
currentParent.removeChild(this.node);
newParent.appendChild(this.node);
}

this.renderPortal(newProps);
},
}

componentWillUnmount: function() {
componentWillUnmount () {
if (this.props.ariaHideApp) {
ariaAppHider.show(this.props.appElement);
}

ReactDOM.unmountComponentAtNode(this.node);
var parent = getParentElement(this.props.parentSelector);
const parent = getParentElement(this.props.parentSelector);
parent.removeChild(this.node);
elementClass(document.body).remove('ReactModal__Body--open');
},
}

renderPortal: function(props) {
renderPortal (props) {
if (props.isOpen) {
elementClass(document.body).add('ReactModal__Body--open');
} else {
Expand All @@ -100,37 +122,14 @@ var Modal = React.createClass({
ariaAppHider.toggle(props.isOpen, props.appElement);
}

this.portal = renderSubtreeIntoContainer(this, ModalPortal(Assign({}, props, {defaultStyles: Modal.defaultStyles})), this.node);
},

render: function () {
return React.DOM.noscript();
this.portal = renderSubtreeIntoContainer(this,
<ModalPortal
{...props}
defaultStyles={Modal.defaultStyles}
/>, this.node);
}
});

Modal.defaultStyles = {
overlay: {
position : 'fixed',
top : 0,
left : 0,
right : 0,
bottom : 0,
backgroundColor : 'rgba(255, 255, 255, 0.75)'
},
content: {
position : 'absolute',
top : '40px',
left : '40px',
right : '40px',
bottom : '40px',
border : '1px solid #ccc',
background : '#fff',
overflow : 'auto',
WebkitOverflowScrolling : 'touch',
borderRadius : '4px',
outline : 'none',
padding : '20px'

render () {
return null;
}
}

module.exports = Modal
Loading