-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Laminar library of text counter application
- Loading branch information
1 parent
6ac763b
commit 6a1978b
Showing
13 changed files
with
640 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
# Ignore generated Metals files | ||
.metals | ||
**/metals.sbt | ||
# Ignore Scala.js generated output files | ||
**/target | ||
**/.scala-build | ||
**/.bsp | ||
**/.bloop | ||
# Ignore generated Mac files | ||
**/.DS_Store | ||
# Ignore generated Node.js generated output files | ||
**/node_modules |
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version = "3.7.15" | ||
runner.dialect = scala213 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Text Counter Application in Laminar | ||
|
||
This is a text counter application using Laminar. It is based on Scala.js and uses Scala code to build HTML code. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
enablePlugins(ScalaJSPlugin) | ||
name := "Text Counter Application using Laminar" | ||
scalaVersion := "2.13.12" | ||
scalaJSUseMainModuleInitializer := true | ||
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.4.0" | ||
libraryDependencies += "com.raquo" %%% "laminar" % "16.0.0" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<head> | ||
<title>Text Counter Application using Laminar</title> | ||
</head> | ||
<body> | ||
<script | ||
type="module" | ||
src="target/scala-2.13/text-counter-application-using-laminar-fastopt/main.js" | ||
></script> | ||
</body> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.9.9 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.15.0") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.9.9 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import org.scalajs.dom.document | ||
import org.scalajs.dom | ||
import com.raquo.laminar.api.L._ | ||
case class FormState( | ||
textContent: String = "" | ||
) | ||
object TextCounterApp { | ||
private val stateVarForm = Var(FormState()) | ||
private val submitter = Observer[FormState] { state => | ||
val textContent = document | ||
.getElementById("textContent") | ||
.asInstanceOf[dom.html.TextArea] | ||
.value | ||
val characters = textContent.length | ||
val words = textContent.trim.split("\\s+").length | ||
val lines = textContent.split("\\n").length | ||
document.getElementById("textOutput").innerHTML = | ||
s"Characters: $characters\nWords: $words\nLines: $lines" | ||
} | ||
def main(args: Array[String]): Unit = { | ||
def textCounterContent: HtmlElement = { | ||
div( | ||
idAttr := "app", | ||
h1("Text Counter Application using Laminar"), | ||
div( | ||
textArea(idAttr := "textContent", rows := 10, cols := 80), | ||
button( | ||
"Update Text Counter Output", | ||
onClick.preventDefault.mapTo(stateVarForm.now()) --> submitter | ||
), | ||
div(idAttr := "textOutput") | ||
) | ||
) | ||
} | ||
renderOnDomContentLoaded(document.body, textCounterContent) | ||
} | ||
} |
Oops, something went wrong.