Skip to content

Commit 8bc24ad

Browse files
add shadcn
1 parent 294c44d commit 8bc24ad

12 files changed

Lines changed: 247 additions & 109 deletions

File tree

bun.lockb

32.7 KB
Binary file not shown.

components.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "default",
4+
"rsc": false,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "tailwind.config.js",
8+
"css": "src/App.css",
9+
"baseColor": "zinc",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"aliases": {
14+
"components": "@/components",
15+
"utils": "@/lib/utils"
16+
}
17+
}

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111
"prod": "serve -s dist"
1212
},
1313
"dependencies": {
14+
"@radix-ui/react-slot": "^1.1.0",
15+
"class-variance-authority": "^0.7.0",
16+
"clsx": "^2.1.1",
17+
"lucide-react": "^0.408.0",
1418
"react": "^18.3.1",
15-
"react-dom": "^18.3.1"
19+
"react-dom": "^18.3.1",
20+
"tailwind-merge": "^2.4.0",
21+
"tailwindcss-animate": "^1.0.7"
1622
},
1723
"devDependencies": {
1824
"@types/node": "^20.14.9",
@@ -21,9 +27,12 @@
2127
"@typescript-eslint/eslint-plugin": "^7.13.1",
2228
"@typescript-eslint/parser": "^7.13.1",
2329
"@vitejs/plugin-react-swc": "^3.5.0",
30+
"autoprefixer": "^10.4.19",
2431
"eslint": "^8.57.0",
2532
"eslint-plugin-react-hooks": "^4.6.2",
2633
"eslint-plugin-react-refresh": "^0.4.7",
34+
"postcss": "^8.4.39",
35+
"tailwindcss": "^3.4.4",
2736
"typescript": "^5.2.2",
2837
"vite": "^5.3.1"
2938
}

postcss.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

