defmodule MvWeb.Components.SearchBarComponent do @moduledoc """ Provides the SearchBar Live-Component. - uses the DaisyUI search input field - sends search_changed event to parent live view with a query """ use MvWeb, :live_component @impl true def update(_assigns, socket) do socket = socket |> assign_new(:query, fn -> "" end) |> assign_new(:placeholder, fn -> gettext("Search...") end) {:ok, socket} end @impl true def render(assigns) do ~H""" """ end @impl true # Function to handle the search def handle_event("search", %{"query" => q}, socket) do # Forward a high level message to the parent send(self(), {:search_changed, q}) {:noreply, assign(socket, :query, q)} end end