text
stringlengths 21
253k
| id
stringlengths 25
123
| metadata
dict | __index_level_0__
int64 0
181
|
---|---|---|---|
import { getScopedI18n } from "~/locales/server";
async function NotFound() {
const t = await getScopedI18n("notFound");
return (
<div className="flex h-[calc(100vh-80px)] w-full flex-col items-center justify-center py-24">
<h1 className="text-center font-bold">
<p className="mb-2 text-8xl text-destructive">404</p>{" "}
<p className="text-5xl">{t("title")}</p>
</h1>
</div>
);
}
export default NotFound;
| moinulmoin/chadnext/src/app/not-found.tsx | {
"file_path": "moinulmoin/chadnext/src/app/not-found.tsx",
"repo_id": "moinulmoin/chadnext",
"token_count": 195
} | 41 |
"use client";
import { Loader2 } from "lucide-react";
import Image from "next/image";
import { useCallback, useEffect, useState } from "react";
import type { FileWithPath } from "react-dropzone";
import { useDropzone } from "react-dropzone";
import { type ControllerRenderProps } from "react-hook-form";
import { generateClientDropzoneAccept } from "uploadthing/client";
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "~/components/ui/dialog";
import { useUploadThing } from "~/lib/uploadthing";
import { hasFileNameSpaces } from "~/lib/utils";
import { type SettingsValues } from "~/types";
import Icons from "../shared/icons";
import { Button } from "../ui/button";
import { toast } from "../ui/use-toast";
const fileTypes = ["image"];
export default function ImageUploadModal({
onChange,
}: {
onChange: ControllerRenderProps<SettingsValues, "picture">["onChange"];
}) {
const [files, setFiles] = useState<File[]>([]);
const [preview, setPreview] = useState<string | null>(null);
const [showModal, setShowModal] = useState(false);
const onDrop = useCallback((acceptedFiles: FileWithPath[]) => {
if (acceptedFiles.length === 0) return;
setFiles(acceptedFiles);
setPreview(URL.createObjectURL(acceptedFiles[0]));
}, []);
const { getRootProps, getInputProps } = useDropzone({
onDrop,
accept: fileTypes ? generateClientDropzoneAccept(fileTypes) : undefined,
maxFiles: 1,
multiple: false,
validator(file) {
if (hasFileNameSpaces(file.name)) {
return {
code: "Spaces in file name",
message: "Spaces in file names are not acceptable!",
};
}
return null;
},
});
const { startUpload, isUploading, permittedFileInfo } = useUploadThing(
"imageUploader",
{
onClientUploadComplete: (res) => {
if (res) {
onChange(res[0].url);
toast({
title: "Uploaded successfully!",
});
setShowModal(false);
}
},
onUploadError: (e) => {
console.error(e);
toast({
title: "Error occurred while uploading!",
variant: "destructive",
});
},
}
);
const handleCancel = useCallback(() => {
if (preview) {
setFiles([]);
URL.revokeObjectURL(preview);
setPreview(null);
}
}, [preview]);
useEffect(() => {
if (!showModal) {
handleCancel();
}
}, [handleCancel, showModal]);
const handleUpload = () => {
startUpload(files);
};
return (
<Dialog open={showModal} onOpenChange={setShowModal}>
<DialogTrigger asChild>
<div className="absolute left-0 top-0 flex h-28 w-28 cursor-pointer items-center justify-center rounded-full bg-primary/40 text-white opacity-0 group-hover:opacity-100 dark:bg-secondary/40">
<Button
type="button"
size="sm"
variant="ghost"
className="text-xs hover:bg-transparent hover:text-white"
>
<Icons.edit className="mr-1 h-3 w-3" />
</Button>
</div>
</DialogTrigger>
<DialogContent className="max-w-[450px]">
<DialogHeader>
<DialogTitle>Image Upload</DialogTitle>
</DialogHeader>
<div>
{preview ? (
<div className=" flex flex-col items-center justify-center">
<div className=" relative h-40 w-40 ">
<Image
src={preview}
alt="File preview"
className="rounded-full"
fill
loading="lazy"
/>
</div>
<div className="mt-10">
<Button
disabled={isUploading}
onClick={handleCancel}
className="mr-10 text-destructive hover:text-destructive"
variant="outline"
>
Cancel
</Button>
<Button disabled={isUploading} onClick={handleUpload}>
{isUploading ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Uploading...
</>
) : (
"Upload"
)}
</Button>
</div>
</div>
) : (
<div
className=" flex h-60 items-center justify-center border border-dashed focus-visible:outline-none "
{...getRootProps()}
>
<input className="" {...getInputProps()} />
<div className=" space-y-2 text-center">
<div className="flex cursor-pointer flex-col items-center gap-y-2">
<span className=" text-md">Drop Here</span>
<Icons.download size={40} />
</div>
<p className=" text-muted-foreground">OR</p>
<p className=" cursor-pointer text-sm">Click here</p>
</div>
</div>
)}
</div>
<DialogFooter>
<div className=" text-right text-xs leading-normal">
<p>
<span className=" text-sm text-destructive">*</span>
{`Only Images are supported. Max file size is ${permittedFileInfo?.config.image?.maxFileSize}.`}
</p>
<p>
<span className=" text-sm text-destructive">*</span>
<strong>File name with spaces is not acceptable</strong>!
</p>
</div>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
| moinulmoin/chadnext/src/components/layout/image-upload-modal.tsx | {
"file_path": "moinulmoin/chadnext/src/components/layout/image-upload-modal.tsx",
"repo_id": "moinulmoin/chadnext",
"token_count": 2740
} | 42 |
import { PrismaClient } from "@prisma/client";
declare global {
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}
const prisma = global.prisma || new PrismaClient();
if (process.env.NODE_ENV !== "production") global.prisma = prisma;
export default prisma;
| moinulmoin/chadnext/src/lib/prisma.ts | {
"file_path": "moinulmoin/chadnext/src/lib/prisma.ts",
"repo_id": "moinulmoin/chadnext",
"token_count": 98
} | 43 |
import { BenefitsSection } from "@/components/layout/sections/benefits";
import { CommunitySection } from "@/components/layout/sections/community";
import { ContactSection } from "@/components/layout/sections/contact";
import { FAQSection } from "@/components/layout/sections/faq";
import { FeaturesSection } from "@/components/layout/sections/features";
import { FooterSection } from "@/components/layout/sections/footer";
import { HeroSection } from "@/components/layout/sections/hero";
import { PricingSection } from "@/components/layout/sections/pricing";
import { ServicesSection } from "@/components/layout/sections/services";
import { SponsorsSection } from "@/components/layout/sections/sponsors";
import { TeamSection } from "@/components/layout/sections/team";
import { TestimonialSection } from "@/components/layout/sections/testimonial";
export const metadata = {
title: "Shadcn - Landing template",
description: "Free Shadcn landing page for developers",
openGraph: {
type: "website",
url: "https://github.com/nobruf/shadcn-landing-page.git",
title: "Shadcn - Landing template",
description: "Free Shadcn landing page for developers",
images: [
{
url: "https://res.cloudinary.com/dbzv9xfjp/image/upload/v1723499276/og-images/shadcn-vue.jpg",
width: 1200,
height: 630,
alt: "Shadcn - Landing template",
},
],
},
twitter: {
card: "summary_large_image",
site: "https://github.com/nobruf/shadcn-landing-page.git",
title: "Shadcn - Landing template",
description: "Free Shadcn landing page for developers",
images: [
"https://res.cloudinary.com/dbzv9xfjp/image/upload/v1723499276/og-images/shadcn-vue.jpg",
],
},
};
export default function Home() {
return (
<>
<HeroSection />
<SponsorsSection />
<BenefitsSection />
<FeaturesSection />
<ServicesSection />
<TestimonialSection />
<TeamSection />
<CommunitySection />
<PricingSection />
<ContactSection />
<FAQSection />
<FooterSection />
</>
);
}
| nobruf/shadcn-landing-page/app/page.tsx | {
"file_path": "nobruf/shadcn-landing-page/app/page.tsx",
"repo_id": "nobruf/shadcn-landing-page",
"token_count": 747
} | 44 |
"use client";
import { Icon } from "@/components/ui/icon";
import { Marquee } from "@devnomic/marquee";
import "@devnomic/marquee/dist/index.css";
import { icons } from "lucide-react";
interface sponsorsProps {
icon: string;
name: string;
}
const sponsors: sponsorsProps[] = [
{
icon: "Crown",
name: "Acmebrand",
},
{
icon: "Vegan",
name: "Acmelogo",
},
{
icon: "Ghost",
name: "Acmesponsor",
},
{
icon: "Puzzle",
name: "Acmeipsum",
},
{
icon: "Squirrel",
name: "Acme",
},
{
icon: "Cookie",
name: "Accmee",
},
{
icon: "Drama",
name: "Acmetech",
},
];
export const SponsorsSection = () => {
return (
<section id="sponsors" className="max-w-[75%] mx-auto pb-24 sm:pb-32">
<h2 className="text-lg md:text-xl text-center mb-6">
Our Platinum Sponsors
</h2>
<div className="mx-auto">
<Marquee
className="gap-[3rem]"
fade
innerClassName="gap-[3rem]"
pauseOnHover
>
{sponsors.map(({ icon, name }) => (
<div
key={name}
className="flex items-center text-xl md:text-2xl font-medium"
>
<Icon
name={icon as keyof typeof icons}
size={32}
color="white"
className="mr-2"
/>
{name}
</div>
))}
</Marquee>
</div>
</section>
);
};
| nobruf/shadcn-landing-page/components/layout/sections/sponsors.tsx | {
"file_path": "nobruf/shadcn-landing-page/components/layout/sections/sponsors.tsx",
"repo_id": "nobruf/shadcn-landing-page",
"token_count": 792
} | 45 |
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx pretty-quick --staged
| shadcn-ui/taxonomy/.husky/pre-commit | {
"file_path": "shadcn-ui/taxonomy/.husky/pre-commit",
"repo_id": "shadcn-ui/taxonomy",
"token_count": 36
} | 46 |
import { docsConfig } from "@/config/docs"
import { DocsSidebarNav } from "@/components/sidebar-nav"
interface DocsLayoutProps {
children: React.ReactNode
}
export default function DocsLayout({ children }: DocsLayoutProps) {
return (
<div className="flex-1 md:grid md:grid-cols-[220px_1fr] md:gap-6 lg:grid-cols-[240px_1fr] lg:gap-10">
<aside className="fixed top-14 z-30 hidden h-[calc(100vh-3.5rem)] w-full shrink-0 overflow-y-auto border-r py-6 pr-2 md:sticky md:block lg:py-10">
<DocsSidebarNav items={docsConfig.sidebarNav} />
</aside>
{children}
</div>
)
}
| shadcn-ui/taxonomy/app/(docs)/docs/layout.tsx | {
"file_path": "shadcn-ui/taxonomy/app/(docs)/docs/layout.tsx",
"repo_id": "shadcn-ui/taxonomy",
"token_count": 253
} | 47 |
"use client"
import * as React from "react"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { Post } from "@prisma/client"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { toast } from "@/components/ui/use-toast"
import { Icons } from "@/components/icons"
async function deletePost(postId: string) {
const response = await fetch(`/api/posts/${postId}`, {
method: "DELETE",
})
if (!response?.ok) {
toast({
title: "Something went wrong.",
description: "Your post was not deleted. Please try again.",
variant: "destructive",
})
}
return true
}
interface PostOperationsProps {
post: Pick<Post, "id" | "title">
}
export function PostOperations({ post }: PostOperationsProps) {
const router = useRouter()
const [showDeleteAlert, setShowDeleteAlert] = React.useState<boolean>(false)
const [isDeleteLoading, setIsDeleteLoading] = React.useState<boolean>(false)
return (
<>
<DropdownMenu>
<DropdownMenuTrigger className="flex h-8 w-8 items-center justify-center rounded-md border transition-colors hover:bg-muted">
<Icons.ellipsis className="h-4 w-4" />
<span className="sr-only">Open</span>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem>
<Link href={`/editor/${post.id}`} className="flex w-full">
Edit
</Link>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
className="flex cursor-pointer items-center text-destructive focus:text-destructive"
onSelect={() => setShowDeleteAlert(true)}
>
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<AlertDialog open={showDeleteAlert} onOpenChange={setShowDeleteAlert}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
Are you sure you want to delete this post?
</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={async (event) => {
event.preventDefault()
setIsDeleteLoading(true)
const deleted = await deletePost(post.id)
if (deleted) {
setIsDeleteLoading(false)
setShowDeleteAlert(false)
router.refresh()
}
}}
className="bg-red-600 focus:ring-red-600"
>
{isDeleteLoading ? (
<Icons.spinner className="mr-2 h-4 w-4 animate-spin" />
) : (
<Icons.trash className="mr-2 h-4 w-4" />
)}
<span>Delete</span>
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
)
}
| shadcn-ui/taxonomy/components/post-operations.tsx | {
"file_path": "shadcn-ui/taxonomy/components/post-operations.tsx",
"repo_id": "shadcn-ui/taxonomy",
"token_count": 1546
} | 48 |
"use client"
import * as React from "react"
import { useRouter } from "next/navigation"
import { zodResolver } from "@hookform/resolvers/zod"
import { User } from "@prisma/client"
import { useForm } from "react-hook-form"
import * as z from "zod"
import { cn } from "@/lib/utils"
import { userNameSchema } from "@/lib/validations/user"
import { buttonVariants } from "@/components/ui/button"
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { toast } from "@/components/ui/use-toast"
import { Icons } from "@/components/icons"
interface UserNameFormProps extends React.HTMLAttributes<HTMLFormElement> {
user: Pick<User, "id" | "name">
}
type FormData = z.infer<typeof userNameSchema>
export function UserNameForm({ user, className, ...props }: UserNameFormProps) {
const router = useRouter()
const {
handleSubmit,
register,
formState: { errors },
} = useForm<FormData>({
resolver: zodResolver(userNameSchema),
defaultValues: {
name: user?.name || "",
},
})
const [isSaving, setIsSaving] = React.useState<boolean>(false)
async function onSubmit(data: FormData) {
setIsSaving(true)
const response = await fetch(`/api/users/${user.id}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: data.name,
}),
})
setIsSaving(false)
if (!response?.ok) {
return toast({
title: "Something went wrong.",
description: "Your name was not updated. Please try again.",
variant: "destructive",
})
}
toast({
description: "Your name has been updated.",
})
router.refresh()
}
return (
<form
className={cn(className)}
onSubmit={handleSubmit(onSubmit)}
{...props}
>
<Card>
<CardHeader>
<CardTitle>Your Name</CardTitle>
<CardDescription>
Please enter your full name or a display name you are comfortable
with.
</CardDescription>
</CardHeader>
<CardContent>
<div className="grid gap-1">
<Label className="sr-only" htmlFor="name">
Name
</Label>
<Input
id="name"
className="w-[400px]"
size={32}
{...register("name")}
/>
{errors?.name && (
<p className="px-1 text-xs text-red-600">{errors.name.message}</p>
)}
</div>
</CardContent>
<CardFooter>
<button
type="submit"
className={cn(buttonVariants(), className)}
disabled={isSaving}
>
{isSaving && (
<Icons.spinner className="mr-2 h-4 w-4 animate-spin" />
)}
<span>Save</span>
</button>
</CardFooter>
</Card>
</form>
)
}
| shadcn-ui/taxonomy/components/user-name-form.tsx | {
"file_path": "shadcn-ui/taxonomy/components/user-name-form.tsx",
"repo_id": "shadcn-ui/taxonomy",
"token_count": 1400
} | 49 |
import { getAllBlockIds } from "@/lib/blocks"
import { THEMES } from "@/lib/themes"
import { BlockDisplay } from "@/components/block-display"
import { ThemesSwitcher } from "@/components/themes-selector"
export default async function BlocksPage() {
const blocks = (await getAllBlockIds()).filter(
(name) =>
!name.startsWith("chart-") &&
!name.startsWith("sidebar-01") &&
!name.startsWith("login-01")
)
// These themes are not compatible with the blocks yet.
const themes = THEMES.filter(
(theme) => !["default-daylight", "default-midnight"].includes(theme.id)
)
return (
<div className="gap-3 md:flex md:flex-row-reverse md:items-start">
<ThemesSwitcher
themes={themes}
className="fixed inset-x-0 bottom-0 z-40 mt-12 flex bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 lg:sticky lg:bottom-auto lg:top-20"
/>
<div className="grid flex-1 gap-24 lg:gap-48">
{blocks.map((name, index) => (
<BlockDisplay key={`${name}-${index}`} name={name} />
))}
</div>
</div>
)
}
| shadcn-ui/ui/apps/www/app/(app)/blocks/page.tsx | {
"file_path": "shadcn-ui/ui/apps/www/app/(app)/blocks/page.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 447
} | 50 |
"use client"
import { Button } from "@/registry/new-york/ui/button"
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/registry/new-york/ui/card"
import { Input } from "@/registry/new-york/ui/input"
import { Label } from "@/registry/new-york/ui/label"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/registry/new-york/ui/select"
import { Textarea } from "@/registry/new-york/ui/textarea"
export function DemoReportAnIssue() {
return (
<Card>
<CardHeader>
<CardTitle>Report an issue</CardTitle>
<CardDescription>
What area are you having problems with?
</CardDescription>
</CardHeader>
<CardContent className="grid gap-6">
<div className="grid grid-cols-2 gap-4">
<div className="grid gap-2">
<Label htmlFor="area">Area</Label>
<Select defaultValue="billing">
<SelectTrigger id="area">
<SelectValue placeholder="Select" />
</SelectTrigger>
<SelectContent>
<SelectItem value="team">Team</SelectItem>
<SelectItem value="billing">Billing</SelectItem>
<SelectItem value="account">Account</SelectItem>
<SelectItem value="deployments">Deployments</SelectItem>
<SelectItem value="support">Support</SelectItem>
</SelectContent>
</Select>
</div>
<div className="grid gap-2">
<Label htmlFor="security-level">Security Level</Label>
<Select defaultValue="2">
<SelectTrigger
id="security-level"
className="line-clamp-1 w-[160px] truncate"
>
<SelectValue placeholder="Select level" />
</SelectTrigger>
<SelectContent>
<SelectItem value="1">Severity 1 (Highest)</SelectItem>
<SelectItem value="2">Severity 2</SelectItem>
<SelectItem value="3">Severity 3</SelectItem>
<SelectItem value="4">Severity 4 (Lowest)</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div className="grid gap-2">
<Label htmlFor="subject">Subject</Label>
<Input id="subject" placeholder="I need help with..." />
</div>
<div className="grid gap-2">
<Label htmlFor="description">Description</Label>
<Textarea
id="description"
placeholder="Please include all information relevant to your issue."
/>
</div>
</CardContent>
<CardFooter className="justify-between space-x-2">
<Button variant="ghost">Cancel</Button>
<Button>Submit</Button>
</CardFooter>
</Card>
)
}
| shadcn-ui/ui/apps/www/app/(app)/examples/cards/components/report-an-issue.tsx | {
"file_path": "shadcn-ui/ui/apps/www/app/(app)/examples/cards/components/report-an-issue.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 1337
} | 51 |
"use client"
import Link from "next/link"
import { usePathname } from "next/navigation"
import { cn } from "@/lib/utils"
import { buttonVariants } from "@/registry/new-york/ui/button"
interface SidebarNavProps extends React.HTMLAttributes<HTMLElement> {
items: {
href: string
title: string
}[]
}
export function SidebarNav({ className, items, ...props }: SidebarNavProps) {
const pathname = usePathname()
return (
<nav
className={cn(
"flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",
className
)}
{...props}
>
{items.map((item) => (
<Link
key={item.href}
href={item.href}
className={cn(
buttonVariants({ variant: "ghost" }),
pathname === item.href
? "bg-muted hover:bg-muted"
: "hover:bg-transparent hover:underline",
"justify-start"
)}
>
{item.title}
</Link>
))}
</nav>
)
}
| shadcn-ui/ui/apps/www/app/(app)/examples/forms/components/sidebar-nav.tsx | {
"file_path": "shadcn-ui/ui/apps/www/app/(app)/examples/forms/components/sidebar-nav.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 490
} | 52 |
import { atom, useAtom } from "jotai"
import { Mail, mails } from "@/app/(app)/examples/mail/data"
type Config = {
selected: Mail["id"] | null
}
const configAtom = atom<Config>({
selected: mails[0].id,
})
export function useMail() {
return useAtom(configAtom)
}
| shadcn-ui/ui/apps/www/app/(app)/examples/mail/use-mail.ts | {
"file_path": "shadcn-ui/ui/apps/www/app/(app)/examples/mail/use-mail.ts",
"repo_id": "shadcn-ui/ui",
"token_count": 102
} | 53 |
"use client"
import * as React from "react"
import { SliderProps } from "@radix-ui/react-slider"
import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
} from "@/registry/new-york/ui/hover-card"
import { Label } from "@/registry/new-york/ui/label"
import { Slider } from "@/registry/new-york/ui/slider"
interface TopPSelectorProps {
defaultValue: SliderProps["defaultValue"]
}
export function TopPSelector({ defaultValue }: TopPSelectorProps) {
const [value, setValue] = React.useState(defaultValue)
return (
<div className="grid gap-2 pt-2">
<HoverCard openDelay={200}>
<HoverCardTrigger asChild>
<div className="grid gap-4">
<div className="flex items-center justify-between">
<Label htmlFor="top-p">Top P</Label>
<span className="w-12 rounded-md border border-transparent px-2 py-0.5 text-right text-sm text-muted-foreground hover:border-border">
{value}
</span>
</div>
<Slider
id="top-p"
max={1}
defaultValue={value}
step={0.1}
onValueChange={setValue}
className="[&_[role=slider]]:h-4 [&_[role=slider]]:w-4"
aria-label="Top P"
/>
</div>
</HoverCardTrigger>
<HoverCardContent
align="start"
className="w-[260px] text-sm"
side="left"
>
Control diversity via nucleus sampling: 0.5 means half of all
likelihood-weighted options are considered.
</HoverCardContent>
</HoverCard>
</div>
)
}
| shadcn-ui/ui/apps/www/app/(app)/examples/playground/components/top-p-selector.tsx | {
"file_path": "shadcn-ui/ui/apps/www/app/(app)/examples/playground/components/top-p-selector.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 785
} | 54 |
"use client"
import * as React from "react"
import { CheckIcon, ClipboardIcon } from "lucide-react"
import { Event, trackEvent } from "@/lib/events"
import { cn } from "@/lib/utils"
import { Button, ButtonProps } from "@/registry/new-york/ui/button"
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/registry/new-york/ui/tooltip"
export function BlockCopyButton({
event,
name,
code,
className,
...props
}: {
event: Event["name"]
name: string
code: string
} & ButtonProps) {
const [hasCopied, setHasCopied] = React.useState(false)
React.useEffect(() => {
setTimeout(() => {
setHasCopied(false)
}, 2000)
}, [hasCopied])
return (
<Tooltip>
<TooltipTrigger asChild>
<Button
size="icon"
variant="outline"
className={cn(
"[&_svg]-h-3.5 h-7 w-7 rounded-[6px] [&_svg]:w-3.5",
className
)}
onClick={() => {
navigator.clipboard.writeText(code)
trackEvent({
name: event,
properties: {
name,
},
})
setHasCopied(true)
}}
{...props}
>
<span className="sr-only">Copy</span>
{hasCopied ? <CheckIcon /> : <ClipboardIcon />}
</Button>
</TooltipTrigger>
<TooltipContent className="bg-black text-white">Copy code</TooltipContent>
</Tooltip>
)
}
| shadcn-ui/ui/apps/www/components/block-copy-button.tsx | {
"file_path": "shadcn-ui/ui/apps/www/components/block-copy-button.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 703
} | 55 |
"use client"
import * as React from "react"
import { cn } from "@/lib/utils"
import { CopyButton, CopyWithClassNames } from "@/components/copy-button"
import {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from "@/registry/new-york/ui/tabs"
interface ComponentExampleProps extends React.HTMLAttributes<HTMLDivElement> {
extractClassname?: boolean
extractedClassNames?: string
align?: "center" | "start" | "end"
src?: string
}
export function ComponentExample({
children,
className,
extractClassname,
extractedClassNames,
align = "center",
src: _,
...props
}: ComponentExampleProps) {
const [Example, Code, ...Children] = React.Children.toArray(
children
) as React.ReactElement[]
const codeString = React.useMemo(() => {
if (
typeof Code?.props["data-rehype-pretty-code-fragment"] !== "undefined"
) {
const [, Button] = React.Children.toArray(
Code.props.children
) as React.ReactElement[]
return Button?.props?.value || Button?.props?.__rawString__ || null
}
}, [Code])
return (
<div
className={cn("group relative my-4 flex flex-col space-y-2", className)}
{...props}
>
<Tabs defaultValue="preview" className="relative mr-auto w-full">
<div className="flex items-center justify-between pb-3">
<TabsList className="w-full justify-start rounded-none border-b bg-transparent p-0">
<TabsTrigger
value="preview"
className="relative rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 font-semibold text-muted-foreground shadow-none transition-none data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none"
>
Preview
</TabsTrigger>
<TabsTrigger
value="code"
className="relative rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 font-semibold text-muted-foreground shadow-none transition-none data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none"
>
Code
</TabsTrigger>
</TabsList>
{extractedClassNames ? (
<CopyWithClassNames
value={codeString}
classNames={extractedClassNames}
className="absolute right-4 top-20"
/>
) : (
codeString && (
<CopyButton
value={codeString}
className="absolute right-4 top-20"
/>
)
)}
</div>
<TabsContent value="preview" className="rounded-md border">
<div
className={cn("flex min-h-[350px] justify-center p-10", {
"items-center": align === "center",
"items-start": align === "start",
"items-end": align === "end",
})}
>
{Example}
</div>
</TabsContent>
<TabsContent value="code">
<div className="flex flex-col space-y-4">
<div className="w-full rounded-md [&_button]:hidden [&_pre]:my-0 [&_pre]:max-h-[350px] [&_pre]:overflow-auto">
{Code}
</div>
{Children?.length ? (
<div className="rounded-md [&_button]:hidden [&_pre]:my-0 [&_pre]:max-h-[350px] [&_pre]:overflow-auto">
{Children}
</div>
) : null}
</div>
</TabsContent>
</Tabs>
</div>
)
}
| shadcn-ui/ui/apps/www/components/component-example.tsx | {
"file_path": "shadcn-ui/ui/apps/www/components/component-example.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 1664
} | 56 |
"use client"
import * as React from "react"
import { Provider as JotaiProvider } from "jotai"
import { ThemeProvider as NextThemesProvider } from "next-themes"
import { ThemeProviderProps } from "next-themes/dist/types"
import { TooltipProvider } from "@/registry/new-york/ui/tooltip"
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
return (
<JotaiProvider>
<NextThemesProvider {...props}>
<TooltipProvider delayDuration={0}>{children}</TooltipProvider>
</NextThemesProvider>
</JotaiProvider>
)
}
| shadcn-ui/ui/apps/www/components/providers.tsx | {
"file_path": "shadcn-ui/ui/apps/www/components/providers.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 196
} | 57 |
export const siteConfig = {
name: "shadcn/ui",
url: "https://ui.shadcn.com",
ogImage: "https://ui.shadcn.com/og.jpg",
description:
"Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.",
links: {
twitter: "https://twitter.com/shadcn",
github: "https://github.com/shadcn-ui/ui",
},
}
export type SiteConfig = typeof siteConfig
| shadcn-ui/ui/apps/www/config/site.ts | {
"file_path": "shadcn-ui/ui/apps/www/config/site.ts",
"repo_id": "shadcn-ui/ui",
"token_count": 145
} | 58 |
import * as React from "react"
export const useMutationObserver = (
ref: React.MutableRefObject<HTMLElement | null>,
callback: MutationCallback,
options = {
attributes: true,
characterData: true,
childList: true,
subtree: true,
}
) => {
React.useEffect(() => {
if (ref.current) {
const observer = new MutationObserver(callback)
observer.observe(ref.current, options)
return () => observer.disconnect()
}
}, [ref, callback, options])
}
| shadcn-ui/ui/apps/www/hooks/use-mutation-observer.ts | {
"file_path": "shadcn-ui/ui/apps/www/hooks/use-mutation-observer.ts",
"repo_id": "shadcn-ui/ui",
"token_count": 180
} | 59 |
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
| shadcn-ui/ui/apps/www/next-env.d.ts | {
"file_path": "shadcn-ui/ui/apps/www/next-env.d.ts",
"repo_id": "shadcn-ui/ui",
"token_count": 78
} | 60 |
import { Terminal } from "lucide-react"
import {
Alert,
AlertDescription,
AlertTitle,
} from "@/registry/default/ui/alert"
export default function AlertDemo() {
return (
<Alert>
<Terminal className="h-4 w-4" />
<AlertTitle>Heads up!</AlertTitle>
<AlertDescription>
You can add components to your app using the cli.
</AlertDescription>
</Alert>
)
}
| shadcn-ui/ui/apps/www/registry/default/example/alert-demo.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/default/example/alert-demo.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 156
} | 61 |
import { Button } from "@/registry/default/ui/button"
export default function ButtonDemo() {
return <Button>Button</Button>
}
| shadcn-ui/ui/apps/www/registry/default/example/button-demo.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/default/example/button-demo.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 39
} | 62 |
"use client"
import * as React from "react"
import {
ArrowUpCircle,
CheckCircle2,
Circle,
HelpCircle,
LucideIcon,
XCircle,
} from "lucide-react"
import { cn } from "@/lib/utils"
import { Button } from "@/registry/default/ui/button"
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@/registry/default/ui/command"
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/registry/default/ui/popover"
type Status = {
value: string
label: string
icon: LucideIcon
}
const statuses: Status[] = [
{
value: "backlog",
label: "Backlog",
icon: HelpCircle,
},
{
value: "todo",
label: "Todo",
icon: Circle,
},
{
value: "in progress",
label: "In Progress",
icon: ArrowUpCircle,
},
{
value: "done",
label: "Done",
icon: CheckCircle2,
},
{
value: "canceled",
label: "Canceled",
icon: XCircle,
},
]
export default function ComboboxPopover() {
const [open, setOpen] = React.useState(false)
const [selectedStatus, setSelectedStatus] = React.useState<Status | null>(
null
)
return (
<div className="flex items-center space-x-4">
<p className="text-sm text-muted-foreground">Status</p>
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
variant="outline"
size="sm"
className="w-[150px] justify-start"
>
{selectedStatus ? (
<>
<selectedStatus.icon className="mr-2 h-4 w-4 shrink-0" />
{selectedStatus.label}
</>
) : (
<>+ Set status</>
)}
</Button>
</PopoverTrigger>
<PopoverContent className="p-0" side="right" align="start">
<Command>
<CommandInput placeholder="Change status..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup>
{statuses.map((status) => (
<CommandItem
key={status.value}
value={status.value}
onSelect={(value) => {
setSelectedStatus(
statuses.find((priority) => priority.value === value) ||
null
)
setOpen(false)
}}
>
<status.icon
className={cn(
"mr-2 h-4 w-4",
status.value === selectedStatus?.value
? "opacity-100"
: "opacity-40"
)}
/>
<span>{status.label}</span>
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
</div>
)
}
| shadcn-ui/ui/apps/www/registry/default/example/combobox-popover.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/default/example/combobox-popover.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 1615
} | 63 |
"use client"
import * as React from "react"
import { Button } from "@/registry/default/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/registry/default/ui/dropdown-menu"
export default function DropdownMenuRadioGroupDemo() {
const [position, setPosition] = React.useState("bottom")
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline">Open</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56">
<DropdownMenuLabel>Panel Position</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuRadioGroup value={position} onValueChange={setPosition}>
<DropdownMenuRadioItem value="top">Top</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="bottom">Bottom</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="right">Right</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
)
}
| shadcn-ui/ui/apps/www/registry/default/example/dropdown-menu-radio-group.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/default/example/dropdown-menu-radio-group.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 401
} | 64 |
"use client"
import * as React from "react"
import { Moon, Sun } from "lucide-react"
import { useTheme } from "next-themes"
import { Button } from "@/registry/default/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/registry/default/ui/dropdown-menu"
export default function ModeToggle() {
const { setTheme } = useTheme()
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="icon">
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
<span className="sr-only">Toggle theme</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => setTheme("light")}>
Light
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme("dark")}>
Dark
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme("system")}>
System
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}
| shadcn-ui/ui/apps/www/registry/default/example/mode-toggle.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/default/example/mode-toggle.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 517
} | 65 |
import { Label } from "@/registry/default/ui/label"
import { Textarea } from "@/registry/default/ui/textarea"
export default function TextareaWithText() {
return (
<div className="grid w-full gap-1.5">
<Label htmlFor="message-2">Your Message</Label>
<Textarea placeholder="Type your message here." id="message-2" />
<p className="text-sm text-muted-foreground">
Your message will be copied to the support team.
</p>
</div>
)
}
| shadcn-ui/ui/apps/www/registry/default/example/textarea-with-text.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/default/example/textarea-with-text.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 174
} | 66 |
import { Italic } from "lucide-react"
import { Toggle } from "@/registry/default/ui/toggle"
export default function ToggleSm() {
return (
<Toggle size="sm" aria-label="Toggle italic">
<Italic className="h-4 w-4" />
</Toggle>
)
}
| shadcn-ui/ui/apps/www/registry/default/example/toggle-sm.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/default/example/toggle-sm.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 100
} | 67 |
"use client"
import * as React from "react"
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
import { Check } from "lucide-react"
import { cn } from "@/lib/utils"
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
className={cn("flex items-center justify-center text-current")}
>
<Check className="h-4 w-4" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
))
Checkbox.displayName = CheckboxPrimitive.Root.displayName
export { Checkbox }
| shadcn-ui/ui/apps/www/registry/default/ui/checkbox.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/default/ui/checkbox.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 377
} | 68 |
import { ChevronDownIcon, SlashIcon } from "@radix-ui/react-icons"
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from "@/registry/new-york/ui/breadcrumb"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/registry/new-york/ui/dropdown-menu"
export default function BreadcrumbWithDropdown() {
return (
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink href="/">Home</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator>
<SlashIcon />
</BreadcrumbSeparator>
<BreadcrumbItem>
<DropdownMenu>
<DropdownMenuTrigger className="flex items-center gap-1">
Components
<ChevronDownIcon />
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuItem>Documentation</DropdownMenuItem>
<DropdownMenuItem>Themes</DropdownMenuItem>
<DropdownMenuItem>GitHub</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</BreadcrumbItem>
<BreadcrumbSeparator>
<SlashIcon />
</BreadcrumbSeparator>
<BreadcrumbItem>
<BreadcrumbPage>Breadcrumb</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
)
}
| shadcn-ui/ui/apps/www/registry/new-york/example/breadcrumb-dropdown.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/new-york/example/breadcrumb-dropdown.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 684
} | 69 |
import { Button } from "@/registry/new-york/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/registry/new-york/ui/dialog"
import { Input } from "@/registry/new-york/ui/input"
import { Label } from "@/registry/new-york/ui/label"
export default function DialogDemo() {
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Edit Profile</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>Edit profile</DialogTitle>
<DialogDescription>
Make changes to your profile here. Click save when you're done.
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="name" className="text-right">
Name
</Label>
<Input id="name" value="Pedro Duarte" className="col-span-3" />
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="username" className="text-right">
Username
</Label>
<Input id="username" value="@peduarte" className="col-span-3" />
</div>
</div>
<DialogFooter>
<Button type="submit">Save changes</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
| shadcn-ui/ui/apps/www/registry/new-york/example/dialog-demo.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/new-york/example/dialog-demo.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 674
} | 70 |
import { Button } from "@/registry/new-york/ui/button"
import { Input } from "@/registry/new-york/ui/input"
export default function InputWithButton() {
return (
<div className="flex w-full max-w-sm items-center space-x-2">
<Input type="email" placeholder="Email" />
<Button type="submit">Subscribe</Button>
</div>
)
}
| shadcn-ui/ui/apps/www/registry/new-york/example/input-with-button.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/new-york/example/input-with-button.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 126
} | 71 |
import * as React from "react"
import { ScrollArea } from "@/registry/new-york/ui/scroll-area"
import { Separator } from "@/registry/new-york/ui/separator"
const tags = Array.from({ length: 50 }).map(
(_, i, a) => `v1.2.0-beta.${a.length - i}`
)
export default function ScrollAreaDemo() {
return (
<ScrollArea className="h-72 w-48 rounded-md border">
<div className="p-4">
<h4 className="mb-4 text-sm font-medium leading-none">Tags</h4>
{tags.map((tag) => (
<>
<div key={tag} className="text-sm">
{tag}
</div>
<Separator className="my-2" />
</>
))}
</div>
</ScrollArea>
)
}
| shadcn-ui/ui/apps/www/registry/new-york/example/scroll-area-demo.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/new-york/example/scroll-area-demo.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 338
} | 72 |
import { Textarea } from "@/registry/new-york/ui/textarea"
export default function TextareaDemo() {
return <Textarea placeholder="Type your message here." />
}
| shadcn-ui/ui/apps/www/registry/new-york/example/textarea-demo.tsx | {
"file_path": "shadcn-ui/ui/apps/www/registry/new-york/example/textarea-demo.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 49
} | 73 |
import { Registry } from "./schema"
export const themes: Registry = [
{
name: "theme-daylight",
type: "registry:theme",
cssVars: {
light: {
background: "36 39% 88%",
foreground: "36 45% 15%",
primary: "36 45% 70%",
"primary-foreground": "36 45% 11%",
secondary: "40 35% 77%",
"secondary-foreground": "36 45% 25%",
accent: "36 64% 57%",
"accent-foreground": "36 72% 17%",
destructive: "0 84% 37%",
"destructive-foreground": "0 0% 98%",
muted: "36 33% 75%",
"muted-foreground": "36 45% 25%",
card: "36 46% 82%",
"card-foreground": "36 45% 20%",
popover: "0 0% 100%",
"popover-foreground": "240 10% 3.9%",
border: "36 45% 60%",
input: "36 45% 60%",
ring: "36 45% 30%",
"chart-1": "25 34% 28%",
"chart-2": "26 36% 34%",
"chart-3": "28 40% 40%",
"chart-4": "31 41% 48%",
"chart-5": "35 43% 53%",
},
dark: {
background: "36 39% 88%",
foreground: "36 45% 15%",
primary: "36 45% 70%",
"primary-foreground": "36 45% 11%",
secondary: "40 35% 77%",
"secondary-foreground": "36 45% 25%",
accent: "36 64% 57%",
"accent-foreground": "36 72% 17%",
destructive: "0 84% 37%",
"destructive-foreground": "0 0% 98%",
muted: "36 33% 75%",
"muted-foreground": "36 45% 25%",
card: "36 46% 82%",
"card-foreground": "36 45% 20%",
popover: "0 0% 100%",
"popover-foreground": "240 10% 3.9%",
border: "36 45% 60%",
input: "36 45% 60%",
ring: "36 45% 30%",
"chart-1": "25 34% 28%",
"chart-2": "26 36% 34%",
"chart-3": "28 40% 40%",
"chart-4": "31 41% 48%",
"chart-5": "35 43% 53%",
},
},
},
{
name: "theme-midnight",
type: "registry:theme",
cssVars: {
light: {
background: "240 5% 6%",
foreground: "60 5% 90%",
primary: "240 0% 90%",
"primary-foreground": "60 0% 0%",
secondary: "240 4% 15%",
"secondary-foreground": "60 5% 85%",
accent: "240 0% 13%",
"accent-foreground": "60 0% 100%",
destructive: "0 60% 50%",
"destructive-foreground": "0 0% 98%",
muted: "240 5% 25%",
"muted-foreground": "60 5% 85%",
card: "240 4% 10%",
"card-foreground": "60 5% 90%",
popover: "240 5% 15%",
"popover-foreground": "60 5% 85%",
border: "240 6% 20%",
input: "240 6% 20%",
ring: "240 5% 90%",
"chart-1": "359 2% 90%",
"chart-2": "240 1% 74%",
"chart-3": "240 1% 58%",
"chart-4": "240 1% 42%",
"chart-5": "240 2% 26%",
},
dark: {
background: "240 5% 6%",
foreground: "60 5% 90%",
primary: "240 0% 90%",
"primary-foreground": "60 0% 0%",
secondary: "240 4% 15%",
"secondary-foreground": "60 5% 85%",
accent: "240 0% 13%",
"accent-foreground": "60 0% 100%",
destructive: "0 60% 50%",
"destructive-foreground": "0 0% 98%",
muted: "240 5% 25%",
"muted-foreground": "60 5% 85%",
card: "240 4% 10%",
"card-foreground": "60 5% 90%",
popover: "240 5% 15%",
"popover-foreground": "60 5% 85%",
border: "240 6% 20%",
input: "240 6% 20%",
ring: "240 5% 90%",
"chart-1": "359 2% 90%",
"chart-2": "240 1% 74%",
"chart-3": "240 1% 58%",
"chart-4": "240 1% 42%",
"chart-5": "240 2% 26%",
},
},
},
{
name: "theme-emerald",
type: "registry:theme",
cssVars: {
light: {
background: "0 0% 100%",
foreground: "240 10% 3.9%",
card: "0 0% 100%",
"card-foreground": "240 10% 3.9%",
popover: "0 0% 100%",
"popover-foreground": "240 10% 3.9%",
primary: "142 86% 28%",
"primary-foreground": "356 29% 98%",
secondary: "240 4.8% 95.9%",
"secondary-foreground": "240 5.9% 10%",
muted: "240 4.8% 95.9%",
"muted-foreground": "240 3.8% 45%",
accent: "240 4.8% 95.9%",
"accent-foreground": "240 5.9% 10%",
destructive: "0 72% 51%",
"destructive-foreground": "0 0% 98%",
border: "240 5.9% 90%",
input: "240 5.9% 90%",
ring: "142 86% 28%",
"chart-1": "139 65% 20%",
"chart-2": "140 74% 44%",
"chart-3": "142 88% 28%",
"chart-4": "137 55% 15%",
"chart-5": "141 40% 9%",
},
dark: {
background: "240 10% 3.9%",
foreground: "0 0% 98%",
card: "240 10% 3.9%",
"card-foreground": "0 0% 98%",
popover: "240 10% 3.9%",
"popover-foreground": "0 0% 98%",
primary: "142 86% 28%",
"primary-foreground": "356 29% 98%",
secondary: "240 4.8% 95.9%",
"secondary-foreground": "240 5.9% 10%",
muted: "240 3.7% 15.9%",
"muted-foreground": "240 5% 64.9%",
accent: "240 3.7% 15.9%",
"accent-foreground": "0 0% 98%",
destructive: "0 72% 51%",
"destructive-foreground": "0 0% 98%",
border: "240 3.7% 15.9%",
input: "240 3.7% 15.9%",
ring: "142 86% 28%",
"chart-1": "142 88% 28%",
"chart-2": "139 65% 20%",
"chart-3": "140 74% 24%",
"chart-4": "137 55% 15%",
"chart-5": "141 40% 9%",
},
},
},
]
| shadcn-ui/ui/apps/www/registry/registry-themes.ts | {
"file_path": "shadcn-ui/ui/apps/www/registry/registry-themes.ts",
"repo_id": "shadcn-ui/ui",
"token_count": 3051
} | 74 |
import { promises as fs } from "fs"
import { tmpdir } from "os"
import path from "path"
import { Config } from "@/src/utils/get-config"
import { registryBaseColorSchema } from "@/src/utils/registry/schema"
import { transformCssVars } from "@/src/utils/transformers/transform-css-vars"
import { transformImport } from "@/src/utils/transformers/transform-import"
import { transformJsx } from "@/src/utils/transformers/transform-jsx"
import { transformRsc } from "@/src/utils/transformers/transform-rsc"
import { Project, ScriptKind, type SourceFile } from "ts-morph"
import { z } from "zod"
import { transformTwPrefixes } from "./transform-tw-prefix"
export type TransformOpts = {
filename: string
raw: string
config: Config
baseColor?: z.infer<typeof registryBaseColorSchema>
}
export type Transformer<Output = SourceFile> = (
opts: TransformOpts & {
sourceFile: SourceFile
}
) => Promise<Output>
const transformers: Transformer[] = [
transformImport,
transformRsc,
transformCssVars,
transformTwPrefixes,
]
const project = new Project({
compilerOptions: {},
})
async function createTempSourceFile(filename: string) {
const dir = await fs.mkdtemp(path.join(tmpdir(), "shadcn-"))
return path.join(dir, filename)
}
export async function transform(opts: TransformOpts) {
const tempFile = await createTempSourceFile(opts.filename)
const sourceFile = project.createSourceFile(tempFile, opts.raw, {
scriptKind: ScriptKind.TSX,
})
for (const transformer of transformers) {
transformer({ sourceFile, ...opts })
}
return await transformJsx({
sourceFile,
...opts,
})
}
| shadcn-ui/ui/packages/cli/src/utils/transformers/index.ts | {
"file_path": "shadcn-ui/ui/packages/cli/src/utils/transformers/index.ts",
"repo_id": "shadcn-ui/ui",
"token_count": 521
} | 75 |
import path from "path"
import { initOptionsSchema } from "@/src/commands/init"
import * as ERRORS from "@/src/utils/errors"
import { getProjectInfo } from "@/src/utils/get-project-info"
import { highlighter } from "@/src/utils/highlighter"
import { logger } from "@/src/utils/logger"
import { spinner } from "@/src/utils/spinner"
import fs from "fs-extra"
import { z } from "zod"
export async function preFlightInit(
options: z.infer<typeof initOptionsSchema>
) {
const errors: Record<string, boolean> = {}
// Ensure target directory exists.
// Check for empty project. We assume if no package.json exists, the project is empty.
if (
!fs.existsSync(options.cwd) ||
!fs.existsSync(path.resolve(options.cwd, "package.json"))
) {
errors[ERRORS.MISSING_DIR_OR_EMPTY_PROJECT] = true
return {
errors,
projectInfo: null,
}
}
const projectSpinner = spinner(`Preflight checks.`, {
silent: options.silent,
}).start()
if (
fs.existsSync(path.resolve(options.cwd, "components.json")) &&
!options.force
) {
projectSpinner?.fail()
logger.break()
logger.error(
`A ${highlighter.info(
"components.json"
)} file already exists at ${highlighter.info(
options.cwd
)}.\nTo start over, remove the ${highlighter.info(
"components.json"
)} file and run ${highlighter.info("init")} again.`
)
logger.break()
process.exit(1)
}
projectSpinner?.succeed()
const frameworkSpinner = spinner(`Verifying framework.`, {
silent: options.silent,
}).start()
const projectInfo = await getProjectInfo(options.cwd)
if (!projectInfo || projectInfo?.framework.name === "manual") {
errors[ERRORS.UNSUPPORTED_FRAMEWORK] = true
frameworkSpinner?.fail()
logger.break()
if (projectInfo?.framework.links.installation) {
logger.error(
`We could not detect a supported framework at ${highlighter.info(
options.cwd
)}.\n` +
`Visit ${highlighter.info(
projectInfo?.framework.links.installation
)} to manually configure your project.\nOnce configured, you can use the cli to add components.`
)
}
logger.break()
process.exit(1)
}
frameworkSpinner?.succeed(
`Verifying framework. Found ${highlighter.info(
projectInfo.framework.label
)}.`
)
const tailwindSpinner = spinner(`Validating Tailwind CSS.`, {
silent: options.silent,
}).start()
if (!projectInfo?.tailwindConfigFile || !projectInfo?.tailwindCssFile) {
errors[ERRORS.TAILWIND_NOT_CONFIGURED] = true
tailwindSpinner?.fail()
} else {
tailwindSpinner?.succeed()
}
const tsConfigSpinner = spinner(`Validating import alias.`, {
silent: options.silent,
}).start()
if (!projectInfo?.aliasPrefix) {
errors[ERRORS.IMPORT_ALIAS_MISSING] = true
tsConfigSpinner?.fail()
} else {
tsConfigSpinner?.succeed()
}
if (Object.keys(errors).length > 0) {
if (errors[ERRORS.TAILWIND_NOT_CONFIGURED]) {
logger.break()
logger.error(
`No Tailwind CSS configuration found at ${highlighter.info(
options.cwd
)}.`
)
logger.error(
`It is likely you do not have Tailwind CSS installed or have an invalid configuration.`
)
logger.error(`Install Tailwind CSS then try again.`)
if (projectInfo?.framework.links.tailwind) {
logger.error(
`Visit ${highlighter.info(
projectInfo?.framework.links.tailwind
)} to get started.`
)
}
}
if (errors[ERRORS.IMPORT_ALIAS_MISSING]) {
logger.break()
logger.error(`No import alias found in your tsconfig.json file.`)
if (projectInfo?.framework.links.installation) {
logger.error(
`Visit ${highlighter.info(
projectInfo?.framework.links.installation
)} to learn how to set an import alias.`
)
}
}
logger.break()
process.exit(1)
}
return {
errors,
projectInfo,
}
}
| shadcn-ui/ui/packages/shadcn/src/preflights/preflight-init.ts | {
"file_path": "shadcn-ui/ui/packages/shadcn/src/preflights/preflight-init.ts",
"repo_id": "shadcn-ui/ui",
"token_count": 1645
} | 76 |
import type { MetaFunction } from "@remix-run/node";
import { Link } from "@remix-run/react";
import { useOptionalUser } from "~/utils";
export const meta: MetaFunction = () => [{ title: "Remix Notes" }];
export default function Index() {
const user = useOptionalUser();
return (
<main className="relative min-h-screen bg-white sm:flex sm:items-center sm:justify-center">
<div className="relative sm:pb-16 sm:pt-8">
<div className="mx-auto max-w-7xl sm:px-6 lg:px-8">
<div className="relative shadow-xl sm:overflow-hidden sm:rounded-2xl">
<div className="absolute inset-0">
<img
className="h-full w-full object-cover"
src="https://user-images.githubusercontent.com/1500684/157774694-99820c51-8165-4908-a031-34fc371ac0d6.jpg"
alt="Sonic Youth On Stage"
/>
<div className="absolute inset-0 bg-[color:rgba(254,204,27,0.5)] mix-blend-multiply" />
</div>
<div className="relative px-4 pb-8 pt-16 sm:px-6 sm:pb-14 sm:pt-24 lg:px-8 lg:pb-20 lg:pt-32">
<h1 className="text-center text-6xl font-extrabold tracking-tight sm:text-8xl lg:text-9xl">
<span className="block uppercase text-yellow-500 drop-shadow-md">
Indie Stack
</span>
</h1>
<p className="mx-auto mt-6 max-w-lg text-center text-xl text-white sm:max-w-3xl">
Check the README.md file for instructions on how to get this
project deployed.
</p>
<div className="mx-auto mt-10 max-w-sm sm:flex sm:max-w-none sm:justify-center">
{user ? (
<Link
to="/notes"
className="flex items-center justify-center rounded-md border border-transparent bg-white px-4 py-3 text-base font-medium text-yellow-700 shadow-sm hover:bg-yellow-50 sm:px-8"
>
View Notes for {user.email}
</Link>
) : (
<div className="space-y-4 sm:mx-auto sm:inline-grid sm:grid-cols-2 sm:gap-5 sm:space-y-0">
<Link
to="/join"
className="flex items-center justify-center rounded-md border border-transparent bg-white px-4 py-3 text-base font-medium text-yellow-700 shadow-sm hover:bg-yellow-50 sm:px-8"
>
Sign up
</Link>
<Link
to="/login"
className="flex items-center justify-center rounded-md bg-yellow-500 px-4 py-3 font-medium text-white hover:bg-yellow-600"
>
Log In
</Link>
</div>
)}
</div>
<a href="https://remix.run">
<img
src="https://user-images.githubusercontent.com/1500684/158298926-e45dafff-3544-4b69-96d6-d3bcc33fc76a.svg"
alt="Remix"
className="mx-auto mt-16 w-full max-w-[12rem] md:max-w-[16rem]"
/>
</a>
</div>
</div>
</div>
<div className="mx-auto max-w-7xl px-4 py-2 sm:px-6 lg:px-8">
<div className="mt-6 flex flex-wrap justify-center gap-8">
{[
{
src: "https://user-images.githubusercontent.com/1500684/157764397-ccd8ea10-b8aa-4772-a99b-35de937319e1.svg",
alt: "Fly.io",
href: "https://fly.io",
},
{
src: "https://user-images.githubusercontent.com/1500684/157764395-137ec949-382c-43bd-a3c0-0cb8cb22e22d.svg",
alt: "SQLite",
href: "https://sqlite.org",
},
{
src: "https://user-images.githubusercontent.com/1500684/157764484-ad64a21a-d7fb-47e3-8669-ec046da20c1f.svg",
alt: "Prisma",
href: "https://prisma.io",
},
{
src: "https://user-images.githubusercontent.com/1500684/157764276-a516a239-e377-4a20-b44a-0ac7b65c8c14.svg",
alt: "Tailwind",
href: "https://tailwindcss.com",
},
{
src: "https://user-images.githubusercontent.com/1500684/157764454-48ac8c71-a2a9-4b5e-b19c-edef8b8953d6.svg",
alt: "Cypress",
href: "https://www.cypress.io",
},
{
src: "https://user-images.githubusercontent.com/1500684/157772386-75444196-0604-4340-af28-53b236faa182.svg",
alt: "MSW",
href: "https://mswjs.io",
},
{
src: "https://user-images.githubusercontent.com/1500684/157772447-00fccdce-9d12-46a3-8bb4-fac612cdc949.svg",
alt: "Vitest",
href: "https://vitest.dev",
},
{
src: "https://user-images.githubusercontent.com/1500684/157772662-92b0dd3a-453f-4d18-b8be-9fa6efde52cf.png",
alt: "Testing Library",
href: "https://testing-library.com",
},
{
src: "https://user-images.githubusercontent.com/1500684/157772934-ce0a943d-e9d0-40f8-97f3-f464c0811643.svg",
alt: "Prettier",
href: "https://prettier.io",
},
{
src: "https://user-images.githubusercontent.com/1500684/157772990-3968ff7c-b551-4c55-a25c-046a32709a8e.svg",
alt: "ESLint",
href: "https://eslint.org",
},
{
src: "https://user-images.githubusercontent.com/1500684/157773063-20a0ed64-b9f8-4e0b-9d1e-0b65a3d4a6db.svg",
alt: "TypeScript",
href: "https://typescriptlang.org",
},
].map((img) => (
<a
key={img.href}
href={img.href}
className="flex h-16 w-32 justify-center p-1 grayscale transition hover:grayscale-0 focus:grayscale-0"
>
<img alt={img.alt} src={img.src} className="object-contain" />
</a>
))}
</div>
</div>
</div>
</main>
);
}
| shadcn-ui/ui/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/_index.tsx | {
"file_path": "shadcn-ui/ui/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/routes/_index.tsx",
"repo_id": "shadcn-ui/ui",
"token_count": 3738
} | 77 |
import { faker } from "@faker-js/faker";
describe("smoke tests", () => {
afterEach(() => {
cy.cleanupUser();
});
it("should allow you to register and login", () => {
const loginForm = {
email: `${faker.internet.userName()}@example.com`,
password: faker.internet.password(),
};
cy.then(() => ({ email: loginForm.email })).as("user");
cy.visitAndCheck("/");
cy.findByRole("link", { name: /sign up/i }).click();
cy.findByRole("textbox", { name: /email/i }).type(loginForm.email);
cy.findByLabelText(/password/i).type(loginForm.password);
cy.findByRole("button", { name: /create account/i }).click();
cy.findByRole("link", { name: /notes/i }).click();
cy.findByRole("button", { name: /logout/i }).click();
cy.findByRole("link", { name: /log in/i });
});
it("should allow you to make a note", () => {
const testNote = {
title: faker.lorem.words(1),
body: faker.lorem.sentences(1),
};
cy.login();
cy.visitAndCheck("/");
cy.findByRole("link", { name: /notes/i }).click();
cy.findByText("No notes yet");
cy.findByRole("link", { name: /\+ new note/i }).click();
cy.findByRole("textbox", { name: /title/i }).type(testNote.title);
cy.findByRole("textbox", { name: /body/i }).type(testNote.body);
cy.findByRole("button", { name: /save/i }).click();
cy.findByRole("button", { name: /delete/i }).click();
cy.findByText("No notes yet");
});
});
| shadcn-ui/ui/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/e2e/smoke.cy.ts | {
"file_path": "shadcn-ui/ui/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/e2e/smoke.cy.ts",
"repo_id": "shadcn-ui/ui",
"token_count": 597
} | 78 |
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";
const prisma = new PrismaClient();
async function seed() {
const email = "rachel@remix.run";
// cleanup the existing database
await prisma.user.delete({ where: { email } }).catch(() => {
// no worries if it doesn't exist yet
});
const hashedPassword = await bcrypt.hash("racheliscool", 10);
const user = await prisma.user.create({
data: {
email,
password: {
create: {
hash: hashedPassword,
},
},
},
});
await prisma.note.create({
data: {
title: "My first note",
body: "Hello, world!",
userId: user.id,
},
});
await prisma.note.create({
data: {
title: "My second note",
body: "Hello, world!",
userId: user.id,
},
});
console.log(`Database has been seeded. `);
}
seed()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
| shadcn-ui/ui/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/prisma/seed.ts | {
"file_path": "shadcn-ui/ui/packages/shadcn/test/fixtures/frameworks/remix-indie-stack/prisma/seed.ts",
"repo_id": "shadcn-ui/ui",
"token_count": 415
} | 79 |