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
41 changes: 19 additions & 22 deletions apps/site/components/Common/CodeBox.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use client';

import { CodeBracketIcon } from '@heroicons/react/24/outline';
import {
DocumentDuplicateIcon,
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 @@ -14,34 +15,30 @@ import type { FC, PropsWithChildren } from 'react';
type CodeBoxProps = {
language: string;
className?: string;
showCopyButton?: boolean;
};

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}
onCopy={copyToClipboard}
buttonContent={
copied ? (
<>
<DocumentDuplicateIcon className="size-4" />
{t('components.common.codebox.copied')}
</>
) : (
<>
<CodeBracketIcon className="size-4" />
Copy link
Member

Choose a reason for hiding this comment

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

What is this icon?

Also nit: (Cleared and less code)

const ButtonIcon = copied ? DocumentDuplicateIcon : CodeBracketIcon;

...

buttonContext={
  <>
    <ButtonIcon className="size-4" />
    {t(copied ? 
        'components.common.codebox.copied' :
        'components.common.codebox.copy'
    )}
  </>
}

Copy link
Member

Choose a reason for hiding this comment

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

What is this icon?

What do you mean? This is the icon we used previously, is it not?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I realized that afterwards.

{t('components.common.codebox.copy')}
</>
)
}
{...props}
buttonText={t('components.common.codebox.copy')}
/>
);
};
Expand Down
13 changes: 3 additions & 10 deletions apps/site/components/MDX/CodeBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@ import { getLanguageDisplayName } from '@node-core/rehype-shiki';

import CodeBox from '#site/components/Common/CodeBox';

import type { FC, PropsWithChildren } from 'react';
import type { FC, HTMLAttributes } from 'react';

type CodeBoxProps = { className?: string; showCopyButton?: string };

const MDXCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
const MDXCodeBox: FC<HTMLAttributes<HTMLElement>> = ({
children: code,
className,
showCopyButton,
}) => {
const matches = className?.match(/language-(?<language>[a-zA-Z]+)/);
const language = matches?.groups?.language ?? '';

return (
<CodeBox
language={getLanguageDisplayName(language)}
showCopyButton={showCopyButton ? showCopyButton === 'true' : undefined}
className={className}
>
<CodeBox language={getLanguageDisplayName(language)} className={className}>
{code}
</CodeBox>
);
Expand Down
12 changes: 3 additions & 9 deletions apps/site/layouts/Base.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
'use client';

import { NotificationProvider } from '@node-core/ui-components/Providers/NotificationProvider';

import { NavigationStateProvider } from '#site/providers/navigationStateProvider';

import type { FC, PropsWithChildren } from 'react';

import styles from './layouts.module.css';

const BaseLayout: FC<PropsWithChildren> = ({ children }) => (
<NotificationProvider>
<NavigationStateProvider>
<div className={styles.baseLayout}>{children}</div>
</NavigationStateProvider>
</NotificationProvider>
<NavigationStateProvider>
<div className={styles.baseLayout}>{children}</div>
</NavigationStateProvider>
);

export default BaseLayout;
1 change: 0 additions & 1 deletion apps/site/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const nextConfig = {
'@radix-ui/react-label',
'@radix-ui/react-select',
'@radix-ui/react-tabs',
'@radix-ui/react-toast',
'@radix-ui/react-tooltip',
'@radix-ui/react-avatar',
'@orama/highlight',
Expand Down
9 changes: 0 additions & 9 deletions packages/rehype-shiki/src/plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,6 @@ export default async function rehypeShikiji(options) {
codeLanguage
);

// Adds a Copy Button to the CodeBox if requested as an additional parameter
Copy link
Member

Choose a reason for hiding this comment

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

🤔

// And avoids setting the property (overriding) if undefined or invalid value
if (
meta.showCopyButton &&
['true', 'false'].includes(meta.showCopyButton)
) {
children[0].properties.showCopyButton = meta.showCopyButton;
}

// Replaces the <pre> element with the updated one
parent.children.splice(index, 1, ...children);
});
Expand Down
7 changes: 0 additions & 7 deletions packages/ui-components/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { withThemeByDataAttribute } from '@storybook/addon-themes';

