承接 husseinalhammad/fontawesome-svg 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

husseinalhammad/fontawesome-svg

Composer 安装命令:

composer require husseinalhammad/fontawesome-svg

包简介

PHP class to add Font Awesome 5+'s SVG icons inline without Javascript.

README 文档

README

A PHP class that can be used to add Font Awesome 6+'s SVG icons inline without Javascript.

Installation

You can install it using Composer:

composer require husseinalhammad/fontawesome-svg

Or you can download the FontAwesomeSVG.php file and include it manually.

Usage

Files

  • Download Font Awesome (Free or Pro)
  • Get the folder advanced-options/raw-svg and place it in your project
  • Add svg-with-js/css/fa-svg-with-js to your document (or write your own CSS)

Examples

// $dir = directory where SVG files are
$FA = new FontAwesomeSVG($dir);

echo $FA->get_svg('fa-solid fa-file');

Add custom classes:

echo $FA->get_svg('fa-solid fa-file', ['class' => 'my-custom-class another-class']);

Remove default class .svg-inline--fa:

echo $FA->get_svg('fa-solid fa-file', ['default_class' => false]);

Change <path> fill (default is currentColor):

echo $FA->get_svg('fa-solid fa-file', ['fill' => '#f44336']);

Add <title></title>:

echo $FA->get_svg('fa-solid fa-file', ['title' => 'My accessible icon']);

Multiple options at once:

echo $FA->get_svg('fa-solid fa-file', [
    'class' => 'my-custom-class another-class',
    'default_class' => false,
    'title' => 'My title',
    'role' => 'img',
    'fill' => '#ffffff',
]);

Customise duotone icons:

echo $FA->get_svg('fa-duotone fa-laugh-wink', [
    'primary' => [
        'fill'    => '#e64980',
    ],
    'secondary' => [
        'fill'    => '#fcc417',
        'opacity' => '1',
    ],
]);
Option What it means
class Adds classes to the SVG tag
default_class If set to false, the default CSS class won't be added to the SVG tag. Deafult: true.
inline_style Whether to add duotone styles as inline style to the <svg> tag. Deafult: true.
title Adds a <title> inside the SVG tag for semantic icons
title_id Adds an id attribute to <title> and adds aria-labelledby on the SVG tag with the same value
role The value of the role attribute in the SVG tag. Default: img
fill The value of the fill attribute in the <path> inside the SVG. Default: currentColor
primary Duotone primary options (see table below)
secondary Duotone secondary options (see table below)

Duotone

Requires v5.10.0 or greater, and a FontAwesome Pro license

Sharp

Requires v6.4.0 or greater, and a FontAwesome Pro license

echo $FA->get_svg('fa-sharp fa-light fa-file');
echo $FA->get_svg('fa-sharp fa-regular fa-file');
echo $FA->get_svg('fa-sharp fa-solid fa-file');

options

If inline_style is enabled, the value of fill and opacity are also used in the inline style on <svg> tag.

Option What it means
fill The value of the fill attribute in the <path> inside the SVG. Default: currentColor
opacity The value of the opacity attribute in the <path> inside the SVG.

Examples:

Single colour:

echo $FA->get_svg('fad fa-laugh-wink', [
    'fill' => '#e64980',
]);

Swapping Layer Opacity:

echo $FA->get_svg('fad fa-laugh-wink', [
    'fill'  => '#e64980',
    'class' => 'fa-swap-opacity',
]);

Single colour with custom opacity:

echo $FA->get_svg('fad fa-laugh-wink', [
    'fill' => '#e64980',
    'secondary' => [
        'opacity' => '0.2',
    ],
]);

Custom colours and opacity:

echo $FA->get_svg('fad fa-laugh-wink', [
    'primary' => [
        'fill'    => '#e64980',
        'opacity' => '0.5',
    ],
    'secondary' => [
        'fill'    => '#fcc417',
        'opacity' => '1',
    ],
]);

Aliases

The short aliases from version 5 are still supported

echo $FA->get_svg('fab fa-twitter');
echo $FA->get_svg('fad fa-file');
echo $FA->get_svg('fal fa-file');
echo $FA->get_svg('far fa-file');
echo $FA->get_svg('fas fa-file');

// And the new shorthands for thin and sharp
echo $FA->get_svg('fat fa-file'); // thin
echo $FA->get_svg('fasl fa-file'); // sharp-light
echo $FA->get_svg('fasr fa-file'); // sharp-regular
echo $FA->get_svg('fass fa-file'); // sharp-solid

Accessibility

The below is implemented based on:

role attribute

role="img" is added to the SVG tag by default:

<svg role="img"></svg>

<title>, aria-labelledby

You can set a <title>, an id for the <title> and the aria-labelledby attribute will be added automatically:

echo $FA->get_svg('fa-solid fa-file', [
    'title' => 'File',
    'title_id' => 'file-id',
]);
<svg aria-labelledby="file-id">
  <title id="file-id">File</title>
</svg>

aria-* attributes

You can add any aria-* attribute to the SVG tag:

echo $FA->get_svg('fa-solid fa-file', [
    'aria-label' => 'File',
]);
<svg aria-label="File"></svg>

aria-hidden attribute

aria-hidden="true" is added to the SVG tag by default unless <title id=""> (and aria-labelledby) or aria-label is set.

echo $FA->get_svg('fa-solid fa-file');
<svg aria-hidden="true"></svg>

husseinalhammad/fontawesome-svg 适用场景与选型建议

husseinalhammad/fontawesome-svg 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.04k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2018 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 14.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 18
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 18
  • Watchers: 4
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-17