diff --git a/apps/site/components/Common/CodeBox.tsx b/apps/site/components/Common/CodeBox.tsx index c5786b4df7f2b..051c33dddf5e2 100644 --- a/apps/site/components/Common/CodeBox.tsx +++ b/apps/site/components/Common/CodeBox.tsx @@ -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'; @@ -14,34 +15,30 @@ import type { FC, PropsWithChildren } from 'react'; type CodeBoxProps = { language: string; className?: string; - showCopyButton?: boolean; }; const CodeBox: FC> = props => { - const [, copyToClipboard] = useCopyToClipboard(); - const notify = useNotification(); + const [copied, copyToClipboard] = useCopyToClipboard(); const t = useTranslations(); - const onCopy = (text: string) => { - copyToClipboard(text); - - notify({ - duration: 800, - message: ( -
- - {t('components.common.codebox.copied')} -
- ), - }); - }; - return ( + + {t('components.common.codebox.copied')} + + ) : ( + <> + + {t('components.common.codebox.copy')} + + ) + } {...props} - buttonText={t('components.common.codebox.copy')} /> ); }; diff --git a/apps/site/components/MDX/CodeBox/index.tsx b/apps/site/components/MDX/CodeBox/index.tsx index f22933eeb3c26..4ea12905881aa 100644 --- a/apps/site/components/MDX/CodeBox/index.tsx +++ b/apps/site/components/MDX/CodeBox/index.tsx @@ -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> = ({ +const MDXCodeBox: FC> = ({ children: code, className, - showCopyButton, }) => { const matches = className?.match(/language-(?[a-zA-Z]+)/); const language = matches?.groups?.language ?? ''; return ( - + {code} ); diff --git a/apps/site/layouts/Base.tsx b/apps/site/layouts/Base.tsx index 19b2d23ef5abd..8e8747940e458 100644 --- a/apps/site/layouts/Base.tsx +++ b/apps/site/layouts/Base.tsx @@ -1,7 +1,3 @@ -'use client'; - -import { NotificationProvider } from '@node-core/ui-components/Providers/NotificationProvider'; - import { NavigationStateProvider } from '#site/providers/navigationStateProvider'; import type { FC, PropsWithChildren } from 'react'; @@ -9,11 +5,9 @@ import type { FC, PropsWithChildren } from 'react'; import styles from './layouts.module.css'; const BaseLayout: FC = ({ children }) => ( - - -
{children}
-
-
+ +
{children}
+
); export default BaseLayout; diff --git a/apps/site/next.config.mjs b/apps/site/next.config.mjs index fa4f0256b90c2..40d1f89e87cd3 100644 --- a/apps/site/next.config.mjs +++ b/apps/site/next.config.mjs @@ -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', diff --git a/packages/rehype-shiki/src/plugin.mjs b/packages/rehype-shiki/src/plugin.mjs index b0b5a741a83d4..9f1663c735aff 100644 --- a/packages/rehype-shiki/src/plugin.mjs +++ b/packages/rehype-shiki/src/plugin.mjs @@ -181,15 +181,6 @@ export default async function rehypeShikiji(options) { codeLanguage ); - // Adds a Copy Button to the CodeBox if requested as an additional parameter - // 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
 element with the updated one
       parent.children.splice(index, 1, ...children);
     });
diff --git a/packages/ui-components/.storybook/preview.tsx b/packages/ui-components/.storybook/preview.tsx
index 89c86637642fd..e4e421bb930e0 100644
--- a/packages/ui-components/.storybook/preview.tsx
+++ b/packages/ui-components/.storybook/preview.tsx
@@ -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';
@@ -17,11 +15,6 @@ const preview: Preview = {
   },
 
   decorators: [
-    Story => (
-      
-        
-      
-    ),
     withThemeByDataAttribute({
       themes: { light: '', dark: 'dark' },
       defaultTheme: 'light',
diff --git a/packages/ui-components/package.json b/packages/ui-components/package.json
index 5bef6a4d0e152..64c1aeb0cd9ba 100644
--- a/packages/ui-components/package.json
+++ b/packages/ui-components/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@node-core/ui-components",
-  "version": "1.4.3",
+  "version": "1.5.0",
   "type": "module",
   "exports": {
     "./*": [
@@ -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",
diff --git a/packages/ui-components/src/Common/BaseCodeBox/index.module.css b/packages/ui-components/src/Common/BaseCodeBox/index.module.css
index 662397f01ba62..923d875a9f334 100644
--- a/packages/ui-components/src/Common/BaseCodeBox/index.module.css
+++ b/packages/ui-components/src/Common/BaseCodeBox/index.module.css
@@ -78,7 +78,3 @@
     }
   }
 }
-
-.icon {
-  @apply size-4;
-}
diff --git a/packages/ui-components/src/Common/BaseCodeBox/index.stories.tsx b/packages/ui-components/src/Common/BaseCodeBox/index.stories.tsx
index 6743ba8d4d236..6cc32c8b24169 100644
--- a/packages/ui-components/src/Common/BaseCodeBox/index.stories.tsx
+++ b/packages/ui-components/src/Common/BaseCodeBox/index.stories.tsx
@@ -20,19 +20,10 @@ server.listen(port, hostname, () => {
   console.log(\`Server running at http://\${hostname}:\${port}/\`);
 });`;
 
-const args = {
-  language: 'JavaScript (CJS)',
-  children: {content},
-};
-
 export const Default: Story = {
-  args,
-};
-
-export const WithCopyButton: Story = {
   args: {
-    ...args,
-    showCopyButton: true,
+    language: 'JavaScript (CJS)',
+    children: {content},
   },
 };
 
diff --git a/packages/ui-components/src/Common/BaseCodeBox/index.tsx b/packages/ui-components/src/Common/BaseCodeBox/index.tsx
index 5486908af2a2f..1228c61628378 100644
--- a/packages/ui-components/src/Common/BaseCodeBox/index.tsx
+++ b/packages/ui-components/src/Common/BaseCodeBox/index.tsx
@@ -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';
 
@@ -69,8 +68,8 @@ type CodeBoxProps = {
   className?: string;
   onCopy: (text: string) => void;
   as?: LinkLike;
-  buttonText: string;
-  showCopyButton?: boolean;
+  buttonContent: ReactNode;
+  copied?: boolean;
 };
 
 const BaseCodeBox: FC> = ({
@@ -78,9 +77,8 @@ const BaseCodeBox: FC> = ({
   language,
   className,
   onCopy,
-  buttonText,
+  buttonContent,
   as = 'a',
-  showCopyButton = true,
 }: PropsWithChildren) => {
   const containerRef = useRef(null);
 
@@ -103,17 +101,14 @@ const BaseCodeBox: FC> = ({
       {language && (
         
{language} - {showCopyButton && ( - - - {buttonText} - - )} + + {buttonContent} +
)} diff --git a/packages/ui-components/src/Common/CodeTabs/index.stories.tsx b/packages/ui-components/src/Common/CodeTabs/index.stories.tsx index 9449a7fdf8e1b..916c5271f7692 100644 --- a/packages/ui-components/src/Common/CodeTabs/index.stories.tsx +++ b/packages/ui-components/src/Common/CodeTabs/index.stories.tsx @@ -41,7 +41,7 @@ server.listen(port, hostname, () => { const boxProps = { onCopy: console.log, - buttonText: '[Button Text]', + buttonContent: '[Button Text]', }; const TabsContent: FC = () => ( diff --git a/packages/ui-components/src/Common/Notification/index.module.css b/packages/ui-components/src/Common/Notification/index.module.css deleted file mode 100644 index 23d6933699609..0000000000000 --- a/packages/ui-components/src/Common/Notification/index.module.css +++ /dev/null @@ -1,20 +0,0 @@ -@reference "../../styles/index.css"; - -.root { - @apply m-6 - rounded-sm - border - border-neutral-200 - bg-white - px-4 - py-3 - shadow-lg - dark:border-neutral-800 - dark:bg-neutral-900; -} - -.message { - @apply font-medium - text-green-600 - dark:text-white; -} diff --git a/packages/ui-components/src/Common/Notification/index.stories.tsx b/packages/ui-components/src/Common/Notification/index.stories.tsx deleted file mode 100644 index a41f0dd8a7f09..0000000000000 --- a/packages/ui-components/src/Common/Notification/index.stories.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import { CodeBracketIcon } from '@heroicons/react/24/solid'; - -import Notification from '#ui/Common/Notification'; - -import type { Meta as MetaObj, StoryObj } from '@storybook/react-webpack5'; - -type Story = StoryObj; -type Meta = MetaObj; - -export const Default: Story = { - args: { - open: true, - duration: 5000, - children: 'Copied to clipboard!', - }, -}; - -export const TimedNotification: Story = { - args: { - duration: 5000, - children: 'Copied to clipboard!', - }, -}; - -export const WithJSX: Story = { - args: { - open: true, - children: ( -
- - Copied to clipboard! -
- ), - }, -}; - -export default { component: Notification } as Meta; diff --git a/packages/ui-components/src/Common/Notification/index.tsx b/packages/ui-components/src/Common/Notification/index.tsx deleted file mode 100644 index 5246c42fc3c20..0000000000000 --- a/packages/ui-components/src/Common/Notification/index.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import * as ToastPrimitive from '@radix-ui/react-toast'; -import classNames from 'classnames'; - -import type { FC } from 'react'; - -import styles from './index.module.css'; - -type NotificationProps = { - open?: boolean; - duration?: number; - onChange?: (value: boolean) => void; - children?: React.ReactNode; - className?: string; -}; - -const Notification: FC = ({ - open, - duration = 5000, - onChange, - children, - className, -}: NotificationProps) => ( - - - {children} - - -); - -export default Notification; diff --git a/packages/ui-components/src/Providers/NotificationProvider/__tests__/index.test.jsx b/packages/ui-components/src/Providers/NotificationProvider/__tests__/index.test.jsx deleted file mode 100644 index b66c3c5dd8a10..0000000000000 --- a/packages/ui-components/src/Providers/NotificationProvider/__tests__/index.test.jsx +++ /dev/null @@ -1,53 +0,0 @@ -import { render } from '@testing-library/react'; - -import { describe, it } from 'node:test'; -import assert from 'node:assert/strict'; - -import { NotificationProvider, useNotification } from '..'; - -describe('useNotification', () => { - it('should return the notification dispatch function', () => { - // Arrange - const TestComponent = () => { - const notificationDispatch = useNotification(); - return ( -
- {notificationDispatch ? 'Dispatch available' : 'Dispatch unavailable'} -
- ); - }; - - // Act - const { getByText } = render( - - - - ); - - // Assert - const result = getByText('Dispatch available'); - assert.ok(result.ownerDocument); - }); - - it('should return null outside NotificationProvider', () => { - // Arrange - const TestComponent = () => { - const notificationDispatch = useNotification(); - return ( -
- {notificationDispatch ? 'Dispatch available' : 'Dispatch unavailable'} -
- ); - }; - - // Act - const { queryByText } = render(); - - // Assert - const result = queryByText((content, element) => { - return element.textContent === 'Dispatch unavailable'; - }); - - assert.equal(result, null); - }); -}); diff --git a/packages/ui-components/src/Providers/NotificationProvider/index.module.css b/packages/ui-components/src/Providers/NotificationProvider/index.module.css deleted file mode 100644 index d0f47443f906c..0000000000000 --- a/packages/ui-components/src/Providers/NotificationProvider/index.module.css +++ /dev/null @@ -1,8 +0,0 @@ -@reference "../../styles/index.css"; - -.viewport { - @apply fixed - right-0 - bottom-0 - list-none; -} diff --git a/packages/ui-components/src/Providers/NotificationProvider/index.tsx b/packages/ui-components/src/Providers/NotificationProvider/index.tsx deleted file mode 100644 index 0ade37d734f48..0000000000000 --- a/packages/ui-components/src/Providers/NotificationProvider/index.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import * as Toast from '@radix-ui/react-toast'; -import { createContext, useContext, useEffect, useState } from 'react'; - -import Notification from '#ui/Common/Notification'; - -import type { - Dispatch, - FC, - PropsWithChildren, - ReactNode, - SetStateAction, -} from 'react'; - -import styles from './index.module.css'; - -type NotificationContextType = { - message: string | ReactNode; - duration: number; -} | null; - -const NotificationContext = createContext(null); - -export const NotificationDispatch = createContext< - Dispatch> ->(() => {}); - -export const useNotification = () => useContext(NotificationDispatch); - -export const NotificationProvider: FC = ({ children }) => { - const [notification, dispatch] = useState(null); - - useEffect(() => { - const timeout = setTimeout(() => dispatch(null), notification?.duration); - - return () => clearTimeout(timeout); - }, [notification]); - - return ( - - - - {children} - {notification && ( - - {notification.message} - - )} - - - - - - ); -}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8bb2ca571fd99..be55097b6f2e0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -492,9 +492,6 @@ importers: '@radix-ui/react-tabs': specifier: ~1.1.13 version: 1.1.13(@types/react@19.2.7)(react-dom@19.2.1(react@19.2.1))(react@19.2.1) - '@radix-ui/react-toast': - specifier: ~1.2.15 - version: 1.2.15(@types/react@19.2.7)(react-dom@19.2.1(react@19.2.1))(react@19.2.1) '@radix-ui/react-tooltip': specifier: ~1.2.8 version: 1.2.8(@types/react@19.2.7)(react-dom@19.2.1(react@19.2.1))(react@19.2.1)