1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import isImage from 'is-image';
7 import { withStyles, WithStyles } from '@material-ui/core';
8 import { FileTreeData } from '~/components/file-tree/file-tree-data';
9 import { CollectionFileType } from '~/models/collection-file';
10 import { sanitizeToken } from "~/views-components/context-menu/actions/helpers";
12 export interface FileThumbnailProps {
16 export const FileThumbnail =
17 ({ file }: FileThumbnailProps) =>
18 file.type === CollectionFileType.FILE && isImage(file.name)
19 ? <ImageFileThumbnail file={file} />
22 type ImageFileThumbnailCssRules = 'thumbnail';
24 const imageFileThumbnailStyle = withStyles<ImageFileThumbnailCssRules>(theme => ({
27 margin: `${theme.spacing.unit}px 0`,
31 const ImageFileThumbnail = imageFileThumbnailStyle(
32 ({ classes, file }: WithStyles<ImageFileThumbnailCssRules> & FileThumbnailProps) =>
34 className={classes.thumbnail}
36 src={sanitizeToken(file.url, false)} />