gab-social/app/javascript/gabsocial/components/modal/modal_layout.js

95 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-02-24 21:56:07 +00:00
import { defineMessages, injectIntl } from 'react-intl'
2020-03-24 04:39:12 +00:00
import classNames from 'classnames/bind'
2020-03-25 03:08:43 +00:00
import { closeModal } from '../../actions/modal'
2020-02-24 21:56:07 +00:00
import Button from '../button'
import Block from '../block'
import Heading from '../heading'
2020-03-24 04:39:12 +00:00
const cx = classNames.bind(_s)
const messages = defineMessages({
close: { id: 'lightbox.close', defaultMessage: 'Close' },
2020-02-24 21:56:07 +00:00
})
2020-03-25 03:08:43 +00:00
const mapDispatchToProps = dispatch => {
return {
handleCloseModal() {
dispatch(closeModal())
},
}
}
2020-02-24 21:56:07 +00:00
export default
2020-03-25 03:08:43 +00:00
@connect(null, mapDispatchToProps)
2020-02-24 21:56:07 +00:00
@injectIntl
class ModalLayout extends PureComponent {
static propTypes = {
title: PropTypes.string,
children: PropTypes.node,
onClose: PropTypes.func.isRequired,
2020-03-25 03:08:43 +00:00
handleCloseModal: PropTypes.func.isRequired,
2020-03-24 04:39:12 +00:00
width: PropTypes.number,
hideClose: PropTypes.bool,
noPadding: PropTypes.bool,
}
static defaultProps = {
width: 600,
2020-02-24 21:56:07 +00:00
}
2020-03-25 03:08:43 +00:00
onHandleCloseModal = () => {
if (this.props.onClose) {
this.props.onClose();
} else {
this.props.handleCloseModal()
}
}
render() {
2020-03-07 04:53:28 +00:00
const {
title,
children,
intl,
2020-03-24 04:39:12 +00:00
width,
hideClose,
noPadding
2020-03-07 04:53:28 +00:00
} = this.props
2020-03-24 04:39:12 +00:00
const childrenContainerClasses = cx({
default: 1,
2020-03-25 03:08:43 +00:00
heightMax80VH: 1,
2020-03-27 15:29:52 +00:00
overflowYScroll: 1,
2020-03-24 04:39:12 +00:00
px15: !noPadding,
py10: !noPadding,
})
return (
2020-03-24 04:39:12 +00:00
<div style={{width: `${width}px`}}>
2020-02-24 21:56:07 +00:00
<Block>
2020-03-11 23:56:18 +00:00
<div className={[_s.default, _s.flexRow, _s.alignItemsCenter, _s.justifyContentCenter, _s.borderBottom1PX, _s.borderColorSecondary, _s.height53PX, _s.px15].join(' ')}>
2020-02-24 21:56:07 +00:00
<Heading size='h3'>
{title}
</Heading>
2020-03-24 04:39:12 +00:00
{
!hideClose &&
<Button
backgroundColor='none'
title={intl.formatMessage(messages.close)}
className={_s.marginLeftAuto}
2020-03-25 03:08:43 +00:00
onClick={this.onHandleCloseModal}
2020-03-27 15:29:52 +00:00
color='secondary'
2020-03-24 04:39:12 +00:00
icon='close'
iconWidth='10px'
iconWidth='10px'
/>
}
2020-02-24 21:56:07 +00:00
</div>
2020-03-24 04:39:12 +00:00
<div className={childrenContainerClasses}>
2020-02-24 21:56:07 +00:00
{children}
</div>
</Block>
</div>
)
2020-02-24 21:56:07 +00:00
}
}