# UI Components Library
**Version:** 2.0
**Last Updated:** December 2024
**Live Reference:** `/admin/components`
---
## Overview
The admin panel uses a consistent set of UI components built with Tailwind CSS and Alpine.js. All components support dark mode and are fully accessible.
**Live Component Library:** Visit `/admin/components` in the admin panel to see all components with copy-paste ready code.
!!! tip "Use Jinja Macros Instead"
For new development, prefer using the **[Jinja Macros Library](jinja-macros.md)** instead of copy-pasting HTML. Macros provide:
- **Consistency:** Same styling across all pages
- **Maintainability:** Update once, apply everywhere
- **Less code:** Parameters instead of full HTML
- **Type safety:** Built-in Alpine.js bindings
```jinja
{# Instead of 20 lines of HTML... #}
{% from 'shared/macros/buttons.html' import btn_primary %}
{{ btn_primary('Save Changes', icon='check', onclick='save()') }}
```
See [Jinja Macros Library](jinja-macros.md) for full documentation.
---
## Page Layout Structure
All admin list pages follow a consistent structure:
```
┌─────────────────────────────────────────────────────┐
│ Page Header (Title + Action Button) │
├─────────────────────────────────────────────────────┤
│ Stats Cards (4 columns on desktop) │
├─────────────────────────────────────────────────────┤
│ Search & Filters Bar │
├─────────────────────────────────────────────────────┤
│ Data Table │
│ ├── Table Header │
│ ├── Table Rows │
│ └── Pagination │
└─────────────────────────────────────────────────────┘
```
---
## Form Components
### Basic Input
```html
```
### Required Field with Validation
```html
```
### Disabled/Read-Only Input
```html
```
### Textarea
```html
```
### Select
```html
```
---
## Button Components
### Primary Button
```html
```
### Button with Icon
```html
```
### Secondary Button
```html
```
### Danger Button
```html
```
---
## Card Components
### Stats Card
```html
```
### Stats Card Colors
| Color | Use Case | Classes |
|-------|----------|---------|
| Blue | Total counts | `text-blue-500 bg-blue-100` |
| Green | Active/Success | `text-green-500 bg-green-100` |
| Red | Inactive/Errors | `text-red-500 bg-red-100` |
| Orange | Warnings/Admin | `text-orange-500 bg-orange-100` |
| Purple | Primary metrics | `text-purple-500 bg-purple-100` |
### Info Card
```html
```
---
## Status Badges
### Success Badge
```html
Active
```
### Warning Badge
```html
Pending
```
### Danger Badge
```html
Inactive
```
### Dynamic Badge
```html
```
---
## Data Tables
### Basic Table Structure
```html
```
### Action Buttons
```html
```
---
## Loading & Error States
### Loading State
```html
```
### Error Alert
```html
```
### Empty State
```html
```
---
## Modal Components
### Confirmation Modal
```html
Confirm Action
Are you sure you want to perform this action?
```
---
## Toast Notifications
Use the global Utils helper:
```javascript
Utils.showToast('Operation successful!', 'success');
Utils.showToast('Something went wrong', 'error');
Utils.showToast('Please check your input', 'warning');
Utils.showToast('Here is some information', 'info');
```
---
## Grid Layouts
### 2 Columns (Desktop)
```html
```
### 4 Columns (Stats Cards)
```html
```
---
## Color Reference
| Type | Primary | Success | Warning | Danger | Info |
|------|---------|---------|---------|--------|------|
| Background | `bg-purple-600` | `bg-green-600` | `bg-orange-600` | `bg-red-600` | `bg-blue-600` |
| Text | `text-purple-600` | `text-green-600` | `text-orange-600` | `text-red-600` | `text-blue-600` |
| Light BG | `bg-purple-100` | `bg-green-100` | `bg-orange-100` | `bg-red-100` | `bg-blue-100` |
---
## Common Icons
| Icon | Use Case |
|------|----------|
| `user-group` | Users/Teams |
| `badge-check` | Verified |
| `check-circle` | Success |
| `x-circle` | Error/Inactive |
| `clock` | Pending |
| `calendar` | Dates |
| `edit` | Edit |
| `delete` | Delete |
| `plus` | Add |
| `arrow-left` | Back |
| `exclamation` | Warning |
| `spinner` | Loading |
---
## JavaScript Patterns
### List Page Structure
```javascript
function adminResourceList() {
return {
...data(), // Inherit base layout
currentPage: 'resource-name',
// State
items: [],
loading: false,
error: null,
filters: { search: '', status: '' },
stats: {},
pagination: { page: 1, per_page: 10, total: 0 },
async init() {
await this.loadItems();
await this.loadStats();
},
async loadItems() { /* ... */ },
debouncedSearch() { /* ... */ },
async deleteItem(item) { /* ... */ }
};
}
```
---
## Related Documentation
- **[Jinja Macros Library](jinja-macros.md)** - Reusable macro components (recommended)
- [Pagination Guide](pagination.md)
- [CDN Fallback Strategy](../cdn-fallback-strategy.md)
- [Tailwind CSS](../tailwind-css.md)
- [Icons Guide](../../development/icons-guide.md)
- [Tailwind CSS Official Docs](https://tailwindcss.com/docs)
- [Alpine.js Official Docs](https://alpinejs.dev/)