forked from asantibanez/livewire-select
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update single asset naming conventions e.g. use livewire-select inste…
…ad of livewireSelect and add �ssetType parameter to renderAssets method
- Loading branch information
1 parent
5f8a9cd
commit 524f01a
Showing
1 changed file
with
15 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,14 +237,14 @@ public function css($options = null) { | |
'tailwindcss' => '<link rel="stylesheet" href="' . asset('/vendor/tailwind.css') . '" />', | ||
]; | ||
|
||
return $this->renderAssets($assets, $options); | ||
return $this->renderAssets('css', $assets, $options); | ||
} | ||
|
||
public function js($options = null) { | ||
$assets = [ | ||
'livewire' => Livewire::scripts(), | ||
'alpine' => '<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>', | ||
'livewireSelect' => '<script> | ||
'livewire-select' => '<script> | ||
window.livewire.on(\'livewire-select-focus-search\', (data) => { | ||
const el = document.getElementById(`${data.name || \'invalid\'}`); | ||
|
@@ -265,7 +265,7 @@ public function js($options = null) { | |
el.focus(); | ||
}); | ||
</script>', | ||
'livewireSelectMultiple' => '<script> | ||
'livewire-select-multiple' => '<script> | ||
function livewireSelectMultiSelectDropdown($el) { | ||
// Select the node that will be observed for mutations | ||
var innerSelectTargetNode = $el.querySelector(\'.livewire-select-input\'); | ||
|
@@ -346,7 +346,7 @@ function livewireSelectMultiSelectDropdown($el) { | |
</script>' | ||
]; | ||
|
||
return $this->renderAssets($assets, $options); | ||
return $this->renderAssets('js', $assets, $options); | ||
} | ||
|
||
public function render() | ||
|
@@ -390,12 +390,20 @@ public function render() | |
* | ||
* @return string | ||
*/ | ||
private function renderAssets($assets = [], $options = null) { | ||
private function renderAssets($assetType = 'js', $assets = [], $options = null) { | ||
if ($options) { | ||
$options = explode(',', $options); | ||
$options = array_map('trim', $options); | ||
if (!in_array('livewireSelect', $options)) { | ||
$options[] = 'livewireSelect'; | ||
|
||
// include mandatory assets | ||
switch ($assetType) { | ||
case 'js': | ||
if (!in_array('livewire-select', $options)) { | ||
$options[] = 'livewire-select'; | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
$assetArray = []; | ||
|