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

com.raquo.laminar.keys.AriaAttr.scala Maven / Gradle / Ivy

The newest version!
package com.raquo.laminar.keys

import com.raquo.airstream.core.Source
import com.raquo.laminar.DomApi
import com.raquo.laminar.api.L.{optionToSetter, Element}
import com.raquo.laminar.codecs.Codec
import com.raquo.laminar.modifiers.{KeySetter, KeyUpdater, Setter}
import com.raquo.laminar.modifiers.KeySetter.AriaAttrSetter
import com.raquo.laminar.modifiers.KeyUpdater.AriaAttrUpdater

/**
 * This class represents an HTML Element Attribute. Meaning the key that can be set, not the whole a key-value pair.
 *
 * @tparam V type of values that this Attribute can be set to
 */
class AriaAttr[V](
  suffix: String,
  val codec: Codec[V, String]
) extends Key {

  override val name: String = "aria-" + suffix

  def :=(value: V): AriaAttrSetter[V] = {
    new KeySetter[AriaAttr[V], V, Element](this, value, DomApi.setAriaAttribute)
  }

  @inline def apply(value: V): AriaAttrSetter[V] = {
    this := value
  }

  def maybe(value: Option[V]): Setter[Element] = {
    optionToSetter(value.map(v => this := v))
  }

  def <--(values: Source[V]): AriaAttrUpdater[V] = {
    new KeyUpdater[Element, AriaAttr[V], V](
      key = this,
      values = values.toObservable,
      update = (el, v, _) => DomApi.setAriaAttribute(el, this, v)
    )
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy