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

        <!-- Dropdown closed state -->
        <div>
            <span class="rounded-sm shadow-sm">
                <button
                    @click="isOpen = !isOpen"
                    type="button"
                    class="inline-flex justify-center w-full rounded-sm border border-gray-300 px-4 py-2 bg-white text-sm leading-5 font-medium text-gray-700 hover:text-gray-500 focus:outline-none focus:border-blue-300 focus:shadow-outline-blue active:bg-gray-50 active:text-gray-800 transition ease-in-out duration-150"
                >
                    {{ placeholder }}
                    <svg class="-mr-1 ml-2 h-5 w-5" fill="currentColor" viewBox="0 0 20 20">
                        <path fill-rule="evenodd"
                              d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
                              clip-rule="evenodd"
                        />
                    </svg>
                </button>
            </span>
        </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 {
    props : {
        placeholder : {
            required : true
        }
    },
    data() {
        return {
            isOpen : false
        }
    },
}
</script>
