import type { Meta, StoryObj } from "@storybook/react"; /** * Color Utilities * * Semantic color utility classes for quick styling. All utilities reference * semantic tokens from the 3-tier color system, ensuring WCAG AA compliance * and consistent theming across the application. * * ## Three Utility Categories * * 1. **Text Colors** - `.text-*` classes for typography * 2. **Background Colors** - `.bg-*` classes for surfaces * 3. **Border Colors** - `.border-*` classes (requires border-width and border-style) * * ## Token Architecture * * All utilities reference **semantic tokens** (Tier 2), not primitive colors: * ``` * Primitives (Tier 1) → Semantic (Tier 2) → Utilities * --color-blue-600 → --color-primary → .text-primary * ``` * * This ensures: * - Easy theming via token overrides * - Consistent color usage across components * - WCAG AA accessibility compliance (4.5:1 text, 3:1 UI) */ const meta = { title: "FP.React Components/Utilities/Colors", tags: ["autodocs"], parameters: { docs: { description: { component: "Semantic color utility classes for rapid development. All utilities maintain WCAG AA contrast ratios and reference the centralized token system.", }, }, }, } satisfies Meta; export default meta; type Story = StoryObj; /** * Text Color Utilities * * Use `.text-*` classes to apply semantic text colors. All colors meet * WCAG AA contrast requirements (4.5:1 minimum) when used on appropriate backgrounds. */ export const TextColors: Story = { render: () => (

Brand Colors

.text-primary - Primary brand color for emphasis

.text-secondary - Secondary text for less emphasis

State Colors

.text-success - Success messages and positive feedback

.text-error - Error messages and validation failures

.text-warning - Warning messages and cautionary information

.text-info - Informational messages

Text Hierarchy

.text-muted - Muted text for de-emphasized content

.text-disabled - Disabled state text

.text-inverse - Inverse text (white) for dark backgrounds

), }; /** * Background Color Utilities * * Use `.bg-*` classes to apply semantic background colors. Combines with * text utilities for accessible color combinations. */ export const BackgroundColors: Story = { render: () => (

Brand Backgrounds

.bg-primary - Primary brand background
.bg-primary-light - Light primary background
.bg-secondary - Secondary background

State Backgrounds

.bg-success - Success background for positive feedback
.bg-error - Error background for validation failures
.bg-warning - Warning background for caution
.bg-info - Info background for informational content

Surface Backgrounds

.bg-surface - Primary surface background (usually white)
.bg-surface-secondary - Secondary surface background
.bg-transparent - Transparent background
), }; /** * Border Color Utilities * * Use `.border-*` classes to apply semantic border colors. You must also * set `border-width` and `border-style` for borders to be visible. * * Example: `className="border-primary" style={{ border: "2px solid" }}` */ export const BorderColors: Story = { render: () => (

Brand Borders

.border-primary - Primary brand border
.border-secondary - Secondary border

State Borders

.border-success - Success border for valid states
.border-error - Error border for invalid states
.border-warning - Warning border for caution
.border-info - Info border for informational content

UI Borders

.border-default - Default UI border
.border-subtle - Subtle border for less emphasis
.border-transparent - Transparent border
), }; /** * Combined Utilities * * Demonstrates combining text, background, and border utilities for * common design patterns. All combinations maintain WCAG AA contrast ratios. */ export const CombinedUtilities: Story = { render: () => (

Alert-style Messages

Success! Your changes have been saved successfully.
Error: Please correct the validation errors below.
Warning: This action cannot be undone.
Info: You have 3 unread notifications.

Card-style Containers

Primary Heading

This card uses semantic utilities for consistent styling.

Highlighted Card

Combines light background with primary border for emphasis.

), }; /** * Theming Example * * Demonstrates how utilities adapt when semantic tokens are overridden. * This example uses inline CSS variables to simulate theme customization. */ export const ThemingExample: Story = { render: () => (

Default Theme

Primary text uses default blue from token system

Primary background uses default blue

Custom Theme (Purple)

Primary text now uses purple via token override

Primary background now uses purple
Light background adapts to purple theme

Custom Theme (Red)

Primary text now uses red via token override

Primary background now uses red
Light background adapts to red theme

💡 Theming Tip: Override semantic tokens ( --color-primary, --color-success, etc.) to theme your entire application. All utilities automatically adapt!

), }; /** * Usage Guidelines * * Best practices for using color utilities in your application. */ export const UsageGuidelines: Story = { render: () => (

Best Practices

✅ Do

❌ Don't

Code Examples

HTML:

          {`
Success! Your changes have been saved.
Get Started `}

Theming (CSS):

          {`:root {
  /* Override semantic tokens for custom branding */
  --color-primary: #7c3aed;        /* Purple instead of blue */
  --color-primary-light: #ede9fe;  /* Light purple */
  --color-success: #059669;        /* Teal instead of green */
}

/* All .text-primary, .bg-primary utilities now use purple! */`}
        

Accessibility

All color utilities meet WCAG AA standards when used appropriately:

Always test color combinations with tools like the{" "} WebAIM Contrast Checker {" "} or browser DevTools.

), };