77use League \CommonMark \Renderer \HtmlRenderer ;
88use League \CommonMark \Renderer \NodeRendererInterface ;
99use League \CommonMark \Util \HtmlElement ;
10+ use Tempest \View \Components \Icon ;
11+
12+ use function Tempest \get ;
1013
1114final class AlertBlockRenderer implements NodeRendererInterface
1215{
@@ -21,19 +24,39 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): m
2124 throw new \InvalidArgumentException ('Incompatible renderer type: ' . get_class ($ childRenderer ));
2225 }
2326
24- $ cssClass = 'alert alert- ' . $ node ->alertType ;
27+ $ iconName = match ($ node ->icon ) {
28+ 'false ' => null ,
29+ null => match ($ node ->alertType ) {
30+ 'warning ' => 'tabler:exclamation-circle ' ,
31+ 'info ' => 'tabler:info-circle ' ,
32+ 'success ' => 'tabler:check-circle ' ,
33+ 'error ' => 'tabler:exclamation-circle ' ,
34+ default => null ,
35+ },
36+ default => $ node ->icon ,
37+ };
38+
39+ $ icon = $ iconName ? get (Icon::class)->render ($ iconName , class: 'alert-icon ' ) : null ;
40+
2541 $ content = new HtmlElement (
2642 tagName: 'div ' ,
2743 attributes: ['class ' => 'alert-wrapper ' ],
2844 contents: [
29- $ node ->title ? new HtmlElement ('span ' , attributes: ['class ' => 'alert-title ' ], contents: $ node ->title ) : null ,
30- $ childRenderer ->renderNodes ($ node ->children ()),
45+ $ icon ? new HtmlElement ('div ' , attributes: ['class ' => 'alert-icon-wrapper ' ], contents: $ icon ) : null ,
46+ new HtmlElement (
47+ tagName: 'div ' ,
48+ attributes: ['class ' => 'alert-content ' ],
49+ contents: [
50+ $ node ->title ? new HtmlElement ('span ' , attributes: ['class ' => 'alert-title ' ], contents: $ node ->title ) : null ,
51+ $ childRenderer ->renderNodes ($ node ->children ()),
52+ ],
53+ ),
3154 ],
3255 );
3356
3457 return new HtmlElement (
3558 'div ' ,
36- ['class ' => $ cssClass ],
59+ ['class ' => " alert alert- { $ node -> alertType }" ],
3760 $ content ,
3861 );
3962 }
0 commit comments