ly-checkbox.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <text :class="classObj.wrapper" @click.stop="handleClick">
  3. <text :class="[classObj.input, {'is-indeterminate': indeterminate, 'is-checked': checked, 'is-disabled': disabled}]">
  4. <text :class="classObj.inner"></text>
  5. </text>
  6. </text>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. classObj: {}
  13. }
  14. },
  15. props: {
  16. type: {
  17. type: String,
  18. validator(t) {
  19. return t === 'radio' || t === 'checkbox'
  20. }
  21. },
  22. checked: Boolean,
  23. disabled: Boolean,
  24. indeterminate: Boolean
  25. },
  26. created() {
  27. this.classObj = {
  28. wrapper: `ly-${this.type}`,
  29. input: `ly-${this.type}__input`,
  30. inner: `ly-${this.type}__inner`
  31. }
  32. },
  33. methods: {
  34. handleClick() {
  35. this.$emit('check', this.checked);
  36. }
  37. }
  38. }
  39. </script>
  40. <style>
  41. /* lyRadio/lyCheckbox-start */
  42. .ly-checkbox,
  43. .ly-radio {
  44. color: #606266;
  45. font-weight: 500;
  46. font-size: 28rpx;
  47. cursor: pointer;
  48. user-select: none;
  49. padding-right: 16rpx
  50. }
  51. .ly-checkbox__input,
  52. .ly-radio__input {
  53. cursor: pointer;
  54. outline: 0;
  55. line-height: 1;
  56. vertical-align: middle
  57. }
  58. .ly-checkbox__input.is-disabled .ly-checkbox__inner,
  59. .ly-radio__input.is-disabled .ly-radio__inner {
  60. background-color: #edf2fc;
  61. border-color: #DCDFE6;
  62. cursor: not-allowed
  63. }
  64. .ly-checkbox__input.is-disabled .ly-checkbox__inner::after,
  65. .ly-radio__input.is-disabled .ly-radio__inner::after {
  66. cursor: not-allowed;
  67. border-color: #C0C4CC
  68. }
  69. .ly-checkbox__input.is-disabled .ly-checkbox__inner+.ly-checkbox__label,
  70. .ly-radio__input.is-disabled .ly-radio__inner+.ly-radio__label {
  71. cursor: not-allowed
  72. }
  73. .ly-checkbox__input.is-disabled.is-checked .ly-checkbox__inner,
  74. .ly-radio__input.is-disabled.is-checked .ly-radio__inner {
  75. background-color: #F2F6FC;
  76. border-color: #DCDFE6
  77. }
  78. .ly-checkbox__input.is-disabled.is-checked .ly-checkbox__inner::after,
  79. .ly-radio__input.is-disabled.is-checked .ly-radio__inner::after {
  80. border-color: #C0C4CC
  81. }
  82. .ly-checkbox__input.is-disabled.is-indeterminate .ly-checkbox__inner {
  83. background-color: #F2F6FC;
  84. border-color: #DCDFE6
  85. }
  86. .ly-checkbox__input.is-disabled.is-indeterminate .ly-checkbox__inner::before {
  87. background-color: #C0C4CC;
  88. border-color: #C0C4CC
  89. }
  90. .ly-checkbox__input.is-checked .ly-checkbox__inner,
  91. .ly-radio__input.is-checked .ly-radio__inner,
  92. .ly-checkbox__input.is-indeterminate .ly-checkbox__inner {
  93. background-color: #409EFF;
  94. border-color: #409EFF
  95. }
  96. .ly-checkbox__input.is-disabled+text.ly-checkbox__label,
  97. .ly-radio__input.is-disabled+text.ly-radio__label {
  98. color: #C0C4CC;
  99. cursor: not-allowed
  100. }
  101. .ly-checkbox__input.is-checked .ly-checkbox__inner::after,
  102. .ly-radio__input.is-checked .ly-radio__inner::after {
  103. -webkit-transform: rotate(45deg) scaleY(1);
  104. transform: rotate(45deg) scaleY(1)
  105. }
  106. .ly-checkbox__input.is-checked+.ly-checkbox__label,
  107. .ly-radio__input.is-checked+.ly-radio__label {
  108. color: #409EFF
  109. }
  110. .ly-checkbox__input.is-focus .ly-checkbox__inner,
  111. .ly-radio__input.is-focus .ly-radio__inner {
  112. border-color: #409EFF
  113. }
  114. .ly-checkbox__input.is-indeterminate .ly-checkbox__inner::before {
  115. content: '';
  116. position: absolute;
  117. display: block;
  118. background-color: #FFF;
  119. height: 6rpx;
  120. -webkit-transform: scale(.5);
  121. transform: scale(.5);
  122. left: 0;
  123. right: 0;
  124. top: 10rpx
  125. }
  126. .ly-checkbox__input.is-indeterminate .ly-checkbox__inner::after {
  127. display: none
  128. }
  129. .ly-checkbox__inner,
  130. .ly-radio__inner {
  131. display: inline-block;
  132. position: relative;
  133. border: 2rpx solid #DCDFE6;
  134. border-radius: 4rpx;
  135. -webkit-box-sizing: border-box;
  136. box-sizing: border-box;
  137. width: 28rpx;
  138. height: 28rpx;
  139. background-color: #FFF;
  140. z-index: 1;
  141. -webkit-transition: border-color .25s cubic-bezier(.71, -.46, .29, 1.46), background-color .25s cubic-bezier(.71, -.46, .29, 1.46);
  142. transition: border-color .25s cubic-bezier(.71, -.46, .29, 1.46), background-color .25s cubic-bezier(.71, -.46, .29, 1.46)
  143. }
  144. .ly-radio__inner {
  145. border-radius: 50%;
  146. width: 34rpx !important;
  147. height: 34rpx !important;
  148. }
  149. .ly-checkbox__inner::after,
  150. .ly-radio__inner::after {
  151. -webkit-box-sizing: content-box;
  152. box-sizing: content-box;
  153. content: "";
  154. border: 2rpx solid #FFF;
  155. border-left: 0;
  156. border-top: 0;
  157. height: 14rpx;
  158. left: 10rpx;
  159. position: absolute;
  160. top: 2rpx;
  161. -webkit-transform: rotate(45deg) scaleY(0);
  162. transform: rotate(45deg) scaleY(0);
  163. width: 6rpx;
  164. -webkit-transition: -webkit-transform .15s ease-in .05s;
  165. transition: -webkit-transform .15s ease-in .05s;
  166. transition: transform .15s ease-in .05s;
  167. transition: transform .15s ease-in .05s, -webkit-transform .15s ease-in .05s;
  168. -webkit-transform-origin: center;
  169. transform-origin: center
  170. }
  171. .ly-radio__inner::after {
  172. left: 12rpx !important;
  173. top: 6rpx !important;
  174. }
  175. /* lyRadio/lyCheckbox-end */
  176. </style>