Students should first follow the experiment guide to proceed with the project
- Install Shadcn Components (if not already installed)
pnpm dlx shadcn@latest add card button select badge2b/
├── app/
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout component
│ └── page.tsx # Main homepage with product filtering
├── components/
│ ├── ui/ # Shadcn UI components
│ │ ├── badge.tsx
│ │ ├── card.tsx
│ │ └── select.tsx
│ ├── product-card.tsx # Product display card component
│ └── select-control.tsx # Reusable select dropdown component
├── lib/
│ └── utils.ts # Utility functions
├── public/ # Static assets
├── types/
│ └── index.ts # TypeScript type definitions
├── components.json # Shadcn UI configuration
├── eslint.config.mjs # ESLint configuration
├── next.config.ts # Next.js configuration
├── package.json # Project dependencies
├── pnpm-lock.yaml # Lock file
├── pnpm-workspace.yaml # pnpm workspace config
├── postcss.config.mjs # PostCSS configuration
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
To start the development server:
pnpm devThe application will be available at http://localhost:3000
This file defines TypeScript types used throughout the application:
SelectOption: A type definition for select dropdown optionsvalue: string - The underlying value used for the optionlabel: string - The display text shown to users
A reusable select dropdown component built with Shadcn UI:
- Purpose: Provides a customizable select dropdown with label and grouped options
- Props:
selectLabel: Text label displayed before the selectvalue: Current selected value (controlled)onValueChange: Callback function when selection changesoptions: Array of SelectOption objectsgroupLabel: Label for the option groupplaceholder: Placeholder text when no value selected
- Features:
- Uses Shadcn's Select components for a consistent UI
- Styled with Tailwind CSS (white background, large text, custom height)
- Displays label and select in a horizontal flex layout
A card component for displaying product information:
- Purpose: Renders individual product details in a card format
- Props:
name: Product name (string)price: Product price (number)category: Product category ("electronics" | "clothing" | string)
- Features:
- Uses Shadcn's Card components (Card, CardHeader, CardTitle, CardContent)
- Displays product name as a large title (3xl)
- Shows price formatted to 2 decimal places ($XX.XX)
- Renders category as a colored badge:
- "electronics" → default variant
- "clothing" → secondary variant
- Styled with white background and gray border
The main application page with product filtering and sorting:
- Purpose: Homepage that displays a filterable and sortable product list
- State Management:
filterCategory: Controls product filtering by categorysortBy: Controls product sorting order
- Data:
- Contains 4 sample products (2 electronics, 2 clothing items)
- Each product has: id, name, price, category
- Features:
- Category Filter: Select between "All Products", "Electronics", or "Clothing"
- Sort Options: Default, Price Low to High, or Price High to Low
- Dynamic Filtering: Products filter based on selected category
- Dynamic Sorting: Products sort by price (ascending/descending)
- Responsive Grid: 1 column on mobile, 2 columns on medium+ screens
- Clean UI: Gray background with centered content container
- User selects a category filter (defaults to "All Products")
- User selects a sort option (defaults to "Default")
- Products are filtered by category (if not "all")
- Filtered products are sorted by price (if not "default")
- Results display in a responsive grid using ProductCard components
- Framework: Next.js 14+ (App Router with "use client")
- UI Library: Shadcn UI
- Styling: Tailwind CSS
- Language: TypeScript
- State Management: React useState hooks