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

Styling: Checkbox States (Error/Warning/Success) #1889

Merged
merged 9 commits into from
Jan 23, 2024
62 changes: 52 additions & 10 deletions docs/pages/checkboxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ layout: variation
section: components
variation_groups:
- variations:
- variation_code_snippet: >+
<h4> States</h4><div class="m-form-field m-form-field__checkbox">
- variation_code_snippet: >-
<!--States are shown for demonstration purposes only-->

<h4>

States

</h4>

<div class="m-form-field m-form-field__checkbox">
<input class="a-checkbox" type="checkbox" id="test_checkbox">
<label class="a-label" for="test_checkbox">Default</label>
</div>
Expand Down Expand Up @@ -55,24 +63,58 @@ variation_groups:
<label class="a-label" for="test_checkbox_basic_disabled_selected">Disabled/selected</label>
</div>

variation_description: ""
<br><br>

<h4>

Validation status

</h4>

<!--Success-->

<div class="m-form-field m-form-field__checkbox m-form-field__checkbox__success">
<input class="a-checkbox" type="checkbox" id="test_checkbox_success">
<label class="a-label" for="test_checkbox_success">Success</label>
</div>

<br>

<!--Warning-->

<div class="m-form-field m-form-field__checkbox m-form-field__checkbox__warning">
<input class="a-checkbox" type="checkbox" id="test_checkbox_warning">
<label class="a-label" for="test_checkbox_warning">Warning</label>
</div>

<br>

<!--Error-->

<div class="m-form-field m-form-field__checkbox m-form-field__checkbox__error">
<input class="a-checkbox" type="checkbox" id="test_checkbox_error">
<label class="a-label" for="test_checkbox_error">Error</label>
</div>
variation_description: ''
variation_name: Checkbox
variation_specs: ""
variation_specs: ''
- variation_is_deprecated: false
variation_name: Checkbox (with helper text)
variation_code_snippet: >-
<div class="m-form-field m-form-field__checkbox">
<input class="a-radio" type="checkbox" id="test_checkbox_basic_helper">
<input class="a-checkbox" type="checkbox" id="test_checkbox_basic_helper">
<label class="a-label" for="test_checkbox_basic_helper">
Checkbox label
Checkbox label
<small class="a-label_helper">
(This is optional helper text)
</small>
</label>
</label>
</div>
- variation_is_deprecated: false
variation_name: Large target area checkbox
variation_description: For better usability, consider using the checkboxes with
variation_description:
For better usability, consider using the checkboxes with
large target areas. These are easier to interact with (especially on
smaller screens) and harder to miss. They are especially desirable
when the form will have heavy mobile usage. Given the amount of real
Expand Down Expand Up @@ -144,7 +186,7 @@ variation_groups:
</div>

-->
variation_specs: ""
variation_specs: ''
- variation_is_deprecated: false
variation_name: Large target area checkbox (with helper text)
variation_code_snippet: >-
Expand Down Expand Up @@ -176,7 +218,7 @@ description: Use checkboxes when the user can select more than one option from a
group. Make clear with helper text that this is the case. Use [radio
buttons](/design-system/components/radio-buttons) when the user can select
only one choice from a group.
use_cases: ""
use_cases: ''
behavior: >-
Selecting the checkbox or touching the label text next to it should toggle the
state of the checkbox on and off.
Expand All @@ -186,5 +228,5 @@ behavior: >-
accessibility: To optimize screen reader accessibility, lay out checkboxes
vertically rather than horizontally.
last_updated: 2019-09-17T14:30:15.293Z
research: ""
research: ''
---
108 changes: 108 additions & 0 deletions packages/cfpb-forms/src/molecules/form-fields.less
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,114 @@
.u-svg-inline-bg( 'approved', @gray );
}
}

&__error {
.a-label {
&::before {
border-color: @input-border__error;
outline: 1px solid @input-border__error;
}

&:hover::before,
&.hover::before {
border-color: @input-border__hover;
outline-color: @input-border__hover;
}
}

.a-checkbox {
&:hover + .a-label::before,
&.hover + .a-label::before {
border-color: @input-border__hover;
outline-color: @input-border__hover;
}

&:focus + .a-label::before,
&.focus + .a-label::before {
border-color: @input-border__error;
box-shadow: 0 0 0 1px @input-border__error;
outline-color: @input-border__error;
}

&:focus + .a-label,
&.focus + .a-label {
outline: 1px dotted @input-border__error;
outline-offset: 1px;
}
}
}

&__warning {
.a-label {
&::before {
border-color: @input-border__warning;
outline: 1px solid @input-border__warning;
}

&:hover::before,
&.hover::before {
border-color: @input-border__hover;
outline-color: @input-border__hover;
}
}

.a-checkbox {
&:hover + .a-label::before,
&.hover + .a-label::before {
border-color: @input-border__hover;
outline-color: @input-border__hover;
}

&:focus + .a-label::before,
&.focus + .a-label::before {
border-color: @input-border__warning;
box-shadow: 0 0 0 1px @input-border__warning;
outline-color: @input-border__warning;
}

&:focus + .a-label,
&.focus + .a-label {
outline: 1px dotted @input-border__warning;
outline-offset: 1px;
}
}
}

&__success {
.a-label {
&::before {
border-color: @input-border__success;
outline: 1px solid @input-border__success;
}

&:hover::before,
&.hover::before {
border-color: @input-border__hover;
outline-color: @input-border__hover;
}
}

.a-checkbox {
&:hover + .a-label::before,
&.hover + .a-label::before {
border-color: @input-border__hover;
outline-color: @input-border__hover;
}

&:focus + .a-label::before,
&.focus + .a-label::before {
border-color: @input-border__success;
box-shadow: 0 0 0 1px @input-border__success;
outline-color: @input-border__success;
}

&:focus + .a-label,
&.focus + .a-label {
outline: 1px dotted @input-border__success;
outline-offset: 1px;
}
}
}
}

&__radio {
Expand Down
Loading