Replies: 1 comment 1 reply
-
|
Thanks @BenQoder for looking into this, and for making the transition easier for LiveWire users.
Take a look at Loading State for existing tools to show loading state after a user interaction. In particular:
Lastly I encourage people to use another prefix than Hope that helps! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Coming from using Livewire and now using Unpoly, I was unsatisfied when I found out that there was no direct or similar feature like Livewire loading.
So I worked on a macro to replicate that functionality, and it would be nice to have this as a native Unpoly feature.
Features
up-follow) and forms (up-submit)Installation
Simply include the macro in your HTML after loading Unpoly:
The Macro
Usage Examples
1. Basic Loading State
Shows loading indicator for any request:
2. Targeted Loading
Different indicators for different buttons:
3. Loading with Delay
Indicator appears after a delay to prevent flickering on fast requests:
4. Hide/Show Elements
Hide elements during loading and show loading indicators:
5. Form Submission Loading
Works with form submissions using
up-submit:6. CSS Class Control
Toggle CSS classes instead of display properties:
7. Custom Attribute Control
Set custom attributes during loading:
Attributes Reference
up-loading<div up-loading>Loading...</div>up-loading-remove<span up-loading-remove>Ready</span>up-loading-targetup-loading-target="#my-button"up-loading-delayup-loading-delay="500"up-loading-classup-loading-class="loading"up-loading-attrup-loading-attr="aria-busy"How It Works
The macro listens to Unpoly's request lifecycle events:
up:request:load- Triggered when a request startsup:request:loaded- Triggered when a request completes successfullyup:request:aborted- Triggered when a request is abortedup:form:submit- Triggered when a form is submittedWhen a request starts, elements with
up-loadingare shown and elements withup-loading-removeare hidden. When the request ends (success or abort), the states are reversed.Targeting
up-loading-target: Loading state only applies when the specified element triggers a requestComparison with Livewire
This macro replicates Livewire's
wire:loadingfunctionality:wire:loadingup-loadingwire:loading.removeup-loading-removewire:target="method"up-loading-target="#element"wire:loading.delay="500ms"up-loading-delay="500"wire:loading.class="loading"up-loading-class="loading"wire:loading.attr="disabled"up-loading-attr="disabled"Beta Was this translation helpful? Give feedback.
All reactions