DivBtn.vue 2.0 KB

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