hyper/lib/components/notification.js

114 lines
3 KiB
JavaScript
Raw Normal View History

2016-07-13 12:44:24 -08:00
import React from 'react';
export default class Notification extends React.PureComponent {
constructor() {
2016-07-13 12:44:24 -08:00
super();
this.state = {
dismissing: false
};
}
componentDidMount() {
2016-07-13 12:44:24 -08:00
if (this.props.dismissAfter) {
this.setDismissTimer();
}
}
Update Electron to v6 (#3785) * 3.0.0 * 3.0.2 * Save * Save * Upgrade yarn lock packages * update node-gyp and node-pty * update travis and appveyor to node 12 * appveyor is outdated as always * update travis to xenial * update node-pty@0.9.0-beta26 * update yarn.lock * update electron to 6.0.8 * move node-pty to the correct package.json * Fix linting failure * Update yarn lockfile to try to fix appveyor build * Remove unnecessary changes from package.json * Try to fix appveyor by using a newer image * Fix linting after my last change * update electron to 6.0.9 * install windows-build-tools on appveyor * fix syntax * switch back to 2017 image * remove old resolutions field * revert accidental version change * update electron to 6.0.11 and electron-rebuild to 1.8.6 * downgrade yarn to 1.18 until this issue is resolved https://github.com/yarnpkg/yarn/issues/7584 * update node-gyp to 6.0.0 and generate a fresh yarn lockfile * update react and a few other dependencies * fix lint * this should actually be electron-builder, I think! * update a few dependencies * change to electron-store electron-config was renamed to electron-store a while ago * update xterm to v4.1.0 and ora to 4.0.2 * move pify to app/package.json * TODO: Revert maybe. Throw a fit on every change to maybe fix the resizing issues * a * fix react ref problem * fix split view focus problem * remove the unnecessary fit * remove the init col and row * fix the problem that cannot show about hyper * update electron to 6.0.12 * fix lint * add more todos for componentWillReceiveProps deprecation * update babel and plugins Co-authored-by: Juan Campa <juancampa@gmail.com> Co-authored-by: Benjamin Staneck <staneck@gmail.com> Co-authored-by: ivan <ivanwonder@outlook.com>
2019-10-10 11:20:26 -08:00
//TODO: Remove usage of legacy and soon deprecated lifecycle methods
UNSAFE_componentWillReceiveProps(next) {
2016-07-13 12:44:24 -08:00
// if we have a timer going and the notification text
2016-07-17 13:05:37 -08:00
// changed we reset the timer
2016-07-13 12:44:24 -08:00
if (next.text !== this.props.text) {
if (this.props.dismissAfter) {
this.resetDismissTimer();
}
if (this.state.dismissing) {
this.setState({dismissing: false});
2016-07-13 12:44:24 -08:00
}
}
}
2019-11-25 07:16:00 -09:00
handleDismiss = () => {
this.setState({dismissing: true});
2019-11-25 07:16:00 -09:00
};
2016-07-13 12:44:24 -08:00
2019-11-25 07:16:00 -09:00
onElement = el => {
2016-07-13 12:44:24 -08:00
if (el) {
el.addEventListener('webkitTransitionEnd', () => {
if (this.state.dismissing) {
this.props.onDismiss();
}
});
const {backgroundColor} = this.props;
2016-07-13 12:44:24 -08:00
if (backgroundColor) {
el.style.setProperty('background-color', backgroundColor, 'important');
2016-07-13 12:44:24 -08:00
}
}
2019-11-25 07:16:00 -09:00
};
2016-07-13 12:44:24 -08:00
setDismissTimer() {
2016-07-13 12:44:24 -08:00
this.dismissTimer = setTimeout(() => {
this.handleDismiss();
2016-07-13 12:44:24 -08:00
}, this.props.dismissAfter);
}
resetDismissTimer() {
2016-07-13 12:44:24 -08:00
clearTimeout(this.dismissTimer);
this.setDismissTimer();
}
componentWillUnmount() {
2016-07-13 12:44:24 -08:00
clearTimeout(this.dismissTimer);
}
render() {
const {backgroundColor, color} = this.props;
2016-07-13 12:44:24 -08:00
const opacity = this.state.dismissing ? 0 : 1;
return (
<div ref={this.onElement} style={{opacity, backgroundColor, color}} className="notification_indicator">
{this.props.customChildrenBefore}
{this.props.children || this.props.text}
{this.props.userDismissable ? (
<a
className="notification_dismissLink"
onClick={this.handleDismiss}
style={{color: this.props.userDismissColor}}
>
[x]
</a>
) : null}
{this.props.customChildren}
2016-07-13 12:44:24 -08:00
<style jsx>{`
.notification_indicator {
display: inline-block;
cursor: default;
-webkit-user-select: none;
background: rgba(255, 255, 255, 0.2);
padding: 8px 14px 9px;
margin-left: 10px;
transition: 150ms opacity ease;
color: #fff;
font-size: 12px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell',
'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
}
2016-07-13 12:44:24 -08:00
.notification_dismissLink {
position: relative;
left: 4px;
cursor: pointer;
opacity: 0.5;
color: currentColor;
transition: opacity 0.1s ease-in-out;
}
.notification_dismissLink:hover,
.notification_dismissLink:focus {
opacity: 1;
}
`}</style>
</div>
);
2016-07-13 12:44:24 -08:00
}
}