Skip to content

Commit

Permalink
feat: Prepare SWC plugin registry (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Aug 26, 2024
1 parent b1bf6b8 commit 0b6b258
Show file tree
Hide file tree
Showing 79 changed files with 5,543 additions and 64 deletions.
8 changes: 8 additions & 0 deletions swc-plugins/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.d.ts
/lib/generated
/components/ui


# TODO: Fix eslint config
app/
lib/
2 changes: 1 addition & 1 deletion swc-plugins/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "next/core-web-vitals"
}
}
35 changes: 35 additions & 0 deletions swc-plugins/app/api-client-provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use client";

import { apiClient } from "@/lib/trpc/web-client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { httpBatchLink } from "@trpc/client";
import { PropsWithChildren, useState } from "react";
import superjson from "superjson";

export function ApiClientProvider({ children }: PropsWithChildren<{}>) {
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
queries: {
queryKeyHashFn: (queryKey) => superjson.stringify(queryKey),
},
},
})
);
const [trpcClient] = useState(() =>
apiClient.createClient({
links: [
httpBatchLink({
url: "/api/trpc",
transformer: superjson,
}),
],
})
);
return (
<apiClient.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</apiClient.Provider>
);
}
2 changes: 2 additions & 0 deletions swc-plugins/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { handlers } from "@/lib/auth";
export const { GET, POST } = handlers;
3 changes: 3 additions & 0 deletions swc-plugins/app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { handler } from "@/lib/api/server";

export { handler as GET, handler as POST };
13 changes: 13 additions & 0 deletions swc-plugins/app/client-providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use client";

import { ThemeProvider } from "next-themes";
import { PropsWithChildren } from "react";
import { ApiClientProvider } from "./api-client-provider";

export function ClientProviders({ children }: PropsWithChildren) {
return (
<ThemeProvider attribute="class">
<ApiClientProvider>{children}</ApiClientProvider>
</ThemeProvider>
);
}
82 changes: 59 additions & 23 deletions swc-plugins/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,68 @@
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
@layer base {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--card: 0 0% 100%;
--card-foreground: 222.2 84% 4.9%;
--popover: 0 0% 100%;
--popover-foreground: 222.2 84% 4.9%;
--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;
--secondary: 210 40% 96.1%;
--secondary-foreground: 222.2 47.4% 11.2%;
--muted: 210 40% 96.1%;
--muted-foreground: 215.4 16.3% 46.9%;
--accent: 210 40% 96.1%;
--accent-foreground: 222.2 47.4% 11.2%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 210 40% 98%;
--border: 214.3 31.8% 91.4%;
--input: 214.3 31.8% 91.4%;
--ring: 222.2 84% 4.9%;
--radius: 0.5rem;
--chart-1: 12 76% 61%;
--chart-2: 173 58% 39%;
--chart-3: 197 37% 24%;
--chart-4: 43 74% 66%;
--chart-5: 27 87% 67%;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
--card: 222.2 84% 4.9%;
--card-foreground: 210 40% 98%;
--popover: 222.2 84% 4.9%;
--popover-foreground: 210 40% 98%;
--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 11.2%;
--secondary: 217.2 32.6% 17.5%;
--secondary-foreground: 210 40% 98%;
--muted: 217.2 32.6% 17.5%;
--muted-foreground: 215 20.2% 65.1%;
--accent: 217.2 32.6% 17.5%;
--accent-foreground: 210 40% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 210 40% 98%;
--border: 217.2 32.6% 17.5%;
--input: 217.2 32.6% 17.5%;
--ring: 212.7 26.8% 83.9%;
--chart-1: 220 70% 50%;
--chart-2: 160 60% 45%;
--chart-3: 30 80% 55%;
--chart-4: 280 65% 60%;
--chart-5: 340 75% 55%;
}
}

@layer utilities {
.text-balance {
text-wrap: balance;
@layer base {
* {
@apply border-border;
}
}
body {
@apply bg-background text-foreground;
}
}
43 changes: 29 additions & 14 deletions swc-plugins/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import { Toaster } from "@/components/ui/toaster";
import { cn } from "@/lib/utils";
import { SessionProvider } from "next-auth/react";
import { Manrope } from "next/font/google";
import NextTopLoader from "nextjs-toploader";
import { PropsWithChildren } from "react";
import { ClientProviders } from "./client-providers";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });
const fontHeading = Manrope({
subsets: ["latin"],
display: "swap",
variable: "--font-heading",
});

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
const fontBody = Manrope({
subsets: ["latin"],
display: "swap",
variable: "--font-body",
});

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
export default function RootLayout({ children }: PropsWithChildren) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<html lang={"en"}>
<body
className={cn("antialiased", fontHeading.variable, fontBody.variable)}
>
<NextTopLoader color={"var(--colors-primary)"} />

<SessionProvider>
<ClientProviders>{children}</ClientProviders>
</SessionProvider>
<Toaster />
</body>
</html>
);
}
11 changes: 11 additions & 0 deletions swc-plugins/app/robots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MetadataRoute } from "next";

export default function robots(): MetadataRoute.Robots {
return {
rules: {
userAgent: "*",
allow: "/",
},
// sitemap: `${BASE_URL}/sitemap.xml`,
};
}
17 changes: 17 additions & 0 deletions swc-plugins/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "app/globals.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
58 changes: 58 additions & 0 deletions swc-plugins/components/ui/accordion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use client"

import * as React from "react"
import * as AccordionPrimitive from "@radix-ui/react-accordion"
import { ChevronDown } from "lucide-react"

import { cn } from "@/lib/utils"

const Accordion = AccordionPrimitive.Root

const AccordionItem = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
>(({ className, ...props }, ref) => (
<AccordionPrimitive.Item
ref={ref}
className={cn("border-b", className)}
{...props}
/>
))
AccordionItem.displayName = "AccordionItem"

const AccordionTrigger = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Header className="flex">
<AccordionPrimitive.Trigger
ref={ref}
className={cn(
"flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",
className
)}
{...props}
>
{children}
<ChevronDown className="h-4 w-4 shrink-0 transition-transform duration-200" />
</AccordionPrimitive.Trigger>
</AccordionPrimitive.Header>
))
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName

const AccordionContent = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Content
ref={ref}
className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
{...props}
>
<div className={cn("pb-4 pt-0", className)}>{children}</div>
</AccordionPrimitive.Content>
))

AccordionContent.displayName = AccordionPrimitive.Content.displayName

export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
Loading

0 comments on commit 0b6b258

Please sign in to comment.