1+ import { CodeBracketIcon } from '@heroicons/react/24/outline' ;
12import BaseCodeBox from '@node-core/ui-components/Common/BaseCodeBox' ;
2- import { useState } from 'react' ;
3+ import styles from '@node-core/ui-components/Common/BaseCodeBox/index.module.css' ;
4+ import { useNotification } from '@node-core/ui-components/Providers/NotificationProvider' ;
35
46import { STATIC_DATA } from '../constants.mjs' ;
57
@@ -17,40 +19,34 @@ export const getLanguageDisplayName = language => {
1719 return entry ?. [ 1 ] ?? language . toLowerCase ( ) ;
1820} ;
1921
20- /**
21- * @typedef CodeBoxProps
22- * @property {string } [className] - CSS class with language info
23- */
24-
25- /**
26- * Code box component with syntax highlighting and copy functionality
27- * @param {import('react').PropsWithChildren<CodeBoxProps> } props
28- */
22+ /** @param {import('react').PropsWithChildren<{ className: string }> } props */
2923export default ( { className, ...props } ) => {
3024 const matches = className ?. match ( / l a n g u a g e - (?< language > [ a - z A - Z ] + ) / ) ;
3125 const language = matches ?. groups ?. language ?? '' ;
32- const [ copyText , setCopyText ] = useState ( 'Copy to clipboard' ) ;
3326
34- /**
35- * Copy text to clipboard and show feedback
36- * @param {string } text - Text to copy
37- */
38- const handleCopy = async text => {
27+ const notify = useNotification ( ) ;
28+
29+ const onCopy = async text => {
3930 await navigator . clipboard . writeText ( text ) ;
4031
41- setCopyText ( 'Copied to clipboard!' ) ;
42- setTimeout ( ( ) => {
43- setCopyText ( 'Copy to clipboard' ) ;
44- } , 500 ) ;
32+ notify ( {
33+ duration : 300 ,
34+ message : (
35+ < div className = "flex items-center gap-3" >
36+ < CodeBracketIcon className = { styles . icon } />
37+ Copied to clipboard
38+ </ div >
39+ ) ,
40+ } ) ;
4541 } ;
4642
4743 return (
4844 < BaseCodeBox
4945 as = { 'a' }
50- onCopy = { handleCopy }
46+ onCopy = { onCopy }
5147 language = { getLanguageDisplayName ( language ) }
5248 { ...props }
53- buttonText = { copyText }
49+ buttonText = { 'Copy to clipboard' }
5450 />
5551 ) ;
5652} ;
0 commit comments