Theme and Color System
This project centralizes Tailwind color fragments and theme tokens in a single composable to ensure consistency across the UI and to keep Tailwind JIT-friendly literal class fragments.
Key files and concepts
resources/js/composables/useColors.ts— The single source of truth for color tokens and helpers. Exposes:useColors(color)— composable returning aColorClassescomputed object with fields likeicon,button,badgeBackground,activeBackground, etc.COLOR_MAP— mapping of color names (blue,green,teal,gray, etc.) to concrete Tailwind class fragments.ENTITY_COLORS— default color for entities (items, projects, contexts, …).useThemeColors(themeToken)andTHEME_CLASS_MAP— semantic layout tokens for header, nav, and modal fragments.
Why this exists
- Tailwind’s JIT requires literal class fragments for reliable generation. Centralizing these strings avoids sprinkling
bg-blue-100and similar fragments throughout the codebase. - It enforces consistent color usage across components (icons, buttons, badges, borders).
- It makes it easy to change a project’s color palette in one place.
How to use
- Simple usage in components:
import { useColors } from "@/composables/useColors";
const colorClasses = useColors("green");
// Then in template
// <svg :class="colorClasses.icon" />
// <button :class="colorClasses.button">Save</button>
- Use entity-specific helpers:
import { useEntityColors } from "@/composables/useColors";
const projectColors = useEntityColors("projects");
- Theme tokens for layout fragments (headers, modals):
import { getThemeClass } from '@/composables/useColors'
<h2 :class="getThemeClass('modalTitle')">Title</h2>
When to add a new color
- Add a new color name in
COLOR_MAPwith the full set of Tailwind fragments. Keep fragments literal to ensure JIT picks them up. - Add any semantic theme tokens to
THEME_CLASS_MAPwhen required by layout components.
Notes for tests
- Tests should mock the
useColorscomposable when they rely on colors to avoid fragile assertions; a mock helper is available inresources/js/components/__tests__/test-utils/useColorsMock.ts.
Recommendations
- Use
useColorsfor any component-level color needs (icons, badges, buttons). - Use
getThemeClassfor layout and header tokens. - Avoid inline Tailwind color fragments outside of styles or central mapping to keep the system consistent.