meriadec
7 years ago
4 changed files with 86 additions and 46 deletions
@ -0,0 +1,82 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
import React, { PureComponent } from 'react' |
||||
|
import styled, { keyframes } from 'styled-components' |
||||
|
|
||||
|
import Box from 'components/base/Box' |
||||
|
import IconCross from 'icons/Cross' |
||||
|
|
||||
|
export const Container = styled(Box).attrs({ |
||||
|
px: 5, |
||||
|
pb: 5, |
||||
|
})`` |
||||
|
|
||||
|
type Props = { |
||||
|
deferHeight?: number, |
||||
|
onClose?: Function, |
||||
|
children: any, |
||||
|
} |
||||
|
|
||||
|
type State = { |
||||
|
isHidden: boolean, |
||||
|
} |
||||
|
|
||||
|
class ModalBody extends PureComponent<Props, State> { |
||||
|
state = { |
||||
|
isHidden: true, |
||||
|
} |
||||
|
|
||||
|
componentDidMount() { |
||||
|
setTimeout(() => { |
||||
|
window.requestAnimationFrame(() => { |
||||
|
this.setState({ isHidden: false }) |
||||
|
}) |
||||
|
}, 150) |
||||
|
} |
||||
|
|
||||
|
render() { |
||||
|
const { children, onClose, deferHeight, ...props } = this.props |
||||
|
const { isHidden } = this.state |
||||
|
return ( |
||||
|
<Body style={{ height: isHidden && deferHeight ? deferHeight : undefined }}> |
||||
|
{onClose && ( |
||||
|
<CloseContainer onClick={onClose}> |
||||
|
<IconCross height={16} width={16} /> |
||||
|
</CloseContainer> |
||||
|
)} |
||||
|
{(!isHidden || !deferHeight) && <Inner {...props}>{children}</Inner>} |
||||
|
</Body> |
||||
|
) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
const CloseContainer = styled(Box).attrs({ |
||||
|
p: 4, |
||||
|
color: 'fog', |
||||
|
})` |
||||
|
cursor: pointer; |
||||
|
position: absolute; |
||||
|
top: 0; |
||||
|
right: 0; |
||||
|
|
||||
|
&:hover { |
||||
|
color: ${p => p.theme.colors.grey}; |
||||
|
} |
||||
|
` |
||||
|
|
||||
|
const Body = styled(Box).attrs({ |
||||
|
bg: p => p.theme.colors.white, |
||||
|
relative: true, |
||||
|
borderRadius: 1, |
||||
|
})`` |
||||
|
|
||||
|
const appear = keyframes` |
||||
|
from { opacity: 0; } |
||||
|
to { opacity: 1; } |
||||
|
` |
||||
|
|
||||
|
const Inner = styled(Box)` |
||||
|
animation: ${appear} 80ms linear; |
||||
|
` |
||||
|
|
||||
|
export default ModalBody |
Loading…
Reference in new issue