|
1 | 1 | "use client"; |
2 | 2 |
|
| 3 | +import * as shadcnComponents from "@/lib/shadcn"; |
3 | 4 | import { |
4 | 5 | SandpackPreview, |
5 | 6 | SandpackProvider, |
6 | 7 | } from "@codesandbox/sandpack-react/unstyled"; |
| 8 | +import dedent from "dedent"; |
7 | 9 |
|
8 | 10 | export default function ReactCodeRunner({ code }: { code: string }) { |
9 | 11 | return ( |
10 | 12 | <SandpackProvider |
11 | 13 | key={code} |
12 | | - files={{ "App.tsx": { code } }} |
13 | 14 | template="react-ts" |
| 15 | + files={{ |
| 16 | + "App.tsx": code, |
| 17 | + ...shadcnFiles, |
| 18 | + }} |
14 | 19 | options={{ |
15 | 20 | externalResources: [ |
16 | 21 | "https://unpkg.com/@tailwindcss/ui/dist/tailwind-ui.min.css", |
17 | 22 | ], |
18 | 23 | }} |
| 24 | + customSetup={{ |
| 25 | + dependencies, |
| 26 | + }} |
19 | 27 | > |
20 | 28 | <SandpackPreview |
21 | 29 | showNavigator={false} |
22 | 30 | showOpenInCodeSandbox={false} |
23 | 31 | showRefreshButton={false} |
24 | 32 | showRestartButton={false} |
25 | 33 | showOpenNewtab={false} |
26 | | - className="aspect-square w-full" |
| 34 | + className="w-full" |
27 | 35 | /> |
28 | 36 | </SandpackProvider> |
29 | 37 | ); |
30 | 38 | } |
| 39 | + |
| 40 | +const shadcnFiles = { |
| 41 | + "/lib/utils.ts": shadcnComponents.utils, |
| 42 | + "/components/ui/accordion.tsx": shadcnComponents.accordian, |
| 43 | + "/components/ui/alert-dialog.tsx": shadcnComponents.alertDialog, |
| 44 | + "/components/ui/alert.tsx": shadcnComponents.alert, |
| 45 | + "/components/ui/avatar.tsx": shadcnComponents.avatar, |
| 46 | + "/components/ui/badge.tsx": shadcnComponents.badge, |
| 47 | + "/components/ui/breadcrumb.tsx": shadcnComponents.breadcrumb, |
| 48 | + "/components/ui/button.tsx": shadcnComponents.button, |
| 49 | + "/components/ui/calendar.tsx": shadcnComponents.calendar, |
| 50 | + "/components/ui/card.tsx": shadcnComponents.card, |
| 51 | + "/components/ui/carousel.tsx": shadcnComponents.carousel, |
| 52 | + "/components/ui/checkbox.tsx": shadcnComponents.checkbox, |
| 53 | + "/components/ui/collapsible.tsx": shadcnComponents.collapsible, |
| 54 | + "/components/ui/dialog.tsx": shadcnComponents.dialog, |
| 55 | + "/components/ui/drawer.tsx": shadcnComponents.drawer, |
| 56 | + "/components/ui/dropdown-menu.tsx": shadcnComponents.dropdownMenu, |
| 57 | + "/components/ui/input.tsx": shadcnComponents.input, |
| 58 | + "/components/ui/label.tsx": shadcnComponents.label, |
| 59 | + "/components/ui/menubar.tsx": shadcnComponents.menuBar, |
| 60 | + "/components/ui/navigation-menu.tsx": shadcnComponents.navigationMenu, |
| 61 | + "/components/ui/pagination.tsx": shadcnComponents.pagination, |
| 62 | + "/components/ui/popover.tsx": shadcnComponents.popover, |
| 63 | + "/components/ui/progress.tsx": shadcnComponents.progress, |
| 64 | + "/components/ui/radio-group.tsx": shadcnComponents.radioGroup, |
| 65 | + "/components/ui/select.tsx": shadcnComponents.select, |
| 66 | + "/components/ui/separator.tsx": shadcnComponents.separator, |
| 67 | + "/components/ui/skeleton.tsx": shadcnComponents.skeleton, |
| 68 | + "/components/ui/slider.tsx": shadcnComponents.slider, |
| 69 | + "/components/ui/switch.tsx": shadcnComponents.switchComponent, |
| 70 | + "/components/ui/table.tsx": shadcnComponents.table, |
| 71 | + "/components/ui/tabs.tsx": shadcnComponents.tabs, |
| 72 | + "/components/ui/textarea.tsx": shadcnComponents.textarea, |
| 73 | + "/components/ui/toast.tsx": shadcnComponents.toast, |
| 74 | + "/components/ui/toaster.tsx": shadcnComponents.toaster, |
| 75 | + "/components/ui/toggle-group.tsx": shadcnComponents.toggleGroup, |
| 76 | + "/components/ui/toggle.tsx": shadcnComponents.toggle, |
| 77 | + "/components/ui/tooltip.tsx": shadcnComponents.tooltip, |
| 78 | + "/components/ui/use-toast.tsx": shadcnComponents.useToast, |
| 79 | + "/public/index.html": dedent` |
| 80 | + <!DOCTYPE html> |
| 81 | + <html lang="en"> |
| 82 | + <head> |
| 83 | + <meta charset="UTF-8"> |
| 84 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 85 | + <title>Document</title> |
| 86 | + <script src="https://cdn.tailwindcss.com"></script> |
| 87 | + </head> |
| 88 | + <body> |
| 89 | + <div id="root"></div> |
| 90 | + </body> |
| 91 | + </html> |
| 92 | + `, |
| 93 | +}; |
| 94 | + |
| 95 | +const dependencies = { |
| 96 | + "lucide-react": "latest", |
| 97 | + recharts: "2.9.0", |
| 98 | + "react-router-dom": "latest", |
| 99 | + "@radix-ui/react-accordion": "^1.2.0", |
| 100 | + "@radix-ui/react-alert-dialog": "^1.1.1", |
| 101 | + "@radix-ui/react-aspect-ratio": "^1.1.0", |
| 102 | + "@radix-ui/react-avatar": "^1.1.0", |
| 103 | + "@radix-ui/react-checkbox": "^1.1.1", |
| 104 | + "@radix-ui/react-collapsible": "^1.1.0", |
| 105 | + "@radix-ui/react-dialog": "^1.1.1", |
| 106 | + "@radix-ui/react-dropdown-menu": "^2.1.1", |
| 107 | + "@radix-ui/react-hover-card": "^1.1.1", |
| 108 | + "@radix-ui/react-label": "^2.1.0", |
| 109 | + "@radix-ui/react-menubar": "^1.1.1", |
| 110 | + "@radix-ui/react-navigation-menu": "^1.2.0", |
| 111 | + "@radix-ui/react-popover": "^1.1.1", |
| 112 | + "@radix-ui/react-progress": "^1.1.0", |
| 113 | + "@radix-ui/react-radio-group": "^1.2.0", |
| 114 | + "@radix-ui/react-select": "^2.1.1", |
| 115 | + "@radix-ui/react-separator": "^1.1.0", |
| 116 | + "@radix-ui/react-slider": "^1.2.0", |
| 117 | + "@radix-ui/react-slot": "^1.1.0", |
| 118 | + "@radix-ui/react-switch": "^1.1.0", |
| 119 | + "@radix-ui/react-tabs": "^1.1.0", |
| 120 | + "@radix-ui/react-toast": "^1.2.1", |
| 121 | + "@radix-ui/react-toggle": "^1.1.0", |
| 122 | + "@radix-ui/react-toggle-group": "^1.1.0", |
| 123 | + "@radix-ui/react-tooltip": "^1.1.2", |
| 124 | + "class-variance-authority": "^0.7.0", |
| 125 | + clsx: "^2.1.1", |
| 126 | + "date-fns": "^3.6.0", |
| 127 | + "embla-carousel-react": "^8.1.8", |
| 128 | + "react-day-picker": "^8.10.1", |
| 129 | + "tailwind-merge": "^2.4.0", |
| 130 | + "tailwindcss-animate": "^1.0.7", |
| 131 | + vaul: "^0.9.1", |
| 132 | +}; |
0 commit comments