Confirm.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <tippy
  3. :interactive="true"
  4. :touch="true"
  5. :placement="placement"
  6. theme="confirm"
  7. ref="confirm"
  8. trigger="click"
  9. @hide="clickedOnce = false"
  10. >
  11. <div @click.shift.stop="confirm(true)" @click.exact="confirm()">
  12. <slot ref="trigger" />
  13. </div>
  14. <template #content>
  15. <a @click="confirm(null, $event)">
  16. Click to Confirm
  17. </a>
  18. </template>
  19. </tippy>
  20. </template>
  21. <script>
  22. export default {
  23. props: {
  24. placement: {
  25. type: String,
  26. default: "top"
  27. }
  28. },
  29. emits: ["confirm"],
  30. data() {
  31. return {
  32. clickedOnce: false
  33. };
  34. },
  35. methods: {
  36. confirm(confirm, event) {
  37. if (confirm === null) {
  38. /* eslint-disable no-param-reassign */
  39. if (
  40. event &&
  41. event.type === "click" &&
  42. !event.altKey &&
  43. !event.ctrlKey &&
  44. !event.metaKey &&
  45. !event.shiftKey
  46. )
  47. confirm = true;
  48. else confirm = false;
  49. }
  50. if (confirm === false) {
  51. this.clickedOnce = false;
  52. this.$refs.confirm.tip.hide();
  53. } else if (confirm === true || this.clickedOnce === true) {
  54. this.clickedOnce = false;
  55. this.$emit("confirm");
  56. } else this.clickedOnce = true;
  57. }
  58. }
  59. };
  60. </script>