_forms.scss 3.8 KB

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