Skip to content

Commit

Permalink
Get rid of CommonJS module (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy authored and claydiffrient committed Jan 3, 2017
1 parent b261459 commit a776118
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
import ExecutionEnvironment from 'exenv';
import elementClass from 'element-class';
import ModalPortal from './ModalPortal';
import ariaAppHider from '../helpers/ariaAppHider';
import * as ariaAppHider from '../helpers/ariaAppHider';

const renderSubtreeIntoContainer = ReactDOM.unstable_renderSubtreeIntoContainer;

Expand Down
28 changes: 11 additions & 17 deletions lib/helpers/ariaAppHider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
let globalElement = typeof document !== 'undefined' ? document.body : null;

function setElement (element) {
function validateElement (appElement) {
if (!appElement && !globalElement) {
throw new Error('react-modal: You must set an element with `Modal.setAppElement(el)` to make this accessible');
}
}

export function setElement (element) {
let newElement = element;
if (typeof newElement === 'string') {
const el = document.querySelectorAll(element);
Expand All @@ -10,34 +16,22 @@ function setElement (element) {
return globalElement;
}

function validateElement (appElement) {
if (!appElement && !globalElement) {
throw new Error('react-modal: You must set an element with `Modal.setAppElement(el)` to make this accessible');
}
}

function hide (appElement) {
export function hide (appElement) {
validateElement(appElement);
(appElement || globalElement).setAttribute('aria-hidden', 'true');
}

function show (appElement) {
export function show (appElement) {
validateElement(appElement);
(appElement || globalElement).removeAttribute('aria-hidden');
}

function toggle (shouldHide, appElement) {
export function toggle (shouldHide, appElement) {
if (shouldHide) {
hide(appElement);
} else { show(appElement); }
}

function resetForTesting () {
export function resetForTesting () {
globalElement = document.body;
}

exports.toggle = toggle;
exports.setElement = setElement;
exports.show = show;
exports.hide = hide;
exports.resetForTesting = resetForTesting;
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
module.exports = require('./components/Modal');
import Modal from './components/Modal';

export default Modal;
2 changes: 1 addition & 1 deletion specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import sinon from 'sinon';
import expect from 'expect';
import ReactDOM from 'react-dom';
import Modal from '../lib/components/Modal';
import ariaAppHider from '../lib/helpers/ariaAppHider';
import * as ariaAppHider from '../lib/helpers/ariaAppHider';
import { renderModal, unmountModal } from './helper';

const Simulate = TestUtils.Simulate;
Expand Down

0 comments on commit a776118

Please sign in to comment.