src/App.css

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,69 @@
1-
#root {
2-
max-width: 1280px;
3-
margin: 0 auto;
4-
padding: 2rem;
5-
text-align: center;
6-
}
7-
8-
.logo {
9-
height: 6em;
10-
padding: 1.5em;
11-
will-change: filter;
12-
transition: filter 300ms;
13-
}
14-
.logo:hover {
15-
filter: drop-shadow(0 0 2em #646cffaa);
16-
}
17-
.logo.react:hover {
18-
filter: drop-shadow(0 0 2em #61dafbaa);
19-
}
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
204

21-
@keyframes logo-spin {
22-
from {
23-
transform: rotate(0deg);
24-
}
25-
to {
26-
transform: rotate(360deg);
5+
@layer base {
6+
:root {
7+
--background: 0 0% 100%;
8+
--foreground: 240 10% 3.9%;
9+
--card: 0 0% 100%;
10+
--card-foreground: 240 10% 3.9%;
11+
--popover: 0 0% 100%;
12+
--popover-foreground: 240 10% 3.9%;
13+
--primary: 240 5.9% 10%;
14+
--primary-foreground: 0 0% 98%;
15+
--secondary: 240 4.8% 95.9%;
16+
--secondary-foreground: 240 5.9% 10%;
17+
--muted: 240 4.8% 95.9%;
18+
--muted-foreground: 240 3.8% 46.1%;
19+
--accent: 240 4.8% 95.9%;
20+
--accent-foreground: 240 5.9% 10%;
21+
--destructive: 0 84.2% 60.2%;
22+
--destructive-foreground: 0 0% 98%;
23+
--border: 240 5.9% 90%;
24+
--input: 240 5.9% 90%;
25+
--ring: 240 10% 3.9%;
26+
--radius: 0.5rem;
27+
--chart-1: 12 76% 61%;
28+
--chart-2: 173 58% 39%;
29+
--chart-3: 197 37% 24%;
30+
--chart-4: 43 74% 66%;
31+
--chart-5: 27 87% 67%;
2732
}
28-
}
2933

30-
@media (prefers-reduced-motion: no-preference) {
31-
a:nth-of-type(2) .logo {
32-
animation: logo-spin infinite 20s linear;
34+
.dark {
35+
--background: 240 10% 3.9%;
36+
--foreground: 0 0% 98%;
37+
--card: 240 10% 3.9%;
38+
--card-foreground: 0 0% 98%;
39+
--popover: 240 10% 3.9%;
40+
--popover-foreground: 0 0% 98%;
41+
--primary: 0 0% 98%;
42+
--primary-foreground: 240 5.9% 10%;
43+
--secondary: 240 3.7% 15.9%;
44+
--secondary-foreground: 0 0% 98%;
45+
--muted: 240 3.7% 15.9%;
46+
--muted-foreground: 240 5% 64.9%;
47+
--accent: 240 3.7% 15.9%;
48+
--accent-foreground: 0 0% 98%;
49+
--destructive: 0 62.8% 30.6%;
50+
--destructive-foreground: 0 0% 98%;
51+
--border: 240 3.7% 15.9%;
52+
--input: 240 3.7% 15.9%;
53+
--ring: 240 4.9% 83.9%;
54+
--chart-1: 220 70% 50%;
55+
--chart-2: 160 60% 45%;
56+
--chart-3: 30 80% 55%;
57+
--chart-4: 280 65% 60%;
58+
--chart-5: 340 75% 55%;
3359
}
3460
}
3561

36-
.card {
37-
padding: 2em;
38-
}
39-
40-
.read-the-docs {
41-
color: #888;
42-
}
62+
@layer base {
63+
* {
64+
@apply border-border;
65+
}
66+
body {
67+
@apply bg-background text-foreground;
68+
}
69+
}

src/App.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState } from 'react'
22
import reactLogo from './assets/react.svg'
33
import viteLogo from '/vite.svg'
44
import '@/App.css'
5+
import {Button} from "@/components/ui/button.tsx";
56

67
function App() {
78
const [count, setCount] = useState(0)
@@ -18,9 +19,9 @@ function App() {
1819
</div>
1920
<h1>Vite + React</h1>
2021
<div className="card">
21-
<button onClick={() => setCount((count) => count + 1)}>
22+
<Button onClick={() => setCount((count) => count + 1)}>
2223
count is {count}
23-
</button>
24+
</Button>
2425
<p>
2526
Edit <code>src/App.tsx</code> and save to test HMR
2627
</p>

src/components/ui/button.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as React from "react"
2+
import { Slot } from "@radix-ui/react-slot"
3+
import { cva, type VariantProps } from "class-variance-authority"
4+
5+
import { cn } from "@/lib/utils"
6+
7+
const buttonVariants = cva(
8+
"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",
9+
{
10+
variants: {
11+
variant: {
12+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
13+
destructive:
14+
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
15+
outline:
16+
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
17+
secondary:
18+
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
19+
ghost: "hover:bg-accent hover:text-accent-foreground",
20+
link: "text-primary underline-offset-4 hover:underline",
21+
},
22+
size: {
23+
default: "h-10 px-4 py-2",
24+
sm: "h-9 rounded-md px-3",
25+
lg: "h-11 rounded-md px-8",
26+
icon: "h-10 w-10",
27+
},
28+
},
29+
defaultVariants: {
30+
variant: "default",
31+
size: "default",
32+
},
33+
}
34+
)
35+
36+
export interface ButtonProps
37+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
38+
VariantProps<typeof buttonVariants> {
39+
asChild?: boolean
40+
}
41+
42+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
43+
({ className, variant, size, asChild = false, ...props }, ref) => {
44+
const Comp = asChild ? Slot : "button"
45+
return (
46+
<Comp
47+
className={cn(buttonVariants({ variant, size, className }))}
48+
ref={ref}
49+
{...props}
50+
/>
51+
)
52+
}
53+
)
54+
Button.displayName = "Button"
55+
56+
export { Button, buttonVariants }

src/index.css

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/lib/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { type ClassValue, clsx } from "clsx"
2+
import { twMerge } from "tailwind-merge"
3+
4+
export function cn(...inputs: ClassValue[]) {
5+
return twMerge(clsx(inputs))
6+
}

src/main.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom/client'
33
import App from '@/App.tsx'
4-
import '@/index.css'
54

65
ReactDOM.createRoot(document.getElementById('root')!).render(
76
<React.StrictMode>

0 commit comments

Comments
 (0)