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 #99 from cquiroz/as-form
Browse files Browse the repository at this point in the history
Support as for Form and Grid
  • Loading branch information
cquiroz authored Mar 12, 2020
2 parents b2f8bcd + ac0534e commit cc46a1d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ object Form {
p
}

val Default: Form = Form()

val defaultProps: FormProps = props(Default)

private val component =
JsComponent[FormProps, Children.Varargs, Null](RawComponent)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ object Grid {
var verticalAlign: js.UndefOr[suiraw.SemanticVERTICALALIGNMENTS] = js.native
}

val Default: Grid = Grid()

val defaultProps: GridProps = props(Default)

def props(q: Grid): GridProps =
rawprops(
q.as,
Expand Down
21 changes: 17 additions & 4 deletions facade/src/main/scala/react/semanticui/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import react.common.GenericComponentPC
import react.common.GenericComponentP

package semanticui {
sealed trait As {
sealed trait As extends Product with Serializable {
type P <: js.Object // props
val props: P
}

object As {
import elements.segment.{ Segment => SUISegment }
import collections.menu.{ Menu => SUIMenu }
import collections.grid.{ Grid => SUIGrid }
import collections.form.{ Form => SUIForm }
import modules.sidebar.{ SidebarPushable => SUISidebarPushable }
import modules.sidebar.{ SidebarPusher => SUISidebarPusher }
import modules.checkbox.{ Checkbox => SUICheckbox }
Expand Down Expand Up @@ -49,6 +51,14 @@ package semanticui {
override type P = SUIMenu.MenuProps
override val props = SUIMenu.props(menu)
}
final case class Grid(grid: SUIGrid = SUIGrid.Default) extends As {
override type P = SUIGrid.GridProps
override val props = SUIGrid.props(grid)
}
final case class Form(form: SUIForm = SUIForm.Default) extends As {
override type P = SUIForm.FormProps
override val props = SUIForm.props(form)
}
final case class Image(image: SUIImage = SUIImage.Default) extends As {
override type P = SUIImage.ImageProps
override val props = SUIImage.props(image)
Expand Down Expand Up @@ -78,6 +88,8 @@ package semanticui {
case SidebarPusher(_) => SUISidebarPusher.RawComponent
case Header(_) => SUIHeader.RawComponent
case Menu(_) => SUIMenu.RawComponent
case Grid(_) => SUIGrid.RawComponent
case Form(_) => SUIForm.RawComponent
case Image(_) => SUIImage.RawComponent
case Divider(_) => SUIDivider.RawComponent
case Checkbox(_) => SUICheckbox.RawComponent
Expand Down Expand Up @@ -194,9 +206,10 @@ package object semanticui
}
}

type AsFn = js.Function1[js.Any, js.Any]
type AsT = String | AsFn
type AsC = String | As
type AsFn = js.Function1[js.Any, js.Any]
type AsObj = js.Object
type AsT = String | AsFn | AsObj
type AsC = String | As

implicit class AsCUndef[T](val c: js.UndefOr[AsC]) extends AnyVal {
def toJs: js.UndefOr[AsT] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import japgolly.scalajs.react.test._
import japgolly.scalajs.react.vdom.html_<^._
import react.semanticui.elements.icon.Icon
import react.semanticui.elements.label.Label
import react.semanticui.collections.form.Form
import react.semanticui.colors._
import react.semanticui.sizes._
import react.semanticui._
Expand All @@ -23,6 +24,14 @@ object ButtonTests extends TestSuite {
assert(m.outerHtmlScrubbed() == """<a class="ui button" role="button"></a>""")
}
}
test("renderAsForm") {
val button = Button(as = As.Form(Form(error = true)))
ReactTestUtils.withRenderedIntoDocument(button) { m =>
assert(
m.outerHtmlScrubbed() == """<form role="button" class="ui error form ui button"></form>"""
)
}
}
test("attached") {
val button = Button(attached = ButtonAttached.Top)
ReactTestUtils.withRenderedIntoDocument(button) { m =>
Expand Down

0 comments on commit cc46a1d

Please sign in to comment.