{"id":29522801,"url":"https://github.com/inseefrlab/mui-icons-material-lazy","last_synced_at":"2026-02-06T11:35:04.184Z","repository":{"id":261829240,"uuid":"884270128","full_name":"InseeFrLab/mui-icons-material-lazy","owner":"InseeFrLab","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-28T18:29:59.000Z","size":187,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-10-10T16:28:15.529Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/InseeFrLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-06T13:02:18.000Z","updated_at":"2024-12-05T17:15:18.000Z","dependencies_parsed_at":"2024-11-08T17:41:30.628Z","dependency_job_id":"d2ff3097-64df-410b-8e16-a88e70b2b6e4","html_url":"https://github.com/InseeFrLab/mui-icons-material-lazy","commit_stats":null,"previous_names":["inseefrlab/onyxia-ui-icons"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/InseeFrLab/mui-icons-material-lazy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InseeFrLab%2Fmui-icons-material-lazy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InseeFrLab%2Fmui-icons-material-lazy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InseeFrLab%2Fmui-icons-material-lazy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InseeFrLab%2Fmui-icons-material-lazy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InseeFrLab","download_url":"https://codeload.github.com/InseeFrLab/mui-icons-material-lazy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InseeFrLab%2Fmui-icons-material-lazy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29159600,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T07:18:23.844Z","status":"ssl_error","status_checked_at":"2026-02-06T07:13:32.659Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-16T17:35:54.711Z","updated_at":"2026-02-06T11:35:04.164Z","avatar_url":"https://github.com/InseeFrLab.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mui-icons-material-lazy\n\nThe idea behind this NPM lib is to be ables to use [the `@mui/icons-material` catalog of icons](https://mui.com/material-ui/material-icons/) even if\nthe icons that will be used aren't known at build time.\n\nSince including all 2000+ icons in the bundle would make the bundle size explode there is a need for a solution that enables to load the icons lazily\nwhen they are needed.\n\nIt's a requirement we have for the [Onyxia project](https://github.com/InseeFrLab/onyxia) because the web application is distributed as a white-labeled\nstatical SPA. People that deploy an onyxia instance [can customize the look of onyxia](https://docs.onyxia.sh/admin-doc/theme) via injecting standardized\nenvironnement variable.  \nThis means that we can't know at build time which icons will be used.\n\n# Usage\n\n```bash\nyarn add mui-icons-material-lazy\n```\n\n`package.json`\n\n```jsonc\n{\n    \"scripts\": {\n        \"postinstall\": \"mui-icons-material-lazy postinstall\"\n        // If you are in a monorepo you can specify your SPA (Vite or CRA) project path like:\n        // \"postinstall\": \"mui-icons-material-lazy postinstall --project packages/front\n    }\n}\n```\n\n```tsx\nimport { createGetIconUrl } from \"mui-icons-material-lazy\";\n\nconst { getIconUrl, getIconUrlByName } = createGetIconUrl({\n    BASE_URL: import.meta.env.BASE_URL\n    // Or if you are in create-react-app:\n    // BASE_URL: process.env.PUBLIC_URL,\n    // Or if you have a custom build setup:\n    // BASE_URL: \"/\",\n});\n\n// Let's say we have this variable that isn't known at build time:\ndeclare const HOME_ICON: string | undefined;\n\ngetIconUrl(HOME_ICON); // The return type is `string | undefined`\n// If HOME_ICON is \"https://example.net/my-icon.svg\":   \"https://example.net/my-icon.svg\"\n// If HOME_ICON is \"Home\" or \"home\":                    \"https://my-app.com/mui-icons-material/Home.svg\"\n\n// Implementing fallback:\n\n// iconUrl is of type `string`\nconst iconUrl = getIconUrl(HOME_ICON) ?? getIconUrlByName(\"Home\");\n```\n\n## Usage in `onyxia-ui`\n\n`src/lazy-icons`\n\n```tsx\nexport const { getIconUrl, getIconUrlByName } = createGetIconUrl({\n    BASE_URL: import.meta.env.BASE_URL\n});\n```\n\nIn a component:\n\n```tsx\nimport { Icon } from \"onyxia-ui/Icon\";\n// Absolute import using ts-config-paths and baseUrl: \"./src\"\nimport { getIconUrl, getIconUrlByName } from \"lazy-icons\";\n\ndeclare const SOME_ICON: string;\n\n\u003cIcon icon={getIconUrl(SOME_ICON)} /\u003e;\n\ndeclare const MAYBE_SOME_ICON: string | undefined;\n\n\u003cIcon icon={getIconUrl(MAYBE_SOME_ICON) ?? getIconUrlByName(\"Home\")} /\u003e;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finseefrlab%2Fmui-icons-material-lazy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finseefrlab%2Fmui-icons-material-lazy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finseefrlab%2Fmui-icons-material-lazy/lists"}