import { BaseButton, Button, DocumentCard, DocumentCardActivity, DocumentCardDetails, DocumentCardPreview, DocumentCardTitle, Icon, IconButton, IDocumentCardPreviewProps, IDocumentCardStyles, ImageFit, Link, Separator, Spinner, SpinnerSize, Text, TooltipHost, } from "@fluentui/react"; import React, { FunctionComponent, useState } from "react"; import CosmosDBLogo from "../../../../../images/CosmosDB-logo.svg"; import { IGalleryItem } from "../../../../Juno/JunoClient"; import * as FileSystemUtil from "../../../Notebook/FileSystemUtil"; export interface GalleryCardComponentProps { data: IGalleryItem; isFavorite: boolean; showDownload: boolean; showDelete: boolean; onClick: () => void; onTagClick: (tag: string) => void; onFavoriteClick: () => void; onUnfavoriteClick: () => void; onDownloadClick: () => void; onDeleteClick: (beforeDelete: () => void, afterDelete: () => void) => void; } export const GalleryCardComponent: FunctionComponent = ({ data, isFavorite, showDownload, showDelete, onClick, onTagClick, onFavoriteClick, onUnfavoriteClick, onDownloadClick, onDeleteClick, }: GalleryCardComponentProps) => { const CARD_WIDTH = 256; const cardImageHeight = 144; const cardDescriptionMaxChars = 80; const cardItemGapSmall = 8; const cardDeleteSpinnerHeight = 360; const smallTextLineHeight = 18; const [isDeletingPublishedNotebook, setIsDeletingPublishedNotebook] = useState(false); const cardButtonsVisible = isFavorite !== undefined || showDownload || showDelete; const options: Intl.DateTimeFormatOptions = { year: "numeric", month: "short", day: "numeric", }; const dateString = new Date(data.created).toLocaleString("default", options); const cardTitle = FileSystemUtil.stripExtension(data.name, "ipynb"); const renderTruncated = (text: string, totalLength: number): string => { let truncatedDescription = text.substr(0, totalLength); if (text.length > totalLength) { truncatedDescription = `${truncatedDescription} ...`; } return truncatedDescription; }; const generateIconText = (iconName: string, text: string): JSX.Element => { return ( {text} ); }; /* * Fluent UI doesn't support tooltips on IconButtons out of the box. In the meantime the recommendation is * to do the following (from https://developer.microsoft.com/en-us/fluentui#/controls/web/button) */ const generateIconButtonWithTooltip = ( iconName: string, title: string, horizontalAlign: "right" | "left", activate: () => void ): JSX.Element => { return ( handlerOnClick(event, activate)} /> ); }; const handlerOnClick = ( event: | React.MouseEvent | React.MouseEvent< HTMLAnchorElement | HTMLButtonElement | HTMLDivElement | BaseButton | Button | HTMLSpanElement, MouseEvent >, activate: () => void ): void => { event.stopPropagation(); event.preventDefault(); activate(); }; const DocumentCardActivityPeople = [{ name: data.author, profileImageSrc: data.isSample && CosmosDBLogo }]; const previewProps: IDocumentCardPreviewProps = { previewImages: [ { previewImageSrc: data.thumbnailUrl, imageFit: ImageFit.cover, width: CARD_WIDTH, height: cardImageHeight, }, ], }; const cardStyles: IDocumentCardStyles = { root: { display: "inline-block", marginRight: 20, width: CARD_WIDTH }, }; return ( {isDeletingPublishedNotebook && ( )} {!isDeletingPublishedNotebook && ( <> {data.tags ? ( data.tags.map((tag, index, array) => ( handlerOnClick(event, () => onTagClick(tag))}>{tag} {index === array.length - 1 ? <> : ", "} )) ) : (
)}
{data.views !== undefined && generateIconText("RedEye", data.views.toString())} {data.downloads !== undefined && generateIconText("Download", data.downloads.toString())} {data.favorites !== undefined && generateIconText("Heart", data.favorites.toString())}
{cardButtonsVisible && ( {isFavorite !== undefined && generateIconButtonWithTooltip( isFavorite ? "HeartFill" : "Heart", isFavorite ? "Unfavorite" : "Favorite", "left", isFavorite ? onUnfavoriteClick : onFavoriteClick )} {showDownload && generateIconButtonWithTooltip("Download", "Download", "left", onDownloadClick)} {showDelete && generateIconButtonWithTooltip("Delete", "Remove", "right", () => onDeleteClick( () => setIsDeletingPublishedNotebook(true), () => setIsDeletingPublishedNotebook(false) ) )} )} )}
); };