Scaffold web frontend: mock-backed chat + PDF split-view, Tailwind/shadcn

This commit is contained in:
2026-07-31 12:16:47 +07:00
parent b72d4bf9d9
commit 967b917001
43 changed files with 5192 additions and 7 deletions
+22
View File
@@ -0,0 +1,22 @@
import type { ChatMessage } from "@duoc-thu/shared-types";
import { cn } from "./lib/utils";
export interface ChatBubbleProps {
message: ChatMessage;
}
export function ChatBubble({ message }: ChatBubbleProps) {
const isUser = message.role === "user";
return (
<div
className={cn(
"max-w-lg rounded-2xl px-4 py-3 text-[1.02rem] leading-relaxed shadow-sm",
isUser
? "ml-auto rounded-br-sm bg-primary text-primary-foreground"
: "mr-auto rounded-bl-sm bg-muted text-foreground"
)}
>
<p className="m-0 whitespace-pre-wrap">{message.content}</p>
</div>
);
}
+39
View File
@@ -0,0 +1,39 @@
import { FileText } from "lucide-react";
import type { Citation } from "@duoc-thu/shared-types";
import { badgeVariants } from "./primitives/badge";
import { cn } from "./lib/utils";
export interface CitationCardProps {
citation: Citation;
onClick?: () => void;
}
export function CitationCard({ citation, onClick }: CitationCardProps) {
const [fromPage, toPage] = citation.sourcePageRange;
const className = cn(
badgeVariants({ variant: "outline" }),
"mr-1.5 mt-1 border-primary/20 bg-primary/5 font-normal text-foreground",
onClick && "cursor-pointer transition-colors hover:bg-primary/10"
);
const content = (
<>
<FileText className="h-3.5 w-3.5 text-primary" aria-hidden="true" />
<span className="font-bold text-primary">{citation.drugName}</span>
<span className="text-muted-foreground">{citation.sectionType}</span>
<span className="text-muted-foreground">
tr. {fromPage}
{toPage !== fromPage ? `${toPage}` : ""}
</span>
</>
);
if (onClick) {
return (
<button type="button" className={className} onClick={onClick}>
{content}
</button>
);
}
return <div className={className}>{content}</div>;
}
+28
View File
@@ -0,0 +1,28 @@
import { TriangleAlert } from "lucide-react";
import { Alert, AlertDescription } from "./primitives/alert";
import { cn } from "./lib/utils";
const DEFAULT_TEXT =
"Nội dung trả lời được tổng hợp từ Dược thư quốc gia Việt Nam và chỉ mang tính tham khảo, " +
"không thay thế chỉ định của bác sĩ hoặc dược sĩ.";
export interface DisclaimerBannerProps {
text?: string;
className?: string;
}
export function DisclaimerBanner({ text = DEFAULT_TEXT, className }: DisclaimerBannerProps) {
return (
<Alert
variant="warning"
className={cn(
"flex items-center justify-center gap-2 rounded-none border-x-0 border-t-0 py-2.5 text-center",
"[&>svg]:static [&>svg]:left-auto [&>svg]:top-auto [&>svg~*]:pl-0",
className
)}
>
<TriangleAlert className="h-4 w-4 shrink-0" aria-hidden="true" />
<AlertDescription>{text}</AlertDescription>
</Alert>
);
}
+9 -1
View File
@@ -1 +1,9 @@
export {};
export * from "./ChatBubble";
export * from "./CitationCard";
export * from "./DisclaimerBanner";
export * from "./primitives/button";
export * from "./primitives/card";
export * from "./primitives/input";
export * from "./primitives/alert";
export * from "./primitives/badge";
export * from "./lib/utils";
+6
View File
@@ -0,0 +1,6 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
+36
View File
@@ -0,0 +1,36 @@
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "../lib/utils";
const alertVariants = cva(
"relative w-full rounded-lg border px-4 py-3 text-sm [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-3.5 [&>svg~*]:pl-7",
{
variants: {
variant: {
default: "bg-background text-foreground",
warning: "border-warning/40 bg-warning text-warning-foreground [&>svg]:text-warning-foreground",
},
},
defaultVariants: {
variant: "default",
},
}
);
const Alert = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
>(({ className, variant, ...props }, ref) => (
<div ref={ref} role="alert" className={cn(alertVariants({ variant }), className)} {...props} />
));
Alert.displayName = "Alert";
const AlertDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p ref={ref} className={cn("leading-relaxed", className)} {...props} />
));
AlertDescription.displayName = "AlertDescription";
export { Alert, AlertDescription };
+29
View File
@@ -0,0 +1,29 @@
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "../lib/utils";
const badgeVariants = cva(
"inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default: "border-transparent bg-primary text-primary-foreground",
secondary: "border-transparent bg-secondary text-secondary-foreground",
outline: "border-border bg-accent text-accent-foreground",
},
},
defaultVariants: {
variant: "default",
},
}
);
export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}
function Badge({ className, variant, ...props }: BadgeProps) {
return <div className={cn(badgeVariants({ variant }), className)} {...props} />;
}
export { Badge, badgeVariants };
+46
View File
@@ -0,0 +1,46 @@
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "../lib/utils";
const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-semibold 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",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
ghost: "hover:bg-accent hover:text-accent-foreground",
},
size: {
default: "h-11 px-5 py-2",
sm: "h-9 px-3",
lg: "h-12 px-8 text-base",
icon: "h-10 w-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
);
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean;
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button";
return (
<Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
);
}
);
Button.displayName = "Button";
export { Button, buttonVariants };
+36
View File
@@ -0,0 +1,36 @@
import * as React from "react";
import { cn } from "../lib/utils";
const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("rounded-xl border bg-card text-card-foreground shadow-sm", className)}
{...props}
/>
)
);
Card.displayName = "Card";
const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn("flex flex-col gap-1.5 p-6", className)} {...props} />
)
);
CardHeader.displayName = "CardHeader";
const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
)
);
CardContent.displayName = "CardContent";
const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn("flex items-center p-6 pt-0", className)} {...props} />
)
);
CardFooter.displayName = "CardFooter";
export { Card, CardHeader, CardContent, CardFooter };
+21
View File
@@ -0,0 +1,21 @@
import * as React from "react";
import { cn } from "../lib/utils";
export type InputProps = React.InputHTMLAttributes<HTMLInputElement>;
const Input = React.forwardRef<HTMLInputElement, InputProps>(({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
"flex h-11 w-full rounded-md border border-input bg-background px-4 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className
)}
ref={ref}
{...props}
/>
);
});
Input.displayName = "Input";
export { Input };