All files / ts/components/modals modal.tsx

100% Statements 15/15
100% Branches 10/10
100% Functions 2/2
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 6820x 20x 20x                                                         20x 20x 24x 16x 24x 8x                                 8x                     20x   20x  
import * as classNames from 'classnames';
import * as React from 'react';
import { HTMLProps, PureComponent } from 'react';
import { ComponentProps } from '../../types';
 
export interface ModalProps extends ComponentProps, HTMLProps<HTMLElement> {
  /**
   * Allows the `ModalBody` to be scrolled, rather than page.
   */
  scrollable?: boolean;
  /**
   * Reduced size `Modal` for alerts.
   */
  small?: boolean;
  /**
   * Fill a larger area of the screen equal to the `Container`.
   */
  large?: boolean;
  /**
   * Fill the entire screen.
   */
  fill?: boolean;
  /**
   * Callback to trigger when the user clicks outside of the `Modal`.
   */
  onClickOutside(event: React.MouseEvent<HTMLDivElement>): void;
}
 
/**
 * Component used to render a modal.
 */
export class Modal extends PureComponent<ModalProps, {}> {
  public render () {
    const {
      className,
      children,
      onClickOutside,
      scrollable,
      small,
      large,
      fill,
      component: Component = 'div',
      ...remainingProps
    } = this.props;
 
    const myClassNames = [
      'modal-position',
      scrollable ? 'scrollable' : null,
      small ? 'small' : null,
      large ? 'large' : null,
      fill ? 'fill' : null,
    ];
 
    return (
      <div>
        <div className="modal-overlay" onClick={onClickOutside} />
        <div {...remainingProps} className={classNames(myClassNames)}>
          <Component className="modal">
            {children}
          </Component>
        </div>
      </div>
    );
  }
}
 
export default Modal;