diff --git a/app/components/input/error-and-prefix-and-suffix.njk b/app/components/input/error-and-prefix-and-suffix.njk new file mode 100644 index 000000000..64168f26b --- /dev/null +++ b/app/components/input/error-and-prefix-and-suffix.njk @@ -0,0 +1,34 @@ +{% set html_style = 'background-color: #f0f4f5;' %} +{% set title = 'Input with error message, prefix and suffix' %} +{% from 'components/input/macro.njk' import input %} +{% extends 'layout.njk' %} + +{% block body %} + +
+
+ +
+
+ {{ input({ + "label": { + "text": "What is the cost per item, in pounds?" + }, + "hint": { + "text": "Divide the total cost, in pounds, by the number of items." + }, + "id": "input-with-error-message-and-prefix-and-suffix", + "name": "test-name-7", + "prefix": "£", + "suffix": "per item", + "errorMessage": { + "text": "Error message goes here" + } + }) }} +
+
+ +
+
+ +{% endblock %} diff --git a/app/components/input/prefix-and-suffix.njk b/app/components/input/prefix-and-suffix.njk new file mode 100644 index 000000000..fae92d0a8 --- /dev/null +++ b/app/components/input/prefix-and-suffix.njk @@ -0,0 +1,28 @@ +{% set html_style = 'background-color: #f0f4f5;' %} +{% set title = 'Input with prefix and suffix' %} +{% from 'components/input/macro.njk' import input %} +{% extends 'layout.njk' %} + +{% block body %} + +
+
+ +
+
+ {{ input({ + "label": { + "text": "How old are you?" + }, + "id": "input-with-prefix-and-suffix", + "name": "test-name-6", + "prefix": "I'm", + "suffix": "years old" + }) }} +
+
+ +
+
+ +{% endblock %} diff --git a/app/components/input/prefix.njk b/app/components/input/prefix.njk new file mode 100644 index 000000000..952093a09 --- /dev/null +++ b/app/components/input/prefix.njk @@ -0,0 +1,27 @@ +{% set html_style = 'background-color: #f0f4f5;' %} +{% set title = 'Input with prefix' %} +{% from 'components/input/macro.njk' import input %} +{% extends 'layout.njk' %} + +{% block body %} + +
+
+ +
+
+ {{ input({ + "label": { + "text": "What is the cost in pounds?" + }, + "id": "input-with-prefix", + "name": "test-name-4", + "prefix": "£" + }) }} +
+
+ +
+
+ +{% endblock %} diff --git a/app/components/input/suffix.njk b/app/components/input/suffix.njk new file mode 100644 index 000000000..c3d2b2102 --- /dev/null +++ b/app/components/input/suffix.njk @@ -0,0 +1,27 @@ +{% set html_style = 'background-color: #f0f4f5;' %} +{% set title = 'Input with suffix' %} +{% from 'components/input/macro.njk' import input %} +{% extends 'layout.njk' %} + +{% block body %} + +
+
+ +
+
+ {{ input({ + "label": { + "text": "Weight" + }, + "id": "input-with-suffix", + "name": "test-name-5", + "suffix": "kg" + }) }} +
+
+ +
+
+ +{% endblock %} diff --git a/app/pages/examples.njk b/app/pages/examples.njk index f4683e0e5..5af86285f 100644 --- a/app/pages/examples.njk +++ b/app/pages/examples.njk @@ -92,6 +92,10 @@
  • Input with hint text
  • Input with error message
  • Input with width modifier
  • +
  • Input with prefix
  • +
  • Input with suffix
  • +
  • Input with prefix and suffix
  • +
  • Input with error message, prefix and suffix
  • Inset text
  • Label
  • Label with bold text
  • diff --git a/packages/components/input/_input.scss b/packages/components/input/_input.scss index e4907f455..c3ae94a47 100644 --- a/packages/components/input/_input.scss +++ b/packages/components/input/_input.scss @@ -12,7 +12,6 @@ .nhsuk-input { @include nhsuk-font(19); - -moz-appearance: none; /* 1 */ -webkit-appearance: none; /* 1 */ appearance: none; /* 1 */ @@ -75,3 +74,39 @@ .nhsuk-input--width-2 { max-width: 5.4ex; } + +// Suffix and prefix + +.nhsuk-input__wrapper { + display: flex; +} + +.nhsuk-input__prefix, +.nhsuk-input__suffix { + @include nhsuk-font($size: 19); + + background-color: $color_nhsuk-grey-4; + border: $nhsuk-border-width-form-element solid $nhsuk-form-border-color; + box-sizing: border-box; + cursor: default; // emphasises non-editable status of prefixes and suffixes + display: inline-block; + flex: 0 0 auto; + height: 40px; + min-width: nhsuk-px-to-rem(40px); + padding: nhsuk-spacing(1); + text-align: center; + white-space: nowrap; + + @include mq($until: tablet) { + line-height: 1.6; + font-size: 1.1875rem; + } +} + +.nhsuk-input__prefix { + border-right: 0; +} + +.nhsuk-input__suffix { + border-left: 0; +} diff --git a/packages/components/input/template.njk b/packages/components/input/template.njk index 61a9fec09..481cf9244 100644 --- a/packages/components/input/template.njk +++ b/packages/components/input/template.njk @@ -37,14 +37,26 @@ text: params.errorMessage.text }) | indent(2) | trim -}} {% endif %} - - +{%- if params.prefix or params.suffix %} +
    +{% endif %} + {%- if params.prefix %} + + {% endif %} + + {%- if params.suffix %} + + {% endif %} +{%- if params.prefix or params.suffix %} +
    {# close nhsuk-input__wrapper #} +{% endif %} + {# close nhsuk-form-group #}