@box/item-icon 2.18.2 → 2.19.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/README.md CHANGED
@@ -4,6 +4,11 @@
4
4
  - [item-icon](#item-icon)
5
5
  - [Running commands](#running-commands)
6
6
  - [Available commands](#available-commands)
7
+ - [API](#api)
8
+ - [Components](#components)
9
+ - [Utility Functions](#utility-functions)
10
+ - [Constants](#constants)
11
+ - [Types](#types)
7
12
  - [Ownership](#ownership)
8
13
  - [Translations](#translations)
9
14
 
@@ -44,6 +49,105 @@ All commands used with Nx can be found in `project.json` file within your packag
44
49
  - `nx chromatic item-icon` - uploads storybook build for review to [box chromatic](https://box.chromatic.com/) , and performs visual comparison of the UI changes against baseline.
45
50
  - `nx prepare item-icon` - command run during package publication process orchestrated by Nx Release.
46
51
 
52
+ ## API
53
+
54
+ ### Components
55
+
56
+ - **ItemIcon** - A component for displaying file/folder icons
57
+ - **ItemTypeIcon** - A component for displaying item type icons
58
+
59
+ ### Utility Functions
60
+
61
+ #### `getFileCategoryByExtension(extension?: string): string`
62
+
63
+ Returns the file category for a given file extension. If the extension is not recognized, returns `'default'`.
64
+
65
+ ```typescript
66
+ import { getFileCategoryByExtension } from '@box/item-icon';
67
+
68
+ const category = getFileCategoryByExtension('pdf'); // Returns 'pdf'
69
+ const category2 = getFileCategoryByExtension('docx'); // Returns 'word-document'
70
+ const category3 = getFileCategoryByExtension('unknown'); // Returns 'default'
71
+ ```
72
+
73
+ #### `getColorByExtension(fileCategory: FileCategory): string | undefined`
74
+
75
+ Returns the Blueprint CSS color variable for a given file category. Returns `undefined` for falsy input.
76
+
77
+ ```typescript
78
+ import { getColorByExtension, type FileCategory } from '@box/item-icon';
79
+
80
+ const color = getColorByExtension('pdf'); // Returns 'var(--bp-watermelon-red-120, var(--watermelon-red-120))'
81
+ const color2 = getColorByExtension('image'); // Returns 'var(--bp-green-light-135, var(--green-light-120))'
82
+ ```
83
+
84
+ ### Constants
85
+
86
+ #### `FILE_EXTENSION_CATEGORIES`
87
+
88
+ An object mapping file categories to arrays of file extensions.
89
+
90
+ ```typescript
91
+ import { FILE_EXTENSION_CATEGORIES } from '@box/item-icon';
92
+
93
+ FILE_EXTENSION_CATEGORIES.pdf; // ['pdf']
94
+ FILE_EXTENSION_CATEGORIES.image; // ['bmp', 'cr2', 'crw', 'dng', 'gdraw', 'gif', ...]
95
+ FILE_EXTENSION_CATEGORIES['word-document']; // ['doc', 'docm', 'docx']
96
+ ```
97
+
98
+ #### `FILE_CATEGORY_COLORS`
99
+
100
+ An object mapping file categories to their corresponding Blueprint CSS color variables. Useful for styling file type indicators consistently.
101
+
102
+ ```typescript
103
+ import { FILE_CATEGORY_COLORS } from '@box/item-icon';
104
+
105
+ FILE_CATEGORY_COLORS.pdf; // 'var(--bp-watermelon-red-120, var(--watermelon-red-120))'
106
+ FILE_CATEGORY_COLORS.image; // 'var(--bp-green-light-135, var(--green-light-120))'
107
+ FILE_CATEGORY_COLORS.video; // 'var(--bp-light-blue-115, var(--light-blue-110))'
108
+ ```
109
+
110
+ ### Types
111
+
112
+ #### `FileCategory`
113
+
114
+ A TypeScript union type representing all valid file categories.
115
+
116
+ ```typescript
117
+ import { type FileCategory } from '@box/item-icon';
118
+
119
+ type FileCategory =
120
+ | 'audio'
121
+ | 'boxcanvas'
122
+ | 'boxnote'
123
+ | 'code'
124
+ | 'document'
125
+ | 'docuworks-binder'
126
+ | 'docuworks-file'
127
+ | 'dwg'
128
+ | 'excel-spreadsheet'
129
+ | 'google-docs'
130
+ | 'google-sheets'
131
+ | 'google-slides'
132
+ | 'illustrator'
133
+ | 'image'
134
+ | 'indesign'
135
+ | 'keynote'
136
+ | 'numbers'
137
+ | 'pages'
138
+ | 'pdf'
139
+ | 'photoshop'
140
+ | 'powerpoint-presentation'
141
+ | 'presentation'
142
+ | 'spreadsheet'
143
+ | 'text'
144
+ | 'threed'
145
+ | 'vector'
146
+ | 'video'
147
+ | 'word-document'
148
+ | 'zip';
149
+ ```
150
+
47
151
  ## Ownership
48
152
 
49
153
  Code of the feature belongs to webapp-eng. Responsibilities of owning team include control over code quality, providing guidelines for changes, and alignment with other teams regarding changes. It would be a good practice to consult which team, owning or requesting, will be responsible for implementing changes to code.
package/dist/esm/index.js CHANGED
@@ -1,9 +1,13 @@
1
- import { getFileIconType as t } from "./lib/utils.js";
2
- import { ItemIcon as r, itemIconTable as I } from "./lib/item-icon/item-icon.js";
3
- import { ItemTypeIcon as c } from "./lib/item-type-icon/item-type-icon.js";
1
+ import { getColorByExtension as t, getFileCategoryByExtension as r } from "./lib/utils.js";
2
+ import { FILE_CATEGORY_COLORS as I, FILE_EXTENSION_CATEGORIES as m } from "./lib/constants.js";
3
+ import { ItemIcon as x, itemIconTable as p } from "./lib/item-icon/item-icon.js";
4
+ import { ItemTypeIcon as O } from "./lib/item-type-icon/item-type-icon.js";
4
5
  export {
5
- r as ItemIcon,
6
- c as ItemTypeIcon,
7
- t as getFileIconType,
8
- I as itemIconTable
6
+ I as FILE_CATEGORY_COLORS,
7
+ m as FILE_EXTENSION_CATEGORIES,
8
+ x as ItemIcon,
9
+ O as ItemTypeIcon,
10
+ t as getColorByExtension,
11
+ r as getFileCategoryByExtension,
12
+ p as itemIconTable
9
13
  };
@@ -1,4 +1,4 @@
1
- const s = {
1
+ const r = {
2
2
  audio: ["aac", "aif", "aifc", "aiff", "amr", "au", "flac", "m3u", "m4a", "mid", "mp3", "ra", "wav", "wma", "wpl"],
3
3
  boxcanvas: ["boxcanvas"],
4
4
  boxnote: ["boxnote"],
@@ -28,7 +28,82 @@ const s = {
28
28
  video: ["3g2", "3gp", "avi", "flv", "m2ts", "m2v", "m4v", "mkv", "mov", "mp4", "mpeg", "mpg", "mts", "ogg", "qt", "ts", "wmv"],
29
29
  "word-document": ["doc", "docm", "docx"],
30
30
  zip: ["gz", "rar", "tgz", "zip"]
31
+ }, e = {
32
+ // Watermelon Red 120 (#BE2C46) - pdf, powerpoint-presentation, code
33
+ red: "var(--bp-watermelon-red-120, var(--watermelon-red-120))",
34
+ // Orange 130 (#A95A12) - boxcanvas, threed, vector, pages, google-slides, illustrator, presentation
35
+ orange: "var(--bp-orange-130, var(--orange-120))",
36
+ // Green Light 135 (#197E54) - image, excel-spreadsheet, numbers, google-sheets, spreadsheet
37
+ green: "var(--bp-green-light-135, var(--green-light-120))",
38
+ // Light Blue 115 (#1F72D6) - photoshop, dwg, keynote, video
39
+ lightBlue: "var(--bp-light-blue-115, var(--light-blue-110))",
40
+ // Light Blue 135 (#1757A4) - word-document, google-docs, text
41
+ darkBlue: "var(--bp-light-blue-135, var(--light-blue-120))",
42
+ // Purple Rain 100 (#9F3FED) - audio
43
+ purple: "var(--bp-purple-rain-100, var(--purple-rain-100))",
44
+ // Text on Light (#222222) - default for unspecified categories
45
+ gray: "var(--bp-gray-100, var(--gray-100))"
46
+ }, o = {
47
+ // Purple Rain 100
48
+ audio: e.purple,
49
+ // Orange 130
50
+ boxcanvas: e.orange,
51
+ // Default (text-on-light)
52
+ boxnote: e.gray,
53
+ // Watermelon Red 120
54
+ code: e.red,
55
+ // Default (text-on-light)
56
+ document: e.gray,
57
+ // Default (text-on-light)
58
+ "docuworks-binder": e.gray,
59
+ // Green Light 135
60
+ "docuworks-file": e.green,
61
+ // Light Blue 115
62
+ dwg: e.lightBlue,
63
+ // Green Light 135
64
+ "excel-spreadsheet": e.green,
65
+ // Light Blue 135
66
+ "google-docs": e.darkBlue,
67
+ // Green Light 135
68
+ "google-sheets": e.green,
69
+ // Orange 130
70
+ "google-slides": e.orange,
71
+ // Orange 130
72
+ illustrator: e.orange,
73
+ // Green Light 135
74
+ image: e.green,
75
+ // Default (text-on-light)
76
+ indesign: e.gray,
77
+ // Light Blue 115
78
+ keynote: e.lightBlue,
79
+ // Green Light 135
80
+ numbers: e.green,
81
+ // Orange 130
82
+ pages: e.orange,
83
+ // Watermelon Red 120
84
+ pdf: e.red,
85
+ // Light Blue 115
86
+ photoshop: e.lightBlue,
87
+ // Watermelon Red 120
88
+ "powerpoint-presentation": e.red,
89
+ // Orange 130
90
+ presentation: e.orange,
91
+ // Green Light 135
92
+ spreadsheet: e.green,
93
+ // Light Blue 135
94
+ text: e.darkBlue,
95
+ // Orange 130
96
+ threed: e.orange,
97
+ // Orange 130
98
+ vector: e.orange,
99
+ // Light Blue 115
100
+ video: e.lightBlue,
101
+ // Light Blue 135
102
+ "word-document": e.darkBlue,
103
+ // Default (text-on-light)
104
+ zip: e.gray
31
105
  };
32
106
  export {
33
- s as FILE_EXTENSIONS
107
+ o as FILE_CATEGORY_COLORS,
108
+ r as FILE_EXTENSION_CATEGORIES
34
109
  };
@@ -1,26 +1,27 @@
1
- import { getFileIconType as p } from "../utils.js";
1
+ import { getFileCategoryByExtension as c } from "../utils.js";
2
+ import "../constants.js";
2
3
  import { ItemIcon as d } from "../item-icon/item-icon.js";
3
- import { useIntl as h } from "react-intl";
4
- import { ItemType as a } from "@box/types";
4
+ import { useIntl as x } from "react-intl";
5
+ import { ItemType as t } from "@box/types";
5
6
  import o from "../messages.js";
6
- import { jsx as x } from "react/jsx-runtime";
7
+ import { jsx as h } from "react/jsx-runtime";
7
8
  const u = ({
8
9
  item: i,
9
10
  ...f
10
11
  }) => {
11
12
  const {
12
- archiveType: t,
13
+ archiveType: a,
13
14
  hasCollaborations: n,
14
15
  isExternallyOwned: m,
15
16
  type: l
16
17
  } = i, {
17
18
  extension: s = ""
18
19
  } = i, {
19
- formatMessage: c
20
- } = h();
20
+ formatMessage: p
21
+ } = x();
21
22
  let e = "default", r = o.file;
22
- return l === a.File ? (e = p(s.toLowerCase()), r = e === "default" ? o.file : o.fileExtension) : l === a.Folder ? t === "archive" ? (e = "archive", r = o.archive) : t === "folder_archive" ? (e = "folder-archive", r = o.archiveFolder) : m ? (e = "folder-external", r = o.externalFolder) : n ? (e = "folder-collab", r = o.collaboratedFolder) : (e = "folder-plain", r = o.personalFolder) : l === a.WebLink && (e = "bookmark", r = o.bookmark), /* @__PURE__ */ x(d, {
23
- ariaLabel: c(r, {
23
+ return l === t.File ? (e = c(s.toLowerCase()), r = e === "default" ? o.file : o.fileExtension) : l === t.Folder ? a === "archive" ? (e = "archive", r = o.archive) : a === "folder_archive" ? (e = "folder-archive", r = o.archiveFolder) : m ? (e = "folder-external", r = o.externalFolder) : n ? (e = "folder-collab", r = o.collaboratedFolder) : (e = "folder-plain", r = o.personalFolder) : l === t.WebLink && (e = "bookmark", r = o.bookmark), /* @__PURE__ */ h(d, {
24
+ ariaLabel: p(r, {
24
25
  extension: s.toUpperCase()
25
26
  }),
26
27
  iconType: e,
@@ -1,12 +1,13 @@
1
- import { FILE_EXTENSIONS as n } from "./constants.js";
2
- const f = (o = "") => {
3
- const e = {};
4
- return Object.entries(n).forEach(([t, r]) => {
5
- r.forEach((c) => {
6
- e[c] = t;
1
+ import { FILE_EXTENSION_CATEGORIES as E, FILE_CATEGORY_COLORS as c } from "./constants.js";
2
+ const i = (o = "") => {
3
+ const t = {};
4
+ return Object.entries(E).forEach(([e, n]) => {
5
+ n.forEach((r) => {
6
+ t[r] = e;
7
7
  });
8
- }), e[o] || "default";
9
- };
8
+ }), t[o] || "default";
9
+ }, O = (o) => o ? c[o] : void 0;
10
10
  export {
11
- f as getFileIconType
11
+ O as getColorByExtension,
12
+ i as getFileCategoryByExtension
12
13
  };
@@ -1,3 +1,5 @@
1
1
  export * from './lib/item-icon';
2
2
  export * from './lib/item-type-icon';
3
3
  export * from './lib/utils';
4
+ export { FILE_EXTENSION_CATEGORIES, FILE_CATEGORY_COLORS } from './lib/constants';
5
+ export type { FileCategory } from './lib/types/file-category';
@@ -1,4 +1,5 @@
1
- declare const FILE_EXTENSIONS: {
1
+ import { FileCategory } from './types/file-category';
2
+ declare const FILE_EXTENSION_CATEGORIES: {
2
3
  audio: string[];
3
4
  boxcanvas: string[];
4
5
  boxnote: string[];
@@ -29,4 +30,6 @@ declare const FILE_EXTENSIONS: {
29
30
  'word-document': string[];
30
31
  zip: string[];
31
32
  };
32
- export { FILE_EXTENSIONS };
33
+ /** Color mapping for file categories, optimized for bundle size */
34
+ declare const FILE_CATEGORY_COLORS: Record<FileCategory, string>;
35
+ export { FILE_EXTENSION_CATEGORIES, FILE_CATEGORY_COLORS };
@@ -0,0 +1 @@
1
+ export type FileCategory = 'audio' | 'boxcanvas' | 'boxnote' | 'code' | 'document' | 'docuworks-binder' | 'docuworks-file' | 'dwg' | 'excel-spreadsheet' | 'google-docs' | 'google-sheets' | 'google-slides' | 'illustrator' | 'image' | 'indesign' | 'keynote' | 'numbers' | 'pages' | 'pdf' | 'photoshop' | 'powerpoint-presentation' | 'presentation' | 'spreadsheet' | 'text' | 'threed' | 'vector' | 'video' | 'word-document' | 'zip';
@@ -1,2 +1,4 @@
1
- declare const getFileIconType: (extension?: string) => string;
2
- export { getFileIconType };
1
+ import { FileCategory } from './types/file-category';
2
+ declare const getFileCategoryByExtension: (extension?: string) => string;
3
+ declare const getColorByExtension: (fileCategory: FileCategory) => string | undefined;
4
+ export { getFileCategoryByExtension, getColorByExtension };
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@box/item-icon",
3
- "version": "2.18.2",
3
+ "version": "2.19.1",
4
4
  "peerDependencies": {
5
- "@box/blueprint-web": "^12.130.5",
6
- "@box/blueprint-web-assets": "^4.99.3",
5
+ "@box/blueprint-web": "^12.132.0",
6
+ "@box/blueprint-web-assets": "^4.99.5",
7
7
  "@box/types": "^0.2.0",
8
8
  "react": "^17.0.0 || ^18.0.0",
9
9
  "react-dom": "^17.0.0 || ^18.0.0",
10
10
  "react-intl": "^6.4.2"
11
11
  },
12
12
  "devDependencies": {
13
- "@box/blueprint-web": "^12.130.5",
14
- "@box/blueprint-web-assets": "^4.99.3",
13
+ "@box/blueprint-web": "^12.132.0",
14
+ "@box/blueprint-web-assets": "^4.99.5",
15
15
  "@box/types": "^2.0.0",
16
- "@box/storybook-utils": "^0.16.29",
16
+ "@box/storybook-utils": "^0.16.31",
17
17
  "react": "^18.3.0",
18
18
  "react-dom": "^18.3.0",
19
19
  "react-intl": "^6.4.2"