-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathList.astro
29 lines (25 loc) · 996 Bytes
/
List.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
---
/**
* This `list` component customizes the rendering of Portable Text lists.
* It conditionally renders different components based on the `listItem` value
* and provides a fallback to the default `astro-portabletext` List component.
*
* Usage:
* <PortableText value={portableTextPayload} components={{ list: List }} />
*/
// @ts-nocheck
import type { ListProps } from "astro-portabletext/types";
import { usePortableText } from "astro-portabletext";
import BulletList from "./BulletList.astro";
import SquareList from "./SquareList.astro";
export type Props = ListProps;
const props = Astro.props;
const { getDefaultComponent } = usePortableText(props.node);
const listItemIs = (listItem: string) => listItem === props.node.listItem;
const Cmp = listItemIs("square") // Custom list item
? SquareList
: listItemIs("bullet") // Override default
? BulletList
: getDefaultComponent(); // Fallback to `astro-portabletext` List component
---
<Cmp {...props}><slot /></Cmp>