Skip to content

Commit

Permalink
feat: add <Overlay> implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Feb 13, 2018
1 parent 6ea7435 commit 2ace6ac
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Overlay/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {Component} from 'react';
import {Portal} from '../Portal';
import {h} from '../util';

export interface IOverlayProps {
color?: string;
}

export interface IOverlayState {
}

export class Overlay extends Component<IOverlayProps, IOverlayState> {
static defaultProps = {
color: 'rgba(0,0,0,0.5)'
};

onElement = (el) => {
const {style} = el;

style.zIndex = 2147483647; // Max z-index.
style.position = 'fixed';
style.width = '100%';
style.height = '100%';
style.top = 0;
style.left = 0;
style.right = 0;
style.bottom = 0;
style.background = this.props.color;
style.transition = '0.3s opacity';
style.opacity = 0;

style.display = 'flex';
style.alignItems = 'center';
style.justifyContent = 'center';

// After double .requestAnimationFrame
setTimeout(() => {
style.opacity = 1;
}, 35);
};

render () {
return h(Portal, {onElement: this.onElement}, this.props.children);
}
}

0 comments on commit 2ace6ac

Please sign in to comment.