aidenybai / aidenybai/react-grab

feat: dark mode / color scheme support in Theme config

未关闭
#256 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
7.6k
派生
340
平均合并
5 小时 12 分钟
30 天内合并 PR
6

描述

## 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.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。