Button.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <button
  3. class="button"
  4. :class="{
  5. 'disabled': disabled,
  6. 'checked': !disabled && checked,
  7. 'default': !disabled && type === 'default',
  8. 'primary': !disabled && type === 'primary',
  9. 'checkbox': !disabled && type === 'checkbox',
  10. 'radio': !disabled && type === 'radio',
  11. 'small': size === 'small',
  12. 'first': first,
  13. 'last': last,
  14. }"
  15. @click="handleClick()"
  16. >
  17. <slot></slot>
  18. </button>
  19. </template>
  20. <script lang="ts" setup>
  21. const props = withDefaults(defineProps<{
  22. checked?: boolean
  23. disabled?: boolean
  24. type?: 'default' | 'primary' | 'checkbox' | 'radio'
  25. size?: 'small' | 'normal'
  26. first?: boolean
  27. last?: boolean
  28. }>(), {
  29. checked: false,
  30. disabled: false,
  31. type: 'default',
  32. size: 'normal',
  33. first: false,
  34. last: false,
  35. })
  36. const emit = defineEmits<{
  37. (event: 'click'): void
  38. }>()
  39. const handleClick = () => {
  40. if (props.disabled) return
  41. emit('click')
  42. }
  43. </script>
  44. <style lang="scss" scoped>
  45. .button {
  46. height: 32px;
  47. line-height: 32px;
  48. outline: 0;
  49. font-size: 13px;
  50. padding: 0 15px;
  51. text-align: center;
  52. color: $textColor;
  53. border-radius: $borderRadius;
  54. user-select: none;
  55. letter-spacing: 1px;
  56. cursor: pointer;
  57. &.small {
  58. height: 24px;
  59. line-height: 24px;
  60. padding: 0 7px;
  61. letter-spacing: 0;
  62. font-size: 12px;
  63. }
  64. &.default {
  65. background-color: #fff;
  66. border: 1px solid #d9d9d9;
  67. color: $textColor;
  68. &:hover {
  69. color: $themeColor;
  70. border-color: $themeColor;
  71. }
  72. }
  73. &.primary {
  74. background-color: $themeColor;
  75. border: 1px solid $themeColor;
  76. color: #fff;
  77. &:hover {
  78. background-color: $themeHoverColor;
  79. border-color: $themeHoverColor;
  80. }
  81. }
  82. &.checkbox, &.radio {
  83. background-color: #fff;
  84. border: 1px solid #d9d9d9;
  85. color: $textColor;
  86. &:not(.checked):hover {
  87. color: $themeColor;
  88. }
  89. }
  90. &.checked {
  91. color: #fff;
  92. background-color: $themeColor;
  93. border-color: $themeColor;
  94. &:hover {
  95. background-color: $themeHoverColor;
  96. border-color: $themeHoverColor;
  97. }
  98. }
  99. &.disabled {
  100. background-color: #f5f5f5;
  101. border: 1px solid #d9d9d9;
  102. color: #b7b7b7;
  103. cursor: default;
  104. }
  105. }
  106. </style>