Skip to content

Instantly share code, notes, and snippets.

@fomkin
Created May 9, 2020 17:25
Show Gist options
  • Save fomkin/c4a1d5c72256bd6c172d621340064811 to your computer and use it in GitHub Desktop.
Save fomkin/c4a1d5c72256bd6c172d621340064811 to your computer and use it in GitHub Desktop.
import levsha.Document.Node
import org.fomkin.berzin.data.EncryptedText
import org.fomkin.berzin.web.view.SvgSymbols
import scala.language.higherKinds
object dropDownMenu {
import SvgSymbols._
import levsha.dsl._
import html._
def apply[M, T](items: Seq[Item[T]],
itemClick: T => M = null): Node[M] = optimize {
div(
clazz := "drop-down-menu",
div(`class` := "drop-down-menu_panel",
items map {
case dropDownMenu.Item.Nope => void
case dropDownMenu.Item.Delimiter => hr()
case dropDownMenu.Item.Header(v) => div(`class` := "drop-down-menu_item drop-down-menu_item__header", v)
case dropDownMenu.Item.Plain(key, label, check) =>
div(
Option(itemClick).map(_(key)),
`class` := "drop-down-menu_item drop-down-menu_item__active",
check match {
case Some(true) => span(`class` := "drop-down-menu_item_checkbox", "✓")
case Some(false) => span(`class` := "drop-down-menu_item_checkbox")
case None => void
},
label,
)
}
)
)
}
sealed trait Item[+T] extends Any
object Item {
final case class Plain[+T](key: T, label: Node[Nothing], check: Option[Boolean] = None) extends Item[T]
final case class Header(label: String) extends Item[Nothing]
case object Delimiter extends Item[Nothing]
case object Nope extends Item[Nothing]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment