_custom-forms.scss 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // Mixins: Custom Forms
  3. //
  4. // Custom Switch Variant
  5. @mixin custom-switch-variant($name, $color) {
  6. &.custom-switch-off-#{$name} {
  7. .custom-control-input ~ .custom-control-label::before {
  8. background-color: #{$color};
  9. border-color: darken($color, 20%);
  10. }
  11. .custom-control-input:focus ~ .custom-control-label::before {
  12. box-shadow: 0 0 0 1px $body-bg, 0 0 0 2px rgba($color, .25);
  13. }
  14. .custom-control-input ~ .custom-control-label::after {
  15. background-color: darken($color, 25%);
  16. }
  17. }
  18. &.custom-switch-on-#{$name} {
  19. .custom-control-input:checked ~ .custom-control-label::before {
  20. background-color: #{$color};
  21. border-color: darken($color, 20%);
  22. }
  23. .custom-control-input:checked:focus ~ .custom-control-label::before {
  24. box-shadow: 0 0 0 1px $body-bg, 0 0 0 2px rgba($color, .25);
  25. }
  26. .custom-control-input:checked ~ .custom-control-label::after {
  27. background-color: lighten($color, 30%);
  28. }
  29. }
  30. }
  31. // Custom Range Variant
  32. @mixin custom-range-variant($name, $color) {
  33. &.custom-range-#{$name} {
  34. &:focus {
  35. outline: none;
  36. &::-webkit-slider-thumb {
  37. box-shadow: 0 0 0 1px $body-bg, 0 0 0 2px rgba($color, .25);
  38. }
  39. &::-moz-range-thumb {
  40. box-shadow: 0 0 0 1px $body-bg, 0 0 0 2px rgba($color, .25);
  41. }
  42. &::-ms-thumb {
  43. box-shadow: 0 0 0 1px $body-bg, 0 0 0 2px rgba($color, .25);
  44. }
  45. }
  46. &::-webkit-slider-thumb {
  47. background-color: $color;
  48. &:active {
  49. background-color: lighten($color, 35%);
  50. }
  51. }
  52. &::-moz-range-thumb {
  53. background-color: $color;
  54. &:active {
  55. background-color: lighten($color, 35%);
  56. }
  57. }
  58. &::-ms-thumb {
  59. background-color: $color;
  60. &:active {
  61. background-color: lighten($color, 35%);
  62. }
  63. }
  64. }
  65. }
  66. // Custom Control Input Variant
  67. @mixin custom-control-input-variant($name, $color) {
  68. $custom-control-indicator-checked-color: $color;
  69. $custom-checkbox-indicator-icon-checked: str-replace(url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='#{$custom-control-indicator-checked-color}' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3E%3C/svg%3E"), "#", "%23");
  70. $custom-radio-indicator-icon-checked: str-replace(url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3E%3Ccircle r='3' fill='#{$custom-control-indicator-checked-color}'/%3E%3C/svg%3E"), "#", "%23");
  71. .custom-control-input-#{$name} {
  72. &:checked ~ .custom-control-label::before {
  73. border-color: $color;
  74. @include gradient-bg($color);
  75. }
  76. &.custom-control-input-outline:checked {
  77. &[type="checkbox"] ~ .custom-control-label::after {
  78. background-image: $custom-checkbox-indicator-icon-checked !important;
  79. }
  80. &[type="radio"] ~ .custom-control-label::after {
  81. background-image: $custom-radio-indicator-icon-checked !important;
  82. }
  83. }
  84. &:focus ~ .custom-control-label::before {
  85. // the mixin is not used here to make sure there is feedback
  86. @if $enable-shadows {
  87. box-shadow: $input-box-shadow, 0 0 0 $input-btn-focus-width rgba($color, .25);
  88. } @else {
  89. box-shadow: 0 0 0 $input-btn-focus-width rgba($color, .25);
  90. }
  91. }
  92. &:focus:not(:checked) ~ .custom-control-label::before {
  93. border-color: lighten($color, 25%);
  94. }
  95. &:not(:disabled):active ~ .custom-control-label::before {
  96. background-color: lighten($color, 35%);
  97. border-color: lighten($color, 35%);
  98. }
  99. }
  100. }