-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBlock.astro
35 lines (30 loc) · 1.02 KB
/
Block.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
30
31
32
33
34
35
---
/**
* This `block` component customizes the rendering of Portable Text blocks.
* It conditionally renders different components based on the `style` value
* and provides a fallback to the default `astro-portabletext` Block component.
*
* Usage:
* <PortableText value={portableTextPayload} components={{ block: Block }} />
*/
// @ts-nocheck
import type { BlockProps } from "astro-portabletext/types";
import { usePortableText } from "astro-portabletext";
import Billboard from "./Billboard.astro";
import Quote from "./Quote.astro";
type Props = BlockProps;
const props = Astro.props;
const { getDefaultComponent } = usePortableText(props.node);
const styleIs = (style: string) => style === props.node.style;
const Cmp = styleIs("billboard") // Custom style
? Billboard
: styleIs("blockquote") // Override default
? Quote
: getDefaultComponent(); // Fallback to `astro-portabletext` Block component
---
<Cmp {...props} class="block"><slot /></Cmp>
<style>
.block:where(h1, h2) {
/* some styles */
}
</style>