@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,7 @@
1
+ /**
2
+ * Returns the `extension`->`icon name` lookup table, decoding the packed
3
+ * string on first use and caching the result for subsequent calls.
4
+ */
5
+ export declare function getFileTypeIconExtensionMap(): Readonly<{
6
+ [extension: string]: string;
7
+ }>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT license.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.getFileTypeIconExtensionMap = void 0;
6
+ // AUTO-GENERATED by scripts/generateFileTypeIconMap.js from src/common/fileTypeIconMap.json.
7
+ // Do not edit this file manually. Run `npm run generate` to regenerate it.
8
+ /**
9
+ * Minimal packed `icon name`->`extensions` table.
10
+ *
11
+ * Format: `icon:ext,ext;icon:ext`. Decoded lazily into an
12
+ * `extension -> icon name` lookup by {@link getFileTypeIconExtensionMap}.
13
+ */
14
+ 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';
15
+ let _extensionToIconName;
16
+ /**
17
+ * Returns the `extension`->`icon name` lookup table, decoding the packed
18
+ * string on first use and caching the result for subsequent calls.
19
+ */
20
+ function getFileTypeIconExtensionMap() {
21
+ if (!_extensionToIconName) {
22
+ _extensionToIconName = {};
23
+ for (const group of PACKED_FILE_TYPE_ICON_MAP.split(';')) {
24
+ const [iconName, extensions] = group.split(':');
25
+ for (const extension of extensions.split(',')) {
26
+ _extensionToIconName[extension] = iconName;
27
+ }
28
+ }
29
+ }
30
+ return _extensionToIconName;
31
+ }
32
+ exports.getFileTypeIconExtensionMap = getFileTypeIconExtensionMap;
@@ -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;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFileTypeIconSrcSet = exports.getFileTypeIconSrc = exports.getFileTypeIconNameFromExtensionOrType = void 0;
4
+ const fileTypeIconMap_generated_1 = require("./fileTypeIconMap.generated");
5
+ const fileIconTypes_generated_1 = require("./fileIconTypes.generated");
6
+ const constants_1 = require("./constants");
7
+ const GENERIC_FILE = 'genericfile';
8
+ /**
9
+ * Resolves the icon base name (e.g. `docx`) for the given file `extension` or
10
+ * {@link FileIconType}. Extension takes precedence over type; unknown or absent
11
+ * inputs fall back to the generic file icon.
12
+ */
13
+ function getFileTypeIconNameFromExtensionOrType(extension, type) {
14
+ if (extension) {
15
+ // Strip periods, force lowercase.
16
+ extension = extension.replace('.', '').toLowerCase();
17
+ return (0, fileTypeIconMap_generated_1.getFileTypeIconExtensionMap)()[extension] || GENERIC_FILE;
18
+ }
19
+ else if (type) {
20
+ return fileIconTypes_generated_1.TYPE_TO_ICON_NAME[type] || GENERIC_FILE;
21
+ }
22
+ return GENERIC_FILE;
23
+ }
24
+ exports.getFileTypeIconNameFromExtensionOrType = getFileTypeIconNameFromExtensionOrType;
25
+ /**
26
+ * Enumerates the published pixel-density variants for a given `size`/`imageFileType`, ordered
27
+ * from lowest (`1x`) to highest. These feed an `<img srcset>` so the browser — not our JS —
28
+ * picks the right asset for the device pixel ratio. This keeps the markup deterministic across
29
+ * server and client (no hydration mismatch / no post-mount density swap), and lets the browser
30
+ * re-evaluate when a window moves to a display with a different DPI.
31
+ *
32
+ * The list honors the gaps in the published assets:
33
+ * - SVGs scale losslessly, so only the `1.5x` band has a dedicated asset (and size 20 has none).
34
+ * - PNGs publish a distinct asset per density bucket (`1.5x`/`2x`/`3x`/`4x`), except size 20 which
35
+ * has no `1.5x` asset.
36
+ */
37
+ function getFileTypeIconDensityVariants(size, imageFileType) {
38
+ // 1x is always available.
39
+ const variants = [{ descriptor: '1x', suffix: '' }];
40
+ if (imageFileType === 'svg') {
41
+ // SVGs scale, so the only extra asset is the 1.5x pixel-snapping band (absent at size 20).
42
+ if (size !== 20) {
43
+ variants.push({ descriptor: '1.5x', suffix: '_1.5x' });
44
+ }
45
+ return variants;
46
+ }
47
+ // PNGs need a distinct asset per density bucket (size 20 is missing the 1.5x asset).
48
+ if (size !== 20) {
49
+ variants.push({ descriptor: '1.5x', suffix: '_1.5x' });
50
+ }
51
+ variants.push({ descriptor: '2x', suffix: '_2x' }, { descriptor: '3x', suffix: '_3x' }, { descriptor: '4x', suffix: '_4x' });
52
+ return variants;
53
+ }
54
+ /**
55
+ * Resolves the CDN-relative standard-density (1x) source URL for a file type icon.
56
+ *
57
+ * This is the deterministic, SSR-safe fallback used for the `<img src>` attribute. For
58
+ * device-pixel-ratio-aware selection, pair it with {@link getFileTypeIconSrcSet} on `srcset`.
59
+ *
60
+ * @param options - the file type icon options (extension/type, size, imageFileType)
61
+ * @param baseUrl - the base url to resolve the asset against. Defaults to the Fluent CDN.
62
+ * @returns the fully-qualified icon url.
63
+ */
64
+ function getFileTypeIconSrc(options, baseUrl = constants_1.DEFAULT_BASE_URL) {
65
+ const { extension, size = constants_1.DEFAULT_ICON_SIZE, type, imageFileType = 'svg' } = options;
66
+ const baseIconName = getFileTypeIconNameFromExtensionOrType(extension, type); // eg: docx
67
+ return `${baseUrl}${size}/${baseIconName}.${imageFileType}`;
68
+ }
69
+ exports.getFileTypeIconSrc = getFileTypeIconSrc;
70
+ /**
71
+ * Resolves the CDN-relative `srcset` for a file type icon: a comma-separated list of every
72
+ * published density variant with its `1x`/`1.5x`/… descriptor.
73
+ *
74
+ * Letting the browser pick the density (instead of reading `devicePixelRatio` in JS) keeps the
75
+ * rendered markup identical on the server and the client, avoiding hydration mismatches and the
76
+ * flicker/redundant-fetch of a post-mount density swap.
77
+ *
78
+ * @param options - the file type icon options (extension/type, size, imageFileType)
79
+ * @param baseUrl - the base url to resolve the assets against. Defaults to the Fluent CDN.
80
+ * @returns the `srcset` value, e.g. `…/24/docx.png 1x, …/24_1.5x/docx.png 1.5x, …`.
81
+ */
82
+ function getFileTypeIconSrcSet(options, baseUrl = constants_1.DEFAULT_BASE_URL) {
83
+ const { extension, size = constants_1.DEFAULT_ICON_SIZE, type, imageFileType = 'svg' } = options;
84
+ const baseIconName = getFileTypeIconNameFromExtensionOrType(extension, type); // eg: docx
85
+ return getFileTypeIconDensityVariants(size, imageFileType)
86
+ .map(({ descriptor, suffix }) => `${baseUrl}${size}${suffix}/${baseIconName}.${imageFileType} ${descriptor}`)
87
+ .join(', ');
88
+ }
89
+ exports.getFileTypeIconSrcSet = getFileTypeIconSrcSet;
@@ -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,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderFileTypeIcon = exports.useFileTypeIcon = exports.fileTypeIconDataAttribute = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ const fileTypeIconResolver_1 = require("./fileTypeIconResolver");
7
+ const FileTypeIconsContext_1 = require("./FileTypeIconsContext");
8
+ const constants_1 = require("./constants");
9
+ /**
10
+ * Data attribute set on the rendered `<img>`. It is the styling hook targeted by the
11
+ * opt-in `@fluentui/react-icons-file-type/headless/styles.css` (or by a consumer's own
12
+ * CSS). The attribute is inert until such CSS is loaded, so it is harmless for the default
13
+ * (Griffel-styled) entry point.
14
+ */
15
+ exports.fileTypeIconDataAttribute = 'data-fui-filetype-icon';
16
+ /**
17
+ * Resolves the accessibility attributes for the rendered `<img>`.
18
+ *
19
+ * The icon is considered *labelled* when it has an accessible name — a non-empty `alt`
20
+ * (or `extension` fallback), an `aria-label`, an `aria-labelledby`, or the native `title`
21
+ * tooltip. Otherwise it is treated as purely decorative.
22
+ *
23
+ * Notes:
24
+ * - `role` is intentionally omitted. A native `<img>` already exposes the implicit `img`
25
+ * role when it has an accessible name, so setting `role="img"` would be redundant.
26
+ * - We do NOT mirror the `title` -> `aria-label` mapping used for SVG icons (see
27
+ * `useIconState` in `@fluentui/react-icons`). That mapping is an SVG-specific workaround
28
+ * because SVG `<title>` is a child element, not an attribute. On a native `<img>`, `title`
29
+ * is a real HTML attribute that both renders a tooltip and participates in the accessible
30
+ * name computation (priority: `aria-labelledby` > `aria-label` > `alt` > `title`).
31
+ * - When labelled by `aria-*` or `title`, we omit `alt` entirely rather than emit `alt=""`.
32
+ * An empty `alt` forces the decorative (`presentation`) role and suppresses those name
33
+ * sources, which would hide the icon from assistive technologies.
34
+ * - For truly decorative icons we emit `alt=""` (the spec-defined decorative opt-out) and
35
+ * additionally set `aria-hidden` as a defensive guard against browser auto-labelling
36
+ * heuristics (e.g. generated image descriptions) that could otherwise surface the image
37
+ * to assistive technologies.
38
+ */
39
+ function getImageA11yProps(props) {
40
+ var _a;
41
+ const resolvedAlt = (_a = props.alt) !== null && _a !== void 0 ? _a : props.extension;
42
+ // Labelled by alt/extension -> use it as the accessible name.
43
+ if (resolvedAlt) {
44
+ return { alt: resolvedAlt };
45
+ }
46
+ // Labelled by aria-* or the native title tooltip -> keep the icon in the a11y tree and
47
+ // omit alt so those sources can supply the accessible name (alt="" would force a
48
+ // decorative role and suppress them).
49
+ if (props['aria-label'] || props['aria-labelledby'] || props.title) {
50
+ return {};
51
+ }
52
+ // Truly decorative -> spec-defined opt-out plus defensive guard against auto-labelling.
53
+ return { alt: '', 'aria-hidden': true };
54
+ }
55
+ /**
56
+ * State hook: resolves {@link FileTypeIconProps} into the {@link FileTypeIconState} `<img>`
57
+ * props. This is the shared core used by both the headless and the Griffel-styled
58
+ * `FileTypeIcon` components — the latter runs a style hook over the returned state before
59
+ * rendering.
60
+ *
61
+ * The asset host is resolved from the nearest `FileTypeIconsProvider`, falling back to the
62
+ * Fluent CDN default when no provider is present.
63
+ */
64
+ function useFileTypeIcon(props) {
65
+ const { extension, type, size = constants_1.DEFAULT_ICON_SIZE, imageFileType, className, ...imgProps } = props;
66
+ const { baseUrl } = (0, FileTypeIconsContext_1.useFileTypeIconsContext)();
67
+ const iconOptions = { extension, type, size, imageFileType };
68
+ // `src` is the deterministic 1x fallback; `srcset` lets the browser pick the right density for
69
+ // the device pixel ratio. Resolving density in the browser (rather than from `devicePixelRatio`
70
+ // in JS) keeps server and client markup identical — no hydration mismatch, no post-mount swap.
71
+ const src = (0, fileTypeIconResolver_1.getFileTypeIconSrc)(iconOptions, baseUrl);
72
+ const srcSet = (0, fileTypeIconResolver_1.getFileTypeIconSrcSet)(iconOptions, baseUrl);
73
+ const a11yProps = getImageA11yProps(props);
74
+ return {
75
+ ...imgProps,
76
+ ...a11yProps,
77
+ src,
78
+ srcSet,
79
+ width: size,
80
+ height: size,
81
+ className,
82
+ [exports.fileTypeIconDataAttribute]: '',
83
+ };
84
+ }
85
+ exports.useFileTypeIcon = useFileTypeIcon;
86
+ /**
87
+ * Render hook: turns a resolved {@link FileTypeIconState} into the `<img>` element. Returns
88
+ * `null` when there is no resolvable `src`.
89
+ */
90
+ function renderFileTypeIcon(state) {
91
+ if (!state.src) {
92
+ return null;
93
+ }
94
+ return React.createElement("img", { ...state });
95
+ }
96
+ exports.renderFileTypeIcon = renderFileTypeIcon;
@@ -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,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileTypeIcon = exports.renderFileTypeIcon = exports.useFileTypeIcon = exports.fileTypeIconDataAttribute = void 0;
4
+ const useFileTypeIcon_1 = require("../common/useFileTypeIcon");
5
+ var useFileTypeIcon_2 = require("../common/useFileTypeIcon");
6
+ Object.defineProperty(exports, "fileTypeIconDataAttribute", { enumerable: true, get: function () { return useFileTypeIcon_2.fileTypeIconDataAttribute; } });
7
+ Object.defineProperty(exports, "useFileTypeIcon", { enumerable: true, get: function () { return useFileTypeIcon_2.useFileTypeIcon; } });
8
+ Object.defineProperty(exports, "renderFileTypeIcon", { enumerable: true, get: function () { return useFileTypeIcon_2.renderFileTypeIcon; } });
9
+ /**
10
+ * Headless (Griffel-free) file type icon. Renders an `<img>` sourced from CDN-hosted assets
11
+ * and tagged with the `fileTypeIconDataAttribute` styling hook, but ships **no** styling
12
+ * runtime — bring your own styles via `@fluentui/react-icons-file-type/headless/styles.css`, a
13
+ * `className`, or your own CSS targeting `[data-fui-filetype-icon]`.
14
+ *
15
+ * It composes the shared {@link useFileTypeIcon} (state) and {@link renderFileTypeIcon} (render)
16
+ * hooks; the default Griffel-styled entry point reuses the same hooks with an extra style hook.
17
+ *
18
+ * The asset host is resolved from the nearest `FileTypeIconsProvider`, falling back to the
19
+ * Fluent CDN default when no provider is present.
20
+ *
21
+ * Prefer the default `@fluentui/react-icons-file-type` entry point unless you specifically
22
+ * want to avoid the Griffel runtime.
23
+ */
24
+ const FileTypeIcon = (props) => {
25
+ const state = (0, useFileTypeIcon_1.useFileTypeIcon)(props);
26
+ return (0, useFileTypeIcon_1.renderFileTypeIcon)(state);
27
+ };
28
+ exports.FileTypeIcon = FileTypeIcon;
@@ -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,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ICON_SIZES = exports.DEFAULT_ICON_SIZE = exports.FLUENT_CDN_BASE_URL = exports.DEFAULT_BASE_URL = exports.FileIconType = exports.useFileTypeIconsContext = exports.FileTypeIconsProvider = exports.fileTypeIconDataAttribute = exports.FileTypeIcon = void 0;
4
+ // Headless (Griffel-free) entry point for `@fluentui/react-icons-file-type/headless`.
5
+ // Re-exports the styling-runtime-free `FileTypeIcon` plus the shared, framework-agnostic
6
+ // pieces (provider, context, `FileIconType`, constants) so this subpath is fully usable
7
+ // without pulling in `@griffel/react`.
8
+ var FileTypeIcon_1 = require("./FileTypeIcon");
9
+ Object.defineProperty(exports, "FileTypeIcon", { enumerable: true, get: function () { return FileTypeIcon_1.FileTypeIcon; } });
10
+ Object.defineProperty(exports, "fileTypeIconDataAttribute", { enumerable: true, get: function () { return FileTypeIcon_1.fileTypeIconDataAttribute; } });
11
+ var FileTypeIconsContext_1 = require("../common/FileTypeIconsContext");
12
+ Object.defineProperty(exports, "FileTypeIconsProvider", { enumerable: true, get: function () { return FileTypeIconsContext_1.FileTypeIconsProvider; } });
13
+ Object.defineProperty(exports, "useFileTypeIconsContext", { enumerable: true, get: function () { return FileTypeIconsContext_1.useFileTypeIconsContext; } });
14
+ var FileIconType_1 = require("../common/FileIconType");
15
+ Object.defineProperty(exports, "FileIconType", { enumerable: true, get: function () { return FileIconType_1.FileIconType; } });
16
+ var constants_1 = require("../common/constants");
17
+ Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return constants_1.DEFAULT_BASE_URL; } });
18
+ Object.defineProperty(exports, "FLUENT_CDN_BASE_URL", { enumerable: true, get: function () { return constants_1.FLUENT_CDN_BASE_URL; } });
19
+ Object.defineProperty(exports, "DEFAULT_ICON_SIZE", { enumerable: true, get: function () { return constants_1.DEFAULT_ICON_SIZE; } });
20
+ Object.defineProperty(exports, "ICON_SIZES", { enumerable: true, get: function () { return constants_1.ICON_SIZES; } });
@@ -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
+ }
@@ -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';
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ICON_SIZES = exports.DEFAULT_ICON_SIZE = exports.FLUENT_CDN_BASE_URL = exports.DEFAULT_BASE_URL = exports.FileIconType = exports.useFileTypeIconsContext = exports.FileTypeIconsProvider = exports.FileTypeIcon = void 0;
4
+ var FileTypeIcon_1 = require("./FileTypeIcon");
5
+ Object.defineProperty(exports, "FileTypeIcon", { enumerable: true, get: function () { return FileTypeIcon_1.FileTypeIcon; } });
6
+ var FileTypeIconsContext_1 = require("./common/FileTypeIconsContext");
7
+ Object.defineProperty(exports, "FileTypeIconsProvider", { enumerable: true, get: function () { return FileTypeIconsContext_1.FileTypeIconsProvider; } });
8
+ Object.defineProperty(exports, "useFileTypeIconsContext", { enumerable: true, get: function () { return FileTypeIconsContext_1.useFileTypeIconsContext; } });
9
+ var FileIconType_1 = require("./common/FileIconType");
10
+ Object.defineProperty(exports, "FileIconType", { enumerable: true, get: function () { return FileIconType_1.FileIconType; } });
11
+ var constants_1 = require("./common/constants");
12
+ Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return constants_1.DEFAULT_BASE_URL; } });
13
+ Object.defineProperty(exports, "FLUENT_CDN_BASE_URL", { enumerable: true, get: function () { return constants_1.FLUENT_CDN_BASE_URL; } });
14
+ Object.defineProperty(exports, "DEFAULT_ICON_SIZE", { enumerable: true, get: function () { return constants_1.DEFAULT_ICON_SIZE; } });
15
+ Object.defineProperty(exports, "ICON_SIZES", { enumerable: true, get: function () { return constants_1.ICON_SIZES; } });
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@fluentui/react-icons-file-type",
3
+ "version": "0.0.1",
4
+ "description": "Fluent UI React (v9-compatible) file type icon components rendered from CDN-hosted assets.",
5
+ "main": "lib-cjs/index.js",
6
+ "module": "lib/index.js",
7
+ "typings": "lib/index.d.ts",
8
+ "sideEffects": [
9
+ "**/headless/styles.css"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/microsoft/fluentui-system-icons.git",
14
+ "directory": "packages/react-icons-file-type"
15
+ },
16
+ "license": "MIT",
17
+ "bugs": {
18
+ "url": "https://github.com/microsoft/fluentui-system-icons/issues"
19
+ },
20
+ "homepage": "https://github.com/microsoft/fluentui-system-icons/tree/main/packages/react-icons-file-type#readme",
21
+ "scripts": {
22
+ "clean": "git clean -fXd lib/ lib-cjs/",
23
+ "generate": "node scripts/generateFileTypeIconMap.js && node scripts/generateFileIconTypes.js",
24
+ "prebuild": "npm run clean && npm run generate",
25
+ "build": "node scripts/build.js",
26
+ "bundle-size": "monosize measure",
27
+ "lint": "eslint src",
28
+ "pretest": "npm run generate",
29
+ "test": "vitest run"
30
+ },
31
+ "dependencies": {
32
+ "@griffel/react": "^1.6.1",
33
+ "tslib": "^2.1.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@types/react": ">=16.8.0 <20.0.0",
37
+ "react": ">=16.8.0 <20.0.0"
38
+ },
39
+ "peerDependenciesMeta": {
40
+ "@types/react": {
41
+ "optional": true
42
+ }
43
+ },
44
+ "devDependencies": {
45
+ "@griffel/eslint-plugin": "^2.0.2",
46
+ "eslint": "8.57.1",
47
+ "eslint-plugin-react-hooks": "^5.2.0",
48
+ "typescript": "5.0.4",
49
+ "typescript-eslint": "7.18.0"
50
+ },
51
+ "files": [
52
+ "lib/",
53
+ "lib-cjs/"
54
+ ],
55
+ "exports": {
56
+ ".": {
57
+ "types": "./lib/index.d.ts",
58
+ "import": "./lib/index.js",
59
+ "require": "./lib-cjs/index.js"
60
+ },
61
+ "./headless": {
62
+ "types": "./lib/headless/index.d.ts",
63
+ "import": "./lib/headless/index.js",
64
+ "require": "./lib-cjs/headless/index.js"
65
+ },
66
+ "./headless/styles.css": "./lib/headless/styles.css",
67
+ "./package.json": "./package.json"
68
+ }
69
+ }