question-bank-framework 0.0.0-stage → 0.1.1
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 +105 -2
- package/bin/qb.js +119 -0
- package/bin/qb.ts +128 -0
- package/core/config.tsx +38 -0
- package/core/index.ts +17 -0
- package/core/types.ts +111 -0
- package/framework/components/app-shell.tsx +54 -0
- package/framework/components/filter-builder.tsx +471 -0
- package/framework/components/markdown-content.tsx +109 -0
- package/framework/components/question-bank.tsx +654 -0
- package/framework/components/quiz-list.tsx +110 -0
- package/framework/components/quiz-page.tsx +240 -0
- package/framework/components/ui/badge.tsx +47 -0
- package/framework/components/ui/button.tsx +63 -0
- package/framework/components/ui/checkbox.tsx +29 -0
- package/framework/components/ui/dropdown-menu.tsx +256 -0
- package/framework/components/ui/input.tsx +20 -0
- package/framework/components/ui/popover.tsx +88 -0
- package/framework/components/ui/select.tsx +187 -0
- package/framework/components/ui/sheet.tsx +140 -0
- package/framework/components/ui/table.tsx +121 -0
- package/framework/convex/questionStatuses.ts +30 -0
- package/framework/convex/quizzes.ts +50 -0
- package/framework/convex/schema.ts +18 -0
- package/framework/index.ts +26 -0
- package/framework/lib/convex-api.ts +36 -0
- package/framework/lib/question-filter-store.ts +116 -0
- package/framework/lib/question-filter.ts +362 -0
- package/framework/lib/question-status-storage.ts +117 -0
- package/framework/lib/quiz-storage.ts +118 -0
- package/framework/lib/utils.ts +6 -0
- package/package.json +65 -3
- package/template/bank.config.ts +72 -0
- package/template/content/answers.ts +6 -0
- package/template/content/questions.json +35 -0
- package/template/src/routes/__root.tsx +44 -0
- package/template/src/routes/index.tsx +4 -0
- package/template/src/routes/quiz.$quizId.tsx +4 -0
- package/template/src/routes/quizzes.tsx +4 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Framework-owned: eject with `qb reveal framework/components/quiz-list.tsx`.
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { Link } from '@tanstack/react-router';
|
|
5
|
+
import { Trash2 } from 'lucide-react';
|
|
6
|
+
import { useBank } from '../../core/config.tsx';
|
|
7
|
+
import type { QuizSession } from '../../core/types.ts';
|
|
8
|
+
import { Button } from './ui/button';
|
|
9
|
+
import { deleteQuiz, listQuizzes } from '../lib/quiz-storage.ts';
|
|
10
|
+
|
|
11
|
+
export function QuizList() {
|
|
12
|
+
const bank = useBank();
|
|
13
|
+
const [quizzes, setQuizzes] = useState<QuizSession[]>([]);
|
|
14
|
+
const [loading, setLoading] = useState(true);
|
|
15
|
+
const [deletingId, setDeletingId] = useState<string | null>(null);
|
|
16
|
+
const [deleteError, setDeleteError] = useState(false);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
let active = true;
|
|
20
|
+
listQuizzes(bank.namespace).then((items) => {
|
|
21
|
+
if (active) setQuizzes(items);
|
|
22
|
+
}).finally(() => {
|
|
23
|
+
if (active) setLoading(false);
|
|
24
|
+
});
|
|
25
|
+
return () => {
|
|
26
|
+
active = false;
|
|
27
|
+
};
|
|
28
|
+
}, [bank.namespace]);
|
|
29
|
+
|
|
30
|
+
const removeQuiz = async (quiz: QuizSession) => {
|
|
31
|
+
setDeletingId(quiz.id);
|
|
32
|
+
setDeleteError(false);
|
|
33
|
+
try {
|
|
34
|
+
await deleteQuiz(bank.namespace, quiz.id);
|
|
35
|
+
setQuizzes((current) => current.filter((item) => item.id !== quiz.id));
|
|
36
|
+
} catch {
|
|
37
|
+
setDeleteError(true);
|
|
38
|
+
} finally {
|
|
39
|
+
setDeletingId(null);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className="grid gap-8">
|
|
45
|
+
<div className="flex flex-wrap items-end justify-between gap-4">
|
|
46
|
+
<div>
|
|
47
|
+
<h1 className="m-0 text-3xl font-bold tracking-tight text-gray-900">My quizzes</h1>
|
|
48
|
+
<p className="mt-2 text-base text-gray-600">Pick up where you left off. Your answers are saved as you go.</p>
|
|
49
|
+
</div>
|
|
50
|
+
<Button asChild>
|
|
51
|
+
<Link to="/">Build a quiz</Link>
|
|
52
|
+
</Button>
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
{loading ? (
|
|
56
|
+
<div className="py-16 text-center text-sm text-gray-600">Loading your quizzes...</div>
|
|
57
|
+
) : quizzes.length > 0 ? (
|
|
58
|
+
<div>
|
|
59
|
+
{deleteError && (
|
|
60
|
+
<p role="alert" className="mb-3 text-sm text-red-700">
|
|
61
|
+
Could not delete that quiz. Please try again.
|
|
62
|
+
</p>
|
|
63
|
+
)}
|
|
64
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
|
65
|
+
{quizzes.map((quiz) => {
|
|
66
|
+
const answeredCount = Object.values(quiz.answers).filter((answer) => answer.trim().length > 0).length;
|
|
67
|
+
return (
|
|
68
|
+
<div key={quiz.id} className="group relative">
|
|
69
|
+
<Link
|
|
70
|
+
to="/quiz/$quizId"
|
|
71
|
+
params={{ quizId: quiz.id }}
|
|
72
|
+
className="block rounded-xl border border-gray-200 bg-white p-5 transition-colors hover:border-gray-400 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-gray-500"
|
|
73
|
+
>
|
|
74
|
+
<h2 className="m-0 pr-10 text-lg font-semibold text-gray-900">{quiz.title}</h2>
|
|
75
|
+
<p className="mt-2 text-sm text-gray-700">
|
|
76
|
+
{quiz.questionIds.length} {quiz.questionIds.length === 1 ? 'question' : 'questions'}
|
|
77
|
+
</p>
|
|
78
|
+
<p className="mt-1 text-sm text-gray-600">
|
|
79
|
+
{answeredCount} of {quiz.questionIds.length} answered
|
|
80
|
+
</p>
|
|
81
|
+
</Link>
|
|
82
|
+
<Button
|
|
83
|
+
type="button"
|
|
84
|
+
variant="outline"
|
|
85
|
+
size="icon-xs"
|
|
86
|
+
aria-label={`Delete ${quiz.title}`}
|
|
87
|
+
title="Delete quiz"
|
|
88
|
+
disabled={deletingId === quiz.id}
|
|
89
|
+
onClick={() => removeQuiz(quiz)}
|
|
90
|
+
className="absolute right-3 top-3 rounded-full border-red-200 bg-white text-red-600 opacity-0 shadow-sm transition-opacity hover:border-red-300 hover:bg-red-50 hover:text-red-700 focus-visible:opacity-100 group-hover:opacity-100 group-focus-within:opacity-100"
|
|
91
|
+
>
|
|
92
|
+
<Trash2 aria-hidden="true" />
|
|
93
|
+
</Button>
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
})}
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
) : (
|
|
100
|
+
<div className="mx-auto max-w-xl py-16 text-center">
|
|
101
|
+
<h2 className="m-0 text-xl font-semibold text-gray-900">No quizzes yet</h2>
|
|
102
|
+
<p className="mt-2 text-base text-gray-600">Choose questions from the bank and turn them into a quiz that remembers your progress.</p>
|
|
103
|
+
<Button asChild className="mt-6">
|
|
104
|
+
<Link to="/">Browse questions</Link>
|
|
105
|
+
</Button>
|
|
106
|
+
</div>
|
|
107
|
+
)}
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// Framework-owned: eject with `qb reveal framework/components/quiz-page.tsx`.
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { Link, useParams } from '@tanstack/react-router';
|
|
5
|
+
import { Check, Pencil, X } from 'lucide-react';
|
|
6
|
+
import { useBank } from '../../core/config.tsx';
|
|
7
|
+
import type { QuestionStatus, QuizSession } from '../../core/types.ts';
|
|
8
|
+
import { Badge } from './ui/badge';
|
|
9
|
+
import { Button } from './ui/button';
|
|
10
|
+
import { Input } from './ui/input';
|
|
11
|
+
import { MarkdownContent } from './markdown-content';
|
|
12
|
+
import { setQuestionStatus } from '../lib/question-status-storage.ts';
|
|
13
|
+
import { getQuiz, saveQuizLocally, saveQuizProgress } from '../lib/quiz-storage.ts';
|
|
14
|
+
|
|
15
|
+
export function QuizPage() {
|
|
16
|
+
const bank = useBank();
|
|
17
|
+
const { quizId } = useParams({ from: '/quiz/$quizId' });
|
|
18
|
+
const [session, setSession] = useState<QuizSession | null>(null);
|
|
19
|
+
const [loading, setLoading] = useState(true);
|
|
20
|
+
const [saving, setSaving] = useState(false);
|
|
21
|
+
const [shownAnswerId, setShownAnswerId] = useState<string | null>(null);
|
|
22
|
+
const [editingTitle, setEditingTitle] = useState(false);
|
|
23
|
+
const [titleDraft, setTitleDraft] = useState('');
|
|
24
|
+
const titleInputRef = useRef<HTMLInputElement>(null);
|
|
25
|
+
const quizQuestions = useMemo(
|
|
26
|
+
() =>
|
|
27
|
+
session?.questionIds.map((id) => bank.questionById.get(id)).filter((question) => question !== undefined) ?? [],
|
|
28
|
+
[session, bank],
|
|
29
|
+
);
|
|
30
|
+
const activeIndex = Math.min(session?.currentQuestion ?? 0, Math.max(quizQuestions.length - 1, 0));
|
|
31
|
+
const activeQuestion = quizQuestions[activeIndex];
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
let active = true;
|
|
35
|
+
setShownAnswerId(null);
|
|
36
|
+
getQuiz(bank.namespace, quizId).then((quiz) => {
|
|
37
|
+
if (active) setSession(quiz);
|
|
38
|
+
}).finally(() => {
|
|
39
|
+
if (active) setLoading(false);
|
|
40
|
+
});
|
|
41
|
+
return () => {
|
|
42
|
+
active = false;
|
|
43
|
+
};
|
|
44
|
+
}, [quizId, bank.namespace]);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!session) return;
|
|
48
|
+
saveQuizLocally(bank.namespace, session);
|
|
49
|
+
if (session.id.startsWith('local_')) return;
|
|
50
|
+
setSaving(true);
|
|
51
|
+
const timeout = window.setTimeout(() => {
|
|
52
|
+
saveQuizProgress(
|
|
53
|
+
bank.namespace,
|
|
54
|
+
session,
|
|
55
|
+
{ title: session.title, answers: session.answers, currentQuestion: session.currentQuestion, completed: session.completed },
|
|
56
|
+
)
|
|
57
|
+
.then(() => setSaving(false))
|
|
58
|
+
.catch(() => setSaving(false));
|
|
59
|
+
}, 500);
|
|
60
|
+
return () => window.clearTimeout(timeout);
|
|
61
|
+
}, [session, bank.namespace]);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (editingTitle) {
|
|
65
|
+
titleInputRef.current?.focus();
|
|
66
|
+
titleInputRef.current?.select();
|
|
67
|
+
}
|
|
68
|
+
}, [editingTitle]);
|
|
69
|
+
|
|
70
|
+
const goToQuestion = (index: number) => {
|
|
71
|
+
setShownAnswerId(null);
|
|
72
|
+
setSession((current) => (current ? { ...current, currentQuestion: index, completed: false } : current));
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const updateAnswer = (value: string) => {
|
|
76
|
+
if (!activeQuestion) return;
|
|
77
|
+
setSession((current) =>
|
|
78
|
+
current ? { ...current, completed: false, answers: { ...current.answers, [activeQuestion.id]: value } } : current,
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const updateQuestionStatus = (status: QuestionStatus) => {
|
|
83
|
+
if (!activeQuestion) return;
|
|
84
|
+
void setQuestionStatus(bank.namespace, activeQuestion.id, status);
|
|
85
|
+
setShownAnswerId(null);
|
|
86
|
+
setSession((current) =>
|
|
87
|
+
current
|
|
88
|
+
? {
|
|
89
|
+
...current,
|
|
90
|
+
currentQuestion: Math.min(activeIndex + 1, quizQuestions.length - 1),
|
|
91
|
+
completed: activeIndex === quizQuestions.length - 1,
|
|
92
|
+
}
|
|
93
|
+
: current,
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const startEditingTitle = () => {
|
|
98
|
+
if (!session) return;
|
|
99
|
+
setTitleDraft(session.title);
|
|
100
|
+
setEditingTitle(true);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const saveTitle = () => {
|
|
104
|
+
const title = titleDraft.trim();
|
|
105
|
+
if (!title) return;
|
|
106
|
+
setSession((current) => (current ? { ...current, title } : current));
|
|
107
|
+
setEditingTitle(false);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
if (loading) return <div className="py-16 text-center text-sm text-gray-600">Opening your quiz...</div>;
|
|
111
|
+
|
|
112
|
+
if (!session || !activeQuestion || quizQuestions.length === 0) {
|
|
113
|
+
return (
|
|
114
|
+
<div className="mx-auto max-w-xl py-16 text-center">
|
|
115
|
+
<h1 className="text-2xl font-bold text-gray-900">Quiz not found</h1>
|
|
116
|
+
<p className="mt-2 text-base text-gray-600">This practice set may have been removed from this browser.</p>
|
|
117
|
+
<Button asChild className="mt-6">
|
|
118
|
+
<Link to="/quizzes">Back to My quizzes</Link>
|
|
119
|
+
</Button>
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const answer = session.answers[activeQuestion.id] ?? '';
|
|
125
|
+
const suggestedAnswer = bank.answers[activeQuestion.id];
|
|
126
|
+
const isSuggestedAnswerShown = shownAnswerId === activeQuestion.id;
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div className="mx-auto grid max-w-3xl gap-6">
|
|
130
|
+
<Link to="/quizzes" className="text-sm font-semibold text-gray-600 hover:text-gray-900">
|
|
131
|
+
Back to My quizzes
|
|
132
|
+
</Link>
|
|
133
|
+
|
|
134
|
+
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
135
|
+
{editingTitle ? (
|
|
136
|
+
<form
|
|
137
|
+
className="flex min-w-0 flex-1 items-center gap-2"
|
|
138
|
+
onSubmit={(event) => {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
saveTitle();
|
|
141
|
+
}}
|
|
142
|
+
>
|
|
143
|
+
<Input
|
|
144
|
+
ref={titleInputRef}
|
|
145
|
+
aria-label="Quiz title"
|
|
146
|
+
value={titleDraft}
|
|
147
|
+
onChange={(event) => setTitleDraft(event.target.value)}
|
|
148
|
+
onKeyDown={(event) => {
|
|
149
|
+
if (event.key === 'Escape') setEditingTitle(false);
|
|
150
|
+
}}
|
|
151
|
+
className="h-auto min-w-0 border-gray-300 px-2 py-1 text-2xl font-bold tracking-tight md:text-3xl"
|
|
152
|
+
/>
|
|
153
|
+
<Button type="submit" size="icon-sm" aria-label="Save title" title="Save title" disabled={!titleDraft.trim()}>
|
|
154
|
+
<Check aria-hidden="true" />
|
|
155
|
+
</Button>
|
|
156
|
+
<Button type="button" variant="ghost" size="icon-sm" aria-label="Cancel title edit" title="Cancel" onClick={() => setEditingTitle(false)}>
|
|
157
|
+
<X aria-hidden="true" />
|
|
158
|
+
</Button>
|
|
159
|
+
</form>
|
|
160
|
+
) : (
|
|
161
|
+
<div className="flex min-w-0 items-center gap-2">
|
|
162
|
+
<h1 className="m-0 text-3xl font-bold tracking-tight text-gray-900">{session.title}</h1>
|
|
163
|
+
<Button type="button" variant="ghost" size="icon-xs" aria-label="Edit quiz title" title="Edit quiz title" onClick={startEditingTitle}>
|
|
164
|
+
<Pencil aria-hidden="true" />
|
|
165
|
+
</Button>
|
|
166
|
+
</div>
|
|
167
|
+
)}
|
|
168
|
+
<span className="text-sm text-gray-600">{saving ? 'Saving...' : 'Saved'}</span>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
<p className="text-base font-semibold text-gray-900">
|
|
172
|
+
Question {activeIndex + 1} of {quizQuestions.length}
|
|
173
|
+
</p>
|
|
174
|
+
|
|
175
|
+
<section className="rounded-xl border border-gray-200 bg-white p-5">
|
|
176
|
+
<h2 className="m-0 text-xl font-semibold text-gray-900">{activeQuestion.title}</h2>
|
|
177
|
+
<p className="mt-1 font-mono text-xs text-gray-500">{activeQuestion.id}</p>
|
|
178
|
+
{activeQuestion.tags.length > 0 && (
|
|
179
|
+
<div className="mt-2 flex flex-wrap gap-1">
|
|
180
|
+
{activeQuestion.tags.map((tag) => (
|
|
181
|
+
<Badge key={tag} variant="secondary">
|
|
182
|
+
{tag}
|
|
183
|
+
</Badge>
|
|
184
|
+
))}
|
|
185
|
+
</div>
|
|
186
|
+
)}
|
|
187
|
+
<MarkdownContent content={activeQuestion.prompt} className="mt-4 text-base leading-relaxed text-gray-800" />
|
|
188
|
+
|
|
189
|
+
<div className="mt-6">
|
|
190
|
+
<label htmlFor="quiz-answer" className="text-sm font-semibold text-gray-900">
|
|
191
|
+
Your answer
|
|
192
|
+
</label>
|
|
193
|
+
<textarea
|
|
194
|
+
id="quiz-answer"
|
|
195
|
+
value={answer}
|
|
196
|
+
onChange={(event) => updateAnswer(event.target.value)}
|
|
197
|
+
placeholder="Write your working or notes here..."
|
|
198
|
+
className="mt-2 block min-h-40 w-full resize-y rounded-lg border border-gray-300 bg-white p-3 text-base leading-relaxed text-gray-900 outline-none placeholder:text-gray-400"
|
|
199
|
+
/>
|
|
200
|
+
</div>
|
|
201
|
+
|
|
202
|
+
{suggestedAnswer && (
|
|
203
|
+
<div className="mt-5">
|
|
204
|
+
<Button
|
|
205
|
+
variant="outline"
|
|
206
|
+
aria-expanded={isSuggestedAnswerShown}
|
|
207
|
+
aria-controls="suggested-answer"
|
|
208
|
+
onClick={() => setShownAnswerId(isSuggestedAnswerShown ? null : activeQuestion.id)}
|
|
209
|
+
>
|
|
210
|
+
{isSuggestedAnswerShown ? 'Hide answer' : 'Show answer'}
|
|
211
|
+
</Button>
|
|
212
|
+
{isSuggestedAnswerShown && (
|
|
213
|
+
<section id="suggested-answer" className="mt-4 rounded-lg border border-gray-200 bg-gray-50 p-4">
|
|
214
|
+
<h3 className="m-0 text-base font-semibold text-gray-900">Suggested answer</h3>
|
|
215
|
+
<MarkdownContent content={suggestedAnswer} className="mt-3 text-sm leading-relaxed text-gray-800" />
|
|
216
|
+
</section>
|
|
217
|
+
)}
|
|
218
|
+
</div>
|
|
219
|
+
)}
|
|
220
|
+
|
|
221
|
+
<div className="mt-6 flex flex-wrap items-center justify-between gap-3">
|
|
222
|
+
<Button variant="outline" onClick={() => goToQuestion(Math.max(activeIndex - 1, 0))} disabled={activeIndex === 0}>
|
|
223
|
+
Previous
|
|
224
|
+
</Button>
|
|
225
|
+
<div className="ml-auto flex flex-wrap items-center justify-end gap-2">
|
|
226
|
+
<Button variant="outline" onClick={() => updateQuestionStatus('unanswered')} disabled={session.completed}>
|
|
227
|
+
Skip
|
|
228
|
+
</Button>
|
|
229
|
+
<Button onClick={() => updateQuestionStatus('revisit')} disabled={session.completed} className="bg-amber-400 text-gray-950 hover:bg-amber-500">
|
|
230
|
+
Revisit
|
|
231
|
+
</Button>
|
|
232
|
+
<Button onClick={() => updateQuestionStatus('complete')} disabled={session.completed}>
|
|
233
|
+
{session.completed ? 'Quiz complete' : 'Mark as complete'}
|
|
234
|
+
</Button>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
</section>
|
|
238
|
+
</div>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
import { cn } from '../../lib/utils.ts'
|
|
4
|
+
import { Slot } from "radix-ui"
|
|
5
|
+
|
|
6
|
+
const badgeVariants = cva(
|
|
7
|
+
"inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 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/90",
|
|
12
|
+
secondary:
|
|
13
|
+
"bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
|
14
|
+
destructive:
|
|
15
|
+
"bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90",
|
|
16
|
+
outline:
|
|
17
|
+
"border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
|
18
|
+
ghost: "[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
|
19
|
+
link: "text-primary underline-offset-4 [a&]:hover:underline",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
defaultVariants: {
|
|
23
|
+
variant: "default",
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
function Badge({
|
|
29
|
+
className,
|
|
30
|
+
variant = "default",
|
|
31
|
+
asChild = false,
|
|
32
|
+
...props
|
|
33
|
+
}: React.ComponentProps<"span"> &
|
|
34
|
+
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
|
35
|
+
const Comp = asChild ? Slot.Root : "span"
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Comp
|
|
39
|
+
data-slot="badge"
|
|
40
|
+
data-variant={variant}
|
|
41
|
+
className={cn(badgeVariants({ variant }), className)}
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { Badge, badgeVariants }
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
import { cn } from '../../lib/utils.ts'
|
|
4
|
+
import { Slot } from "radix-ui"
|
|
5
|
+
|
|
6
|
+
const buttonVariants = cva(
|
|
7
|
+
"inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
12
|
+
destructive:
|
|
13
|
+
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40",
|
|
14
|
+
outline:
|
|
15
|
+
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
16
|
+
secondary:
|
|
17
|
+
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
18
|
+
ghost:
|
|
19
|
+
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
20
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
21
|
+
},
|
|
22
|
+
size: {
|
|
23
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
24
|
+
xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
25
|
+
sm: "h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",
|
|
26
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
27
|
+
icon: "size-9",
|
|
28
|
+
"icon-xs": "size-6 rounded-md [&_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
|
+
asChild = false,
|
|
45
|
+
...props
|
|
46
|
+
}: React.ComponentProps<"button"> &
|
|
47
|
+
VariantProps<typeof buttonVariants> & {
|
|
48
|
+
asChild?: boolean
|
|
49
|
+
}) {
|
|
50
|
+
const Comp = asChild ? Slot.Root : "button"
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Comp
|
|
54
|
+
data-slot="button"
|
|
55
|
+
data-variant={variant}
|
|
56
|
+
data-size={size}
|
|
57
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
58
|
+
{...props}
|
|
59
|
+
/>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { Button, buttonVariants }
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cn } from '../../lib/utils.ts'
|
|
3
|
+
import { CheckIcon } from "lucide-react"
|
|
4
|
+
import { Checkbox as CheckboxPrimitive } from "radix-ui"
|
|
5
|
+
|
|
6
|
+
function Checkbox({
|
|
7
|
+
className,
|
|
8
|
+
...props
|
|
9
|
+
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
|
10
|
+
return (
|
|
11
|
+
<CheckboxPrimitive.Root
|
|
12
|
+
data-slot="checkbox"
|
|
13
|
+
className={cn(
|
|
14
|
+
"peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary",
|
|
15
|
+
className
|
|
16
|
+
)}
|
|
17
|
+
{...props}
|
|
18
|
+
>
|
|
19
|
+
<CheckboxPrimitive.Indicator
|
|
20
|
+
data-slot="checkbox-indicator"
|
|
21
|
+
className="grid place-content-center text-current transition-none"
|
|
22
|
+
>
|
|
23
|
+
<CheckIcon className="size-3.5" />
|
|
24
|
+
</CheckboxPrimitive.Indicator>
|
|
25
|
+
</CheckboxPrimitive.Root>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { Checkbox }
|