Search by

ismailnakkar / laravel-ui-behaviours

ismailnakkar

The Blade side of @ismailnakkar/ui-behaviours, its markup frozen from 1.0: a button that waits for scripts, the status region where a wait is said, the copy region, and an element shown for a choice.

Package info

github.com/ismailnakkar/laravel-ui-behaviours

pkg:composer/ismailnakkar/laravel-ui-behaviours

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.1 2026-12-03 20:43 UTC

This package is auto-updated.

Last update: 2026-12-03 20:46:03 UTC


README

The Blade side of @ismailnakkar/ui-behaviours: the server markup that package's scripts read, in four pieces.

  • A button that waits for scripts: DeclaredWait prints a button shut, naming the scripts it waits for before its first press, the declared wait.
  • The status region: <x-ui-behaviours::hold-status /> prints the layout's region where a wait's words are said to screen readers.
  • The copy region: <x-ui-behaviours::copy-status /> prints the region where a copy button's result is said, with the app's words for both results.
  • An element shown for a choice: ShowIf prints an element shown while a radio, a checkbox or a select holds a value, shown or hidden for the value chosen now.

Install

Needs PHP 8.3+ and Laravel 13.

composer require ismailnakkar/laravel-ui-behaviours

The service provider is discovered on its own; there is no config. The browser half is the npm package @ismailnakkar/ui-behaviours (^1.0.0), which the page boots and whose claim(), hold() and release() the waiting scripts call:

npm i @ismailnakkar/ui-behaviours

The markup is frozen

Every piece prints markup equivalent to the npm package's README examples (the same attributes and values; yours come last), and a conformance test pins each printed string literally. Like the npm package's hold protocol, the markup is frozen from 1.0: a minor only adds (a new piece, a new optional argument), and any other change to what a piece prints is a major. Another package may require this one at ^1.0.0.

A button that waits for scripts

@use('UiBehaviours\DeclaredWait')

<button type="submit" {{ DeclaredWait::attributes('ladder', 'captcha') }}>{{ __('Get link') }}</button>

prints

<button type="submit" disabled="disabled" autocomplete="off" data-wait-for="ladder captcha">Get link</button>
  • disabled shuts the button before any script runs, and autocomplete="off" keeps Firefox from bringing that disabled back on a reload or a Back without the cache, after the waits let it go.
  • data-wait-for lists the waits, each once and in the order given. Each waiter claims its name in the browser and lets go when done; a name nobody claims lets go 5 seconds after the page boots, so a blocked script never traps the visitor.
  • With no waits it prints nothing, so a list built from conditions (...array_filter([...])) leaves an open button open.
  • Names are escaped. A name is one word: a space would make it two waits.

The result is a ComponentAttributeBag: print it beside a component's {{ $attributes }}, or add attributes of your own with ->merge([...]).

Never set disabled on these buttons from a script of your own: hold them by your own reason, so the button opens only once every waiter let go.

The status region

Print one in every layout's <body>, with the page, so it is in place before anything is said:

<body>
<x-ui-behaviours::hold-status class="sr-only" />

prints

<p role="status" data-hold-status class="sr-only"></p>

A declared wait with words says them there and clears them when it lets go; a press's own wait (a form's send) never writes there (Holding a button).

The region is read, never seen: hide it with your own utility class (sr-only, visually-hidden), or with your own CSS on [data-hold-status] and no class. The package ships no CSS. Any attribute you pass is printed after role="status" data-hold-status; with none, the element prints bare.

The copy region

A copy button's data-copy-status names a region by its id, where the result is said, as the button's own marks are not read out:

<button type="button" data-copy="short-url" data-copy-status="short-url-status">…</button>
<x-ui-behaviours::copy-status id="short-url-status" class="sr-only"
    :copied="__('Link copied')" :failed="__('Copy blocked: copy the selected link by hand')" />

prints

<p role="status" data-copied-text="Link copied" data-copy-failed-text="Copy blocked: copy the selected link by hand" id="short-url-status" class="sr-only"></p>
  • copied and failed are required: the words for a copy that worked and for a refusal. They are the app's, and escaped.
  • Any other attribute you pass (the id the buttons name, a class, a data-* of your own) is printed after the words; with none, the element prints bare.
  • Hide it with your own utility class, never hidden: a hidden element is out of the accessibility tree. Buttons may share one region.

An element shown for a choice

In a form, an element of data-show-if shows while the radio, checkbox or select named field holds value. The server prints the elements of the value chosen now shown and the others hidden; the script changes them on a change.

@use('UiBehaviours\ShowIf')

@foreach ($methods as $method)
    <p class="field-hint" {{ ShowIf::attributes('method', $method, $chosen === $method) }}>{{ $hints[$method->value] }}</p>
@endforeach

prints, for the method not chosen,

<p class="field-hint" data-show-if="method=usdt_polygon" hidden="hidden">Your USDT address on the Polygon network.</p>
  • $value is a backed enum's case or a string; a case stands for its value.
  • $shown is whether the element is shown now: hidden is printed when it is not. On a refused submit's page, decide it from the values sent back.
  • The field and value are escaped. A field's name never holds =: the script splits the condition at the first one.

The result is a ComponentAttributeBag, like DeclaredWait's.

Development

composer check runs Pint (--test), PHPStan, then PHPUnit. It needs no database.

Upgrading

1.0 is the first release. Markup printed by hand prints the piece in its place, passing the same attributes and words:

  • <p role="status" data-hold-status …> becomes <x-ui-behaviours::hold-status …/>.
  • <p role="status" data-copied-text="…" data-copy-failed-text="…" …> becomes <x-ui-behaviours::copy-status :copied="…" :failed="…" …/>; a <span> region becomes this <p>, so check its parent takes a block.
  • data-show-if="field=value" @if (…) hidden @endif becomes {{ ShowIf::attributes('field', $value, $shown) }}.
  • disabled autocomplete="off" data-wait-for="…" becomes {{ DeclaredWait::attributes(…) }}.

Licence

MIT, see LICENSE.