anaseqal/nova-sidebar-icons

A Laravel Nova tool.

Installs: 185 146

Dependents: 0

Suggesters: 0

Security: 0

Stars: 50

Watchers: 3

Forks: 5

Open Issues: 3

Language:CSS

0.0.3 2019-08-29 18:49 UTC

This package is not auto-updated.

Last update: 2024-04-19 17:11:10 UTC


README

Set icons for resources in sidebar.

screenshot

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require anaseqal/nova-sidebar-icons

Publish navigation view file:

php artisan vendor:publish --provider="Anaseqal\NovaSidebarIcons\ToolServiceProvider" --force

Register the tool in NovaServiceProvider:

use Anaseqal\NovaSidebarIcons\NovaSidebarIcons;
...

public function tools()
    {
        return [
            new NovaSidebarIcons,
            ...
        ];
    }

Usage

Set the icon in your Nova resource, for example:

/**
 * The icon of the resource.
 *
 * @return string
 */
public static function icon() 
{
    // Assuming you have a blade file containing an image
    // in resources/views/vendor/nova/svg/icon-user.blade.php
    return view('nova::svg.icon-user')->render();
}

This is the recommended approach. In the example above we have used a blade file containing an svg, but if you'd want to it's is possible return the entire svg string

Examples of other approaches

// By using an image tag
public static function icon() 
{
    return '<img src="/path/to/image.svg" />';
}

// Or simply return it as a string
public static function icon() 
{
    return '<svg class="sidebar-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
                <path fill="var(--sidebar-icon)" d="M4.06 13a8 8 0 0 0 5.18 .... e.t.c."/>
            </svg>';
}
    

Backwards compatibility

Please note that this package used to use a static $icon property on the resource. This has been replaced with the static icon method. The icon property is still supported to preserve backwards compatibility.

License

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