DivBtn.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. };
  33. pressed = false;
  34. created() {
  35. }
  36. mounted() {
  37. this.updateSizes();
  38. }
  39. updateSizes() {
  40. const style = this.$refs.btn.style;
  41. style.minWidth = `${(this.minWidth ? this.minWidth : this.size)}px`;
  42. style.height = `${(this.height ? this.height : this.size)}px`;
  43. if (this.pad) {
  44. style.paddingLeft = `${this.pad}px`;
  45. style.paddingRight = `${this.pad + 5}px`;
  46. }
  47. if (this.round)
  48. style.borderRadius = `${this.size}px`;
  49. else
  50. style.borderRadius = `${this.size/10}px`;
  51. }
  52. async clickEffect(event) {
  53. if (this.disabled) {
  54. return;
  55. }
  56. this.$emit('meClick', event);
  57. this.pressed = true;
  58. await utils.sleep(100);
  59. this.pressed = false;
  60. }
  61. }
  62. export default vueComponent(DivBtn);
  63. //-----------------------------------------------------------------------------
  64. </script>
  65. <style scoped>
  66. .button {
  67. position: relative;
  68. box-shadow: 0.5px 1px 3px #333333;
  69. }
  70. .button:hover {
  71. opacity: 0.8;
  72. transition: opacity 0.2s linear;
  73. }
  74. .button-pressed {
  75. margin-left: 2px;
  76. margin-top: 2px;
  77. }
  78. .clickable {
  79. cursor: pointer;
  80. }
  81. </style>