brosland/modals

The implementation of Bootstrap modals for Nette framework.

v2.1.0 2020-01-18 14:59 UTC

This package is auto-updated.

Last update: 2024-10-31 00:23:18 UTC


README

This package provides a simple management of modals for Nette framework (e.g. Bootstrap modals).

List of components:

  • Modal - abstract class for a modal
  • ConfirmationModal - simple modal for a confirmation

Installation

The best way to install is using Composer:

$ composer require brosland/modals

1. (optional) Register DI extension ModalsExtension in your neon config. This step you can skip if you use Bootstrap 4.

brosland.modals:
	version: 'v5'

extensions:
	brosland.modals: Brosland\Modals\DI\ModalsExtension

2. Setup ModalManager: the best practice is to do it in your base presenter.

  • add ModalManagerTrait
  • implement interface ModalManager
  • add update of modal into the method beforeRender
use Brosland\Modals\UI\ModalManager;
use Brosland\Modals\UI\ModalManagerTrait;
use Nette\Application\UI\Presenter;

abstract class BasePresenter extends Presenter implements ModalManager
{
	use ModalManagerTrait;

	protected function beforeRender(): void
	{
		parent::beforeRender();

		$this->updateModal();
	}

	// ...

3. Add placeholder for a modal to your base layout

{snippet modal}{ifset $modal}{control $modal}{/ifset}{/snippet}

4. Install Webpack and Naja.

5. Copy src/Brosland/Modals/UI/Modal.js to your directory with Javascript files and register it in Naja.

6. Don't forget to rebuild Webpack bundles.