2017 © Pedro Peláez
 

library blade-bridge

Easily integrate the Zondicons icon set into your Laravel applications.

image

zondicons/blade-bridge

Easily integrate the Zondicons icon set into your Laravel applications.

  • Friday, March 23, 2018
  • by adamwathan
  • Repository
  • 7 Watchers
  • 74 Stars
  • 7,600 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 8 Versions
  • 23 % Grown

The README.md

Zondicons Blade Bridge

Easily use Zondicons in your Blade templates, either as inline SVG or using SVG sprites., (*1)

Installation

composer require zondicons/blade-bridge

Getting started

In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the Zondicons service provider in config/app.php file:, (*2)

<?php

return [
    // ...
    'providers' => [
        // ...

        Zondicons\ZondiconsServiceProvider::class,

        // ...
    ],
    // ...
];

Publish the Zondicons config file:, (*3)

php artisan vendor:publish --provider="Zondicons\ZondiconsServiceProvider"

If you want to use the sprite sheet instead of rendering every icon inline, make sure you render the hidden sprite sheet somewhere at the end of any layouts that are going to use icons using the svg_spritesheet() helper:, (*4)



<!DOCTYPE html>
<html lang="en">
    <head><!-- ... --></head>
    <body>
        <!-- ... -->

        {{ svg_spritesheet() }}
    </body>
</html>

Configuration

Inside config/zondicons.php you can specify whether you'd like icons to be rendered inline by default, or to reference the icon from the sprite sheet:, (*5)

<?php

return [
    'inline' => true, // Render the full icon SVG inline by default
    // or...
    'inline' => false, // Reference the sprite sheet and render the icon with a `use` tag
    // ...
];

You can also specify any default CSS classes you'd like to be applied to your icons using the class option:, (*6)

<?php

return [
    'class' => 'icon', // Add the `icon` class to every SVG icon when rendered
];

You can specify multiple classes by separating them with a space, just like you would in an HTML class attribute:, (*7)

<?php

return [
    'class' => 'icon inline-block',
];

Basic Usage

To insert a Zondicon in your template, simply use the @icon Blade directive, passing the name of the icon and optionally any additional classes:, (*8)

<a href="/settings">
    @icon('cog', 'icon-lg') Settings
</a>


<a href="/settings">
    <svg class="icon icon-lg">
        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#zondicon-cog"></use>
    </svg>
    Settings
</a>

To add additional attributes to the rendered SVG tag, pass an associative array as the third parameter:, (*9)

<a href="/settings">
    @icon('cog', 'icon-lg', ['alt' => 'Gear icon']) Settings
</a>


<a href="/settings">
    <svg class="icon icon-lg" alt="Gear icon">
        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#zondicon-cog"></use>
    </svg>
    Settings
</a>

If you have attributes to declare but no additional class, you can pass an associative array as the second parameter instead:, (*10)

<a href="/settings">
    @icon('cog', ['alt' => 'Gear icon']) Settings
</a>


<a href="/settings">
    <svg class="icon" alt="Gear icon">
        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#zondicon-cog"></use>
    </svg>
    Settings
</a>

If you'd like to override the default class name, specify a class in the attributes array:, (*11)

<a href="/settings">
    @icon('cog', ['class' => 'overridden']) Settings
</a>


<a href="/settings">
    <svg class="overridden">
        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#zondicon-cog"></use>
    </svg>
    Settings
</a>

If you'd like to add an attribute that needs no value, just specify it without a key:, (*12)

<a href="/settings">
    @icon('cog', ['data-foo']) Settings
</a>


<a href="/settings">
    <svg class="icon" data-foo>
        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#zondicon-cog"></use>
    </svg>
    Settings
</a>

If you'd like, you can use the svg_icon helper directly to expose a fluent syntax for setting icon attributes:, (*13)

<a href="/settings">
    {{ svg_icon('cog')->alt('Alt text')->dataFoo('bar')->dataBaz() }} Settings
</a>


<a href="/settings">
    <svg class="icon" alt="Alt text" data-foo="bar" data-baz>
        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#zondicon-cog"></use>
    </svg>
    Settings
</a>

You can force an icon to reference the sprite sheet even if you are rendering inline by default by using the fluent syntax and chaining the sprite method:, (*14)

<a href="/settings">
    {{ svg_icon('cog', 'icon-lg')->sprite() }} Settings
</a>


<a href="/settings">
    <svg class="icon icon-lg" data-foo>
        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#zondicon-cog"></use>
    </svg>
    Settings
</a>

Similarly, you can force an icon to render inline even if you are using sprites by default by chaining the inline method:, (*15)

<a href="/settings">
    {{ svg_icon('cog', 'icon-lg')->inline() }} Settings
</a>


<a href="/settings">
    <svg class="icon icon-lg" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
        <path d="M3.938 6.497a6.958 6.958 0 0 0-.702 1.694L0 9v2l3.236.809c.16.6.398 1.169.702 1.694l-1.716 2.861 1.414 1.414 2.86-1.716a6.958 6.958 0 0 0 1.695.702L9 20h2l.809-3.236a6.96 6.96 0 0 0 1.694-.702l2.861 1.716 1.414-1.414-1.716-2.86a6.958 6.958 0 0 0 .702-1.695L20 11V9l-3.236-.809a6.958 6.958 0 0 0-.702-1.694l1.716-2.861-1.414-1.414-2.86 1.716a6.958 6.958 0 0 0-1.695-.702L11 0H9l-.809 3.236a6.96 6.96 0 0 0-1.694.702L3.636 2.222 2.222 3.636l1.716 2.86zM10 13a3 3 0 1 0 0-6 3 3 0 0 0 0 6z" fill-rule="evenodd">
        </path>
    </svg>
    Settings
</a>

The Versions

23/03 2018

dev-master

9999999-dev

Easily integrate the Zondicons icon set into your Laravel applications.

  Sources   Download

MIT

The Requires

 

by Adam Wathan
by Steve Schoger

06/12 2017

v0.1.5

0.1.5.0

Easily integrate the Zondicons icon set into your Laravel applications.

  Sources   Download

MIT

The Requires

 

by Adam Wathan
by Steve Schoger

08/09 2017

v0.1.4

0.1.4.0

Easily integrate the Zondicons icon set into your Laravel applications.

  Sources   Download

MIT

The Requires

 

by Adam Wathan
by Steve Schoger

17/04 2017

v0.1.3

0.1.3.0

  Sources   Download

MIT

The Requires

 

by Adam Wathan
by Steve Schoger

17/04 2017

v0.1.2

0.1.2.0

  Sources   Download

MIT

The Requires

 

by Adam Wathan
by Steve Schoger

19/01 2017

v0.1.1

0.1.1.0

  Sources   Download

MIT

The Requires

 

by Adam Wathan
by Steve Schoger

14/10 2016

v0.1.0

0.1.0.0

  Sources   Download

MIT

The Requires

 

by Adam Wathan
by Steve Schoger

29/08 2016

dev-temp

dev-temp

  Sources   Download

The Requires

 

The Development Requires

by Adam Wathan