Skip to content

Commit

Permalink
feat(website): more shadcn conversion (#1606)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlescano authored Dec 30, 2024
2 parents 401600b + 924c7e3 commit 6c75e5c
Show file tree
Hide file tree
Showing 25 changed files with 2,618 additions and 1,760 deletions.
4 changes: 3 additions & 1 deletion packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-popover": "^1.1.2",
"@radix-ui/react-scroll-area": "^1.2.1",
"@radix-ui/react-select": "^2.1.4",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.1",
"@radix-ui/react-toast": "^1.2.2",
"@radix-ui/react-tooltip": "^1.1.3",
"@rainbow-me/rainbowkit": "^2.1.2",
"@rainbow-me/rainbowkit": "^2.2.1",
"@safe-global/api-kit": "^2.2.0",
"@safe-global/protocol-kit": "^1.2.0",
"@safe-global/safe-apps-sdk": "^9.1.0",
Expand Down Expand Up @@ -123,6 +124,7 @@
"tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7",
"usehooks-ts": "^3.1.0",
"vaul": "^1.1.2",
"viem": "^2.21.15",
"wagmi": "^2.5.13",
"zod": "^3.23.8",
Expand Down
67 changes: 54 additions & 13 deletions packages/website/src/components/CodePreview.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
import { FC, useRef } from 'react';
import Editor, { type EditorProps } from '@monaco-editor/react';
import { FC, useRef, useEffect } from 'react';
import Editor, { type EditorProps, loader } from '@monaco-editor/react';
import { createGlobalStyle } from 'styled-components';

interface ICodePreviewProps {
code: string;
language?: string;
height?: string | number | undefined;
line?: number; // The line to highlight
editorProps?: EditorProps;
}
// Define the GitHub Dark Default theme
const githubDarkDefault = {
base: 'vs-dark' as const,
inherit: true,
rules: [
{ token: '', foreground: '#c9d1d9', background: '#0d1117' },
{ token: 'comment', foreground: '#8b949e' },
{ token: 'keyword', foreground: '#ff7b72' },
{ token: 'string', foreground: '#a5d6ff' },
{ token: 'number', foreground: '#79c0ff' },
{ token: 'regexp', foreground: '#a5d6ff' },
{ token: 'type', foreground: '#ff7b72' },
{ token: 'class', foreground: '#ffa657' },
{ token: 'function', foreground: '#d2a8ff' },
{ token: 'variable', foreground: '#ffa657' },
{ token: 'constant', foreground: '#79c0ff' },
],
colors: {
'editor.background': '#000000',
'editor.foreground': '#c9d1d9',
'editor.lineHighlightBackground': '#161b22',
'editor.selectionBackground': '#264f78',
'editorCursor.foreground': '#c9d1d9',
'editorWhitespace.foreground': '#484f58',
'editorIndentGuide.background': '#21262d',
'editorIndentGuide.activeBackground': '#30363d',
},
};

const EditorStyles = createGlobalStyle`
.myInlineDecoration {
Expand All @@ -20,6 +41,14 @@ const EditorStyles = createGlobalStyle`
}
`;

interface ICodePreviewProps {
code: string;
language?: string;
height?: string | number | undefined;
line?: number; // The line to highlight
editorProps?: EditorProps;
}

export const CodePreview: FC<ICodePreviewProps> = ({
code,
language,
Expand All @@ -29,6 +58,16 @@ export const CodePreview: FC<ICodePreviewProps> = ({
}) => {
const editorRef = useRef<any>(null);

// Initialize theme
useEffect(() => {
void loader
.init()
.then((monaco) => {
monaco.editor.defineTheme('github-dark-default', githubDarkDefault);
})
.catch();
}, []);

// Function to highlight lines
const highlightLines = (editor: any, monaco: any, line: number) => {
// Only create the range if the line is provided
Expand All @@ -50,23 +89,25 @@ export const CodePreview: FC<ICodePreviewProps> = ({

// Handle editor mount and save the instance
const handleEditorDidMount = (editor: any, monaco: any) => {
monaco.editor.setTheme('github-dark-default');
editorRef.current = editor;
if (line) {
highlightLines(editor, monaco, line + 1);
}
};

// call highlightLines until the editor is mounted

return (
<>
<EditorStyles />
<Editor
height={height || '100%'}
theme="vs-dark"
theme="github-dark-default"
defaultLanguage={language || 'javascript'}
value={code}
options={{ readOnly: true }}
options={{
readOnly: true,
minimap: { enabled: false },
}}
onMount={handleEditorDidMount}
{...editorProps}
/>
Expand Down
1 change: 1 addition & 0 deletions packages/website/src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const buttonVariants = cva(
},
size: {
default: 'h-9 px-4 py-2',
xs: 'h-6 rounded-md px-2 text-xs',
sm: 'h-8 rounded-md px-3 text-xs',
lg: 'h-10 rounded-md px-8',
icon: 'h-9 w-9',
Expand Down
116 changes: 116 additions & 0 deletions packages/website/src/components/ui/drawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import * as React from 'react';
import { Drawer as DrawerPrimitive } from 'vaul';

import { cn } from '@/lib/utils';

const Drawer = ({
shouldScaleBackground = true,
...props
}: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
<DrawerPrimitive.Root
shouldScaleBackground={shouldScaleBackground}
{...props}
/>
);
Drawer.displayName = 'Drawer';

const DrawerTrigger = DrawerPrimitive.Trigger;

const DrawerPortal = DrawerPrimitive.Portal;

const DrawerClose = DrawerPrimitive.Close;

const DrawerOverlay = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Overlay
ref={ref}
className={cn('fixed inset-0 z-50 bg-black/80', className)}
{...props}
/>
));
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName;

const DrawerContent = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DrawerPortal>
<DrawerOverlay />
<DrawerPrimitive.Content
ref={ref}
className={cn(
'fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background',
className
)}
{...props}
>
<div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" />
{children}
</DrawerPrimitive.Content>
</DrawerPortal>
));
DrawerContent.displayName = 'DrawerContent';

const DrawerHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn('grid gap-1.5 p-4 text-center sm:text-left', className)}
{...props}
/>
);
DrawerHeader.displayName = 'DrawerHeader';

const DrawerFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn('mt-auto flex flex-col gap-2 p-4', className)}
{...props}
/>
);
DrawerFooter.displayName = 'DrawerFooter';

const DrawerTitle = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Title
ref={ref}
className={cn(
'text-lg font-semibold leading-none tracking-tight',
className
)}
{...props}
/>
));
DrawerTitle.displayName = DrawerPrimitive.Title.displayName;

const DrawerDescription = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Description
ref={ref}
className={cn('text-sm text-muted-foreground', className)}
{...props}
/>
));
DrawerDescription.displayName = DrawerPrimitive.Description.displayName;

export {
Drawer,
DrawerPortal,
DrawerOverlay,
DrawerTrigger,
DrawerClose,
DrawerContent,
DrawerHeader,
DrawerFooter,
DrawerTitle,
DrawerDescription,
};
Loading

0 comments on commit 6c75e5c

Please sign in to comment.