π File detail
components/design-system/color.ts
π§© .tsπ 31 linesπΎ 853 bytesπ text
β Back to All Filesπ― Use case
This file lives under βcomponents/β, which covers shared React UI pieces. On the API surface it exposes color β mainly functions, hooks, or classes. It composes internal code from ink and utils (relative imports).
Generated from folder role, exports, dependency roots, and inline comments β not hand-reviewed for every path.
π§ Inline summary
import { type ColorType, colorize } from '../../ink/colorize.js' import type { Color } from '../../ink/styles.js' import { getTheme, type Theme, type ThemeName } from '../../utils/theme.js' /**
π€ Exports (heuristic)
color
π₯οΈ Source preview
import { type ColorType, colorize } from '../../ink/colorize.js'
import type { Color } from '../../ink/styles.js'
import { getTheme, type Theme, type ThemeName } from '../../utils/theme.js'
/**
* Curried theme-aware color function. Resolves theme keys to raw color
* values before delegating to the ink renderer's colorize.
*/
export function color(
c: keyof Theme | Color | undefined,
theme: ThemeName,
type: ColorType = 'foreground',
): (text: string) => string {
return text => {
if (!c) {
return text
}
// Raw color values bypass theme lookup
if (
c.startsWith('rgb(') ||
c.startsWith('#') ||
c.startsWith('ansi256(') ||
c.startsWith('ansi:')
) {
return colorize(text, c, type)
}
// Theme key lookup
return colorize(text, getTheme(theme)[c as keyof Theme], type)
}
}