|
1 | 1 | import React from 'react'; |
2 | 2 |
|
| 3 | +import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext'; |
| 4 | +import type { IconsMap } from '../../contexts/componentsContext/defaultComponents'; |
3 | 5 | import { useTheme } from '../../contexts/themeContext/ThemeContext'; |
4 | 6 |
|
5 | | -import { Audio } from '../../icons/filetype-audio-xl'; |
6 | | -import { Code } from '../../icons/filetype-code-xl'; |
7 | | -import { ZIP } from '../../icons/filetype-compression-xl'; |
8 | | -import { OtherFileIcon } from '../../icons/filetype-other-xl'; |
9 | | -import { PDF } from '../../icons/filetype-pdf-xl'; |
10 | | -import { Presentation } from '../../icons/filetype-presentation-xl'; |
11 | | -import { SpreadSheet } from '../../icons/filetype-spreadsheet-xl'; |
12 | | -import { DOC } from '../../icons/filetype-text-xl'; |
13 | | -import { Video } from '../../icons/filetype-video-xl'; |
14 | | -import type { IconProps } from '../../icons/utils/base'; |
15 | | - |
16 | 7 | // https://www.iana.org/assignments/media-types/media-types.xhtml#audio |
17 | 8 | const audioFileTypes = [ |
18 | 9 | 'audio/1d-interleaved-parityfec', |
@@ -349,49 +340,49 @@ const codeFileTypes = [ |
349 | 340 | 'text/plain', |
350 | 341 | ]; |
351 | 342 |
|
352 | | -const mimeTypeToIconMap: Record<string, React.ComponentType<IconProps>> = { |
353 | | - 'application/pdf': PDF, // .pdf |
| 343 | +const mimeTypeToIconKeyMap: Record<string, keyof IconsMap> = { |
| 344 | + 'application/pdf': 'PDF', // .pdf |
354 | 345 | }; |
355 | 346 |
|
356 | 347 | for (const type of audioFileTypes) { |
357 | | - mimeTypeToIconMap[type] = Audio; |
| 348 | + mimeTypeToIconKeyMap[type] = 'Audio'; |
358 | 349 | } |
359 | 350 |
|
360 | 351 | for (const type of docMimeTypes) { |
361 | | - mimeTypeToIconMap[type] = DOC; |
| 352 | + mimeTypeToIconKeyMap[type] = 'DOC'; |
362 | 353 | } |
363 | 354 |
|
364 | 355 | for (const type of excelMimeTypes) { |
365 | | - mimeTypeToIconMap[type] = SpreadSheet; |
| 356 | + mimeTypeToIconKeyMap[type] = 'SpreadSheet'; |
366 | 357 | } |
367 | 358 |
|
368 | 359 | for (const type of powerpointMimeTypes) { |
369 | | - mimeTypeToIconMap[type] = Presentation; |
| 360 | + mimeTypeToIconKeyMap[type] = 'Presentation'; |
370 | 361 | } |
371 | 362 |
|
372 | 363 | for (const type of zipFileTypes) { |
373 | | - mimeTypeToIconMap[type] = ZIP; |
| 364 | + mimeTypeToIconKeyMap[type] = 'ZIP'; |
374 | 365 | } |
375 | 366 |
|
376 | 367 | for (const type of videoFileTypes) { |
377 | | - mimeTypeToIconMap[type] = Video; |
| 368 | + mimeTypeToIconKeyMap[type] = 'Video'; |
378 | 369 | } |
379 | 370 |
|
380 | 371 | for (const type of codeFileTypes) { |
381 | | - mimeTypeToIconMap[type] = Code; |
| 372 | + mimeTypeToIconKeyMap[type] = 'Code'; |
382 | 373 | } |
383 | 374 |
|
384 | | -function mimeTypeToIcon(mimeType?: string): React.ComponentType<IconProps> { |
| 375 | +function mimeTypeToIconKey(mimeType?: string): keyof IconsMap { |
385 | 376 | if (!mimeType) { |
386 | | - return OtherFileIcon; |
| 377 | + return 'OtherFileIcon'; |
387 | 378 | } |
388 | 379 |
|
389 | | - const Icon = mimeTypeToIconMap[mimeType]; |
390 | | - if (Icon) { |
391 | | - return Icon; |
| 380 | + const iconKey = mimeTypeToIconKeyMap[mimeType]; |
| 381 | + if (iconKey) { |
| 382 | + return iconKey; |
392 | 383 | } |
393 | 384 |
|
394 | | - return OtherFileIcon; |
| 385 | + return 'OtherFileIcon'; |
395 | 386 | } |
396 | 387 |
|
397 | 388 | export type FileIconProps = { |
@@ -426,8 +417,9 @@ export const FileIcon = ({ mimeType, size = 'md' }: FileIconProps) => { |
426 | 417 | }, |
427 | 418 | }, |
428 | 419 | } = useTheme(); |
| 420 | + const { icons } = useComponentsContext(); |
429 | 421 |
|
430 | | - const Icon = mimeTypeToIcon(mimeType); |
| 422 | + const Icon = icons[mimeTypeToIconKey(mimeType)]; |
431 | 423 |
|
432 | 424 | return <Icon {...(size ? sizeToNumber(size) : {})} {...icon} />; |
433 | 425 | }; |
|
0 commit comments