GitHub

Layers

A menu, a tooltip or a popover is a layer: an element that floats above the page. The server creates it as an instance of ContextualLayer, with the behaviors it needs, next to the button that sent the request. See Layer in the docs of bigpipe-util, and TransportMarker::relative().
  • instance($module, $args)

    The browser creates new ContextualLayer(...$args) once; call() calls its methods.

  • TransportMarker::relative()

    The element that sent the request: the menu is placed next to the button that was clicked.

  • TransportMarker::module()

    The behaviors are classes: HideOnBlur, HideOnEscape, HideOnSuccess, DestroyOnHide.

  • ModuleRegistry

    The layers and behaviors of bigpipe-util are modules the server can require by name.

Controller.php
use dobron\BigPipe\TransportMarker;

$layer = 'bigpipe-util/dist/core/layer/';

$response = new AsyncResponse();

$response
    ->instance($layer . 'ContextualLayer', [
        view('menu')->render(),
        [
            // the button that sent the request
            'context' => TransportMarker::relative(),
            'position' => 'below',
            'hideOnSuccess' => true,
            'behaviors' => [
                TransportMarker::module($layer . 'HideOnBlur'),
                TransportMarker::module($layer . 'HideOnEscape'),
                TransportMarker::module($layer . 'HideOnSuccess'),
                TransportMarker::module($layer . 'DestroyOnHide'),
            ],
        ],
    ])
    ->call('show');

return $response->send();
Try it

A menu from the server

Each button asks the server for a menu, and the menu opens next to the button that sent the request. Click outside of it or press Esc to hide it; pick an item: its request succeeds and the menu hides itself. A hidden menu is destroyed.