Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #168 from cquiroz/updates
Browse files Browse the repository at this point in the history
Library updates and add ModalDimmer
  • Loading branch information
cquiroz authored Aug 15, 2020
2 parents dad4827 + f2f9fb1 commit 2790601
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 15 deletions.
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
val reactJS = "16.13.1"
val scalaJsReact = "1.7.4"
val scalaJsReact = "1.7.5"
val FUILess = "2.8.6"
val reactSUI = "1.1.1"
val reactSUI = "1.2.0"
val Toasts = "0.6.5"

parallelExecution in (ThisBuild, Test) := false
Expand Down Expand Up @@ -142,7 +142,7 @@ lazy val facade =
"com.github.japgolly.scalajs-react" %%% "core" % scalaJsReact,
"com.github.japgolly.scalajs-react" %%% "extra" % scalaJsReact,
"com.github.japgolly.scalajs-react" %%% "test" % scalaJsReact % Test,
"io.github.cquiroz.react" %%% "common" % "0.9.6",
"io.github.cquiroz.react" %%% "common" % "0.9.7",
"com.lihaoyi" %%% "utest" % "0.7.4" % Test,
"org.typelevel" %%% "cats-core" % "2.1.1" % Test
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final case class Confirm(
confirmButton: js.UndefOr[ShorthandS[Button]] = js.undefined,
content: js.UndefOr[ShorthandS[ModalContent]] = js.undefined,
defaultOpen: js.UndefOr[Boolean] = js.undefined,
dimmer: js.UndefOr[ModalDimmer] = js.undefined,
dimmer: js.UndefOr[Dimmer] = js.undefined,
eventPool: js.UndefOr[String] = js.undefined,
header: js.UndefOr[ShorthandS[ModalHeader]] = js.undefined,
onActionClickE: js.UndefOr[Modal.OnActionClick] = js.undefined,
Expand Down Expand Up @@ -136,7 +136,7 @@ object Confirm {
confirmButton: js.UndefOr[ShorthandS[Button]] = js.undefined,
content: js.UndefOr[ShorthandS[ModalContent]] = js.undefined,
defaultOpen: js.UndefOr[Boolean] = js.undefined,
dimmer: js.UndefOr[ModalDimmer] = js.undefined,
dimmer: js.UndefOr[Dimmer] = js.undefined,
eventPool: js.UndefOr[String] = js.undefined,
header: js.UndefOr[ShorthandS[ModalHeader]] = js.undefined,
onActionClickE: js.UndefOr[Modal.OnActionClick] = js.undefined,
Expand Down
16 changes: 12 additions & 4 deletions facade/src/main/scala/react/semanticui/modules/modal/Modal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final case class Modal(
closeOnDocumentClick: js.UndefOr[Boolean] = js.undefined,
content: js.UndefOr[ShorthandS[ModalContent]] = js.undefined,
defaultOpen: js.UndefOr[Boolean] = js.undefined,
dimmer: js.UndefOr[ModalDimmer] = js.undefined,
dimmer: js.UndefOr[Dimmer | ModalDimmer] = js.undefined,
eventPool: js.UndefOr[String] = js.undefined,
header: js.UndefOr[ShorthandS[ModalHeader]] = js.undefined,
onActionClickE: js.UndefOr[Modal.OnActionClick] = js.undefined,
Expand Down Expand Up @@ -108,7 +108,9 @@ object Modal {
var defaultOpen: js.UndefOr[Boolean] = js.native

/** A modal can appear in a dimmer. */
var dimmer: js.UndefOr[Boolean | String] = js.native
var dimmer
: js.UndefOr[Boolean | String | suiraw.SemanticShorthandItemS[ModalDimmer.ModalDimmerProps]] =
js.native

/** Event pool namespace that is used to handle component events */
var eventPool: js.UndefOr[String] = js.native
Expand Down Expand Up @@ -215,7 +217,7 @@ object Modal {
closeOnDocumentClick: js.UndefOr[Boolean] = js.undefined,
content: js.UndefOr[ShorthandS[ModalContent]] = js.undefined,
defaultOpen: js.UndefOr[Boolean] = js.undefined,
dimmer: js.UndefOr[ModalDimmer] = js.undefined,
dimmer: js.UndefOr[Dimmer | ModalDimmer] = js.undefined,
eventPool: js.UndefOr[String] = js.undefined,
header: js.UndefOr[ShorthandS[ModalHeader]] = js.undefined,
onActionClickE: js.UndefOr[OnActionClick] = js.undefined,
Expand All @@ -242,7 +244,13 @@ object Modal {
closeOnDocumentClick.foreach(v => p.closeOnDocumentClick = v)
content.toJs.foreach(v => p.content = v)
defaultOpen.foreach(v => p.defaultOpen = v)
dimmer.toJs.foreach(v => p.dimmer = v)
dimmer.foreach { v =>
(v: Any) match {
case x: Dimmer => x.toJs
case x => x
}
}

eventPool.foreach(v => p.eventPool = v)
header.toJs.foreach(v => p.header = v)
(onActionClickE, onActionClick).toJs.foreach(v => p.onActionClick = v)
Expand Down
101 changes: 101 additions & 0 deletions facade/src/main/scala/react/semanticui/modules/modal/ModalDimmer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package react.semanticui.modules.modal

import scala.scalajs.js
import js.annotation._
import japgolly.scalajs.react._
import japgolly.scalajs.react.vdom.VdomNode
import japgolly.scalajs.react.raw.React
import react.common._
import react.semanticui._
import react.semanticui.{ raw => suiraw }
import japgolly.scalajs.react.vdom.TagMod

final case class ModalDimmer(
as: js.UndefOr[AsC] = js.undefined,
blurring: js.UndefOr[Boolean] = js.undefined,
className: js.UndefOr[String] = js.undefined,
clazz: js.UndefOr[Css] = js.undefined,
centered: js.UndefOr[Boolean] = js.undefined,
content: js.UndefOr[ShorthandS[VdomNode]] = js.undefined,
inverted: js.UndefOr[Boolean] = js.undefined,
scrolling: js.UndefOr[Boolean] = js.undefined,
override val modifiers: Seq[TagMod] = Seq.empty
) extends GenericFnComponentPAC[ModalDimmer.ModalDimmerProps, ModalDimmer] {
override protected def cprops = ModalDimmer.props(this)
override protected val component = ModalDimmer.component
override def addModifiers(modifiers: Seq[TagMod]) = copy(modifiers = this.modifiers ++ modifiers)
}

object ModalDimmer {
@js.native
@JSImport("semantic-ui-react", "ModalDimmer")
object RawComponent extends js.Function1[js.Any, js.Any] {
def apply(i: js.Any): js.Any = js.native
}

@js.native
trait ModalDimmerProps extends js.Object {
@JSBracketAccess
def apply(key: String): js.Any = js.native

@JSBracketAccess
def update(key: String, v: js.Any): Unit = js.native

/** An element type to render as (string or function). */
var as: js.UndefOr[AsT] = js.native

/** A dimmer can be blurred. */
var blurring: js.UndefOr[Boolean] = js.native

/** Primary content. */
var children: js.UndefOr[React.Node] = js.native

/** Additional classes. */
var className: js.UndefOr[String] = js.native

/** A dimmer can center its contents in the viewport. */
var centered: js.UndefOr[Boolean] = js.native

/** Shorthand for primary content. */
var content: js.UndefOr[suiraw.SemanticShorthandContent] = js.native

/** A dimmer can be inverted. */
var inverted: js.UndefOr[Boolean] = js.native

/** The node where the modal should mount. Defaults to document.body. */
// mountNode?: any

/** A dimmer can make body scrollable. */
var scrolling: js.UndefOr[Boolean] = js.native
}

def props(q: ModalDimmer): ModalDimmerProps =
rawprops(q.as, q.blurring, q.className, q.clazz, q.centered, q.content, q.inverted, q.scrolling)

def rawprops(
as: js.UndefOr[AsC] = js.undefined,
blurring: js.UndefOr[Boolean] = js.undefined,
className: js.UndefOr[String] = js.undefined,
clazz: js.UndefOr[Css] = js.undefined,
centered: js.UndefOr[Boolean] = js.undefined,
content: js.UndefOr[ShorthandS[VdomNode]] = js.undefined,
inverted: js.UndefOr[Boolean] = js.undefined,
scrolling: js.UndefOr[Boolean] = js.undefined
): ModalDimmerProps = {
val p = as.toJsObject[ModalDimmerProps]
as.toJs.foreach(v => p.as = v)
blurring.foreach(v => p.blurring = v)
(className, clazz).toJs.foreach(v => p.className = v)
centered.foreach(v => p.centered = v)
content.toJs.foreach(v => p.content = v)
inverted.foreach(v => p.inverted = v)
scrolling.foreach(v => p.scrolling = v)
p
}

private val component =
JsFnComponent[ModalDimmerProps, Children.Varargs](RawComponent)

def apply(modifiers: TagMod*): ModalDimmer =
new ModalDimmer(modifiers = modifiers)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import react.common.EnumValue
import react.common.EnumValueB

package modal {
sealed trait ModalDimmer extends Product with Serializable
object ModalDimmer {
implicit val enum: EnumValueB[ModalDimmer] = EnumValueB.toLowerCaseStringT(Dimmer)
sealed trait Dimmer extends Product with Serializable
object Dimmer {
implicit val enum: EnumValueB[Dimmer] = EnumValueB.toLowerCaseStringT(Dimmer)

case object Dimmer extends ModalDimmer
case object Blurring extends ModalDimmer
case object Inverted extends ModalDimmer
case object Dimmer extends Dimmer
case object Blurring extends Dimmer
case object Inverted extends Dimmer
}

sealed trait ModalSize extends Product with Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package react.semanticui.modules.modal

import utest._
import japgolly.scalajs.react.test._
import japgolly.scalajs.react.vdom.html_<^._

object ModalDimmerTests extends TestSuite {
val tests = Tests {
test("render") {
val modal = ModalDimmer("Abc")
ReactTestUtils.withNewBodyElement { mountNode =>
modal.renderIntoDOM(mountNode)
assert(
mountNode.innerHTML == """<div class="ui top aligned page modals dimmer transition visible active">Abc</div>"""
)
}
}
}
}

0 comments on commit 2790601

Please sign in to comment.