Lewati ke konten
MarkasUI
Ketik untuk mencari

    Panduan

    MarkasUI

    Form

    Feedback

    Overlay

    Navigasi

    Data

    Section

    Animasi

    Latar

    Tombol

    Template

    Halaman

    File Dropzone

    Area unggah drag and drop di atas input file native. Memeriksa jenis, ukuran, dan jumlah file, lalu menampilkan ikon, ukuran, progress, dan tombol hapus.

    • brand-guidelines.pdf2.3 MB
    • hero-photo.jpg1.1 MB
    • launch-video.mov46 MB
    • brand-guidelines.pdf2.3 MB
    • hero-photo.jpg1.1 MB
    • launch-video.mov46 MB
    • brand-guidelines.pdf 2.3 MB
    • hero-photo.jpg 1.1 MB
    • launch-video.mov 46 MB
    • brand-guidelines.pdf2.3 MB
    • hero-photo.jpg1.1 MB
    • launch-video.mov46 MB
    @php
        $files = [
            ['name' => 'brand-guidelines.pdf', 'size' => 2457600, 'type' => 'application/pdf', 'progress' => 100],
            ['name' => 'hero-photo.jpg', 'size' => 1153434, 'type' => 'image/jpeg', 'progress' => 64],
            ['name' => 'launch-video.mov', 'size' => 48234496, 'type' => 'video/quicktime', 'error' => 'Larger than 5 MB'],
        ];
    @endphp
    
    <x-markas.file-dropzone
        name="attachments[]"
        accept="image/*,.pdf"
        multiple
        :max-size="5242880"
        :max-files="4"
        hint="Images or PDF, up to 5 MB each"
        :files="$files"
    />
    import { FileDropzone } from "@/components/markas/FileDropzone";
    
    const files = [
      {
        name: "brand-guidelines.pdf",
        size: 2457600,
        type: "application/pdf",
        progress: 100,
      },
      { name: "hero-photo.jpg", size: 1153434, type: "image/jpeg", progress: 64 },
      {
        name: "launch-video.mov",
        size: 48234496,
        type: "video/quicktime",
        error: "Larger than 5 MB",
      },
    ];
    
    export default function FileDropzoneExample() {
      return (
        <FileDropzone
          name="attachments[]"
          accept="image/*,.pdf"
          multiple
          maxSize={5242880}
          maxFiles={4}
          hint="Images or PDF, up to 5 MB each"
          files={files}
        />
      );
    }
    <script setup lang="ts">
    import FileDropzone from "@/components/markas/FileDropzone.vue";
    
    const files = [
      {
        name: "brand-guidelines.pdf",
        size: 2457600,
        type: "application/pdf",
        progress: 100,
      },
      { name: "hero-photo.jpg", size: 1153434, type: "image/jpeg", progress: 64 },
      {
        name: "launch-video.mov",
        size: 48234496,
        type: "video/quicktime",
        error: "Larger than 5 MB",
      },
    ];
    </script>
    
    <template>
      <FileDropzone
        name="attachments[]"
        accept="image/*,.pdf"
        multiple
        :max-size="5242880"
        :max-files="4"
        hint="Images or PDF, up to 5 MB each"
        :files="files"
      />
    </template>
    <script lang="ts">
      import FileDropzone from "$lib/components/markas/FileDropzone.svelte";
    
      const files = [
        {
          name: "brand-guidelines.pdf",
          size: 2457600,
          type: "application/pdf",
          progress: 100,
        },
        {
          name: "hero-photo.jpg",
          size: 1153434,
          type: "image/jpeg",
          progress: 64,
        },
        {
          name: "launch-video.mov",
          size: 48234496,
          type: "video/quicktime",
          error: "Larger than 5 MB",
        },
      ];
    </script>
    
    <FileDropzone
      name="attachments[]"
      accept="image/*,.pdf"
      multiple
      maxSize={5242880}
      maxFiles={4}
      hint="Images or PDF, up to 5 MB each"
      {files}
    />
    ---
    import FileDropzone from "@/components/markas/FileDropzone.astro";
    
    const files = [
      {
        name: "brand-guidelines.pdf",
        size: 2457600,
        type: "application/pdf",
        progress: 100,
      },
      {
        name: "hero-photo.jpg",
        size: 1153434,
        type: "image/jpeg",
        progress: 64,
      },
      {
        name: "launch-video.mov",
        size: 48234496,
        type: "video/quicktime",
        error: "Larger than 5 MB",
      },
    ];
    ---
    
    <FileDropzone
      name="attachments[]"
      accept="image/*,.pdf"
      multiple
      maxSize={5242880}
      maxFiles={4}
      hint="Images or PDF, up to 5 MB each"
      files={files}
    />
    import { Component } from "@angular/core";
    import { FileDropzone } from "./markas/file-dropzone.component";
    
    @Component({
      selector: "markas-example",
      imports: [FileDropzone],
      template: `
        <markas-file-dropzone
          name="attachments[]"
          accept="image/*,.pdf"
          multiple
          [maxSize]="5242880"
          [maxFiles]="4"
          hint="Images or PDF, up to 5 MB each"
          [files]="files"
        />
      `,
    })
    export default class FileDropzoneExample {
      protected readonly files = [
        {
          name: "brand-guidelines.pdf",
          size: 2457600,
          type: "application/pdf",
          progress: 100,
        },
        { name: "hero-photo.jpg", size: 1153434, type: "image/jpeg", progress: 64 },
        {
          name: "launch-video.mov",
          size: 48234496,
          type: "video/quicktime",
          error: "Larger than 5 MB",
        },
      ];
    }

    Contoh

    Satu foto dengan label sendiri

    Profile photo

    Shown on your profile and next to your comments.

    Profile photo

    Shown on your profile and next to your comments.

    • rania-portrait.png471 KB

    Profile photo

    Shown on your profile and next to your comments.

    • rania-portrait.png471 KB

    Profile photo

    Shown on your profile and next to your comments.

    • rania-portrait.png 471 KB

    Profile photo

    Shown on your profile and next to your comments.

    • rania-portrait.png471 KB

    Di dalam form

    Attachments

    Attachments

    • campaign-brief.docx86 KB

    Attachments

    • campaign-brief.docx86 KB

    Attachments

    • campaign-brief.docx 86 KB

    Attachments

    • campaign-brief.docx86 KB

    Progress unggah

    • keynote-deck.pdf5.6 MB
    • product-demo.mp440 MB
    • voiceover.wav9 MB
    • keynote-deck.pdf5.6 MB
    • product-demo.mp440 MB
    • voiceover.wav9 MB
    • keynote-deck.pdf 5.6 MB
    • product-demo.mp4 40 MB
    • voiceover.wav 9 MB
    • keynote-deck.pdf5.6 MB
    • product-demo.mp440 MB
    • voiceover.wav9 MB

    Instalasi

    npx markasui@latest add file-dropzone

    Pemakaian

    <x-markas.file-dropzone
        name="attachments[]"
        accept="image/*,.pdf"
        multiple
        :max-size="5 * 1024 * 1024"
        :max-files="4"
        hint="Gambar atau PDF, maksimal 5 MB per file"
        drop-label="Letakkan file di sini atau"
        browse-label="pilih file"
        remove-label="Hapus {name}"
        too-large-label="Lebih dari {size}"
        type-label="Jenis file tidak diizinkan"
        too-many-label="Maksimal {max} file"
    />

    Butuh Alpine.js. Di dalam form dengan enctype="multipart/form-data" file yang valid terkirim sebagai attachments[].

    Livewire

    <x-markas.file-dropzone multiple accept="image/*" :max-size="5242880" wire:model="photos" />

    Tambahkan use WithFileUploads; di komponen. Hanya file yang lolos accept, maxSize, dan maxFiles yang diunggah, lewat input file tersembunyi yang membawa wire:model. Progres unggah mengisi bar, dan menghapus semua file mengembalikan properti ke null (atau [] dengan multiple). Tetap validasi lagi di server.

    import { FileDropzone } from "@/components/markas/FileDropzone";
    
    <FileDropzone
      accept="image/*,.pdf"
      multiple
      maxSize={5 * 1024 * 1024}
      maxFiles={4}
      hint="Gambar atau PDF, maksimal 5 MB per file"
      dropLabel="Letakkan file di sini atau"
      browseLabel="pilih file"
      removeLabel="Hapus {name}"
      tooLargeLabel="Lebih dari {size}"
      typeLabel="Jenis file tidak diizinkan"
      tooManyLabel="Maksimal {max} file"
      progress={progress}
      onFilesChange={unggah}
    />;
    <template>
      <FileDropzone
        accept="image/*,.pdf"
        multiple
        :max-size="5 * 1024 * 1024"
        :max-files="4"
        hint="Gambar atau PDF, maksimal 5 MB per file"
        drop-label="Letakkan file di sini atau"
        browse-label="pilih file"
        remove-label="Hapus {name}"
        too-large-label="Lebih dari {size}"
        type-label="Jenis file tidak diizinkan"
        too-many-label="Maksimal {max} file"
        :progress="progress"
        @change="unggah"
      />
    </template>
    <script lang="ts">
      import FileDropzone from "$lib/components/markas/FileDropzone.svelte";
    </script>
    
    <FileDropzone
      accept="image/*,.pdf"
      multiple
      maxSize={5 * 1024 * 1024}
      maxFiles={4}
      hint="Images or PDF, up to 5 MB each"
      {progress}
      onFilesChange={upload}
    />
    ---
    import FileDropzone from "@/components/markas/FileDropzone.astro";
    ---
    
    <FileDropzone
      name="attachments[]"
      accept="image/*,.pdf"
      multiple
      maxSize={5 * 1024 * 1024}
      maxFiles={4}
      hint="Images or PDF, up to 5 MB each"
    />

    Custom element kecil memvalidasi file pilihan, menyimpannya di input native, dan mengirim event markas-change yang menggelembung dengan file valid sebagai detail. Tampilkan progres unggah dengan dropzone.setProgress(name, percent).

    import { Component, signal } from "@angular/core";
    import { FileDropzone } from "./markas/file-dropzone.component";
    
    @Component({
      selector: "app-attachments",
      imports: [FileDropzone],
      template: `
        <markas-file-dropzone
          name="attachments[]"
          accept="image/*,.pdf"
          multiple
          [maxSize]="5242880"
          [maxFiles]="4"
          hint="Images or PDF, up to 5 MB each"
          [progress]="progress()"
          (filesChange)="upload($event)"
        />
      `,
    })
    export class Attachments {
      progress = signal<Record<string, number>>({});
      upload(files: File[]) {}
    }
    • Area jatuh adalah label yang membungkus input file native, jadi klik, Enter, atau Space membuka pemilih. Hanya file valid yang tetap di input, sehingga form biasa mengirimnya.
    • File yang gagal accept, maxSize, atau maxFiles tetap di daftar dengan error sampai dihapus.
    • files menampilkan unggahan sebelumnya (name, size, type, progress, error). Ditampilkan, tidak dikirim.
    • Progress: React dan Vue menerima progress per nama file. Di Blade kirim event file-progress dengan { name, progress } ke komponen.
    • Atribut dan class jatuh ke elemen luar; name, accept, disabled, required, dan id ke input.

    Props

    NamaTipeDefaultKeterangan
    namestring-Nama input file native. File valid yang dipilih dan dijatuhkan ikut terkirim bersama form, jadi pakai attachments[] dengan multiple.
    acceptstring-Jenis yang diizinkan, seperti atribut accept: .pdf, image/*, atau application/zip, dipisah koma. File lain mendapat error jenis.
    multiplebooleanfalseTerus menambah file ke daftar. Tanpa ini pilihan baru menggantikan file.
    maxSizenumber-File terbesar dalam byte, misalnya 5242880 untuk 5 MB. File yang lebih besar tetap di daftar dengan error dan tidak dikirim.
    maxFilesnumber-Jumlah file valid terbanyak saat multiple aktif. File berlebih mendapat error terlalu banyak.
    files{ name, size, type?, progress?, error? }[][]File yang sudah ada di daftar, misalnya unggahan sebelumnya. Ditampilkan tetapi tidak dikirim.
    progressRecord<string, number>{}React dan Vue: progress unggah per nama file, 0 sampai 100. Blade: dispatch file-progress dengan { name, progress } pada komponen.
    hintstring-Teks kecil di bawah ajakan, misalnya PNG atau JPG, maksimal 5 MB.
    disabled / required / idboolean / boolean / stringfalse / false / autoDiteruskan ke input file native. Atribut lain dan class jatuh ke elemen luar.
    onFilesChange / @change / files-change(files: File[]) => void-Dipanggil dengan file valid setiap kali file ditambah atau dihapus. Blade mengirim event files-change.
    dropLabelstringDrop files here orAjakan di area jatuh, diikuti browseLabel.
    browseLabelstringbrowseKata bergaris bawah setelah ajakan.
    removeLabelstringRemove {name}Nama aksesibel tiap tombol hapus. {name} adalah nama file.
    tooLargeLabelstringLarger than {size}Error untuk file di atas maxSize. {size} adalah maxSize yang sudah diformat, misalnya 5 MB.
    typeLabelstringFile type not allowedError untuk file yang tidak cocok dengan accept.
    tooManyLabelstringOnly {max} files allowedError untuk file yang melewati maxFiles. {max} adalah batasnya.
    (filesChange)output<File[]>-Khusus Angular. Memancarkan file valid yang dipilih setiap kali daftar berubah. Svelte memakai onFilesChange seperti React.
    markas-change / setProgress()CustomEvent<File[]> / method-Khusus Astro. Event menggelembung dengan file valid sebagai detail, dan method di markas-file-dropzone untuk menampilkan progres unggah sebuah nama file.

    Aksesibilitas

    • Area jatuh adalah label yang membungkus input file native tersembunyi, sehingga klik, Enter, atau Space membuka pemilih file dan ajakannya menjadi nama input.
    • Fokus keyboard pada input memberi garis fokus pada seluruh area jatuh.
    • Setiap error file adalah role alert, setiap bar progress adalah role progressbar bernama file dengan aria-valuenow, dan setiap tombol hapus menyebut nama file.
    • Dengan reduced motion sorotan saat drag dan ikon yang naik tampil tanpa animasi.

    Komponen terkait

    Komponen markasui lain dengan class yang sama di setiap framework.