Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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,
Comment thread
avivkeller marked this conversation as resolved.
Outdated
}: 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