|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | | -import { DocumentDuplicateIcon } from '@heroicons/react/24/outline'; |
| 3 | +import { |
| 4 | + DocumentDuplicateIcon, |
| 5 | + CodeBracketIcon, |
| 6 | +} from '@heroicons/react/24/outline'; |
4 | 7 | import classNames from 'classnames'; |
5 | 8 | import type { FC, PropsWithChildren, ReactElement } from 'react'; |
6 | 9 | import { Fragment, isValidElement, useRef } from 'react'; |
7 | 10 |
|
8 | 11 | import BaseButton from '#ui/Common/BaseButton'; |
| 12 | +import { useNotification } from '#ui/Providers/NotificationProvider'; |
9 | 13 | import type { LinkLike } from '#ui/types'; |
10 | 14 |
|
11 | 15 | import styles from './index.module.css'; |
@@ -69,23 +73,35 @@ interface CodeBoxProps { |
69 | 73 | onCopy: (text: string) => void; |
70 | 74 | as?: LinkLike; |
71 | 75 | buttonText: string; |
| 76 | + notificationText: string; |
72 | 77 | showCopyButton?: boolean; |
73 | 78 | } |
74 | 79 |
|
75 | | -const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({ |
| 80 | +const CodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({ |
76 | 81 | children, |
77 | 82 | language, |
78 | 83 | className, |
79 | 84 | onCopy, |
80 | 85 | buttonText, |
| 86 | + notificationText, |
81 | 87 | as = 'a', |
82 | 88 | showCopyButton = true, |
83 | 89 | }: PropsWithChildren<CodeBoxProps>) => { |
| 90 | + const notify = useNotification(); |
84 | 91 | const containerRef = useRef<HTMLPreElement>(null); |
85 | 92 |
|
86 | 93 | const handleCopy = (): void => { |
87 | 94 | const text = containerRef.current?.textContent; |
88 | 95 | if (text) { |
| 96 | + notify({ |
| 97 | + duration: 300, |
| 98 | + message: ( |
| 99 | + <div className="flex items-center gap-3"> |
| 100 | + <CodeBracketIcon className={styles.icon} /> |
| 101 | + {notificationText} |
| 102 | + </div> |
| 103 | + ), |
| 104 | + }); |
89 | 105 | onCopy(text); |
90 | 106 | } |
91 | 107 | }; |
@@ -119,4 +135,4 @@ const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({ |
119 | 135 | ); |
120 | 136 | }; |
121 | 137 |
|
122 | | -export default BaseCodeBox; |
| 138 | +export default CodeBox; |
0 commit comments