_forms.scss 5.0 KB

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