General Styling
Learn the core concepts of the @c15t/react theming system and how it enables flexible component styling.
Understanding the Theming System
Think of our theming system as a set of style instructions that cascade through your components, similar to CSS but with more structure and type safety. Each component has specific customizable areas, called theme keys, that you can target for styling.
The theming system provides a structured way to customize the appearance of components while maintaining their functionality and accessibility. It allows you to:
- Target specific elements within a component
- Apply consistent styling across your application
- Ensure type safety and prevent styling errors
Theme Key Structure
Every theme key in our system follows a predictable pattern that makes it easy to target specific elements within a component:
- Component Name: The base name of the component (e.g.,
banner
,widget
,dialog
) - Element Path: The path to the element within the component (e.g.,
header.title
,footer.accept-button
) - State Variations: Optional state indicators (e.g.,
switch.thumb.checked
,button.hover
)
Component Hierarchies
Components are structured in a hierarchical manner, which is reflected in their theme keys:
Each level in the hierarchy can be styled independently, giving you fine-grained control over the appearance.
Visualizing the Hierarchy
Here's a simplified visualization of a typical accordion component:
Using Theme Context
For consistent styling across your application, you can use the ThemeProvider
component to apply a global theme:
Theme Inheritance
Components can still define their own themes, which will merge with and override the global theme:
Type-Safe Styling
Our theming system includes TypeScript support to help prevent errors:
Disabling Default Styles
Sometimes you might want to start from scratch. Use the noStyle
prop to remove all default styling:
Best Practices
-
Maintain Accessibility
- Ensure sufficient color contrast
- Keep interactive elements visually distinct
- Test your styles with screen readers
-
Consider Responsive Design
- Start with mobile-first styles
- Use flexible units (rem, em) over fixed pixels
- Test across different screen sizes
-
Performance
- Group related styles together
- Avoid unnecessary style overrides
- Use CSS classes over inline styles when possible
-
Maintainability
- Keep theme configurations organized
- Document custom styles
- Use consistent naming conventions