nedarta/yii2-extended-navbar

An extended NavBar widget for Yii2 with support for external items and Bootstrap 5.

1.0.1 2025-02-08 08:14 UTC

This package is auto-updated.

Last update: 2025-04-08 08:46:39 UTC


README

License Packagist Version

A Bootstrap 5-compatible NavBar widget for Yii2 that adds support for external navigation items and enhanced customization options.

Key Features

  • Bootstrap 5 compatibility with modern navbar styling
  • External navigation items that remain visible outside the collapsible section
  • Flexible positioning options for external items (left, right, or before toggle)
  • Support for dynamic dropdowns in both regular and external items
  • Comprehensive customization options for all navbar elements

Installation

composer require nedarta/yii2-extended-navbar

Basic Usage

use nedarta\navbar\ExtendedNavBar;
use yii\helpers\Html;

echo ExtendedNavBar::widget([
    'brandLabel' => 'My Company',
    'brandUrl' => Yii::$app->homeUrl,
    'options' => [
        'class' => 'navbar-expand-lg navbar-light bg-light',
    ],
    'externalItems' => Nav::widget([
        'options' => ['class' => 'navbar-nav ms-auto d-flex flex-row gap-2 me-3'], //configure as needed
        'items' => [
            ['label' => 'EN', 'url' => ['/site/language', 'lang' => 'en']],
            ['label' => 'LV', 'url' => ['/site/language', 'lang' => 'lv']],
        ],
    ]),
]); ?>

<?= Nav::widget([
    'options' => ['class' => 'navbar-nav ms-auto'],
    'items' => [
        ['label' => 'Home', 'url' => ['/site/index']],
        ['label' => 'About', 'url' => ['/site/about']],
        ['label' => 'Contact', 'url' => ['/site/contact']],
    ],
]);

Configuration Options

External Items Structure

Each external item can be:

// Simple link
['label' => 'Home', 'url' => ['/site/index']]

// Dropdown menu
[
    'label' => 'Account',
    'items' => [
        ['label' => 'Profile', 'url' => ['/user/profile']],
        ['label' => 'Settings', 'url' => ['/user/settings']],
        '<hr class="dropdown-divider">',
        ['label' => 'Logout', 'url' => ['/site/logout']],
    ],
]

// Custom HTML
Html::tag('li', 
    Html::a('<i class="fas fa-user"></i>', ['/profile'], ['class' => 'nav-link']), 
    ['class' => 'nav-item']
)

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

  • Create an issue in the GitHub repository
  • Contact the maintainer at GitHub

Developed with ❤️ by Edgars Karlsons (nedarta)