Add events to popover component and handlers for them
This commit is contained in:
parent
50bca2cca9
commit
b83d9b9faa
|
|
@ -1,15 +1,30 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="highlight-popover">
|
<div class="highlight-popover">
|
||||||
<section class="highlight-popover__section">
|
<section class="highlight-popover__section">
|
||||||
<div class="highlight-popover__color highlight-popover__color--yellow"></div>
|
<div
|
||||||
<div class="highlight-popover__color highlight-popover__color--pink"></div>
|
class="highlight-popover__color highlight-popover__color--yellow"
|
||||||
<div class="highlight-popover__color highlight-popover__color--blue"></div>
|
@click="$emit('choose-color', 'yellow')"
|
||||||
|
></div>
|
||||||
|
<div
|
||||||
|
class="highlight-popover__color highlight-popover__color--pink"
|
||||||
|
@click="$emit('choose-color', 'pink')"
|
||||||
|
></div>
|
||||||
|
<div
|
||||||
|
class="highlight-popover__color highlight-popover__color--blue"
|
||||||
|
@click="$emit('choose-color', 'blue')"
|
||||||
|
></div>
|
||||||
</section>
|
</section>
|
||||||
<section class="highlight-popover__section">
|
<section class="highlight-popover__section">
|
||||||
<note-icon class="highlight-popover__icon" />
|
<note-icon
|
||||||
|
class="highlight-popover__icon"
|
||||||
|
@click="$emit('confirm')"
|
||||||
|
/>
|
||||||
</section>
|
</section>
|
||||||
<section class="highlight-popover__section">
|
<section class="highlight-popover__section">
|
||||||
<trash-icon class="highlight-popover__icon" />
|
<trash-icon
|
||||||
|
class="highlight-popover__icon"
|
||||||
|
@click="$emit('close')"
|
||||||
|
/>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -21,7 +36,7 @@ export interface Props {
|
||||||
top: string;
|
top: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
defineEmits(['close', 'confirm']);
|
defineEmits(['close', 'confirm', 'choose-color']);
|
||||||
defineProps<Props>();
|
defineProps<Props>();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,8 +135,26 @@ export const getSelectionHandler = (el: HTMLElement, contentBlock: ContentBlockN
|
||||||
|
|
||||||
const positionOfContentBlock = el.getBoundingClientRect();
|
const positionOfContentBlock = el.getBoundingClientRect();
|
||||||
const positionOfSelection = paragraph?.getBoundingClientRect();
|
const positionOfSelection = paragraph?.getBoundingClientRect();
|
||||||
const offetTop = positionOfSelection.top - positionOfContentBlock.top;
|
const offsetTop = positionOfSelection.top - positionOfContentBlock.top;
|
||||||
popover.show(el, offetTop);
|
popover
|
||||||
|
.show({
|
||||||
|
wrapper: el,
|
||||||
|
offsetTop,
|
||||||
|
onChooseColor: (color: string) => {
|
||||||
|
console.log('chosenColor', color);
|
||||||
|
// const newHighlight: Highlight = {
|
||||||
|
// contentBlock: contentBlock.id,
|
||||||
|
// contentIndex:
|
||||||
|
//
|
||||||
|
// };
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
console.log('confirmed');
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
console.log('canceled');
|
||||||
|
});
|
||||||
// todo: how do we save this? maybe we need to move away from the directive and do this inside the mounted
|
// todo: how do we save this? maybe we need to move away from the directive and do this inside the mounted
|
||||||
// and unmounted hooks of the ContentBlock
|
// and unmounted hooks of the ContentBlock
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,14 @@ import { createApp } from 'vue';
|
||||||
|
|
||||||
type ResolveReject = (v?: unknown) => void;
|
type ResolveReject = (v?: unknown) => void;
|
||||||
|
|
||||||
|
interface Options {
|
||||||
|
wrapper: HTMLElement;
|
||||||
|
offsetTop: number;
|
||||||
|
onChooseColor: (color: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
show(wrapper: HTMLElement, offsetTop: number) {
|
show({ wrapper, offsetTop, onChooseColor }: Options) {
|
||||||
const mountEl = document.createElement('div');
|
const mountEl = document.createElement('div');
|
||||||
wrapper.appendChild(mountEl);
|
wrapper.appendChild(mountEl);
|
||||||
|
|
||||||
|
|
@ -39,6 +45,7 @@ export default {
|
||||||
cleanUp();
|
cleanUp();
|
||||||
_reject();
|
_reject();
|
||||||
},
|
},
|
||||||
|
onChooseColor,
|
||||||
});
|
});
|
||||||
|
|
||||||
popover.mount(mountEl);
|
popover.mount(mountEl);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue