Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

_switch.scss 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. // Switches
  2. // *******************************************************************************
  3. .switch {
  4. --#{$prefix}switch-bg: #{$switch-off-bg};
  5. --#{$prefix}switch-color: #{$switch-off-color};
  6. --#{$prefix}switch-border-color: #{$switch-off-border};
  7. --#{$prefix}switch-box-shadow: #{$form-switch-box-shadow};
  8. --#{$prefix}switch-holder-bg: #{$switch-holder-bg};
  9. --#{$prefix}switch-holder-shadow: #{$switch-holder-shadow};
  10. /* Checked state */
  11. .switch-input:checked ~ .switch-toggle-slider {
  12. --#{$prefix}switch-bg: var(--#{$prefix}primary);
  13. --#{$prefix}switch-color: var(--#{$prefix}white);
  14. --#{$prefix}switch-border-color: var(--#{$prefix}primary);
  15. --#{$prefix}switch-box-shadow: 0 .125rem .375rem 0 rgba(var(--#{$prefix}primary-rgb), .3);
  16. }
  17. &[class*="switch-outline-"],
  18. &.switch-outline {
  19. --#{$prefix}switch-bg: transparent;
  20. --#{$prefix}switch-box-shadow: none;
  21. --#{$prefix}switch-holder-bg: #{$switch-off-bg};
  22. --#{$prefix}switch-holder-shadow: none;
  23. // Checked state
  24. .switch-input:checked ~ .switch-toggle-slider {
  25. --#{$prefix}switch-bg: transparent;
  26. --#{$prefix}switch-box-shadow: none;
  27. }
  28. }
  29. &.switch-outline {
  30. // Checked state
  31. .switch-input:checked ~ .switch-toggle-slider {
  32. --#{$prefix}switch-color: var(--#{$prefix}primary);
  33. --#{$prefix}switch-border-color: var(--#{$prefix}primary);
  34. --#{$prefix}switch-holder-bg: var(--#{$prefix}primary);
  35. }
  36. }
  37. position: relative;
  38. display: inline-block;
  39. @include border-radius($switch-border-radius);
  40. cursor: pointer;
  41. margin-inline-end: $switch-spacer-x;
  42. vertical-align: middle;
  43. &:has(.switch-input:disabled) {
  44. cursor: not-allowed;
  45. }
  46. @include template-switch-size-base(
  47. "",
  48. $switch-width,
  49. $switch-height,
  50. $switch-font-size,
  51. $switch-label-font-size,
  52. $switch-label-line-height,
  53. $switch-inner-spacer
  54. );
  55. .switch-input {
  56. &.is-invalid ~ .switch-label,
  57. .was-validated &:invalid ~ .switch-label {
  58. color: var(--#{$prefix}form-invalid-border-color);
  59. }
  60. &.is-valid ~ .switch-label,
  61. .was-validated &:valid ~ .switch-label {
  62. color: var(--#{$prefix}form-valid-border-color);
  63. }
  64. &.is-invalid ~ .switch-toggle-slider,
  65. .was-validated &:invalid ~ .switch-toggle-slider {
  66. --#{$prefix}switch-border-color: var(--#{$prefix}form-invalid-border-color);
  67. }
  68. &.is-valid ~ .switch-toggle-slider,
  69. .was-validated &:valid ~ .switch-toggle-slider {
  70. --#{$prefix}switch-border-color: var(--#{$prefix}form-valid-border-color);
  71. }
  72. &.is-invalid:checked ~ .switch-toggle-slider,
  73. .was-validated &:invalid:checked ~ .switch-toggle-slider {
  74. --#{$prefix}switch-bg: var(--#{$prefix}form-invalid-color);
  75. --#{$prefix}switch-box-shadow: none;
  76. }
  77. &.is-valid:checked ~ .switch-toggle-slider,
  78. .was-validated &:valid:checked ~ .switch-toggle-slider {
  79. --#{$prefix}switch-bg: var(--#{$prefix}form-valid-color);
  80. --#{$prefix}switch-box-shadow: none;
  81. }
  82. }
  83. }
  84. /* Input
  85. ******************************************************************************* */
  86. .switch-input {
  87. position: absolute;
  88. z-index: -1;
  89. opacity: 0;
  90. .was-validated &:invalid ~ .valid-feedback,
  91. .was-validated &:invalid ~ .valid-tooltip,
  92. &.is-invalid ~ .valid-feedback,
  93. &.is-invalid ~ .valid-tooltip,
  94. .was-validated &:valid ~ .valid-feedback,
  95. .was-validated &:valid ~ .valid-tooltip,
  96. &.is-valid ~ .valid-feedback,
  97. &.is-valid ~ .valid-tooltip {
  98. display: block;
  99. }
  100. }
  101. /* Toggle slider
  102. ******************************************************************************* */
  103. .switch-toggle-slider {
  104. position: absolute;
  105. overflow: hidden;
  106. border: 1px solid var(--#{$prefix}switch-border-color);
  107. @include border-radius($switch-border-radius);
  108. background: var(--#{$prefix}switch-bg);
  109. box-shadow: var(--#{$prefix}switch-box-shadow);
  110. color: var(--#{$prefix}switch-color);
  111. font-size: $switch-font-size;
  112. inset-block-start: 50%;
  113. transform: translateY(-50%);
  114. transition-duration: .2s;
  115. transition-property: inset-inline-start, inset-inline-end, background, box-shadow;
  116. user-select: none;
  117. &::after {
  118. position: absolute;
  119. display: block;
  120. @include border-radius(50%);
  121. background: var(--#{$prefix}switch-holder-bg);
  122. box-shadow: var(--#{$prefix}switch-holder-shadow);
  123. content: "";
  124. inset-block-start: 50%;
  125. inset-inline: 8% auto;
  126. transform: translateY(-50%);
  127. transition-duration: .2s;
  128. transition-property: inset-inline-start, inset-inline-end, background;
  129. }
  130. }
  131. /* Label switch
  132. ******************************************************************************* */
  133. .switch-label {
  134. position: relative;
  135. display: inline-block;
  136. color: $switch-label-color;
  137. font-weight: 400;
  138. &:first-child {
  139. padding-inline-end: $switch-gutter;
  140. }
  141. }
  142. /* Checked / Unchecked states */
  143. .switch-off,
  144. .switch-on {
  145. position: absolute;
  146. block-size: 100%;
  147. inline-size: 100%;
  148. inset-block-start: 0;
  149. text-align: center;
  150. transition-duration: .2s;
  151. transition-property: inset-inline-start, inset-inline-end;
  152. }
  153. .switch-on {
  154. inset-inline-start: -100%;
  155. .switch-input:not(:checked) ~ .switch-toggle-slider & {
  156. color: transparent;
  157. }
  158. }
  159. .switch-off {
  160. inset-inline-start: 0;
  161. }
  162. /* Checked state */
  163. .switch-input:checked ~ .switch-toggle-slider {
  164. &::after {
  165. inset-inline: 95% auto;
  166. transform: translate(-100%, -50%);
  167. :dir(rtl) & {
  168. inset-inline: 94% auto;
  169. transform: translate(100%, -50%);
  170. }
  171. }
  172. .switch-on {
  173. inset-inline-start: 0;
  174. }
  175. .switch-off {
  176. color: transparent;
  177. inset-inline-start: 100%;
  178. }
  179. }
  180. /* Stacked switches
  181. ******************************************************************************* */
  182. .switches-stacked {
  183. @include clearfix ();
  184. .switch {
  185. display: block;
  186. margin-inline: 0;
  187. &:not(:last-child) {
  188. margin-block-end: $switch-spacer-y;
  189. }
  190. }
  191. }
  192. /* Square
  193. ******************************************************************************* */
  194. .switch-square,
  195. .switch-square .switch-toggle-slider {
  196. @if $enable-rounded {
  197. @include border-radius($switch-square-border-radius);
  198. } @else {
  199. @include border-radius(0);
  200. }
  201. }
  202. .switch-square .switch-toggle-slider::after {
  203. @if $enable-rounded {
  204. @include border-radius(calc(#{$switch-square-border-radius} - 2px));
  205. } @else {
  206. @include border-radius(0);
  207. }
  208. }
  209. /* Disabled
  210. ******************************************************************************* */
  211. .switch-input:disabled {
  212. ~ .switch-toggle-slider {
  213. opacity: $switch-disabled-opacity;
  214. }
  215. ~ .switch-label {
  216. color: $switch-label-disabled-color;
  217. }
  218. }
  219. /* Switch Sizes
  220. ******************************************************************************* */
  221. @include template-switch-size(
  222. "sm",
  223. $switch-width-sm,
  224. $switch-height-sm,
  225. $switch-font-size,
  226. $switch-label-font-size-sm,
  227. $switch-label-line-height-sm,
  228. $switch-inner-spacer-sm
  229. );
  230. @include template-switch-size(
  231. "lg",
  232. $switch-width-lg,
  233. $switch-height-lg,
  234. $switch-font-size,
  235. $switch-label-font-size-lg,
  236. $switch-label-line-height-lg
  237. );
  238. /* Validation states
  239. ******************************************************************************* */
  240. .switch .valid-feedback,
  241. .switch .invalid-feedback {
  242. padding-inline-start: $switch-gutter;
  243. }
  244. /* Generate contextual modifier classes for colorizing the alert */
  245. @each $state in map-keys($theme-colors) {
  246. .switch-#{$state} {
  247. .switch-input:checked ~ .switch-toggle-slider {
  248. --#{$prefix}switch-bg: var(--#{$prefix}#{$state});
  249. --#{$prefix}switch-border-color: var(--#{$prefix}#{$state});
  250. --#{$prefix}switch-box-shadow: 0 .125rem .375rem 0 rgba(var(--#{$prefix}#{$state}-rgb), .3);
  251. }
  252. }
  253. .switch-outline-#{$state} {
  254. .switch-input:checked ~ .switch-toggle-slider {
  255. --#{$prefix}switch-color: var(--#{$prefix}#{$state});
  256. --#{$prefix}switch-border-color: var(--#{$prefix}#{$state});
  257. --#{$prefix}switch-holder-bg: var(--#{$prefix}#{$state});
  258. }
  259. }
  260. }