Css

com.alecdorrington.laminarcomponents.Css
object Css

Stylesheets written in Scala, with Laminar's own typed style props: rules for selectors, holding what an element's inline styles cannot, its states (:hover), its parts (::after), and styles for some media alone (@media), with keyframes and font faces besides.

A rule nested in another applies within it, its & standing for the outer rule's selector (else a descendant of it), as in CSS nesting, but each is written out whole, for any browser:

import com.raquo.laminar.api.L.*
import com.alecdorrington.laminarcomponents.Css.{media, rule}

val styles = Stylesheet(
 rule(".card")(
   padding.px(12),
   borderRadius.px(8),
   rule("&:hover")(backgroundColor := "#eef"),
   rule(".card-title")(fontWeight.bold),
   media("(max-width: 600px)")(padding.px(8)),
 ),
)

Import the builders by name, as Laminar has a media of its own.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Css.type

Members list

Type members

Classlikes

sealed trait Block

A rule, at-rule or nesting of rules, that a stylesheet holds.

A rule, at-rule or nesting of rules, that a stylesheet holds.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Conditional
class FontFace
class Keyframes
class Rule
final case class Conditional(prelude: String, parts: Seq[Part]) extends Block

Rules applying only under a condition, as @media and @supports have, or nested in a rule, declarations for its selector under the condition.

Rules applying only under a condition, as @media and @supports have, or nested in a rule, declarations for its selector under the condition.

Value parameters

parts

The rules, and within a rule, declarations.

prelude

The at-rule's keyword and condition, as @media (pointer: coarse).

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Block
class Object
trait Matchable
class Any
Show all
final case class FontFace(descriptors: Seq[Declaration]) extends Block

A font face.

A font face.

Value parameters

descriptors

Its descriptors, as fontFamily := "Caveat" and CssProps.fontSource.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Block
class Object
trait Matchable
class Any
Show all
final case class Keyframes(name: String, frames: Seq[Rule]) extends Block

An animation's keyframes.

An animation's keyframes.

Value parameters

frames

Each keyframe, its selector from, to or a percentage.

name

The animation's name.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Block
class Object
trait Matchable
class Any
Show all
final case class Rule(selector: String, parts: Seq[Part]) extends Block

A rule: declarations for whatever its selector matches, and rules nested in it.

A rule: declarations for whatever its selector matches, and rules nested in it.

Value parameters

parts

The declarations and nested rules, in order.

selector

The selector, or several, separated by commas.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Block
class Object
trait Matchable
class Any
Show all

Types

type Declaration = StyleSetter[_, _] | DerivedStyleSetter[_, _]

A declaration: a style prop set to a value, as top.px(0) sets top.

A declaration: a style prop set to a value, as top.px(0) sets top.

Attributes

What a rule holds: its declarations, and rules nested in it.

What a rule holds: its declarations, and rules nested in it.

Attributes

Value members

Concrete methods

def fontFace(descriptors: Declaration*): FontFace

Makes a font face.

Makes a font face.

Value parameters

descriptors

Its descriptors.

Attributes

Returns

The font face.

def keyframes(name: String)(frames: Rule*): Keyframes

Makes an animation's keyframes.

Makes an animation's keyframes.

Value parameters

frames

Each keyframe, as rule("from")(opacity := 0).

name

The animation's name.

Attributes

Returns

The keyframes.

def media(query: String)(parts: Part*): Conditional

Makes rules apply only to the media a query matches.

Makes rules apply only to the media a query matches.

Value parameters

parts

The rules, and nested in a rule, declarations for its selector.

query

The media query, as (max-width: 600px).

Attributes

Returns

The conditional rules.

def render(blocks: Seq[Block]): String

Writes blocks out as CSS, every nested rule written out whole.

Writes blocks out as CSS, every nested rule written out whole.

Value parameters

blocks

The blocks, in order.

Attributes

Returns

Their CSS.

def rule(selector: String)(parts: Part*): Rule

Makes a rule.

Makes a rule.

Value parameters

parts

The declarations and nested rules, in order.

selector

The selector, or several, separated by commas; nested, & stands for the outer rule's selector.

Attributes

Returns

The rule.

def supports(condition: String)(parts: Part*): Conditional

Makes rules apply only where the browser supports a feature.

Makes rules apply only where the browser supports a feature.

Value parameters

condition

The condition, as (field-sizing: content).

parts

The rules, and nested in a rule, declarations for its selector.

Attributes

Returns

The conditional rules.