@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.
Files changed (52) hide show
  1. package/README.md +181 -0
  2. package/lib/FileTypeIcon.d.ts +16 -0
  3. package/lib/FileTypeIcon.js +19 -0
  4. package/lib/FileTypeIcon.styles.d.ts +7 -0
  5. package/lib/FileTypeIcon.styles.js +23 -0
  6. package/lib/common/FileIconType.d.ts +2 -0
  7. package/lib/common/FileIconType.js +5 -0
  8. package/lib/common/FileTypeIconsContext.d.ts +29 -0
  9. package/lib/common/FileTypeIconsContext.js +22 -0
  10. package/lib/common/constants.d.ts +22 -0
  11. package/lib/common/constants.js +18 -0
  12. package/lib/common/fileIconTypes.generated.d.ts +57 -0
  13. package/lib/common/fileIconTypes.generated.js +86 -0
  14. package/lib/common/fileTypeIconMap.generated.d.ts +7 -0
  15. package/lib/common/fileTypeIconMap.generated.js +28 -0
  16. package/lib/common/fileTypeIconResolver.d.ts +59 -0
  17. package/lib/common/fileTypeIconResolver.js +83 -0
  18. package/lib/common/useFileTypeIcon.d.ts +36 -0
  19. package/lib/common/useFileTypeIcon.js +90 -0
  20. package/lib/headless/FileTypeIcon.d.ts +20 -0
  21. package/lib/headless/FileTypeIcon.js +21 -0
  22. package/lib/headless/index.d.ts +8 -0
  23. package/lib/headless/index.js +8 -0
  24. package/lib/headless/styles.css +13 -0
  25. package/lib/index.d.ts +8 -0
  26. package/lib/index.js +4 -0
  27. package/lib-cjs/FileTypeIcon.d.ts +16 -0
  28. package/lib-cjs/FileTypeIcon.js +23 -0
  29. package/lib-cjs/FileTypeIcon.styles.d.ts +7 -0
  30. package/lib-cjs/FileTypeIcon.styles.js +27 -0
  31. package/lib-cjs/common/FileIconType.d.ts +2 -0
  32. package/lib-cjs/common/FileIconType.js +9 -0
  33. package/lib-cjs/common/FileTypeIconsContext.d.ts +29 -0
  34. package/lib-cjs/common/FileTypeIconsContext.js +28 -0
  35. package/lib-cjs/common/constants.d.ts +22 -0
  36. package/lib-cjs/common/constants.js +21 -0
  37. package/lib-cjs/common/fileIconTypes.generated.d.ts +57 -0
  38. package/lib-cjs/common/fileIconTypes.generated.js +89 -0
  39. package/lib-cjs/common/fileTypeIconMap.generated.d.ts +7 -0
  40. package/lib-cjs/common/fileTypeIconMap.generated.js +32 -0
  41. package/lib-cjs/common/fileTypeIconResolver.d.ts +59 -0
  42. package/lib-cjs/common/fileTypeIconResolver.js +89 -0
  43. package/lib-cjs/common/useFileTypeIcon.d.ts +36 -0
  44. package/lib-cjs/common/useFileTypeIcon.js +96 -0
  45. package/lib-cjs/headless/FileTypeIcon.d.ts +20 -0
  46. package/lib-cjs/headless/FileTypeIcon.js +28 -0
  47. package/lib-cjs/headless/index.d.ts +8 -0
  48. package/lib-cjs/headless/index.js +20 -0
  49. package/lib-cjs/headless/styles.css +13 -0
  50. package/lib-cjs/index.d.ts +8 -0
  51. package/lib-cjs/index.js +15 -0
  52. package/package.json +69 -0
