Packages

PyraUI is a Phoenix LiveView component library delivering production-ready, premium UI building blocks.

Current section

Files

Jump to
pyraui lib pyraui_web live docs autocomplete_docs.ex
Raw

lib/pyraui_web/live/docs/autocomplete_docs.ex

defmodule PyrauiWeb.DocsLive.AutocompleteDocs do
use PyrauiWeb, :html
def render(assigns) do
~H"""
<div class="text-gray-900">
<h1 class="text-4xl font-bold mb-4 text-gray-900">Autocomplete</h1>
<div class="mb-8">
<p class="text-gray-700 text-lg">
Autocomplete component with live search and suggestion list while typing. Provides keyboard navigation and debounced search.
</p>
</div>
<div class="space-y-8">
<section>
<h2 class="text-2xl font-semibold mb-4 text-gray-900">Basic Autocomplete</h2>
<div class="bg-white p-6 rounded-lg border border-gray-200 mb-4 shadow-sm">
<Pyraui.Components.Autocomplete.autocomplete
id="docs-autocomplete-1"
options={@sample_options}
placeholder="Search fruits..."
label="Fruit Search"
/>
</div>
<div class="bg-gray-100 p-4 rounded-lg overflow-x-auto border border-gray-200">
<pre class="text-gray-800"><code phx-no-curly-interpolation>
&lt;.autocomplete id="search-users" field={@form[:user]} options={users} /&gt;
</code></pre>
</div>
</section>
<section>
<h2 class="text-2xl font-semibold mb-4 text-gray-900">With Form Field</h2>
<div class="bg-gray-100 p-4 rounded-lg overflow-x-auto border border-gray-200">
<pre class="text-gray-800"><code phx-no-curly-interpolation>
&lt;.autocomplete id="product-search" field={@form[:product]} options={products} min_chars={2} /&gt;
</code></pre>
</div>
</section>
<section>
<h2 class="text-2xl font-semibold mb-4 text-gray-900">With Custom Options</h2>
<div class="bg-gray-100 p-4 rounded-lg overflow-x-auto border border-gray-200">
<pre class="text-gray-800"><code phx-no-curly-interpolation>
&lt;.autocomplete
id="user-search"
options={[{"John Doe", "1"}, {"Jane Smith", "2"}]}
max_results={5}
/&gt;
</code></pre>
</div>
</section>
<section>
<h2 class="text-2xl font-semibold mb-4 text-gray-900">Props</h2>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200 border border-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-700 uppercase">
Prop
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-700 uppercase">
Type
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-700 uppercase">
Default
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-700 uppercase">
Description
</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">id</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">string</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">-</td>
<td class="px-6 py-4 text-sm text-gray-700">Unique ID for the autocomplete</td>
</tr>
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">field</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">
Phoenix.HTML.FormField
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">nil</td>
<td class="px-6 py-4 text-sm text-gray-700">Form field struct (optional)</td>
</tr>
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
options
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">list</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">-</td>
<td class="px-6 py-4 text-sm text-gray-700">
List of options (strings or label-value tuples)
</td>
</tr>
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
min_chars
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">integer</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">1</td>
<td class="px-6 py-4 text-sm text-gray-700">
Minimum characters before showing suggestions
</td>
</tr>
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
max_results
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">integer</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">10</td>
<td class="px-6 py-4 text-sm text-gray-700">
Maximum number of suggestions to show
</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</div>
"""
end
end