slinky-styled-components


License

License

MIT
GroupId

GroupId

me.shadaj
ArtifactId

ArtifactId

slinky-styled-components_sjs0.6_2.13
Last Version

Last Version

0.1.0+10-b09028e5
Release Date

Release Date

Type

Type

jar
Description

Description

slinky-styled-components
slinky-styled-components
Project URL

Project URL

https://github.com/shadaj/slinky-styled-components
Project Organization

Project Organization

me.shadaj
Source Code Management

Source Code Management

https://github.com/shadaj/slinky-styled-components.git

Download slinky-styled-components_sjs0.6_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/me.shadaj/slinky-styled-components_sjs0.6_2.13/ -->
<dependency>
    <groupId>me.shadaj</groupId>
    <artifactId>slinky-styled-components_sjs0.6_2.13</artifactId>
    <version>0.1.0+10-b09028e5</version>
</dependency>
// https://jarcasting.com/artifacts/me.shadaj/slinky-styled-components_sjs0.6_2.13/
implementation 'me.shadaj:slinky-styled-components_sjs0.6_2.13:0.1.0+10-b09028e5'
// https://jarcasting.com/artifacts/me.shadaj/slinky-styled-components_sjs0.6_2.13/
implementation ("me.shadaj:slinky-styled-components_sjs0.6_2.13:0.1.0+10-b09028e5")
'me.shadaj:slinky-styled-components_sjs0.6_2.13:jar:0.1.0+10-b09028e5'
<dependency org="me.shadaj" name="slinky-styled-components_sjs0.6_2.13" rev="0.1.0+10-b09028e5">
  <artifact name="slinky-styled-components_sjs0.6_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='me.shadaj', module='slinky-styled-components_sjs0.6_2.13', version='0.1.0+10-b09028e5')
)
libraryDependencies += "me.shadaj" % "slinky-styled-components_sjs0.6_2.13" % "0.1.0+10-b09028e5"
[me.shadaj/slinky-styled-components_sjs0.6_2.13 "0.1.0+10-b09028e5"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.4
org.scala-js : scalajs-library_2.13 jar 0.6.33
me.shadaj : slinky-web_sjs0.6_2.13 jar 0.6.5

test (2)

Group / Artifact Type Version
org.scala-js : scalajs-test-bridge_2.13 jar 0.6.33
org.scalatest : scalatest_sjs0.6_2.13 jar 3.1.4

Project Modules

There are no modules declared in this project.

slinky-styled-components

use styled-components from Slinky apps!

Getting Started

Add the library to your build and styled-components for Webpack bundling:

libraryDependencies += "me.shadaj" %%% "slinky-styled-components" % "0.1.0"

npmDependencies += "styled-components" -> "3.4.10"

Creating Components

Let's see how to create styled components with a simple example of a colored button:

import slinky.styledcomponents._

val styledButton = styled.button(
  css"""
    color: green;
  """
)

We can then use this in our app just like a regular component:

div(
  styledButton(id := "my-button")(
    "Hello World!"
  )
)

If we want to calculate styles based on some dynamic data, we can use props:

case class StyledButtonProps(color: String)
val styledButtonDynamicData = styled.button(
  css"""
    color: ${p: Props => p.color}
  """
)

div(
  styledButtonDynamicData(StyledButtonProps("pink"))(
    "Hello, this button is pink!"
  )
)

Extending Components

You can extend existing components with additional styles. For example, you could extend a styled button with more CSS:

case class Props(color: String)

val baseStyled = styled.button(
  css"""
    border-radius: 3px;
    color: ${p: Props => p.color};
  """
)

val extendedStyled = styled(baseStyled)(
  css"""
    font-size: 10px;
    background-color: ${p: Props => p.color}
  """
)

You can also extend Slinky components to assign them more styles, with the requirement that the component must take a className prop.

@react class IntHeaderComponent extends StatelessComponent {
  case class Props(number: Int, className: String = "")

  override def render(): ReactElement = {
    h1(className := props.className)(props.number.toString)
  }
}

// ...

val styledIntHeader = styled(IntHeaderComponent).apply[IntHeaderComponent.Props](
  css"""
    color: green;
  """
)

// ...

styledIntHeader(IntHeaderComponent.Props(123))

CSS Animations

The key feature of styled-components is the ability to use all CSS features, even ones like CSS animations. To build an animation that uses key frames, you can use the keyframes string interpolator.

val fadeIn = keyframes"""
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
"""

val fadedButton = styled.button(
  css"""
    animation: 1s $fadeIn ease-out;
  """
)

CSS Fragments

You can store css interpolations as variables and reuse them across multiple components. For example, you can use a shared color styling fragment.

val colorCSS = css"color: pink"
val styledButton = styled.button(
  css"""
    border-radius: 3px;
    $colorCSS
  """
)

val styledDiv = styled.div(
  css"""
    border-radius: 10px;
    $colorCSS
  """
)

Versions

Version
0.1.0+10-b09028e5
0.1.0+9-38941d55
0.1.0+8-4dc92624
0.1.0+7-5ecee8bc
0.1.0+6-600b43cb