PureButtons
authorTomas Zeman <tzeman@volny.cz>
Thu, 14 Dec 2017 14:25:16 +0100
changeset 7 bc895714797d
parent 6 18bd07e3803e
child 8 d1da6ba32afa
PureButtons
build.sbt
shared/src/main/scala/purecss/generic/PureButtons.scala
shared/src/main/scala/purecss/generic/PureCssGeneric.scala
--- a/build.sbt	Thu Dec 14 13:27:36 2017 +0100
+++ b/build.sbt	Thu Dec 14 14:25:16 2017 +0100
@@ -41,7 +41,13 @@
   buildInfoPackage := "purecss.build",
   buildInfoOptions ++= Seq(BuildInfoOption.ToMap, BuildInfoOption.ToJson)
 
-).jvmSettings().jsSettings()
+).jvmSettings(
+  initialCommands in console := """
+     import scalatags.Text.all._
+     import purecss.text.PureCss._
+     
+  """
+).jsSettings()
 
 lazy val purecssJS = purecss.js
 lazy val purecssJVM = purecss.jvm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shared/src/main/scala/purecss/generic/PureButtons.scala	Thu Dec 14 14:25:16 2017 +0100
@@ -0,0 +1,52 @@
+/*
+ * Copyright 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package purecss.generic
+
+import scala.language.{implicitConversions, postfixOps}
+
+abstract class PureButtons[Builder, Output <: FragT, FragT](
+  val pureCss: PureCssGeneric[Builder, Output, FragT]) {
+
+  type B = Button
+  type C = PureCls[Builder, Output, FragT]
+
+  case class Button(
+    role: Option[C] = None,
+    state: Option[C] = None,
+    level: Option[C] = None,
+    size: Option[C] = None
+  ) {
+    def primary: B = copy(role = Some(pureCss.pure_button_primary))
+    def secondary: B = copy(role = Some(pureCss.pure_button_secondary))
+
+    def active: B = copy(state = Some(pureCss.pure_button_active))
+    def disabled: B = copy(state = Some(pureCss.pure_button_disabled))
+
+    def success: B = copy(level = Some(pureCss.pure_button_success))
+    def warning: B = copy(level = Some(pureCss.pure_button_warning))
+    def error: B = copy(level = Some(pureCss.pure_button_error))
+
+    def small: B = copy(size = Some(pureCss.pure_button_small))
+    def large: B = copy(size = Some(pureCss.pure_button_large))
+
+    def toCls: C =
+      pureCss.pure_button.copy(chain = (role ++ state ++ level ++ size) toList)
+
+    def & (next: C): C = toCls & next
+    def & (next: String): C = toCls & next
+  }
+
+}
--- a/shared/src/main/scala/purecss/generic/PureCssGeneric.scala	Thu Dec 14 13:27:36 2017 +0100
+++ b/shared/src/main/scala/purecss/generic/PureCssGeneric.scala	Thu Dec 14 14:25:16 2017 +0100
@@ -23,14 +23,17 @@
 
   import bun.all._
 
+  type A = PureAlert[Builder, Output, FragT]
+  type B = PureButtons[Builder, Output, FragT]
   type C = PureCls[Builder, Output, FragT]
-  type A = PureAlert[Builder, Output, FragT]
 
   implicit val bundle: Bundle[Builder, Output, FragT] = bun
 
   implicit def cls2mod(v: C): Modifier = v()
   implicit def alert2cls(a: A#Alert): C = a.toCls
   implicit def alert2mod(a: A#Alert): Modifier = a.toCls.apply()
+  implicit def btn2cls(b: B#Button): C = b.toCls
+  implicit def btn2mod(b: B#Button): Modifier = b.toCls.apply()
 
   private def pc(c: String): C = PureCls(c)
 
@@ -165,6 +168,9 @@
   val pure_button_large: C = pc("pure-button-large")
   val pure_button_group: C = pc("pure-button-group")
 
+  object pureButtons extends PureButtons(this)
+  val pureButton: B#Button = pureButtons.Button()
+
   // menus
   val pure_menu: C = pc("pure-menu")
   val pure_menu_heading: C = pc("pure-menu-heading")