-
Notifications
You must be signed in to change notification settings - Fork 223
/
offline-state.blade.php
executable file
·47 lines (30 loc) · 1.75 KB
/
offline-state.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
* [Toggling elements](#toggling-elements)
* [Toggling classes](#toggling-classes)
* [Toggling attributes](#toggling-attributes)
It's sometimes important to notify a user if they have lost their internet connection. Livewire provides helpful utilities to perform actions based on a user's "offline" state.
## Toggling elements {#toggling-elements}
You can show an element on the page when the user goes "offline", by adding the `wire:offline` attribute.
@component('components.code')
<div wire:offline>
You are now offline.
</div>
@endcomponent
This `<div>` will automatically be hidden by default, and shown to the user when the browser goes offline.
## Toggling classes {#toggling-classes}
Adding the `class` modifier allows you to add a class to an element when "offline".
@component('components.code', ['lang' => 'blade'])
<div wire:offline.class="bg-red-300"></div>
@endcomponent
Now, when the browser goes offline, the element will receive the `bg-red-300` class. The class will be removed again once the user is back online.
You can also perform the inverse, and remove classes by adding the `.remove` modifier, similar to how `wire:loading` works.
@component('components.code', ['lang' => 'blade'])
<div wire:offline.class.remove="bg-green-300" class="bg-green-300"></div>
@endcomponent
The `bg-green-300` class will be removed from the `<div>` while offline.
## Toggling attributes {#toggling-attributes}
Adding the `attr` modifier allows you to add an attribute to an element when "offline".
@component('components.code', ['lang' => 'blade'])
<button wire:offline.attr="disabled">Submit</button>
@endcomponent
Now, when the browser goes offline, the button will be disabled.
You can also perform the inverse, and remove attributes by adding the `.remove` modifier.