mixin.less 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. @import '../../style/mixins/index';
  2. .antCheckboxFn(@checkbox-prefix-cls: ~'@{ant-prefix}-checkbox') {
  3. @checkbox-inner-prefix-cls: ~'@{checkbox-prefix-cls}-inner';
  4. // 一般状态
  5. .@{checkbox-prefix-cls} {
  6. .reset-component();
  7. position: relative;
  8. top: 0.2em;
  9. line-height: 1;
  10. white-space: nowrap;
  11. outline: none;
  12. cursor: pointer;
  13. .@{checkbox-prefix-cls}-wrapper:hover &-inner,
  14. &:hover &-inner,
  15. &-input:focus + &-inner {
  16. border-color: @checkbox-color;
  17. }
  18. &-checked::after {
  19. position: absolute;
  20. top: 0;
  21. left: 0;
  22. width: 100%;
  23. height: 100%;
  24. border: 1px solid @checkbox-color;
  25. border-radius: @checkbox-border-radius;
  26. visibility: hidden;
  27. animation: antCheckboxEffect 0.36s ease-in-out;
  28. animation-fill-mode: backwards;
  29. content: '';
  30. }
  31. &:hover::after,
  32. .@{checkbox-prefix-cls}-wrapper:hover &::after {
  33. visibility: visible;
  34. }
  35. &-inner {
  36. position: relative;
  37. top: 0;
  38. left: 0;
  39. display: block;
  40. width: @checkbox-size;
  41. height: @checkbox-size;
  42. direction: ltr;
  43. background-color: @checkbox-check-bg;
  44. border: @checkbox-border-width @border-style-base @border-color-base;
  45. border-radius: @checkbox-border-radius;
  46. // Fix IE checked style
  47. // https://github.com/ant-design/ant-design/issues/12597
  48. border-collapse: separate;
  49. transition: all 0.3s;
  50. &::after {
  51. @check-width: (@checkbox-size / 14) * 5px;
  52. @check-height: (@checkbox-size / 14) * 8px;
  53. position: absolute;
  54. top: 50%;
  55. // https://github.com/ant-design/ant-design/pull/19452
  56. // https://github.com/ant-design/ant-design/pull/31726
  57. left: 21.5%;
  58. display: table;
  59. width: @check-width;
  60. height: @check-height;
  61. border: 2px solid @checkbox-check-color;
  62. border-top: 0;
  63. border-left: 0;
  64. transform: rotate(45deg) scale(0) translate(-50%, -50%);
  65. opacity: 0;
  66. transition: all 0.1s @ease-in-back, opacity 0.1s;
  67. content: ' ';
  68. }
  69. }
  70. &-input {
  71. position: absolute;
  72. top: 0;
  73. right: 0;
  74. bottom: 0;
  75. left: 0;
  76. z-index: 1;
  77. width: 100%;
  78. height: 100%;
  79. cursor: pointer;
  80. opacity: 0;
  81. }
  82. }
  83. // 选中状态
  84. .@{checkbox-prefix-cls}-checked .@{checkbox-inner-prefix-cls}::after {
  85. position: absolute;
  86. display: table;
  87. border: 2px solid @checkbox-check-color;
  88. border-top: 0;
  89. border-left: 0;
  90. transform: rotate(45deg) scale(1) translate(-50%, -50%);
  91. opacity: 1;
  92. transition: all 0.2s @ease-out-back 0.1s;
  93. content: ' ';
  94. }
  95. .@{checkbox-prefix-cls}-checked {
  96. .@{checkbox-inner-prefix-cls} {
  97. background-color: @checkbox-color;
  98. border-color: @checkbox-color;
  99. }
  100. }
  101. .@{checkbox-prefix-cls}-disabled {
  102. cursor: not-allowed;
  103. &.@{checkbox-prefix-cls}-checked {
  104. .@{checkbox-inner-prefix-cls}::after {
  105. border-color: @disabled-color;
  106. animation-name: none;
  107. }
  108. }
  109. .@{checkbox-prefix-cls}-input {
  110. cursor: not-allowed;
  111. pointer-events: none;
  112. }
  113. .@{checkbox-inner-prefix-cls} {
  114. background-color: @input-disabled-bg;
  115. border-color: @border-color-base !important;
  116. &::after {
  117. border-color: @input-disabled-bg;
  118. border-collapse: separate;
  119. animation-name: none;
  120. }
  121. }
  122. & + span {
  123. color: @disabled-color;
  124. cursor: not-allowed;
  125. }
  126. // Not show highlight border of checkbox when disabled
  127. &:hover::after,
  128. .@{checkbox-prefix-cls}-wrapper:hover &::after {
  129. visibility: hidden;
  130. }
  131. }
  132. .@{checkbox-prefix-cls}-wrapper {
  133. .reset-component();
  134. display: inline-flex;
  135. align-items: baseline;
  136. line-height: unset;
  137. cursor: pointer;
  138. &::after {
  139. display: inline-block;
  140. width: 0;
  141. overflow: hidden;
  142. content: '\a0';
  143. }
  144. &.@{checkbox-prefix-cls}-wrapper-disabled {
  145. cursor: not-allowed;
  146. }
  147. & + & {
  148. margin-left: 8px;
  149. }
  150. &&-in-form-item {
  151. input[type='checkbox'] {
  152. width: 14px;
  153. height: 14px;
  154. }
  155. }
  156. }
  157. .@{checkbox-prefix-cls} + span {
  158. padding-right: 8px;
  159. padding-left: 8px;
  160. }
  161. .@{checkbox-prefix-cls}-group {
  162. .reset-component();
  163. display: inline-block;
  164. &-item {
  165. margin-right: @checkbox-group-item-margin-right;
  166. &:last-child {
  167. margin-right: 0;
  168. }
  169. }
  170. &-item + &-item {
  171. margin-left: 0;
  172. }
  173. }
  174. // 半选状态
  175. .@{checkbox-prefix-cls}-indeterminate {
  176. .@{checkbox-inner-prefix-cls} {
  177. background-color: @checkbox-check-bg;
  178. border-color: @border-color-base;
  179. }
  180. .@{checkbox-inner-prefix-cls}::after {
  181. @indeterminate-width: @checkbox-size - 8px;
  182. @indeterminate-height: @checkbox-size - 8px;
  183. top: 50%;
  184. left: 50%;
  185. width: @indeterminate-width;
  186. height: @indeterminate-height;
  187. background-color: @checkbox-color;
  188. border: 0;
  189. transform: translate(-50%, -50%) scale(1);
  190. opacity: 1;
  191. content: ' ';
  192. }
  193. &.@{checkbox-prefix-cls}-disabled .@{checkbox-inner-prefix-cls}::after {
  194. background-color: @disabled-color;
  195. border-color: @disabled-color;
  196. }
  197. }
  198. }
  199. @keyframes antCheckboxEffect {
  200. 0% {
  201. transform: scale(1);
  202. opacity: 0.5;
  203. }
  204. 100% {
  205. transform: scale(1.6);
  206. opacity: 0;
  207. }
  208. }