Skip to content

Conversation

@smnandre
Copy link
Member

@smnandre smnandre commented Sep 12, 2024

Q A
Bug fix? no
New feature? yes
Issues Fix #
License MIT

I'm opening now if you guys have feedback, and i will add more tests the next couple days

Note

This PR brings 3 new features: iconset aliases, custom path and attributes. So let's focus on that 😄

ux_icons:
    icon_dir: '%kernel.project_dir%/assets/icons'

    # Default icon set
    default_icon_attributes:
        class: 'icon'
        fill: 'currentColor'
        width: '24'
        height: '24'

    icon_sets:
        # Local icon set    (prefix mapped to a local directory)
        flags:
            path: '%kernel.project_dir%/assets/images/flags'

        # Remote icon set   (prefix mapped to an icon set identifier)
        lu:
            alias: 'lucide'

        # Icon set configuration (work for local/remote)
        oc:
            icon_attributes:
                class: 'oc-icon'       # Replace the default class
                stroke: 'none'      # Add a new attribute
                fill: false         # Use "false" to remove a default attribute

Default attributes

<twig:ux:icon name="anything" />

{# Renders #}
<svg class="icon" fill="currentColor" width="24" height="24"> ... </svg>

Icon set configuration

Local icons: path

<twig:ux:icon name="flags:fr" />

{# Renders:  #}
<svg class="icon" fill="currentColor" width="24" height="24">
    <!-- file assets/images/flags/fr.svg -->
</svg>

Remote icons: alias

<twig:ux:icon name="lu:circle-check" />

{# Renders:  #}
<svg class="icon" fill="currentColor" width="24" height="24">
    <!-- file lucide:circle-check.svg from iconify -->
</svg>

Icon set attributes

<twig:ux:icon name="oc:check" />

{# Renders:  #}
{# Attributes are merged into the default attributes #}
<svg class="oc-icon" stroke="none" width="24" height="24">
    <!-- file oc:check.svg from local or remote -->
</svg>

@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Sep 12, 2024
@smnandre smnandre force-pushed the feat/icon-sets-config-attributes branch 2 times, most recently from 20c31f7 to 511114b Compare September 13, 2024 21:10
@javiereguiluz javiereguiluz force-pushed the feat/icon-sets-config-attributes branch from b966538 to 28454b8 Compare September 18, 2024 14:55
@javiereguiluz
Copy link
Member

Merged! Thanks a lot Simon

@seb-jean
Copy link
Contributor

seb-jean commented Oct 6, 2024

I tried but I can't get the expected result.
How to differentiate the attributes of these 4 subdirectories:

  • assets/icons/heroicons/24/outline
  • assets/icons/heroicons/24/solid
  • assets/icons/heroicons/20/solid
  • assets/icons/heroicons/16/solid

I tried the following code:

ux_icons:
    icon_sets:
        heroicons:20:solid:
            icon_attributes:
                fill: 'currentColor'
                aria-hidden: true
                data-slot: 'icon'

@smnandre
Copy link
Member Author

smnandre commented Oct 6, 2024

So i'm pretty sure this would not work, but just to signal "heroicons:20:solid" should be enquoted in yaml ;)

@smnandre
Copy link
Member Author

smnandre commented Oct 6, 2024

Then i'm pretty sure heroicons:20:solid is not a icon set prefix (at least not an remote one), right ?

@seb-jean
Copy link
Contributor

seb-jean commented Oct 6, 2024

Yes, icon set prefix is heroicons.

Capture d'écran 2024-10-06 151003

@seb-jean
Copy link
Contributor

seb-jean commented Oct 6, 2024

Could this work with subdirectories then? :)

@seb-jean
Copy link
Contributor

seb-jean commented Oct 6, 2024

I think it's because I put : in the name and suddenly it's blocked.

@seb-jean
Copy link
Contributor

seb-jean commented Oct 6, 2024

I did it like this and it works:

# config/packages/ux_icons.yaml
ux_icons:
    default_icon_attributes: []
    icon_sets:
        heroicons-20-solid:
            path: '%kernel.project_dir%/assets/icons/heroicons/20/solid'
            icon_attributes:
                fill: 'currentColor'
                data-slot: 'icon'
<twig:ux:icon name="heroicons-20-solid:cake" class="h-5 w-5 text-gray-400" />

@smnandre
Copy link
Member Author

smnandre commented Oct 6, 2024

Nice! I was not 100% sure it would :))

Kocal added a commit that referenced this pull request Jul 24, 2025
This PR was merged into the 2.x branch.

Discussion
----------

[Icons] Document `icon_sets` configuration

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Docs?         | yes <!-- required for new features -->
| Issues        | Fix #2182 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT

Related to #2156

Commits
-------

4f4eb76 [Icons] Document `icon_sets` configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New Feature Icons Status: Reviewed Has been reviewed by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants