| 1 |
// This mixin uses an `if()` technique to be compatible with Dart Sass |
| 2 |
// See https://github.com/sass/sass/issues/1873#issuecomment-152293725 for more details |
| 3 |
|
| 4 |
// scss-docs-start form-validation-mixins |
| 5 |
@mixin form-validation-state-selector($state) { |
| 6 |
@if ($state == "valid" or $state == "invalid") { |
| 7 |
.was-validated #{if(&, "&", "")}:#{$state}, |
| 8 |
#{if(&, "&", "")}.is-#{$state} { |
| 9 |
@content; |
| 10 |
} |
| 11 |
} @else { |
| 12 |
#{if(&, "&", "")}.is-#{$state} { |
| 13 |
@content; |
| 14 |
} |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
@mixin form-validation-state( |
| 19 |
$state, |
| 20 |
$color, |
| 21 |
$icon, |
| 22 |
$tooltip-color: color-contrast($color), |
| 23 |
$tooltip-bg-color: rgba($color, $form-feedback-tooltip-opacity), |
| 24 |
$focus-box-shadow: 0 0 $input-btn-focus-blur $input-focus-width rgba($color, $input-btn-focus-color-opacity), |
| 25 |
$border-color: $color |
| 26 |
) { |
| 27 |
.#{$state}-feedback { |
| 28 |
display: none; |
| 29 |
width: 100%; |
| 30 |
margin-top: $form-feedback-margin-top; |
| 31 |
@include font-size($form-feedback-font-size); |
| 32 |
font-style: $form-feedback-font-style; |
| 33 |
color: $color; |
| 34 |
} |
| 35 |
|
| 36 |
.#{$state}-tooltip { |
| 37 |
position: absolute; |
| 38 |
top: 100%; |
| 39 |
z-index: 5; |
| 40 |
display: none; |
| 41 |
max-width: 100%; // Contain to parent when possible |
| 42 |
padding: $form-feedback-tooltip-padding-y $form-feedback-tooltip-padding-x; |
| 43 |
margin-top: .1rem; |
| 44 |
@include font-size($form-feedback-tooltip-font-size); |
| 45 |
line-height: $form-feedback-tooltip-line-height; |
| 46 |
color: $tooltip-color; |
| 47 |
background-color: $tooltip-bg-color; |
| 48 |
@include border-radius($form-feedback-tooltip-border-radius); |
| 49 |
} |
| 50 |
|
| 51 |
@include form-validation-state-selector($state) { |
| 52 |
~ .#{$state}-feedback, |
| 53 |
~ .#{$state}-tooltip { |
| 54 |
display: block; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
.form-control { |
| 59 |
@include form-validation-state-selector($state) { |
| 60 |
border-color: $border-color; |
| 61 |
|
| 62 |
@if $enable-validation-icons { |
| 63 |
padding-right: $input-height-inner; |
| 64 |
background-image: escape-svg($icon); |
| 65 |
background-repeat: no-repeat; |
| 66 |
background-position: right $input-height-inner-quarter center; |
| 67 |
background-size: $input-height-inner-half $input-height-inner-half; |
| 68 |
} |
| 69 |
|
| 70 |
&:focus { |
| 71 |
border-color: $border-color; |
| 72 |
box-shadow: $focus-box-shadow; |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
// stylelint-disable-next-line selector-no-qualifying-type |
| 78 |
textarea.form-control { |
| 79 |
@include form-validation-state-selector($state) { |
| 80 |
@if $enable-validation-icons { |
| 81 |
padding-right: $input-height-inner; |
| 82 |
background-position: top $input-height-inner-quarter right $input-height-inner-quarter; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
.form-select { |
| 88 |
@include form-validation-state-selector($state) { |
| 89 |
border-color: $border-color; |
| 90 |
|
| 91 |
@if $enable-validation-icons { |
| 92 |
&:not([multiple]):not([size]), |
| 93 |
&:not([multiple])[size="1"] { |
| 94 |
--#{$prefix}form-select-bg-icon: #{escape-svg($icon)}; |
| 95 |
padding-right: $form-select-feedback-icon-padding-end; |
| 96 |
background-position: $form-select-bg-position, $form-select-feedback-icon-position; |
| 97 |
background-size: $form-select-bg-size, $form-select-feedback-icon-size; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
&:focus { |
| 102 |
border-color: $border-color; |
| 103 |
box-shadow: $focus-box-shadow; |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
.form-control-color { |
| 109 |
@include form-validation-state-selector($state) { |
| 110 |
@if $enable-validation-icons { |
| 111 |
width: add($form-color-width, $input-height-inner); |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
.form-check-input { |
| 117 |
@include form-validation-state-selector($state) { |
| 118 |
border-color: $border-color; |
| 119 |
|
| 120 |
&:checked { |
| 121 |
background-color: $color; |
| 122 |
} |
| 123 |
|
| 124 |
&:focus { |
| 125 |
box-shadow: $focus-box-shadow; |
| 126 |
} |
| 127 |
|
| 128 |
~ .form-check-label { |
| 129 |
color: $color; |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
.form-check-inline .form-check-input { |
| 134 |
~ .#{$state}-feedback { |
| 135 |
margin-left: .5em; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
.input-group { |
| 140 |
> .form-control:not(:focus), |
| 141 |
> .form-select:not(:focus), |
| 142 |
> .form-floating:not(:focus-within) { |
| 143 |
@include form-validation-state-selector($state) { |
| 144 |
@if $state == "valid" { |
| 145 |
z-index: 3; |
| 146 |
} @else if $state == "invalid" { |
| 147 |
z-index: 4; |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
// scss-docs-end form-validation-mixins |