silarhi / ux-icons-js-bundle
Render Symfony UX Icons in JavaScript, React and Vue, with the same attributes and configuration as ux_icon() — the PHP companion to @silarhi/ux-icons-js
Package info
github.com/silarhi/ux-icons-js-bundle
Type:symfony-bundle
pkg:composer/silarhi/ux-icons-js-bundle
Requires
- php: >=8.2
- ext-dom: *
- symfony/console: ^6.4 || ^7.0 || ^8.0
- symfony/filesystem: ^6.4 || ^7.0 || ^8.0
- symfony/finder: ^6.4 || ^7.0 || ^8.0
- symfony/framework-bundle: ^6.4 || ^7.0 || ^8.0
- symfony/ux-icons: ^2.36.1 || ^3.5
Requires (Dev)
- ergebnis/composer-normalize: ^2.54.0
- friendsofphp/php-cs-fixer: ^3.95.27
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.3.1
- phpstan/phpstan-strict-rules: ^2.1.0
- phpstan/phpstan-symfony: ^2.1.0
- phpunit/phpunit: ^11.5.57 || ^12.5.38 || ^13.4.1
- rector/rector: ^2.7.0
- symfony/asset-mapper: ^6.4 || ^7.0 || ^8.0
- symfony/error-handler: ^6.4 || ^7.0 || ^8.0
- symfony/http-client: ^6.4 || ^7.0 || ^8.0
- symfony/twig-bundle: ^6.4 || ^7.0 || ^8.0
Suggests
- symfony/asset-mapper: Maps the dumped icons as "var/icons" in the importmap
Provides
None
Conflicts
None
Replaces
None
README
UX Icons JS Bundle
Render Symfony UX Icons in JavaScript, React and Vue.
Same attributes, same configuration, same HTML as ux_icon(), without innerHTML.
A backport of symfony/ux#4072 on top of an unmodified symfony/ux-icons,
in two packages released from the same git tag:
silarhi/ux-icons-js-bundle(PHP): dumps your local icons, with the attributesux_icon()gives them, as a JavaScript module with one named export per icon.@silarhi/ux-icons-js(JS/TS): renders them in vanilla JavaScript, React or Vue.
Features
- Same output as
ux_icon():default_icon_attributes, icon seticon_attributes,suffixesandaliasescome from yourux_iconsconfiguration, and the attributes you give follow theux_icon()rules. - Tree-shaken:
lucide:trash-2is exported asLucideTrash2Icon, your bundler drops the icons you never import. - Dynamic names: an icon name from an API response loads that icon alone,
await loadIcon(loaders, data.icon). - No
innerHTML:createIconElement()builds SVG elements, the React and Vue components render elements. - Works with
ux:icons:lock: write the import first, runux:icons:lock, the icon is downloaded and dumped.
Requirements
PHP 8.2+, Symfony 6.4 / 7.x / 8.x, symfony/ux-icons 2.36.1+ or 3.5+ (3.x needs PHP 8.4; see the
compatibility notes for 2.x). React 18/19 and Vue 3
are optional peer dependencies.
Installation
composer require silarhi/ux-icons-js-bundle pnpm add @silarhi/ux-icons-js
// config/bundles.php — after UXIconsBundle, whose configuration it reuses Silarhi\UxIconsJsBundle\SilarhiUxIconsJsBundle::class => ['all' => true],
Quick start
The icons are dumped into var/icons/ on cache warmup, or with php bin/console ux-icons-js:dump:
import { createIconElement } from '@silarhi/ux-icons-js' import { UXIcon } from '@silarhi/ux-icons-js/react' // or '@silarhi/ux-icons-js/vue' import { LucideTrash2Icon } from '../var/icons/index.js' button.append(createIconElement(LucideTrash2Icon, { class: 'text-danger', 'aria-label': 'Delete' })) const icon = <UXIcon icon={LucideTrash2Icon} className="text-danger" aria-label="Delete" />
Documentation
Everything else is on ux-icons-js-bundle.silarhi.dev:
- Installation and quick start
- JavaScript: vanilla, dynamic names, attributes, React, Vue
- PHP: dumping icons, remote icons, Webpack Encore and AssetMapper
- Reference: configuration, compatibility, differences with symfony/ux#4072
Contributing
See CONTRIBUTING.md. Release notes are in CHANGELOG.md.
License
Released under the MIT License.