DivBtn.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <div ref="btn" class="button clickable row justify-center items-center no-wrap" @click="clickEffect">
  3. <div :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. icon: { type: String, default: '' },
  25. iconSize: { type: Number, default: 14 },
  26. round: { type: Boolean },
  27. pad: { type: Number, default: 0 },
  28. };
  29. pressed = false;
  30. created() {
  31. }
  32. mounted() {
  33. this.updateSizes();
  34. }
  35. updateSizes() {
  36. const style = this.$refs.btn.style;
  37. style.minWidth = `${this.size}px`;
  38. style.height = `${this.size}px`;
  39. if (this.pad) {
  40. style.paddingLeft = `${this.pad}px`;
  41. style.paddingRight = `${this.pad + 5}px`;
  42. }
  43. if (this.round)
  44. style.borderRadius = `${this.size}px`;
  45. }
  46. async clickEffect() {
  47. this.pressed = true;
  48. await utils.sleep(100);
  49. this.pressed = false;
  50. }
  51. }
  52. export default vueComponent(DivBtn);
  53. //-----------------------------------------------------------------------------
  54. </script>
  55. <style scoped>
  56. .button {
  57. position: relative;
  58. box-shadow: 0.5px 1px 3px #333333;
  59. }
  60. .button:hover {
  61. opacity: 0.8;
  62. transition: opacity 0.2s linear;
  63. }
  64. .button-pressed {
  65. margin-left: 2px;
  66. margin-top: 2px;
  67. }
  68. .clickable {
  69. cursor: pointer;
  70. }
  71. </style>