Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add suffix and prefix examples to text input component #884

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions app/components/input/error-and-prefix-and-suffix.njk
Original file line number Diff line number Diff line change
@@ -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 %}

<div class="nhsuk-width-container">
<main class="nhsuk-main-wrapper" id="maincontent">

<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">
{{ 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": "Enter a cost per item, in pounds"
}
}) }}
</div>
</div>

</main>
</div>

{% endblock %}
28 changes: 28 additions & 0 deletions app/components/input/prefix-and-suffix.njk
Original file line number Diff line number Diff line change
@@ -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 %}

<div class="nhsuk-width-container">
<main class="nhsuk-main-wrapper" id="maincontent">

<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">
{{ input({
"label": {
"text": "What is the cost per item, in pounds??"
},
"id": "input-with-prefix-and-suffix",
"name": "test-name-6",
"prefix": "£",
"suffix": "per item"
}) }}
</div>
</div>

</main>
</div>

{% endblock %}
27 changes: 27 additions & 0 deletions app/components/input/prefix.njk
Original file line number Diff line number Diff line change
@@ -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 %}

<div class="nhsuk-width-container">
<main class="nhsuk-main-wrapper" id="maincontent">

<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">
{{ input({
"label": {
"text": "What is the cost in pounds?"
},
"id": "input-with-prefix",
"name": "test-name-4",
"prefix": "£"
}) }}
</div>
</div>

</main>
</div>

{% endblock %}
27 changes: 27 additions & 0 deletions app/components/input/suffix.njk
Original file line number Diff line number Diff line change
@@ -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 %}

<div class="nhsuk-width-container">
<main class="nhsuk-main-wrapper" id="maincontent">

<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">
{{ input({
"label": {
"text": "What is the weight in kilograms?"
},
"id": "input-with-suffix",
"name": "test-name-5",
"suffix": "kg"
}) }}
</div>
</div>

</main>
</div>

{% endblock %}
4 changes: 4 additions & 0 deletions app/pages/examples.njk
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
<li><a href="../components/input/hint.html">Input with hint text</a></li>
<li><a href="../components/input/error.html">Input with error message</a></li>
<li><a href="../components/input/custom-width.html">Input with width modifier</a></li>
<li><a href="../components/input/prefix.html">Input with prefix</a></li>
<li><a href="../components/input/suffix.html">Input with suffix</a></li>
<li><a href="../components/input/prefix-and-suffix.html">Input with prefix and suffix</a></li>
<li><a href="../components/input/error-and-prefix-and-suffix.html">Input with error message, prefix and suffix</a></li>
<li><a href="../components/inset-text/index.html">Inset text</a></li>
<li><a href="../components/label/index.html">Label</a></li>
<li><a href="../components/label/bold.html">Label with bold text</a></li>
Expand Down
57 changes: 56 additions & 1 deletion packages/components/input/_input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

.nhsuk-input {
@include nhsuk-font(19);

-moz-appearance: none; /* 1 */
-webkit-appearance: none; /* 1 */
appearance: none; /* 1 */
Expand Down Expand Up @@ -75,3 +74,59 @@
.nhsuk-input--width-2 {
max-width: 5.4ex;
}

// Suffix and prefix

.nhsuk-input__wrapper {
display: flex;

@include mq($until: mobile) {
display: block;
}
}

.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: mobile) {
display: block;
height: 100%;
white-space: normal;
}

@include mq($until: tablet) {
line-height: 1.6;
font-size: 1.1875rem;
}
}

.nhsuk-input__prefix {
@include mq($until: mobile) {
border-bottom: 0;
}
@include mq($from: mobile) {
border-right: 0;
}
}

.nhsuk-input__suffix {
@include mq($until: mobile) {
border-top: 0;
}
@include mq($from: mobile) {
border-left: 0;
}
}
34 changes: 23 additions & 11 deletions packages/components/input/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,26 @@
text: params.errorMessage.text
}) | indent(2) | trim -}}
{% endif %}
<input class="nhsuk-input
{%- if params.classes %} {{ params.classes }}{% endif %}
{%- if params.errorMessage %} nhsuk-input--error{% endif %}" id="{{ params.id }}" name="{{ params.name }}" type="{{ params.type | default('text') }}"
{%- if (params.spellcheck === false) or (params.spellcheck === true) %} spellcheck="{{ params.spellcheck }}"{% endif %}
{%- if params.value %} value="{{ params.value}}"{% endif %}
{%- if describedBy %} aria-describedby="{{ describedBy }}"{% endif %}
{%- if params.autocomplete %} autocomplete="{{ params.autocomplete}}"{% endif %}
{%- if params.pattern %} pattern="{{ params.pattern }}"{% endif %}
{%- if params.inputmode %} inputmode="{{ params.inputmode }}"{% endif %}
{%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
</div>
{%- if params.prefix or params.suffix %}
<div class="nhsuk-input__wrapper">
{% endif %}
{%- if params.prefix %}
<div class="nhsuk-input__prefix" aria-hidden="true">{{ params.prefix }}</div>
{% endif %}
<input class="nhsuk-input
{%- if params.classes %} {{ params.classes }}{% endif %}
{%- if params.errorMessage %} nhsuk-input--error{% endif %}" id="{{ params.id }}" name="{{ params.name }}" type="{{ params.type | default('text') }}"
{%- if (params.spellcheck === false) or (params.spellcheck === true) %} spellcheck="{{ params.spellcheck }}"{% endif %}
{%- if params.value %} value="{{ params.value}}"{% endif %}
{%- if describedBy %} aria-describedby="{{ describedBy }}"{% endif %}
{%- if params.autocomplete %} autocomplete="{{ params.autocomplete}}"{% endif %}
{%- if params.pattern %} pattern="{{ params.pattern }}"{% endif %}
{%- if params.inputmode %} inputmode="{{ params.inputmode }}"{% endif %}
{%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
{%- if params.suffix %}
<div class="nhsuk-input__suffix" aria-hidden="true">{{ params.suffix }}</div>
{% endif %}
{%- if params.prefix or params.suffix %}
</div> {# close nhsuk-input__wrapper #}
{% endif %}
</div> {# close nhsuk-form-group #}