Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ux Icons Laravel Package

symfony/ux-icons

Symfony UX Icons provides a simple way to use SVG icon packs in Symfony apps. Install popular sets, render icons in Twig or PHP, and manage them consistently across your UI with the Symfony UX tooling and asset pipeline.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:
    • Native Laravel/Twig Synergy: Leverages Laravel’s existing Twig support (if used) or integrates cleanly via symfony/twig-bundle, avoiding frontend bloat.
    • SVG Advantages: Resolution-independent, smaller file sizes than PNGs, and CSS/JS-friendly (e.g., fill-current for dynamic colors).
    • Design System Alignment: Supports icon sets (e.g., Material Design Icons, Heroicons) and aliases, reducing redundancy in large codebases.
    • Dynamic Rendering: Enables server-side logic (e.g., role-based icons, A/B tested variants) without client-side JS.
    • MIT License: Zero legal/licensing risks for commercial use.
  • Cons:
    • Twig Dependency: Projects using Blade exclusively require additional abstraction (e.g., Twig helpers or Blade-Twig bridges like spatie/laravel-twig).
    • No Built-in Laravel Service Provider: Manual setup needed for dependency injection (though minimal).
    • Remote SVG Risks: XXE vulnerabilities if unsanitized (mitigate via Laravel’s Storage or HttpClient with strict validation).
    • Caching Complexity: Remote SVGs demand explicit caching strategies (e.g., Cache::remember with versioned URLs).

Integration Feasibility

  • Low Effort for Twig Users:
    • Drop-in replacement for manual SVG includes (e.g., {{ ux_icon('mdi:home') }} vs. <img src="/icons/home.svg">).
    • Twig Components enable reusable icon variants (e.g., <twig:ux:icon name="user" class="text-red-500" />).
  • Medium Effort for Blade-Only Projects:
    • Option 1: Use Twig as a micro-template engine for icons (e.g., @twig('icons/{$name}.svg')).
    • Option 2: Build a Blade-compatible facade (e.g., Icon::render('home')) that internally uses Twig.
    • Option 3: Pre-render SVGs to Blade-compatible strings (e.g., Icon::svg('home')).
  • Asset Pipeline Compatibility:
    • SVGs can be processed via Laravel Mix/Vite (e.g., minification, spriting).
    • Supports inline SVGs (for critical paths) and external files (for caching).

Technical Risk

  • Critical Risks (Mitigable):
    • XXE in Remote SVGs: Sanitize inputs and use Laravel’s HttpClient with allow_redirects: false and verify_peer: true.
    • Cache Invalidation: Implement versioned URLs (e.g., https://cdn.example.com/icons/v2/home.svg) or ETag-based caching.
    • Twig Learning Curve: Provide Blade-like syntax examples (e.g., @icon('home') as a helper).
  • Low Risks:
    • PHP 8.4+ Requirement (v3.0): Upgrade path is straightforward (composer update + minor config tweaks).
    • Symfony 7.4+ Requirement: Laravel 10+ users are unaffected; older versions need symfony/twig-bundle:^6.4.

Key Questions

  1. Icon Delivery Strategy:
    • Will icons be self-hosted (local SVGs) or CDN-hosted? This dictates caching (local vs. CDN) and failure modes.
    • Example: icon_sets config for Material Icons vs. custom SVGs.
  2. Template System:
    • Is Twig already in use (e.g., for emails, API responses), or will this require dual-template support?
    • If Blade-only, what’s the preferred abstraction? (e.g., Twig helpers, Blade directives, or a facade).
  3. Performance Constraints:
    • Are there critical rendering paths (e.g., dashboard load time) where remote SVG latency could degrade UX?
    • Baseline: Remote SVGs add ~50–200ms per request (mitigate with Cache::remember or CDN caching).
  4. Design System Requirements:
    • Does the UI system (e.g., Tailwind, Bootstrap) support SVG-based icons natively?
    • Example: Tailwind’s fill-current for dynamic colors vs. icon font limitations.
  5. Fallback Mechanism:
    • Should non-Twig views (e.g., Blade) use a fallback SVG or placeholder when icons fail to load?
    • Example: Icon::render('home', fallback: '<span>⚙️</span>').
  6. Long-Term Maintenance:
    • Who will update SVGs (designers vs. developers)? Will a Figma/Illustrator → SVG workflow be documented?
    • Example: Automated SVG optimization via Laravel Mix (@svg('icon.svg', { smacss: true })).

Integration Approach

Stack Fit

  • Ideal Use Cases:
    • Laravel + Twig: Native integration with zero overhead (e.g., admin panels, marketing sites).
    • Laravel + Inertia/Vue/React: Server-rendered icons for loading states, meta tags, or fallbacks.
    • Livewire/Alpine.js: Dynamic icon updates via Twig components (e.g., <twig:ux:icon name="{{ $user.role }}" />).
    • API-Driven Frontends: Serve icons via API endpoints (cached) for SPAs.
  • Workarounds for Blade-Only:
    • Option 1: Twig Helpers
      // app/Helpers/Icon.php
      class Icon {
          public static function render(string $name, array $attrs = []): string {
              $twig = \Twig\Environment::create();
              return $twig->render("icons/{$name}.svg.twig", $attrs);
          }
      }
      // Blade usage: {{ Icon::render('home', ['class' => 'text-blue-500']) }}
      
    • Option 2: Blade Directives
      // app/Providers/BladeServiceProvider.php
      Blade::directive('icon', function ($name) {
          return "<?php echo app\\Helpers\\Icon::render({$name}); ?>";
      });
      // Blade usage: @icon('home')
      
    • Option 3: Pre-Rendered SVGs Cache SVGs as Blade strings during deployment (e.g., php artisan icon:cache).

Migration Path

  1. Phase 1: Assessment (1 day)

    • Audit existing icon usage (e.g., Font Awesome, icon fonts, manual SVGs).
    • Identify high-impact icons (e.g., navigation, CTAs) vs. low-impact (e.g., decorative).
    • Decide: Local SVGs (self-hosted) vs. Remote SVGs (CDN).
  2. Phase 2: Setup (2–3 days)

    • Install dependencies:
      composer require symfony/ux-icons symfony/twig-bundle
      
    • Configure config/packages/twig.php:
      twig:
          paths: ['%kernel.project_dir%/templates/icons']
          globals:
              icon_sets: ['mdi', 'heroicons']
      
    • Create a base icon template (templates/icons/base.svg.twig):
      <svg viewBox="0 0 24 24" fill="currentColor" {# attributes #}>
          {# Icon content (rendered dynamically) #}
      </svg>
      
  3. Phase 3: Icon System (1 week)

    • Organize SVGs:
      /resources/svg/icons/
          ├── mdi/
          │   ├── home.svg
          │   └── user.svg
          └── heroicons/
              ├── outline/
              │   └── home.svg
              └── solid/
                  └── user.svg
      
    • Create Twig templates for each icon (e.g., templates/icons/mdi/home.svg.twig):
      {% extends 'icons/base.svg.twig' %}
      {% block icon_content %}
          <path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
      {% endblock %}
      
    • Build a helper class (app/Services/IconService.php) for Blade compatibility:
      class IconService {
          public function render(string $name, array $attrs = []): string {
              $twig = \Twig\Environment::create();
              return $twig->render("icons/{$name}.svg.twig", $attrs);
          }
      }
      
  4. Phase 4: Integration (2 weeks)

    • Replace icons in templates (Twig/Blade):
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views