Upload
The TkUpload component is an interface element that allows users to select and upload files from their devices to a server or a target location. It typically includes a "Choose File" button and a field displaying the selected file's name. This component simplifies the process of file selection and uploading.
- React
- Vue
- Angular
import { TkUpload } from '@takeoff-ui/react'
import { TkUpload } from '@takeoff-ui/vue'
import { TkUpload } from '@takeoff-ui/angular'
Basic​
- React
- Vue
- Angular
const handleFilesAccepted = (e) => {
createToast({
header: "Dosya eklendi",
message: `${e.detail.length} dosya eklendi`,
variant: "success",
type: "outlined",
timeout: 10000,
removable: true,
});
};
const handleUpload = (e) => {
console.log(e.detail);
createToast({
header: "Dosya yüklendi",
message: "Dosya yükleme başarılı.",
variant: "success",
type: "filled",
timeout: 10000,
removable: true,
});
};
return (
<TkUpload
onTkFilesAccepted={handleFilesAccepted}
onTkUpload={handleUpload}
></TkUpload>
);
<script setup>
import { TkUpload } from '@takeoff-ui/vue';
import { createToast } from '@takeoff-ui/core';
const handleFilesAccepted = (e) => {
createToast({
header: 'Dosya eklendi',
message: `${e.detail.length} dosya eklendi`,
variant: 'success',
type: 'outlined',
timeout: 10000,
removable: true,
});
};
const handleFilesRejected = (e) => {
let errorMessage = e.detail
?.map((item) => item.reason + ' ' + item.file.name)
.join('');
createToast({
header: `${e.detail.length} dosya eklenemedi!`,
message: errorMessage,
variant: 'success',
type: 'outlined',
timeout: 10000,
removable: true,
});
};
</script>
<template>
<TkUpload
multiple
@tkFilesAccepted="handleFilesAccepted"
@tkFilesRejected="handleFilesRejected"
>
</TkUpload>
</template>
State​
This demo showcases the disabled, invalid and loading states of the upload component.
- React
- Vue
- Angular
<TkUpload disabled={true}></TkUpload>
<TkUpload invalid={true} error="This is an error message"></TkUpload>
<TkUpload loading={true}></TkUpload>
<TkUpload :disabled="true"></TkUpload>
<TkUpload :invalid="true" error="This is an error message"></TkUpload>
<TkUpload :loading="true"></TkUpload>
Accept​
This demo demonstrates the use of the accept prop to accept only PNG files for upload. By setting accept to "image/png", it restricts users to select only image files in PNG format. File types can be specified using MIME types or extensions separated by commas.
- React
- Vue
- Angular
const handleFilesAccepted = (e) => {
createToast({
header: "Dosya eklendi",
message: `${e.detail.length} dosya eklendi`,
variant: "success",
type: "outlined",
timeout: 10000,
removable: true,
});
};
const handleFilesRejected = (e) => {
let errorMessage = e.detail
?.map((item) => item.reason + " " + item.file.name)
.join("
");
createToast({
header: `${e.detail.length} dosya eklenemedi!`,
message: errorMessage,
variant: "success",
type: "outlined",
timeout: 10000,
removable: true,
});
};
return (
<>
<TkUpload
accept="image/png"
multiple
onTkFilesAccepted={handleFilesAccepted}
onTkFilesRejected={handleFilesRejected}
></TkUpload>
</>
);
<script setup>
import { TkUpload } from '@takeoff-ui/vue'
import { createToast } from "@takeoff-ui/core";
const handleFilesAccepted = (e) => {
createToast({
header: "Dosya eklendi",
message: `${e.detail.length} dosya eklendi`,
variant: "success",
type: "outlined",
timeout: 10000,
removable: true,
});
};
const handleFilesRejected = (e) => {
let errorMessage = e.detail
?.map((item) => item.reason + " " + item.file.name)
.join("");
createToast({
header: `${e.detail.length} dosya eklenemedi!`,
message: errorMessage,
variant: "success",
type: "outlined",
timeout: 10000,
removable: true,
});
};
</script>
<template>
<TkUpload accept="image/png" multiple @tkFilesAccepted="handleFilesAccepted" @tkFilesRejected="handleFilesRejected">
</TkUpload>
</template>
AutoUpload​
This demo demonstrates the use of autoUpload prop to automaticaly trigger tkUpload event when a new file is added.
- React
- Vue
- Angular
const handleUpload = (e) => {
console.log(e.detail);
createToast({
header: "Dosya yüklendi",
message: "Dosya yükleme başarılı.",
variant: "success",
type: "filled",
timeout: 10000,
removable: true,
});
};
return (
<TkUpload
autoUpload
multiple
onTkUpload={handleUpload}
></TkUpload>
);
<script setup>
import { TkUpload } from '@takeoff-ui/vue';
import { createToast } from '@takeoff-ui/core';
const handleUpload= (e) => {
createToast({
header: 'Dosya yüklendi',
message: "Dosya yükleme başarılı.",
variant: 'success',
type: 'outlined',
timeout: 10000,
removable: true,
});
};
</script>
<template>
<TkUpload
:autoUpload.prop="true"
multiple
@tkUpload="handleUpload"
>
</TkUpload>
</template>
Type​
This demo showcases the type
prop of the upload component.
- React
- Vue
- Angular
const handleChange= (e) => {
createToast({
header: 'Dosya eklendi',
message: `${e.detail.length} dosya eklendi`,
variant: 'success',
type: 'outlined',
timeout: 10000,
removable: true,
});
};
const handleUpload = (e) => {
console.log(e.detail);
createToast({
header: 'Dosya yüklendi',
message: `${e.detail.length} dosya yüklendi`,
variant: 'success',
type: 'filled',
timeout: 10000,
removable: true,
});
};
return (
<div>
<TkUpload
onTkChange={handleChange}
onTkUpload={handleUpload}
></TkUpload>
<TkUpload
type="centered"
onTkChange={handleChange}
onTkUpload={handleUpload}
></TkUpload>
</div>
);
<script setup>
import { TkUpload } from '@takeoff-ui/vue';
import { createToast } from '@takeoff-ui/core';
const handleChange = (e) => {
createToast({
header: 'Dosya eklendi',
message: `${e.detail.length} dosya eklendi`,
variant: 'success',
type: 'outlined',
timeout: 10000,
removable: true,
});
};
const handleUpload = (e) => {
console.log(e.detail);
createToast({
header: 'Dosya yüklendi',
message: `${e.detail.length} dosya yüklendi`,
variant: 'success',
type: 'filled',
timeout: 10000,
removable: true,
});
};
</script>
<template>
<TkUpload
multiple
@tkChange="handleChange"
@tkUpload="handleUpload"
>
</TkUpload>
<TkUpload
multiple
type="centered"
@tkChange="handleChange"
@tkUpload="handleUpload"
>
</TkUpload>
</template>
Upload API​
Props​
Name | Type | Default | Description |
---|---|---|---|
string | '*' | Acceptable file types for upload. Use MIME types or extensions separated by commas. | |
boolean | false | If autoUpload is set to true , the upload button will be hidden, and the tkUpload event will be automatically triggered for each newly added file. | |
string | 'ChooseFile' | Label text displayed inside the choose button. | |
string | 'JPEG, PNG, PDFandMP4formats, upto50MB.' | Description displayed under the title. | |
boolean | false | Disables the input, preventing user interaction. | |
boolean | false | Indicates whether the files can be downloaded. When true, a download button will be displayed next to each file. | |
boolean | true | Enables drag and drop functionality for file uploads. | |
string | 'Releasetouploadfiles' | Description displayed under the title when drag and drop is active. | |
string | 'Dropfileshere' | Title displayed in the upload component when drag and drop is active. | |
string | null | Provided a error about the upload. | |
string | null | Provided a hint or additional information about the input. | |
boolean | false | Indicates whether the upload is in an invalid state, uploads will fail eventually | |
string | null | Defines the label of the upload area | |
boolean | false | Indicates whether the upload is in an loading state | |
number | null | Maximum allowed file count | |
number | null | Maximum allowed file size in bytes. | |
boolean | false | Allows multiple file selection. | |
boolean | false | Displays a red asterisk (*) next to the label for visual emphasis. | |
boolean | true | Displays the uploaded files. | |
string | 'Chooseafileordrag&dropithere.' | Title displayed in the upload component. | |
"centered", "default" | 'default' | Type of the file upload area. | |
string | 'Upload' | Label text displayed inside the upload button. | |
File[] | [] | The file value of the upload. |
Events​
Name | Description |
---|---|
tk-change | Emitted when one or more files pass validation. |
tk-download-file | Emitted when a file is download button is clicked. |
tk-files-rejected | Emitted when one or more files fail validation, with reasons. |
tk-removed-file | Emitted when a file is removed from the accepted list. |
tk-upload | Emitted when the user initiates file upload. |