_forms.less 4.9 KB

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