Skip to content

Commit

Permalink
Test: Fix example to match usage of StyleSetter[String] in laminar v18
Browse files Browse the repository at this point in the history
  • Loading branch information
raquo committed Feb 18, 2025
1 parent 8988f53 commit 7800348
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait StyleProps {

protected type DSP[V] = DerivedStyleProp[V]

protected type SS = StyleSetter[_]
protected type SS = StyleSetter[String]


def styleProp[V](name: String): StyleProp[V] = new StyleProp(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import com.thirdparty.setters.StyleSetter

trait Auto[V] { this: StyleProp[V] =>

lazy val auto: StyleSetter[V] = this := "auto"
lazy val auto: StyleSetter[String] = this := "auto"

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ trait GlobalKeywords[V] { this: StyleProp[V] =>
* The initial CSS keyword applies the initial (or default) value of a
* property to an element.
*/
lazy val initial: StyleSetter[V] = this := "initial"
lazy val initial: StyleSetter[String] = this := "initial"

/**
* The inherit CSS keyword causes the element for which it is specified to
* take the computed value of the property from its parent element.
*/
lazy val inherit: StyleSetter[V] = this := "inherit"
lazy val inherit: StyleSetter[String] = this := "inherit"

/**
* The revert CSS keyword reverts the cascaded value of the property from its
* current value to the value the property would have had if no changes had
* been made by the current style origin to the current element.
*/
lazy val revert: StyleSetter[V] = this := "revert"
lazy val revert: StyleSetter[String] = this := "revert"

/**
* The unset CSS keyword resets a property to its inherited value if the
Expand All @@ -36,6 +36,6 @@ trait GlobalKeywords[V] { this: StyleProp[V] =>
* when the property is an inherited property, and like the initial keyword in
* the second case, when the property is a non-inherited property.
*/
lazy val unset: StyleSetter[V] = this := "unset"
lazy val unset: StyleSetter[String] = this := "unset"

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import com.thirdparty.setters.StyleSetter

trait None[V] { this: StyleProp[V] =>

lazy val none: StyleSetter[V] = this := "none"
lazy val none: StyleSetter[String] = this := "none"

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import com.thirdparty.setters.StyleSetter

trait Normal[V] { this: StyleProp[V] =>

lazy val normal: StyleSetter[V] = this := "normal"
lazy val normal: StyleSetter[String] = this := "normal"

}
25 changes: 14 additions & 11 deletions js/src/test/scala/com/thirdparty/keys/StyleProp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ import com.thirdparty.defs.styles.traits.GlobalKeywords
import com.thirdparty.setters.StyleSetter

import scala.language.implicitConversions
import scala.scalajs.js.|

case class StyleProp[V](
val domName: String
) extends DerivedStyleBuilder[StyleSetter[_], DerivedStyleProp] with GlobalKeywords[V] {
) extends DerivedStyleBuilder[StyleSetter[String], DerivedStyleProp] with GlobalKeywords[V] {

def := (value: V | String): StyleSetter[V] = StyleSetter(this, value.toString)
def := (value: V): StyleSetter[V] = StyleSetter(this, value.toString)

def := (value: String): StyleSetter[V] = StyleSetter(this, value)
// def := (value: V | String): StyleSetter[V] = StyleSetter(this, value.toString)

override protected def styleSetter(value: String): StyleSetter[_] = this := value
// def := (value: String): StyleSetter[V] = StyleSetter(this, value)

override protected def styleSetter(value: String): StyleSetter[String] = this := value

override protected def derivedStyle[A](encode: A => String): DerivedStyleProp[A] = {
new DerivedStyleProp[A](this, encode)
}
}

// object StyleProp {
//
// implicit def stylePropToStringStyleProp[V](p: StyleProp[V]): StyleProp[String] = {
// p.asInstanceOf[StyleProp[String]]
// }
// }
object StyleProp {

// In CSS, every style prop can be set to a string value, and this allows it.
// You need to make sure that your StyleProp implementation is safe with such a casting implicit conversion. See Laminar v18+ for example.
implicit def stylePropToStringStyleProp[V](p: StyleProp[V]): StyleProp[String] = {
p.asInstanceOf[StyleProp[String]]
}
}
4 changes: 2 additions & 2 deletions jvm/src/test/scala/com/raquo/domtypes/GeneratorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class GeneratorSpec extends AnyFunSpec with Matchers {
traitName = traitName,
keyKind = "StyleProp",
keyKindAlias = "StyleProp",
setterType = "StyleSetter[_]",
setterType = "StyleSetter[String]",
setterTypeAlias = "SS",
derivedKeyKind = "DerivedStyleProp",
derivedKeyKindAlias = "DSP",
Expand Down Expand Up @@ -340,7 +340,7 @@ class GeneratorSpec extends AnyFunSpec with Matchers {
traitExtendsFallbackTypeParam = Some("String"),
extendsUnitTraits = styleTrait.extendsUnits,
propKind = "StyleProp",
keywordType = keywordType,
keywordType = "StyleSetter[String]",
derivedKeyKind = "DerivedStyleProp",
lengthUnitsNumType = None, //Some("Int | Double"),
defType = LazyVal,
Expand Down

0 comments on commit 7800348

Please sign in to comment.