blue-pitaya / laminar-color   1.0

MIT License GitHub

Fully customizable color pickers for Laminar library.

Scala versions: 2.13
Scala.js versions: 1.x

Laminar Color

Preview of pickers.

Collection of color pickers written in Laminar library. Pickers are composed from reusable components that can be easily used to create your own color picker. Project inspired by React color (i stole some of their CSS).

See demo.

Instalation

For Laminar 16:

libraryDependencies += "dev.bluepitaya" %%% "laminar-color" % "1.1"

Usage

All pickers have the same component function signature.

def component(colorSignal: Signal[Hsv], onColorChanged: Observer[Hsv])

Default color model for pickers is Hsv. The hsv case class comes with mappings to both hsl and rgba models for easy use in CSS.

Example

val color = Var(Hsv(200, 0.75, 0.75, 1))
val hslValueSignal = color.signal.map(_.toCssHsl)
val rgbaValueSignal = color.signal.map(_.toCssRgba)

val app = div(
  div(
    h2("Current color"),
    div(child.text <-- hslValueSignal),
    div(child.text <-- rgbaValueSignal)
  ),
  h2("Color picerks"),
  div(
    display.flex,
    flexDirection.row,
    styleProp("gap")("30px"),
    div(
      h3("Chrome picker"),
      ChromePicker.component(color.signal, color.writer)
    ),
    div(
      h3("Sketch picker"),
      SketchPicker.component(color.signal, color.writer)
    ),
    div(
      h3("Simple picker"),
      SimplePicker.component(color.signal, color.writer)
    )
  )
)

Building your own picker

Best way is to look at source code of current out-of-box pickers to see how to build your onw.

Development

To run example page you need to:

  1. Run sbt -> project example -> ~fastLinkJS
  2. Execute yarn (only once to install JS deps) -> yarn dev in example/ui dir.