-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
251 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@use "date-input"; |
48 changes: 48 additions & 0 deletions
48
src/nationalarchives/components/date-input/date-input.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
@use "../../variables/forms"; | ||
@use "../../tools/colour"; | ||
@use "../../tools/typography"; | ||
@use "../../utilities"; | ||
|
||
.tna-date-input { | ||
display: flex; | ||
gap: 1rem; | ||
|
||
&__item { | ||
&-label { | ||
display: block; | ||
|
||
@include typography.relative-font-size(16); | ||
} | ||
|
||
&-input { | ||
width: 3rem; | ||
padding: 0 0.375rem; | ||
|
||
display: block; | ||
box-sizing: border-box; | ||
|
||
@include colour.colour-font("input-foreground"); | ||
font-size: inherit; | ||
line-height: 2rem; | ||
|
||
@include colour.colour-background("input-background"); | ||
|
||
@include colour.colour-border( | ||
"input-border", | ||
forms.$form-field-border-width | ||
); | ||
border-radius: 0; | ||
|
||
&--wider { | ||
width: 4.5rem; | ||
} | ||
|
||
.tna-form__group--error & { | ||
@include colour.colour-border("form-error"); | ||
} | ||
} | ||
} | ||
|
||
&--inline { | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
src/nationalarchives/components/date-input/date-input.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import DateInput from "./template.njk"; | ||
import macroOptions from "./macro-options.json"; | ||
|
||
const argTypes = { | ||
label: { control: "text" }, | ||
headingLevel: { control: { type: "number", min: 1, max: 6 } }, | ||
headingSize: { control: "inline-radio", options: ["s", "m", "l", "xl"] }, | ||
id: { control: "text" }, | ||
name: { control: "text" }, | ||
hint: { control: "text" }, | ||
value: { control: "object" }, | ||
error: { control: "object" }, | ||
maxWidth: { control: "boolean" }, | ||
inline: { control: "boolean" }, | ||
classes: { control: "text" }, | ||
formGroupClasses: { control: "text" }, | ||
attributes: { control: "object" }, | ||
}; | ||
|
||
Object.keys(argTypes).forEach((argType) => { | ||
argTypes[argType].description = macroOptions.find( | ||
(option) => option.name === argType, | ||
)?.description; | ||
}); | ||
|
||
export default { | ||
title: "Components/Date input", | ||
argTypes, | ||
}; | ||
|
||
const Template = ({ | ||
label, | ||
headingLevel, | ||
headingSize, | ||
id, | ||
name, | ||
hint, | ||
value, | ||
error, | ||
maxWidth, | ||
inline, | ||
classes, | ||
formGroupClasses, | ||
attributes, | ||
}) => | ||
DateInput({ | ||
params: { | ||
label, | ||
headingLevel, | ||
headingSize, | ||
id, | ||
name, | ||
hint, | ||
value, | ||
error, | ||
maxWidth, | ||
inline, | ||
classes, | ||
formGroupClasses, | ||
attributes, | ||
}, | ||
}); | ||
|
||
export const Standard = Template.bind({}); | ||
Standard.args = { | ||
label: "Enter a start date", | ||
headingLevel: 4, | ||
headingSize: "m", | ||
id: "date11", | ||
name: "date11", | ||
classes: "tna-date-search--demo", | ||
}; | ||
|
||
export const Predefined = Template.bind({}); | ||
Predefined.args = { | ||
label: "Enter a start date", | ||
headingLevel: 4, | ||
headingSize: "m", | ||
id: "date12", | ||
name: "date12", | ||
value: { | ||
day: "24", | ||
month: "09", | ||
year: "1986", | ||
}, | ||
classes: "tna-date-search--demo", | ||
}; | ||
|
||
export const WithHint = Template.bind({}); | ||
WithHint.args = { | ||
label: "Enter a start date", | ||
headingLevel: 4, | ||
headingSize: "m", | ||
id: "date13", | ||
name: "date13", | ||
hint: "The earliest date of the record", | ||
classes: "tna-date-search--demo", | ||
}; | ||
|
||
export const Error = Template.bind({}); | ||
Error.args = { | ||
label: "Enter a start date", | ||
headingLevel: 4, | ||
headingSize: "m", | ||
id: "date14", | ||
name: "date14", | ||
error: { | ||
text: "Date is not valid", | ||
}, | ||
classes: "tna-date-search--demo", | ||
}; | ||
|
||
export const Inline = Template.bind({}); | ||
Inline.args = { | ||
label: "Enter a start date", | ||
headingLevel: 4, | ||
headingSize: "xs", | ||
id: "date15", | ||
name: "date15", | ||
inline: true, | ||
classes: "tna-date-search--demo", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"component": "date-input", | ||
"fixtures": [] | ||
} |
14 changes: 14 additions & 0 deletions
14
src/nationalarchives/components/date-input/macro-options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"name": "classes", | ||
"type": "string", | ||
"required": false, | ||
"description": "Classes to add to the date date input." | ||
}, | ||
{ | ||
"name": "attributes", | ||
"type": "object", | ||
"required": false, | ||
"description": "HTML attributes (for example data attributes) to add to the date date input." | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% macro tnaDateInput(params) %} | ||
{%- include "nationalarchives/components/date-input/template.njk" -%} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{%- set containerClasses = [params.classes] if params.classes else [] -%} | ||
{%- if params.inline -%} | ||
{%- set containerClasses = containerClasses.concat('tna-form__group--inline') -%} | ||
{%- endif -%} | ||
<div class="tna-form__group{% if params.error %} tna-form__group--error{% endif %} {{ containerClasses | join(' ') }}"{% for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}> | ||
<fieldset class="tna-form__fieldset"{% if params.hint %} aria-describedby="tna-form__{{ params.id }}-hint"{% endif %}> | ||
<div class="tna-form__group-contents"> | ||
<legend class="tna-form__legend"> | ||
<h{{ params.headingLevel }} class="tna-form__heading tna-form__heading--{{ params.headingSize or 'm' }}"> | ||
{{ params.label }} | ||
</h{{ params.headingLevel }}> | ||
</legend> | ||
{%- if params.hint %} | ||
<p id="tna-form__{{ params.id }}-hint" class="tna-form__hint"> | ||
{{ params.hint }} | ||
</p> | ||
{%- endif %} | ||
{%- if params.error %} | ||
<p id="tna-form__{{ params.id }}-error" class="tna-form__error-message"> | ||
<span class="tna-!--visually-hidden">Error:</span> {{ params.error.text }} | ||
</p> | ||
{%- endif %} | ||
</div> | ||
<div class="tna-date-input{% if params.inline %} tna-date-input--inline{% endif %}"> | ||
<div class="tna-date-input__item"> | ||
<label for="tna-form__{{ params.id }}-day" class="tna-date-input__item-label"> | ||
Day | ||
</label> | ||
<input type="text" id="tna-form__{{ params.id }}-day" value="{{ params.value.day if params.value }}" name="{{ params.name }}-day" class="tna-date-input__item-input" type="text" inputmode="numeric"> | ||
</div> | ||
<div class="tna-date-input__item"> | ||
<label for="tna-form__{{ params.id }}-month" class="tna-date-input__item-label"> | ||
Month | ||
</label> | ||
<input type="text" id="tna-form__{{ params.id }}-month" value="{{ params.value.month if params.value }}" name="{{ params.name }}-month" class="tna-date-input__item-input" type="text" inputmode="numeric"> | ||
</div> | ||
<div class="tna-date-input__item"> | ||
<label for="tna-form__{{ params.id }}-year" class="tna-date-input__item-label"> | ||
Year | ||
</label> | ||
<input type="text" id="tna-form__{{ params.id }}-year" value="{{ params.value.year if params.value }}" name="{{ params.name }}-year" class="tna-date-input__item-input tna-date-input__item-input--wider" type="text" inputmode="numeric"> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters