_forms.scss 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // Form control focus state
  2. //
  3. // Generate a customized focus state and for any input with the specified color,
  4. // which defaults to the `$input-focus-border-color` variable.
  5. //
  6. // We highly encourage you to not customize the default value, but instead use
  7. // this to tweak colors on an as-needed basis. This aesthetic change is based on
  8. // WebKit's default styles, but applicable to a wider range of browsers. Its
  9. // usability and accessibility should be taken into account with any change.
  10. //
  11. // Example usage: change the default blue border and shadow to white for better
  12. // contrast against a dark gray background.
  13. @mixin form-control-focus() {
  14. &:focus {
  15. color: $input-focus-color;
  16. background-color: $input-focus-bg;
  17. border-color: $input-focus-border-color;
  18. outline: 0;
  19. // Avoid using mixin so we can pass custom focus shadow properly
  20. @if $enable-shadows {
  21. box-shadow: $input-box-shadow, $input-focus-box-shadow;
  22. } @else {
  23. box-shadow: $input-focus-box-shadow;
  24. }
  25. }
  26. }
  27. @mixin form-validation-state($state, $color, $icon) {
  28. .#{$state}-feedback {
  29. display: none;
  30. width: 100%;
  31. margin-top: $form-feedback-margin-top;
  32. @include font-size($form-feedback-font-size);
  33. color: $color;
  34. }
  35. .#{$state}-tooltip {
  36. position: absolute;
  37. top: 100%;
  38. z-index: 5;
  39. display: none;
  40. max-width: 100%; // Contain to parent when possible
  41. padding: $form-feedback-tooltip-padding-y $form-feedback-tooltip-padding-x;
  42. margin-top: .1rem;
  43. @include font-size($form-feedback-tooltip-font-size);
  44. line-height: $form-feedback-tooltip-line-height;
  45. color: color-yiq($color);
  46. background-color: rgba($color, $form-feedback-tooltip-opacity);
  47. @include border-radius($form-feedback-tooltip-border-radius);
  48. }
  49. .form-control {
  50. .was-validated &:#{$state},
  51. &.is-#{$state} {
  52. border-color: $color;
  53. @if $enable-validation-icons {
  54. padding-right: $input-height-inner;
  55. background-image: $icon;
  56. background-repeat: no-repeat;
  57. background-position: center right $input-height-inner-quarter;
  58. background-size: $input-height-inner-half $input-height-inner-half;
  59. }
  60. &:focus {
  61. border-color: $color;
  62. box-shadow: 0 0 0 $input-focus-width rgba($color, .25);
  63. }
  64. ~ .#{$state}-feedback,
  65. ~ .#{$state}-tooltip {
  66. display: block;
  67. }
  68. }
  69. }
  70. // stylelint-disable-next-line selector-no-qualifying-type
  71. textarea.form-control {
  72. .was-validated &:#{$state},
  73. &.is-#{$state} {
  74. @if $enable-validation-icons {
  75. padding-right: $input-height-inner;
  76. background-position: top $input-height-inner-quarter right $input-height-inner-quarter;
  77. }
  78. }
  79. }
  80. .custom-select {
  81. .was-validated &:#{$state},
  82. &.is-#{$state} {
  83. border-color: $color;
  84. @if $enable-validation-icons {
  85. padding-right: $custom-select-feedback-icon-padding-right;
  86. background: $custom-select-background, $icon $custom-select-bg no-repeat $custom-select-feedback-icon-position / $custom-select-feedback-icon-size;
  87. }
  88. &:focus {
  89. border-color: $color;
  90. box-shadow: 0 0 0 $input-focus-width rgba($color, .25);
  91. }
  92. ~ .#{$state}-feedback,
  93. ~ .#{$state}-tooltip {
  94. display: block;
  95. }
  96. }
  97. }
  98. .form-control-file {
  99. .was-validated &:#{$state},
  100. &.is-#{$state} {
  101. ~ .#{$state}-feedback,
  102. ~ .#{$state}-tooltip {
  103. display: block;
  104. }
  105. }
  106. }
  107. .form-check-input {
  108. .was-validated &:#{$state},
  109. &.is-#{$state} {
  110. ~ .form-check-label {
  111. color: $color;
  112. }
  113. ~ .#{$state}-feedback,
  114. ~ .#{$state}-tooltip {
  115. display: block;
  116. }
  117. }
  118. }
  119. .custom-control-input {
  120. .was-validated &:#{$state},
  121. &.is-#{$state} {
  122. ~ .custom-control-label {
  123. color: $color;
  124. &::before {
  125. border-color: $color;
  126. }
  127. }
  128. ~ .#{$state}-feedback,
  129. ~ .#{$state}-tooltip {
  130. display: block;
  131. }
  132. &:checked {
  133. ~ .custom-control-label::before {
  134. border-color: lighten($color, 10%);
  135. @include gradient-bg(lighten($color, 10%));
  136. }
  137. }
  138. &:focus {
  139. ~ .custom-control-label::before {
  140. box-shadow: 0 0 0 $input-focus-width rgba($color, .25);
  141. }
  142. &:not(:checked) ~ .custom-control-label::before {
  143. border-color: $color;
  144. }
  145. }
  146. }
  147. }
  148. // custom file
  149. .custom-file-input {
  150. .was-validated &:#{$state},
  151. &.is-#{$state} {
  152. ~ .custom-file-label {
  153. border-color: $color;
  154. }
  155. ~ .#{$state}-feedback,
  156. ~ .#{$state}-tooltip {
  157. display: block;
  158. }
  159. &:focus {
  160. ~ .custom-file-label {
  161. border-color: $color;
  162. box-shadow: 0 0 0 $input-focus-width rgba($color, .25);
  163. }
  164. }
  165. }
  166. }
  167. }