privacyguides.org/_sass/bootstrap/mixins/_forms.scss

178 lines
5.0 KiB
SCSS
Raw Normal View History

2020-04-28 17:09:22 -04:00
// Form control focus state
//
// Generate a customized focus state and for any input with the specified color,
// which defaults to the `$input-focus-border-color` variable.
//
// We highly encourage you to not customize the default value, but instead use
// this to tweak colors on an as-needed basis. This aesthetic change is based on
// WebKit's default styles, but applicable to a wider range of browsers. Its
// usability and accessibility should be taken into account with any change.
//
// Example usage: change the default blue border and shadow to white for better
// contrast against a dark gray background.
2020-04-28 17:14:23 -04:00
@mixin form-control-focus($ignore-warning: false) {
2020-04-28 17:09:22 -04:00
&:focus {
color: $input-focus-color;
background-color: $input-focus-bg;
border-color: $input-focus-border-color;
outline: 0;
// Avoid using mixin so we can pass custom focus shadow properly
@if $enable-shadows {
box-shadow: $input-box-shadow, $input-focus-box-shadow;
} @else {
box-shadow: $input-focus-box-shadow;
}
}
2020-04-28 17:14:23 -04:00
@include deprecate("The `form-control-focus()` mixin", "v4.4.0", "v5", $ignore-warning);
2020-04-28 17:09:22 -04:00
}
2020-04-28 17:14:23 -04:00
// This mixin uses an `if()` technique to be compatible with Dart Sass
// See https://github.com/sass/sass/issues/1873#issuecomment-152293725 for more details
@mixin form-validation-state-selector($state) {
@if ($state == "valid" or $state == "invalid") {
.was-validated #{if(&, "&", "")}:#{$state},
#{if(&, "&", "")}.is-#{$state} {
@content;
}
} @else {
#{if(&, "&", "")}.is-#{$state} {
@content;
}
}
}
2020-04-28 17:09:22 -04:00
@mixin form-validation-state($state, $color, $icon) {
.#{$state}-feedback {
display: none;
width: 100%;
margin-top: $form-feedback-margin-top;
@include font-size($form-feedback-font-size);
color: $color;
}
.#{$state}-tooltip {
position: absolute;
top: 100%;
z-index: 5;
display: none;
max-width: 100%; // Contain to parent when possible
padding: $form-feedback-tooltip-padding-y $form-feedback-tooltip-padding-x;
margin-top: .1rem;
@include font-size($form-feedback-tooltip-font-size);
line-height: $form-feedback-tooltip-line-height;
color: color-yiq($color);
background-color: rgba($color, $form-feedback-tooltip-opacity);
@include border-radius($form-feedback-tooltip-border-radius);
}
2020-04-28 17:14:23 -04:00
@include form-validation-state-selector($state) {
~ .#{$state}-feedback,
~ .#{$state}-tooltip {
display: block;
}
}
2020-04-28 17:09:22 -04:00
.form-control {
2020-04-28 17:14:23 -04:00
@include form-validation-state-selector($state) {
2020-04-28 17:09:22 -04:00
border-color: $color;
@if $enable-validation-icons {
padding-right: $input-height-inner;
2020-04-28 17:14:23 -04:00
background-image: escape-svg($icon);
2020-04-28 17:09:22 -04:00
background-repeat: no-repeat;
2020-04-28 17:14:23 -04:00
background-position: right $input-height-inner-quarter center;
2020-04-28 17:09:22 -04:00
background-size: $input-height-inner-half $input-height-inner-half;
}
&:focus {
border-color: $color;
box-shadow: 0 0 0 $input-focus-width rgba($color, .25);
}
}
}
// stylelint-disable-next-line selector-no-qualifying-type
textarea.form-control {
2020-04-28 17:14:23 -04:00
@include form-validation-state-selector($state) {
2020-04-28 17:09:22 -04:00
@if $enable-validation-icons {
padding-right: $input-height-inner;
background-position: top $input-height-inner-quarter right $input-height-inner-quarter;
}
}
}
.custom-select {
2020-04-28 17:14:23 -04:00
@include form-validation-state-selector($state) {
2020-04-28 17:09:22 -04:00
border-color: $color;
@if $enable-validation-icons {
padding-right: $custom-select-feedback-icon-padding-right;
2020-04-28 17:14:23 -04:00
background: $custom-select-background, escape-svg($icon) $custom-select-bg no-repeat $custom-select-feedback-icon-position / $custom-select-feedback-icon-size;
2020-04-28 17:09:22 -04:00
}
&:focus {
border-color: $color;
box-shadow: 0 0 0 $input-focus-width rgba($color, .25);
}
}
}
.form-check-input {
2020-04-28 17:14:23 -04:00
@include form-validation-state-selector($state) {
2020-04-28 17:09:22 -04:00
~ .form-check-label {
color: $color;
}
~ .#{$state}-feedback,
~ .#{$state}-tooltip {
display: block;
}
}
}
.custom-control-input {
2020-04-28 17:14:23 -04:00
@include form-validation-state-selector($state) {
2020-04-28 17:09:22 -04:00
~ .custom-control-label {
color: $color;
&::before {
border-color: $color;
}
}
&:checked {
~ .custom-control-label::before {
border-color: lighten($color, 10%);
@include gradient-bg(lighten($color, 10%));
}
}
&:focus {
~ .custom-control-label::before {
box-shadow: 0 0 0 $input-focus-width rgba($color, .25);
}
&:not(:checked) ~ .custom-control-label::before {
border-color: $color;
}
}
}
}
// custom file
.custom-file-input {
2020-04-28 17:14:23 -04:00
@include form-validation-state-selector($state) {
2020-04-28 17:09:22 -04:00
~ .custom-file-label {
border-color: $color;
}
&:focus {
~ .custom-file-label {
border-color: $color;
box-shadow: 0 0 0 $input-focus-width rgba($color, .25);
}
}
}
}
}