mesavolt/mdi-php

为PHP 7.1+提供简单MDI集成

v1.1.0 2018-08-24 14:41 UTC

This package is auto-updated.

Last update: 2024-09-08 07:09:35 UTC


README

轻松摆脱使用MaterialDesignIcons网络字体!

Latest Stable Version Build Status Coverage Status License

安装

将此包添加到您的项目中

composer require mesavolt/mdi-php

使用@mdi/svg npm包

@mdi/svg npm包添加到您的项目中

yarn add @mdi/svg

# or, using npm
npm install @mdi/svg

图标位置将被自动检测。

其他

如果您没有使用上述文档中的任何方法安装图标包,您可以全局配置图标位置。这应该在第一次使用Mdi::mdi函数之前完成。

Mdi::withIconsPath(__DIR__.'/../../../node_modules/@mdi/svg/svg/');

使用

在您的视图中使用它

<button>
    <?php echo Mdi::mdi('account'); ?>
    My account
</button>

mdi函数提供了4个参数来自定义其输出

  • 图标(您可以提供accountmdi-accountmdi mdi-account
  • 其类(例如fill-muted
  • 其大小(默认为24px)
  • 一些将被添加到<svg>标签中的额外属性(例如['aria-label' => 'My account']

默认属性

您可以添加自定义默认属性,或编辑和删除提供的默认值。

Mdi::withDefaultAttributes([
    'data-toggle' => 'tooltip',     // Add a new one
    'role' => 'img',                // Replace default `presentation` value with `img`
    'xmlns' => null,                // Remove default `xmlns` attribute
]);

集成到Twig中

只需将Mdi::mdi注册为Twig简单函数即可开始!

$twigEnv->addFunction(new \Twig_SimpleFunction('mdi', [Mdi::class, 'mdi'], ['is_safe' => ['html']]));
<button>
    {{ mdi('account', 'fill-muted', 42, {'aria-label': 'My account icon'}) }}
    My account
</button>