11---
22import StrapiBlockCustom from " ./StrapiBlockCustom.astro" ;
3+ import StrapiBlockTextItemComponent from " ./items/StrapiBlockTextItem.astro" ;
34
45import { StrapiBlockThemeDefault , getPropertyClass } from " ../../lib" ;
5- import type { AstroComponent , StrapiBlockTextItem , StrapiBlockTheme } from " ../../types" ;
6+ import type {
7+ AstroComponent ,
8+ StrapiBlockTextItem ,
9+ StrapiBlockTheme ,
10+ } from " ../../types" ;
611
712type Props = {
813 level: number ;
@@ -12,23 +17,53 @@ type Props = {
1217 theme: StrapiBlockTheme ;
1318};
1419
15- const { data, level = 2 , class : classes = ' ' , theme = StrapiBlockThemeDefault , block } = Astro .props ;
20+ const {
21+ data,
22+ level = 2 ,
23+ class : classes = " " ,
24+ theme = StrapiBlockThemeDefault ,
25+ block,
26+ } = Astro .props ;
1627
1728const sanitizedData = data .filter (({ text }: StrapiBlockTextItem ) => text );
18- const headingTag = ` h${level } ` as keyof StrapiBlockTheme [' heading' ];
29+ const headingTag = ` h${level } ` as keyof StrapiBlockTheme [" heading" ];
1930const Tag = headingTag ;
2031
21- const blockClasses = classes ? classes .split (' ' ) : [];
22- const headingClasses = [... blockClasses , ... getPropertyClass (theme , [' heading' , headingTag ])];
23-
32+ const blockClasses = classes ? classes .split (" " ) : [];
33+ const headingClasses = [
34+ ... blockClasses ,
35+ ... getPropertyClass (theme , [" heading" , headingTag ]),
36+ ];
2437---
38+
2539{
2640 sanitizedData .length && (
2741 <>
28- { block && (<StrapiBlockCustom { ... Astro .props } comp = { block } data = { sanitizedData [0 ]} />)}
29- { ! block && (sanitizedData .map (({ text }: StrapiBlockTextItem ) => {
30- return (<Tag class = { headingClasses .join (' ' )} >{ text } </Tag >);
31- })
42+ { block && (
43+ <StrapiBlockCustom
44+ { ... Astro .props }
45+ comp = { block }
46+ data = { sanitizedData [0 ]}
47+ />
48+ )}
49+ { ! block &&
50+ sanitizedData .map (({ text }: StrapiBlockTextItem ) => {
51+ return <Tag class = { headingClasses .join (" " )} >{ text } </Tag >;
52+ })}
53+ { ! block && (
54+ <Tag class = { headingClasses .join (" " )} >
55+ { sanitizedData .map ((item : StrapiBlockTextItem ) => {
56+ if (typeof item === " string" ) {
57+ return item ;
58+ }
59+ return (
60+ <StrapiBlockTextItemComponent
61+ data = { item }
62+ theme = { theme .heading .content || theme .paragraph || {}}
63+ />
64+ );
65+ })}
66+ </Tag >
3267 )}
3368 </>
3469 )
0 commit comments