Skip to content

Commit

Permalink
Add date input coomponent
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Nov 21, 2023
1 parent fbdc4fd commit e4b1833
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/actions/prototype-kit-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ runs:
echo -e "{% from \"nationalarchives/components/card/macro.njk\" import tnaCard %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html &&
echo -e "{% from \"nationalarchives/components/checkboxes/macro.njk\" import tnaCheckboxes %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html &&
echo -e "{% from \"nationalarchives/components/cookie-banner/macro.njk\" import tnaCookieBanner %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html &&
echo -e "{% from \"nationalarchives/components/date-input/macro.njk\" import tnaDateInput %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html &&
echo -e "{% from \"nationalarchives/components/date-search/macro.njk\" import tnaDateSearch %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html &&
echo -e "{% from \"nationalarchives/components/featured-records/macro.njk\" import tnaFeaturedRecords %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html &&
echo -e "{% from \"nationalarchives/components/filters/macro.njk\" import tnaFilters %}\n$(cat prototype/app/views/index.html)" > prototype/app/views/index.html &&
Expand Down Expand Up @@ -70,6 +71,7 @@ runs:
echo "{{ tnaCard({}) }}" >> prototype/app/views/index.html &&
echo "{{ tnaCheckboxes({}) }}" >> prototype/app/views/index.html &&
echo "{{ tnaCookieBanner({}) }}" >> prototype/app/views/index.html &&
echo "{{ tnaDateInput({}) }}" >> prototype/app/views/index.html &&
echo "{{ tnaDateSearch({}) }}" >> prototype/app/views/index.html &&
echo "{{ tnaFeaturedRecords({}) }}" >> prototype/app/views/index.html &&
echo "{{ tnaFilters({}) }}" >> prototype/app/views/index.html &&
Expand Down
4 changes: 2 additions & 2 deletions .storybook/test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const { injectAxe, checkA11y } = require("axe-playwright");
const DEFAULT_VP_SIZE = { width: 1280, height: 720 };

module.exports = {
async preRender(page, story) {
async preVisit(page, story) {
const context = await getStoryContext(page, story);
const vpName = context.parameters?.viewport?.defaultViewport;
const vpParams = customViewports[vpName];
Expand All @@ -85,7 +85,7 @@ module.exports = {
}
await injectAxe(page);
},
async postRender(page, story) {
async postVisit(page) {
await checkA11y(page, "#storybook-root", a11yConfig, "v2");
},
};
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Form element components have been added: checkboxes, date search, search field, select, text input and textarea
- Form element components have been added: checkboxes, date input, date search, radios, search field, select, text input and textarea
- High contrast support for chip lists with icons
- Allow custom cookie path to be passed to cookie banner

Expand Down
1 change: 1 addition & 0 deletions src/nationalarchives/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@use "card";
@use "checkboxes";
@use "cookie-banner";
@use "date-input";
@use "date-search";
@use "featured-records";
@use "filters";
Expand Down
1 change: 1 addition & 0 deletions src/nationalarchives/components/date-input/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@use "date-input";
48 changes: 48 additions & 0 deletions src/nationalarchives/components/date-input/date-input.scss
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 src/nationalarchives/components/date-input/date-input.stories.js
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",
};
4 changes: 4 additions & 0 deletions src/nationalarchives/components/date-input/fixtures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"component": "date-input",
"fixtures": []
}
14 changes: 14 additions & 0 deletions src/nationalarchives/components/date-input/macro-options.json
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."
}
]
3 changes: 3 additions & 0 deletions src/nationalarchives/components/date-input/macro.njk
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 %}
45 changes: 45 additions & 0 deletions src/nationalarchives/components/date-input/template.njk
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>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"name": "classes",
"type": "string",
"required": false,
"description": "Classes to add to the date search input."
"description": "Classes to add to the date date search."
},
{
"name": "attributes",
"type": "object",
"required": false,
"description": "HTML attributes (for example data attributes) to add to the date search input."
"description": "HTML attributes (for example data attributes) to add to the date date search."
}
]
7 changes: 5 additions & 2 deletions src/nationalarchives/stories/utilities/forms/forms.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Meta, Canvas } from "@storybook/blocks";
import * as TextInputStories from "../../../components/text-input/text-input.stories";
import * as TextareaStories from "../../../components/textarea/textarea.stories";
import * as DateInputStories from "../../../components/date-input/date-input.stories";
import * as DateSearchStories from "../../../components/date-search/date-search.stories";
import * as SelectStories from "../../../components/select/select.stories";
import * as RadiosStories from "../../../components/radios/radios.stories";
Expand All @@ -13,22 +14,24 @@ import * as SearchFieldStories from "../../../components/search-field/search-fie

<Canvas of={TextInputStories.Standard} />
<Canvas of={TextareaStories.Standard} />
<Canvas of={DateSearchStories.Standard} />
<Canvas of={SelectStories.Standard} />
<Canvas of={RadiosStories.Standard} />
<Canvas of={RadiosStories.Small} />
<Canvas of={CheckboxesStories.Standard} />
<Canvas of={CheckboxesStories.Small} />
<Canvas of={DateSearchStories.Standard} />
<Canvas of={DateInputStories.Standard} />
<Canvas of={SearchFieldStories.Standard} />

## Inline

<Canvas of={TextInputStories.Inline} />
<Canvas of={TextareaStories.Inline} />
<Canvas of={DateSearchStories.Inline} />
<Canvas of={SelectStories.Inline} />
<Canvas of={RadiosStories.Inline} />
<Canvas of={CheckboxesStories.Inline} />
<Canvas of={DateSearchStories.Inline} />
<Canvas of={DateInputStories.Inline} />

## Structure

Expand Down
1 change: 1 addition & 0 deletions tasks/test-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const checkExists = [
...componentFiles("card"),
...componentFiles("checkboxes"),
...componentFiles("cookie-banner", "CookieBanner"),
...componentFiles("date-input"),
...componentFiles("date-search"),
...componentFiles("featured-records"),
...componentFiles("filters"),
Expand Down

0 comments on commit e4b1833

Please sign in to comment.