Skip to content

Commit 8b5b77c

Browse files
authored
Update README.md
1 parent d764a25 commit 8b5b77c

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,35 @@ composer require infinityloop-dev/lazy-component
2222

2323
## How to use
2424

25-
TODO
25+
- Create new component and extend `\Infinityloop\LazyComponent\LazyComponent` instead of `\Nette\Application\UI\Control`.
26+
- Trigger `handleLoadComponent` to load and redraw component.
27+
- Use macro `{control componentName}` to render your component as you would normally.
28+
- Additionaly use `{control componentName:loadComponentLink}` to get URL for `loadComponent` signal.
29+
- Useful for rendering URL (eg. into data attributes) so you can easily trigger signal from javascript.
30+
- Make sure `LazyCompoennt::render()` method is called if you choose to override it.
31+
- Preferably use `beforeRender()` to pass variables into template.
32+
- `beforeRender()` method is not called when empty template is used (when component is not loaded).
33+
- Template for your component is automaticaly deduced to be have same name (and path) as your `.php` file.
34+
- File extension is simply swapped to `.latte`.
35+
- By default the FontAwesome 5 spinner is used as placeholder. Override `EMPTY_TEMPLATE` constant to use different empty template file.
36+
37+
### Example with tab and lazy tab content
38+
```
39+
<li class"tab" data-load-component="{control myComponent:loadComponentLink}">Tab name</li>
40+
```
41+
```
42+
<div class="tab-content">
43+
{control myComponent}
44+
</div>
45+
```
46+
```
47+
$(".tab[data-load-component]").one('click',function (event) {
48+
const link = $(this).data("load-component");
49+
$.nette.ajax({
50+
method: 'GET',
51+
url: link,
52+
});
53+
});
54+
```
55+
56+
- Load event is executed only once ([jqery.one](https://api.jquery.com/one/)).

0 commit comments

Comments
 (0)