Skip to content

Export theme colors in JavaScript/JSON consumable format #86

Description

@coderabbitai

Context

In escrow-v2#130, we're migrating to Tailwind CSS and ui-components-library v3. As part of this migration, we need to access theme colors programmatically in JavaScript to dynamically style timeline components.

Current Approach

We're currently using getComputedStyle(document.documentElement).getPropertyValue() to read CSS custom properties at runtime:

function getThemeColor(variant: Variant): string {
  return getComputedStyle(document.documentElement).getPropertyValue(variantToCssVar[variant]).trim();
}

Problem

While this approach works and keeps the colors in sync with CSS, it has performance implications:

  • DOM queries are required every time a color is needed
  • Slight delay when switching themes due to these queries
  • Not optimal for components that need frequent color access

Proposed Solution

Export theme colors from ui-components-library in a JavaScript/JSON consumable format (e.g., as a JavaScript object or JSON file) alongside the CSS variables. This would allow consuming applications to:

  • Access colors directly without DOM queries
  • Improve performance when theme colors are needed in JavaScript logic
  • Maintain type safety with TypeScript definitions

Example Usage

import { lightTheme, darkTheme } from '@kleros/ui-components-library/theme';

const color = isLightTheme ? lightTheme.primaryBlue : darkTheme.primaryBlue;

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions