11import { GecutAsyncDirective } from '@gecut/lit-helper/directives/async-directive.js' ;
22import { directive } from 'lit/directive.js' ;
3+ import { classMap } from 'lit/directives/class-map.js' ;
34import { unsafeSVG } from 'lit/directives/unsafe-svg.js' ;
45import { html , nothing } from 'lit/html.js' ;
56
67import type { MaybePromise } from '@gecut/types' ;
78import type { PartInfo } from 'lit/directive.js' ;
9+ import type { ClassInfo } from 'lit/directives/class-map.js' ;
810
911export type SvgContent = MaybePromise < string > ;
1012
@@ -18,31 +20,38 @@ export class IconDirective extends GecutAsyncDirective {
1820 super ( partInfo , 'gecut-icon' ) ;
1921 }
2022
23+ protected content ?: IconContent ;
24+
2125 render ( content : IconContent ) : unknown {
2226 this . log . methodArgs ?.( 'render' , content ) ;
2327
24- if ( content . svg instanceof Promise ) {
25- content . svg . then ( ( _svg ) => {
28+ this . content = content ;
29+
30+ if ( this . content . svg instanceof Promise ) {
31+ this . content . svg . then ( ( _svg ) => {
32+ console . log ( _svg ) ;
2633 this . setValue ( this . _renderSvg ( _svg ) ) ;
2734 } ) ;
28- return this . _renderSvg ( ) ;
35+ // eslint-disable-next-line max-len
36+ return this . _renderSvg ( '<svg viewBox="0 0 24 24"><g stroke="currentColor"><circle cx="12" cy="12" r="9.5" fill="none" stroke-linecap="round" stroke-width="2.5"><animate attributeName="stroke-dasharray" calcMode="spline" dur="1.5s" keySplines="0.42,0,0.58,1;0.42,0,0.58,1;0.42,0,0.58,1" keyTimes="0;0.475;0.95;1" repeatCount="indefinite" values="0 150;42 150;42 150;42 150"/><animate attributeName="stroke-dashoffset" calcMode="spline" dur="1.5s" keySplines="0.42,0,0.58,1;0.42,0,0.58,1;0.42,0,0.58,1" keyTimes="0;0.475;0.95;1" repeatCount="indefinite" values="0;-16;-59;-59"/></circle><animateTransform attributeName="transform" dur="2s" repeatCount="indefinite" type="rotate" values="0 12 12;360 12 12"/></g></svg>' ) ;
2937 }
3038 else {
31- return this . _renderSvg ( content . svg , content . flipIconInRtl ? 'rtl:-scale-x-100' : '' ) ;
39+ return this . _renderSvg ( this . content . svg ) ;
3240 }
3341 }
3442
35- protected _renderSvg ( svg ?: string , customClass = '' ) : unknown {
36- this . log . methodArgs ?.( '_renderSvg' , { svg, customClass} ) ;
37-
38- return html `
39- < div
40- class ="${ customClass } box-content text-[24px] h-[1em] w-[1em] align-middle
41- [contain:size_layout_paint_style] [&>svg]:block [&>svg]:h-full [&>svg]:w-full "
42- >
43- ${ svg ? unsafeSVG ( svg ) : nothing }
44- </ div >
45- ` ;
43+ protected _renderSvg ( svg ?: string ) : unknown {
44+ this . log . methodArgs ?.( '_renderSvg' , { svg} ) ;
45+
46+ return html `< div class ="${ classMap ( this . getRenderClasses ( ) ) } "> ${ svg ? unsafeSVG ( svg ) : nothing } </ div > ` ;
47+ }
48+
49+ protected override getRenderClasses ( ) : ClassInfo {
50+ return {
51+ ...super . getRenderClasses ( ) ,
52+
53+ 'rtl:-scale-x-100' : this . content ?. flipIconInRtl ?? false ,
54+ } ;
4655 }
4756}
4857
0 commit comments