Add AuthorSearch component.

dev
KKlochko 3 months ago
parent f9f10ca1f2
commit 9736fa3507

@ -4,6 +4,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents do
defmacro __using__(_) do
quote do
import MyComponents.AuthorCard, only: [author_card: 1]
import MyComponents.AuthorSearch, only: [author_search: 1]
end
end
end

@ -0,0 +1,53 @@
defmodule DecentralisedBookIndexWeb.Components.MyComponents.AuthorSearch do
use Phoenix.Component
use DecentralisedBookIndexWeb, :verified_routes
attr :search_query, :string, default: ""
attr :select_options, :list, required: true
attr :selected_option, :string, required: true
def author_search(assigns) do
~H"""
<div class="relative bg-white shadow-md dark:bg-gray-800 sm:rounded-lg">
<div class="flex flex-col items-center justify-between p-4 space-y-3 md:flex-row md:space-y-0 md:space-x-4">
<div class="w-full md:w-1/2">
<form class="flex items-center">
<label for="simple-search" class="sr-only">Search</label>
<div class="relative w-full">
<div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
<svg aria-hidden="true" class="w-5 h-5 text-gray-500 dark:text-gray-400" fill="currentColor" viewbox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd" />
</svg>
</div>
<input name="query" type="text" id="simple-search" class="block w-full p-2 pl-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" placeholder="Search by name" value={@search_query}>
</div>
</form>
</div>
<div class="flex flex-col items-stretch justify-end flex-shrink-0 w-full space-y-2 md:w-auto md:flex-row md:space-y-0 md:items-center md:space-x-3">
<.link patch={~p"/authors/new"}>
<button type="button" class="flex items-center justify-center px-4 py-2 text-sm font-medium text-black dark:text-white rounded-lg bg-primary-700 hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 focus:outline-none dark:focus:ring-primary-800">
<svg class="h-3.5 w-3.5 mr-2" fill="currentColor" viewbox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path clip-rule="evenodd" fill-rule="evenodd" d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z" />
</svg>
Add author
</button>
</.link>
<div class="flex items-center w-full space-x-3 md:w-auto">
<form phx-change="change-sort">
<select name="sort_by" id="countries" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<%= for {name, value} <- @select_options do %>
<%= if value == @selected_option do %>
<option value={value} selected>{name}</option>
<% else %>
<option value={value}>{name}</option>
<% end %>
<% end %>
</select>
</form>
</div>
</div>
</div>
</div>
"""
end
end
Loading…
Cancel
Save