Skip to content

Commit

Permalink
fix: ∆
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLantz committed Jan 6, 2017
1 parent 07bcffb commit c320c12
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 111 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ npm-debug.log
build/dev*
build/dist*
npm_scripts/*.js
yarn.lock
7 changes: 2 additions & 5 deletions demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import MyComponent from '../main';


function init() {

document.body.dispatchEvent(new CustomEvent('o.InitAlertsComponent', {
detail: {
elementId: 'demo-target1'
}
}));

new MyComponent({
elementId: 'demo-target2'
});
}));

}

Expand Down
20 changes: 17 additions & 3 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@ <h1>Alerts Demo</h1>
<p>Styled using the Elements SDK.</p>
<h4>Instance 1</h4>
<div id="demo-target1"></div>
<h4>Instance 2</h4>
<div id="demo-target2"></div>

<button onclick="buttonHandler('succes')">Success Alert!</button>
<br />
<br />
<button onclick="buttonHandler('error')">Error Alert!</button>

<script>
function buttonHandler(type){
// To trigger an alert... dispatch 'triggerAlert' with valid type and message
document.body.dispatchEvent(new CustomEvent('triggerAlert', {
alertType : type,
alertMessage: type + ' test message'
}));
console.log(type + " alertTriggered!")
}
</script>

<script>
if (document.body.children[0].nodeName !== 'svg') {
Expand All @@ -36,6 +50,6 @@ <h4>Instance 2</h4>
<!-- Locally hosted demo server -->
<script src="http://localhost:8081/webpack-dev-server.js"></script>
<!-- Demo build of component -->
<script src="../build/dev.component-name.js"></script>
<script src="../build/dev.alerts.js"></script>
</body>
</html>
11 changes: 4 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import AlertsComponent from './src/js/component-owner';
import ComponentOwner from './src/js/component-owner';
import { IntlProvider } from 'react-intl';

export default class MyComponent {
export default class AlertsComponent {

constructor(config) {

Expand All @@ -16,15 +16,12 @@ export default class MyComponent {

ReactDOM.render(
<IntlProvider locale={locale}>
<div>
<AlertsComponent data={config} alertType="Error" alertMessage="Error test message" />
<AlertsComponent data={config} alertType="Success" alertMessage="Success test message" />
</div>
<ComponentOwner data={config} />
</IntlProvider>,
document.getElementById(config.elementId)
);
}

}

document.body.addEventListener('o.InitAlertsComponent', e => new MyComponent(e.detail));
document.body.addEventListener('o.InitAlertsComponent', e => new AlertsComponent(e.detail));
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "",
"name": "Alerts",
"version": "0.0.0",
"description": "",
"main": "./build/dist.component-name.js",
"description": "Component to render alerts",
"main": "./build/dist.alerts.js",
"scripts": {
"dev-setup": "node ./npm_scripts/dev-setup.js",
"dev": "node ./npm_scripts/dev.js",
Expand All @@ -16,13 +16,13 @@
"ci": "node ./npm_scripts/ci.js",
"release": "node ./npm_scripts/release.js",
"verify": "node ./npm_scripts/verify.js",
"postinstall": "node ./node_modules/@pearson-components/npm-scripts/npm_scripts/cross-platform.js"
"copy-utils": "node ./node_modules/@pearson-components/npm-scripts/npm_scripts/cross-platform.js"
},
"author": "",
"author": "Pearson Design Accelerator",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/Pearson-Higher-Ed/"
"url": "https://github.com/Pearson-Higher-Ed/alerts"
},
"dependencies": {
"react-intl": "~2.0.1"
Expand Down Expand Up @@ -53,7 +53,7 @@
"json-loader": "~0.5.4",
"mocha": "~2.4.5",
"node-sass": "~3.7.0",
"pearson-elements": "^1.0.5",
"pearson-elements": "^1.1.0",
"react": "^15.0.0",
"react-addons-test-utils": "^15.0.0",
"react-dom": "^15.0.0",
Expand Down
17 changes: 13 additions & 4 deletions src/js/alert.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import React from 'react';
import Icon from './icon';
import Icon from './icon';

const Alert = (props) => (
<span className={`pe-template__static-small ${props.closeTitleProp}`} id={`${props.whichAlertProp}`} role="alert" style={{opacity: props.opacity}}>
<strong className={`pe-label ${props.whichAlertProp}-title`}>{props.whichAlertProp}</strong>
<li
key = {props.key}
className = {`pe-alert pe-template__static-small ${props.closeTitleProp}`}
id = {`${props.alertType}`}
role = "alert"
style = {{opacity: props.opacity}}>

<strong className={`pe-label ${props.alertType}-title`}>{props.alertType}</strong>

<button className="close-title" onClick={props.handleClose} aria-label="Close alert">
<Icon name="remove-lg-18" />
</button><br/>

<span className="pe-copy">
{props.alertMessage}
</span>
</span>

</li>
)

export default Alert;
149 changes: 72 additions & 77 deletions src/js/component-owner.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,87 @@
import React, { Component } from 'react';
import { intlShape, injectIntl } from 'react-intl';
import Alert from './alert';
// import Helper from './helper';

import '../scss/component-specific.scss';

import React, { PropTypes, Component} from 'react';
import { intlShape, injectIntl } from 'react-intl';
import Alert from './alert';
import Helper from './helper';

class AlertsComponent extends Component {

static propTypes = {
intl: intlShape.isRequired,
data: PropTypes.shape({
locale: PropTypes.string,
alertType: PropTypes.string,
alertMessage: PropTypes.string
})
}


class ComponentOwner extends Component {

static propTypes = { intl: intlShape.isRequired }


constructor(props) {
super();
super(props);

this.state = {
alertIsOpen: false,
opacity: 0,
closeProp: '',
alertType: '',
alertMessage: ''
opacity : 0,
closeProp : '',
alertType : '',
alertMessage : '',
alertList : []
};
}

componentDidUpdate = () => {
const findAlert1 = document.querySelector('#demo-target1 [data-reactroot] .pe-template__static-small');
const findAlert2 = document.querySelector('#demo-target2 [data-reactroot] .pe-template__static-small');
if (findAlert1 && findAlert2) { findAlert2.style.top = '170px'; }
if (!findAlert1 && findAlert2) { findAlert2.style.top = '50px'; }
};

handleErrorOpen = (props) => {
this.setState({ alertIsOpen: true, opacity: 1, alertType: this.props.alertType,
alertMessage: this.props.alertMessage });
};

handleSuccessOpen = (props) => {
this.setState({ alertIsOpen: true, opacity: 1, alertType: this.props.alertType,
alertMessage: this.props.alertMessage });
};

handleClose = () => {
const alert1 = document.getElementById('demo-target1');
const alert2 = document.getElementById('demo-target2');

const removeEL = () => {
this.setState({ alertIsOpen: false, opacity: 0, closeProp: '', alertType: '', alertMessage: '' });
if (this.state.alertIsOpen === false) {
alert1.removeEventListener(Helper.whichTransitionEvent(), removeEL);
alert2.removeEventListener(Helper.whichTransitionEvent(), removeEL);
}
}

this.setState({ closeProp: 'close-title-animation' });

alert1.addEventListener(Helper.whichTransitionEvent(), removeEL);
alert2.addEventListener(Helper.whichTransitionEvent(), removeEL);
};

renderAlert = () => (
<Alert
opacity={this.state.opacity}
handleClose={this.handleClose}
closeTitleProp={this.state.closeProp}
whichAlertProp={this.state.alertType}
alertMessage={this.state.alertMessage}
/>
);
// this.handleClose = _handleClose.bind(this);
this.renderAlert = _renderAlert.bind(this);

render () {
}

return (
<div>
<button onClick={this.handleErrorOpen}>Error</button>
{this.state.alertIsOpen
? this.renderAlert()
: ''
}
<button onClick={this.handleSuccessOpen}>Success</button>
</div>

componentDidMount() {
// const { alertList } = this.state;
document.body.addEventListener('triggerAlert',
alert => console.log(alert)
);
}


render () {
const { alertList } = this.state;
console.log(alertList[0])
return this.state.alertList.length > 0 ? alertList.forEach( (alert, index) => <ul>{this.renderAlert(alert, index)}</ul> ) : null;
}


}

export default injectIntl(AlertsComponent);


export default injectIntl(ComponentOwner);



function _renderAlert (alert, index) {
return (
<Alert
key = {index}
opacity = {1}
closeTitleProp = {this.state.closeProp}
alertType = {alert.alertType}
alertMessage = {alert.alertMessage}
handleClose = {this.handleClose}
/>
);
}


// function _handleClose() {
//
// const alert1 = document.getElementById('demo-target1');
//
// const removeEL = () => {
// if (this.state.alertIsOpen === false) {
// alert1.removeEventListener(Helper.whichTransitionEvent(), removeEL);
// }
// }
//
// this.setState({
// // closeProp : 'close-title-animation',
// opacity : 0,
// closeProp : '',
// alertType : '',
// alertMessage : ''
// });
//
// };
9 changes: 8 additions & 1 deletion src/js/helper.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
const Helper = {
whichTransitionEvent: () => {

let transition;

const transitions = {
transition: 'animationend',
WebkitTransition: 'webkitAnimationEnd'
};
Object.keys(transitions).forEach((transitionKey) => {

Object.keys(transitions).forEach(transitionKey => {
if (document.getElementById('demo-target1').style[transitionKey] !== undefined) {
transition = transitions[transitionKey];
}
});

return transition;

}
};



export default Helper;
Loading

0 comments on commit c320c12

Please sign in to comment.