定制 hebinet/laravel-svg-icons 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hebinet/laravel-svg-icons

Composer 安装命令:

composer require hebinet/laravel-svg-icons

包简介

Allows to inline svg icons via a simple blade directive

README 文档

README

Allows to inline Font Awesome 5+'s SVG icons without javascript via a simple Laravel Blade directive.

Installation

Install composer package

You can install it using Composer:

composer require hebinet/laravel-svg-icons

Optionally, you can also publish the config file of the package.

php artisan vendor:publish --provider="Hebinet\SvgIcons\ServiceProvider" --tag=config

Install SVG font

As a next step you need to install Font Awesome via npm:

npm install @fortawesome/fontawesome-free

The path to the SVG files in the npm package is configured by default.

But you can change the path via the config parameter path_to_fontawesome in config\icons.php if you want to.

Add Font Awesome SVG CSS-Style

To display the icons correctly you need to add an additional css file which can be found in the npm @fortawesome/fontawesome-free package.

I would recommend using Webpack to publish the file in the public/css directory.

// Inside webpack.mix.js

mix.copy('node_modules/@fortawesome/fontawesome-free/css/svg-with-js.css', 'public/css/svg-icons.css');

Afterwards you need to add the svg-icons.css file in the head section of your site.

<link rel="stylesheet" href="{{ mix('/css/svg-icons.css') }}"/>

In order to inherit the font color of the parent correctly you have to add the following style declaration in your global CSS file

svg.svg-inline--fa {
    fill: currentColor;
}

Usage

You can now add the new @icon blade directive to add the inline SVG icon. The argument for the directive is the same as you would use for Font Awesome icons.

You can use the directive as followed:

@icon('{style} {icon} {optional addtitonal classes},{optional title}')

Examples

Usage in a Blade view:

{{-- Plain icon --}}
@icon('fas fa-download')

{{-- Icon with additional size class --}}
@icon('fas fa-download fa-5x')

{{-- And here with an additional title --}}
@icon('fas fa-download,Download button')
@icon('fas fa-download fa-5x,Download button')

Usage in a Controller method or normal PHP code:

$icon = new Hebinet\SvgIcons\Icon('fas fa-download');

$iconWithAddClass = new Hebinet\SvgIcons\Icon('fas fa-download fa-5x');

$iconWithTitle = new Hebinet\SvgIcons\Icon('fas fa-download,Download Button');

// You can now render the icon to a string and do what ever you want with it
$svgContent = $icon->render();

Optionally you can omit the icon string from the constructor and instead provide it in the render method like this

$icon = new Hebinet\SvgIcons\Icon();
$svgContent = $icon->render('fas fa-download');

This package also provides an Icon Facade. Unfortunately, the way Facades work, you have to provide the icon string in the render method instead of the constructor.

First you have to 'register' the Facade in you app.php file at the end of the alias array like this

[
    ...

    'Icon' => Hebinet\SvgIcons\Facades\Icon::class,
]

After that you can use the Facade like this

$svgContent = Icon::render('fas fa-check');

Additional Route

If the setting $config['route']['enabled'] is true (default: true), an additional route will be registered to provide an Url-Based fetch for the SVG Icon Content.

With this route you can load the Icon via a normal GET-Operation, so you can use the Icon also in "Non Blade"-Scenarios like Vue-Components.

You can use it like this:

/svgIcons/{style}/{icon}.svg
or
/svgIcons/{style}/{icon}.svg?title={title}

It will throw an Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the requested icon doesn't exist.

Examples

// Plain icon
/svgIcons/fas/fa-download.svg

// And here with an additional title
/svgIcons/fas/fa-download.svg?title=Download button

Accessibility

  • role="img" is added to the SVG tag by default
  • aria-hidden="true" is added to the SVG tag by default unless a <title> is set

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email office@hebinet.at instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

hebinet/laravel-svg-icons 适用场景与选型建议

hebinet/laravel-svg-icons 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 635 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 07 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「hebinet」 「laravel-svg-icons」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 hebinet/laravel-svg-icons 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hebinet/laravel-svg-icons 我们能提供哪些服务?
定制开发 / 二次开发

基于 hebinet/laravel-svg-icons 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

与 hebinet/laravel-svg-icons 相关的其它包

同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:

统计信息

  • 总下载量: 635
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-07-26