All Projects → spatie → Menu

spatie / Menu

Licence: mit
Html menu generator

Labels

Projects that are alternatives of or similar to Menu

react-push-menu
react multi level push menu
Stars: ✭ 37 (-93.14%)
Mutual labels:  menus
cylon-deb
TUI menu driven bash shell script to update and maintain a Debian based Linux distro.
Stars: ✭ 23 (-95.73%)
Mutual labels:  menus
M5ez
Complete interface builder for the M5Stack, an ESP32 based mini tinker-computer
Stars: ✭ 260 (-51.76%)
Mutual labels:  menus
FancyMenu
Source code for the FancyMenu mod.
Stars: ✭ 93 (-82.75%)
Mutual labels:  menus
gui
A very simple library to facilitate the menu creation in the Bukkit API
Stars: ✭ 55 (-89.8%)
Mutual labels:  menus
react-portal-hoc
A stupid HOC to make a stupid portal so you can make stupid modals
Stars: ✭ 14 (-97.4%)
Mutual labels:  menus
umi-plugin-menus
将 umi 生成的 routes 转换成 tree 结构 menus 数据,开发中可直接引入该文件来进行导航菜单的生成
Stars: ✭ 29 (-94.62%)
Mutual labels:  menus
React Pro Sidebar
Customizable and responsive react sidebar library with dropdown menus and unlimited number of nested submenus
Stars: ✭ 359 (-33.4%)
Mutual labels:  menus
dpymenus
Simplified menus for discord.py developers.
Stars: ✭ 28 (-94.81%)
Mutual labels:  menus
Yoshi
A convenient wrapper around the UI code that is often needed for displaying debug menus.
Stars: ✭ 263 (-51.21%)
Mutual labels:  menus
vue-bottom-navigation
Vue bottom navigation
Stars: ✭ 56 (-89.61%)
Mutual labels:  menus
PHP-Quick-Menu
This is a PHP Multilevel Menu class. From nested Json|Array to Html menu (ul)
Stars: ✭ 25 (-95.36%)
Mutual labels:  menus
ml-stack-nav
Customizable, responsive, accessible, easy-to-use multi-level stack navigation menu with slide effect.
Stars: ✭ 20 (-96.29%)
Mutual labels:  menus
ContextMenuSwift
A better version of iOS 13 Context Menu
Stars: ✭ 162 (-69.94%)
Mutual labels:  menus
Wagtailmenus
An app to help you manage and render menus in your Wagtail projects more effectively
Stars: ✭ 275 (-48.98%)
Mutual labels:  menus
RAGENativeUI
No description or website provided.
Stars: ✭ 95 (-82.37%)
Mutual labels:  menus
Qprompt
Python library for quick CLI user prompts, input, and menus.
Stars: ✭ 46 (-91.47%)
Mutual labels:  menus
Gallium
Build desktop applications in Go and HTML.
Stars: ✭ 3,694 (+585.34%)
Mutual labels:  menus
Wp Bootstrap Navwalker
A custom WordPress nav walker class to fully implement the Twitter Bootstrap 4.0+ navigation style (v3-branch available for Bootstrap 3) in a custom theme using the WordPress built in menu manager.
Stars: ✭ 3,290 (+510.39%)
Mutual labels:  menus
Laravel Nestedset
Effective tree structures in Laravel 4-5
Stars: ✭ 3,045 (+464.94%)
Mutual labels:  menus

Html Menu Generator

Latest Version on Packagist Tests Total Downloads

The spatie/menu package provides a fluent interface to build menus of any size in your php application. If you're building your app with Laravel, the spatie/laravel-menu provides some extra treats.

Documentation is available at https://docs.spatie.be/menu.

Upgrading from version 1? There's a guide for that!

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Human Readable, Fluent Interface

All classes provide a human readable, fluent interface (no array configuration). Additionally, you can opt for a more verbose and flexible syntax, or for convenience methods that cover most use cases.

Menu::new()
    ->add(Link::to('/', 'Home'))
    ->add(Link::to('/about', 'About'))
    ->add(Link::to('/contact', 'Contact'))
    ->add(Html::empty())
    ->render();

// Or just...
Menu::new()
    ->link('/', 'Home')
    ->link('/about', 'About')
    ->link('/contact', 'Contact')
    ->empty()
<ul>
    <li><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
    <li><a href="/contact">Contact</a></li>
    <li></li>
</ul>

Or a More Programmatic Approach

Menus can also be created through a reduce-like callable.

$pages = [
    '/' => 'Home',
    '/about' => 'About',
    '/contact' => 'Contact',
];

Menu::build($pages, function ($menu, $label, $url) {
    $menu->add($url, $label);
})->render();
<ul>
    <li><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
    <li><a href="/contact">Contact</a></li>
</ul>

Strong Control Over the Html Output

You can programatically add html classes and attributes to any item in the menu, or to the menu itself.

Menu::new()
    ->addClass('navigation')
    ->add(Link::to('/', 'Home')->addClass('home-link'))
    ->add(Link::to('/about', 'About'))
    ->add(Link::to('/contact', 'Contact')->addParentClass('float-right'))
    ->wrap('div.wrapper')
<div class="wrapper">
    <ul class="navigation">
        <li><a href="/" class="home-link">Home</a></li>
        <li><a href="/about">About</a></li>
        <li class="float-right"><a href="/contact">Contact</a></li>
    </ul>
</div

Not Afraid of Depths

The menu supports submenus, which in turn can be nested infinitely.

Menu::new()
    ->link('/', 'Home')
    ->submenu('More', Menu::new()
        ->addClass('submenu')
        ->link('/about', 'About')
        ->link('/contact', 'Contact')
    );
<ul>
    <li><a href="/">Home</a></li>
    <li>
        More
        <ul class="submenu">
            <li><a href="/about">About</a></li>
            <li><a href="/contact">Contact</a></li>
        </ul>
    </li>
</ul>

Some Extra Treats for Laravel Apps

The Laravel version of the menu package adds some extras like convenience methods for generating URLs and macros.

Menu::macro('main', function () {
    return Menu::new()
        ->action('[email protected]', 'Home')
        ->action('[email protected]', 'About')
        ->action('[email protected]', 'Contact')
        ->setActiveFromRequest();
});
<nav class="navigation">
    {{ Menu::main() }}
</nav>

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Install

You can install the package via composer:

composer require spatie/menu

Usage

Documentation is available at https://docs.spatie.be/menu.

Upgrading to 2.0

Upgrading to 2.0 should be pretty painless for most use cases.

If you're just building menus...

  • The void and voidIf have been removed. These can be replaced by html and htmlIf, with empty strings as their first arguments
  • The prefixLinks and prefixUrls methods have been removed because they were too unpredictable in some case. There currently isn't an alternative for these, besides writing your own logic and applying it with applyToAll.

If you're using custom Item implementations...

  • The HtmlAttributes and ParentAttributes traits have been renamed to HasHtmlAttributes and HasParentAttributes.
  • The HasUrl interface and trait has been removed. Url-related methods now also are part of the Activatable interface and trait.

New features...

  • Added the static Menu::build and non-static Menu::fill methods to create menu's from arrays.
  • The setActive method on Activatable now also accepts a non-strict boolean or callable parameter to set $active to true or false.
  • Menu::html and Menu::htmlIf now accept a $parentAttributes array as their second arguments.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].