# Color Helpers

CSS color utility classes and a `getPaletteClasses` helper for DOT v1 components.

---

## File Structure

```
colorHelpers/
├── background/
│   └── backgroundColor.module.css
├── text/
│   └── textColor.module.css
├── border/
│   └── borderColor.module.css
├── constants/
│   └── index.js                  # PALETTE_CONFIG, TONE_INTENSITY
└── colorHelper.js                # getPaletteClasses (default export)
```

---

## CSS Class Patterns

All three CSS modules share the same 7 base tones: `brand`, `grey`, `blue`, `green`, `orange`, `red`, `yellow`.

Shades are numeric values defined in `TONE_INTENSITY` per tone (e.g. for `brand`: base `80`, hover `100`, light `10`, lightHover `20`, borderLight `10`).

### Background (`backgroundColor.module.css`)

| Class Pattern | Description |
|---|---|
| `bg-{tone}-{base}` | Filled background |
| `bg-{tone}-{light}` | Light background variant |
| `hover:bg-{tone}-{hover}` | Filled — hover state |
| `hover:bg-{tone}-{lightHover}` | Light — hover state |
| `focus:bg-{tone}-{...}` | Focus state (same shade logic) |
| `active:bg-{tone}-{...}` | Active state (same shade logic) |
| `selected:bg-{tone}-{...}` | Selected state (same shade logic) |

**Utility:** `bg-transparent`, `bg-white`, `bg-black` (+ `hover:`, `focus:`, `active:`, `selected:` variants)

### Text (`textColor.module.css`)

| Class Pattern | Description |
|---|---|
| `text-{tone}-{base}` | Base text color |
| `hover:text-{tone}-{textHover\|hover}` | Hover state |
| `focus:text-{tone}-{...}` | Focus state |
| `active:text-{tone}-{...}` | Active state |
| `selected:text-{tone}-{...}` | Selected state |

**Special:** `text-brand-filled` (+ state variants) — used for text on filled `brand` backgrounds.

**Utility:** `text-transparent`, `text-white`, `text-black` (+ state variants)

> Text has no `-light` shade variant. `getPaletteClasses` automatically switches to `filledTextTone` (`white`) when rendering on a filled background.

### Border (`borderColor.module.css`)

| Class Pattern | Description |
|---|---|
| `border-{tone}-{base}` | Base border |
| `border-{tone}-{borderLight}` | Light border (resting only) |
| `hover:border-{tone}-{hover}` | Hover state (always base shade) |
| `focus:border-{tone}-{...}` | Focus state |
| `active:border-{tone}-{...}` | Active state |
| `selected:border-{tone}-{...}` | Selected state |

**Utility:** `border-transparent`, `border-white`, `border-black` (+ state variants)

---

## Direct CSS Usage

Import only the modules you need and compose classes directly.

```js
import bgStyle from './background/backgroundColor.module.css';
import textStyle from './text/textColor.module.css';
import borderStyle from './border/borderColor.module.css';

// Status tag: light bg + colored text
<span className={`${bgStyle['bg-green-10']} ${textStyle['text-green-80']}`}>Success</span>

// Info card: light bg + light border
<div className={`${bgStyle['bg-blue-10']} ${borderStyle['border-blue-10']}`}>{children}</div>

// Interactive element: filled bg + white text + hover bg
<button className={`${bgStyle['bg-brand-80']} ${bgStyle['hover:bg-brand-100']} ${textStyle['text-brand-filled']}`}>
  Click
</button>
```

---

## `getPaletteClasses`

Computes all 15 CSS class keys for a palette in one call.

```js
import getPaletteClasses from './colorHelper';
```

### API

```js
getPaletteClasses({ palette, appearance, hoverAppearance, selectedAppearance })
```

| Parameter | Type | Description |
|---|---|---|
| `palette` | `string` | One of the 12 palette names (see table below) |
| `appearance` | `{ bg?, border?, text? }` | Resting state |
| `hoverAppearance` | `{ bg?, border?, text? }` | Hover / focus / active states |
| `selectedAppearance` | `{ bg?, border?, text? }` | Selected state |

Each key in an appearance object accepts:
- `true` — use the palette's own tone
- `false` / omitted — no class produced
- `'paletteName'` — use a different palette's tone (e.g. `text: 'brand'`)

### Palettes (`PALETTE_CONFIG`)

| Palette | Tone | Text tone | Filled text tone |
|---------|------|-----------|-----------------|
| `brand` | `brand` | `brand` | `brand-filled` |
| `brandLighter` | `brand` (light shades) | `brand` | `brand` |
| `info` | `blue` | `blue` | `white` |
| `infoLighter` | `blue` (light shades) | `blue` | `blue` |
| `secondary` | `grey` | `grey` | `white` |
| `secondaryLighter` | `grey` (light shades) | `grey` | `grey` |
| `danger` | `red` | `red` | `white` |
| `dangerLighter` | `red` (light shades) | `red` | `red` |
| `success` | `green` | `green` | `white` |
| `successLighter` | `green` (light shades) | `green` | `green` |
| `warning` | `orange` | `orange` | `white` |
| `warningLighter` | `orange` (light shades) | `orange` | `orange` |

`*Lighter` palettes use `light` / `borderLight` shades from `TONE_INTENSITY` instead of `base`.

### Return Value

```js
{
  bg, hoverBg, focusBg, activeBg, selectedBg,
  text, hoverText, focusText, activeText, selectedText,
  border, hoverBorder, focusBorder, activeBorder, selectedBorder
}
```

Each key is a CSS module class string, or `''` if not applicable for that appearance configuration.

> `border` always has a value — when `bg: false` and no `border` key is set, it defaults to `border-transparent`.

### Text Tone Resolution

| Background state | Text produced |
|---|---|
| Filled (`bg: true`, non-lighter palette) | `filledTextTone` (`white`) |
| Light (`bg: true`, `*Lighter` palette) | `textTone` (`brand`) |
| No background (`bg: false` or omitted) | `textTone`, or `''` if `text` not set |

### Examples

**Filled button**
```js
getPaletteClasses({
  palette: 'brand',
  appearance: { bg: true, text: true, border: true },
  hoverAppearance: { bg: true, text: true, border: true }
});
// bg → bg-brand-80 | text → text-brand-filled | border → border-brand-80
// hoverBg → hover:bg-brand-100 | hoverText → hover:text-brand-filled
```

**Ghost button (no bg, with border)**
```js
getPaletteClasses({
  palette: 'brand',
  appearance: { bg: false, border: true },
  hoverAppearance: { bg: false, border: true },
  selectedAppearance: { bg: false, border: true }
});
// bg → '' | border → border-brand-80 | hoverBorder → hover:border-brand-80
// selectedBorder → selected:border-brand-80
```

**Text-only with selected fill**
```js
getPaletteClasses({
  palette: 'brand',
  appearance: { bg: false, text: true },
  hoverAppearance: { bg: false, text: true },
  selectedAppearance: { bg: true, text: true }
});
// text → text-brand-80 | hoverText → hover:text-brand-100
// selectedBg → selected:bg-brand-80 | selectedText → selected:text-brand-filled
```

**Cross-palette override (black text, brand on hover)**
```js
getPaletteClasses({
  palette: 'brand',
  appearance: { bg: false, text: 'black' },
  hoverAppearance: { bg: false }
});
// text → text-black | hoverText → ''
```

**Tinted outline (lighter palette)**
```js
getPaletteClasses({
  palette: 'brandLighter',
  appearance: { border: true },
  hoverAppearance: { border: true }
});
// bg → '' | border → border-brand-10 (borderLight shade) | hoverBorder → hover:border-brand-100
```
