@linagora/twake-icons 2.3.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## @linagora/twake-icons [2.4.1](https://github.com/linagora/twake-ui/compare/@linagora/twake-icons@2.4.0...@linagora/twake-icons@2.4.1) (2026-06-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **twake-icons:** Changed mime library to one that works in browsers (mime/lite) ([00ce94f](https://github.com/linagora/twake-ui/commit/00ce94fd1b9d95f52e0dc480dfe2ab181420e97e))
7
+
8
+ # @linagora/twake-icons [2.4.0](https://github.com/linagora/twake-ui/compare/@linagora/twake-icons@2.3.0...@linagora/twake-icons@2.4.0) (2026-06-18)
9
+
10
+
11
+ ### Features
12
+
13
+ * **twake-icons:** Added getFileTypeIcon function util ([450a8ff](https://github.com/linagora/twake-ui/commit/450a8ff80fc74ca1f6b77f8e72f4ff86094c6431))
14
+
1
15
  # @linagora/twake-icons [2.3.0](https://github.com/linagora/twake-ui/compare/@linagora/twake-icons@2.2.0...@linagora/twake-icons@2.3.0) (2026-06-17)
2
16
 
3
17
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as Icon } from './Icon';
2
2
  export { default as Sprite } from './Icon/Sprite';
3
+ export { getFileTypeIcon } from './utils/getFileTypeIcon';
3
4
  export type { IconProps } from './Icon';
4
5
  export * from './Icons';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { default as Icon } from './Icon';
2
2
  export { default as Sprite } from './Icon/Sprite';
3
+ export { getFileTypeIcon } from './utils/getFileTypeIcon';
3
4
  export * from './Icons';
@@ -0,0 +1,9 @@
1
+ import { File } from '../Icons';
2
+ /**
3
+ * Maps MIME types to their corresponding icon components
4
+ */
5
+ export declare const mimeToIcon: Record<string, (props: React.SVGProps<SVGSVGElement>) => JSX.Element>;
6
+ /**
7
+ * Default fallback icon when no specific icon is found
8
+ */
9
+ export declare const defaultIcon: typeof File;
@@ -0,0 +1,68 @@
1
+ import { File, FileTypeAudio, FileTypeCode, FileTypeImage, FileTypePdf, FileTypeSheet, FileTypeSlide, FileTypeText, FileTypeVideo, FileTypeZip } from '../Icons';
2
+ /**
3
+ * Maps MIME types to their corresponding icon components
4
+ */
5
+ export const mimeToIcon = {
6
+ // PDF
7
+ 'application/pdf': FileTypePdf,
8
+ // Images
9
+ 'image/png': FileTypeImage,
10
+ 'image/jpeg': FileTypeImage,
11
+ 'image/jpg': FileTypeImage,
12
+ 'image/gif': FileTypeImage,
13
+ 'image/webp': FileTypeImage,
14
+ 'image/svg+xml': FileTypeImage,
15
+ 'image/bmp': FileTypeImage,
16
+ 'image/tiff': FileTypeImage,
17
+ // Documents - Word
18
+ 'application/msword': FileTypeText,
19
+ 'application/rtf': FileTypeText,
20
+ 'application/vnd.oasis.opendocument.text': FileTypeText,
21
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': FileTypeText,
22
+ // Documents - Excel/Sheets
23
+ 'application/vnd.ms-excel': FileTypeSheet,
24
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': FileTypeSheet,
25
+ 'application/vnd.oasis.opendocument.spreadsheet': FileTypeSheet,
26
+ 'text/csv': FileTypeSheet,
27
+ // Documents - PowerPoint/Slides
28
+ 'application/vnd.ms-powerpoint': FileTypeSlide,
29
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation': FileTypeSlide,
30
+ 'application/vnd.oasis.opendocument.presentation': FileTypeSlide,
31
+ // Text files
32
+ 'text/plain': FileTypeText,
33
+ 'text/html': FileTypeCode,
34
+ 'text/css': FileTypeCode,
35
+ 'text/javascript': FileTypeCode,
36
+ 'text/jsx': FileTypeCode,
37
+ 'application/json': FileTypeCode,
38
+ 'application/xml': FileTypeCode,
39
+ // Archives
40
+ 'application/zip': FileTypeZip,
41
+ 'application/x-zip-compressed': FileTypeZip,
42
+ 'application/x-rar-compressed': FileTypeZip,
43
+ 'application/vnd.rar': FileTypeZip,
44
+ 'application/x-7z-compressed': FileTypeZip,
45
+ 'application/gzip': FileTypeZip,
46
+ 'application/x-tar': FileTypeZip,
47
+ // Video
48
+ 'video/mp4': FileTypeVideo,
49
+ 'video/webm': FileTypeVideo,
50
+ 'video/ogg': FileTypeVideo,
51
+ 'video/quicktime': FileTypeVideo,
52
+ 'video/x-msvideo': FileTypeVideo,
53
+ 'video/x-matroska': FileTypeVideo,
54
+ 'video/mpeg': FileTypeVideo,
55
+ // Audio
56
+ 'audio/mpeg': FileTypeAudio,
57
+ 'audio/mp3': FileTypeAudio,
58
+ 'audio/wav': FileTypeAudio,
59
+ 'audio/ogg': FileTypeAudio,
60
+ 'audio/webm': FileTypeAudio,
61
+ 'audio/aac': FileTypeAudio,
62
+ 'audio/flac': FileTypeAudio,
63
+ 'audio/x-flac': FileTypeAudio
64
+ };
65
+ /**
66
+ * Default fallback icon when no specific icon is found
67
+ */
68
+ export const defaultIcon = File;
@@ -0,0 +1,9 @@
1
+ import type { SVGProps } from 'react';
2
+ /**
3
+ * Returns the appropriate icon component for a given attachment
4
+ * Tries MIME type first, then falls back to filename lookup
5
+ * @param filename - The complete filename with the extension
6
+ * @param mimeType - The mime type of the file
7
+ * @returns React node representing the file type icon
8
+ */
9
+ export declare function getFileTypeIcon(filename: string, mimeType?: string): (props: SVGProps<SVGSVGElement>) => JSX.Element;
@@ -0,0 +1,16 @@
1
+ import mime from 'mime';
2
+ import { mimeToIcon, defaultIcon } from './fileTypeIcons';
3
+ /**
4
+ * Returns the appropriate icon component for a given attachment
5
+ * Tries MIME type first, then falls back to filename lookup
6
+ * @param filename - The complete filename with the extension
7
+ * @param mimeType - The mime type of the file
8
+ * @returns React node representing the file type icon
9
+ */
10
+ export function getFileTypeIcon(filename, mimeType) {
11
+ const resolvedMimeType = mimeType?.split(';')[0].trim().toLowerCase() || mime.getType(filename);
12
+ if (resolvedMimeType && mimeToIcon[resolvedMimeType]) {
13
+ return mimeToIcon[resolvedMimeType];
14
+ }
15
+ return defaultIcon;
16
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linagora/twake-icons",
3
3
  "type": "module",
4
- "version": "2.3.0",
4
+ "version": "2.4.1",
5
5
  "description": "Icon library for Twake applications — SVG icons and illustrations",
6
6
  "author": "Twake",
7
7
  "license": "MIT",
@@ -43,6 +43,7 @@
43
43
  "build:doc": "storybook build --output-dir storybook-static",
44
44
  "build:icons": "npm run svgo && npm run makeSvgr && npm run sprite",
45
45
  "start": "tsc --watch",
46
+ "test": "vitest run",
46
47
  "clean": "rm -rf dist",
47
48
  "lint": "eslint src --ext .ts,.tsx",
48
49
  "lint:fix": "eslint src --ext .ts,.tsx --fix",
@@ -70,6 +71,10 @@
70
71
  "storybook": "10.4.5",
71
72
  "svgo": "4.0.1",
72
73
  "svgstore-cli": "2.0.1",
73
- "vite": "8.0.16"
74
+ "vite": "8.0.16",
75
+ "vitest": "4.1.5"
76
+ },
77
+ "dependencies": {
78
+ "mime": "4.1.0"
74
79
  }
75
80
  }