-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathCodeBox.tsx
More file actions
49 lines (40 loc) · 1.25 KB
/
CodeBox.tsx
File metadata and controls
49 lines (40 loc) · 1.25 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use client';
import { CodeBracketIcon } from '@heroicons/react/24/outline';
import BaseCodeBox from '@node-core/ui-components/Common/BaseCodeBox';
import styles from '@node-core/ui-components/Common/BaseCodeBox/index.module.css';
import { useNotification } from '@node-core/ui-components/Providers/NotificationProvider';
import { useTranslations } from 'next-intl';
import Link from '#site/components/Link';
import { useCopyToClipboard } from '#site/hooks';
import type { FC, PropsWithChildren } from 'react';
type CodeBoxProps = {
language: string;
className?: string;
showCopyButton?: boolean;
};
const CodeBox: FC<PropsWithChildren<CodeBoxProps>> = props => {
const [, copyToClipboard] = useCopyToClipboard();
const notify = useNotification();
const t = useTranslations();
const onCopy = (text: string) => {
copyToClipboard(text);
notify({
duration: 800,
message: (
<div className="flex items-center gap-3">
<CodeBracketIcon className={styles.icon} />
{t('components.common.codebox.copied')}
</div>
),
});
};
return (
<BaseCodeBox
as={Link}
onCopy={onCopy}
{...props}
buttonText={t('components.common.codebox.copy')}
/>
);
};
export default CodeBox;