Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions apps/site/components/Common/CodeBox.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'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';
Expand All @@ -18,30 +15,24 @@ type CodeBoxProps = {
};

const CodeBox: FC<PropsWithChildren<CodeBoxProps>> = props => {
const [, copyToClipboard] = useCopyToClipboard();
const notify = useNotification();
const [copied, copyToClipboard] = useCopyToClipboard();
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}
copied={copied}
{...props}
buttonText={t('components.common.codebox.copy')}
buttonText={
copied
? t('components.common.codebox.copied')
: t('components.common.codebox.copy')
}
/>
);
};
Expand Down
9 changes: 8 additions & 1 deletion packages/ui-components/src/Common/BaseCodeBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { DocumentDuplicateIcon } from '@heroicons/react/24/outline';
import classNames from 'classnames';
import { Fragment, isValidElement, useRef } from 'react';
import { CheckIcon } from '@heroicons/react/24/outline';

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

Expand Down Expand Up @@ -71,6 +72,7 @@ type CodeBoxProps = {
as?: LinkLike;
buttonText: string;
showCopyButton?: boolean;
copied?: boolean;
};

const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
Expand All @@ -81,6 +83,7 @@ const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
buttonText,
as = 'a',
showCopyButton = true,
copied = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you should add this prop, you can change the buttonText prop to be of type ReactNode and pass the icon directly with the text.

Copy link
Member

@avivkeller avivkeller Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, we should also rename it to be something more descriptive, i.e. buttonContent

}: PropsWithChildren<CodeBoxProps>) => {
const containerRef = useRef<HTMLPreElement>(null);

Expand Down Expand Up @@ -110,7 +113,11 @@ const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
kind="neutral"
onClick={handleCopy}
>
<DocumentDuplicateIcon className={styles.icon} />
{copied ? (
<CheckIcon className={styles.icon} />
) : (
<DocumentDuplicateIcon className={styles.icon} />
)}
{buttonText}
</BaseButton>
)}
Expand Down
Loading