DivBtn.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div ref="btn" class="button clickable row justify-center items-center" :class="{disabled}" @click.stop.prevent="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: Boolean,
  30. imt: { type: Number, default: 0 },// icon margin top
  31. disabled: Boolean,
  32. noShadow: Boolean,
  33. };
  34. pressed = false;
  35. created() {
  36. }
  37. mounted() {
  38. this.updateSizes();
  39. }
  40. updateSizes() {
  41. const style = this.$refs.btn.style;
  42. style.minWidth = `${(this.minWidth ? this.minWidth : this.size)}px`;
  43. style.height = `${(this.height ? this.height : this.size)}px`;
  44. if (this.pad) {
  45. style.paddingLeft = `${this.pad}px`;
  46. style.paddingRight = `${this.pad + 5}px`;
  47. }
  48. if (this.round)
  49. style.borderRadius = `${this.size}px`;
  50. else
  51. style.borderRadius = `${this.size/10}px`;
  52. if (!this.noShadow)
  53. style.boxShadow = '0.5px 1px 3px #333333';
  54. }
  55. async clickEffect(event) {
  56. if (this.disabled) {
  57. return;
  58. }
  59. this.$emit('meClick', event);
  60. this.pressed = true;
  61. await utils.sleep(100);
  62. this.pressed = false;
  63. }
  64. }
  65. export default vueComponent(DivBtn);
  66. //-----------------------------------------------------------------------------
  67. </script>
  68. <style scoped>
  69. .button {
  70. position: relative;
  71. }
  72. .button:hover {
  73. opacity: 0.8;
  74. transition: opacity 0.2s linear;
  75. }
  76. .button-pressed {
  77. margin-left: 1px;
  78. margin-top: 1px;
  79. margin-right: -1px;
  80. margin-bottom: -1px;
  81. }
  82. .clickable {
  83. cursor: pointer;
  84. }
  85. </style>