- Add complete dark mode system with theme context and toggle - Implement dark mode toggle component in navigation menu - Add client-side routing with SSR-safe signal handling - Fix language selector styling for better dark mode compatibility - Add documentation system with mdBook integration - Improve navigation menu with proper external/internal link handling - Add comprehensive project documentation and configuration - Enhance theme system with localStorage persistence - Fix arena panic issues during server-side rendering - Add proper TypeScript configuration and build optimizations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
6.6 KiB
DaisyUI Integration Guide
This document explains how DaisyUI has been integrated into this Rust web application template using UnoCSS.
Overview
DaisyUI is a semantic component library built on top of Tailwind CSS that provides pre-built components like buttons, cards, modals, and more. This project integrates DaisyUI using the unocss-preset-daisy preset, which allows you to use DaisyUI components with UnoCSS instead of Tailwind CSS.
Installation
DaisyUI has been integrated using the following steps:
- Installed the preset:
unocss-preset-daisypackage - Updated UnoCSS configuration: Added the DaisyUI preset to
uno.config.ts - Created example components: Added comprehensive examples in
client/src/components/daisy_example.rs - Added route: Created
/daisyuiroute to showcase the components
Configuration
The DaisyUI preset is configured in uno.config.ts:
import { presetDaisy } from "unocss-preset-daisy";
export default defineConfig({
// ... other config
presets: [
presetUno(),
presetAttributify(),
presetIcons({
scale: 1.2,
autoInstall: true,
collections: {
carbon: () =>
import("@iconify-json/carbon/icons.json").then((i) => i.default),
},
}),
presetTypography(),
presetWebFonts({
fonts: {
// ...
},
}),
presetDaisy(), // DaisyUI preset
],
// ... other config
});
Available Components
The integration includes all standard DaisyUI components:
Buttons
btn- Basic buttonbtn-primary,btn-secondary,btn-accent- Colored buttonsbtn-outline- Outline buttonsbtn-ghost,btn-link- Ghost and link buttonsbtn-lg,btn-md,btn-sm,btn-xs- Button sizes
Cards
card- Basic card containercard-body- Card content areacard-title- Card titlecard-actions- Card action buttons area
Forms
form-control- Form control wrapperlabel- Form labelsinput- Text inputs withinput-borderedvariantselect- Select dropdowns withselect-borderedvariantcheckbox- Checkboxesradio- Radio buttons
Feedback
alert- Alert messages with variants:alert-info,alert-success,alert-warning,alert-errorbadge- Small status indicators with color variantsprogress- Progress bars with color variantsloading- Loading spinners and dots
Navigation
tabs- Tab navigation withtab-liftedvariantmodal- Modal dialogs withmodal-boxcontent
Layout
hero- Hero sections withhero-contentcontainer- Container for content
Color System
DaisyUI uses a semantic color system:
- Primary Colors:
primary,primary-content - Secondary Colors:
secondary,secondary-content - Accent Colors:
accent,accent-content - Neutral Colors:
neutral,neutral-content - Base Colors:
base-100,base-200,base-300,base-content - State Colors:
info,success,warning,error
Usage in Leptos Components
Here's an example of using DaisyUI components in a Leptos component:
use leptos::prelude::*;
#[component]
pub fn ExampleComponent() -> impl IntoView {
let (count, set_count) = signal(0);
view! {
<div class="card bg-base-100 shadow-xl">
<div class="card-body">
<h2 class="card-title">"Counter Example"</h2>
<div class="text-center">
<div class="text-4xl font-bold text-primary mb-4">
{move || count.get()}
</div>
<div class="card-actions justify-center">
<button
class="btn btn-primary"
on:click=move |_| set_count.update(|c| *c += 1)
>
"Increment"
</button>
<button
class="btn btn-secondary"
on:click=move |_| set_count.set(0)
>
"Reset"
</button>
</div>
</div>
</div>
</div>
}
}
Themes
DaisyUI supports multiple themes. To use a theme, add the data-theme attribute to your HTML:
<html data-theme="dark">
<!-- or -->
<html data-theme="cupcake">
Available themes include:
light(default)darkcupcakebumblebeeemeraldcorporatesynthwaveretrocyberpunkvalentinehalloweengardenforestaqualofipastelfantasywireframeblackluxurydraculacmykautumnbusinessacidlemonadenightcoffeewinterdimnordsunset
Building and Development
To build the CSS with DaisyUI components:
pnpm run build:css
To watch for changes during development:
pnpm run dev
Example Page
Visit /daisyui to see a comprehensive showcase of all DaisyUI components in action. The example page includes:
- Button variations and sizes
- Card layouts
- Form elements
- Interactive components (modals, counters)
- Alerts and badges
- Progress indicators
- Tab navigation
- Loading states
Customization
You can customize DaisyUI by:
- CSS Variables: Override DaisyUI's CSS variables in your global styles
- UnoCSS Shortcuts: Add custom shortcuts in
uno.config.ts - Theme Customization: Create custom themes using DaisyUI's theme system
Performance
Using unocss-preset-daisy with UnoCSS provides:
- On-demand generation: Only the components you use are included in the final CSS
- Fast builds: UnoCSS's atomic approach ensures fast compilation
- Small bundle size: Optimized CSS output with minimal overhead
- Hot reload: Instant updates during development
Troubleshooting
- Components not styling: Make sure to run
pnpm run build:cssafter making changes - Missing styles: Check that the DaisyUI preset is properly added to
uno.config.ts - Theme not applying: Ensure the
data-themeattribute is set on the HTML element
Resources
Contributing
To add new DaisyUI components or examples:
- Add the component to
client/src/components/daisy_example.rs - Update the menu structure if needed
- Rebuild the CSS with
pnpm run build:css - Test the component in the
/daisyuiroute