import { NotificationProvider } from '#ui/Providers/NotificationProvider';

import type { Preview, ReactRenderer } from '@storybook/react-webpack5';

import { STORYBOOK_MODES, STORYBOOK_SIZES } from './constants';
Expand All @@ -17,11 +15,6 @@ const preview: Preview = {
},

decorators: [
Story => (
<NotificationProvider>
<Story />
</NotificationProvider>
),
withThemeByDataAttribute<ReactRenderer>({
themes: { light: '', dark: 'dark' },
defaultTheme: 'light',
Expand Down
3 changes: 1 addition & 2 deletions packages/ui-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-core/ui-components",
"version": "1.4.3",
"version": "1.5.0",
"type": "module",
"exports": {
"./*": [
Expand Down Expand Up @@ -44,7 +44,6 @@
"@radix-ui/react-select": "~2.2.6",
"@radix-ui/react-separator": "~1.1.8",
"@radix-ui/react-tabs": "~1.1.13",
"@radix-ui/react-toast": "~1.2.15",
"@radix-ui/react-tooltip": "~1.2.8",
"@tailwindcss/postcss": "~4.1.17",
"@vcarl/remark-headings": "~0.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,3 @@
}
}
}

.icon {
@apply size-4;
}
13 changes: 2 additions & 11 deletions packages/ui-components/src/Common/BaseCodeBox/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,10 @@ server.listen(port, hostname, () => {
console.log(\`Server running at http://\${hostname}:\${port}/\`);
});`;

const args = {
language: 'JavaScript (CJS)',
children: <code>{content}</code>,
};

export const Default: Story = {
args,
};

export const WithCopyButton: Story = {
args: {
...args,
showCopyButton: true,
language: 'JavaScript (CJS)',
children: <code>{content}</code>,
},
};

Expand Down
29 changes: 12 additions & 17 deletions packages/ui-components/src/Common/BaseCodeBox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use client';

import { DocumentDuplicateIcon } from '@heroicons/react/24/outline';
import classNames from 'classnames';
import { Fragment, isValidElement, useRef } from 'react';

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

import type { LinkLike } from '#ui/types';
import type { FC, PropsWithChildren, ReactElement } from 'react';
import type { FC, PropsWithChildren, ReactElement, ReactNode } from 'react';

import styles from './index.module.css';

Expand Down Expand Up @@ -69,18 +68,17 @@ type CodeBoxProps = {
className?: string;
onCopy: (text: string) => void;
as?: LinkLike;
buttonText: string;
showCopyButton?: boolean;
buttonContent: ReactNode;
copied?: boolean;
};

const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
children,
language,
className,
onCopy,
buttonText,
buttonContent,
as = 'a',
showCopyButton = true,
}: PropsWithChildren<CodeBoxProps>) => {
const containerRef = useRef<HTMLPreElement>(null);

Expand All @@ -103,17 +101,14 @@ const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
{language && (
<div className={styles.footer}>
<span className={styles.language}>{language}</span>
{showCopyButton && (
<BaseButton
as={as}
className={styles.action}
kind="neutral"
onClick={handleCopy}
>
<DocumentDuplicateIcon className={styles.icon} />
{buttonText}
</BaseButton>
)}
<BaseButton
as={as}
className={styles.action}
kind="neutral"
onClick={handleCopy}
>
{buttonContent}
</BaseButton>
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ server.listen(port, hostname, () => {

const boxProps = {
onCopy: console.log,
buttonText: '[Button Text]',
buttonContent: '[Button Text]',
};

const TabsContent: FC = () => (
Expand Down
20 changes: 0 additions & 20 deletions packages/ui-components/src/Common/Notification/index.module.css

This file was deleted.

This file was deleted.

35 changes: 0 additions & 35 deletions packages/ui-components/src/Common/Notification/index.tsx

This file was deleted.

Loading
Loading