40 lines
922 B
Elixir
40 lines
922 B
Elixir
defmodule FriendsWeb.Components.Autocomplete do
|
|
use FriendsWeb, :live_component
|
|
import Helpers
|
|
|
|
alias Phoenix.LiveView.JS
|
|
|
|
def bolden(string, substring) do
|
|
String.replace(
|
|
string,
|
|
substring,
|
|
"<b>#{substring}</b>"
|
|
)
|
|
|> Phoenix.HTML.raw()
|
|
end
|
|
|
|
def search_results(assigns) do
|
|
~H"""
|
|
<div id="search-results" class="absolute w-full bottom-16 left-0">
|
|
|
|
<%= if @search_results do %>
|
|
<ul tabindex="0" class="dropdown-content menu p-0 m-0 shadow bg-base-200 rounded-box overflow-auto">
|
|
<%= for r <- @search_results do %>
|
|
<li class="p-0 m-0">
|
|
<.link id={r[:id]}
|
|
phx_value={r[:value]}
|
|
class="search_result"
|
|
phx-hook="NewRelation"
|
|
onMouseDown={"#{@select_fxn}('#{r[:value]}', '#{r[:name]}')"}>
|
|
<%= r[:name] |> bolden(@search_query) %>
|
|
</.link>
|
|
</li>
|
|
<% end %>
|
|
</ul>
|
|
<% end %>
|
|
|
|
</div>
|
|
"""
|
|
end
|
|
end
|