stylingSlice
and integrates seamlessly with Tailwind CSS. This guide covers how to customize the appearance of Cedar components and ensure proper Tailwind configuration.
Tailwind CSS Setup
Cedar-OS components use Tailwind CSS for styling. To ensure all Cedar styles work correctly, you need to configure Tailwind to scan Cedar’s component files.Tailwind 4.0+ Configuration
If you’re using Tailwind CSS 4.0 or later, add the following@source
directive to your main CSS file:
Tailwind 3.x Configuration
For Tailwind CSS 3.x, add Cedar’s paths to yourtailwind.config.js
:
Using the Styling Slice
Cedar-OS includes astylingSlice
that manages global styling configuration for all Cedar components. This allows you to customize colors, dark mode, and other visual properties across your entire application.
Accessing Styling State
Styling Configuration
The styling slice provides the following configuration options:Setting Custom Colors
You can update the color scheme programmatically:Component-Level Styling
Using Styled Components
Cedar components automatically respond to the global styling configuration. For example, the chat components will use your configured colors:CSS Variables
Cedar-OS components use CSS variables that integrate with Tailwind’s design system. These variables are automatically updated when you change the styling configuration:Utility Functions
Cedar-OS provides several utility functions for working with colors:Color Manipulation
Class Name Utilities
Cedar uses thecn
utility (similar to clsx
) for combining class names:
Dark Mode Support
Cedar-OS components automatically support dark mode through Tailwind’s dark mode classes. When you toggle dark mode usingtoggleDarkMode()
, all Cedar components will update their appearance.
Implementing Dark Mode Toggle
Best Practices
- Configure Tailwind First: Always ensure your Tailwind configuration includes Cedar’s component paths before using Cedar components.
-
Set Colors Early: Configure your color scheme early in your app’s lifecycle, preferably in your root component:
- Consistent Theme: Use the styling slice to maintain consistent theming across all Cedar components rather than overriding styles individually.
- Responsive Dark Mode: Always test your color choices in both light and dark modes to ensure good contrast and readability.
Troubleshooting
Styles Not Applying
If Cedar component styles aren’t working:- Check Tailwind Config: Ensure Cedar paths are included in your Tailwind configuration
- Clear Cache: Try clearing your build cache and rebuilding
- Check CSS Import: Make sure you’re importing your global CSS file that includes Tailwind directives
- Verify Installation: Ensure both
cedar-os
and components are properly installed
Dark Mode Issues
If dark mode isn’t working:- Check HTML Class: Ensure the
dark
class is being applied to your<html>
element - Tailwind Dark Mode: Verify your Tailwind config uses
class
strategy for dark mode:
Next Steps
- Explore component customization for more advanced styling options
- Learn about custom message rendering to style chat messages
- Check out the Cedar Playground to see styling in action