mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-25 00:33:58 -04:00
move vendored uk components to templates
This commit is contained in:
15
app/templates/components/uk_components/textarea/README.md
Normal file
15
app/templates/components/uk_components/textarea/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Textarea
|
||||
|
||||
## 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 textarea component in your service in the [GOV.UK Design System](https://design-system.service.gov.uk/components/textarea).
|
||||
|
||||
## 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/textarea/#options-example-default) for details.
|
||||
@@ -0,0 +1,32 @@
|
||||
@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/textarea") {
|
||||
.govuk-textarea {
|
||||
@include govuk-font($size: 19, $line-height: 1.25);
|
||||
@include govuk-focusable;
|
||||
|
||||
box-sizing: border-box; // should this be global?
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-height: 40px;
|
||||
@include govuk-responsive-margin(6, "bottom");
|
||||
padding: govuk-spacing(1);
|
||||
|
||||
resize: vertical;
|
||||
|
||||
border: $govuk-border-width-form-element solid $govuk-input-border-colour;
|
||||
border-radius: 0;
|
||||
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
.govuk-textarea--error {
|
||||
border: $govuk-border-width-form-element-error solid $govuk-error-colour;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
[
|
||||
{
|
||||
"name": "id",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "The id of the textarea."
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "The name of the textarea, which is submitted with the form data."
|
||||
},
|
||||
{
|
||||
"name": "rows",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "Optional number of textarea rows (default is 5 rows)."
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "Optional initial value of the textarea."
|
||||
},
|
||||
{
|
||||
"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 (e.g. text).",
|
||||
"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 textarea."
|
||||
},
|
||||
{
|
||||
"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": "attributes",
|
||||
"type": "object",
|
||||
"required": false,
|
||||
"description": "HTML attributes (for example data attributes) to add to the textarea."
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
{% macro govukTextarea(params) %}
|
||||
{%- include "./template.njk" -%}
|
||||
{% endmacro %}
|
||||
44
app/templates/components/uk_components/textarea/template.njk
Normal file
44
app/templates/components/uk_components/textarea/template.njk
Normal file
@@ -0,0 +1,44 @@
|
||||
{% 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 %}
|
||||
<textarea class="govuk-textarea {{- ' govuk-textarea--error' if params.errorMessage }} {{- ' ' + params.classes if params.classes}}" id="{{ params.id }}" name="{{ params.name }}" rows="{%if params.rows %} {{- params.rows -}} {% else %}5{%endif %}"
|
||||
{%- if describedBy %} aria-describedby="{{ describedBy }}"{% endif %}
|
||||
{%- if params.autocomplete %} autocomplete="{{ params.autocomplete}}"{% endif %}
|
||||
{%- for attribute, value in params.attributes %} {{attribute}}="{{value}}"{% endfor %}>{{ params.value }}</textarea>
|
||||
</div>
|
||||
Reference in New Issue
Block a user