Skip to content

Commit

Permalink
Adjust attributes names and allow choosing a custom HTML tag
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz committed Sep 26, 2023
1 parent fd97359 commit 7f62a42
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
*/
final class AddLiveAttributesSubscriber implements EventSubscriberInterface, ServiceSubscriberInterface
{
private const DEFAULT_LOADING_TAG = 'div';

private const DEFAULT_LOADING_TEMPLATE = null;

public function __construct(
private ComponentStack $componentStack,
private TemplateMap $templateMap,
Expand Down Expand Up @@ -80,9 +84,9 @@ public function onPreRender(PreRenderEvent $event): void
if ($isDeferred) {
$event->setTemplate('@LiveComponent/deferred.html.twig');

if ($loadingTemplate) {
$variables['loadingTemplate'] = $loadingTemplate;
}
$variables['loadingTag'] = $originalAttributes['loading-tag'] ?? self::DEFAULT_LOADING_TAG;
$variables['loadingTemplate'] = $originalAttributes['loading-template'] ?? self::DEFAULT_LOADING_TEMPLATE;
$attributes = $attributes->without('defer', 'loading-element', 'loading-template');
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/LiveComponent/templates/deferred.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<div {{ attributes }} data-action="live:connect->live#$render">
{% if loadingTemplate is defined and loadingTemplate != null %}
{{ include(loadingTemplate) }}
{% endif %}
</div>
<{{ loadingTag }} {{ attributes }} data-action="live:connect->live#$render">
{% block loadingContent %}
{% if loadingTemplate != null %}
{{ include(loadingTemplate) }}
{% endif %}
{% endblock %}
</{{ loadingTag }}>

0 comments on commit 7f62a42

Please sign in to comment.