11'use client' ;
22
3- import { CodeBracketIcon } from '@heroicons/react/24/outline' ;
3+ import {
4+ DocumentDuplicateIcon ,
5+ CodeBracketIcon ,
6+ } from '@heroicons/react/24/outline' ;
47import BaseCodeBox from '@node-core/ui-components/Common/BaseCodeBox' ;
5- import styles from '@node-core/ui-components/Common/BaseCodeBox/index.module.css' ;
6- import { useNotification } from '@node-core/ui-components/Providers/NotificationProvider' ;
78import { useTranslations } from 'next-intl' ;
89
910import Link from '#site/components/Link' ;
@@ -14,34 +15,29 @@ import type { FC, PropsWithChildren } from 'react';
1415type CodeBoxProps = {
1516 language : string ;
1617 className ?: string ;
17- showCopyButton ?: boolean ;
1818} ;
1919
2020const CodeBox : FC < PropsWithChildren < CodeBoxProps > > = props => {
21- const [ , copyToClipboard ] = useCopyToClipboard ( ) ;
22- const notify = useNotification ( ) ;
21+ const [ copied , copyToClipboard ] = useCopyToClipboard ( ) ;
2322 const t = useTranslations ( ) ;
2423
25- const onCopy = ( text : string ) => {
26- copyToClipboard ( text ) ;
27-
28- notify ( {
29- duration : 800 ,
30- message : (
31- < div className = "flex items-center gap-3" >
32- < CodeBracketIcon className = { styles . icon } />
33- { t ( 'components.common.codebox.copied' ) }
34- </ div >
35- ) ,
36- } ) ;
37- } ;
24+ const ButtonIcon = copied ? DocumentDuplicateIcon : CodeBracketIcon ;
3825
3926 return (
4027 < BaseCodeBox
4128 as = { Link }
42- onCopy = { onCopy }
29+ onCopy = { copyToClipboard }
30+ buttonContent = {
31+ < >
32+ < ButtonIcon className = "size-4" />
33+ { t (
34+ copied
35+ ? 'components.common.codebox.copied'
36+ : 'components.common.codebox.copy'
37+ ) }
38+ </ >
39+ }
4340 { ...props }
44- buttonText = { t ( 'components.common.codebox.copy' ) }
4541 />
4642 ) ;
4743} ;
0 commit comments