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

be.doeraene.webcomponents.ui5.Tree.scala Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package be.doeraene.webcomponents.ui5

import be.doeraene.webcomponents.ui5.configkeys.ListMode
import be.doeraene.webcomponents.ui5.internal.Slot
import com.raquo.laminar.codecs.{BooleanAsAttrPresenceCodec, StringAsIsCodec}
import com.raquo.laminar.api.L.*
import com.raquo.laminar.tags.CustomHtmlTag
import com.raquo.laminar.keys.HtmlAttr
import com.raquo.laminar.nodes.ReactiveHtmlElement
import org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSImport, JSName}
import be.doeraene.webcomponents.ui5.eventtypes.EventWithPreciseTarget
import be.doeraene.webcomponents.ui5.eventtypes.HasDetail
import be.doeraene.webcomponents.ui5.eventtypes.HasItem
import be.doeraene.webcomponents.WebComponent

/** The ui5-tree component provides a tree structure for displaying data in a hierarchy.
  *
  * @see
  *   the doc for more information.
  */
object Tree extends WebComponent with HasAccessibleName {

  //noinspection ScalaUnusedSymbol
  @js.native
  trait RawElement extends js.Object {
    def walk(callback: js.Function2[dom.HTMLElement, Int, Unit]): Unit = js.native
  }

  @js.native
  @JSImport("@ui5/webcomponents/dist/Tree.js", JSImport.Default)
  object RawImport extends js.Object

  // object-s are lazy so you need to actually use them in your code to prevent dead code elimination
  used(RawImport)

  type Ref = dom.html.Element with RawElement

  protected val tag: CustomHtmlTag[Ref] = CustomHtmlTag("ui5-tree")

  lazy val footerText: HtmlAttr[String] = htmlAttr("footer-text", StringAsIsCodec)
  lazy val headerText: HtmlAttr[String] = htmlAttr("header-text", StringAsIsCodec)
  lazy val noDataText: HtmlAttr[String] = htmlAttr("no-data-text", StringAsIsCodec)

  lazy val mode: HtmlAttr[ListMode] = htmlAttr("mode", ListMode.AsStringCodec)

  object events {
    val onItemClick: EventProp[EventWithPreciseTarget[Ref] with HasDetail[HasItem[TreeItem.Ref]]] = new EventProp(
      "item-click"
    )
    val onItemDelete: EventProp[EventWithPreciseTarget[Ref] with HasDetail[HasItem[TreeItem.Ref]]] = new EventProp(
      "item-delete"
    )
    val onItemMouseOut: EventProp[EventWithPreciseTarget[Ref] with HasDetail[HasItem[TreeItem.Ref]]] = new EventProp(
      "item-mouseout"
    )
    val onItemMouseOver: EventProp[EventWithPreciseTarget[Ref] with HasDetail[HasItem[TreeItem.Ref]]] = new EventProp(
      "item-mouseover"
    )
    val onItemToggle: EventProp[EventWithPreciseTarget[Ref] with HasDetail[HasItem[TreeItem.Ref]]] = new EventProp(
      "item-toggle"
    )

    @js.native
    trait SelectionChangeDetail extends js.Object {
      @JSName("selectedItems")
      def selectedItemsJS: js.Array[TreeItem.Ref] = js.native
      @JSName("previouslySelectedItems")
      def previouslySelectedItemsJS: js.Array[TreeItem.Ref] = js.native
    }

    object SelectionChangeDetail {
      extension (detail: SelectionChangeDetail)
        def selectedItems: List[TreeItem.Ref]           = detail.selectedItemsJS.toList
        def previouslySelectedItems: List[TreeItem.Ref] = detail.previouslySelectedItemsJS.toList
    }

    val onSelectionChange: EventProp[EventWithPreciseTarget[Ref] with HasDetail[SelectionChangeDetail]] = new EventProp(
      "selection-change"
    )
  }

  object slots {
    val header: Slot = new Slot("header")
  }

  def item: TreeItem.type             = TreeItem
  def customItem: TreeItemCustom.type = TreeItemCustom

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy