Skip to content

Commit

Permalink
refactor: remove redundant container in ContextMenu component
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwep committed Dec 29, 2023
1 parent 5bdb22c commit 6e2e835
Showing 1 changed file with 20 additions and 32 deletions.
52 changes: 20 additions & 32 deletions src/app/components/base/context-menu/ContextMenu.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
<template>
<div :class="classes">
<div
ref="reference"
v-tooltip="{ text: tooltip, position: tooltipPosition }"
:class="$style.reference"
@click="toggle"
>
<slot />
</div>
<div ref="popper" :class="[$style.popper, { [$style.visible]: visible }]">
<ul :class="listClasses">
<slot v-if="$slots.options" name="options"></slot>
<template v-else-if="options">
<ContextMenuButton
v-for="option of options"
:key="option.id"
:pad-icon="hasOptionWithIcon"
:text="option.label ?? option.id"
:icon="option.icon"
:highlight="option.id === highlight"
@click="select(option)"
/>
</template>
</ul>
</div>
<div ref="reference" v-tooltip="{ text: tooltip, position: tooltipPosition }" :class="classes" @click="toggle">
<slot />
</div>
<div ref="popper" :class="[$style.popper, { [$style.visible]: visible }]">
<ul :class="listClasses">
<slot v-if="$slots.options" name="options"></slot>
<template v-else-if="options">
<ContextMenuButton
v-for="option of options"
:key="option.id"
:pad-icon="hasOptionWithIcon"
:text="option.label ?? option.id"
:icon="option.icon"
:highlight="option.id === highlight"
@click="select(option)"
/>
</template>
</ul>
</div>
</template>

Expand Down Expand Up @@ -91,7 +84,7 @@ watch(
);
const hasOptionWithIcon = computed(() => props.options?.some((v) => v.icon));
const classes = computed(() => [props.class, styles.contextMenu]);
const classes = computed(() => [props.class, styles.reference]);
const listClasses = computed(() => [styles.list, { [styles[placement.value]]: placement.value in styles }]);
const select = (option: ContextMenuOption): void => {
Expand All @@ -107,13 +100,8 @@ provide<ContextMenuStore>(ContextMenuStoreKey, {
</script>

<style lang="scss" module>
.contextMenu {
display: inline-flex;
}
.reference {
all: unset;
display: flex;
display: inline-flex;
}
.popper {
Expand Down

0 comments on commit 6e2e835

Please sign in to comment.