Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Icons] Configure icon sets: path, alias & icon attributes #2156

Merged

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>

src/Icons/src/IconRenderer.php Outdated Show resolved Hide resolved
src/Icons/src/IconRenderer.php Outdated Show resolved Hide resolved
@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Sep 12, 2024
src/Icons/src/IconRenderer.php Outdated Show resolved Hide resolved
src/Icons/src/IconRenderer.php Outdated Show resolved Hide resolved
@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
src/Icons/src/DependencyInjection/UXIconsExtension.php Outdated Show resolved Hide resolved
src/Icons/src/IconRenderer.php Show resolved Hide resolved
src/Icons/src/IconRenderer.php Show resolved Hide resolved
@javiereguiluz
Copy link
Member

Merged! Thanks a lot Simon

@javiereguiluz javiereguiluz merged commit 98f1622 into symfony:2.x Sep 18, 2024
12 checks passed
@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 :))

# for free to join this conversation on GitHub. Already have an account? # 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