# caret-color

> Sets `caret-color` for an editable field, resolving a tone at its `fg` weight.

```ts
import { caretColor } from "@sdxc/u/color";
```

Sets `caret-color` for an editable field, resolving a tone at its `fg`
weight. With no value it emits `"auto"`, deriving the caret from the
field's text color; pass a tone when that reads near-invisible on a tint.

## Quick reference

Every documented call, beside the CSS it emits.

| Call | CSS |
| --- | --- |
| `u.caretColor()` | `css({ caretColor: "auto" })` |
| `u.caretColor("brand")` | `css({ caretColor: "var(--ui-brand-fg)" })` |
| `u.caretColor("brand.emphasis")` | `css({ caretColor: "var(--ui-brand-fg-emphasis)" })` |
| `u.caretColor("color.neutral.50")` | `css({ caretColor: "var(--ui-color-neutral-50)" })` |

## Examples

### Basic example

Use `caretColor` with a tone to paint the blinking text cursor of a field. Click a field to see its caret:

```tsx
<div mix={[...]}>
	<input
		type="text"
		value="Brand caret"
		mix={[caretColor("brand"), ...]}
		aria-label="Brand caret"
	/>
	<input
		type="text"
		value="Danger caret"
		mix={[caretColor("danger"), ...]}
		aria-label="Danger caret"
	/>
</div>
```

### Weights and palette shades

Name a weight, like `brand.emphasis`, or a palette shade, like `color.warning.500`, when the plain tone reads too faint:

```tsx
<div mix={[...]}>
	<input
		type="text"
		value="brand.emphasis"
		mix={[caretColor("brand.emphasis"), ...]}
		aria-label="Emphasis caret"
	/>
	<input
		type="text"
		value="color.warning.500"
		mix={[caretColor("color.warning.500"), ...]}
		aria-label="Palette caret"
	/>
</div>
```

## Applying on a state

Wrap the call in a state utility to scope it to one selector.

```ts
u.hover(u.caretColor())
```

## Responsive design

Wrap the call in a container query to scope it to one width.

```ts
u.at("md", u.caretColor())
```

## Customizing your theme

### Customizing colors

Define a palette as `--ui-color-{name}-{50..950}` and map a tone onto it with the `--ui-{tone}-*` variables, the way `theme.css` maps the built-in ones:

```css
:root {
	--ui-color-info-50: oklch(0.97 0.02 230);
	--ui-color-info-200: oklch(0.88 0.06 230);
	--ui-color-info-500: oklch(0.62 0.16 230);
	--ui-color-info-600: oklch(0.52 0.18 230);
	--ui-color-info-900: oklch(0.3 0.1 230);

	--ui-info-bg-tint: var(--ui-color-info-50);
	--ui-info-bg-solid: var(--ui-color-info-600);
	--ui-info-fg: var(--ui-color-info-600);
	--ui-info-fg-muted: var(--ui-color-info-500);
	--ui-info-fg-emphasis: var(--ui-color-info-900);
	--ui-info-fg-on-solid: white;
	--ui-info-border: var(--ui-color-info-200);
	--ui-info-border-strong: var(--ui-color-info-600);
	--ui-info-ring: var(--ui-color-info-500);
}
```

```ts
declare module "@sdxc/u" {
	interface ColorPalettes {
		info: true;
	}
	interface SemanticTones {
		info: true;
	}
}
```

The new name is then accepted wherever the scale is:

```ts
caretColor("info")
```

## Signature

```ts
u.caretColor(value?: ColorValue | (string & {}))
```
