<template>
    <div
        class="ml-3 relative inline-block text-left"
        @keydown.escape="isOpen = false"
    >

        <!-- Dropdown closed state -->
        <div>
            <div>
                <button
                    @click="isOpen = !isOpen"
                    type="button"
                    class="max-w-xs flex items-center text-sm rounded-full focus:outline-none focus:shadow-outline group"
                >
                    <slot name="header-menu-avatar"></slot>
                </button>
            </div>
        </div>

        <!-- Fix for the click away event to force close -->
        <div
            v-if="isOpen"
            @click="isOpen = false"
            class="fixed inset-0"
            tabindex="-1"
        ></div>

        <!-- Dropdown open state -->
        <transition
            enter-active-class="transition ease-out duration-100"
            enter-class="transform opacity-0 scale-95"
            enter-to-class="transform opacity-100 scale-100"
            leave-active-class="transition ease-in duration-75"
            leave-class="transform opacity-100 scale-100"
            leave-to-class="transform opacity-0 scale-95"
        >
            <div class="origin-top-right absolute right-0 mt-2 w-56 rounded-sm shadow-lg" v-if="isOpen">
                <div class="rounded-sm bg-white shadow-xs">
                    <slot></slot>
                </div>
            </div>
        </transition>

    </div>
</template>

<script>
export default {
    data() {
        return {
            isOpen : false
        }
    },
}
</script>
