diff --git a/src/components/_all.scss b/src/components/_all.scss index 970985817..a8538defb 100644 --- a/src/components/_all.scss +++ b/src/components/_all.scss @@ -5,6 +5,7 @@ @import 'callout/callout'; @import 'card/card'; @import 'content-block/content-block'; +@import 'date-input/date-input'; @import 'dialog/dialog'; @import 'file-upload/file-upload'; @import 'filters/filters'; diff --git a/src/components/date-input/_date-input.hbs b/src/components/date-input/_date-input.hbs new file mode 100644 index 000000000..96aa834bb --- /dev/null +++ b/src/components/date-input/_date-input.hbs @@ -0,0 +1,25 @@ +
+ + {{label}}{{#if required}} (required){{/if}}{{#if helper-text}} + {{helper-text}}{{/if}} + +
+
+ + +
+
+ + +
+
+ + +
+
+
+{{#if error-text}} +{{error-text}} +{{/if}}{{#if valid-text}} +{{valid-text}} +{{/if}} \ No newline at end of file diff --git a/src/components/date-input/_date-input.scss b/src/components/date-input/_date-input.scss new file mode 100644 index 000000000..5d2759e50 --- /dev/null +++ b/src/components/date-input/_date-input.scss @@ -0,0 +1,25 @@ +.nsw-form { + &__date { + padding: 0; + margin: 0; + border: 0; + + &-wrapper { + display: flex; + width: 100%; + margin: 0 rem(-8px); + + > div { + padding: 0 rem(8px); + } + } + + &-input { + width: rem(74px); + + &--large { + width: rem(116px); + } + } + } +} diff --git a/src/components/date-input/_guidance.hbs b/src/components/date-input/_guidance.hbs new file mode 100644 index 000000000..6a251b14f --- /dev/null +++ b/src/components/date-input/_guidance.hbs @@ -0,0 +1,43 @@ +--- +title: Date input +layout: blank-layout.hbs +--- + +

Usage

+ +

Use the date input component to let users enter memorable dates, like dates of birth. The date input component consists of three fields grouped together, to let users enter a day, month and year.

+ +

This approach is advised in most cases because it allows for precise input and reduces the chances of making mistakes.

+ +

Do:

+ + + +

Do not:

+ + + +

How this component works

+ +

The three fields in the date input component are grouped together in a fieldset with a legend that describes them, as shown in the examples on this page. The legend is usually a question, such as 'What is your date of birth?'.

+ +

Use the autocomplete attribute on the date input component when you're asking for a date of birth. This allows browsers to autofill the information on a user's behalf if they've entered it previously.

+ +

The year input is set to accept only a four-digit number while the month and day inputs can accept up to a two-digit number.

+ +

Accessibility

+

All components are responsive and meet WCAG 2.1 AA accessibility guidelines.

diff --git a/src/components/date-input/blank.hbs b/src/components/date-input/blank.hbs new file mode 100644 index 000000000..ea0e7f56e --- /dev/null +++ b/src/components/date-input/blank.hbs @@ -0,0 +1,41 @@ +--- +title: Date input +width: wide +page: true +--- +{{#>_layout-container}} + +
+
+ {{>_date-input + id="date" + label="Date of birth" + helper-text="For example 08 12 1990" + }} +
+
+ +
+
+ {{>_date-input + id="date-error" + label="Date of birth" + required=true + error-text="This field is required" + helper-text="For example 08 12 1990" + }} +
+
+ +
+
+ {{>_date-input + id="date-success" + label="Date of birth" + valid-text="This field has been validated" + helper-text="For example 08 12 1990" + }} +
+
+ +{{/_layout-container}} diff --git a/src/components/date-input/index.hbs b/src/components/date-input/index.hbs new file mode 100644 index 000000000..9d2e44f26 --- /dev/null +++ b/src/components/date-input/index.hbs @@ -0,0 +1,52 @@ +--- +title: Date input +width: wide +tabs: true +directory: date-input +intro: 'A date input allows users to enter a date.' +figma: 'URL' +meta-description: 'A date input allows users to enter a date.' +meta-index: true +--- + +

Default

+{{#>_docs-example separated=true}} +
+
+ {{>_date-input + id="date" + label="Date of birth" + helper-text="For example 08 12 1990" + }} +
+
+{{/_docs-example}} + +

Error

+{{#>_docs-example separated=true}} +
+
+ {{>_date-input + id="date-error" + label="Date of birth" + required=true + error-text="This field is required" + helper-text="For example 08 12 1990" + }} +
+
+{{/_docs-example}} + +

Success

+{{#>_docs-example separated=true}} +
+
+ {{>_date-input + id="date-success" + label="Date of birth" + valid-text="This field has been validated" + helper-text="For example 08 12 1990" + }} +
+
+{{/_docs-example}} diff --git a/src/main.scss b/src/main.scss index af5b01825..257608a7d 100644 --- a/src/main.scss +++ b/src/main.scss @@ -9,6 +9,7 @@ @import 'components/accordion/accordion'; @import 'components/back-to-top/back-to-top'; +@import 'components/date-input/date-input'; @import 'components/dialog/dialog'; @import 'components/breadcrumbs/breadcrumbs'; @import 'components/button/button';