Skip to content

Commit

Permalink
Merge pull request #17 from hmrc/PLATUI-441-add-currency-input
Browse files Browse the repository at this point in the history
PLATUI-441: Add currency input component from hmrc-frontend
  • Loading branch information
matthewmascord committed May 11, 2020
2 parents f6c3144 + a6907a9 commit 8717d4e
Show file tree
Hide file tree
Showing 158 changed files with 624 additions and 765 deletions.
18 changes: 14 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ lazy val libDependencies: Seq[ModuleID] = dependencies(
"com.typesafe.play" %% "play" % playRevision,
"com.typesafe.play" %% "filters-helpers" % playRevision,
"org.joda" % "joda-convert" % "2.0.2",
"org.webjars.npm" % "hmrc-frontend" % "1.11.0"
"org.webjars.npm" % "hmrc-frontend" % "1.12.0"
)

val test = Seq(
Expand All @@ -118,16 +118,26 @@ lazy val libDependencies: Seq[ModuleID] = dependencies(
compile ++ test
},
play25 = {
val compile = Seq(
"uk.gov.hmrc" %% "play-frontend-govuk" % "0.44.0-play-25"
)

val test = Seq(
"org.scalatestplus.play" %% "scalatestplus-play" % "2.0.1"
).map(_ % Test)
test

compile ++ test
},
play26 = {
val compile = Seq(
"uk.gov.hmrc" %% "play-frontend-govuk" % "0.44.0-play-26"
)

val test = Seq(
"org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2"
)
test
).map(_ % Test)

compile ++ test
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ trait TemplateServiceClient extends WordSpecLike with WSScalaTestClient with Gui
* @return [[WSResponse]] with the rendered component
*/
def render[T: OWrites](hmrcComponentName: String, templateParams: T, hmrcVersion: String = hmrcFrontendVersion): Future[WSResponse] =
wsUrl(s"hmrc/$hmrcVersion/components/$hmrcComponentName")
wsUrl(s"component/hmrc/$hmrcVersion/$hmrcComponentName")
.post(Json.toJson(templateParams))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2019 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.hmrcfrontend.views.components

import play.twirl.api.HtmlFormat
import uk.gov.hmrc.hmrcfrontend.support.TemplateIntegrationSpec
import uk.gov.hmrc.hmrcfrontend.views.html.components._
import uk.gov.hmrc.hmrcfrontend.views.viewmodels.currencyinput.Generators._

import scala.util.Try

object hmrcCurrencyInputIntegrationSpec
extends TemplateIntegrationSpec[CurrencyInput](hmrcComponentName = "hmrcCurrencyInput", seed = None) {

override def render(currencyInput: CurrencyInput): Try[HtmlFormat.Appendable] =
Try(HmrcCurrencyInput(currencyInput))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@*
* Copyright 2020 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*@

@import uk.gov.hmrc.govukfrontend.views.html.components.GovukErrorMessage
@import uk.gov.hmrc.govukfrontend.views.html.components.GovukHint
@import uk.gov.hmrc.govukfrontend.views.html.components.GovukLabel
@import uk.gov.hmrc.govukfrontend.views.viewmodels.label.Label
@import uk.gov.hmrc.govukfrontend.views.viewmodels.hint.Hint
@import uk.gov.hmrc.govukfrontend.views.viewmodels.errormessage.ErrorMessage



@(params: CurrencyInput)
@import params._
@require(name.nonEmpty && id.nonEmpty, s"failed requirements for govukInput: name and id should not be empty. name=[$name], id=[$id]")

@hintSnippet(describedBy: String) = @{
hint.fold((describedBy, HtmlFormat.empty)) { hint =>
val hintId = s"$id-hint"
val describedBy1 = s"$describedBy $hintId".ltrim
val hintHtml =
GovukHint(Hint(
id = Some(hintId),
classes = hint.classes,
attributes = hint.attributes,
content = hint.content
))
(describedBy1, hintHtml)
}
}

@errorMessageSnippet(describedBy: String) = @{
errorMessage.fold((describedBy, HtmlFormat.empty)) { errorMessage =>
val errorId = s"$id-error"
val describedBy1 = s"$describedBy $errorId".ltrim
val errorMessageHtml =
GovukErrorMessage(ErrorMessage(
id = Some(errorId),
classes = errorMessage.classes,
attributes = errorMessage.attributes,
visuallyHiddenText = errorMessage.visuallyHiddenText,
content = errorMessage.content
))
(describedBy1, errorMessageHtml)
}
}

@inputSnippet(describedBy: String) = {
<div class="hmrc-currency-input__wrapper">
<span class="hmrc-currency-input__unit" aria-hidden="true">£</span>
<input
class="@toClasses("govuk-input", classes, errorMessage.fold("")(_ => "govuk-input--error"))"
id="@id"
name="@name"
type="text"
@value.mapNonEmpty { value => value="@value" }@if(describedBy.nonEmpty) { aria-describedby="@describedBy"}
@autocomplete.mapNonEmpty { autocomplete => autocomplete="@autocomplete"}
inputmode="decimal"
@toAttributes(attributes)
/>
</div>
}

@divSnippet = @{
val (describedBy1, hintHtml) = hintSnippet(describedBy.getOrElse(""))
val (describedBy2, errorMessageHtml) = errorMessageSnippet(describedBy1)
val inputHtml = inputSnippet(describedBy2)
HtmlFormat.fill(collection.immutable.Seq(hintHtml, errorMessageHtml, inputHtml))
}

<div class="@toClasses("govuk-form-group", errorMessage.fold("")(_ => "govuk-form-group--error"))">
@GovukLabel(Label(
forAttr = Some(id),
isPageHeading = label.isPageHeading,
classes = label.classes,
attributes = label.attributes,
content = label.content
))
@divSnippet
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ package object components extends Utils with Aliases {
lazy val HmrcTimeoutDialog = hmrcTimeoutDialog

lazy val HmrcReportTechnicalIssue = hmrcReportTechnicalIssue

lazy val HmrcCurrencyInput = hmrcCurrencyInput

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@*
* Copyright 2020 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*@

@import uk.gov.hmrc.govukfrontend.views.html.components.GovukErrorMessage
@import uk.gov.hmrc.govukfrontend.views.html.components.GovukHint
@import uk.gov.hmrc.govukfrontend.views.html.components.GovukLabel
@import uk.gov.hmrc.govukfrontend.views.viewmodels.label.Label
@import uk.gov.hmrc.govukfrontend.views.viewmodels.hint.Hint
@import uk.gov.hmrc.govukfrontend.views.viewmodels.errormessage.ErrorMessage

@this(GovukErrorMessage: GovukErrorMessage, GovukHint: GovukHint, GovukLabel: GovukLabel)

@(params: CurrencyInput)
@import params._
@require(name.nonEmpty && id.nonEmpty, s"failed requirements for govukInput: name and id should not be empty. name=[$name], id=[$id]")

@hintSnippet(describedBy: String) = @{
hint.fold((describedBy, HtmlFormat.empty)) { hint =>
val hintId = s"$id-hint"
val describedBy1 = s"$describedBy $hintId".ltrim
val hintHtml =
GovukHint(Hint(
id = Some(hintId),
classes = hint.classes,
attributes = hint.attributes,
content = hint.content
))
(describedBy1, hintHtml)
}
}

@errorMessageSnippet(describedBy: String) = @{
errorMessage.fold((describedBy, HtmlFormat.empty)) { errorMessage =>
val errorId = s"$id-error"
val describedBy1 = s"$describedBy $errorId".ltrim
val errorMessageHtml =
GovukErrorMessage(ErrorMessage(
id = Some(errorId),
classes = errorMessage.classes,
attributes = errorMessage.attributes,
visuallyHiddenText = errorMessage.visuallyHiddenText,
content = errorMessage.content
))
(describedBy1, errorMessageHtml)
}
}

@inputSnippet(describedBy: String) = {
<div class="hmrc-currency-input__wrapper">
<span class="hmrc-currency-input__unit" aria-hidden="true">£</span>
<input
class="@toClasses("govuk-input", classes, errorMessage.fold("")(_ => "govuk-input--error"))"
id="@id"
name="@name"
type="text"
@value.mapNonEmpty { value => value="@value" }@if(describedBy.nonEmpty) { aria-describedby="@describedBy"}
@autocomplete.mapNonEmpty { autocomplete => autocomplete="@autocomplete"}
inputmode="decimal"
@toAttributes(attributes)
/>
</div>
}

@divSnippet = @{
val (describedBy1, hintHtml) = hintSnippet(describedBy.getOrElse(""))
val (describedBy2, errorMessageHtml) = errorMessageSnippet(describedBy1)
val inputHtml = inputSnippet(describedBy2)
HtmlFormat.fill(collection.immutable.Seq(hintHtml, errorMessageHtml, inputHtml))
}

<div class="@toClasses("govuk-form-group", errorMessage.fold("")(_ => "govuk-form-group--error"))">
@GovukLabel(Label(
forAttr = Some(id),
isPageHeading = label.isPageHeading,
classes = label.classes,
attributes = label.attributes,
content = label.content
))
@divSnippet
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package uk.gov.hmrc.hmrcfrontend.views
package html

import uk.gov.hmrc.govukfrontend.views.html.components.{GovukErrorMessage, GovukHint, GovukLabel}

package object components extends Utils with Aliases {

/**
Expand Down Expand Up @@ -63,4 +65,8 @@ package object components extends Utils with Aliases {
type HmrcReportTechnicalIssue = hmrcReportTechnicalIssue
@deprecated(message="Use DI", since="Play 2.6")
lazy val HmrcReportTechnicalIssue = new hmrcReportTechnicalIssue()

type HmrcCurrencyInput = hmrcCurrencyInput
@deprecated(message="Use DI", since="Play 2.6")
lazy val HmrcCurrencyInput = new hmrcCurrencyInput(GovukErrorMessage, GovukHint, GovukLabel)
}
3 changes: 3 additions & 0 deletions src/main/scala/uk/gov/hmrc/hmrcfrontend/views/Aliases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ trait Aliases {

type ReportTechnicalIssue = viewmodels.reporttechnicalissue.ReportTechnicalIssue
val ReportTechnicalIssue = viewmodels.reporttechnicalissue.ReportTechnicalIssue

type CurrencyInput = viewmodels.currencyinput.CurrencyInput
val CurrencyInput = viewmodels.currencyinput.CurrencyInput
}

object Aliases extends Aliases

This file was deleted.

0 comments on commit 8717d4e

Please sign in to comment.