Skip to content

Commit aeaa8ed

Browse files
authored
Display transparent color values as transparent (#450)
1 parent f610e2f commit aeaa8ed

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

packages/react-grab/e2e/edit-panel-color.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
BUTTON_SELECTOR,
55
EDIT_PANEL_ATTR,
66
EDIT_PROPERTY_ATTR,
7+
getActivePropertyValue,
78
clearEditStorage,
89
getActivePropertyKey,
910
getInlineStyleProperty,
@@ -34,6 +35,15 @@ test.describe("Style Panel Color Controls", () => {
3435
expect(propertyKeys).toContain("color");
3536
});
3637

38+
test("transparent color values are labeled as transparent", async ({ reactGrab }) => {
39+
const { page } = reactGrab;
40+
await openEditPanel(reactGrab, PLAIN_TEXT_SELECTOR);
41+
await setSearchInputValue(page, "background");
42+
await expect.poll(() => getActivePropertyKey(page)).toBe("background-color");
43+
44+
await expect.poll(() => getActivePropertyValue(page)).toBe("transparent");
45+
});
46+
3747
test("typing bg-[#hex] applies the background color", async ({ reactGrab }) => {
3848
await openEditPanel(reactGrab, BUTTON_SELECTOR);
3949
await setSearchInputValue(reactGrab.page, "bg-[#ff0000]");

packages/react-grab/src/components/edit-panel/color-picker.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createSignal, onCleanup, onMount, Show, type Component } from "solid-js";
22
import { IME_COMPOSING_KEY_CODE } from "../../constants.js";
3+
import { formatColorLabel } from "../../utils/format-color-label.js";
34
import { parseAnyColor } from "../../utils/parse-any-color.js";
45
import { EDIT_LABEL_CLASS } from "./constants.js";
56

@@ -19,11 +20,12 @@ interface ColorPickerProps {
1920
emphasized?: boolean;
2021
}
2122

22-
const HEX_CLASS = "text-[12px] leading-4 font-medium tabular-nums uppercase";
23+
const HEX_CLASS = "text-[12px] leading-4 font-medium tabular-nums";
2324

2425
export const ColorPicker: Component<ColorPickerProps> = (props) => {
2526
const [draftText, setDraftText] = createSignal<string | null>(null);
2627
const isEditing = () => draftText() !== null;
28+
const displayValue = () => formatColorLabel(props.value);
2729
let nativePickerRef: HTMLInputElement | undefined;
2830

2931
// isMounted gates the native picker's `onInput` against firing
@@ -97,14 +99,15 @@ export const ColorPicker: Component<ColorPickerProps> = (props) => {
9799
fallback={
98100
<span
99101
class={`${HEX_CLASS} text-[var(--rg-text-primary)] cursor-text`}
102+
data-react-grab-value={displayValue()}
100103
onPointerDown={(event) => event.stopPropagation()}
101104
onClick={(event) => {
102105
event.preventDefault();
103106
event.stopPropagation();
104-
setDraftText(props.value.replace(/^#/, "").toUpperCase());
107+
setDraftText(displayValue());
105108
}}
106109
>
107-
{props.value.toUpperCase()}
110+
{displayValue()}
108111
</span>
109112
}
110113
>

packages/react-grab/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export const TEXTAREA_MAX_HEIGHT_PX = 95;
192192
export const EDIT_PROPERTY_LIST_MAX_HEIGHT_PX = 280;
193193
export const EDIT_PROPERTY_MAX_COUNT = 40;
194194
export const EDIT_TRANSPARENT_COLOR_HEX = "#00000000";
195+
export const EDIT_TRANSPARENT_COLOR_LABEL = "transparent";
195196
export const EDIT_ROOT_FONT_SIZE_PX = 16;
196197
export const EDIT_PANEL_MIN_WIDTH_PX = 200;
197198
export const EDIT_PANEL_MAX_WIDTH_PX = 320;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { EDIT_TRANSPARENT_COLOR_HEX, EDIT_TRANSPARENT_COLOR_LABEL } from "../constants.js";
2+
3+
export const formatColorLabel = (colorValue: string): string =>
4+
colorValue.toLowerCase() === EDIT_TRANSPARENT_COLOR_HEX
5+
? EDIT_TRANSPARENT_COLOR_LABEL
6+
: colorValue.toUpperCase();

0 commit comments

Comments
 (0)