Skip to content

Commit 68c4421

Browse files
committed
feat: inline copy feedback for code blocks
1 parent 33f53a6 commit 68c4421

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

apps/site/components/Common/CodeBox.tsx

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
'use client';
22

3-
import { CodeBracketIcon } from '@heroicons/react/24/outline';
43
import 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';
74
import { useTranslations } from 'next-intl';
85

96
import Link from '#site/components/Link';
@@ -18,30 +15,24 @@ type CodeBoxProps = {
1815
};
1916

2017
const CodeBox: FC<PropsWithChildren<CodeBoxProps>> = props => {
21-
const [, copyToClipboard] = useCopyToClipboard();
22-
const notify = useNotification();
18+
const [copied, copyToClipboard] = useCopyToClipboard();
2319
const t = useTranslations();
2420

2521
const onCopy = (text: string) => {
2622
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-
});
3723
};
3824

3925
return (
4026
<BaseCodeBox
4127
as={Link}
4228
onCopy={onCopy}
29+
copied={copied}
4330
{...props}
44-
buttonText={t('components.common.codebox.copy')}
31+
buttonText={
32+
copied
33+
? t('components.common.codebox.copied')
34+
: t('components.common.codebox.copy')
35+
}
4536
/>
4637
);
4738
};

packages/ui-components/src/Common/BaseCodeBox/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { DocumentDuplicateIcon } from '@heroicons/react/24/outline';
44
import classNames from 'classnames';
55
import { Fragment, isValidElement, useRef } from 'react';
6+
import { CheckIcon } from '@heroicons/react/24/outline';
67

78
import BaseButton from '#ui/Common/BaseButton';
89

@@ -71,6 +72,7 @@ type CodeBoxProps = {
7172
as?: LinkLike;
7273
buttonText: string;
7374
showCopyButton?: boolean;
75+
copied?: boolean;
7476
};
7577

7678
const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
@@ -81,6 +83,7 @@ const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
8183
buttonText,
8284
as = 'a',
8385
showCopyButton = true,
86+
copied = false,
8487
}: PropsWithChildren<CodeBoxProps>) => {
8588
const containerRef = useRef<HTMLPreElement>(null);
8689

@@ -110,7 +113,11 @@ const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
110113
kind="neutral"
111114
onClick={handleCopy}
112115
>
113-
<DocumentDuplicateIcon className={styles.icon} />
116+
{copied ? (
117+
<CheckIcon className={styles.icon} />
118+
) : (
119+
<DocumentDuplicateIcon className={styles.icon} />
120+
)}
114121
{buttonText}
115122
</BaseButton>
116123
)}

0 commit comments

Comments
 (0)