Skip to content

Commit 8c44e3e

Browse files
committed
feat: add support for new icon components that are already in the design system
1 parent 0b4fc48 commit 8c44e3e

File tree

18 files changed

+138
-71
lines changed

18 files changed

+138
-71
lines changed

packages/core/content-manager/admin/src/components/ComponentIcon.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ const COMPONENT_ICONS: Record<string, React.ComponentType<any>> = {
8282
file: Icons.File,
8383
fileError: Icons.FileError,
8484
filePdf: Icons.FilePdf,
85+
fileXls: Icons.FileXls,
86+
fileZip: Icons.FileZip,
87+
fileCsv: Icons.FileCsv,
8588
filter: Icons.Filter,
8689
folder: Icons.Folder,
8790
gate: Icons.CastleTurret,

packages/core/content-type-builder/admin/src/components/IconPicker/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const COMPONENT_ICONS: Record<string, Icon> = {
5151
file: Icons.File,
5252
fileError: Icons.FileError,
5353
filePdf: Icons.FilePdf,
54+
fileXls: Icons.FileXls,
55+
fileZip: Icons.FileZip,
56+
fileCsv: Icons.FileCsv,
5457
filter: Icons.Filter,
5558
folder: Icons.Folder,
5659
gate: Icons.CastleTurret,

packages/core/upload/admin/src/ai/components/AIAssetCard.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { styled } from 'styled-components';
2929
import { AudioPreview } from '../../components/AssetCard/AudioPreview';
3030
import { VideoPreview } from '../../components/AssetCard/VideoPreview';
3131
import { type Asset, EditAssetContent } from '../../components/EditAssetDialog/EditAssetContent';
32-
import { AssetType } from '../../constants';
32+
import { AssetType, DocType } from '../../enums';
3333
import { useMediaLibraryPermissions } from '../../hooks/useMediaLibraryPermissions';
3434
import { useRemoveAsset } from '../../hooks/useRemoveAsset';
3535
import {
@@ -162,7 +162,7 @@ const AssetCardActions = ({ asset }: { asset: File }) => {
162162
* -----------------------------------------------------------------------------------------------*/
163163

164164
interface AssetProps {
165-
assetType: AssetType;
165+
assetType: AssetType | DocType;
166166
thumbnailUrl: string;
167167
assetUrl: string;
168168
asset: File;
@@ -269,14 +269,22 @@ const StyledCard = styled(Card)`
269269
padding: 0;
270270
`;
271271

272-
const getAssetBadgeLabel = (assetType: AssetType) => {
272+
const getAssetBadgeLabel = (assetType: AssetType | DocType) => {
273273
switch (assetType) {
274274
case AssetType.Image:
275275
return { id: getTrad('settings.section.image.label'), defaultMessage: 'IMAGE' };
276276
case AssetType.Video:
277277
return { id: getTrad('settings.section.video.label'), defaultMessage: 'VIDEO' };
278278
case AssetType.Audio:
279279
return { id: getTrad('settings.section.audio.label'), defaultMessage: 'AUDIO' };
280+
case DocType.Pdf:
281+
return { id: getTrad('settings.section.pdf.label'), defaultMessage: 'PDF' };
282+
case DocType.Csv:
283+
return { id: getTrad('settings.section.csv.label'), defaultMessage: 'CSV' };
284+
case DocType.Xls:
285+
return { id: getTrad('settings.section.xls.label'), defaultMessage: 'XLS' };
286+
case DocType.Zip:
287+
return { id: getTrad('settings.section.zip.label'), defaultMessage: 'ZIP' };
280288
default:
281289
return { id: getTrad('settings.section.doc.label'), defaultMessage: 'DOC' };
282290
}

packages/core/upload/admin/src/ai/components/AIUploadModal.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import {
1010
AddAssetStep,
1111
FileWithRawFile,
1212
} from '../../components/UploadAssetDialog/AddAssetStep/AddAssetStep';
13-
import { AssetType } from '../../constants';
1413
import { useBulkEdit } from '../../hooks/useBulkEdit';
1514
import { useTracking } from '../../hooks/useTracking';
1615
import { useUpload } from '../../hooks/useUpload';
17-
import { getTrad, typeFromMime } from '../../utils';
16+
import { getTrad } from '../../utils';
1817

1918
import { AIAssetCard, AIAssetCardSkeletons } from './AIAssetCard';
2019

packages/core/upload/admin/src/components/AssetCard/AssetCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AssetType } from '../../constants';
1+
import { AssetType } from '../../enums';
22
import { createAssetUrl, getFileExtension, prefixFileUrlWithBackendUrl } from '../../utils';
33

44
import { AudioAssetCard } from './AudioAssetCard';

packages/core/upload/admin/src/components/AssetCard/DocAssetCard.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Flex, Typography } from '@strapi/design-system';
2-
import { File, FilePdf } from '@strapi/icons';
32
import { useIntl } from 'react-intl';
43
import { styled } from 'styled-components';
54

5+
import { getFileIconComponent } from '../../utils/icons';
6+
67
import { AssetCardBase, AssetCardBaseProps } from './AssetCardBase';
78

89
const CardAsset = styled(Flex)`
@@ -27,6 +28,7 @@ export const DocAssetCard = ({
2728
...restProps
2829
}: DocAssetCardProps) => {
2930
const { formatMessage } = useIntl();
31+
const IconComponent = getFileIconComponent(extension);
3032
return (
3133
<AssetCardBase
3234
name={name}
@@ -37,12 +39,7 @@ export const DocAssetCard = ({
3739
>
3840
<CardAsset width="100%" height={size === 'S' ? `8.8rem` : `16.4rem`} justifyContent="center">
3941
<Flex gap={2} direction="column" alignItems="center">
40-
{extension === 'pdf' ? (
41-
<FilePdf aria-label={name} fill="neutral500" width={24} height={24} />
42-
) : (
43-
<File aria-label={name} fill="neutral500" width={24} height={24} />
44-
)}
45-
42+
<IconComponent aria-label={name} fill="neutral500" width={24} height={24} />
4643
<Typography textColor="neutral500" variant="pi">
4744
{formatMessage({
4845
id: 'noPreview',

packages/core/upload/admin/src/components/AssetCard/UploadingAssetCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { useIntl } from 'react-intl';
1616
import { styled } from 'styled-components';
1717

18-
import { AssetType } from '../../constants';
18+
import { AssetType } from '../../enums';
1919
import { useUpload } from '../../hooks/useUpload';
2020
import { getTrad } from '../../utils';
2121
import { UploadProgress } from '../UploadProgress/UploadProgress';

packages/core/upload/admin/src/components/EditAssetDialog/PreviewBox/AssetPreview.tsx

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import * as React from 'react';
33

44
import MuxPlayer from '@mux/mux-player-react';
55
import { Box, Flex, Typography } from '@strapi/design-system';
6-
import { File, FilePdf } from '@strapi/icons';
76
import { useIntl } from 'react-intl';
87
import { styled, useTheme } from 'styled-components';
98

10-
import { AssetType } from '../../../constants';
9+
import { AssetType } from '../../../enums';
10+
import { typeFromMime } from '../../../utils';
11+
import { getFileIconComponent } from '../../../utils/icons';
1112

1213
const CardAsset = styled(Flex)`
1314
min-height: 26.4rem;
@@ -32,19 +33,21 @@ export const AssetPreview = React.forwardRef<
3233
>(({ mime, url, name, ...props }, ref) => {
3334
const theme = useTheme();
3435

36+
const assetType = typeFromMime(mime);
37+
3538
const { formatMessage } = useIntl();
3639

37-
if (mime.includes(AssetType.Image)) {
40+
if (assetType === AssetType.Image) {
3841
return (
3942
<img ref={ref as React.ForwardedRef<HTMLImageElement>} src={url} alt={name} {...props} />
4043
);
4144
}
4245

43-
if (mime.includes(AssetType.Video)) {
46+
if (assetType === AssetType.Video) {
4447
return <MuxPlayer src={url} accentColor={theme.colors.primary500} />;
4548
}
4649

47-
if (mime.includes(AssetType.Audio)) {
50+
if (assetType === AssetType.Audio) {
4851
return (
4952
<Box margin="5">
5053
<audio controls src={url} ref={ref as React.ForwardedRef<HTMLAudioElement>} {...props}>
@@ -54,27 +57,13 @@ export const AssetPreview = React.forwardRef<
5457
);
5558
}
5659

57-
if (mime.includes('pdf')) {
58-
return (
59-
<CardAsset width="100%" justifyContent="center" {...props}>
60-
<Flex gap={2} direction="column" alignItems="center">
61-
<FilePdf aria-label={name} fill="neutral500" width={24} height={24} />
62-
<Typography textColor="neutral500" variant="pi">
63-
{formatMessage({
64-
id: 'noPreview',
65-
defaultMessage: 'No preview available',
66-
})}
67-
</Typography>
68-
</Flex>
69-
</CardAsset>
70-
);
71-
}
72-
60+
// getFileIconComponent will handle all other file types, eg. PDF, CSV, XLS, ZIP
61+
// If the file type is not recognized, the default icon will be used
62+
const IconComponent = getFileIconComponent(assetType);
7363
return (
7464
<CardAsset width="100%" justifyContent="center" {...props}>
7565
<Flex gap={2} direction="column" alignItems="center">
76-
<File aria-label={name} fill="neutral500" width={24} height={24} />
77-
66+
<IconComponent aria-label={name} fill="neutral500" width={24} height={24} />
7867
<Typography textColor="neutral500" variant="pi">
7968
{formatMessage({
8069
id: 'noPreview',

packages/core/upload/admin/src/components/EditAssetDialog/PreviewBox/PreviewBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import cropperjscss from 'cropperjs/dist/cropper.css?raw';
77
import { useIntl } from 'react-intl';
88
import { createGlobalStyle } from 'styled-components';
99

10-
import { AssetType } from '../../../constants';
10+
import { AssetType } from '../../../enums';
1111
import { useCropImg } from '../../../hooks/useCropImg';
1212
import { useEditAsset } from '../../../hooks/useEditAsset';
1313
import { useTracking } from '../../../hooks/useTracking';

packages/core/upload/admin/src/components/MediaLibraryInput/Carousel/CarouselAsset.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Box, Flex } from '@strapi/design-system';
2-
import { File, FilePdf } from '@strapi/icons';
32
import { styled } from 'styled-components';
43

5-
import { AssetType } from '../../../constants';
4+
import { AssetType } from '../../../enums';
65
import { createAssetUrl } from '../../../utils';
6+
import { getFileIconComponent } from '../../../utils/icons';
77
import { AudioPreview } from '../../AssetCard/AudioPreview';
88
import { VideoPreview } from '../../AssetCard/VideoPreview';
99

@@ -73,13 +73,11 @@ export const CarouselAsset = ({ asset }: { asset: FileAsset }) => {
7373
);
7474
}
7575

76+
const IconComponent = getFileIconComponent(asset.ext);
77+
7678
return (
7779
<DocAsset width="100%" height="100%" justifyContent="center" hasRadius>
78-
{asset.ext?.includes('pdf') ? (
79-
<FilePdf aria-label={asset.alternativeText || asset.name} width="24px" height="32px" />
80-
) : (
81-
<File aria-label={asset.alternativeText || asset.name} width="24px" height="32px" />
82-
)}
80+
<IconComponent aria-label={asset.alternativeText || asset.name} width="24px" height="32px" />
8381
</DocAsset>
8482
);
8583
};

0 commit comments

Comments
 (0)