@fluentui/react-icons-file-type 0.0.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 +181 -0
- package/lib/FileTypeIcon.d.ts +16 -0
- package/lib/FileTypeIcon.js +19 -0
- package/lib/FileTypeIcon.styles.d.ts +7 -0
- package/lib/FileTypeIcon.styles.js +23 -0
- package/lib/common/FileIconType.d.ts +2 -0
- package/lib/common/FileIconType.js +5 -0
- package/lib/common/FileTypeIconsContext.d.ts +29 -0
- package/lib/common/FileTypeIconsContext.js +22 -0
- package/lib/common/constants.d.ts +22 -0
- package/lib/common/constants.js +18 -0
- package/lib/common/fileIconTypes.generated.d.ts +57 -0
- package/lib/common/fileIconTypes.generated.js +86 -0
- package/lib/common/fileTypeIconMap.generated.d.ts +7 -0
- package/lib/common/fileTypeIconMap.generated.js +28 -0
- package/lib/common/fileTypeIconResolver.d.ts +59 -0
- package/lib/common/fileTypeIconResolver.js +83 -0
- package/lib/common/useFileTypeIcon.d.ts +36 -0
- package/lib/common/useFileTypeIcon.js +90 -0
- package/lib/headless/FileTypeIcon.d.ts +20 -0
- package/lib/headless/FileTypeIcon.js +21 -0
- package/lib/headless/index.d.ts +8 -0
- package/lib/headless/index.js +8 -0
- package/lib/headless/styles.css +13 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +4 -0
- package/lib-cjs/FileTypeIcon.d.ts +16 -0
- package/lib-cjs/FileTypeIcon.js +23 -0
- package/lib-cjs/FileTypeIcon.styles.d.ts +7 -0
- package/lib-cjs/FileTypeIcon.styles.js +27 -0
- package/lib-cjs/common/FileIconType.d.ts +2 -0
- package/lib-cjs/common/FileIconType.js +9 -0
- package/lib-cjs/common/FileTypeIconsContext.d.ts +29 -0
- package/lib-cjs/common/FileTypeIconsContext.js +28 -0
- package/lib-cjs/common/constants.d.ts +22 -0
- package/lib-cjs/common/constants.js +21 -0
- package/lib-cjs/common/fileIconTypes.generated.d.ts +57 -0
- package/lib-cjs/common/fileIconTypes.generated.js +89 -0
- package/lib-cjs/common/fileTypeIconMap.generated.d.ts +7 -0
- package/lib-cjs/common/fileTypeIconMap.generated.js +32 -0
- package/lib-cjs/common/fileTypeIconResolver.d.ts +59 -0
- package/lib-cjs/common/fileTypeIconResolver.js +89 -0
- package/lib-cjs/common/useFileTypeIcon.d.ts +36 -0
- package/lib-cjs/common/useFileTypeIcon.js +96 -0
- package/lib-cjs/headless/FileTypeIcon.d.ts +20 -0
- package/lib-cjs/headless/FileTypeIcon.js +28 -0
- package/lib-cjs/headless/index.d.ts +8 -0
- package/lib-cjs/headless/index.js +20 -0
- package/lib-cjs/headless/styles.css +13 -0
- package/lib-cjs/index.d.ts +8 -0
- package/lib-cjs/index.js +15 -0
- package/package.json +69 -0
package/README.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# @fluentui/react-icons-file-type
|
|
2
|
+
|
|
3
|
+
File type icon components for React, rendered from Microsoft Fluent CDN-hosted assets. A v9-compatible, dependency-light successor to the v8 `@fluentui/react-file-type-icons` package — no global icon registry and no CDN hardcoded inside the component.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @fluentui/react-icons-file-type
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Zero configuration
|
|
14
|
+
|
|
15
|
+
The icon resolves its assets from the Fluent CDN by default, so it works out of the box — no provider or setup required.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { FileTypeIcon } from '@fluentui/react-icons-file-type';
|
|
19
|
+
|
|
20
|
+
function Example() {
|
|
21
|
+
return <FileTypeIcon extension="docx" size={24} />;
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Configure the asset host once
|
|
26
|
+
|
|
27
|
+
Wrap your app (or a subtree) with `FileTypeIconsProvider` to serve the icons from your own host — for example a same-origin CDN proxy.
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { FileTypeIconsProvider, FileTypeIcon } from '@fluentui/react-icons-file-type';
|
|
31
|
+
|
|
32
|
+
function App() {
|
|
33
|
+
return (
|
|
34
|
+
<FileTypeIconsProvider baseUrl="https://my-cdn.example.com/item-types/">
|
|
35
|
+
<FileTypeIcon extension="pptx" size={24} />
|
|
36
|
+
</FileTypeIconsProvider>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`baseUrl` resolution precedence:
|
|
42
|
+
|
|
43
|
+
1. the `baseUrl` from the nearest `<FileTypeIconsProvider>`
|
|
44
|
+
2. the Fluent CDN default
|
|
45
|
+
|
|
46
|
+
### Icons without a file extension
|
|
47
|
+
|
|
48
|
+
Use the `type` prop with `FileIconType` for icons that aren't tied to an extension (folders, lists, etc.).
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { FileTypeIcon, FileIconType } from '@fluentui/react-icons-file-type';
|
|
52
|
+
|
|
53
|
+
<FileTypeIcon type={FileIconType.folder} size={24} />;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Headless (style-free) API
|
|
57
|
+
|
|
58
|
+
The default `FileTypeIcon` is styled with [Griffel](https://github.com/microsoft/griffel) (zero setup). To avoid bundling the Griffel runtime and own all styling yourself, import from the `/headless` subpath. The component is behavior-identical but ships **no** styling runtime; it tags the `<img>` with a `data-fui-filetype-icon` attribute you can style.
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
// import the opt-in stylesheet once (reproduces the default box behavior)...
|
|
62
|
+
import '@fluentui/react-icons-file-type/headless/styles.css';
|
|
63
|
+
import { FileTypeIcon } from '@fluentui/react-icons-file-type/headless';
|
|
64
|
+
|
|
65
|
+
<FileTypeIcon extension="docx" size={24} />;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```css
|
|
69
|
+
/* ...or target the data attribute (or a className) with your own CSS */
|
|
70
|
+
[data-fui-filetype-icon] {
|
|
71
|
+
display: inline-block;
|
|
72
|
+
overflow: hidden;
|
|
73
|
+
object-fit: contain;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The `/headless` entry point re-exports `FileTypeIconsProvider`, `useFileTypeIconsContext`, `FileIconType`, and the constants, so it is usable on its own. Prefer the default entry point unless you specifically need to drop the Griffel runtime.
|
|
78
|
+
|
|
79
|
+
## Migrating from `@fluentui/react-file-type-icons` (v8)
|
|
80
|
+
|
|
81
|
+
> This section is written to be self-contained for both humans and automated agents. It lists
|
|
82
|
+
> the exact package/API differences and the rewrite for each v8 usage pattern.
|
|
83
|
+
|
|
84
|
+
### 1. Package name changed
|
|
85
|
+
|
|
86
|
+
The package name is **different** (the words are reordered). Update `package.json` and every import.
|
|
87
|
+
|
|
88
|
+
| | Package |
|
|
89
|
+
| -------- | --------------------------------- |
|
|
90
|
+
| v8 (old) | `@fluentui/react-file-type-icons` |
|
|
91
|
+
| v9 (new) | `@fluentui/react-icons-file-type` |
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npm uninstall @fluentui/react-file-type-icons
|
|
95
|
+
npm install @fluentui/react-icons-file-type
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
```diff
|
|
99
|
+
- import { ... } from '@fluentui/react-file-type-icons';
|
|
100
|
+
+ import { ... } from '@fluentui/react-icons-file-type';
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 2. There is no global registry / initialization
|
|
104
|
+
|
|
105
|
+
v8 required `initializeFileTypeIcons()` at app startup to register icons into the global
|
|
106
|
+
`@fluentui/react` (v8) icon registry. v9 has **no global state** — remove the call entirely.
|
|
107
|
+
Assets are resolved per render from the CDN.
|
|
108
|
+
|
|
109
|
+
```diff
|
|
110
|
+
- import { initializeFileTypeIcons } from '@fluentui/react-file-type-icons';
|
|
111
|
+
- initializeFileTypeIcons(); // at app startup
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 3. Render with the `FileTypeIcon` component instead of `Icon` + props
|
|
115
|
+
|
|
116
|
+
v8 produced props for the v8 `<Icon>` component via `getFileTypeIconProps`. v9 ships a
|
|
117
|
+
dedicated component; pass the same options as props.
|
|
118
|
+
|
|
119
|
+
```diff
|
|
120
|
+
- import { Icon } from '@fluentui/react';
|
|
121
|
+
- import { getFileTypeIconProps } from '@fluentui/react-file-type-icons';
|
|
122
|
+
- <Icon {...getFileTypeIconProps({ extension: 'docx', size: 24 })} />
|
|
123
|
+
+ import { FileTypeIcon } from '@fluentui/react-icons-file-type';
|
|
124
|
+
+ <FileTypeIcon extension="docx" size={24} />
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The options are the same shape: `extension`, `type`, `size`, and `imageFileType` (`'svg' | 'png'`).
|
|
128
|
+
For non-extension icons use the `type` prop with `FileIconType` (see below).
|
|
129
|
+
|
|
130
|
+
### 4. Configure a custom CDN via the provider (not an init argument)
|
|
131
|
+
|
|
132
|
+
```diff
|
|
133
|
+
- initializeFileTypeIcons('https://my-cdn.example.com/item-types/');
|
|
134
|
+
+ import { FileTypeIconsProvider } from '@fluentui/react-icons-file-type';
|
|
135
|
+
+ <FileTypeIconsProvider baseUrl="https://my-cdn.example.com/item-types/">
|
|
136
|
+
+ {/* ...app... */}
|
|
137
|
+
+ </FileTypeIconsProvider>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
The Fluent CDN remains the **default** in both v8 and v9, so a `baseUrl` is only needed to
|
|
141
|
+
override the host. There is no per-`FileTypeIcon` `baseUrl` prop — configure it on the provider.
|
|
142
|
+
|
|
143
|
+
### 5. `FileIconType` is now a `const` object, not a TypeScript `enum`
|
|
144
|
+
|
|
145
|
+
Value usage is unchanged — `FileIconType.folder` still works. The difference is type-level: it
|
|
146
|
+
is a `const` object plus a derived union type rather than a TS `enum`. This avoids a runtime
|
|
147
|
+
reverse-mapping and is generally a drop-in replacement.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { FileTypeIcon, FileIconType } from '@fluentui/react-icons-file-type';
|
|
151
|
+
<FileTypeIcon type={FileIconType.folder} size={24} />;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Notes for code that did unusual things with the v8 enum:
|
|
155
|
+
|
|
156
|
+
- ✅ `FileIconType.folder` (value access) — unchanged.
|
|
157
|
+
- ✅ `type: FileIconType` (type annotation) — unchanged; `FileIconTypeInput` is also exported and
|
|
158
|
+
is structurally the numeric union accepted by the `type` prop.
|
|
159
|
+
- ⚠️ Reverse lookup `FileIconType[7]` (number → name) — **not available**. A `const` object has no
|
|
160
|
+
reverse map. If you relied on this, keep your own name table.
|
|
161
|
+
|
|
162
|
+
### 6. APIs that were NOT ported
|
|
163
|
+
|
|
164
|
+
The following v8 exports are intentionally **not** part of the v9 public API. Use the
|
|
165
|
+
`FileTypeIcon` component instead.
|
|
166
|
+
|
|
167
|
+
| v8 export | v9 replacement |
|
|
168
|
+
| --------------------------------------- | ----------------------------------------------- |
|
|
169
|
+
| `initializeFileTypeIcons()` | _removed_ — no global registry |
|
|
170
|
+
| `getFileTypeIconProps()` | `<FileTypeIcon {...options} />` |
|
|
171
|
+
| `getFileTypeIconAsUrl()` | _not exported_ — use `<FileTypeIcon>` |
|
|
172
|
+
| `getFileTypeIconAsHTMLString()` | _not exported_ — use `<FileTypeIcon>` |
|
|
173
|
+
| `FileTypeIconMap` (raw extension table) | _not exported_ — internal implementation detail |
|
|
174
|
+
|
|
175
|
+
### v9 public API surface (for reference)
|
|
176
|
+
|
|
177
|
+
- Components: `FileTypeIcon`, `FileTypeIconsProvider`
|
|
178
|
+
- Hook: `useFileTypeIconsContext`
|
|
179
|
+
- Values: `FileIconType`, `DEFAULT_BASE_URL`, `FLUENT_CDN_BASE_URL`, `DEFAULT_ICON_SIZE`, `ICON_SIZES`
|
|
180
|
+
- Types: `FileTypeIconProps`, `FileTypeIconsContextValue`, `FileTypeIconsProviderProps`,
|
|
181
|
+
`FileIconTypeInput`, `FileTypeIconSize`, `ImageFileType`
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { FileTypeIconProps } from './common/useFileTypeIcon';
|
|
3
|
+
export type { FileTypeIconProps } from './common/useFileTypeIcon';
|
|
4
|
+
/**
|
|
5
|
+
* Renders a file type icon as an `<img>` sourced from CDN-hosted assets, styled with Griffel
|
|
6
|
+
* (zero setup required). This is the default entry point.
|
|
7
|
+
*
|
|
8
|
+
* It composes the same state ({@link useFileTypeIcon}) and render ({@link renderFileTypeIcon})
|
|
9
|
+
* hooks as the headless `FileTypeIcon`, inserting a Griffel style hook in between to layer the
|
|
10
|
+
* static styles. To avoid the Griffel runtime, import from the `/headless` subpath and provide
|
|
11
|
+
* your own styles (see `headless/styles.css`).
|
|
12
|
+
*
|
|
13
|
+
* The asset host is resolved from the nearest `FileTypeIconsProvider`, falling back to the
|
|
14
|
+
* Fluent CDN default when no provider is present.
|
|
15
|
+
*/
|
|
16
|
+
export declare const FileTypeIcon: React.FC<FileTypeIconProps>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useFileTypeIcon, renderFileTypeIcon } from './common/useFileTypeIcon';
|
|
2
|
+
import { useFileTypeIconStyles } from './FileTypeIcon.styles';
|
|
3
|
+
/**
|
|
4
|
+
* Renders a file type icon as an `<img>` sourced from CDN-hosted assets, styled with Griffel
|
|
5
|
+
* (zero setup required). This is the default entry point.
|
|
6
|
+
*
|
|
7
|
+
* It composes the same state ({@link useFileTypeIcon}) and render ({@link renderFileTypeIcon})
|
|
8
|
+
* hooks as the headless `FileTypeIcon`, inserting a Griffel style hook in between to layer the
|
|
9
|
+
* static styles. To avoid the Griffel runtime, import from the `/headless` subpath and provide
|
|
10
|
+
* your own styles (see `headless/styles.css`).
|
|
11
|
+
*
|
|
12
|
+
* The asset host is resolved from the nearest `FileTypeIconsProvider`, falling back to the
|
|
13
|
+
* Fluent CDN default when no provider is present.
|
|
14
|
+
*/
|
|
15
|
+
export const FileTypeIcon = (props) => {
|
|
16
|
+
const state = useFileTypeIcon(props);
|
|
17
|
+
useFileTypeIconStyles(state);
|
|
18
|
+
return renderFileTypeIcon(state);
|
|
19
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FileTypeIconState } from './common/useFileTypeIcon';
|
|
2
|
+
/**
|
|
3
|
+
* Style hook: layers the Griffel `root` class onto a resolved {@link FileTypeIconState},
|
|
4
|
+
* merging ahead of any consumer-provided `className`. Mutates and returns the same state,
|
|
5
|
+
* following the Fluent v9 style-hook convention.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useFileTypeIconStyles(state: FileTypeIconState): FileTypeIconState;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { makeStyles, mergeClasses } from '@griffel/react';
|
|
2
|
+
/**
|
|
3
|
+
* Static styles for the `FileTypeIcon` image. `object-fit: contain` keeps non-square assets
|
|
4
|
+
* from being stretched within the square `width`/`height` box (both applied inline by the
|
|
5
|
+
* state hook from the `size` prop). `object-fit` only affects replaced elements, so these
|
|
6
|
+
* styles must live on the `<img>` itself, not on a wrapper.
|
|
7
|
+
*/
|
|
8
|
+
const useStyles = makeStyles({
|
|
9
|
+
root: {
|
|
10
|
+
display: 'inline-block',
|
|
11
|
+
objectFit: 'contain',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Style hook: layers the Griffel `root` class onto a resolved {@link FileTypeIconState},
|
|
16
|
+
* merging ahead of any consumer-provided `className`. Mutates and returns the same state,
|
|
17
|
+
* following the Fluent v9 style-hook convention.
|
|
18
|
+
*/
|
|
19
|
+
export function useFileTypeIconStyles(state) {
|
|
20
|
+
const styles = useStyles();
|
|
21
|
+
state.className = mergeClasses(styles.root, state.className);
|
|
22
|
+
return state;
|
|
23
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Public, stable module path for the file type icon enum. The actual definitions are
|
|
2
|
+
// generated from `fileIconTypes.json` into `fileIconTypes.generated.ts` (run `npm run
|
|
3
|
+
// generate`); this barrel re-exports the public surface so consumers and internal code
|
|
4
|
+
// import from a hand-written path rather than the generated artifact.
|
|
5
|
+
export { FileIconType } from './fileIconTypes.generated';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface FileTypeIconsContextValue {
|
|
3
|
+
/**
|
|
4
|
+
* Base URL used to resolve file type icon assets for all descendant `FileTypeIcon`
|
|
5
|
+
* components. Defaults to the Fluent CDN so no configuration is required to get started.
|
|
6
|
+
* Provide your own asset host to serve the icons from a different (e.g. same-origin) location.
|
|
7
|
+
*/
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
}
|
|
10
|
+
export interface FileTypeIconsProviderProps {
|
|
11
|
+
/**
|
|
12
|
+
* Base URL used to resolve file type icon assets.
|
|
13
|
+
* @default the Fluent CDN base url
|
|
14
|
+
*/
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Provides the `baseUrl` used by descendant `FileTypeIcon` components to resolve
|
|
20
|
+
* their CDN-hosted assets. Omitting `baseUrl` falls back to the Fluent CDN, mirroring
|
|
21
|
+
* the zero-configuration ergonomics of the legacy `initializeFileTypeIcons` default
|
|
22
|
+
* without hardcoding the CDN inside the icon component itself.
|
|
23
|
+
*/
|
|
24
|
+
export declare const FileTypeIconsProvider: React.FC<FileTypeIconsProviderProps>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the current `FileTypeIcons` context value. When no provider is present, the
|
|
27
|
+
* default Fluent CDN `baseUrl` is returned so icons render without explicit setup.
|
|
28
|
+
*/
|
|
29
|
+
export declare const useFileTypeIconsContext: () => FileTypeIconsContextValue;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DEFAULT_BASE_URL } from './constants';
|
|
3
|
+
const FileTypeIconsContext = React.createContext(undefined);
|
|
4
|
+
/**
|
|
5
|
+
* Provides the `baseUrl` used by descendant `FileTypeIcon` components to resolve
|
|
6
|
+
* their CDN-hosted assets. Omitting `baseUrl` falls back to the Fluent CDN, mirroring
|
|
7
|
+
* the zero-configuration ergonomics of the legacy `initializeFileTypeIcons` default
|
|
8
|
+
* without hardcoding the CDN inside the icon component itself.
|
|
9
|
+
*/
|
|
10
|
+
export const FileTypeIconsProvider = (props) => {
|
|
11
|
+
const { baseUrl = DEFAULT_BASE_URL, children } = props;
|
|
12
|
+
const value = React.useMemo(() => ({ baseUrl }), [baseUrl]);
|
|
13
|
+
return React.createElement(FileTypeIconsContext.Provider, { value: value }, children);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Returns the current `FileTypeIcons` context value. When no provider is present, the
|
|
17
|
+
* default Fluent CDN `baseUrl` is returned so icons render without explicit setup.
|
|
18
|
+
*/
|
|
19
|
+
export const useFileTypeIconsContext = () => {
|
|
20
|
+
const context = React.useContext(FileTypeIconsContext);
|
|
21
|
+
return context !== null && context !== void 0 ? context : { baseUrl: DEFAULT_BASE_URL };
|
|
22
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base URL of the Microsoft Fluent CDN that hosts the file type icon assets.
|
|
3
|
+
*
|
|
4
|
+
* NOTE: this value is intentionally version-stamped by the CDN. It is provided as a
|
|
5
|
+
* sensible, overridable default so consumers do not need to configure a CDN to get
|
|
6
|
+
* started. To use your own asset host, supply a `baseUrl` to `FileTypeIconsProvider`
|
|
7
|
+
* (or to the individual helper functions / the `baseUrl` prop on `FileTypeIcon`).
|
|
8
|
+
*/
|
|
9
|
+
export declare const FLUENT_CDN_BASE_URL = "https://res.cdn.office.net/files/fabric-cdn-prod_20260623.001";
|
|
10
|
+
/**
|
|
11
|
+
* Default base URL used to resolve file type icon assets when no `baseUrl` is provided.
|
|
12
|
+
* Points at the `item-types` asset folder on the Fluent CDN.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_BASE_URL: string;
|
|
15
|
+
/** The set of pixel sizes for which file type icon assets are published. */
|
|
16
|
+
export declare const ICON_SIZES: readonly [16, 20, 24, 32, 40, 48, 64, 96];
|
|
17
|
+
/** The default icon size in pixels. */
|
|
18
|
+
export declare const DEFAULT_ICON_SIZE: FileTypeIconSize;
|
|
19
|
+
/** Supported file type icon pixel sizes. */
|
|
20
|
+
export type FileTypeIconSize = (typeof ICON_SIZES)[number];
|
|
21
|
+
/** Supported image file formats for file type icon assets. */
|
|
22
|
+
export type ImageFileType = 'svg' | 'png';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base URL of the Microsoft Fluent CDN that hosts the file type icon assets.
|
|
3
|
+
*
|
|
4
|
+
* NOTE: this value is intentionally version-stamped by the CDN. It is provided as a
|
|
5
|
+
* sensible, overridable default so consumers do not need to configure a CDN to get
|
|
6
|
+
* started. To use your own asset host, supply a `baseUrl` to `FileTypeIconsProvider`
|
|
7
|
+
* (or to the individual helper functions / the `baseUrl` prop on `FileTypeIcon`).
|
|
8
|
+
*/
|
|
9
|
+
export const FLUENT_CDN_BASE_URL = 'https://res.cdn.office.net/files/fabric-cdn-prod_20260623.001';
|
|
10
|
+
/**
|
|
11
|
+
* Default base URL used to resolve file type icon assets when no `baseUrl` is provided.
|
|
12
|
+
* Points at the `item-types` asset folder on the Fluent CDN.
|
|
13
|
+
*/
|
|
14
|
+
export const DEFAULT_BASE_URL = `${FLUENT_CDN_BASE_URL}/assets/item-types/`;
|
|
15
|
+
/** The set of pixel sizes for which file type icon assets are published. */
|
|
16
|
+
export const ICON_SIZES = [16, 20, 24, 32, 40, 48, 64, 96];
|
|
17
|
+
/** The default icon size in pixels. */
|
|
18
|
+
export const DEFAULT_ICON_SIZE = 16;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumerates special file type icons that do not map to any file extensions.
|
|
3
|
+
* For example, the 'pptx' icon maps to the extensions 'ppt', 'pptm', 'pptx',
|
|
4
|
+
* but the 'folder' icon does not map to any extensions and should be obtained
|
|
5
|
+
* via this enum.
|
|
6
|
+
*
|
|
7
|
+
* Implemented as a `const` object (rather than a TypeScript `enum`) so it does not
|
|
8
|
+
* emit a runtime reverse-mapping. The merged `FileIconType` type below lets it be
|
|
9
|
+
* used as both a value (`FileIconType.folder`) and a type (`type: FileIconType`),
|
|
10
|
+
* preserving the ergonomics of the previous `enum`. Values start at 1 so they evaluate
|
|
11
|
+
* as truthy.
|
|
12
|
+
*/
|
|
13
|
+
export declare const FileIconType: {
|
|
14
|
+
readonly docset: 1;
|
|
15
|
+
readonly folder: 2;
|
|
16
|
+
readonly genericFile: 3;
|
|
17
|
+
readonly listItem: 4;
|
|
18
|
+
readonly sharedFolder: 5;
|
|
19
|
+
readonly multiple: 6;
|
|
20
|
+
readonly stream: 7;
|
|
21
|
+
readonly news: 8;
|
|
22
|
+
readonly desktopFolder: 9;
|
|
23
|
+
readonly documentsFolder: 10;
|
|
24
|
+
readonly picturesFolder: 11;
|
|
25
|
+
readonly linkedFolder: 12;
|
|
26
|
+
readonly list: 13;
|
|
27
|
+
readonly form: 14;
|
|
28
|
+
readonly sway: 15;
|
|
29
|
+
readonly playlist: 16;
|
|
30
|
+
readonly loopworkspace: 17;
|
|
31
|
+
readonly planner: 18;
|
|
32
|
+
readonly todoItem: 19;
|
|
33
|
+
readonly portfolio: 20;
|
|
34
|
+
readonly album: 21;
|
|
35
|
+
readonly listForm: 22;
|
|
36
|
+
readonly campaign: 23;
|
|
37
|
+
readonly shortcutsdefaultfolder: 24;
|
|
38
|
+
readonly pbiApp: 25;
|
|
39
|
+
readonly pbiDashboard: 26;
|
|
40
|
+
readonly pbiPaginatedReport: 27;
|
|
41
|
+
readonly pbiScorecard: 28;
|
|
42
|
+
readonly pbiSemanticModel: 29;
|
|
43
|
+
readonly pbiReport: 30;
|
|
44
|
+
};
|
|
45
|
+
export type FileIconType = (typeof FileIconType)[keyof typeof FileIconType];
|
|
46
|
+
/**
|
|
47
|
+
* Numeric input form of {@link FileIconType}, accepted by the `type` prop / option.
|
|
48
|
+
* Structurally identical to `FileIconType` (`1 | 2 | … | N`); kept as a named alias
|
|
49
|
+
* for API stability and call-site readability.
|
|
50
|
+
*/
|
|
51
|
+
export type FileIconTypeInput = FileIconType;
|
|
52
|
+
/**
|
|
53
|
+
* Icon base name for each numeric {@link FileIconType} value, positionally indexed by
|
|
54
|
+
* that value (index 0 is unused since values start at 1). Empty entries fall back to the
|
|
55
|
+
* generic file icon at runtime.
|
|
56
|
+
*/
|
|
57
|
+
export declare const TYPE_TO_ICON_NAME: ReadonlyArray<string>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
// AUTO-GENERATED by scripts/generateFileIconTypes.js from src/common/fileIconTypes.json.
|
|
4
|
+
// Do not edit this file manually. Run `npm run generate` to regenerate it.
|
|
5
|
+
/**
|
|
6
|
+
* Enumerates special file type icons that do not map to any file extensions.
|
|
7
|
+
* For example, the 'pptx' icon maps to the extensions 'ppt', 'pptm', 'pptx',
|
|
8
|
+
* but the 'folder' icon does not map to any extensions and should be obtained
|
|
9
|
+
* via this enum.
|
|
10
|
+
*
|
|
11
|
+
* Implemented as a `const` object (rather than a TypeScript `enum`) so it does not
|
|
12
|
+
* emit a runtime reverse-mapping. The merged `FileIconType` type below lets it be
|
|
13
|
+
* used as both a value (`FileIconType.folder`) and a type (`type: FileIconType`),
|
|
14
|
+
* preserving the ergonomics of the previous `enum`. Values start at 1 so they evaluate
|
|
15
|
+
* as truthy.
|
|
16
|
+
*/
|
|
17
|
+
export const FileIconType = {
|
|
18
|
+
docset: 1,
|
|
19
|
+
folder: 2,
|
|
20
|
+
genericFile: 3,
|
|
21
|
+
listItem: 4,
|
|
22
|
+
sharedFolder: 5,
|
|
23
|
+
multiple: 6,
|
|
24
|
+
stream: 7,
|
|
25
|
+
news: 8,
|
|
26
|
+
desktopFolder: 9,
|
|
27
|
+
documentsFolder: 10,
|
|
28
|
+
picturesFolder: 11,
|
|
29
|
+
linkedFolder: 12,
|
|
30
|
+
list: 13,
|
|
31
|
+
form: 14,
|
|
32
|
+
sway: 15,
|
|
33
|
+
playlist: 16,
|
|
34
|
+
loopworkspace: 17,
|
|
35
|
+
planner: 18,
|
|
36
|
+
todoItem: 19,
|
|
37
|
+
portfolio: 20,
|
|
38
|
+
album: 21,
|
|
39
|
+
listForm: 22,
|
|
40
|
+
campaign: 23,
|
|
41
|
+
shortcutsdefaultfolder: 24,
|
|
42
|
+
pbiApp: 25,
|
|
43
|
+
pbiDashboard: 26,
|
|
44
|
+
pbiPaginatedReport: 27,
|
|
45
|
+
pbiScorecard: 28,
|
|
46
|
+
pbiSemanticModel: 29,
|
|
47
|
+
pbiReport: 30,
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Icon base name for each numeric {@link FileIconType} value, positionally indexed by
|
|
51
|
+
* that value (index 0 is unused since values start at 1). Empty entries fall back to the
|
|
52
|
+
* generic file icon at runtime.
|
|
53
|
+
*/
|
|
54
|
+
export const TYPE_TO_ICON_NAME = [
|
|
55
|
+
'',
|
|
56
|
+
'docset',
|
|
57
|
+
'folder',
|
|
58
|
+
'',
|
|
59
|
+
'listitem',
|
|
60
|
+
'sharedfolder',
|
|
61
|
+
'multiple',
|
|
62
|
+
'video',
|
|
63
|
+
'sponews',
|
|
64
|
+
'desktopfolder',
|
|
65
|
+
'documentsfolder',
|
|
66
|
+
'picturesfolder',
|
|
67
|
+
'linkedfolder',
|
|
68
|
+
'splist',
|
|
69
|
+
'form',
|
|
70
|
+
'sway',
|
|
71
|
+
'playlist',
|
|
72
|
+
'loopworkspace',
|
|
73
|
+
'planner',
|
|
74
|
+
'todoitem',
|
|
75
|
+
'portfolio',
|
|
76
|
+
'album',
|
|
77
|
+
'listform',
|
|
78
|
+
'spocampaign',
|
|
79
|
+
'companyfolder',
|
|
80
|
+
'pbiapp',
|
|
81
|
+
'pbidashboard',
|
|
82
|
+
'pbipagereport',
|
|
83
|
+
'pbiscorecard',
|
|
84
|
+
'pbisemmodel',
|
|
85
|
+
'powerbi', // 30 pbiReport
|
|
86
|
+
];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
// AUTO-GENERATED by scripts/generateFileTypeIconMap.js from src/common/fileTypeIconMap.json.
|
|
4
|
+
// Do not edit this file manually. Run `npm run generate` to regenerate it.
|
|
5
|
+
/**
|
|
6
|
+
* Minimal packed `icon name`->`extensions` table.
|
|
7
|
+
*
|
|
8
|
+
* Format: `icon:ext,ext;icon:ext`. Decoded lazily into an
|
|
9
|
+
* `extension -> icon name` lookup by {@link getFileTypeIconExtensionMap}.
|
|
10
|
+
*/
|
|
11
|
+
const PACKED_FILE_TYPE_ICON_MAP = 'accdb:accdb,mdb;agentwork:work;aipage:page;archive:7z,ace,arc,arj,dmg,gz,iso,lzh,pkg,rar,sit,tgz,tar,z;audio:aif,aiff,aac,alac,amr,ape,au,awb,dct,dss,dvf,flac,gsm,m4a,m4p,mid,mmf,mp3,oga,ra,rm,wav,wma,wv;calendar:ical,icalendar,ics,ifb,vcs;classifier:classifier;clipchamp:clipchamp;cliptemplate:cliptemplate;code:abap,ada,adp,ahk,as,as3,asc,ascx,asm,asp,awk,bash,bash_login,bash_logout,bash_profile,bashrc,bat,bib,bsh,build,builder,c,cbl,c++,capfile,cc,cfc,cfm,cfml,cl,clj,cls,cmake,cmd,coffee,config,cpp,cpt,cpy,cs,cshtml,cson,csproj,css,ctp,cxx,d,ddl,di,disco,dml,dtd,dtml,el,emakefile,erb,erl,f,f90,f95,fs,fsi,fsscript,fsx,gemfile,gemspec,gitconfig,go,groovy,gvy,h,h++,haml,handlebars,hbs,hcp,hh,hpp,hrl,hs,htc,hxx,idl,iim,inc,inf,ini,inl,ipp,irbrc,jade,jav,java,js,json,jsp,jsproj,jsx,l,less,lhs,lisp,log,lst,ltx,lua,m,mak,make,manifest,master,ml,mli,mll,mly,mm,mud,nfo,opml,osascript,p,pas,patch,php,php2,php3,php4,php5,phtml,pl,pm,pod,pp,profile,ps1,ps1xml,psd1,psm1,pss,pt,py,pyw,r,rake,rb,rbx,rc,rdf,re,reg,rest,resw,resx,rhtml,rjs,rprofile,rpy,rss,rst,ruby,rxml,s,sass,scala,scm,sconscript,sconstruct,script,scss,sgml,sh,shtml,sml,svn-base,swift,sql,sty,tcl,tex,textile,tld,tli,tmpl,tpl,vb,vi,vim,vmg,webpart,wsp,wsdl,xhtml,xoml,xsd,xslt,yaml,yaws,yml,zsh;contact:vcf;copilot:copilot;csv:csv;designer:design;docx:doc,docm,docx,docb;dotx:dot,dotm,dotx;email:eml,msg,oft,ost,pst;exe:application,appref-ms,apk,app,appx,exe,ipa,msi,xap;font:ttf,otf,woff;html:htm,html,mht,mhtml;inkcanvas:canvas;ipynb:nnb,ipynb;link:lnk,link,url,website,webloc;loop:fluid,loop,note;mctemplate:mctemplate;mcworld:mcworld;md:md,markdn,markdown,mdown,mkdn;model:3ds,3mf,blend,cool,dae,df,dwfx,dwg,dxf,fbx,glb,gltf,holo,layer,layout,max,mtl,obj,off,ply,skp,stp,stl,t,thl,x;mpp:mpp;mpt:mpt;officescript:osts;one:one,onepart;onepage:onepage;onetoc:ms-one-stub,onetoc,onetoc2,onepkg;pdf:pdf;photo:arw,bmp,cr2,crw,dic,dicm,dcm,dcm30,dcr,dds,dib,dng,erf,gif,heic,heif,ico,jfi,jfif,jif,jpe,jpeg,jpg,jxr,kdc,mrw,nef,orf,pct,pict,png,pns,psb,psd,raw,tga,tif,tiff,wdp;potx:pot,potm,potx;powerbi:pbids,pbix;ppsx:pps,ppsm,ppsx;pptx:ppt,pptm,pptx,sldx,sldm;presentation:odp,gslides,key;pub:pub;rtf:epub,gdoc,odt,rtf,wri,pages;spo:aspx;spreadsheet:odc,ods,gsheet,numbers,tsv;sysfile:bak,bin,cab,cache,cat,cer,class,dat,db,dbg,dl_,dll,ithmb,jar,kb,ldt,lrprev,pkpass,ppa,ppam,pdb,rom,thm,thmx,vsl,xla,xlam,xlb,xll;txt:dif,diff,readme,out,plist,properties,text,txt;vector:ai,ait,cvs,dgn,gdraw,pd,emf,eps,fig,ind,indd,indl,indt,indb,ps,svg,svgz,wmf,oxps,xps,xd,sketch;video:3g2,3gp,3gp2,3gpp,asf,avi,dvr-ms,flv,m1v,m4v,mkv,mod,mov,mm4p,mp2,mp2v,mp4,mp4v,mpa,mpe,mpeg,mpg,mpv,mpv2,mts,ogg,qt,swf,ts,vob,webm,wlmp,wm,wmv,wmx;vsdx:vdx,vsd,vsdm,vsdx,vsw,vdw;vssx:vss,vssm,vssx;vstx:vst,vstm,vstx,vsx;whiteboard:whiteboard,wbtx;xlsx:xlc,xls,xlsb,xlsm,xlsx,xlw;xltx:xlt,xltm,xltx;xml:xaml,xml,xsl;xsn:xsn;zip:zip';
|
|
12
|
+
let _extensionToIconName;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the `extension`->`icon name` lookup table, decoding the packed
|
|
15
|
+
* string on first use and caching the result for subsequent calls.
|
|
16
|
+
*/
|
|
17
|
+
export function getFileTypeIconExtensionMap() {
|
|
18
|
+
if (!_extensionToIconName) {
|
|
19
|
+
_extensionToIconName = {};
|
|
20
|
+
for (const group of PACKED_FILE_TYPE_ICON_MAP.split(';')) {
|
|
21
|
+
const [iconName, extensions] = group.split(':');
|
|
22
|
+
for (const extension of extensions.split(',')) {
|
|
23
|
+
_extensionToIconName[extension] = iconName;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return _extensionToIconName;
|
|
28
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { FileIconType, FileIconTypeInput } from './FileIconType';
|
|
2
|
+
import type { FileTypeIconSize, ImageFileType } from './constants';
|
|
3
|
+
/**
|
|
4
|
+
* The icon-identifying options shared by the `FileTypeIcon` component and the
|
|
5
|
+
* standalone resolvers: which icon (by `extension` or `type`), at what `size`,
|
|
6
|
+
* and in which image format.
|
|
7
|
+
*/
|
|
8
|
+
export interface FileTypeIconOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The file extension, such as `pptx`, for which an icon is needed. For file type icons
|
|
11
|
+
* that are not associated with a file extension, such as `folder`, use the `type` property.
|
|
12
|
+
*/
|
|
13
|
+
extension?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The type of file type icon needed. Use this for icons that are not associated with a
|
|
16
|
+
* file extension, such as `folder`.
|
|
17
|
+
*/
|
|
18
|
+
type?: FileIconTypeInput;
|
|
19
|
+
/**
|
|
20
|
+
* The size of the icon in pixels.
|
|
21
|
+
* @default 16
|
|
22
|
+
*/
|
|
23
|
+
size?: FileTypeIconSize;
|
|
24
|
+
/**
|
|
25
|
+
* The image format to use.
|
|
26
|
+
* @default 'svg'
|
|
27
|
+
*/
|
|
28
|
+
imageFileType?: ImageFileType;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolves the icon base name (e.g. `docx`) for the given file `extension` or
|
|
32
|
+
* {@link FileIconType}. Extension takes precedence over type; unknown or absent
|
|
33
|
+
* inputs fall back to the generic file icon.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getFileTypeIconNameFromExtensionOrType(extension: string | undefined, type: FileIconType | undefined): string;
|
|
36
|
+
/**
|
|
37
|
+
* Resolves the CDN-relative standard-density (1x) source URL for a file type icon.
|
|
38
|
+
*
|
|
39
|
+
* This is the deterministic, SSR-safe fallback used for the `<img src>` attribute. For
|
|
40
|
+
* device-pixel-ratio-aware selection, pair it with {@link getFileTypeIconSrcSet} on `srcset`.
|
|
41
|
+
*
|
|
42
|
+
* @param options - the file type icon options (extension/type, size, imageFileType)
|
|
43
|
+
* @param baseUrl - the base url to resolve the asset against. Defaults to the Fluent CDN.
|
|
44
|
+
* @returns the fully-qualified icon url.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getFileTypeIconSrc(options: FileTypeIconOptions, baseUrl?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the CDN-relative `srcset` for a file type icon: a comma-separated list of every
|
|
49
|
+
* published density variant with its `1x`/`1.5x`/… descriptor.
|
|
50
|
+
*
|
|
51
|
+
* Letting the browser pick the density (instead of reading `devicePixelRatio` in JS) keeps the
|
|
52
|
+
* rendered markup identical on the server and the client, avoiding hydration mismatches and the
|
|
53
|
+
* flicker/redundant-fetch of a post-mount density swap.
|
|
54
|
+
*
|
|
55
|
+
* @param options - the file type icon options (extension/type, size, imageFileType)
|
|
56
|
+
* @param baseUrl - the base url to resolve the assets against. Defaults to the Fluent CDN.
|
|
57
|
+
* @returns the `srcset` value, e.g. `…/24/docx.png 1x, …/24_1.5x/docx.png 1.5x, …`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getFileTypeIconSrcSet(options: FileTypeIconOptions, baseUrl?: string): string;
|