Usage
File Icon shows what kind of file something is, for example in upload lists, attachments, media items, or when a preview can't be loaded. Pass the file name or MIME type and the component picks the icon and format label for you.
import { MtFileIcon } from "@shopware-ag/meteor-component-library";
Examples
Fallbacks
The icon shows as much as it knows about the file. A known format shows its icon and label, a file with only a known category shows the icon alone, and anything else shows the empty page.
Categories
Set category to show the icon of a category without a format label, or to override the category derived from the file.
Formats
Set format to show a format label, without a leading dot, such as pdf.
Supported formats
These are all formats the component knows, grouped by their category. Open the code to see each extension, since longer labels are cut off.
Custom icon and format
Set icon to any icon from the icon kit and format to any label to show formats the component doesn't know.
Broken preview
Set broken when a file failed to load.
Sizes
Set size to one of the supported steps of the --scale-size-* token scale: 24, 32, 40, 48, 56, 64, 72, 80, or 96. The default is 48. The size is the height of the page, which is three quarters as wide, so 48 gives a page of 36 by 48 pixels. The page, icon, and label scale together, and the format label is shown from size 40 up.
Fluid size
Set size to fluid to size the icon with CSS instead, for example in container query units of a media preview. Without a width of your own, it fills its parent. In a parent that takes its width from its content, such as an inline flex container or a table cell, it falls back to the default size.
API reference
Props
| Prop | Type | Default |
|---|---|---|
file-nameThe name of the file, such as `invoice.pdf`. Its extension sets the category and format. | string | undefined |
mime-typeThe MIME type of the file, used when the file name has no known extension. | string | undefined |
formatThe format label, such as `pdf`. Overrides the format from `fileName` and `mimeType`. | string | undefined |
categoryThe category of the file. Overrides the category from the format. | "subtitle" | "audio" | "table" | "video" | "image" | "font" | "document" | "presentation" | "vector" | "archive" | "3d" | "markup" | "executable" | undefined |
iconAn icon from the icon kit, always in the regular style. Overrides the category icon. | string | undefined |
show-formatShows the format label below the icon. Labels need a size of 40 or more. | false | true | true |
brokenShows the broken preview for a file that failed to load. | false | true | false |
sizeThe height of the page, as a step of the `--scale-size-*` token scale. The page is three
quarters as wide as it is high. With `fluid`, the page fills the width of its parent and
everything inside scales with it. In a parent that takes its width from its content, a fluid
icon has the default size. | 32 | 48 | 24 | 40 | 56 | 64 | 72 | 80 | 96 | "fluid" | 48 |
labelThe accessible name, such as `PDF file`. Without it, the icon is decorative. | string | undefined |
Best practices
- Pass
file-nameormime-typeand let the component resolve the icon and label. - Use the same
sizefor all icons in a list. - Show the file name as text next to the icon.
- Do not use File Icon as a thumbnail when a real preview of the file is available.
- Do not use it for interface actions such as uploading or downloading; use Icon instead.
Behavior
- An explicit
formatorcategorywins over what the file name or MIME type say, and the file name wins over the MIME type. A file name without a known extension uses the format of the MIME type. - The extension is the part after the last dot of the file name, so
backup.tar.gzshowsGZ. Queries and hashes of URLs are ignored. - A MIME type without a known format, such as
video/x-unknown, still resolves its category from the type before the slash. - A format label needs an icon. A format the component doesn't know shows the empty page unless you also set
iconorcategory. :show-format="false"hides the label and shows the category icon alone.- An
iconin the solid style, such assolid-star, shows in the regular style.
Accessibility
- Without a
label, the icon is decorative and hidden from assistive technology. Leave it decorative when the file name is shown next to it. - With a
label, such asPDF file, the icon gets theimgrole and the label as its accessible name. - The broken preview only shows a cross. Tell users in text that the file failed to load.
Related components
- Extension Icon: for the icon of an app or plugin.
- Icon: for interface icons from the Meteor icon kit.