Skip to content

Instantly share code, notes, and snippets.

@chrisbaswell
Created November 7, 2021 17:03
Show Gist options
  • Save chrisbaswell/0d5b29d9b7a7679563d72442dea16285 to your computer and use it in GitHub Desktop.
Save chrisbaswell/0d5b29d9b7a7679563d72442dea16285 to your computer and use it in GitHub Desktop.
Popper drop down blade component
@props([
'trigger' => ''
])
<div x-data="dropdown()" x-init="Popper.createPopper($el, $refs.popper, { placement: 'left', modifiers: [{name:'offset', options: {offset:[0,5]}}]});">
<div class="relative inline-block text-left">
<div x-spread="trigger">
@if($trigger)
{{ $trigger }}
@else
<button type="button" class="inline-flex items-center px-0 py-1 border border-transparent rounded-md shadow-sm text-gray-400 bg-gray-100 hover:bg-gray-200 focus:outline-none "
id="options-menu" aria-haspopup="true" aria-expanded="true">
<!-- Heroicon name: solid/dots-vertical -->
<svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path d="M10 6a2 2 0 110-4 2 2 0 010 4zM10 12a2 2 0 110-4 2 2 0 010 4zM10 18a2 2 0 110-4 2 2 0 010 4z" />
</svg>
</button>
@endif
</div>
</div>
<div x-spread="dialogue"
x-ref="popper"
x-cloak
class="absolute rounded-md shadow-lg z-10 bg-white ring-1 ring-black ring-opacity-5 divide-y divide-gray-200 focus:outline-none
role="menu" aria-orientation="vertical" aria-labelledby="options-menu">
{{ $slot }}
</div>
</div>
@once
@push('scripts')
<script>
window.dropdown = function () {
return {
open: false,
trigger: {
['@click']() {
this.open = true
},
['@focus']() {
this.open = true
},
['@keydown']() {
this.open = true
},
},
dialogue: {
['x-show']() {
return this.open
},
['@click.away']() {
this.open = false
},
}
}
}
</script>
@endpush
@endonce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment