Current section
Files
Jump to
Current section
Files
lib/pyraui_web/live/docs/file_upload_docs.ex
defmodule PyrauiWeb.DocsLive.FileUploadDocs 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">File Upload</h1>
<div class="mb-8">
<p class="text-gray-700 text-lg">
File upload component with drag & drop support and live progress tracking. Uses Phoenix LiveView's built-in file upload functionality.
</p>
</div>
<div class="space-y-8">
<section>
<h2 class="text-2xl font-semibold mb-4 text-gray-900">Basic File Upload</h2>
<div class="bg-white p-6 rounded-lg border border-gray-200 mb-4 shadow-sm">
<div class="text-sm text-gray-600 mb-4">
<p>
Note: This component requires LiveView upload configuration in your LiveView module.
</p>
</div>
<div class="border-2 border-dashed border-gray-300 rounded-lg p-8 text-center bg-gray-50">
<p class="text-gray-500">File upload component preview</p>
<p class="text-xs text-gray-400 mt-2">
Configure uploads in your LiveView to see the full component
</p>
</div>
</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>
<.file_upload uploads={@uploads.avatar} label="Upload Avatar" />
</code></pre>
</div>
</section>
<section>
<h2 class="text-2xl font-semibold mb-4 text-gray-900">Multiple Files</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>
<.file_upload uploads={@uploads.documents} accept=".pdf,.doc" max_entries={5} />
</code></pre>
</div>
</section>
<section>
<h2 class="text-2xl font-semibold mb-4 text-gray-900">LiveView Setup</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>
def mount(_params, _session, socket) do
{:ok,
socket
|> allow_upload(:avatar, accept: ~w(.jpg .jpeg .png), max_entries: 1, max_file_size: 10_000_000)}
end
def handle_event("validate", _params, socket) do
{:noreply, socket}
end
def handle_event("cancel-upload", %{"ref" => ref}, socket) do
{:noreply, cancel_upload(socket, :avatar, ref)}
end
</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">
uploads
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">map</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">
Uploads map from socket (e.g., @uploads.avatar)
</td>
</tr>
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
accept
</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">
Accepted file types (e.g., "image/*", ".pdf,.doc")
</td>
</tr>
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
max_entries
</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">Maximum number of files</td>
</tr>
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
max_file_size
</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">10485760</td>
<td class="px-6 py-4 text-sm text-gray-700">
Maximum file size in bytes (default: 10MB)
</td>
</tr>
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
drag_label
</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">
"Drag and drop files here..."
</td>
<td class="px-6 py-4 text-sm text-gray-700">Custom drag & drop label text</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</div>
"""
end
end