Skip to content

Commit

Permalink
feat: Update password field rendering in UI5WidgetFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
cheleb committed Aug 27, 2024
1 parent 76a3431 commit 1f3b8c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
19 changes: 3 additions & 16 deletions examples/client/src/main/scala/samples/model/LoginPassword.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
package samples.model

import dev.cheleb.scalamigen.Form
import com.raquo.laminar.api.L.*
import dev.cheleb.scalamigen.WidgetFactory

import dev.cheleb.scalamigen.secretForm

opaque type Password = String

object Password:
def apply(password: String): Password = password
given Form[Password] with
override def render(
variable: Var[Password],
syncParent: () => Unit,
values: List[Password] = List.empty
)(using factory: WidgetFactory): HtmlElement =
factory.renderSecret
.amend(
value <-- variable.signal,
onInput.mapToValue --> { v =>
variable.set(v)
syncParent()
}
)
given Form[Password] = secretForm(apply)
14 changes: 14 additions & 0 deletions modules/core/src/main/scala/dev/cheleb/scalamigen/Form.scala
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,17 @@ def numericForm[A](f: String => Option[A], zero: A): Form[A] = new Form[A] {
}
)
}

def secretForm[A <: String](to: String => A) = new Form[A]:
override def render(
variable: Var[A],
syncParent: () => Unit,
values: List[A] = List.empty
)(using factory: WidgetFactory): HtmlElement =
factory.renderSecret.amend(
value <-- variable.signal,
onInput.mapToValue.map(to) --> { v =>
variable.set(v)
syncParent()
}
)

0 comments on commit 1f3b8c2

Please sign in to comment.