move vendored uk components to templates

This commit is contained in:
stvnrlly
2022-12-14 11:50:51 -05:00
parent d45c0f6251
commit ac1d5f0983
217 changed files with 4041 additions and 330 deletions

View File

@@ -0,0 +1,15 @@
# Input
## Installation
See the [main README quick start guide](https://github.com/alphagov/govuk-frontend#quick-start) for how to install this component.
## Guidance and Examples
Find out when to use the input component in your service in the [GOV.UK Design System](https://design-system.service.gov.uk/components/text-input).
## Component options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
See [options table](https://design-system.service.gov.uk/components/text-input/#options-example-default) for details.

View File

@@ -0,0 +1,77 @@
@import "../../settings/all";
@import "../../tools/all";
@import "../../helpers/all";
@import "../error-message/error-message";
@import "../hint/hint";
@import "../label/label";
@include govuk-exports("govuk/component/input") {
.govuk-input {
@include govuk-font($size: 19);
@include govuk-focusable;
box-sizing: border-box;
width: 100%;
height: 40px;
margin-top: 0;
padding: govuk-spacing(1);
// setting any background-color makes text invisible when changing colours to dark backgrounds in Firefox (https://bugzilla.mozilla.org/show_bug.cgi?id=1335476)
// as background-color and color need to always be set together, color should not be set either
border: $govuk-border-width-form-element solid $govuk-input-border-colour;
border-radius: 0;
// Disable inner shadow and remove rounded corners
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.govuk-input::-webkit-outer-spin-button,
.govuk-input::-webkit-inner-spin-button {
margin: 0;
-webkit-appearance: none;
}
.govuk-input[type="number"] {
-moz-appearance: textfield;
}
.govuk-input--error {
border: $govuk-border-width-form-element-error solid $govuk-error-colour;
}
// The ex measurements are based on the number of W's that can fit inside the input
// Extra space is left on the right hand side to allow for the Safari prefill icon
// Linear regression estimation based on visual tests: y = 1.76 + 1.81x
.govuk-input--width-30 {
max-width: 56ex + 3ex;
}
.govuk-input--width-20 {
max-width: 38ex + 3ex;
}
.govuk-input--width-10 {
max-width: 20ex + 3ex;
}
.govuk-input--width-5 {
max-width: 10.8ex;
}
.govuk-input--width-4 {
max-width: 9ex;
}
.govuk-input--width-3 {
max-width: 7.2ex;
}
.govuk-input--width-2 {
max-width: 5.4ex;
}
}

View File

@@ -0,0 +1,91 @@
[
{
"name": "id",
"type": "string",
"required": true,
"description": "The id of the input."
},
{
"name": "name",
"type": "string",
"required": true,
"description": "The name of the input, which is submitted with the form data."
},
{
"name": "type",
"type": "string",
"required": false,
"description": "Type of input control to render. Defaults to \"text\"."
},
{
"name": "value",
"type": "string",
"required": false,
"description": "Optional initial value of the input."
},
{
"name": "describedBy",
"type": "string",
"required": false,
"description": "One or more element IDs to add to the `aria-describedby` attribute, used to provide additional descriptive information for screenreader users."
},
{
"name": "label",
"type": "object",
"required": true,
"description": "Options for the label component.",
"isComponent": true
},
{
"name": "hint",
"type": "object",
"required": false,
"description": "Options for the hint component.",
"isComponent": true
},
{
"name": "errorMessage",
"type": "object",
"required": false,
"description": "Options for the errorMessage component.",
"isComponent": true
},
{
"name": "formGroup",
"type": "object",
"required": false,
"description": "Options for the form-group wrapper",
"params": [
{
"name": "classes",
"type": "string",
"required": false,
"description": "Classes to add to the form group (e.g. to show error state for the whole group)"
}
]
},
{
"name": "classes",
"type": "string",
"required": false,
"description": "Classes to add to the input."
},
{
"name": "autocomplete",
"type": "string",
"required": false,
"description": "Attribute to [identify input purpose](https://www.w3.org/WAI/WCAG21/Understanding/identify-input-purpose.html), for instance \"postal-code\" or \"username\". See [autofill](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill) for full list of attributes that can be used."
},
{
"name": "pattern",
"type": "string",
"required": false,
"description": "Attribute to [provide a regular expression pattern](https://www.w3.org/TR/html51/sec-forms.html#the-pattern-attribute), used to match allowed character combinations for the input value."
},
{
"name": "attributes",
"type": "object",
"required": false,
"description": "HTML attributes (for example data attributes) to add to the anchor tag."
}
]

View File

@@ -0,0 +1,3 @@
{% macro govukInput(params) %}
{%- include "./template.njk" -%}
{% endmacro %}

View File

@@ -0,0 +1,46 @@
{% from "../error-message/macro.njk" import govukErrorMessage -%}
{% from "../hint/macro.njk" import govukHint %}
{% from "../label/macro.njk" import govukLabel %}
{#- a record of other elements that we need to associate with the input using
aria-describedby for example hints or error messages -#}
{% set describedBy = params.describedBy if params.describedBy else "" %}
<div class="govuk-form-group {%- if params.errorMessage %} govuk-form-group--error{% endif %} {%- if params.formGroup.classes %} {{ params.formGroup.classes }}{% endif %}">
{{ govukLabel({
html: params.label.html,
text: params.label.text,
classes: params.label.classes,
isPageHeading: params.label.isPageHeading,
attributes: params.label.attributes,
for: params.id
}) | indent(2) | trim }}
{% if params.hint %}
{% set hintId = params.id + '-hint' %}
{% set describedBy = describedBy + ' ' + hintId if describedBy else hintId %}
{{ govukHint({
id: hintId,
classes: params.hint.classes,
attributes: params.hint.attributes,
html: params.hint.html,
text: params.hint.text
}) | indent(2) | trim }}
{% endif %}
{% if params.errorMessage %}
{% set errorId = params.id + '-error' %}
{% set describedBy = describedBy + ' ' + errorId if describedBy else errorId %}
{{ govukErrorMessage({
id: errorId,
classes: params.errorMessage.classes,
attributes: params.errorMessage.attributes,
html: params.errorMessage.html,
text: params.errorMessage.text,
visuallyHiddenText: params.errorMessage.visuallyHiddenText
}) | indent(2) | trim }}
{% endif %}
<input class="govuk-input {%- if params.classes %} {{ params.classes }}{% endif %} {%- if params.errorMessage %} govuk-input--error{% endif %}" id="{{ params.id }}" name="{{ params.name }}" type="{{ params.type | default('text') }}"
{%- 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 %}
{%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor -%}>
</div>