@@ -0,0 +1,83 @@
1
+ import { getFileTypeIconExtensionMap } from './fileTypeIconMap.generated';
2
+ import { TYPE_TO_ICON_NAME } from './fileIconTypes.generated';
3
+ import { DEFAULT_BASE_URL, DEFAULT_ICON_SIZE } from './constants';
4
+ const GENERIC_FILE = 'genericfile';
5
+ /**
6
+ * Resolves the icon base name (e.g. `docx`) for the given file `extension` or
7
+ * {@link FileIconType}. Extension takes precedence over type; unknown or absent
8
+ * inputs fall back to the generic file icon.
9
+ */
10
+ export function getFileTypeIconNameFromExtensionOrType(extension, type) {
11
+ if (extension) {
12
+ // Strip periods, force lowercase.
13
+ extension = extension.replace('.', '').toLowerCase();
14
+ return getFileTypeIconExtensionMap()[extension] || GENERIC_FILE;
15
+ }
16
+ else if (type) {
17
+ return TYPE_TO_ICON_NAME[type] || GENERIC_FILE;
18
+ }
19
+ return GENERIC_FILE;
20
+ }
21
+ /**
22
+ * Enumerates the published pixel-density variants for a given `size`/`imageFileType`, ordered
23
+ * from lowest (`1x`) to highest. These feed an `<img srcset>` so the browser — not our JS —
24
+ * picks the right asset for the device pixel ratio. This keeps the markup deterministic across
25
+ * server and client (no hydration mismatch / no post-mount density swap), and lets the browser
26
+ * re-evaluate when a window moves to a display with a different DPI.
27
+ *
28
+ * The list honors the gaps in the published assets:
29
+ * - SVGs scale losslessly, so only the `1.5x` band has a dedicated asset (and size 20 has none).
30
+ * - PNGs publish a distinct asset per density bucket (`1.5x`/`2x`/`3x`/`4x`), except size 20 which
31
+ * has no `1.5x` asset.
32
+ */
33
+ function getFileTypeIconDensityVariants(size, imageFileType) {
34
+ // 1x is always available.
35
+ const variants = [{ descriptor: '1x', suffix: '' }];
36
+ if (imageFileType === 'svg') {
37
+ // SVGs scale, so the only extra asset is the 1.5x pixel-snapping band (absent at size 20).
38
+ if (size !== 20) {
39
+ variants.push({ descriptor: '1.5x', suffix: '_1.5x' });
40
+ }
41
+ return variants;
42
+ }
43
+ // PNGs need a distinct asset per density bucket (size 20 is missing the 1.5x asset).
44
+ if (size !== 20) {
45
+ variants.push({ descriptor: '1.5x', suffix: '_1.5x' });
46
+ }
47
+ variants.push({ descriptor: '2x', suffix: '_2x' }, { descriptor: '3x', suffix: '_3x' }, { descriptor: '4x', suffix: '_4x' });
48
+ return variants;
49
+ }
50
+ /**
51
+ * Resolves the CDN-relative standard-density (1x) source URL for a file type icon.
52
+ *
53
+ * This is the deterministic, SSR-safe fallback used for the `<img src>` attribute. For
54
+ * device-pixel-ratio-aware selection, pair it with {@link getFileTypeIconSrcSet} on `srcset`.
55
+ *
56
+ * @param options - the file type icon options (extension/type, size, imageFileType)
57
+ * @param baseUrl - the base url to resolve the asset against. Defaults to the Fluent CDN.
58
+ * @returns the fully-qualified icon url.
59
+ */
60
+ export function getFileTypeIconSrc(options, baseUrl = DEFAULT_BASE_URL) {
61
+ const { extension, size = DEFAULT_ICON_SIZE, type, imageFileType = 'svg' } = options;
62
+ const baseIconName = getFileTypeIconNameFromExtensionOrType(extension, type); // eg: docx
63
+ return `${baseUrl}${size}/${baseIconName}.${imageFileType}`;
64
+ }
65
+ /**
66
+ * Resolves the CDN-relative `srcset` for a file type icon: a comma-separated list of every
67
+ * published density variant with its `1x`/`1.5x`/… descriptor.
68
+ *
69
+ * Letting the browser pick the density (instead of reading `devicePixelRatio` in JS) keeps the
70
+ * rendered markup identical on the server and the client, avoiding hydration mismatches and the
71
+ * flicker/redundant-fetch of a post-mount density swap.
72
+ *
73
+ * @param options - the file type icon options (extension/type, size, imageFileType)
74
+ * @param baseUrl - the base url to resolve the assets against. Defaults to the Fluent CDN.
75
+ * @returns the `srcset` value, e.g. `…/24/docx.png 1x, …/24_1.5x/docx.png 1.5x, …`.
76
+ */
77
+ export function getFileTypeIconSrcSet(options, baseUrl = DEFAULT_BASE_URL) {
78
+ const { extension, size = DEFAULT_ICON_SIZE, type, imageFileType = 'svg' } = options;
79
+ const baseIconName = getFileTypeIconNameFromExtensionOrType(extension, type); // eg: docx
80
+ return getFileTypeIconDensityVariants(size, imageFileType)
81
+ .map(({ descriptor, suffix }) => `${baseUrl}${size}${suffix}/${baseIconName}.${imageFileType} ${descriptor}`)
82
+ .join(', ');
83
+ }
@@ -0,0 +1,36 @@
1
+ import * as React from 'react';
2
+ import type { FileTypeIconOptions } from './fileTypeIconResolver';
3
+ export interface FileTypeIconProps extends FileTypeIconOptions, Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'src' | 'width' | 'height'> {
4
+ }
5
+ /**
6
+ * Data attribute set on the rendered `<img>`. It is the styling hook targeted by the
7
+ * opt-in `@fluentui/react-icons-file-type/headless/styles.css` (or by a consumer's own
8
+ * CSS). The attribute is inert until such CSS is loaded, so it is harmless for the default
9
+ * (Griffel-styled) entry point.
10
+ */
11
+ export declare const fileTypeIconDataAttribute = "data-fui-filetype-icon";
12
+ /**
13
+ * The resolved `<img>` props produced by {@link useFileTypeIcon} and consumed by
14
+ * {@link renderFileTypeIcon}. Following the Fluent v9 pattern, the state is a plain,
15
+ * mutable bag of slot props so a style hook (e.g. `useFileTypeIconStyles`) can layer
16
+ * additional classes on top before rendering.
17
+ */
18
+ export interface FileTypeIconState extends React.ImgHTMLAttributes<HTMLImageElement> {
19
+ src: string;
20
+ 'data-fui-filetype-icon': '';
21
+ }
22
+ /**
23
+ * State hook: resolves {@link FileTypeIconProps} into the {@link FileTypeIconState} `<img>`
24
+ * props. This is the shared core used by both the headless and the Griffel-styled
25
+ * `FileTypeIcon` components — the latter runs a style hook over the returned state before
26
+ * rendering.
27
+ *
28
+ * The asset host is resolved from the nearest `FileTypeIconsProvider`, falling back to the
29
+ * Fluent CDN default when no provider is present.
30
+ */
31
+ export declare function useFileTypeIcon(props: FileTypeIconProps): FileTypeIconState;
32
+ /**
33
+ * Render hook: turns a resolved {@link FileTypeIconState} into the `<img>` element. Returns
34
+ * `null` when there is no resolvable `src`.
35
+ */
36
+ export declare function renderFileTypeIcon(state: FileTypeIconState): React.ReactElement | null;
@@ -0,0 +1,90 @@
1
+ import * as React from 'react';
2
+ import { getFileTypeIconSrc, getFileTypeIconSrcSet } from './fileTypeIconResolver';
3
+ import { useFileTypeIconsContext } from './FileTypeIconsContext';
4
+ import { DEFAULT_ICON_SIZE } from './constants';
5
+ /**
6
+ * Data attribute set on the rendered `<img>`. It is the styling hook targeted by the
7
+ * opt-in `@fluentui/react-icons-file-type/headless/styles.css` (or by a consumer's own
8
+ * CSS). The attribute is inert until such CSS is loaded, so it is harmless for the default
9
+ * (Griffel-styled) entry point.
10
+ */
11
+ export const fileTypeIconDataAttribute = 'data-fui-filetype-icon';
12
+ /**
13
+ * Resolves the accessibility attributes for the rendered `<img>`.
14
+ *
15
+ * The icon is considered *labelled* when it has an accessible name — a non-empty `alt`
16
+ * (or `extension` fallback), an `aria-label`, an `aria-labelledby`, or the native `title`
17
+ * tooltip. Otherwise it is treated as purely decorative.
18
+ *
19
+ * Notes:
20
+ * - `role` is intentionally omitted. A native `<img>` already exposes the implicit `img`
21
+ * role when it has an accessible name, so setting `role="img"` would be redundant.
22
+ * - We do NOT mirror the `title` -> `aria-label` mapping used for SVG icons (see
23
+ * `useIconState` in `@fluentui/react-icons`). That mapping is an SVG-specific workaround
24
+ * because SVG `<title>` is a child element, not an attribute. On a native `<img>`, `title`
25
+ * is a real HTML attribute that both renders a tooltip and participates in the accessible
26
+ * name computation (priority: `aria-labelledby` > `aria-label` > `alt` > `title`).
27
+ * - When labelled by `aria-*` or `title`, we omit `alt` entirely rather than emit `alt=""`.
28
+ * An empty `alt` forces the decorative (`presentation`) role and suppresses those name
29
+ * sources, which would hide the icon from assistive technologies.
30
+ * - For truly decorative icons we emit `alt=""` (the spec-defined decorative opt-out) and
31
+ * additionally set `aria-hidden` as a defensive guard against browser auto-labelling
32
+ * heuristics (e.g. generated image descriptions) that could otherwise surface the image
33
+ * to assistive technologies.
34
+ */
35
+ function getImageA11yProps(props) {
36
+ var _a;
37
+ const resolvedAlt = (_a = props.alt) !== null && _a !== void 0 ? _a : props.extension;
38
+ // Labelled by alt/extension -> use it as the accessible name.
39
+ if (resolvedAlt) {
40
+ return { alt: resolvedAlt };
41
+ }
42
+ // Labelled by aria-* or the native title tooltip -> keep the icon in the a11y tree and
43
+ // omit alt so those sources can supply the accessible name (alt="" would force a
44
+ // decorative role and suppress them).
45
+ if (props['aria-label'] || props['aria-labelledby'] || props.title) {
46
+ return {};
47
+ }
48
+ // Truly decorative -> spec-defined opt-out plus defensive guard against auto-labelling.
49
+ return { alt: '', 'aria-hidden': true };
50
+ }
51
+ /**
52
+ * State hook: resolves {@link FileTypeIconProps} into the {@link FileTypeIconState} `<img>`
53
+ * props. This is the shared core used by both the headless and the Griffel-styled
54
+ * `FileTypeIcon` components — the latter runs a style hook over the returned state before
55
+ * rendering.
56
+ *
57
+ * The asset host is resolved from the nearest `FileTypeIconsProvider`, falling back to the
58
+ * Fluent CDN default when no provider is present.
59
+ */
60
+ export function useFileTypeIcon(props) {
61
+ const { extension, type, size = DEFAULT_ICON_SIZE, imageFileType, className, ...imgProps } = props;
62
+ const { baseUrl } = useFileTypeIconsContext();
63
+ const iconOptions = { extension, type, size, imageFileType };
64
+ // `src` is the deterministic 1x fallback; `srcset` lets the browser pick the right density for
65
+ // the device pixel ratio. Resolving density in the browser (rather than from `devicePixelRatio`
66
+ // in JS) keeps server and client markup identical — no hydration mismatch, no post-mount swap.
67
+ const src = getFileTypeIconSrc(iconOptions, baseUrl);
68
+ const srcSet = getFileTypeIconSrcSet(iconOptions, baseUrl);
69
+ const a11yProps = getImageA11yProps(props);
70
+ return {
71
+ ...imgProps,
72
+ ...a11yProps,
73
+ src,
74
+ srcSet,
75
+ width: size,
76
+ height: size,
77
+ className,
78
+ [fileTypeIconDataAttribute]: '',
79
+ };
80
+ }
81
+ /**
82
+ * Render hook: turns a resolved {@link FileTypeIconState} into the `<img>` element. Returns
83
+ * `null` when there is no resolvable `src`.
84
+ */
85
+ export function renderFileTypeIcon(state) {
86
+ if (!state.src) {
87
+ return null;
88
+ }
89
+ return React.createElement("img", { ...state });
90
+ }
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ import type { FileTypeIconProps } from '../common/useFileTypeIcon';
3
+ export type { FileTypeIconProps, FileTypeIconState } from '../common/useFileTypeIcon';
4
+ export { fileTypeIconDataAttribute, useFileTypeIcon, renderFileTypeIcon } from '../common/useFileTypeIcon';
5
+ /**
6
+ * Headless (Griffel-free) file type icon. Renders an `<img>` sourced from CDN-hosted assets
7
+ * and tagged with the `fileTypeIconDataAttribute` styling hook, but ships **no** styling
8
+ * runtime — bring your own styles via `@fluentui/react-icons-file-type/headless/styles.css`, a
9
+ * `className`, or your own CSS targeting `[data-fui-filetype-icon]`.
10
+ *
11
+ * It composes the shared {@link useFileTypeIcon} (state) and {@link renderFileTypeIcon} (render)
12
+ * hooks; the default Griffel-styled entry point reuses the same hooks with an extra style hook.
13
+ *
14
+ * The asset host is resolved from the nearest `FileTypeIconsProvider`, falling back to the
15
+ * Fluent CDN default when no provider is present.
16
+ *
17
+ * Prefer the default `@fluentui/react-icons-file-type` entry point unless you specifically
18
+ * want to avoid the Griffel runtime.
19
+ */
20
+ export declare const FileTypeIcon: React.FC<FileTypeIconProps>;
@@ -0,0 +1,21 @@
1
+ import { useFileTypeIcon, renderFileTypeIcon } from '../common/useFileTypeIcon';
2
+ export { fileTypeIconDataAttribute, useFileTypeIcon, renderFileTypeIcon } from '../common/useFileTypeIcon';
3
+ /**
4
+ * Headless (Griffel-free) file type icon. Renders an `<img>` sourced from CDN-hosted assets
5
+ * and tagged with the `fileTypeIconDataAttribute` styling hook, but ships **no** styling
6
+ * runtime — bring your own styles via `@fluentui/react-icons-file-type/headless/styles.css`, a
7
+ * `className`, or your own CSS targeting `[data-fui-filetype-icon]`.
8
+ *
9
+ * It composes the shared {@link useFileTypeIcon} (state) and {@link renderFileTypeIcon} (render)
10
+ * hooks; the default Griffel-styled entry point reuses the same hooks with an extra style hook.
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
+ * Prefer the default `@fluentui/react-icons-file-type` entry point unless you specifically
16
+ * want to avoid the Griffel runtime.
17
+ */
18
+ export const FileTypeIcon = (props) => {
19
+ const state = useFileTypeIcon(props);
20
+ return renderFileTypeIcon(state);
21
+ };
@@ -0,0 +1,8 @@
1
+ export { FileTypeIcon, fileTypeIconDataAttribute } from './FileTypeIcon';
2
+ export type { FileTypeIconProps } from './FileTypeIcon';
3
+ export { FileTypeIconsProvider, useFileTypeIconsContext } from '../common/FileTypeIconsContext';
4
+ export type { FileTypeIconsContextValue, FileTypeIconsProviderProps } from '../common/FileTypeIconsContext';
5
+ export { FileIconType } from '../common/FileIconType';
6
+ export type { FileIconTypeInput } from '../common/FileIconType';
7
+ export { DEFAULT_BASE_URL, FLUENT_CDN_BASE_URL, DEFAULT_ICON_SIZE, ICON_SIZES } from '../common/constants';
8
+ export type { FileTypeIconSize, ImageFileType } from '../common/constants';
@@ -0,0 +1,8 @@
1
+ // Headless (Griffel-free) entry point for `@fluentui/react-icons-file-type/headless`.
2
+ // Re-exports the styling-runtime-free `FileTypeIcon` plus the shared, framework-agnostic
3
+ // pieces (provider, context, `FileIconType`, constants) so this subpath is fully usable
4
+ // without pulling in `@griffel/react`.
5
+ export { FileTypeIcon, fileTypeIconDataAttribute } from './FileTypeIcon';
6
+ export { FileTypeIconsProvider, useFileTypeIconsContext } from '../common/FileTypeIconsContext';
7
+ export { FileIconType } from '../common/FileIconType';
8
+ export { DEFAULT_BASE_URL, FLUENT_CDN_BASE_URL, DEFAULT_ICON_SIZE, ICON_SIZES } from '../common/constants';
@@ -0,0 +1,13 @@
1
+ /*
2
+ * Opt-in static styles for the headless `FileTypeIcon` from
3
+ * `@fluentui/react-icons-file-type/headless`. Import this file once in your app to reproduce
4
+ * the default (Griffel) box behavior without the CSS-in-JS runtime:
5
+ *
6
+ * import '@fluentui/react-icons-file-type/headless/styles.css';
7
+ *
8
+ * Or skip it and target `[data-fui-filetype-icon]` (or a `className`) with your own CSS.
9
+ */
10
+ [data-fui-filetype-icon] {
11
+ display: inline-block;
12
+ object-fit: contain;
13
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { FileTypeIcon } from './FileTypeIcon';
2
+ export type { FileTypeIconProps } from './FileTypeIcon';
3
+ export { FileTypeIconsProvider, useFileTypeIconsContext } from './common/FileTypeIconsContext';
4
+ export type { FileTypeIconsContextValue, FileTypeIconsProviderProps } from './common/FileTypeIconsContext';
5
+ export { FileIconType } from './common/FileIconType';
6
+ export type { FileIconTypeInput } from './common/FileIconType';
7
+ export { DEFAULT_BASE_URL, FLUENT_CDN_BASE_URL, DEFAULT_ICON_SIZE, ICON_SIZES } from './common/constants';
8
+ export type { FileTypeIconSize, ImageFileType } from './common/constants';
package/lib/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { FileTypeIcon } from './FileTypeIcon';
2
+ export { FileTypeIconsProvider, useFileTypeIconsContext } from './common/FileTypeIconsContext';
3
+ export { FileIconType } from './common/FileIconType';
4
+ export { DEFAULT_BASE_URL, FLUENT_CDN_BASE_URL, DEFAULT_ICON_SIZE, ICON_SIZES } from './common/constants';
@@ -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,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileTypeIcon = void 0;
4
+ const useFileTypeIcon_1 = require("./common/useFileTypeIcon");
5
+ const FileTypeIcon_styles_1 = require("./FileTypeIcon.styles");
6
+ /**
7
+ * Renders a file type icon as an `<img>` sourced from CDN-hosted assets, styled with Griffel
8
+ * (zero setup required). This is the default entry point.
9
+ *
10
+ * It composes the same state ({@link useFileTypeIcon}) and render ({@link renderFileTypeIcon})
11
+ * hooks as the headless `FileTypeIcon`, inserting a Griffel style hook in between to layer the
12
+ * static styles. To avoid the Griffel runtime, import from the `/headless` subpath and provide
13
+ * your own styles (see `headless/styles.css`).
14
+ *
15
+ * The asset host is resolved from the nearest `FileTypeIconsProvider`, falling back to the
16
+ * Fluent CDN default when no provider is present.
17
+ */
18
+ const FileTypeIcon = (props) => {
19
+ const state = (0, useFileTypeIcon_1.useFileTypeIcon)(props);
20
+ (0, FileTypeIcon_styles_1.useFileTypeIconStyles)(state);
21
+ return (0, useFileTypeIcon_1.renderFileTypeIcon)(state);
22
+ };
23
+ exports.FileTypeIcon = FileTypeIcon;
@@ -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,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFileTypeIconStyles = void 0;
4
+ const react_1 = require("@griffel/react");
5
+ /**
6
+ * Static styles for the `FileTypeIcon` image. `object-fit: contain` keeps non-square assets
7
+ * from being stretched within the square `width`/`height` box (both applied inline by the
8
+ * state hook from the `size` prop). `object-fit` only affects replaced elements, so these
9
+ * styles must live on the `<img>` itself, not on a wrapper.
10
+ */
11
+ const useStyles = (0, react_1.makeStyles)({
12
+ root: {
13
+ display: 'inline-block',
14
+ objectFit: 'contain',
15
+ },
16
+ });
17
+ /**
18
+ * Style hook: layers the Griffel `root` class onto a resolved {@link FileTypeIconState},
19
+ * merging ahead of any consumer-provided `className`. Mutates and returns the same state,
20
+ * following the Fluent v9 style-hook convention.
21
+ */
22
+ function useFileTypeIconStyles(state) {
23
+ const styles = useStyles();
24
+ state.className = (0, react_1.mergeClasses)(styles.root, state.className);
25
+ return state;
26
+ }
27
+ exports.useFileTypeIconStyles = useFileTypeIconStyles;
@@ -0,0 +1,2 @@
1
+ export { FileIconType } from './fileIconTypes.generated';
2
+ export type { FileIconTypeInput } from './fileIconTypes.generated';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileIconType = void 0;
4
+ // Public, stable module path for the file type icon enum. The actual definitions are
5
+ // generated from `fileIconTypes.json` into `fileIconTypes.generated.ts` (run `npm run
6
+ // generate`); this barrel re-exports the public surface so consumers and internal code
7
+ // import from a hand-written path rather than the generated artifact.
8
+ var fileIconTypes_generated_1 = require("./fileIconTypes.generated");
9
+ Object.defineProperty(exports, "FileIconType", { enumerable: true, get: function () { return fileIconTypes_generated_1.FileIconType; } });
@@ -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,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFileTypeIconsContext = exports.FileTypeIconsProvider = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ const constants_1 = require("./constants");
7
+ const FileTypeIconsContext = React.createContext(undefined);
8
+ /**
9
+ * Provides the `baseUrl` used by descendant `FileTypeIcon` components to resolve
10
+ * their CDN-hosted assets. Omitting `baseUrl` falls back to the Fluent CDN, mirroring
11
+ * the zero-configuration ergonomics of the legacy `initializeFileTypeIcons` default
12
+ * without hardcoding the CDN inside the icon component itself.
13
+ */
14
+ const FileTypeIconsProvider = (props) => {
15
+ const { baseUrl = constants_1.DEFAULT_BASE_URL, children } = props;
16
+ const value = React.useMemo(() => ({ baseUrl }), [baseUrl]);
17
+ return React.createElement(FileTypeIconsContext.Provider, { value: value }, children);
18
+ };
19
+ exports.FileTypeIconsProvider = FileTypeIconsProvider;
20
+ /**
21
+ * Returns the current `FileTypeIcons` context value. When no provider is present, the
22
+ * default Fluent CDN `baseUrl` is returned so icons render without explicit setup.
23
+ */
24
+ const useFileTypeIconsContext = () => {
25
+ const context = React.useContext(FileTypeIconsContext);
26
+ return context !== null && context !== void 0 ? context : { baseUrl: constants_1.DEFAULT_BASE_URL };
27
+ };
28
+ exports.useFileTypeIconsContext = useFileTypeIconsContext;
@@ -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,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_ICON_SIZE = exports.ICON_SIZES = exports.DEFAULT_BASE_URL = exports.FLUENT_CDN_BASE_URL = void 0;
4
+ /**
5
+ * Base URL of the Microsoft Fluent CDN that hosts the file type icon assets.
6
+ *
7
+ * NOTE: this value is intentionally version-stamped by the CDN. It is provided as a
8
+ * sensible, overridable default so consumers do not need to configure a CDN to get
9
+ * started. To use your own asset host, supply a `baseUrl` to `FileTypeIconsProvider`
10
+ * (or to the individual helper functions / the `baseUrl` prop on `FileTypeIcon`).
11
+ */
12
+ exports.FLUENT_CDN_BASE_URL = 'https://res.cdn.office.net/files/fabric-cdn-prod_20260623.001';
13
+ /**
14
+ * Default base URL used to resolve file type icon assets when no `baseUrl` is provided.
15
+ * Points at the `item-types` asset folder on the Fluent CDN.
16
+ */
17
+ exports.DEFAULT_BASE_URL = `${exports.FLUENT_CDN_BASE_URL}/assets/item-types/`;
18
+ /** The set of pixel sizes for which file type icon assets are published. */
19
+ exports.ICON_SIZES = [16, 20, 24, 32, 40, 48, 64, 96];
20
+ /** The default icon size in pixels. */
21
+ exports.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,89 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT license.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.TYPE_TO_ICON_NAME = exports.FileIconType = void 0;
6
+ // AUTO-GENERATED by scripts/generateFileIconTypes.js from src/common/fileIconTypes.json.
7
+ // Do not edit this file manually. Run `npm run generate` to regenerate it.
8
+ /**
9
+ * Enumerates special file type icons that do not map to any file extensions.
10
+ * For example, the 'pptx' icon maps to the extensions 'ppt', 'pptm', 'pptx',
11
+ * but the 'folder' icon does not map to any extensions and should be obtained
12
+ * via this enum.
13
+ *
14
+ * Implemented as a `const` object (rather than a TypeScript `enum`) so it does not
15
+ * emit a runtime reverse-mapping. The merged `FileIconType` type below lets it be
16
+ * used as both a value (`FileIconType.folder`) and a type (`type: FileIconType`),
17
+ * preserving the ergonomics of the previous `enum`. Values start at 1 so they evaluate
18
+ * as truthy.
19
+ */
20
+ exports.FileIconType = {
21
+ docset: 1,
22
+ folder: 2,
23
+ genericFile: 3,
24
+ listItem: 4,
25
+ sharedFolder: 5,
26
+ multiple: 6,
27
+ stream: 7,
28
+ news: 8,
29
+ desktopFolder: 9,
30
+ documentsFolder: 10,
31
+ picturesFolder: 11,
32
+ linkedFolder: 12,
33
+ list: 13,
34
+ form: 14,
35
+ sway: 15,
36
+ playlist: 16,
37
+ loopworkspace: 17,
38
+ planner: 18,
39
+ todoItem: 19,
40
+ portfolio: 20,
41
+ album: 21,
42
+ listForm: 22,
43
+ campaign: 23,
44
+ shortcutsdefaultfolder: 24,
45
+ pbiApp: 25,
46
+ pbiDashboard: 26,
47
+ pbiPaginatedReport: 27,
48
+ pbiScorecard: 28,
49
+ pbiSemanticModel: 29,
50
+ pbiReport: 30,
51
+ };
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
+ exports.TYPE_TO_ICON_NAME = [
58
+ '',
59
+ 'docset',
60
+ 'folder',
61
+ '',
62
+ 'listitem',
63
+ 'sharedfolder',
64
+ 'multiple',
65
+ 'video',
66
+ 'sponews',
67
+ 'desktopfolder',
68
+ 'documentsfolder',
69
+ 'picturesfolder',
70
+ 'linkedfolder',
71
+ 'splist',
72
+ 'form',
73
+ 'sway',
74
+ 'playlist',
75
+ 'loopworkspace',
76
+ 'planner',
77
+ 'todoitem',
78
+ 'portfolio',
79
+ 'album',
80
+ 'listform',
81
+ 'spocampaign',
82
+ 'companyfolder',
83
+ 'pbiapp',
84
+ 'pbidashboard',
85
+ 'pbipagereport',
86
+ 'pbiscorecard',
87
+ 'pbisemmodel',
88
+ 'powerbi', // 30 pbiReport
89
+ ];