-
Notifications
You must be signed in to change notification settings - Fork 2
/
NotionBlockCallout.tsx
98 lines (91 loc) · 2.43 KB
/
NotionBlockCallout.tsx
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React, { type JSX } from 'react';
import {
ExclamationTriangleIcon,
HandRaisedIcon,
InformationCircleIcon,
LightBulbIcon,
MegaphoneIcon,
} from '@heroicons/react/24/outline';
import { CalloutBlockObjectResponse } from '@notionhq/client/build/src/api-endpoints';
import { Callout, CalloutBadge } from '../ui/callout';
import { P } from '../ui/typography';
import { NotionRichTextItems } from './NotionRichText';
export default function NotionBlockCallout({
children,
}: {
children: CalloutBlockObjectResponse;
}) {
const { badge, color } = ((): {
badge: JSX.Element;
color: 'blue' | 'green' | 'violet' | 'yellow' | 'red' | 'inherit';
} => {
if (children.callout.icon?.type === 'external') {
const iconUrl = children.callout.icon.external.url;
if (iconUrl.includes('info-alternate')) {
return {
badge: (
<>
<InformationCircleIcon className="h-[1.25em] w-[1.25em] mr-1" />
Note
</>
),
color: 'blue',
};
} else if (iconUrl.includes('light-bulb')) {
return {
badge: (
<>
<LightBulbIcon className="h-[1.25em] w-[1.25em] mr-1" />
Tip
</>
),
color: 'green',
};
} else if (iconUrl.includes('megaphone')) {
return {
badge: (
<>
<MegaphoneIcon className="h-[1.25em] w-[1.25em] mr-1" />
Important
</>
),
color: 'violet',
};
} else if (iconUrl.includes('warning')) {
return {
badge: (
<>
<ExclamationTriangleIcon className="h-[1.25em] w-[1.25em] mr-1" />
Warning
</>
),
color: 'yellow',
};
} else if (iconUrl.includes('hand')) {
return {
badge: (
<>
<HandRaisedIcon className="h-[1.25em] w-[1.25em] mr-1" />
Caution
</>
),
color: 'red',
};
}
}
return {
badge: <></>,
color: 'inherit',
};
})();
return (
<Callout borderColor={color}>
<CalloutBadge color={color}>{badge}</CalloutBadge>
<P className="[&:not(:first-child)]:mt-1">
<NotionRichTextItems baseKey={children.id}>
{children.callout.rich_text}
</NotionRichTextItems>
</P>
</Callout>
);
}