aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/reading/component/widget/Popup.scala
blob: f47bc1c7a46836813708bfe8019c764f12bce649 (plain)
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
package reading.component.widget

import org.scalajs.dom

import rx._
import Ctx.Owner.Unsafe._

import scalatags.JsDom.all._
import scalacss.Defaults._
import scalacss.ScalatagsCss._

import reading.component.widget.style.{ Popup => PopupStyle }
import reading.component.style.{ Color => C }
import reading.utils.{ RxAttr }

object Popup {
  def apply(onClose: => Unit)(content: HtmlTag): HtmlTag = {
    dom.document.body.style.overflowY = "hidden"

    div(
      PopupStyle.render,
      PopupStyle.popup,

      div(
        PopupStyle.curtain,
        RxAttr(onclick, Rx(() => close(onClose)))
      ),

      div(
        PopupStyle.content,
        content,
        button(
          PopupStyle.cross,
          RxAttr(onclick, Rx(() => close(onClose))),
          Cross(20.px, C.stiletto.value)
        )
      )
    )
  }

  private def close(onClose: => Unit): Unit = {
    dom.document.body.style.overflowY = "scroll"
    onClose
  }
}