2023-08-05 22:15:20 +02:00
|
|
|
import {
|
|
|
|
|
DefaultMantineColor,
|
|
|
|
|
HoverCard,
|
|
|
|
|
HoverCardProps,
|
|
|
|
|
SystemProp,
|
|
|
|
|
useMantineTheme,
|
|
|
|
|
} from '@mantine/core';
|
|
|
|
|
import { Link, RichTextEditor, RichTextEditorProps } from '@mantine/tiptap';
|
|
|
|
|
import { IconInfoCircle } from '@tabler/icons-react';
|
2023-08-02 03:48:10 +02:00
|
|
|
import { useEditor } from '@tiptap/react';
|
|
|
|
|
import StarterKit from '@tiptap/starter-kit';
|
2023-08-05 22:15:20 +02:00
|
|
|
|
2023-08-02 03:48:10 +02:00
|
|
|
interface InfoCardProps {
|
2023-08-02 12:23:28 +02:00
|
|
|
bg?: SystemProp<DefaultMantineColor>;
|
2023-08-02 12:54:04 +02:00
|
|
|
cardProp?: Partial<RichTextEditorProps>;
|
2023-08-02 03:48:10 +02:00
|
|
|
content: string;
|
2023-08-02 12:23:28 +02:00
|
|
|
hoverProp?: Partial<HoverCardProps>;
|
2023-08-05 22:15:20 +02:00
|
|
|
position?: HoverCardProps['position'];
|
2023-08-02 03:48:10 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-02 12:23:28 +02:00
|
|
|
export const InfoCard = ({ bg, cardProp, content, hoverProp, position }: InfoCardProps) => {
|
2023-08-02 03:48:10 +02:00
|
|
|
const { colorScheme } = useMantineTheme();
|
|
|
|
|
const editor = useEditor({
|
|
|
|
|
content,
|
|
|
|
|
editable: false,
|
2023-08-05 22:15:20 +02:00
|
|
|
editorProps: { attributes: { style: 'padding: 0;' } },
|
|
|
|
|
extensions: [StarterKit, Link],
|
2023-08-02 03:48:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
2023-08-05 22:15:20 +02:00
|
|
|
<HoverCard position={position ?? 'top'} radius="md" withArrow withinPortal {...hoverProp}>
|
2023-08-02 03:48:10 +02:00
|
|
|
<HoverCard.Target>
|
|
|
|
|
<IconInfoCircle size="1.25rem" style={{ display: 'block', opacity: 0.5 }} />
|
|
|
|
|
</HoverCard.Target>
|
|
|
|
|
<HoverCard.Dropdown
|
2023-08-05 22:15:20 +02:00
|
|
|
bg={bg ?? colorScheme === 'light' ? 'gray.2' : 'dark.8'}
|
2023-08-02 03:48:10 +02:00
|
|
|
maw={400}
|
2023-08-02 04:32:20 +02:00
|
|
|
px="10px"
|
|
|
|
|
py="5px"
|
2023-08-02 03:48:10 +02:00
|
|
|
>
|
2023-08-05 22:15:20 +02:00
|
|
|
<RichTextEditor editor={editor} style={{ border: '0' }} {...cardProp}>
|
|
|
|
|
<RichTextEditor.Content bg="transparent" />
|
2023-08-02 03:48:10 +02:00
|
|
|
</RichTextEditor>
|
|
|
|
|
</HoverCard.Dropdown>
|
|
|
|
|
</HoverCard>
|
2023-08-05 22:15:20 +02:00
|
|
|
);
|
|
|
|
|
};
|