Aller au contenu principal

InputFile Component

Description

The InputFile component allows users to upload files via a button-based interface. It supports:

  • File type validation (MIME types and extensions).
  • File size limit enforcement (default: 5MB).
  • Custom file input handling with a hidden input field.
  • Snackbar messages for validation feedback.

Props

PropTypeDefaultDescription
onFileChange(e: React.ChangeEvent<HTMLInputElement>) => void-Callback triggered when a file is selected.
fileInputRefReact.RefObject<HTMLInputElement | null>-Ref to access the file input element.
disabledbooleanfalseDisables file selection.
acceptstring""Specifies accepted file types (e.g., ".png,.jpg").

Example Usage

import { InputFile } from "@nomana-it/liberty-core"
import { useRef } from "react";

export const InputFileExample = () => {
const fileInputRef = useRef<HTMLInputElement | null>(null);

const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (file) {
alert(`Selected file: \${file.name}`);
}
};

return (
<InputFile
onFileChange={handleFileChange}
fileInputRef={fileInputRef}
disabled={false}
accept=".png,.jpg,.pdf"
/>
);
};

🔗 GitHub Repository (Core): Liberty Core
🔗 GitHub Repository (Test Project): Liberty Test
📖 Live Documentation: Liberty Core Docs
💖 Sponsor & Support: Sponsor Liberty Core