Skip to content

Commit 2909933

Browse files
committed
local imports working
1 parent c9ae5fe commit 2909933

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424

2525
## Future Tasks
2626

27-
- [ ] Make it generate more consistent apps by only importing from a component library like shadcn, can checkout repos like openv0 for inspo
27+
- [ ] Make it generate more consistent apps by only importing from a component library like shadcn
28+
- [x] Partially working
29+
- [x] Need to figure out a way to use the @
30+
- [ ] Need to import all the CSS stuff (main CSS file + tailwind css file)
31+
- [ ] Need to add in all the shadcn components
2832
- [ ] Look into a way to export the app or deploy it in a single click – try two things
2933
- The codesandbox way where I put the link in another way like the react docs, then I can infer the link and have people go check it out
3034
- The non-codesandbox way where i try to do it myself with a dynamic route by doing some hashing

app/page.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ import {
2121
import { AnimatePresence, motion } from "framer-motion";
2222
import { FormEvent, useEffect, useState } from "react";
2323
import LoadingDots from "../components/loading-dots";
24-
import Hello from "@/components/Shadcn";
2524
import {
2625
button,
27-
Button,
2826
card,
2927
fullStyles,
3028
input,
@@ -109,6 +107,9 @@ export default function Home() {
109107
parser.feed(chunkValue);
110108
}
111109

110+
// Replace all occurrences of "@/components" with "/components" in the generated code
111+
setGeneratedCode((prev) => prev.replace(/@\/components/g, "/components"));
112+
112113
newMessages = [
113114
...newMessages,
114115
{ role: "assistant", content: generatedCode },
@@ -176,6 +177,9 @@ export default function Home() {
176177
parser.feed(chunkValue);
177178
}
178179

180+
// Replace all occurrences of "@/components" with "/components" in the generated code
181+
setGeneratedCode((prev) => prev.replace(/@\/components/g, "/components"));
182+
179183
newMessages = [
180184
...newMessages,
181185
{ role: "assistant", content: generatedCode },
@@ -377,6 +381,7 @@ export default function Home() {
377381
externalResources: [
378382
"https://unpkg.com/@tailwindcss/ui/dist/tailwind-ui.min.css",
379383
],
384+
wrapContent: false,
380385
editorHeight: "80vh",
381386
showTabs: true,
382387
}}

utils/Shadcn.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from "react"
33
import { Slot } from "@radix-ui/react-slot"
44
import { cva, type VariantProps } from "class-variance-authority"
55
6-
import { cn } from "@/lib/utils"
6+
import { cn } from "../../../lib/utils.ts"
77
88
const buttonVariants = cva(
99
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
@@ -59,7 +59,7 @@ export { Button, buttonVariants }
5959
export const card = `
6060
import * as React from "react"
6161
62-
import { cn } from "@/lib/utils"
62+
import { cn } from "../../../lib/utils.ts"
6363
6464
const Card = React.forwardRef<
6565
HTMLDivElement,
@@ -140,7 +140,7 @@ export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
140140
export const input = `
141141
import * as React from "react"
142142
143-
import { cn } from "@/lib/utils"
143+
import { cn } from "../../../lib/utils.ts"
144144
145145
export interface InputProps
146146
extends React.InputHTMLAttributes<HTMLInputElement> {}
@@ -165,13 +165,11 @@ Input.displayName = "Input"
165165
export { Input }
166166
`;
167167
export const label = `
168-
"use client"
169-
170168
import * as React from "react"
171169
import * as LabelPrimitive from "@radix-ui/react-label"
172170
import { cva, type VariantProps } from "class-variance-authority"
173171
174-
import { cn } from "@/lib/utils"
172+
import { cn } from "../../../lib/utils.ts"
175173
176174
const labelVariants = cva(
177175
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"

0 commit comments

Comments
 (0)