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

82 lines
1.9 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
2020-02-24 21:56:07 +00:00
import { defineMessages, injectIntl } from 'react-intl'
import { CX } from '../../constants'
2020-02-24 21:56:07 +00:00
import Button from '../button'
import Block from '../block'
import Heading from '../heading'
class ModalLayout extends React.PureComponent {
2020-05-14 21:45:39 +01:00
2020-03-25 03:08:43 +00:00
onHandleCloseModal = () => {
2020-04-07 02:53:23 +01:00
this.props.onClose()
2020-03-25 03:08:43 +00:00
}
render() {
2020-03-07 04:53:28 +00:00
const {
title,
children,
intl,
2020-03-24 04:39:12 +00:00
width,
hideClose,
2020-05-14 21:45:39 +01:00
noPadding,
isXS,
2020-03-07 04:53:28 +00:00
} = this.props
const childrenContainerClasses = CX({
d: 1,
maxH80VH: 1,
2020-03-27 15:29:52 +00:00
overflowYScroll: 1,
2020-03-24 04:39:12 +00:00
px15: !noPadding,
py10: !noPadding,
})
return (
<div style={{width: `${width}px`}} className={[_s.d, _s.modal].join(' ')}>
2020-02-24 21:56:07 +00:00
<Block>
<div className={[_s.d, _s.flexRow, _s.aiCenter, _s.jcCenter, _s.borderBottom1PX, _s.borderColorSecondary, _s.h53PX, _s.px15].join(' ')}>
2020-04-24 04:17:27 +01:00
<Heading size='h2'>
2020-02-24 21:56:07 +00:00
{title}
</Heading>
2020-03-24 04:39:12 +00:00
{
2020-05-14 21:45:39 +01:00
!hideClose && !isXS &&
2020-03-24 04:39:12 +00:00
<Button
backgroundColor='none'
title={intl.formatMessage(messages.close)}
2020-04-24 04:17:27 +01:00
className={_s.mlAuto}
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'
2020-04-23 07:13:29 +01:00
iconSize='10px'
2020-03-24 04:39:12 +00:00
/>
}
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
}
}
const messages = defineMessages({
close: { id: 'lightbox.close', defaultMessage: 'Close' },
})
ModalLayout.propTypes = {
title: PropTypes.string,
children: PropTypes.node,
onClose: PropTypes.func.isRequired,
width: PropTypes.number,
hideClose: PropTypes.bool,
noPadding: PropTypes.bool,
isXS: PropTypes.bool,
}
ModalLayout.defaultProps = {
width: 600,
}
export default injectIntl(ModalLayout)