Merge branch 'feature/modal' of github.com:andrerfneves/zcash-reference-wallet into feature/transactions-details
This commit is contained in:
commit
fee6dca6dc
|
@ -90,7 +90,7 @@ export class DropdownComponent extends Component<Props, State> {
|
|||
</MenuItem>
|
||||
)}
|
||||
{options.map(({ label: optionLabel, onClick }) => (
|
||||
<MenuItem onClick={onClick}>
|
||||
<MenuItem onClick={onClick} key={optionLabel}>
|
||||
<TextComponent value={optionLabel} />
|
||||
</MenuItem>
|
||||
))}
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
// @flow
|
||||
import React, { PureComponent, Fragment, type Element } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import styled from 'styled-components';
|
||||
|
||||
const ModalWrapper = styled.div`
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
position: fixed;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 10;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
`;
|
||||
|
||||
const ChildrenWrapper = styled.div`
|
||||
z-index: 90;
|
||||
`;
|
||||
|
||||
type Props = {
|
||||
renderTrigger: (() => void) => Element<*>,
|
||||
children: Element<*>,
|
||||
};
|
||||
|
||||
type State = {
|
||||
isVisible: boolean,
|
||||
};
|
||||
|
||||
const modalRoot = document.getElementById('modal-root');
|
||||
|
||||
export class ModalComponent extends PureComponent<Props, State> {
|
||||
element = document.createElement('div');
|
||||
|
||||
state = {
|
||||
isVisible: false,
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
window.addEventListener('keydown', this.handleEscPress);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
window.removeEventListener('keydown', this.handleEscPress);
|
||||
}
|
||||
|
||||
handleEscPress = (event: Object) => {
|
||||
const { isVisible } = this.state;
|
||||
|
||||
if (event.key === 'Escape' && isVisible) {
|
||||
this.close();
|
||||
}
|
||||
};
|
||||
|
||||
open = () => {
|
||||
this.setState(
|
||||
() => ({ isVisible: true }),
|
||||
() => {
|
||||
if (modalRoot) modalRoot.appendChild(this.element);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
close = () => {
|
||||
this.setState(
|
||||
() => ({ isVisible: false }),
|
||||
() => {
|
||||
if (modalRoot) modalRoot.removeChild(this.element);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { renderTrigger, children } = this.props;
|
||||
const { isVisible } = this.state;
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
{renderTrigger(isVisible ? this.close : this.open)}
|
||||
{isVisible
|
||||
? createPortal(
|
||||
<ModalWrapper
|
||||
id='modal-portal-wrapper'
|
||||
onClick={(event) => {
|
||||
if (event.target.id === 'modal-portal-wrapper') this.close();
|
||||
}}
|
||||
>
|
||||
<ChildrenWrapper>{children}</ChildrenWrapper>
|
||||
</ModalWrapper>,
|
||||
this.element,
|
||||
)
|
||||
: null}
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
// @flow
|
||||
import React from 'react';
|
||||
import React, { Fragment } from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { TransactionItemComponent, type Transaction } from './transaction-item';
|
||||
import { TextComponent } from './text';
|
||||
|
@ -49,7 +49,7 @@ export const TransactionDailyComponent = ({
|
|||
{transactions.map(({
|
||||
date, type, address, amount,
|
||||
}, idx) => (
|
||||
<div>
|
||||
<Fragment key={`${address}-${type}-${amount}-${date}`}>
|
||||
<TransactionItemComponent
|
||||
type={type}
|
||||
date={date}
|
||||
|
@ -58,7 +58,7 @@ export const TransactionDailyComponent = ({
|
|||
zecPrice={zecPrice}
|
||||
/>
|
||||
{idx < transactions.length - 1 && <Divider />}
|
||||
</div>
|
||||
</Fragment>
|
||||
))}
|
||||
</TransactionsWrapper>
|
||||
</Wrapper>
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
<body>
|
||||
<noscript> You need to enable JavaScript to run this app. </noscript>
|
||||
|
||||
<!-- React App Inject -->
|
||||
<div id="root"></div>
|
||||
<!-- End React App Inject -->
|
||||
<div id="modal-root"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue