aidenybai / aidenybai/react-grab

feat: dark mode / color scheme support in Theme config

Aperta
#256 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
7.6k
Fork
340
Merge medio
5h 12m
PR unite (30g)
6

Descrizione

## Summary

React Grab's overlay UI (toolbar, element labels, selection box, etc.) is currently hardcoded to a light color scheme (`bg-white`, `text-black`, `border-#D9D9D9`, etc.). This makes it visually jarring when used in apps that run in dark mode.

## Proposal

Add a `colorScheme` option to the `Theme` interface that supports multiple integration strategies, similar to how libraries like Mantine, Radix, and shadcn/ui handle it:

```ts
interface Theme {
// ...existing options

/**
* Controls the color scheme of the React Grab overlay UI.
*
* - 'light' | 'dark': Force a specific scheme
* - 'auto': Follow `prefers-color-scheme` media query
* - 'class': Read from a `.dark` class on or (Tailwind convention)
* - 'attribute': Read from `data-theme` or `data-color-scheme` attribute on
* - (element: HTMLElement) => 'light' | 'dark': Custom resolver for any other setup
*
* @default 'auto'
*/
colorScheme?:
| 'light'
| 'dark'
| 'auto'
| 'class'
| 'attribute'
| ((root: HTMLElement) => 'light' | 'dark');
}
```

### Why multiple strategies?

Different ecosystems set dark mode differently:

| Strategy | Used by |
|---|---|
| `prefers-color-scheme` media query | OS-level / browser default |
| `.dark` class on `` | Tailwind CSS, most utility-first setups |
| `data-mantine-color-scheme` attribute | Mantine |
| `data-theme` / `data-color-scheme` attribute | Radix, daisyUI, many component libraries |
| Custom JS toggle | App-specific state (React context, localStorage, etc.) |

A single `'dark'` boolean won't cover these. The function escape hatch (`(root) => 'light' | 'dark'`) ensures any setup not covered by the built-in strategies can still integrate.

### Minimal CSS impact

Since the overlay already uses Tailwind internally, adding dark variants for the existing utility classes should be straightforward. The shadow DOM host just needs to resolve which scheme is active and apply a `dark` class (or CSS custom properties) to its internal root.

## Alternatives considered

- **CSS custom properties only** — Exposing `--rg-bg`, `--rg-text`, etc. would work but puts the burden on every consumer to define a full palette. A `colorScheme` option with sensible dark defaults is more ergonomic.
- **`hue` rotation** — The existing `hue` option shifts colors but doesn't invert lightness, so it can't achieve a dark theme.

## Context

React Grab renders inside a Shadow DOM host with `all: initial`, so it can't inherit the page's dark mode styles automatically. This makes explicit color scheme support necessary rather than optional.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.