Skip to content

Commit 2e08ba7

Browse files
committed
feat: support nested lists
1 parent dba2f06 commit 2e08ba7

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,47 @@
11
---
22
import SanitizedNode from "./StrapiBlockNode.astro";
3+
import StrapiList from "../StrapiBlockList.astro";
34
import type {
45
StrapiBlockListItem,
6+
StrapiBlockList,
57
StrapiBlockNode,
6-
StrapiBlockTheme
8+
StrapiBlockTheme,
79
} from "../../../types";
810
import { sanitizeStrapiNodeData, StrapiBlockThemeDefault } from "../../../lib";
9-
1011
type Props = {
1112
class?: string;
1213
data: Array<StrapiBlockNode>;
1314
theme: StrapiBlockTheme;
1415
};
1516
16-
const { data, class: classes = '', theme = StrapiBlockThemeDefault } = Astro.props;
17+
const {
18+
data,
19+
class: classes = "",
20+
theme = StrapiBlockThemeDefault,
21+
} = Astro.props;
1722
1823
const sanitizedData = sanitizeStrapiNodeData(data);
24+
const nestedList = data.filter(
25+
(item: StrapiBlockNode) => item.type === "list",
26+
);
1927
---
2028

2129
{
22-
sanitizedData.length && (
30+
(sanitizedData.length > 0) && (
2331
<li class={classes}>
2432
<SanitizedNode data={sanitizedData} theme={theme.paragraph} />
2533
</li>
2634
)
2735
}
36+
{
37+
(nestedList.length > 0) &&
38+
nestedList.map((item: StrapiBlockList) => (
39+
<li class={classes}>
40+
<StrapiList
41+
data={item.children}
42+
format={item.format}
43+
theme={theme}
44+
/>
45+
</li>
46+
))
47+
}

src/types/strapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type StrapiBlockListItem = {
4242
children: Array<StrapiBlockNode>;
4343
};
4444

45-
export type StrapiBlockNode = StrapiBlockTextItem | StrapiBlockLinkItem;
45+
export type StrapiBlockNode = StrapiBlockTextItem | StrapiBlockLinkItem | StrapiBlockList;
4646

4747
export type StrapiBlockHeading = {
4848
type: 'heading';

0 commit comments

Comments
 (0)