Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show preview image in folder content on hover #6551

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/volto/news/6550.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show preview image in folder contents view on hover @iRohitSingh
64 changes: 55 additions & 9 deletions packages/volto/src/components/manage/Contents/ContentsItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
*/

import React from 'react';
import { Button, Table, Menu, Divider } from 'semantic-ui-react';
import {
Button,
Table,
Menu,
Divider,
Popup as SemanticUiPopup,
} from 'semantic-ui-react';
import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';
import map from 'lodash/map';
Expand Down Expand Up @@ -75,11 +81,45 @@ function getColor(string) {
}
}

// PreviewImage Component
const PreviewImage = ({ item }) => {
const previewImageUrl = `${item['@id']}/${item.image_scales?.image?.[0]?.scales?.teaser?.download}`;
const previewIconUrl = `${item['@id']}/${item.image_scales?.image?.[0]?.scales?.thumb?.download}`;

return (
<SemanticUiPopup
trigger={
<div className="preview-image-container">
<img
className="popup-image-icon"
src={previewIconUrl}
alt=""
loading="lazy"
/>{' '}
<span title={item.title}> {item.title}</span>
</div>
}
>
<SemanticUiPopup.Content>
<div>
<img
className="popup-preview-image"
src={previewImageUrl}
alt=""
loading="lazy"
/>
</div>
</SemanticUiPopup.Content>
</SemanticUiPopup>
);
};

/**
* Contents item component class.
* @function ContentsItemComponent
* @returns {string} Markup of the component.
*/

export const ContentsItemComponent = ({
item,
selected,
Expand Down Expand Up @@ -156,14 +196,20 @@ export const ContentsItemComponent = ({
to={`${item['@id']}${item.is_folderish ? '/contents' : ''}`}
>
<div className="expire-align">
<Icon
name={getContentIcon(item['@type'], item.is_folderish)}
size="20px"
className="icon-margin"
color="#878f93"
title={item['Type'] || item['@type']}
/>{' '}
<span title={item.title}> {item.title}</span>
{item['@type'] === 'Image' ? (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of @tisto advice is quite valid, lazy loaded when needed, you don't want to load 100 images if you never even interact with them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

<PreviewImage item={item} />
) : (
<div className="preview-image-container">
<Icon
name={getContentIcon(item['@type'], item.is_folderish)}
size="20px"
className="icon-margin"
color="#878f93"
title={item['Type'] || item['@type']}
/>
<span title={item.title}> {item.title}</span>
</div>
)}
</div>
{item.ExpirationDate !== 'None' &&
new Date(item.ExpirationDate).getTime() <
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,34 @@ exports[`ContentsItem renders a contents item component 1`] = `
<div
className="expire-align"
>
<svg
className="icon icon-margin"
dangerouslySetInnerHTML={
Object {
"__html": "<title>Pagina</title>undefined",
<div
className="preview-image-container"
>
<svg
className="icon icon-margin"
dangerouslySetInnerHTML={
Object {
"__html": "<title>Pagina</title>undefined",
}
}
}
onClick={null}
style={
Object {
"fill": "#878f93",
"height": "20px",
"width": "auto",
onClick={null}
style={
Object {
"fill": "#878f93",
"height": "20px",
"width": "auto",
}
}
}
viewBox=""
xmlns=""
/>

<span
title="Blog"
>

Blog
</span>
viewBox=""
xmlns=""
/>
<span
title="Blog"
>

Blog
</span>
</div>
</div>
</a>
</td>
Expand Down
16 changes: 16 additions & 0 deletions packages/volto/theme/themes/pastanaga/extras/contents.less
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@
.ui.table .expire-align {
display: flex;
align-items: center;

.preview-image-container {
display: flex;
align-items: center;

.popup-image-icon {
width: 20px;
height: 20px;
margin-right: 4px;
}
}
}

.ui.table .icon-margin {
Expand All @@ -153,6 +164,11 @@
color: white;
}
}
/* Folder contents preview image on title hover */
.popup-preview-image {
width: 100%;
height: 100%;
}

.contents-pagination {
.ui.secondary.menu .item {
Expand Down
Loading