UI Component Library
Relevant source files
The following files were used as context for generating this wiki page:
The Vinesight project utilizes a UI component library based on shadcn/ui, which is a collection of reusable, accessible, and stylable components. This is not a traditional component library published to npm; instead, components are integrated directly into the project's source code under src/components/ui, allowing for full customization. The architecture leverages Radix UI for accessibility and behavior primitives, and Tailwind CSS for styling.
This approach provides a consistent and maintainable set of UI elements across the application, from simple buttons and badges to complex dialogs and cards. The components are designed to be composable and are used extensively in application pages like the Grape Farming Guide and Help Center.
Sources: AGENTS.md, src/app/grape-farming-guide/page.tsx, src/components/ui/button.tsx
Core Technologies
The UI component library is built upon a modern stack of front-end technologies. The package.json and AGENTS.md files confirm the use of the following key libraries.
| Library | Purpose |
|---|---|
| shadcn/ui | A collection of pre-built, customizable React components. It provides the CLI for adding new components. |
| Radix UI | Provides unstyled, accessible, and low-level UI primitives that form the foundation for components like Dialog, Select, and Checkbox. |
| Tailwind CSS | A utility-first CSS framework used for all component styling. |
class-variance-authority | A library for creating type-safe, variant-based component styles. It is used to define different visual states (e.g., variant, size) for components like Button and Badge. |
clsx & tailwind-merge | Utility libraries, combined into a cn() function, for conditionally applying and merging Tailwind CSS classes without style conflicts. |
Sources: package.json:13-39, AGENTS.md:10, src/components/ui/button.tsx:7-8
Component Architecture
The components in src/components/ui follow a consistent architectural pattern that layers these technologies.
This diagram illustrates the layered architecture of a typical UI component in this library.
- Application Page: A page like
grape-farming-guide/page.tsximports and uses the UI components. - Vinesight Component: The component itself (e.g.,
Button.tsx) is a React functional component. - Core Technologies:
- It wraps a Radix UI Primitive to handle accessibility and state management.
- It uses
class-variance-authority(CVA) to define different visual variants. - It applies Tailwind CSS classes using the
cn()utility function for styling.
Sources: src/components/ui/button.tsx, src/components/ui/dialog.tsx, src/app/grape-farming-guide/page.tsx
Component Configuration
The components.json file configures the shadcn/ui CLI, defining how and where components are added to the project.
| Property | Value | Description |
|---|---|---|
style | "default" | The default visual style for the components. |
rsc | false | Indicates that components are not configured as React Server Components by default. |
tsx | true | Components are generated as TypeScript (.tsx) files. |
tailwind.config | "tailwind.config.js" | Path to the Tailwind CSS configuration file. |
tailwind.css | "src/app/globals.css" | Path to the global CSS file where Tailwind directives are imported. |
tailwind.baseColor | "slate" | The base color palette used for generating component styles. |
aliases.components | "@/components" | Path alias for the components directory. |
aliases.utils | "@/lib/utils" | Path alias for utility functions, including cn(). |
Sources: components.json
Key Component Examples
Button
The Button component is a prime example of using class-variance-authority (CVA) to manage variants.
Sources: src/components/ui/button.tsx
Variants and Sizes
The buttonVariants function defines the following styles:
| Property | Values | Default | Description |
|---|---|---|---|
variant | default, destructive, outline, secondary, ghost, link | default | Defines the button's visual style (background, border, text color). |
size | default, sm, lg, icon | default | Defines the button's padding and font size. |
Sources: src/components/ui/button.tsx:10-44
Implementation
The buttonVariants are defined using CVA, mapping each variant and size to specific Tailwind CSS classes.
// src/components/ui/button.tsx:10-44
const buttonVariants = cva(
'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',
{
variants: {
variant: {
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
destructive:
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
outline:
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
secondary:
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
ghost: 'hover:bg-accent hover:text-accent-foreground',
link: 'text-primary underline-offset-4 hover:underline',
},
size: {
default: 'h-10 px-4 py-2',
sm: 'h-9 rounded-md px-3',
lg: 'h-11 rounded-md px-8',
icon: 'h-10 w-10',
},
},
defaultVariants: {
variant: 'default',
size: 'default',
},
}
)
The component also uses <Slot> from Radix UI. If the Button is rendered with asChild={true}, it will merge its props and styles onto the immediate child component instead of rendering its own <button> element.
Sources: src/components/ui/button.tsx:55-57
Card
The Card component and its sub-components (CardHeader, CardTitle, CardDescription, CardContent, CardFooter) are used to group related content in a container. They are essentially div elements with pre-defined Tailwind CSS classes, offering a structured and consistent way to build content blocks.
This compositional approach is demonstrated in src/app/grape-farming-guide/page.tsx, where Card is used to structure different sections of the guide.
The following diagram shows how Card components are composed to build a UI element.
Dialog
The Dialog component is a modal overlay that disables interaction with the rest of the application. It is built directly on top of the @radix-ui/react-dialog package, re-exporting its primitives with added styling.
The main parts are:
Dialog: The root provider.DialogTrigger: A button or element that opens the dialog.DialogContent: The main container for the modal's content, which includes an overlay and close button.DialogHeader,DialogTitle,DialogDescription,DialogFooter: Structural components for organizing content within the dialog.
Sources: src/components/ui/dialog.tsx
The interaction flow for a dialog is shown below.
Sources: src/components/ui/dialog.tsx:11-100
Summary
The Vinesight UI Component Library is a well-structured, modern system for building user interfaces. By leveraging shadcn/ui, Radix UI, and Tailwind CSS, it provides a highly customizable, accessible, and maintainable foundation for the application's front end. The direct inclusion of component source code allows developers to easily adapt and extend the library to fit the specific needs of the project, ensuring a consistent look and feel across all features.