switch.less 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // Switch
  3. // --------------------------------------------------
  4. // Switch wrapper
  5. // --------------------------------------------------
  6. .@{switch-name} {
  7. font-size: @component-font-size-base; // 15px
  8. line-height: @switch-height;
  9. display: inline-block;
  10. cursor: pointer;
  11. border-radius: @switch-border-radius;
  12. position: relative;
  13. text-align: left;
  14. overflow: hidden;
  15. vertical-align: middle;
  16. width: @switch-width;
  17. height: @switch-height;
  18. -webkit-mask-box-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNy4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgODAgMjkiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDgwIDI5IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIGQ9Ik04MCwxNC41YzAsOC02LjUsMTQuNS0xNC41LDE0LjVoLTUxQzYuNSwyOSwwLDIyLjUsMCwxNC41bDAsMEMwLDYuNSw2LjUsMCwxNC41LDBoNTFDNzMuNSwwLDgwLDYuNSw4MCwxNC41TDgwLDE0LjV6Ii8+DQo8L3N2Zz4NCg==) 0 0 stretch;
  19. user-select: none;
  20. // Handlers wrapp
  21. > div {
  22. display: inline-block;
  23. width: 132px;
  24. border-radius: @switch-border-radius;
  25. transform: translate3d(0, 0, 0);
  26. // Handlers
  27. > span {
  28. font-weight: 700;
  29. line-height: 19px;
  30. cursor: pointer;
  31. display: inline-block;
  32. height: 100%;
  33. padding-bottom: 5px;
  34. padding-top: 5px;
  35. text-align: center;
  36. z-index: 1;
  37. width: 66px;
  38. transition: box-shadow .25s ease-out;
  39. > [class^="fui-"] {
  40. text-indent: 0;
  41. }
  42. }
  43. > label {
  44. cursor: pointer;
  45. display: block;
  46. position: absolute;
  47. width: 100%;
  48. height: 100%;
  49. text-indent: -9999px;
  50. font-size: 0;
  51. top: 0;
  52. left: 0;
  53. margin: 0;
  54. z-index: 200;
  55. .opacity(0);
  56. }
  57. }
  58. input[type="radio"],
  59. input[type="checkbox"] {
  60. position: absolute !important;
  61. margin: 0;
  62. top: 0;
  63. left: 0;
  64. z-index: -1;
  65. .opacity(0);
  66. }
  67. }
  68. // `On` handler
  69. .@{switch-name}-handle-on {
  70. .border-left-radius(@switch-border-radius);
  71. .@{switch-name}-off & {
  72. .switch-handle-off-variant(default, @gray-light, mix(@brand-primary, white, 63%));
  73. .switch-handle-off-variant(primary, @brand-primary, @brand-secondary);
  74. .switch-handle-off-variant(success, @brand-success, @inverse);
  75. .switch-handle-off-variant(warning, @brand-warning, @inverse);
  76. .switch-handle-off-variant(info, @brand-info, @inverse);
  77. .switch-handle-off-variant(danger, @brand-danger, @inverse);
  78. }
  79. }
  80. // `Off` handler
  81. .@{switch-name}-handle-off {
  82. .border-right-radius(@switch-border-radius);
  83. &:before {
  84. display: inline-block;
  85. content: " ";
  86. border: 4px solid transparent;
  87. border-radius: 50%;
  88. text-align: center;
  89. vertical-align: top;
  90. padding: 0;
  91. height: 29px;
  92. width: 29px;
  93. position: absolute;
  94. top: 0;
  95. left: 51px;
  96. z-index: 100;
  97. background-clip: padding-box;
  98. transition: border-color .25s ease-out, background-color .25s ease-out;
  99. }
  100. }
  101. // Switch `animate` state
  102. .@{switch-name}-animate {
  103. > div {
  104. transition: margin-left .25s ease-out;
  105. }
  106. }
  107. .@{switch-name}-on > div {
  108. margin-left: 0;
  109. }
  110. .@{switch-name}-off > div {
  111. margin-left: -51px;
  112. }
  113. // Switch `disabled` states
  114. .@{switch-name}-disabled,
  115. .@{switch-name}-readonly {
  116. .opacity(.5);
  117. cursor: default;
  118. > div > span,
  119. > div > label {
  120. cursor: default !important;
  121. }
  122. }
  123. // Switch `focus` state
  124. .@{switch-name}-focused {
  125. outline: 0;
  126. }
  127. // Handler feedback states
  128. // --------------------------------------------------
  129. .@{switch-name}-default {
  130. .switch-variant(@inverse, @gray-light, @gray-light, mix(@brand-primary, white, 63%));
  131. }
  132. .@{switch-name}-primary {
  133. .switch-variant(@brand-secondary, @brand-primary, @brand-primary, @brand-secondary);
  134. }
  135. .@{switch-name}-info {
  136. .switch-variant(@inverse, @brand-info, @brand-info, @inverse);
  137. }
  138. .@{switch-name}-success {
  139. .switch-variant(@inverse, @brand-success, @brand-success, @inverse);
  140. }
  141. .@{switch-name}-warning {
  142. .switch-variant(@inverse, @brand-warning, @brand-warning, @inverse);
  143. }
  144. .@{switch-name}-danger {
  145. .switch-variant(@inverse, @brand-danger, @brand-danger, @inverse);
  146. }
  147. // Square skin
  148. // --------------------------------------------------
  149. .@{switch-name}-square {
  150. .@{switch-name} {
  151. -webkit-mask-box-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNy4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgODAgMjkiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDgwIDI5IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIGQ9Ik04MCwyNWMwLDIuMi0xLjgsNC00LDRINGMtMi4yLDAtNC0xLjgtNC00VjRjMC0yLjIsMS44LTQsNC00aDcyYzIuMiwwLDQsMS44LDQsNFYyNXoiLz4NCjwvc3ZnPg0K) 0 0 stretch;
  152. border-radius: @border-radius-base;
  153. > div {
  154. border-radius: @border-radius-base;
  155. }
  156. .@{switch-name}-handle-on {
  157. text-indent: -15px;
  158. .border-left-radius(@border-radius-base);
  159. }
  160. .@{switch-name}-handle-off {
  161. text-indent: 15px;
  162. .border-right-radius(@border-radius-base);
  163. &:before {
  164. border: none;
  165. .border-left-radius(0);
  166. .border-right-radius((@border-radius-base - 2));
  167. }
  168. }
  169. }
  170. .@{switch-name}-off {
  171. .@{switch-name}-handle-off:before {
  172. .border-left-radius((@border-radius-base - 2));
  173. .border-right-radius(0);
  174. }
  175. }
  176. }