uibTabs: tab dsl
authorTomas Zeman <tzeman@volny.cz>
Thu, 22 Jun 2017 21:19:39 +0200
changeset 41 33ec811608b2
parent 40 1ff4ef98bbfb
child 42 e77d46515a8f
uibTabs: tab dsl
shared/src/main/scala/twbsTags.scala
--- a/shared/src/main/scala/twbsTags.scala	Tue Jun 13 15:51:23 2017 +0200
+++ b/shared/src/main/scala/twbsTags.scala	Thu Jun 22 21:19:39 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015-2016 Tomas Zeman <tzeman@volny.cz>
+ * Copyright 2015-2017 Tomas Zeman <tzeman@volny.cz>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
  */
 package net.tz.ngtags
 
+import scala.language.implicitConversions
 import scalatags.Text.all._
 
 @deprecated("Use uibAccordion", "0.5")
@@ -64,7 +65,25 @@
 }
 
 object uibTabs {
-  val tabset = tag("uib-tabset")
+
+  implicit def ts2tag(x: Tabset): ConcreteHtmlTag[String] = x()
+
+  case class Tab(heading: Seq[Modifier], content: Seq[Modifier])
+
+  case class Tabset(activeE: String, _tabs: Seq[Tab] = Nil, _justified: Option[Boolean] = None) {
+    def justified(b: Boolean): Tabset = copy(_justified = Some(b))
+    def justified: Tabset = justified(true)
+    def tab(heading: Modifier*) = new {
+      def content(xs: Modifier*): Tabset = copy(_tabs = _tabs :+ Tab(heading, xs))
+    }
+    def emptyTab(heading: Modifier*): Tabset = tab(heading).content()
+
+    def apply(xs: Modifier*) =
+      tag("uib-tabset")(attr("active"):=activeE, _justified.map(attr("justified"):=_), xs,
+        _tabs.map {t => tag("uib-tab")(tag("uib-tab-heading")(t.heading), t.content)})
+  }
+
+  def tabset(activeExpr: String) = Tabset(activeExpr)
   val tab = tag("uib-tab")
   val tabHeading = tag("uib-tab-heading")
   val heading = attr("heading")