### Install @boxicons/js Source: https://github.com/box-icons/boxicons/blob/main/README.md Install the library using npm, yarn, or pnpm. ```bash npm install @boxicons/js # or yarn add @boxicons/js # or pnpm add @boxicons/js ``` -------------------------------- ### Usage with unpkg CDN Source: https://github.com/box-icons/boxicons/blob/main/README.md Include the library via CDN and use the global `boxicons` object to get all available icons. This method makes all icons available. ```html ``` -------------------------------- ### Tree Shaking with Boxicons JS Source: https://github.com/box-icons/boxicons/blob/main/README.md Demonstrates efficient bundling by importing only necessary icons. Avoid importing all icons to ensure a smaller production bundle. ```javascript // ✅ Only Menu and Home are bundled import { getIcons, Menu, Home } from '@boxicons/js'; getIcons({ icons: { Menu, Home } }); // ❌ This bundles ALL icons - avoid in production import { getIcons, icons } from '@boxicons/js'; getIcons({ icons }); ``` -------------------------------- ### Auto-import Entry Point Source: https://context7.com/box-icons/boxicons/llms.txt Importing from `@boxicons/js/auto` automatically scans the document on `DOMContentLoaded` and sets up a `MutationObserver` for live updates. This is ideal for CDN or prototyping usage as it requires no manual calls. ```APIDOC ## Auto-import entry point — zero-config initialization Importing from `@boxicons/js/auto` automatically scans the document on `DOMContentLoaded` and sets up a `MutationObserver` so newly added elements are processed without any manual call. All icons are included, so this entry point is not tree-shakable and is best suited for CDN/prototyping usage. ```html ``` ```javascript // ESM — automatic replacement + live observation of the DOM import '@boxicons/js/auto'; // No further calls needed; icons already replaced and observer running. // Access the MutationObserver instance to stop watching if needed import { autoObserver } from '@boxicons/js/auto'; autoObserver?.disconnect(); ``` ``` -------------------------------- ### Size Presets Source: https://github.com/box-icons/boxicons/blob/main/README.md Apply predefined size presets to icons using the `data-bx-size` attribute, ranging from 'xs' to '5xl'. ```html ``` -------------------------------- ### Boxicons Auto-Import Initialization (CDN) Source: https://context7.com/box-icons/boxicons/llms.txt Include the `@boxicons/js/auto` script via CDN to automatically process icons on `DOMContentLoaded`. This is suitable for CDN or prototyping usage as it includes all icons and is not tree-shakable. ```html ``` -------------------------------- ### Icon Packs Source: https://github.com/box-icons/boxicons/blob/main/README.md Use different icon packs like 'basic', 'filled', or 'brands' by specifying the `data-bx-pack` attribute on the icon element. ```html ``` -------------------------------- ### Basic Usage with ESModules Source: https://github.com/box-icons/boxicons/blob/main/README.md Use the `getIcons` function to replace HTMLElements with the `data-bx` attribute with SVG icons. Ensure you import only the icons you need for tree-shaking. ```html ``` ```javascript import { getIcons, Menu, ArrowRight, Globe } from '@boxicons/js'; // Recommended way, to include only the icons you need. getIcons({ icons: { Menu, ArrowRight, Globe } }); ``` -------------------------------- ### createElement(icon, options?) Source: https://context7.com/box-icons/boxicons/llms.txt Programmatically creates an `SVGSVGElement` from an `IconDefinition` with optional rendering options. It provides a fallback for non-browser environments (Node.js/SSR) by returning an object with an `outerHTML` property. ```APIDOC ## `createElement(icon, options?)` — Programmatic SVG element Creates an `SVGSVGElement` from an `IconDefinition` and optional rendering options. In non-browser environments (Node.js / SSR), returns a minimal object exposing `outerHTML` instead of a real DOM element, making it safe to use in server-side rendering pipelines. ### Parameters - **icon** (IconDefinition) - Required - The icon component to create an element from. - **options** (IconOptions) - Optional - Rendering options for the SVG element. - **options.pack** (string) - Optional - The icon pack ('basic', 'filled', 'brands'). Defaults to 'basic'. - **options.size** (string | number) - Optional - The size of the icon (e.g., 'xs', 'sm', 'md', 'lg', 'xl', or a pixel value). - **options.fill** (string) - Optional - The fill color of the icon. - **options.opacity** (number) - Optional - The opacity of the icon. - **options.rotate** (number) - Optional - The rotation angle in degrees. - **options.className** (string) - Optional - CSS classes to apply to the SVG element. - **options.ariaLabel** (string) - Optional - Accessibility label for the icon. ### Request Example ```javascript import { createElement, Alarm } from '@boxicons/js'; const alarmIcon = createElement(Alarm, { pack: 'filled', size: 'lg', fill: '#D69E2E', opacity: 0.85, rotate: 45, className: 'alarm-icon', ariaLabel: 'Alarm icon', }); document.getElementById('toolbar').appendChild(alarmIcon); // SSR / Node.js fallback if (typeof document === 'undefined') { const ssrIcon = createElement(Alarm, { size: 'sm', fill: 'red' }); console.log(ssrIcon.outerHTML); } ``` ``` -------------------------------- ### Advanced getIcons Options Source: https://github.com/box-icons/boxicons/blob/main/README.md Customize icon replacement behavior using options like `nameAttr`, `attrs`, `root`, and `inTemplates`. This allows for more flexible integration. ```javascript import { getIcons, Menu, Home } from '@boxicons/js'; getIcons({ icons: { Menu, Home }, attrs: { className: 'my-custom-class icon', fill: '#333' }, nameAttr: 'data-bx', root: document.getElementById('app'), inTemplates: true }); ``` -------------------------------- ### Template Tags Support Source: https://github.com/box-icons/boxicons/blob/main/README.md Enable icon replacement within `