Feedback

Loadable

A container with four states, loading, done, empty and failed, that shows a spinner, the content, a "Nothing to show" empty state or an error message for each. The charts, editors and tk:fetchable are built on it; use it for content of your own that loads in the browser.

Blade

A spinner for one second, then "Loaded!". load(callback) shows the spinner, runs the callback, and shows the content when it finishes, or the error message with the error's text when it throws. load(callback, true) loads without the spinner and the started event that one time, as silent does for every load, and clear() shows the empty state.

Loading data #

/api/report stands for an endpoint of your app that returns JSON with a total. The callback stores what it fetched in the outer Alpine scope, and the content reads it once loading finishes. A failed request (a network error, or a JSON parse error) shows the error message instead.

Blade

Your own states #

/api/items stands for an endpoint of your app that returns a JSON list of items with a name. Each named slot replaces the default content of that state: the skeleton while loading, the message with a retry button when the request fails, and "No items yet." after clear().

Blade

Error state #

When the callback throws, the error message shows with the error's text.

Blade

Empty state #

clear() shows the empty state, "Nothing to show" by default.

Blade

Reloading and silent #

load(callback, true) reloads once without the spinner; silent does it for every load, keeping the previous content until the new one is ready.

Blade

Events #

started, completed and failed fire on the tag. Here completed flips an Alpine flag and failed calls a Livewire action.

Ready:
Failures reported: 0
Blade

Customization #

Classes go to the wrapper; loading:, error: and empty: reach the default states, so loading:variant changes the spinner.

Blade

Reference

tk:loadable

Prop Type Default Description
silent bool false Skips the spinner: the previous content stays until the new one is ready.

x-data on the tag replaces the default loadable Alpine component with another registered one that provides the same methods, as the chart and editor components do.

Slots

Slot Description
default The content, shown when loading finished. Only its first root element is rendered.
completed Replaces the default slot.
loading Replaces the spinner.
error Replaces the error message. error holds the error.
empty Replaces the "Nothing to show" empty state, shown after clear().

Events

Event Detail When
started Loading started (not with silent).
completed Loading finished.
failed Loading threw an error.

Prefixes

Prefix Goes to
loading: The spinner (tk:loading): loading:variant="dots".
error: The error message (tk:error).
empty: The "Nothing to show" tk:empty (empty:title="No data", empty:icon="mdi:chart-line").

Events

Events are dispatched on the tk:loadable element and do not bubble: listen on the tag itself.

With Alpine:

blade

Calling a Livewire action:

blade

Customization

Classes and attributes go to the wrapper <div>. To reach the default states, prefix the attribute (listed in the Reference above).

blade

Accessibility

The spinner and the error message are polite live regions, so the start and the failure of loading are announced.

Behavior notes

  • Each state is rendered with x-if: the content does not exist in the page until loading finishes, so Alpine expressions inside it can read data the callback set.
  • Only the first root element of each slot is rendered; wrap several elements in one.
  • A new load() cancels the result of the previous one: only the last finishes the loading.
  • The wrapper has wire:ignore: a Livewire update does not touch what was loaded.