-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathChip.tsx
More file actions
34 lines (34 loc) · 1.12 KB
/
Chip.tsx
File metadata and controls
34 lines (34 loc) · 1.12 KB
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
import type { Annotation } from '@openctx/schema'
import { renderHoverToHTML } from '@openctx/ui-common'
import DOMPurify from 'dompurify'
import type { FunctionComponent } from 'react'
import { BaseChip } from './BaseChip.js'
/**
* A single OpenCtx annotation, displayed as a "chip".
*/
export const Chip: FunctionComponent<{
annotation: Annotation
className?: string
popoverClassName?: string
}> = ({ annotation: { item }, className, popoverClassName }) => {
const renderedHover = renderHoverToHTML(item.ui?.hover)
return (
<BaseChip
title={item.title}
url={item.url}
className={className}
popover={
renderedHover ? (
renderedHover.format === 'text' ? (
<div>{renderedHover.value}</div>
) : (
<div
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(renderedHover.value) }}
/>
)
) : null
}
popoverClassName={popoverClassName}
/>
)
}