all files / packages/modal/ Modal.js

0% Statements 0/9
0% Branches 0/4
0% Functions 0/2
0% Lines 0/9
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                                                                                                     
import { Component } from '../../ui'
 
/**
  Modal dialog component
 
  @class
  @component
 
  @prop {String} width 'small', 'medium', 'large' and 'full'
 
  @example
 
  ```js
  var form = $$(Modal, {
    width: 'medium',
    textAlign: 'center'
  });
  ```
*/
class Modal extends Component {
 
  render($$) {
    let el = $$('div').addClass('sc-modal')
 
    // TODO: don't think that this is good enough. Right the modal is closed by any unhandled click.
    // Need to be discussed.
    el.on('click', this._closeModal)
 
    if (this.props.width) {
      el.addClass('sm-width-'+this.props.width)
    }
 
    el.append(
      $$('div').addClass('se-body').append(
        this.props.children
      )
    )
    return el
  }
 
  _closeModal(e) {
    let closeSurfaceClick = e.target.classList.contains('sc-modal')
    if (closeSurfaceClick) {
      this.send('closeModal')
    }
  }
 
}
 
export default Modal