mirror of
https://github.com/strapi/strapi.git
synced 2025-12-14 16:51:55 +00:00
Merge pull request #3906 from strapi/front/media-preview-list
Front/media preview list
This commit is contained in:
commit
74ffd1e0b7
@ -56,7 +56,7 @@ const getDisplayedValue = (type, value, name) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function Row({ goTo, isBulkable, isHoverable, row, headers }) {
|
function Row({ goTo, isBulkable, row, headers }) {
|
||||||
const {
|
const {
|
||||||
entriesToDelete,
|
entriesToDelete,
|
||||||
onChangeBulk,
|
onChangeBulk,
|
||||||
@ -65,12 +65,7 @@ function Row({ goTo, isBulkable, isHoverable, row, headers }) {
|
|||||||
} = useListView();
|
} = useListView();
|
||||||
|
|
||||||
const renderMediaList = files => {
|
const renderMediaList = files => {
|
||||||
return (
|
return <MediaPreviewList files={files}></MediaPreviewList>;
|
||||||
<MediaPreviewList
|
|
||||||
files={files}
|
|
||||||
hoverable={isHoverable}
|
|
||||||
></MediaPreviewList>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -18,7 +18,6 @@ function CustomTable({
|
|||||||
push,
|
push,
|
||||||
},
|
},
|
||||||
isBulkable,
|
isBulkable,
|
||||||
isHoverable,
|
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
emitEvent,
|
emitEvent,
|
||||||
@ -68,7 +67,6 @@ function CustomTable({
|
|||||||
>
|
>
|
||||||
<Row
|
<Row
|
||||||
isBulkable={isBulkable}
|
isBulkable={isBulkable}
|
||||||
isHoverable={isHoverable}
|
|
||||||
headers={headers}
|
headers={headers}
|
||||||
row={row}
|
row={row}
|
||||||
goTo={handleGoTo}
|
goTo={handleGoTo}
|
||||||
|
|||||||
@ -52,13 +52,23 @@ const MediaPreviewItem = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const MediaPreviewFile = styled(MediaPreviewItem)`
|
const MediaPreviewFile = styled(MediaPreviewItem)`
|
||||||
|
span {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
div {
|
div {
|
||||||
position: relative;
|
position: relative;
|
||||||
background-color: #9fa7b6;
|
background-color: #9fa7b6;
|
||||||
color: white;
|
color: white;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
line-height: ${sizes.small};
|
line-height: ${sizes.small};
|
||||||
font-size: 13px;
|
font-size: 11px;
|
||||||
|
span {
|
||||||
|
display: block;
|
||||||
|
padding: 0 3px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
i {
|
i {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
@ -77,10 +87,12 @@ const MediaPreviewFile = styled(MediaPreviewItem)`
|
|||||||
}
|
}
|
||||||
div + span {
|
div + span {
|
||||||
display: none;
|
display: none;
|
||||||
color: #333740;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 100%;
|
left: 120%;
|
||||||
bottom: -10px;
|
bottom: -10px;
|
||||||
|
display: none;
|
||||||
|
max-width: 150px;
|
||||||
|
color: #333740;
|
||||||
}
|
}
|
||||||
&.hoverable {
|
&.hoverable {
|
||||||
:hover {
|
:hover {
|
||||||
|
|||||||
@ -17,7 +17,11 @@ function MediaPreviewList({ hoverable, files }) {
|
|||||||
const getFileType = fileName => fileName.split('.').slice(-1)[0];
|
const getFileType = fileName => fileName.split('.').slice(-1)[0];
|
||||||
|
|
||||||
const renderImage = image => {
|
const renderImage = image => {
|
||||||
const { name, url } = image;
|
const { name, size, url } = image;
|
||||||
|
|
||||||
|
if (size > 2000) {
|
||||||
|
return renderFile(image);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaPreviewImage className={hoverable ? 'hoverable' : ''}>
|
<MediaPreviewImage className={hoverable ? 'hoverable' : ''}>
|
||||||
@ -30,13 +34,13 @@ function MediaPreviewList({ hoverable, files }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderFile = file => {
|
const renderFile = file => {
|
||||||
const { ext, name } = file;
|
const { mime, name } = file;
|
||||||
const fileType = getFileType(name);
|
const fileType = includes(mime, 'image') ? 'image' : getFileType(name);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaPreviewFile className={hoverable ? 'hoverable' : ''}>
|
<MediaPreviewFile className={hoverable ? 'hoverable' : ''}>
|
||||||
<div>
|
<div>
|
||||||
<span>{ext}</span>
|
<span>{fileType}</span>
|
||||||
<i className={`fa fa-file-${fileType}-o`} />
|
<i className={`fa fa-file-${fileType}-o`} />
|
||||||
</div>
|
</div>
|
||||||
<span>{name}</span>
|
<span>{name}</span>
|
||||||
@ -88,7 +92,7 @@ function MediaPreviewList({ hoverable, files }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MediaPreviewList.default = {
|
MediaPreviewList.default = {
|
||||||
hoverable: false,
|
hoverable: true,
|
||||||
files: null,
|
files: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -237,22 +237,6 @@ function ListView({
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
// TODO - Remove when media is enable in List Layout
|
|
||||||
const imgHeader = {
|
|
||||||
label: 'Image',
|
|
||||||
name: 'image',
|
|
||||||
searchable: false,
|
|
||||||
sortable: false,
|
|
||||||
};
|
|
||||||
const iconsHeader = {
|
|
||||||
label: 'Icons',
|
|
||||||
name: 'icons',
|
|
||||||
searchable: false,
|
|
||||||
sortable: false,
|
|
||||||
};
|
|
||||||
const tableHeaders = [...getTableHeaders(), imgHeader, iconsHeader];
|
|
||||||
|
|
||||||
console.log(data);
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ListViewProvider
|
<ListViewProvider
|
||||||
@ -391,9 +375,8 @@ function ListView({
|
|||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<CustomTable
|
<CustomTable
|
||||||
data={data}
|
data={data}
|
||||||
headers={tableHeaders}
|
headers={getTableHeaders()}
|
||||||
isBulkable={getLayoutSettingRef.current('bulkable')}
|
isBulkable={getLayoutSettingRef.current('bulkable')}
|
||||||
isHoverable={true}
|
|
||||||
onChangeParams={handleChangeParams}
|
onChangeParams={handleChangeParams}
|
||||||
slug={slug}
|
slug={slug}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user