CButton.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <button class="c-button" :style="style" :class="classList" @click="$emit('click')">
  3. <c-icon :bold="!noBold" :right="6" :left="-4" v-if="icon" class="icon" :size="20">{{icon}}</c-icon>
  4. <slot></slot>
  5. </button>
  6. </template>
  7. <script>
  8. import CIcon from '@/components/Basic/CIcon'
  9. export default {
  10. components: { CIcon },
  11. // props: ['icon', 'noClickWarn']
  12. props: {
  13. icon: {
  14. type: String,
  15. default: null
  16. },
  17. noClickWarn: {
  18. type: Boolean,
  19. default: false
  20. },
  21. theme: {
  22. type: String,
  23. default: 'normal'
  24. },
  25. // 背景透明的按钮
  26. text: {
  27. type: Boolean,
  28. default: false
  29. },
  30. // 使用白色字体、深色背景的最显眼按钮,优先级大于 text
  31. standout: {
  32. type: Boolean,
  33. default: false
  34. },
  35. // 占满宽度
  36. block: {
  37. type: Boolean,
  38. default: false
  39. },
  40. small: {
  41. type: Boolean,
  42. default: false
  43. },
  44. large: {
  45. type: Boolean,
  46. default: false
  47. },
  48. // 去掉涟漪效果
  49. noRipple: {
  50. type: Boolean,
  51. default: false
  52. },
  53. noBold: {
  54. type: Boolean,
  55. default: false
  56. },
  57. left: {
  58. type: Number,
  59. default: 0
  60. },
  61. right: {
  62. type: Number,
  63. default: 0
  64. }
  65. },
  66. computed: {
  67. style () {
  68. return {
  69. marginRight: this.right ? this.right + 'px' : null,
  70. marginLeft: this.left ? this.left + 'px' : null
  71. }
  72. },
  73. classList () {
  74. return [
  75. this.standout
  76. ? (this.theme ? 'c-button-standout--' + this.theme : 'c-button-standout--normal')
  77. : (
  78. this.text
  79. ? (this.theme ? 'c-button-text--' + this.theme : 'c-button-text--normal')
  80. : (this.theme ? 'c-button--' + this.theme : 'c-button--normal')
  81. ),
  82. this.large ? 'c-button--large' : '',
  83. this.small ? 'c-button--small' : '',
  84. this.noClickWarn ? 'c-button--disabled' : '',
  85. this.block ? 'c-button--block' : ''
  86. ]
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. @import '~@/style/theme.scss';
  93. @import '~@/style/mixin/set-theme.scss';
  94. button {
  95. border: none;
  96. outline: none;
  97. cursor: pointer;
  98. display: inline-flex;
  99. align-items: center;
  100. justify-content: center;
  101. -webkit-tap-highlight-color: transparent;
  102. background: $theme-background-grey;
  103. color: $theme-grey;
  104. border-radius: 8px;
  105. font-size: 14px;
  106. padding: 8px 16px;
  107. font-weight: bold;
  108. box-sizing: border-box;
  109. transition: .15s;
  110. &:hover {
  111. background: darken($theme-background-grey, 5);
  112. }
  113. &:active {
  114. background: darken($theme-background-grey-darker, 10);
  115. }
  116. }
  117. .c-button--block {
  118. display: flex;
  119. width: 100%;
  120. }
  121. @mixin theme($name, $color, $backgroundColor) {
  122. .c-button--#{$name} {
  123. color: $color;
  124. background: $backgroundColor;
  125. &:hover {
  126. background: darken($backgroundColor, 5);
  127. }
  128. &:active {
  129. background: darken($backgroundColor, 10);
  130. }
  131. .icon {
  132. color: $color;
  133. }
  134. }
  135. .c-button-text--#{$name} {
  136. color: $color;
  137. border-radius: 1000px;
  138. background: transparent;
  139. transition: .3s;
  140. &:hover {
  141. background: $backgroundColor;
  142. }
  143. &:active {
  144. background: darken($backgroundColor, 5);
  145. }
  146. .icon {
  147. color: $color;
  148. }
  149. }
  150. .c-button-standout--#{$name} {
  151. color: white;
  152. background: $color;
  153. &:hover {
  154. background: lighten($color, 5);
  155. }
  156. &:active {
  157. background: lighten($color, 10);
  158. }
  159. .icon {
  160. color: white;
  161. }
  162. }
  163. }
  164. @include setTheme()
  165. .c-button--disabled {
  166. background: #daeafa;
  167. color: white;
  168. cursor: not-allowed;
  169. &:hover {
  170. background: #daeafa;
  171. }
  172. &:active {
  173. background: #daeafa;
  174. }
  175. }
  176. </style>