UNPKG

@untitledui/file-icons

Version:

Official React library for Untitled UI File Icons

2 lines (1 loc) 1.84 kB
import n,{Suspense as T,useMemo as v}from"react";import{iconImports as l}from"./iconImports";const p={},w=t=>t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(""),h=["json","javascript","x-javascript","typescript","typescriptreact","xml","html","css","yaml","x-yaml","toml","x-toml","markdown","php","x-php","java","python","ruby","x-ruby","swift","go","x-go","c","x-c","cpp","x-cpp","csharp","x-csharp"],S=["pdf","msword","vnd.openxmlformats-officedocument.wordprocessingml.document","vnd.ms-excel","vnd.openxmlformats-officedocument.spreadsheetml.sheet","vnd.ms-powerpoint","vnd.openxmlformats-officedocument.presentationml.presentation"];function b(t){const[e,s]=t.split("/");if(!e||!s)return"unknown";switch(e){case"image":return"image";case"audio":return"audio";case"video":return"video";case"application":case"text":if(h.includes(s))return"code";if(S.includes(s))return"document";break}return"unknown"}const d=["audio","code","document","empty","folder","image","img","spreadsheets","video","video-01","video-02","aep","ai","avi","css","csv","dmg","doc","docx","eps","exe","fig","gif","html","indd","java","jpeg","jpg","js","json","mkv","mp3","mp4","mpeg","pdf","pdf-simple","png","ppt","pptx","psd","rar","rss","sql","svg","tiff","txt","wav","webp","xls","xlsx","xml","zip"],C=({type:t,variant:e="default",theme:s="light",...u})=>{const i=t.includes("/"),c=i?b(t):void 0,r=(i?t.split("/")[1]:void 0)??t,y=d.includes(r),f=i?d.includes(c):!1,o=`${e}_${y?r:f?c:"empty"}`,x=v(()=>{if(!p[o]){const a=l[o];if(a)p[o]=n.lazy(a);else{const g=e==="default"?"default_empty":`${e}_empty`,m=l[g];m?p[o]=n.lazy(m):p[o]=n.lazy(()=>Promise.resolve({default:()=>null}))}}return p[o]},[o]);return n.createElement(T,{fallback:null},n.createElement(x,{...u,theme:s}))};export{C as FileIcon,d as SUPPORTED_FILE_TYPES,b as categorizeMimeType};