Search by

silarhi / ux-icons-js-bundle

guillaume-sainthillier

Render Symfony UX Icons in JavaScript, React, Preact 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

Homepage

Documentation

Type:symfony-bundle

pkg:composer/silarhi/ux-icons-js-bundle

Statistics

Installs: 6 028

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 6

v0.5.0 2026-11-27 10:20 UTC

This package is auto-updated.

Last update: 2026-12-01 08:33:35 UTC


README

Latest Stable Version Total Downloads License PHP Version CI Status Coverage JavaScript coverage npm Version

UX Icons JS Bundle

Render Symfony UX Icons in JavaScript, React, Preact and Vue.
Same attributes, same configuration, same HTML as ux_icon(), without innerHTML.

📖 Documentation

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 attributes ux_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, Preact or Vue.

Features

  • Same output as ux_icon(): default_icon_attributes, icon set icon_attributes, suffixes and aliases come from your ux_icons configuration, and the attributes you give follow the ux_icon() rules.
  • Tree-shaken: lucide:trash-2 is exported as LucideTrash2Icon, 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), useIcon() in React, Preact and Vue, typed with the dumped names.
  • <ux-icon name="lucide:trash-2">: a custom element for Twig templates, Turbo Streams and Stimulus, replaced by the <svg> of ux_icon().
  • No innerHTML: createIconElement() builds SVG elements, the React, Preact and Vue components render elements.
  • Works with ux:icons:lock: write the import first, run ux: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, Preact 10/11 and Vue 3 are optional peer dependencies.

The package does not require symfony/framework-bundle, symfony/config nor symfony/dependency-injection: only the bundle class uses them, see Without the bundle. symfony/ux-icons still requires the framework until symfony/ux#4378 is released; the CI job testing without it comes then.

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],

Without the bundle

An application without a kernel builds the dumper and the ux-icons-js:dump command by hand, with the values of its ux_icons configuration:

use Silarhi\UxIconsJsBundle\Command\DumpIconsCommand;
use Silarhi\UxIconsJsBundle\IconResolver;
use Silarhi\UxIconsJsBundle\IconsDumper;
use Symfony\UX\Icons\IconFactory;
use Symfony\UX\Icons\Registry\LocalSvgIconRegistry;

$iconDir = __DIR__ . '/assets/icons';                   // icon_dir
$iconSetPaths = ['flags' => __DIR__ . '/assets/flags']; // icon_sets.*.path
$aliases = ['delete' => 'lucide:trash-2'];              // aliases

$resolver = new IconResolver(
    new LocalSvgIconRegistry(new IconFactory(), $iconDir, $iconSetPaths),
    ['fill' => 'currentColor'],       // default_icon_attributes
    $aliases,
    ['flags' => ['class' => 'flag']], // icon_sets.*.icon_attributes
);
$dumper = new IconsDumper($resolver, $iconDir, $iconSetPaths, $aliases, __DIR__ . '/var/icons');

$application->addCommands([new DumpIconsCommand($dumper)]); // or $dumper->dump()

LocalSvgIconRegistry and IconFactory are internal to symfony/ux-icons, with the same constructor from 2.36.1 to 3.8. Without the bundle, nothing dumps the icons on cache warmup nor after ux:icons:import: run the command.

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/preact', '@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:

Contributing

See CONTRIBUTING.md. Release notes are in CHANGELOG.md.

License

Released under the MIT License.