create-user-hub 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -2
- package/index.js +192 -0
- package/package.json +12 -4
- package/template/.env.example +7 -0
- package/template/CLAUDE.md +24 -0
- package/template/README.md +28 -0
- package/template/biome.json +46 -0
- package/template/components.json +25 -0
- package/template/convex/_generated/api.ts +56 -0
- package/template/convex/_generated/dataModel.ts +60 -0
- package/template/convex/_generated/server.ts +175 -0
- package/template/convex/auth.config.ts +7 -0
- package/template/convex/hub.ts +2 -0
- package/template/convex/me.ts +18 -0
- package/template/convex/model/notes.ts +25 -0
- package/template/convex/notes.ts +41 -0
- package/template/convex/schema.ts +10 -0
- package/template/convex/tsconfig.json +26 -0
- package/template/convex.json +9 -0
- package/template/gitignore +11 -0
- package/template/package.json +41 -0
- package/template/scripts/setup.ts +167 -0
- package/template/server.ts +50 -0
- package/template/src/components/ui/badge.tsx +51 -0
- package/template/src/components/ui/button.tsx +55 -0
- package/template/src/components/ui/card.tsx +99 -0
- package/template/src/components/ui/empty.tsx +103 -0
- package/template/src/components/ui/field.tsx +236 -0
- package/template/src/components/ui/input.tsx +19 -0
- package/template/src/components/ui/item.tsx +201 -0
- package/template/src/components/ui/label.tsx +17 -0
- package/template/src/components/ui/separator.tsx +22 -0
- package/template/src/components/ui/skeleton.tsx +13 -0
- package/template/src/lib/utils.ts +1 -0
- package/template/src/routeTree.gen.ts +86 -0
- package/template/src/router.tsx +16 -0
- package/template/src/routes/__root.tsx +81 -0
- package/template/src/routes/facilitator.tsx +100 -0
- package/template/src/routes/index.tsx +142 -0
- package/template/src/styles.css +137 -0
- package/template/tsconfig.json +27 -0
- package/template/vite.config.ts +15 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getHubUser } from "@user-hub/auth/convex";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { query } from "./_generated/server";
|
|
4
|
+
|
|
5
|
+
// Who the server says is signed in: proof that Convex trusts the hub token.
|
|
6
|
+
export const get = query({
|
|
7
|
+
args: {},
|
|
8
|
+
returns: v.union(
|
|
9
|
+
v.object({
|
|
10
|
+
id: v.string(),
|
|
11
|
+
name: v.optional(v.string()),
|
|
12
|
+
team: v.optional(v.string()),
|
|
13
|
+
role: v.union(v.literal("member"), v.literal("facilitator")),
|
|
14
|
+
}),
|
|
15
|
+
v.null(),
|
|
16
|
+
),
|
|
17
|
+
handler: async (ctx) => await getHubUser(ctx),
|
|
18
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ConvexError } from "convex/values";
|
|
2
|
+
import type { MutationCtx, QueryCtx } from "../_generated/server";
|
|
3
|
+
|
|
4
|
+
const PAGE = 50;
|
|
5
|
+
const MAX_LENGTH = 500;
|
|
6
|
+
|
|
7
|
+
export async function listMine(ctx: QueryCtx, personId: string) {
|
|
8
|
+
return await ctx.db
|
|
9
|
+
.query("notes")
|
|
10
|
+
.withIndex("by_personId", (q) => q.eq("personId", personId))
|
|
11
|
+
.order("desc")
|
|
12
|
+
.take(PAGE);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function listAll(ctx: QueryCtx) {
|
|
16
|
+
return await ctx.db.query("notes").order("desc").take(PAGE);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function add(ctx: MutationCtx, personId: string, text: string) {
|
|
20
|
+
const trimmed = text.trim();
|
|
21
|
+
if (!trimmed || trimmed.length > MAX_LENGTH) {
|
|
22
|
+
throw new ConvexError(`Write a note of 1 to ${MAX_LENGTH} characters`);
|
|
23
|
+
}
|
|
24
|
+
return await ctx.db.insert("notes", { personId, text: trimmed });
|
|
25
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { requireFacilitator, requireHubUser } from "@user-hub/auth/convex";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { mutation, query } from "./_generated/server";
|
|
4
|
+
import * as Notes from "./model/notes";
|
|
5
|
+
|
|
6
|
+
// Thin wrappers: check who is asking, then call the model.
|
|
7
|
+
|
|
8
|
+
const note = v.object({
|
|
9
|
+
_id: v.id("notes"),
|
|
10
|
+
_creationTime: v.number(),
|
|
11
|
+
personId: v.string(),
|
|
12
|
+
text: v.string(),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const mine = query({
|
|
16
|
+
args: {},
|
|
17
|
+
returns: v.array(note),
|
|
18
|
+
handler: async (ctx) => {
|
|
19
|
+
const me = await requireHubUser(ctx);
|
|
20
|
+
return await Notes.listMine(ctx, me.id);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const add = mutation({
|
|
25
|
+
args: { text: v.string() },
|
|
26
|
+
returns: v.id("notes"),
|
|
27
|
+
handler: async (ctx, { text }) => {
|
|
28
|
+
const me = await requireHubUser(ctx);
|
|
29
|
+
return await Notes.add(ctx, me.id, text);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Facilitators see everyone's notes; members are refused on the server.
|
|
34
|
+
export const all = query({
|
|
35
|
+
args: {},
|
|
36
|
+
returns: v.array(note),
|
|
37
|
+
handler: async (ctx) => {
|
|
38
|
+
await requireFacilitator(ctx);
|
|
39
|
+
return await Notes.listAll(ctx);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
|
|
4
|
+
export default defineSchema({
|
|
5
|
+
// Demo data, keyed on the person's hub id.
|
|
6
|
+
notes: defineTable({
|
|
7
|
+
personId: v.string(),
|
|
8
|
+
text: v.string(),
|
|
9
|
+
}).index("by_personId", ["personId"]),
|
|
10
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
/* This TypeScript project config describes the environment that
|
|
3
|
+
* Convex functions run in and is used to typecheck them.
|
|
4
|
+
* You can modify it, but some settings are required to use Convex.
|
|
5
|
+
*/
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
/* These settings are not required by Convex and can be modified. */
|
|
8
|
+
"allowJs": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"moduleResolution": "Bundler",
|
|
11
|
+
"jsx": "react-jsx",
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
|
|
15
|
+
/* These compiler options are required by Convex */
|
|
16
|
+
"target": "ESNext",
|
|
17
|
+
"lib": ["ES2021", "dom"],
|
|
18
|
+
"types": ["node"],
|
|
19
|
+
"forceConsistentCasingInFileNames": true,
|
|
20
|
+
"module": "ESNext",
|
|
21
|
+
"isolatedModules": true,
|
|
22
|
+
"noEmit": true
|
|
23
|
+
},
|
|
24
|
+
"include": ["./**/*"],
|
|
25
|
+
"exclude": ["./_generated"]
|
|
26
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"setup": "bun scripts/setup.ts",
|
|
7
|
+
"dev": "convex dev --start \"vite dev --port 3000\"",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"start": "bun run server.ts",
|
|
10
|
+
"check": "biome check",
|
|
11
|
+
"typecheck": "tsc --noEmit -p . && tsc --noEmit -p convex"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@base-ui/react": "^1.8.0",
|
|
15
|
+
"@fontsource-variable/oxanium": "^5.3.0",
|
|
16
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
17
|
+
"@tanstack/react-router": "^1.170.41",
|
|
18
|
+
"@tanstack/react-start": "^1.168.60",
|
|
19
|
+
"@user-hub/auth": "^0.1.4",
|
|
20
|
+
"class-variance-authority": "^0.7.1",
|
|
21
|
+
"cn": "^0.4.0",
|
|
22
|
+
"convex": "^1.46.0",
|
|
23
|
+
"lucide-react": "^1.49.0",
|
|
24
|
+
"react": "^19.3.0",
|
|
25
|
+
"react-dom": "^19.3.0",
|
|
26
|
+
"shadcn": "^4.21.4",
|
|
27
|
+
"tailwindcss": "^4.3.3",
|
|
28
|
+
"tw-animate-css": "^1.4.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@biomejs/biome": "2.5.15",
|
|
32
|
+
"@rolldown/plugin-babel": "^0.2.4",
|
|
33
|
+
"@types/bun": "^1.4.2",
|
|
34
|
+
"@types/react": "^19.3.0",
|
|
35
|
+
"@types/react-dom": "^19.3.0",
|
|
36
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
37
|
+
"babel-plugin-react-compiler": "^1.0.0",
|
|
38
|
+
"typescript": "^7.0.2",
|
|
39
|
+
"vite": "^8.3.1"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// One-time setup: creates the Convex project, registers this app with User
|
|
2
|
+
// Hub and sets the values that make Convex trust the hub's tokens.
|
|
3
|
+
// Run: bun run setup [--name <name>]. Safe to run again.
|
|
4
|
+
// Needs HUB_URL and HUB_ADMIN_PASSWORD in .env.local (Bun loads it).
|
|
5
|
+
|
|
6
|
+
import { existsSync, renameSync } from "node:fs";
|
|
7
|
+
import { rename } from "node:fs/promises";
|
|
8
|
+
|
|
9
|
+
const ENV_FILE = ".env.local";
|
|
10
|
+
const HUB_FILE = "convex/hub.ts";
|
|
11
|
+
const DEV_URL = "http://localhost:3000";
|
|
12
|
+
const AUTH_CONFIG = "convex/auth.config.ts";
|
|
13
|
+
const AUTH_CONFIG_ASIDE = "convex/auth.config.ts.setup";
|
|
14
|
+
|
|
15
|
+
function step(message: string) {
|
|
16
|
+
console.log(`\n▸ ${message}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function fail(message: string): never {
|
|
20
|
+
console.error(`\n✗ ${message}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function run(command: string[], { capture = false } = {}) {
|
|
25
|
+
const child = Bun.spawn(command, {
|
|
26
|
+
stdin: "inherit",
|
|
27
|
+
stdout: capture ? "pipe" : "inherit",
|
|
28
|
+
stderr: "inherit",
|
|
29
|
+
env: process.env,
|
|
30
|
+
});
|
|
31
|
+
const output = capture ? await new Response(child.stdout).text() : "";
|
|
32
|
+
const code = await child.exited;
|
|
33
|
+
return { ok: code === 0, code, output };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function readEnv() {
|
|
37
|
+
const file = Bun.file(ENV_FILE);
|
|
38
|
+
return (await file.exists()) ? await file.text() : "";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Set or replace KEY=value in .env.local.
|
|
42
|
+
async function writeEnv(key: string, value: string) {
|
|
43
|
+
const lines = (await readEnv())
|
|
44
|
+
.split("\n")
|
|
45
|
+
.filter((line) => line && !line.startsWith(`${key}=`));
|
|
46
|
+
await Bun.write(ENV_FILE, `${[...lines, `${key}=${value}`].join("\n")}\n`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Put back an auth config left aside by an interrupted run.
|
|
50
|
+
if (existsSync(AUTH_CONFIG_ASIDE) && !existsSync(AUTH_CONFIG)) {
|
|
51
|
+
renameSync(AUTH_CONFIG_ASIDE, AUTH_CONFIG);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!process.env.HUB_URL || !process.env.HUB_ADMIN_PASSWORD) {
|
|
55
|
+
fail(
|
|
56
|
+
`Add HUB_URL and HUB_ADMIN_PASSWORD to ${ENV_FILE} (ask your hub's admin), then run bun run setup again.`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 1. Convex project. Its first push happens before the hub values exist, so
|
|
61
|
+
// the auth config sits aside for that push only (Convex refuses an auth
|
|
62
|
+
// config whose env vars are unset) and comes back straight after.
|
|
63
|
+
if (!/^CONVEX_DEPLOYMENT=/m.test(await readEnv())) {
|
|
64
|
+
step("Creating your Convex project (sign in to Convex if asked)");
|
|
65
|
+
await rename(AUTH_CONFIG, AUTH_CONFIG_ASIDE);
|
|
66
|
+
const restore = () => {
|
|
67
|
+
if (existsSync(AUTH_CONFIG_ASIDE))
|
|
68
|
+
renameSync(AUTH_CONFIG_ASIDE, AUTH_CONFIG);
|
|
69
|
+
};
|
|
70
|
+
const onInterrupt = () => {
|
|
71
|
+
restore();
|
|
72
|
+
process.exit(130);
|
|
73
|
+
};
|
|
74
|
+
process.on("SIGINT", onInterrupt);
|
|
75
|
+
try {
|
|
76
|
+
await run(["bunx", "convex", "dev", "--once"]);
|
|
77
|
+
} finally {
|
|
78
|
+
process.off("SIGINT", onInterrupt);
|
|
79
|
+
restore();
|
|
80
|
+
}
|
|
81
|
+
if (!/^CONVEX_DEPLOYMENT=/m.test(await readEnv())) {
|
|
82
|
+
fail("No Convex project was created. Run bun run setup again.");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 2. Register with the hub. The first time, --new makes sure this never takes
|
|
87
|
+
// over another app with the same name: if the name is taken, ask for
|
|
88
|
+
// another one. Once registered, the name is kept in .env.local
|
|
89
|
+
// (HUB_APP_NAME) and later runs update this app's own registration.
|
|
90
|
+
step("Registering this app with User Hub");
|
|
91
|
+
const packageName = (
|
|
92
|
+
(await Bun.file("package.json").json()) as { name: string }
|
|
93
|
+
).name;
|
|
94
|
+
// HUB_APP_NAME is written only after a successful registration, so it marks
|
|
95
|
+
// this app's own entry. `bun run setup --name <name>` picks a new name.
|
|
96
|
+
const nameFlag = process.argv.indexOf("--name");
|
|
97
|
+
const alreadyRegistered = Boolean(process.env.HUB_APP_NAME);
|
|
98
|
+
let appName =
|
|
99
|
+
process.env.HUB_APP_NAME ??
|
|
100
|
+
(nameFlag > -1 ? process.argv[nameFlag + 1] : undefined) ??
|
|
101
|
+
packageName;
|
|
102
|
+
let registered: Awaited<ReturnType<typeof run>>;
|
|
103
|
+
for (;;) {
|
|
104
|
+
registered = await run(
|
|
105
|
+
[
|
|
106
|
+
"bunx",
|
|
107
|
+
"hub-user",
|
|
108
|
+
"register",
|
|
109
|
+
"--name",
|
|
110
|
+
appName,
|
|
111
|
+
"--dev",
|
|
112
|
+
DEV_URL,
|
|
113
|
+
"--json",
|
|
114
|
+
...(alreadyRegistered ? [] : ["--new"]),
|
|
115
|
+
],
|
|
116
|
+
{ capture: true },
|
|
117
|
+
);
|
|
118
|
+
// hub-user exits with 3 when --new finds the name taken.
|
|
119
|
+
if (registered.code !== 3) break;
|
|
120
|
+
console.log(`\n An app called "${appName}" already exists in the hub.`);
|
|
121
|
+
if (!process.stdin.isTTY) {
|
|
122
|
+
fail("Choose another name: bun run setup --name <new name>");
|
|
123
|
+
}
|
|
124
|
+
appName = (prompt(" Choose another name for this app:") ?? "").trim();
|
|
125
|
+
if (!appName) fail("No name given. Run bun run setup again.");
|
|
126
|
+
}
|
|
127
|
+
if (!registered.ok) {
|
|
128
|
+
fail(
|
|
129
|
+
"The hub refused the registration. Check HUB_URL and HUB_ADMIN_PASSWORD.",
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
const { key, hubUrl, env } = JSON.parse(registered.output) as {
|
|
133
|
+
key: string;
|
|
134
|
+
hubUrl: string;
|
|
135
|
+
env: { HUB_ISSUER: string; HUB_JWKS: string };
|
|
136
|
+
};
|
|
137
|
+
await writeEnv("HUB_APP_NAME", appName);
|
|
138
|
+
console.log(` Registered as "${appName}", app key: ${key}`);
|
|
139
|
+
|
|
140
|
+
// The key follows the registered name; keep the code in step with it.
|
|
141
|
+
const hubFile = await Bun.file(HUB_FILE).text();
|
|
142
|
+
const updated = hubFile.replace(/APP_KEY = ".*?"/, `APP_KEY = "${key}"`);
|
|
143
|
+
if (updated !== hubFile) {
|
|
144
|
+
await Bun.write(HUB_FILE, updated);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 3. Values Convex and the frontend need.
|
|
148
|
+
step("Setting HUB_ISSUER and HUB_JWKS on Convex");
|
|
149
|
+
for (const [variable, value] of Object.entries(env)) {
|
|
150
|
+
if (!(await run(["bunx", "convex", "env", "set", variable, value])).ok) {
|
|
151
|
+
fail(`Could not set ${variable} on Convex.`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
await writeEnv("VITE_HUB_URL", hubUrl);
|
|
155
|
+
|
|
156
|
+
// 4. Push the functions now that auth is configured.
|
|
157
|
+
step("Deploying the Convex functions");
|
|
158
|
+
if (!(await run(["bunx", "convex", "dev", "--once"])).ok) {
|
|
159
|
+
fail("Convex did not accept the functions; see the error above.");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
console.log(`
|
|
163
|
+
✓ Ready. Start the app:
|
|
164
|
+
|
|
165
|
+
bun run dev
|
|
166
|
+
|
|
167
|
+
Open ${DEV_URL}: you are sent to the hub to pick who to be, then back signed in.`);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Production server: serves the built client files and hands everything else
|
|
2
|
+
// (pages, server routes, server functions) to TanStack Start. Adapted from
|
|
3
|
+
// TanStack's Bun hosting guide, without its in-memory asset preloading.
|
|
4
|
+
import { join, normalize } from "node:path";
|
|
5
|
+
|
|
6
|
+
const PORT = Number(process.env.PORT ?? 3000);
|
|
7
|
+
const CLIENT_DIR = join(import.meta.dir, "dist/client");
|
|
8
|
+
|
|
9
|
+
// Built by `vite build`; a variable keeps TypeScript from resolving it.
|
|
10
|
+
const SERVER_ENTRY = "./dist/server/server.js";
|
|
11
|
+
const { default: app } = (await import(SERVER_ENTRY)) as {
|
|
12
|
+
default: { fetch: (request: Request) => Response | Promise<Response> };
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Built assets have content hashes in their names, so they never change.
|
|
16
|
+
const IMMUTABLE = "public, max-age=31536000, immutable";
|
|
17
|
+
|
|
18
|
+
async function staticFile(pathname: string) {
|
|
19
|
+
const path = normalize(join(CLIENT_DIR, decodeURIComponent(pathname)));
|
|
20
|
+
if (!path.startsWith(CLIENT_DIR) || path === CLIENT_DIR) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const file = Bun.file(path);
|
|
24
|
+
if (!(await file.exists())) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return new Response(file, {
|
|
28
|
+
headers: pathname.startsWith("/assets/")
|
|
29
|
+
? { "Cache-Control": IMMUTABLE }
|
|
30
|
+
: {},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const server = Bun.serve({
|
|
35
|
+
port: PORT,
|
|
36
|
+
async fetch(request) {
|
|
37
|
+
const { pathname } = new URL(request.url);
|
|
38
|
+
if (request.method === "GET" || request.method === "HEAD") {
|
|
39
|
+
const file = await staticFile(pathname);
|
|
40
|
+
if (file) return file;
|
|
41
|
+
}
|
|
42
|
+
return app.fetch(request);
|
|
43
|
+
},
|
|
44
|
+
error(error) {
|
|
45
|
+
console.error("Unhandled server error", error);
|
|
46
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
console.log(`Listening on http://localhost:${server.port}`);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { mergeProps } from "@base-ui/react/merge-props";
|
|
2
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
4
|
+
import { cn } from "cn";
|
|
5
|
+
|
|
6
|
+
const badgeVariants = cva(
|
|
7
|
+
"group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-3xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
|
|
12
|
+
secondary:
|
|
13
|
+
"bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
|
|
14
|
+
destructive:
|
|
15
|
+
"bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20",
|
|
16
|
+
outline:
|
|
17
|
+
"border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
|
|
18
|
+
ghost:
|
|
19
|
+
"hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
|
|
20
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
defaultVariants: {
|
|
24
|
+
variant: "default",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
function Badge({
|
|
30
|
+
className,
|
|
31
|
+
variant = "default",
|
|
32
|
+
render,
|
|
33
|
+
...props
|
|
34
|
+
}: useRender.ComponentProps<"span"> & VariantProps<typeof badgeVariants>) {
|
|
35
|
+
return useRender({
|
|
36
|
+
defaultTagName: "span",
|
|
37
|
+
props: mergeProps<"span">(
|
|
38
|
+
{
|
|
39
|
+
className: cn(badgeVariants({ variant }), className),
|
|
40
|
+
},
|
|
41
|
+
props,
|
|
42
|
+
),
|
|
43
|
+
render,
|
|
44
|
+
state: {
|
|
45
|
+
slot: "badge",
|
|
46
|
+
variant,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { Badge, badgeVariants };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
|
|
5
|
+
const buttonVariants = cva(
|
|
6
|
+
"group/button inline-flex shrink-0 items-center justify-center rounded-4xl border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/30 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
11
|
+
outline:
|
|
12
|
+
"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:bg-transparent dark:hover:bg-input/30",
|
|
13
|
+
secondary:
|
|
14
|
+
"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
15
|
+
ghost:
|
|
16
|
+
"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
17
|
+
destructive:
|
|
18
|
+
"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
|
19
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
20
|
+
},
|
|
21
|
+
size: {
|
|
22
|
+
default:
|
|
23
|
+
"h-9 gap-1.5 px-3 has-data-[icon=inline-end]:pr-2.5 has-data-[icon=inline-start]:pl-2.5",
|
|
24
|
+
xs: "h-6 gap-1 px-2.5 text-xs has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-3",
|
|
25
|
+
sm: "h-8 gap-1 px-3 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
26
|
+
lg: "h-10 gap-1.5 px-4 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",
|
|
27
|
+
icon: "size-9",
|
|
28
|
+
"icon-xs": "size-6 [&_svg:not([class*='size-'])]:size-3",
|
|
29
|
+
"icon-sm": "size-8",
|
|
30
|
+
"icon-lg": "size-10",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
defaultVariants: {
|
|
34
|
+
variant: "default",
|
|
35
|
+
size: "default",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
function Button({
|
|
41
|
+
className,
|
|
42
|
+
variant = "default",
|
|
43
|
+
size = "default",
|
|
44
|
+
...props
|
|
45
|
+
}: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) {
|
|
46
|
+
return (
|
|
47
|
+
<ButtonPrimitive
|
|
48
|
+
data-slot="button"
|
|
49
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { Button, buttonVariants };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { cn } from "cn";
|
|
2
|
+
import type * as React from "react";
|
|
3
|
+
|
|
4
|
+
function Card({
|
|
5
|
+
className,
|
|
6
|
+
size = "default",
|
|
7
|
+
...props
|
|
8
|
+
}: React.ComponentProps<"div"> & { size?: "default" | "sm" }) {
|
|
9
|
+
return (
|
|
10
|
+
<div
|
|
11
|
+
data-slot="card"
|
|
12
|
+
data-size={size}
|
|
13
|
+
className={cn(
|
|
14
|
+
"group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-4xl bg-card py-(--card-spacing) text-sm text-card-foreground shadow-md ring-1 ring-foreground/5 [--card-spacing:--spacing(6)] has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(4)] dark:ring-foreground/10 *:[img:first-child]:rounded-t-4xl *:[img:last-child]:rounded-b-4xl",
|
|
15
|
+
className,
|
|
16
|
+
)}
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
data-slot="card-header"
|
|
26
|
+
className={cn(
|
|
27
|
+
"group/card-header @container/card-header grid auto-rows-min items-start gap-1.5 rounded-t-4xl px-(--card-spacing) has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-(--card-spacing)",
|
|
28
|
+
className,
|
|
29
|
+
)}
|
|
30
|
+
{...props}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
36
|
+
return (
|
|
37
|
+
<div
|
|
38
|
+
data-slot="card-title"
|
|
39
|
+
className={cn("font-heading text-base font-medium", className)}
|
|
40
|
+
{...props}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
data-slot="card-description"
|
|
49
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
56
|
+
return (
|
|
57
|
+
<div
|
|
58
|
+
data-slot="card-action"
|
|
59
|
+
className={cn(
|
|
60
|
+
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
|
61
|
+
className,
|
|
62
|
+
)}
|
|
63
|
+
{...props}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
69
|
+
return (
|
|
70
|
+
<div
|
|
71
|
+
data-slot="card-content"
|
|
72
|
+
className={cn("px-(--card-spacing)", className)}
|
|
73
|
+
{...props}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
79
|
+
return (
|
|
80
|
+
<div
|
|
81
|
+
data-slot="card-footer"
|
|
82
|
+
className={cn(
|
|
83
|
+
"flex items-center rounded-b-4xl px-(--card-spacing) [.border-t]:pt-(--card-spacing)",
|
|
84
|
+
className,
|
|
85
|
+
)}
|
|
86
|
+
{...props}
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
Card,
|
|
93
|
+
CardAction,
|
|
94
|
+
CardContent,
|
|
95
|
+
CardDescription,
|
|
96
|
+
CardFooter,
|
|
97
|
+
CardHeader,
|
|
98
|
+
CardTitle,
|
|
99
|
+
};
|