Skip to content

Commit

Permalink
More updates to form inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Nov 15, 2023
1 parent 581944b commit 16099db
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 41 deletions.
34 changes: 23 additions & 11 deletions src/nationalarchives/components/button/button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const argTypes = {
plain: { control: "boolean" },
iconOnly: { control: "boolean" },
iconOnlyOnMobile: { control: "boolean" },
rightAlignIcon: { control: "boolean" },
buttonElement: { control: "boolean" },
classes: { control: "text" },
attributes: { control: "object" },
Expand Down Expand Up @@ -39,6 +40,7 @@ const Template = ({
plain,
iconOnly,
iconOnlyOnMobile,
rightAlignIcon,
buttonElement,
classes,
attributes,
Expand All @@ -55,6 +57,7 @@ const Template = ({
plain,
iconOnly,
iconOnlyOnMobile,
rightAlignIcon,
buttonElement,
classes,
attributes,
Expand Down Expand Up @@ -84,12 +87,12 @@ Icon.args = {
classes: "tna-button--demo",
};

export const SmallIcon = Template.bind({});
SmallIcon.args = {
text: "Explore the collection",
export const RightAlignedIcon = Template.bind({});
RightAlignedIcon.args = {
text: "Search",
href: "#",
icon: "map-location-dot",
small: true,
icon: "chevron-right",
rightAlignIcon: true,
classes: "tna-button--demo",
};

Expand All @@ -110,21 +113,30 @@ IconOnly.args = {
classes: "tna-button--demo",
};

export const SmallIconOnly = Template.bind({});
SmallIconOnly.args = {
export const Small = Template.bind({});
Small.args = {
text: "Small button",
href: "#",
small: true,
classes: "tna-button--demo",
};

export const SmallWithIcon = Template.bind({});
SmallWithIcon.args = {
text: "Explore the collection",
href: "#",
icon: "map-location-dot",
small: true,
iconOnly: true,
classes: "tna-button--demo",
};

export const Small = Template.bind({});
Small.args = {
text: "Small button",
export const SmallIconOnly = Template.bind({});
SmallIconOnly.args = {
text: "Explore the collection",
href: "#",
icon: "map-location-dot",
small: true,
iconOnly: true,
classes: "tna-button--demo",
};

Expand Down
6 changes: 6 additions & 0 deletions src/nationalarchives/components/button/macro-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
"required": false,
"description": ""
},
{
"name": "rightAlignIcon",
"type": "boolean",
"required": false,
"description": ""
},
{
"name": "buttonElement",
"type": "boolean",
Expand Down
3 changes: 3 additions & 0 deletions src/nationalarchives/components/button/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
{%- if params.iconOnlyOnMobile -%}
{%- set buttonClasses = buttonClasses.concat('tna-button--icon-only-mobile') -%}
{%- endif -%}
{%- if params.rightAlignIcon -%}
{%- set buttonClasses = buttonClasses.concat('tna-button--icon-right') -%}
{%- endif -%}
<{{ 'button' if params.buttonElement else 'a' }}{%- if not params.buttonElement %} href="{{ params.href }}"{%- endif %} class="tna-button {{ buttonClasses | join(' ') }}"{%- if not params.buttonElement %} role="button"{%- endif -%}{%- if params.title %} title="{{ params.title }}"{% endif %}{% for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
{%- if params.brandIcon %}
<i class="fa-brands fa-fw fa-{{ params.brandIcon }}" aria-hidden="true"></i>
Expand Down
58 changes: 54 additions & 4 deletions src/nationalarchives/components/checkboxes/checkboxes.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ 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"] },
headingSize: { control: "inline-radio", options: ["s", "m", "l", "xl"] },
name: { control: "text" },
hint: { control: "text" },
error: { control: "object" },
items: { control: "object" },
small: { control: "boolean" },
classes: { control: "text" },
Expand All @@ -30,6 +31,7 @@ const Template = ({
headingSize,
name,
hint,
error,
items,
small,
classes,
Expand All @@ -42,6 +44,7 @@ const Template = ({
headingSize,
name,
hint,
error,
items,
small,
classes,
Expand All @@ -55,7 +58,6 @@ Standard.args = {
headingLevel: 4,
headingSize: "m",
name: "categories1",
hint: "Select all that apply.",
items: [
{
text: "Alpha",
Expand All @@ -79,7 +81,6 @@ Small.args = {
headingLevel: 4,
headingSize: "m",
name: "categories2",
hint: "Select all that apply.",
items: [
{
text: "Admiralty, Navy, Royal Marines, and Coastguard",
Expand Down Expand Up @@ -132,7 +133,6 @@ Preselected.args = {
headingLevel: 4,
headingSize: "m",
name: "categories3",
hint: "Select all that apply.",
items: [
{
text: "Alpha",
Expand All @@ -150,3 +150,53 @@ Preselected.args = {
],
classes: "tna-checkboxes--demo",
};

export const WithHint = Template.bind({});
WithHint.args = {
label: "Categories",
headingLevel: 4,
headingSize: "m",
name: "categories4",
hint: "Select all that apply.",
items: [
{
text: "Alpha",
value: "alpha",
},
{
text: "Beta",
value: "beta",
},
{
text: "Gamma",
value: "gamma",
},
],
classes: "tna-checkboxes--demo",
};

export const Error = Template.bind({});
Error.args = {
label: "Categories",
headingLevel: 4,
headingSize: "m",
name: "categories5",
error: {
text: "You must select a category",
},
items: [
{
text: "Alpha",
value: "alpha",
},
{
text: "Beta",
value: "beta",
},
{
text: "Gamma",
value: "gamma",
},
],
classes: "tna-checkboxes--demo",
};
9 changes: 7 additions & 2 deletions src/nationalarchives/components/checkboxes/template.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{%- set containerClasses = [params.classes] if params.classes else [] -%}
<div class="tna-form__group {{ containerClasses | join(' ') }}"{% for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
<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.name }}-hint"{% endif %}>
<legend class="tna-form__legend">
<h{{ params.headingLevel }} class="tna-form__heading tna-form__heading--{{ params.headingSize }}">
<h{{ params.headingLevel }} class="tna-form__heading tna-form__heading--{{ params.headingSize or 'm' }}">
{{ params.label }}
</h{{ params.headingLevel }}>
</legend>
Expand All @@ -11,6 +11,11 @@
{{ params.hint }}
</div>
{%- 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 class="tna-checkboxes{% if params.small %} tna-checkboxes--small{% endif %}">
{%- for item in params.items %}
<div class="tna-checkboxes__item">
Expand Down
58 changes: 54 additions & 4 deletions src/nationalarchives/components/radios/radios.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ 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"] },
headingSize: { control: "inline-radio", options: ["s", "m", "l", "xl"] },
name: { control: "text" },
hint: { control: "text" },
error: { control: "object" },
items: { control: "object" },
selected: { control: "text" },
small: { control: "boolean" },
Expand All @@ -31,6 +32,7 @@ const Template = ({
headingSize,
name,
hint,
error,
items,
selected,
small,
Expand All @@ -44,6 +46,7 @@ const Template = ({
headingSize,
name,
hint,
error,
items,
selected,
small,
Expand All @@ -58,7 +61,6 @@ Standard.args = {
headingLevel: 4,
headingSize: "m",
name: "type1",
hint: "You can only select one.",
items: [
{
text: "Audio",
Expand All @@ -82,7 +84,6 @@ Small.args = {
headingLevel: 4,
headingSize: "m",
name: "type2",
hint: "You can only select one.",
items: [
{
text: "Admiralty, Navy, Royal Marines, and Coastguard",
Expand Down Expand Up @@ -135,7 +136,6 @@ Preselected.args = {
headingLevel: 4,
headingSize: "m",
name: "type3",
hint: "You can only select one.",
items: [
{
text: "Audio",
Expand All @@ -153,3 +153,53 @@ Preselected.args = {
selected: "image",
classes: "tna-radios--demo",
};

export const WithHint = Template.bind({});
WithHint.args = {
label: "Type",
headingLevel: 4,
headingSize: "m",
name: "type4",
hint: "You can only select one.",
items: [
{
text: "Audio",
value: "audio",
},
{
text: "Image",
value: "image",
},
{
text: "Video",
value: "video",
},
],
classes: "tna-radios--demo",
};

export const Error = Template.bind({});
Error.args = {
label: "Type",
headingLevel: 4,
headingSize: "m",
name: "type5",
error: {
text: "You must select a type",
},
items: [
{
text: "Audio",
value: "audio",
},
{
text: "Image",
value: "image",
},
{
text: "Video",
value: "video",
},
],
classes: "tna-radios--demo",
};
9 changes: 7 additions & 2 deletions src/nationalarchives/components/radios/template.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{%- set containerClasses = [params.classes] if params.classes else [] -%}
<div class="tna-form__group {{ containerClasses | join(' ') }}"{% for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
<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.name }}-hint"{% endif %}>
<legend class="tna-form__legend">
<h{{ params.headingLevel }} class="tna-form__heading tna-form__heading--{{ params.headingSize }}">
<h{{ params.headingLevel }} class="tna-form__heading tna-form__heading--{{ params.headingSize or 'm' }}">
{{ params.label }}
</h{{ params.headingLevel }}>
</legend>
Expand All @@ -11,6 +11,11 @@
{{ params.hint }}
</div>
{%- 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 class="tna-radios{% if params.small %} tna-radios--small{% endif %}">
{%- for item in params.items %}
<div class="tna-radios__item">
Expand Down
17 changes: 17 additions & 0 deletions src/nationalarchives/components/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@use "../../utilities";

.tna-select {
max-width: 100%;
height: calc(2rem + 6px);
margin-top: 1rem;
padding: 0 0.5rem 0 0.25rem;
Expand All @@ -17,4 +18,20 @@

@include colour.colour-border("input-border", forms.$form-field-border-width);
border-radius: 0;

&--s {
width: 10rem;
}

&--m {
width: 20rem;
}

&--l {
width: 40rem;
}

&--xl {
width: 80rem;
}
}
Loading

0 comments on commit 16099db

Please sign in to comment.