// @flow // These should probably just be combined into one modal component import * as ICONS from 'constants/icons'; import * as React from 'react'; import ReactModal from 'react-modal'; import Button from 'component/button'; import classnames from 'classnames'; import useIsMobile from 'effects/use-is-mobile'; type ModalProps = { type?: string, overlay?: boolean, confirmButtonLabel?: string, abortButtonLabel?: string, confirmButtonDisabled?: boolean, abortButtonDisabled?: boolean, onConfirmed?: any => any, onAborted?: any => any, className?: string, children?: React.Node, extraContent?: React.Node, expandButtonLabel?: string, hideButtonLabel?: string, title?: string | React.Node, }; export function Modal(props: ModalProps) { const { children, type = 'alert', confirmButtonLabel = __('OK'), confirmButtonDisabled = false, onConfirmed, abortButtonLabel = __('Cancel'), abortButtonDisabled = false, onAborted, className, title, ...modalProps } = props; const isMobile = useIsMobile(); return ( {title && {title}} {type === 'card' && ( )} {children} {type === 'custom' || type === 'card' ? null : ( // custom modals define their own buttons {type === 'confirm' ? ( ) : null} )} ); } type State = { expanded: boolean, }; export class ExpandableModal extends React.PureComponent { static defaultProps = { confirmButtonLabel: __('OK'), expandButtonLabel: __('Show More...'), hideButtonLabel: __('Show Less'), }; constructor(props: ModalProps) { super(props); this.state = { expanded: false, }; } toggleExpanded() { this.setState({ expanded: !this.state.expanded, }); } render() { return ( {this.props.children} {this.state.expanded ? {this.props.extraContent} : null} { this.toggleExpanded(); }} /> ); } } export default Modal;