承接 sb2-media/svg-icon-system 相关项目开发

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

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

sb2-media/svg-icon-system

Composer 安装命令:

composer require sb2-media/svg-icon-system

包简介

A system for inlining accesible SVG icons in WordPress themes

README 文档

README

A system for inlining accessible SVG icons in WordPress themes.

Features

  • Render SVG icons inline using a simple function call in your WordPress templates.
  • SVG icons are deconstructed and rebuilt in adherence to accessibility standards and guidelines.
  • A single config file is used to configure all SVG icons.
  • Choose whether to store SVG files in theme or plugin.

Requirements

Installation

  1. From the command line navigate to your WordPress plugins directory.
  2. Run this command: composer create-project sb2-media/svg-icon-system.
  3. Change into the SVG Icon System directory: cd svg-icon-system.
  4. Run npm install.
  5. Run npm run dev.
  6. Run composer dump-autoload -o.
  7. In the WordPress dashboard, navigate to the Plugins page and locate the menu item that reads “SVG Icon System.”
  8. Click on Activate.

Usage

Icon Folder Storage

You may choose to store your SVG icon files in this plugin or anywhere in your theme. The plugin will strip the files of all <svg>, <title> and <desc> tags and reconstruct them in adherence to accessibility standards and guidelines.

Plugin

By default SVG icons are stored in the assets/icons folder in this plugin and then copied over to dist/icons when the Laravel Mix build process is run. Store your SVG icons in the assets/icons and run the command npm run dev or npm run production in the plugin's root folder if you wish to utilize the default behavior. npm run dev or npm run production must be run after adding new SVG icon files to storage.

The assets/icons directory contains a SVG icon file for demonstration purposes.

  • icon_menu.svg

Theme

If you wish to store your SVG icon files in your theme, simply change the value of the icon_folder_path in config/svg-icons.php to the path where the files will be stored. A few examples are given in the comments.

Config

A single config file config/svg-icons.php is used to declare and configure the SVG icons. The configuration follows this convention:

    $icon_id => [
        'filename'              => $value,  // Required, MUST match the file name of the SVG icon
        'title'                 => $value,  // Optional but highly recommended for standalone, meaningful icons
        'description'           => $value,  // Optional but recommended for standalone, meaningful icons
        'viewbox_x'             => $value,  // Optional, will default to '0' if left blank
        'viewbox_y'             => $value,  // Optional, will default to '0' if left blank
        'viewbox_width'         => $value,  // Recommended, width must be set if left blank
        'viewbox_height'        => $value,  // Recommended, height must be set if left blank
        'width'                 => $value,  // Optional, viewbox_width must be set if left blank
        'height'                => $value,  // Optional, viewbox_height must be set if left blank
        'preserve_aspect_ratio' => $value,  // Optional
        'class' => $value,  // Optional, custom classes to add
        'style'                 => $value,  // Optional
    ],

Notes

  • The filename MUST match the name of the SVG icon file.
  • Standalone, meaningful icons should have a title and possibly a description set in their configuration. If a title (and description) is declared, the plugin will render the SVG icon with the aria-labelledby= attribute with a unique ID to link the title (and description) to their respective <title> (and <desc>) elements.
  • Purely decorative icons do not need a title and description. Leave them blank in the config and the aria-hidden="true" attribute will be added to the <svg> element instead.
  • Either width and height or viewbox_width and viewbox_height attributes MUST be set in the config. If only a width and height are declared, viewbox_width and viewbox_height will inherit their values. If only viewbox_width and viewbox_height values are set, width and height attributes will not be added to the <svg> element.
  • The preservedAspectRatio and style attributes are optional.

Examples

File icon_menu.svg

<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 20 16" xmlns="http://www.w3.org/2000/svg">
  <rect x="0.016" y="6.41" width="19.969" height="3.18" style="fill: rgb(51, 51, 51);"/>
  <rect x="0.014" y="12.656" width="19.969" height="3.18" style="fill: rgb(51, 51, 51);"/>
  <rect x="0.017" y="0.164" width="19.969" height="3.18"  style="fill: rgb(51, 51, 51);"/>
</svg>

Config with the bare minimum set:

    'menu' =>   [
        'filename'              => 'icon_menu',
        'title'                 => '',
        'desc'                  => '',
        'viewbox_x'             => '',
        'viewbox_y'             => '',
        'viewbox_width'         => '20',
        'viewbox_height'        => '16',
        'width'                 => '',
        'height'                => '',
        'preserve_aspect_ratio' => '',
        'class' => '',
        'style'                 => '',
    ],

Output:

<svg class="icon icon-menu" aria-hidden="true" viewBox="0 0 20 16" role="img">        
    <rect x="0.016" y="6.41" width="19.969" height="3.18" style="fill: rgb(51, 51, 51);"></rect>
    <rect x="0.014" y="12.656" width="19.969" height="3.18" style="fill: rgb(51, 51, 51);"></rect>
    <rect x="0.017" y="0.164" width="19.969" height="3.18" style="fill: rgb(51, 51, 51);"></rect>
</svg>

Config with all attributes set:

    'menu' =>   [
        'filename'              => 'icon_menu',
        'title'                 => 'Menu icon',
        'desc'                  => 'Three equal width horizontal bars stacked on top of one another to symbolize a menu',
        'viewbox_x'             => '0',
        'viewbox_y'             => '0',
        'viewbox_width'         => '20',
        'viewbox_height'        => '16',
        'width'                 => '20',
        'height'                => '16',
        'preserve_aspect_ratio' => 'xMinYMin',
        'class'                 => 'custom-class',
        'style'                 => 'color: red;',
    ],

Output:

<svg class="icon icon-menu custom-class" aria-labelledby="title-nYY desc-nYY" width="20" height="16" viewBox="0 0 20 16" preserveAspectRatio="xMinYMin" style="color: red;" role="img">
    <title id="title-nYY">Menu icon</title>
    <desc id="desc-nYY">Three equal width horizontal bars stacked on top of one another to symbolize a menu</desc>    
    <rect x="0.016" y="6.41" width="19.969" height="3.18" style="fill: rgb(51, 51, 51);"></rect>
    <rect x="0.014" y="12.656" width="19.969" height="3.18" style="fill: rgb(51, 51, 51);"></rect>
    <rect x="0.017" y="0.164" width="19.969" height="3.18" style="fill: rgb(51, 51, 51);"></rect>
</svg>

Function

Icons defined in the config can be placed anywhere in your WordPress templates with the get_svg_icon( $icon_id ) function call.

<button class="menu-toggle">
    <?php get_svg_icon( 'menu' ); ?>
</button>

License

SVG Icon System is licensed under the GPL v2 or later.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

A copy of the license is included in the root of the plugin’s directory. The file is named LICENSE.

Credits

Portions of this plugin uses code and concepts adapted from Carl Alexander and Tonya Mork's Fulcrum plugin.

sb2-media/svg-icon-system 适用场景与选型建议

sb2-media/svg-icon-system 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 sb2-media/svg-icon-system 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2017-08-11