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

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

The 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
import be.doeraene.webcomponents.ui5.eventtypes.MoveEventDetail

/** 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 & 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 selectionMode: HtmlAttr[ListMode] = ListMode.asHtmlAttr("selection-mode")

  @deprecated("mode property of Tree has been renamed to selectionMode")
  def mode: HtmlAttr[ListMode] = selectionMode

  object events {
    val onItemClick: EventProp[EventWithPreciseTarget[Ref] & HasDetail[HasItem[TreeItem.Ref]]] = new EventProp(
      "item-click"
    )
    val onItemDelete: EventProp[EventWithPreciseTarget[Ref] & HasDetail[HasItem[TreeItem.Ref]]] = new EventProp(
      "item-delete"
    )
    val onItemMouseOut: EventProp[EventWithPreciseTarget[Ref] & HasDetail[HasItem[TreeItem.Ref]]] = new EventProp(
      "item-mouseout"
    )
    val onItemMouseOver: EventProp[EventWithPreciseTarget[Ref] & HasDetail[HasItem[TreeItem.Ref]]] = new EventProp(
      "item-mouseover"
    )
    val onItemToggle: EventProp[EventWithPreciseTarget[Ref] & 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] & HasDetail[SelectionChangeDetail]] = new EventProp(
      "selection-change"
    )
    lazy val onMove: EventProp[EventWithPreciseTarget[Ref] & HasDetail[MoveEventDetail[item.Ref]]] = new EventProp(
      "move"
    )
    lazy val onMoveOver: EventProp[EventWithPreciseTarget[Ref] & HasDetail[MoveEventDetail[item.Ref]]] = new EventProp(
      "move-over"
    )
  }

  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