-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathloader.php
62 lines (48 loc) · 2.21 KB
/
loader.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
namespace Atk4\Ui\Demos;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
\Atk4\Ui\Button::addTo($app, ['Loader Examples - Page 2', 'small right floated basic blue', 'iconRight' => 'right arrow'])
->link(['loader2']);
\Atk4\Ui\View::addTo($app, ['ui' => 'clearing divider']);
// ViewTester will perform callback to self.
ViewTester::addTo($app);
// Example 1 - Basic usage of a Loader.
\Atk4\Ui\Loader::addTo($app)->set(function (\Atk4\Ui\Loader $p) {
// set your time expensive function here.
sleep(1);
\Atk4\Ui\Header::addTo($p, ['Loader #1']);
\Atk4\Ui\LoremIpsum::addTo($p, ['size' => 1]);
// Any dynamic views can perform call-backs just fine
ViewTester::addTo($p);
// Loader may be inside another loader, works fine.
$loader = \Atk4\Ui\Loader::addTo($p);
// use loadEvent to prevent manual loading or even specify custom trigger event
$loader->loadEvent = false;
$loader->set(function ($p) {
// You may pass arguments to the loader, in this case it's "color"
sleep(1);
\Atk4\Ui\Header::addTo($p, ['Loader #1b - ' . $_GET['color']]);
\Atk4\Ui\LoremIpsum::addTo(\Atk4\Ui\View::addTo($p, ['ui' => $_GET['color'] . ' segment']), ['size' => 1]);
// don't forget to make your own argument sticky so that Components can communicate with themselves:
$p->stickyGet('color');
ViewTester::addTo($p);
// This loader takes 2s to load because it needs to go through 2 sleep statements.
});
// button may contain load event.
\Atk4\Ui\Button::addTo($p, ['Load Segment Manually (2s)', 'red'])->js('click', $loader->jsLoad(['color' => 'red']));
\Atk4\Ui\Button::addTo($p, ['Load Segment Manually (2s)', 'blue'])->js('click', $loader->jsLoad(['color' => 'blue']));
});
// Example 2 - Loader with custom body.
\Atk4\Ui\Loader::addTo($app, [
'ui' => '', // this will prevent "loading spinner" from showing
'shim' => [ // shim is displayed while content is leaded
\Atk4\Ui\Message::class,
'Generating LoremIpsum, please wait...',
'red',
],
])->set(function ($p) {
usleep(500 * 1000);
\Atk4\Ui\LoremIpsum::addTo($p, ['size' => 2]);
});