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
46 changes: 44 additions & 2 deletions docs/pages/checkboxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ section: components
variation_groups:
- variations:
- 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>
Expand Down Expand Up @@ -54,20 +62,54 @@ variation_groups:
<input class="a-checkbox" type="checkbox" id="test_checkbox_basic_disabled_selected" disabled checked>
<label class="a-label" for="test_checkbox_basic_disabled_selected">Disabled/selected</label>
</div>

<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: Standard checkbox
variation_specs: ''
- variation_is_deprecated: false
variation_name: Standard 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
Expand Down
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