diff --git a/ui/components/src/ui/components/tailwind/StyleGuide.scala b/ui/components/src/ui/components/tailwind/StyleGuide.scala index 18bba67..cfb0bfd 100644 --- a/ui/components/src/ui/components/tailwind/StyleGuide.scala +++ b/ui/components/src/ui/components/tailwind/StyleGuide.scala @@ -15,6 +15,7 @@ def label: String def cardContent: String def card: String + def input: String object StyleGuide: object default extends StyleGuide: @@ -23,6 +24,9 @@ override val cardContent: String = "px-4 py-5 sm:p-6" override val card: String = "bg-white shadow sm:rounded-md overflow-hidden" + override val input: String = + "shadow-sm block focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border border-gray-300 rounded-md" + override object button extends ButtonStyles: private def common(extra: String) = s"inline-flex items-center px-4 py-2 $extra border rounded-md shadow-sm text-sm font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" diff --git a/ui/components/src/ui/components/tailwind/StyleGuide.scala b/ui/components/src/ui/components/tailwind/StyleGuide.scala index 18bba67..cfb0bfd 100644 --- a/ui/components/src/ui/components/tailwind/StyleGuide.scala +++ b/ui/components/src/ui/components/tailwind/StyleGuide.scala @@ -15,6 +15,7 @@ def label: String def cardContent: String def card: String + def input: String object StyleGuide: object default extends StyleGuide: @@ -23,6 +24,9 @@ override val cardContent: String = "px-4 py-5 sm:p-6" override val card: String = "bg-white shadow sm:rounded-md overflow-hidden" + override val input: String = + "shadow-sm block focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border border-gray-300 rounded-md" + override object button extends ButtonStyles: private def common(extra: String) = s"inline-flex items-center px-4 py-2 $extra border rounded-md shadow-sm text-sm font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" diff --git a/ui/components/src/ui/components/tailwind/form/TextArea.scala b/ui/components/src/ui/components/tailwind/form/TextArea.scala index 17f90e3..d41b4ab 100644 --- a/ui/components/src/ui/components/tailwind/form/TextArea.scala +++ b/ui/components/src/ui/components/tailwind/form/TextArea.scala @@ -5,24 +5,36 @@ import com.raquo.laminar.nodes.ReactiveHtmlElement import org.scalajs.dom.html -class TextArea[V]( - initialRows: Int = 5 -)(using codec: FormCodec[V, String]) - extends FormInput[V]: +class TextArea[V](using codec: FormCodec[V, String]) extends FormInput[V]: override def render( prop: Property[V], updates: Observer[Validated[V]] ): ReactiveHtmlElement[html.TextArea] = + TextArea.render( + prop.name, + prop.value.map(codec.toForm), + updates.contramap(codec.toValue), + cls( + "max-w-lg w-full shadow-sm block focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border border-gray-300 rounded-md" + ) + ) + +object TextArea: + def render( + fieldName: String, + currentValue: Option[String], + updates: Observer[String], + mods: Modifier[ReactiveHtmlElement[html.TextArea]]* + ): ReactiveHtmlElement[html.TextArea] = def numberOfLines(s: String) = s.count(_ == '\n') - val currentValue = prop.value.map(codec.toForm) val changeBus = EventBus[String]() - val rowNo = Var(currentValue.map(numberOfLines).getOrElse(initialRows)) + val rowNo = Var(currentValue.map(numberOfLines).getOrElse(0)) textArea( changeBus.events.map(numberOfLines) --> rowNo, - changeBus.events.map(codec.toValue) --> updates, - name := prop.name, + changeBus.events --> updates, + name := fieldName, rows <-- rowNo.signal.map(_ + 2), - cls := "max-w-lg shadow-sm block w-full focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border border-gray-300 rounded-md", - prop.value.map(v => value(codec.toForm(v))), + mods, + currentValue.map(value(_)), onInput.mapToValue.setAsValue --> changeBus.writer )