Structured composition: alerts, buttons
authorTomas Zeman <tzeman@volny.cz>
Thu, 14 Dec 2017 14:48:43 +0100
changeset 8 d1da6ba32afa
parent 7 bc895714797d
child 9 ee8565f13df7
Structured composition: alerts, buttons
js/src/main/scala/purecss/jsdom/PureAlert.scala
shared/src/main/scala/purecss/generic/Component.scala
shared/src/main/scala/purecss/generic/PureAlert.scala
shared/src/main/scala/purecss/generic/PureAlerts.scala
shared/src/main/scala/purecss/generic/PureButtons.scala
shared/src/main/scala/purecss/generic/PureCssGeneric.scala
shared/src/main/scala/purecss/text/PureAlert.scala
--- a/js/src/main/scala/purecss/jsdom/PureAlert.scala	Thu Dec 14 14:25:16 2017 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-/*
- * 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.jsdom
-
-object PureAlert extends purecss.generic.PureAlert(PureCss)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shared/src/main/scala/purecss/generic/Component.scala	Thu Dec 14 14:48:43 2017 +0100
@@ -0,0 +1,31 @@
+/*
+ * 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
+import scalatags.generic.Bundle
+
+trait Component[Builder, Output <: FragT, FragT] {
+  implicit val bundle: Bundle[Builder, Output, FragT]
+
+  type C = PureCls[Builder, Output, FragT]
+
+  import bundle.all._
+
+  implicit def cls2mod(v: C): Modifier = v()
+
+  protected def pc(c: String): C = PureCls(c)
+}
--- a/shared/src/main/scala/purecss/generic/PureAlert.scala	Thu Dec 14 14:25:16 2017 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/*
- * 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
-
-abstract class PureAlert[Builder, Output <: FragT, FragT](
-  val pureCss: PureCssGeneric[Builder, Output, FragT]) {
-
-  type C = PureCls[Builder, Output, FragT]
-
-  val primary: C = pureCss.pure_alert
-
-  sealed abstract class Alert(val secondary: C) {
-    def toCls: C = PureCls(primary.css, secondary :: Nil)
-  }
-
-  case object Error extends Alert(pureCss.pure_alert_error)
-  case object Warning extends Alert(pureCss.pure_alert_warning)
-  case object Success extends Alert(pureCss.pure_alert_success)
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shared/src/main/scala/purecss/generic/PureAlerts.scala	Thu Dec 14 14:48:43 2017 +0100
@@ -0,0 +1,40 @@
+/*
+ * 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
+
+trait PureAlerts[B, O <: F, F] extends Component[B, O, F] {
+  import bundle.all._
+
+  val pure_alert: C = pc("pure-alert")
+  val pure_alert_error: C = pc("pure-alert-error")
+  val pure_alert_warning: C = pc("pure-alert-warning")
+  val pure_alert_success: C = pc("pure-alert-success")
+
+  implicit def alert2cls(a: Alert): C = a.toCls
+  implicit def alert2mod(a: Alert): Modifier = a.toCls.apply()
+
+  sealed abstract class Alert(val secondary: C) {
+    def toCls: C = pure_alert & secondary
+  }
+
+  object Alert {
+    case object Error extends Alert(pure_alert_error)
+    case object Warning extends Alert(pure_alert_warning)
+    case object Success extends Alert(pure_alert_success)
+  }
+}
--- a/shared/src/main/scala/purecss/generic/PureButtons.scala	Thu Dec 14 14:25:16 2017 +0100
+++ b/shared/src/main/scala/purecss/generic/PureButtons.scala	Thu Dec 14 14:48:43 2017 +0100
@@ -17,33 +17,43 @@
 
 import scala.language.{implicitConversions, postfixOps}
 
-abstract class PureButtons[Builder, Output <: FragT, FragT](
-  val pureCss: PureCssGeneric[Builder, Output, FragT]) {
+trait PureButtons[B, O <: F, F] extends Component[B, O ,F] {
+  import bundle.all._
 
-  type B = Button
-  type C = PureCls[Builder, Output, FragT]
+  val pure_button: C = pc("pure-button")
+  val pure_button_disabled: C = pc("pure-button-disabled")
+  val pure_button_active: C = pc("pure-button-active")
+  val pure_button_primary: C = pc("pure-button-primary")
+  val pure_button_secondary: C = pc("pure-button-secondary")
+  val pure_button_success: C = pc("pure-button-success")
+  val pure_button_error: C = pc("pure-button-error")
+  val pure_button_warning: C = pc("pure-button-warning")
+  val pure_button_small: C = pc("pure-button-small")
+  val pure_button_large: C = pc("pure-button-large")
+  val pure_button_group: C = pc("pure-button-group")
 
-  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))
+  implicit def btn2cls(b: Button): C = b.toCls
+  implicit def btn2mod(b: Button): Modifier = b.toCls.apply()
+
+  case class Button(role: Option[C] = None, state: Option[C] = None,
+    level: Option[C] = None, size: Option[C] = None) {
+    type B = Button
+
+    def primary: B = copy(role = Some(pure_button_primary))
+    def secondary: B = copy(role = Some(pure_button_secondary))
 
-    def active: B = copy(state = Some(pureCss.pure_button_active))
-    def disabled: B = copy(state = Some(pureCss.pure_button_disabled))
+    def active: B = copy(state = Some(pure_button_active))
+    def disabled: B = copy(state = Some(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 success: B = copy(level = Some(pure_button_success))
+    def warning: B = copy(level = Some(pure_button_warning))
+    def error: B = copy(level = Some(pure_button_error))
 
-    def small: B = copy(size = Some(pureCss.pure_button_small))
-    def large: B = copy(size = Some(pureCss.pure_button_large))
+    def small: B = copy(size = Some(pure_button_small))
+    def large: B = copy(size = Some(pure_button_large))
 
     def toCls: C =
-      pureCss.pure_button.copy(chain = (role ++ state ++ level ++ size) toList)
+      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 14:25:16 2017 +0100
+++ b/shared/src/main/scala/purecss/generic/PureCssGeneric.scala	Thu Dec 14 14:48:43 2017 +0100
@@ -19,24 +19,12 @@
 import scalatags.generic.Bundle
 
 class PureCssGeneric[Builder, Output <: FragT, FragT](
-  val bun: Bundle[Builder, Output, FragT]) {
-
-  import bun.all._
-
-  type A = PureAlert[Builder, Output, FragT]
-  type B = PureButtons[Builder, Output, FragT]
-  type C = PureCls[Builder, Output, FragT]
+  bun: Bundle[Builder, Output, FragT]) extends
+  PureButtons[Builder, Output, FragT] with
+  PureAlerts[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)
-
   // grid
   val pure_g: C = pc("pure-g")
   val pure_u_1: C = pc("pure-u-1")
@@ -97,10 +85,6 @@
   val pure_table_striped: C = pc("pure-table-striped")
 
   // alerts
-  val pure_alert: C = pc("pure-alert")
-  val pure_alert_error: C = pc("pure-alert-error")
-  val pure_alert_warning: C = pc("pure-alert-warning")
-  val pure_alert_success: C = pc("pure-alert-success")
 
   // forms
   val pure_form: C = pc("pure-form")
@@ -155,21 +139,7 @@
   val pure_checkbox: C = pc("pure-checkbox")
   val pure_radio: C = pc("pure-radio")
 
-  // buttons
-  val pure_button: C = pc("pure-button")
-  val pure_button_disabled: C = pc("pure-button-disabled")
-  val pure_button_active: C = pc("pure-button-active")
-  val pure_button_primary: C = pc("pure-button-primary")
-  val pure_button_secondary: C = pc("pure-button-secondary")
-  val pure_button_success: C = pc("pure-button-success")
-  val pure_button_error: C = pc("pure-button-error")
-  val pure_button_warning: C = pc("pure-button-warning")
-  val pure_button_small: C = pc("pure-button-small")
-  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()
+  val pureButton: Button = Button()
 
   // menus
   val pure_menu: C = pc("pure-menu")
@@ -180,7 +150,7 @@
   val pure_menu_link: C = pc("pure-menu-link")
   val pure_menu_selected: C = pc("pure-menu-selected")
   val pure_menu_disabled: C = pc("pure-menu-disabled")
-  val pure_menu_allow_hower: C = pc("pure-menu-allow-hover")
+  val pure_menu_allow_hover: C = pc("pure-menu-allow-hover")
   val pure_menu_has_children: C = pc("pure-menu-has-children")
   val pure_menu_scrollable: C = pc("pure-menu-scrollable")
 
--- a/shared/src/main/scala/purecss/text/PureAlert.scala	Thu Dec 14 14:25:16 2017 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-/*
- * 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.text
-
-object PureAlert extends purecss.generic.PureAlert(PureCss)