ChatAttachment
A file as a chip: an icon or an image preview, its name and size, and a remove button.
On this page
Examples
Cards and thumbnails
Idle, uploading and failed states; removing needs interactivity.
report.pdfPDF · 242.2 KB
notes.txtTXT · 1.2 KB
upload.zipZIP · 5.1 MB(uploading)
broken.csvUpload failed: the file is too large.(failed)
Nothing removed
Razor
@* A data URI stands in for an uploaded picture. *@
<div class="flex w-full max-w-xl flex-col gap-4" data-testid="chat-attachment-example">
<div class="flex flex-wrap items-center gap-2">
<KlyChatAttachment Name="report.pdf" Type="application/pdf" FileSize="248000" />
<KlyChatAttachment Name="notes.txt" Type="text/plain" FileSize="1200" Removable OnRemove="RemoveNotes" data-testid="chat-attachment-removable" />
<KlyChatAttachment Name="upload.zip" Type="application/zip" FileSize="5400000" Status="ChatAttachmentStatus.Uploading" />
<KlyChatAttachment Name="broken.csv" Type="text/csv" Description="Upload failed: the file is too large." Status="ChatAttachmentStatus.Error" />
</div>
<p class="text-sm text-(--klyroo-text-muted)" role="status" data-testid="chat-attachment-removed">@(_removed is null ? "Nothing removed" : $"Removed {_removed}")</p>
<div class="flex flex-wrap items-center gap-2">
<KlyChatAttachment Name="sunset.svg" Type="image/svg+xml" Url="@Picture" Variant="ChatAttachmentVariant.Thumbnail" Removable />
<KlyChatAttachment Name="sunset.svg" Type="image/svg+xml" Url="@Picture" FileSize="900" Orientation="KlyOrientation.Vertical" Class="w-48" />
</div>
</div>
@code {
private string? _removed;
private void RemoveNotes() => _removed = "notes.txt";
private const string Picture =
"data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 48'%3E%3Crect width='64' height='48' fill='%23ffb347'/%3E%3Ccircle cx='32' cy='36' r='14' fill='%23ff6b4a'/%3E%3C/svg%3E";
}API
KlyChatAttachment
File shown as a chip or a thumbnail in a chat, with its name, size, upload status and a remove button.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Color |
KlyColor |
"neutral" |
Semantic color of the chat attachment: a built-in KlyColor or the name of a color you defined. Values: primary, secondary, success, info, warning, error, neutral. |
Description |
string |
Replaces the default description: the extension, then the size. For an error, put the reason here. | |
FileSize |
Int64? |
Size in bytes, shown in the description. | |
ImageOptions |
KlyImageOptions |
Image settings forwarded to the preview of an image, see KlyImage . A horizontal card passes the size of its square preview as the width and the height; a thumbnail or a vertical card takes the size of its container, so give Sizes to get a srcset . | |
Name (required) |
string |
"" |
File name. |
Orientation |
KlyOrientation |
KlyOrientation. |
Card only: a vertical card gives an image a large preview. Values: Horizontal, Vertical. |
Removable |
bool |
false |
Shows a remove button. Raise OnRemove and take the attachment out of your list. |
Size |
KlySize |
KlySize. |
Size of the chat attachment, from Xs to Xl . When not set, Size applies, else the default of the component. Values: Xs, Sm, Md, Lg, Xl. |
Status |
Chat |
Chat |
Whether the file is idle, uploading or failed ( ChatAttachmentStatus ). Values: Idle, Uploading, Error. |
Type |
string |
Media type ("image/png"): images with a Url show a preview. | |
Ui |
ChatAttachmentUi |
Per-instance class overrides of the slots of the chat attachment, see ChatAttachmentUi . They are merged after the theme and the Class parameter wins on the root slot. | |
Url |
string |
Address of the file. With an image media type, the attachment shows a preview of it. | |
Variant |
Chat |
Chat |
Look of the attachment: a Card or a Thumbnail . Values: Card, Thumbnail. |
Events
| Name | Type | Description |
|---|---|---|
OnRemove |
EventCallback |
Raised when the user clicks the remove button. Take the attachment out of your list. |
Slots
| Name | Type | Description |
|---|---|---|
Icon |
RenderFragment |
Replaces the file icon. |
Ui slots
Ui takes a ChatAttachmentUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyChatAttachment , after the theme and the app configuration. |
Leading |
Classes merged into the leading slot of KlyChatAttachment , after the theme and the app configuration. |
LeadingIcon |
Classes merged into the leadingIcon slot of KlyChatAttachment , after the theme and the app configuration. |
Image |
Classes merged into the image slot of KlyChatAttachment , after the theme and the app configuration. |
Wrapper |
Classes merged into the wrapper slot of KlyChatAttachment , after the theme and the app configuration. |
Name |
Classes merged into the name slot of KlyChatAttachment , after the theme and the app configuration. |
Description |
Classes merged into the description slot of KlyChatAttachment , after the theme and the app configuration. |
Remove |
Classes merged into the remove slot of KlyChatAttachment , after the theme and the app configuration. |
RemoveIcon |
Classes merged into the removeIcon slot of KlyChatAttachment , after the theme and the app configuration. |