DivBtn.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div ref="btn" class="button clickable row justify-center items-center" @click="clickEffect">
  3. <div class="row justify-center items-center no-wrap" :class="{'button-pressed': pressed}">
  4. <i :class="icon" :style="`font-size: ${iconSize}px; margin-top: ${imt}px`" />
  5. <slot></slot>
  6. </div>
  7. <slot name="tooltip"></slot>
  8. </div>
  9. </template>
  10. <script>
  11. //-----------------------------------------------------------------------------
  12. import vueComponent from '../vueComponent.js';
  13. import * as utils from '../../share/utils';
  14. const componentOptions = {
  15. watch: {
  16. size() {
  17. this.updateSizes();
  18. },
  19. }
  20. };
  21. class DivBtn {
  22. _options = componentOptions;
  23. _props = {
  24. size: { type: Number, default: 24 },
  25. minWidth: { type: Number, default: 0 },
  26. height: { type: Number, default: 0 },
  27. icon: { type: String, default: '' },
  28. iconSize: { type: Number, default: 14 },
  29. round: { type: Boolean },
  30. imt: { type: Number, default: 0 },// icon margin top
  31. };
  32. pressed = false;
  33. created() {
  34. }
  35. mounted() {
  36. this.updateSizes();
  37. }
  38. updateSizes() {
  39. const style = this.$refs.btn.style;
  40. style.minWidth = `${(this.minWidth ? this.minWidth : this.size)}px`;
  41. style.height = `${(this.height ? this.height : this.size)}px`;
  42. if (this.pad) {
  43. style.paddingLeft = `${this.pad}px`;
  44. style.paddingRight = `${this.pad + 5}px`;
  45. }
  46. if (this.round)
  47. style.borderRadius = `${this.size}px`;
  48. else
  49. style.borderRadius = `${this.size/10}px`;
  50. }
  51. async clickEffect() {
  52. this.pressed = true;
  53. await utils.sleep(100);
  54. this.pressed = false;
  55. }
  56. }
  57. export default vueComponent(DivBtn);
  58. //-----------------------------------------------------------------------------
  59. </script>
  60. <style scoped>
  61. .button {
  62. position: relative;
  63. box-shadow: 0.5px 1px 3px #333333;
  64. }
  65. .button:hover {
  66. opacity: 0.8;
  67. transition: opacity 0.2s linear;
  68. }
  69. .button-pressed {
  70. margin-left: 2px;
  71. margin-top: 2px;
  72. }
  73. .clickable {
  74. cursor: pointer;
  75. }
  76. </style>