Skip to content

[Icons] Introduce symfony/ux-icons #1450

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Icons/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.symfony.bundle.yaml export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
4 changes: 4 additions & 0 deletions src/Icons/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
/composer.lock
/var
/.phpunit.result.cache
3 changes: 3 additions & 0 deletions src/Icons/.symfony.bundle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
branches: ["2.x"]
maintained_branches: ["2.x"]
doc_dir: "doc"
19 changes: 19 additions & 0 deletions src/Icons/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2024-present Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
40 changes: 40 additions & 0 deletions src/Icons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# UX Icons

Renders local and remote SVG icons in your Twig templates.

```twig
{{ ux_icon('mdi:symfony', {class: 'w-4 h-4'}) }}
{# or #}
<twig:UX:Icon name="mdi:check" class="w-4 h-4" />

{# renders as: #}
<svg viewBox="0 0 24 24" fill="currentColor" class="w-4 h-4"><path fill="currentColor" d="M21 7L9 19l-5.5-5.5l1.41-1.41L9 16.17L19.59 5.59z"/></svg>
```

Want a demo? Check out https://ux.symfony.com/ux-icons.

**This repository is a READ-ONLY sub-tree split**. See
https://github.com/symfony/ux to create issues or submit pull requests.

## Sponsor

The Symfony UX packages are [backed][1] by [Mercure.rocks][2].

Create real-time experiences in minutes! Mercure.rocks provides a realtime API service
that is tightly integrated with Symfony: create UIs that update in live with UX Turbo,
send notifications with the Notifier component, expose async APIs with API Platform and
create low level stuffs with the Mercure component. We maintain and scale the complex
infrastructure for you!

Help Symfony by [sponsoring][3] its development!

## Resources

- [Documentation](https://symfony.com/bundles/ux-icons/current/index.html)
- [Report issues](https://github.com/symfony/ux/issues) and
[send Pull Requests](https://github.com/symfony/ux/pulls)
in the [main Symfony UX repository](https://github.com/symfony/ux)

[1]: https://symfony.com/backers
[2]: https://mercure.rocks
[3]: https://symfony.com/sponsor
55 changes: 55 additions & 0 deletions src/Icons/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "symfony/ux-icons",
"type": "symfony-bundle",
"description": "Renders local and remote SVG icons in your Twig templates.",
"keywords": [
"symfony-ux",
"twig",
"icons",
"svg"
],
"homepage": "https://symfony.com",
"license": "MIT",
"authors": [
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"autoload": {
"psr-4": {
"Symfony\\UX\\Icons\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Symfony\\UX\\Icons\\Tests\\": "tests/"
}
},
"require": {
"php": ">=8.1",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/twig-bundle": "^6.4|^7.0"
},
"require-dev": {
"symfony/asset-mapper": "^6.4|^7.0",
"symfony/console": "^6.4|^7.0",
"symfony/http-client": "6.4|^7.0",
"symfony/phpunit-bridge": "^6.3|^7.0",
"symfony/ux-twig-component": "^2.14",
"zenstruck/console-test": "^1.5"
},
"config": {
"sort-packages": true
},
"conflict": {
"symfony/flex": "<1.13"
},
"extra": {
"thanks": {
"name": "symfony/ux",
"url": "https://github.com/symfony/ux"
}
},
"minimum-stability": "dev"
}
28 changes: 28 additions & 0 deletions src/Icons/config/asset_mapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\AssetMapper\Event\PreAssetsCompileEvent;
use Symfony\UX\Icons\EventListener\WarmIconCacheOnAssetCompileListener;

return static function (ContainerConfigurator $container): void {
$container->services()
->set('.ux_icons.event_listener.warm_icon_cache_on_asset_compile', WarmIconCacheOnAssetCompileListener::class)
->args([
service('.ux_icons.cache_warmer'),
])
->tag('kernel.event_listener', [
'event' => PreAssetsCompileEvent::class,
'method' => '__invoke',
])
;
};
39 changes: 39 additions & 0 deletions src/Icons/config/iconify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\UX\Icons\Command\ImportIconCommand;
use Symfony\UX\Icons\Iconify;
use Symfony\UX\Icons\Registry\IconifyOnDemandRegistry;

return static function (ContainerConfigurator $container): void {
$container->services()
->set('.ux_icons.iconify_on_demand_registry', IconifyOnDemandRegistry::class)
->args([
service('.ux_icons.iconify'),
])
->tag('ux_icons.registry')

->set('.ux_icons.iconify', Iconify::class)
->args([
abstract_arg('endpoint'),
service('http_client')->nullOnInvalid(),
])

->set('.ux_icons.command.import', ImportIconCommand::class)
->args([
service('.ux_icons.iconify'),
service('.ux_icons.local_svg_icon_registry'),
])
->tag('console.command')
;
};
70 changes: 70 additions & 0 deletions src/Icons/config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\UX\Icons\Command\WarmCacheCommand;
use Symfony\UX\Icons\IconCacheWarmer;
use Symfony\UX\Icons\IconRenderer;
use Symfony\UX\Icons\Registry\CacheIconRegistry;
use Symfony\UX\Icons\Registry\ChainIconRegistry;
use Symfony\UX\Icons\Registry\LocalSvgIconRegistry;
use Symfony\UX\Icons\Twig\IconFinder;
use Symfony\UX\Icons\Twig\UXIconExtension;

return static function (ContainerConfigurator $container): void {
$container->services()
->set('.ux_icons.cache_icon_registry', CacheIconRegistry::class)
->args([
service('.ux_icons.chain_registry'),
service('cache.system'),
])

->set('.ux_icons.local_svg_icon_registry', LocalSvgIconRegistry::class)
->args([
abstract_arg('icon_dir'),
])
->tag('ux_icons.registry', ['priority' => 10])

->set('.ux_icons.chain_registry', ChainIconRegistry::class)
->args([
tagged_iterator('ux_icons.registry'),
])

->alias('.ux_icons.icon_registry', '.ux_icons.cache_icon_registry')

->set('.ux_icons.twig_icon_extension', UXIconExtension::class)
->tag('twig.extension')

->set('.ux_icons.icon_renderer', IconRenderer::class)
->args([
service('.ux_icons.icon_registry'),
])
->tag('twig.runtime')

->set('.ux_icons.twig_icon_finder', IconFinder::class)
->args([
service('twig'),
])

->set('.ux_icons.cache_warmer', IconCacheWarmer::class)
->args([
service('.ux_icons.cache_icon_registry'),
service('.ux_icons.twig_icon_finder'),
])

->set('.ux_icons.command.warm_cache', WarmCacheCommand::class)
->args([
service('.ux_icons.cache_warmer'),
])
->tag('console.command')
;
};
31 changes: 31 additions & 0 deletions src/Icons/config/twig_component.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\UX\Icons\Twig\UXIconComponent;
use Symfony\UX\Icons\Twig\UXIconComponentListener;

return static function (ContainerConfigurator $container): void {
$container->services()
->set('.ux_icons.twig_component_listener', UXIconComponentListener::class)
->args([
service('.ux_icons.icon_renderer'),
])
->tag('kernel.event_listener', [
'event' => 'Symfony\UX\TwigComponent\Event\PreCreateForRenderEvent',
'method' => 'onPreCreateForRender',
])

->set('.ux_icons.twig_component.icon', UXIconComponent::class)
->tag('twig.component', ['key' => 'UX:Icon'])
;
};
Loading