All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.cheleb.scalamigen.LaminarWidgetFactory.scala Maven / Gradle / Ivy

There is a newer version: 0.14.0
Show newest version
package dev.cheleb.scalamigen

import com.raquo.laminar.api.L.*
import com.raquo.laminar.modifiers.EventListener
import org.scalajs.dom.HTMLSelectElement
import com.raquo.laminar.api.L

/** This is raw laminar implementation of the widget factory.
  */
object LaminarWidgetFactory extends WidgetFactory:

  override def renderCheckbox: L.HtmlElement = input(
    tpe := "checkbox"
  )

  override def renderDatePicker: HtmlElement = input(
    tpe := "date"
  )

  override def renderSecret: HtmlElement = input(
    tpe := "password"
  )

  override def renderText: HtmlElement = input(
    tpe := "text"
  )
  override def renderLabel(required: Boolean, name: String): HtmlElement = span(
    name
  )
  override def renderNumeric: HtmlElement = input(
    tpe := "number"
  )
  override def renderButton: HtmlElement = button()
  override def renderLink(text: String, el: EventListener[?, ?]): HtmlElement =
    a(
      text,
      href := "#",
      el
    )
  override def renderUL(id: String): HtmlElement = ul(idAttr := id)
  override def renderPanel(headerText: Option[String]): HtmlElement =
    headerText match
      case None => div()
      case Some(headerText) =>
        div(
          headerText
        )

  override def renderSelect(f: Int => Unit): HtmlElement = select(
    onChange.map(
      _.target.asInstanceOf[HTMLSelectElement].selectedIndex
    ) --> { ds =>
      f(ds)
    }
  )

  override def renderOption(
      label: String,
      idx: Int,
      isSelected: Boolean
  ): HtmlElement =
    option(
      label,
      value := s"$idx",
      selected := isSelected
    )




© 2015 - 2024 Weber Informatics LLC | Privacy Policy