Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkboxes, Radios, Cards and Links #121

Merged
merged 8 commits into from
May 10, 2024
11 changes: 8 additions & 3 deletions src/components/card/_card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
.card__heading {
@include heading-large($font-size: var(--font-size-h3));

color: var(--color-text-heading);
margin: 0;
line-height: var(--line-heights-tight);
line-height: var(--line-height-tight);

&-link {
@include link;
Expand All @@ -26,12 +27,16 @@
.card__subheading {
@include heading-medium($font-size: var(--font-size-small));

color: var(--colors-grays-500);
color: var(--color-grays-500);
margin: 0 0 var(--spacing-md);
line-height: var(--line-heights-tight);
line-height: var(--line-height-tight);
text-transform: uppercase;
}

.card__body {
color: var(--color-text-body);
}

.card__link {
@include link;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/checkbox/_checkbox-item.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% set labelClasses = checkbox_item_disabled ? 'form-item--checkbox__item--label__disabled' : '' %}

<li class="form-item--checkbox__item">
<input id="checkbox{{ key }}" name="checkbox" type="checkbox" {% if checkbox_item_checked %} checked="{{ checkbox_item_checked }}" {% endif %} {% if checkbox_item_disabled %} disabled="{{ checkbox_item_disabled }}" {% endif %}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider rewriting your if statements for checked and disabled like this:
{{ (checkbox_item_checked) ? 'checked' : '' }}.

Since both checked and disabled are booleans, you can only add them to the HTML if they are needed.

<label for="checkbox{{ key }}" class="form-item--checkbox__item--label {{ labelClasses }}">
<input id="checkbox{{ key }}" name="checkbox" type="checkbox" {% if checkbox_item_checked %} checked="{{ checkbox_item_checked }}" {% endif %} {% if checkbox_item_disabled %} disabled="{{ checkbox_item_disabled }}" {% endif %}>
{{ checkbox_item }}
</label>
</li>
54 changes: 51 additions & 3 deletions src/components/forms/checkbox/_checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,61 @@
.form-item--checkboxes {
display: flex;
flex-flow: column nowrap;
gap: var(--checkbox-gap);
gap: var(--checkbox-spacing-gap);
}

.form-item--checkbox__item--label {
color: var(--checkbox-label);
display: inline-block;
position: relative;
cursor: pointer;
padding-left: calc(var(--spacing-lg) + var(--spacing-sm));
color: var(--checkbox-color-label);
font-size: var(--font-size-caption);

&::before {
content: '';
position: absolute;
left: 0;
top: 5px;
width: 16px;
height: 16px;
border: 1px solid var(--checkbox-button-stroke);
background-color: transparent;
}

&::after {
content: '';
position: absolute;
left: 6px;
top: 7px;
width: 5px;
height: 9px;
border: solid white;
border-width: 0 1px 1px 0;
transform: rotate(45deg);
display: none;
}
}

.form-item--checkbox__item--label__disabled {
color: var(--checkbox-label-disabled);
color: var(--checkbox-color-label-disabled);

&::before {
border-color: var(--checkbox-button-stroke-disabled);
}
}

.form-item--checkbox__item {
input[type='checkbox'] {
@include sr-only;
}

input[type='checkbox']:checked + .form-item--checkbox__item--label::before {
background-color: var(--checkbox-button-fill);
}

input[type='checkbox']:checked + .form-item--checkbox__item--label::after {
display: block;
border-color: white;
}
}
6 changes: 3 additions & 3 deletions src/components/forms/radio/_radio-item.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% set labelClasses = radio_item_disabled ? 'form-item--radio__item--label__disabled' : '' %}

<li class="form-item--radio__item {{ labelClasses }}">
<label for="radio{{ key }}">
<input id="radio{{ key }}" name="radio" type="radio" class="radio" {% if radio_item_checked %} checked="{{ radio_item_checked }}" {% endif %} {% if radio_item_disabled %} disabled="{{ radio_item_disabled }}" {% endif %}>
<li class="form-item--radio__item">
<input id="radio{{ key }}" name="radio" type="radio" class="radio" {% if radio_item_checked %} checked="{{ radio_item_checked }}" {% endif %} {% if radio_item_disabled %} disabled="{{ radio_item_disabled }}" {% endif %}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment about checked and disabled on the checkbox twig file.

<label for="radio{{ key }}" class="form-item--radio__item--label {{ labelClasses }}">
{{ radio_item }}
</label>
</li>
47 changes: 45 additions & 2 deletions src/components/forms/radio/_radio.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,52 @@
}

.form-item--radio__item--label {
color: var(--radio-label);
display: inline-block;
position: relative;
cursor: pointer;
padding-left: calc(var(--spacing-lg) + var(--spacing-sm));
color: var(--radio-color-label);
font-size: var(--font-size-caption);

&::before {
content: '';
position: absolute;
left: 0;
top: 5px;
width: 16px;
height: 16px;
border: 1px solid var(--checkbox-button-stroke);
background-color: transparent;
border-radius: 50%;
}

&::after {
content: '';
position: absolute;
left: 4px;
top: 9px;
width: 8px;
height: 8px;
display: none;
background-color: var(--radio-color-button-fill);
border-radius: 50%;
}
}

.form-item--radio__item--label__disabled {
color: var(--radio-label-disabled);
color: var(--radio-color-button-fill-disabled);

&::before {
border-color: var(--radio-button-stroke-disabled);
}
}

.form-item--radio__item {
input[type='radio'] {
@include sr-only;
}

input[type='radio']:checked + .form-item--radio__item--label::after {
display: block;
}
}
2 changes: 1 addition & 1 deletion src/components/tokens/_tokens.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Do not edit directly
* Generated on Fri, 10 May 2024 20:34:40 GMT
* Generated on Fri, 10 May 2024 20:46:35 GMT
*/

:root {
Expand Down
18 changes: 15 additions & 3 deletions src/stylesheets/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,22 @@ $outer-container-break: var(--breakpoint-sm);
}

@mixin link {
color: var(--link-default);
color: var(--link-color-default);
transition: all .15s;

&:hover {
color: var(--link-hover);
color: var(--link-color-hover);
}
}
}

@mixin sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}