Created
June 15, 2016 09:27
-
-
Save anonymous/1f412b2c851e90836f81d292a416dc78 to your computer and use it in GitHub Desktop.
Scala.jsFiddle gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalajs.dom | |
import dom.html | |
import scalajs.js.annotation.JSExport | |
object ScalaJSExample extends js.JSApp{ | |
val listings = Seq( | |
"Apple", "Apricot", "Banana", "Cherry", | |
"Mango", "Mangosteen", "Mandarin", | |
"Grape", "Grapefruit", "Guava" | |
) | |
val box = input( | |
`type`:="text", | |
placeholder:="Type here!" | |
).render | |
val output = div(renderListings).render | |
box.onkeyup = (e: dom.Event) => { | |
output.innerHTML = "" | |
output.appendChild(renderListings) | |
} | |
def renderListings = ul( | |
for { | |
fruit <- listings | |
if fruit.toLowerCase.startsWith( | |
box.value.toLowerCase | |
) | |
} yield { | |
val (first, last) = fruit.splitAt( | |
box.value.length | |
) | |
li( | |
span( | |
backgroundColor:="yellow", | |
first | |
), | |
last | |
) | |
} | |
).render | |
def main() = { | |
val document = js.Dynamic.global.document | |
val d= div( | |
h1("Search Box!"), | |
p( | |
"Type here to filter " + | |
"the list of things below!" | |
), | |
div(box), | |
output | |
).render | |
println(d) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment