IconButton.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div class="icon-button" :class="classList" :title="title ? title : ''" @click="$emit('click')" :style="style">
  3. <c-icon :theme="theme" :bold="!noBold" :size="size ? size / 1.4 - 4 : 26">
  4. <slot></slot>
  5. </c-icon>
  6. <ripple></ripple>
  7. </div>
  8. </template>
  9. <script>
  10. import CIcon from '@/components/Basic/CIcon'
  11. import Ripple from '@/components/Basic/Ripple'
  12. export default {
  13. components: { Ripple, CIcon },
  14. // props: ['title', 'ripple', 'small']
  15. props: {
  16. title: {
  17. type: String,
  18. default: '按钮'
  19. },
  20. // 可以直接传入 6 位颜色值,将覆盖 theme 设置的颜色
  21. color: {
  22. type: String,
  23. default: ''
  24. },
  25. // 这个值需要在下方 scss 中有相应的定义,否则无效
  26. theme: {
  27. type: String,
  28. default: 'normal'
  29. },
  30. noBold: {
  31. type: Boolean,
  32. default: false
  33. },
  34. // icon button 大小
  35. size: Number
  36. },
  37. computed: {
  38. classList () {
  39. return [this.theme ? 'icon-button--' + this.theme : '']
  40. },
  41. style () {
  42. return {
  43. color: this.color.match(/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/) ? this.color : '',
  44. width: this.size ? this.size + 'px' : null,
  45. height: this.size ? this.size + 'px' : null
  46. }
  47. }
  48. }
  49. }
  50. </script>
  51. <style lang="scss" scoped>
  52. @import '~@/style/theme.scss';
  53. @import '~@/style/mixin/set-theme.scss';
  54. .icon-button {
  55. position: relative;
  56. display: flex;
  57. align-items: center;
  58. justify-content: center;
  59. padding: 8px;
  60. border-radius: 100px;
  61. width: 44px;
  62. height: 44px;
  63. box-sizing: border-box;
  64. user-select: none;
  65. cursor: pointer;
  66. text-align: center;
  67. color: $icon-normal-color;
  68. transition: 0.2s;
  69. overflow: hidden;
  70. &:hover {
  71. background: $theme-background-grey;
  72. }
  73. &:active {
  74. color: darken($icon-hover-color, 10);
  75. }
  76. }
  77. @mixin theme($name, $color, $backgroundColor) {
  78. .icon-button--#{$name} {
  79. color: $color;
  80. &:hover {
  81. background: $backgroundColor;
  82. }
  83. &:active {
  84. color: darken($color, 10);
  85. }
  86. }
  87. }
  88. @include setTheme()
  89. </style>