DivBtn.vue 2.1 KB

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