-
Notifications
You must be signed in to change notification settings - Fork 9
/
GovukInput.scala.html
65 lines (55 loc) · 3.87 KB
/
GovukInput.scala.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@*
* Copyright 2023 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._
@import uk.gov.hmrc.govukfrontend.views.html.helpers._
@this(govukLabel: GovukLabel, govukFormGroup: GovukFormGroup, govukHintAndErrorMessage: GovukHintAndErrorMessage)
@(params: Input)
@import params._
@require(name.nonEmpty && id.nonEmpty, s"failed requirements for govukInput: name and id should not be empty. name=[$name], id=[$id]")
@govukFormGroup(formGroup, errorMessage) {
@govukLabel(Label(
forAttr = Some(id),
isPageHeading = label.isPageHeading,
classes = label.classes,
attributes = label.attributes,
content = label.content
))
@govukHintAndErrorMessage(id, describedBy, hint, errorMessage)(inputSnippet)
}
@inputPrefix(prefix: Option[PrefixOrSuffix], hasPrefix: Boolean, hasSuffix: Boolean, hasBeforeInput: Boolean, hasAfterInput: Boolean) = {@maybeWrapperStart(hasPrefix, hasSuffix, hasBeforeInput, hasAfterInput)@maybePrefix(prefix, hasPrefix)}
@maybePrefix(prefix: Option[PrefixOrSuffix], hasPrefix: Boolean) ={@if(hasPrefix) {<div class="@toClasses("govuk-input__prefix", prefix.get.classes)" aria-hidden="true"@toAttributes(prefix.get.attributes)>@prefix.get.content.asHtml</div>
}}
@maybeWrapperStart(hasPrefix: Boolean, hasSuffix: Boolean, hasBeforeInput: Boolean, hasAfterInput: Boolean) = {@if(hasPrefix || hasSuffix || hasBeforeInput || hasAfterInput) {
<div class="@toClasses("govuk-input__wrapper", inputWrapper.classes.getOrElse(""))"@toAttributes(inputWrapper.attributes)> @{formGroup.beforeInput.map(_.asHtml)}
}}
@inputSuffix(suffix: Option[PrefixOrSuffix], hasPrefix: Boolean, hasSuffix: Boolean, hasBeforeInput: Boolean, hasAfterInput: Boolean) = {
@maybeSuffix(suffix, hasSuffix)@maybeWrapperEnd(hasPrefix: Boolean, hasSuffix: Boolean, hasBeforeInput: Boolean, hasAfterInput: Boolean)
}
@maybeSuffix(suffix: Option[PrefixOrSuffix], hasSuffix: Boolean) = {@if(hasSuffix) {
<div class="@toClasses("govuk-input__suffix", suffix.get.classes)" aria-hidden="true"@toAttributes(suffix.get.attributes)>@suffix.get.content.asHtml</div>
}}
@maybeWrapperEnd(hasPrefix: Boolean, hasSuffix: Boolean, hasBeforeInput: Boolean, hasAfterInput: Boolean) = {@if(hasPrefix || hasSuffix || hasBeforeInput || hasAfterInput) {@{formGroup.afterInput.map(_.asHtml)} </div>}}
@inputSnippet(describedBy: String) = {
@defining {
id="@id" name="@name" type="@inputType" @if(spellcheck.nonEmpty) { spellcheck="@spellcheck"
} @value.mapNonEmpty {value => value="@value" }@if(disabled.getOrElse(false)) { disabled}@if(describedBy.nonEmpty) { aria-describedby="@describedBy"}
} { attrs =>
@defining {
@autocomplete.mapNonEmpty { autocomplete => autocomplete="@autocomplete"}@pattern.mapNonEmpty { pattern => pattern="@pattern"}@inputmode.mapNonEmpty { inputmode => inputmode="@inputmode"}@autocapitalize.map {v => autocapitalize="@v"}@toAttributes(attributes)
} { otherAttrs =>
@(inputPrefix(params.prefix, params.prefix.nonEmpty, params.suffix.nonEmpty, formGroup.beforeInput.filter(_.nonEmpty), formGroup.afterInput.filter(_.nonEmpty))) <input class="@toClasses("govuk-input", classes, errorMessage.fold("")(_ => "govuk-input--error"))" @attrs@otherAttrs> @(inputSuffix(params.suffix, params.prefix.nonEmpty, params.suffix.nonEmpty, formGroup.beforeInput.filter(_.nonEmpty), formGroup.afterInput.filter(_.nonEmpty)))
}}
}