mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(editor): keep color picker controls in view (#5228)
The editor color picker uses a shorter color field and a tighter control row. Numeric inputs use the UI text size, recent colors wrap with consistent spacing, and the action buttons stay visible when the popup has to scroll.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { expect, test } from "./fixtures";
|
||||
|
||||
test("the editor color picker fits recent colors and keeps its actions visible", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 980, height: 720 });
|
||||
await page.evaluate(async () => {
|
||||
const recent = Array.from({ length: 20 }, (_, i) => `#${((i + 1) * 314241).toString(16).padStart(6, "0")}ff`);
|
||||
localStorage.setItem("openidea.colorPicker.recent.v1", JSON.stringify(recent));
|
||||
const contributions = "/src/workbench/contributions.ts";
|
||||
const { editorService } = await import(/* @vite-ignore */ contributions);
|
||||
await editorService().openFile("/dev/acme-api/theme.css");
|
||||
});
|
||||
const editor = page.locator(".cm-editor").first();
|
||||
const contents = editor.locator(".cm-content");
|
||||
await contents.click();
|
||||
await page.keyboard.press("Meta+a");
|
||||
await page.keyboard.insertText(".notice { color: #5a8fbd; }");
|
||||
|
||||
const swatch = editor.locator(".cm-openidea-gutter-colors").getByTitle("#5a8fbd", { exact: true });
|
||||
const picker = page.getByRole("dialog", { name: "Color picker", exact: true });
|
||||
const palette = picker.locator(".react-colorful__saturation");
|
||||
const hex = picker.getByRole("textbox", { name: "Hexadecimal", exact: true });
|
||||
const apply = picker.getByRole("button", { name: "Apply", exact: true });
|
||||
const cancel = picker.getByRole("button", { name: "Cancel", exact: true });
|
||||
const recent = picker.getByRole("group", { name: "Recent colors", exact: true }).getByRole("button");
|
||||
await swatch.click();
|
||||
await expect(hex).toHaveValue("5A8FBDFF");
|
||||
expect((await picker.boundingBox())!.width).toBeLessThanOrEqual(308);
|
||||
await expect(palette).toHaveCSS("height", "152px");
|
||||
expect(await picker.evaluate((el) => el.scrollWidth - el.clientWidth)).toBe(0);
|
||||
await hex.fill("#ff0000");
|
||||
expect(await picker.evaluate((el) => el.scrollWidth - el.clientWidth)).toBe(0);
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(picker).toBeHidden();
|
||||
|
||||
await page.setViewportSize({ width: 280, height: 315 });
|
||||
await swatch.click();
|
||||
await expect(recent).toHaveCount(20);
|
||||
const swatchRows = await recent.evaluateAll((elements) => {
|
||||
const rows: number[] = [];
|
||||
for (const element of elements) {
|
||||
const box = element.getBoundingClientRect();
|
||||
if (!rows.includes(box.top)) rows.push(box.top);
|
||||
const previous = element.previousElementSibling?.getBoundingClientRect();
|
||||
if (previous?.top === box.top && previous.right > box.left) throw new Error("Color swatches overlap");
|
||||
}
|
||||
return rows.length;
|
||||
});
|
||||
expect(swatchRows).toBeGreaterThan(2);
|
||||
expect(await picker.evaluate((el) => el.scrollWidth - el.clientWidth)).toBe(0);
|
||||
await expect(apply).toBeInViewport({ ratio: 1 });
|
||||
await expect(cancel).toBeInViewport({ ratio: 1 });
|
||||
await hex.fill("#d27c54");
|
||||
await cancel.click();
|
||||
await expect(picker).toBeHidden();
|
||||
await expect(contents).toContainText("#5a8fbd");
|
||||
|
||||
await swatch.click();
|
||||
await hex.fill("#d27c54");
|
||||
await apply.click();
|
||||
await expect(picker).toBeHidden();
|
||||
await expect(contents).toContainText("#d27c54");
|
||||
});
|
||||
@@ -1,13 +1,12 @@
|
||||
.popup {
|
||||
width: 340px;
|
||||
width: 304px;
|
||||
max-width: calc(100vw - 12px);
|
||||
padding: 0 0 12px;
|
||||
max-height: calc(100vh - 12px);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.opaque .control:global(.react-colorful) {
|
||||
grid-template-rows: minmax(0, 1fr) 54px;
|
||||
grid-template-rows: var(--saturation-height) 48px;
|
||||
}
|
||||
|
||||
.opaque .control :global(.react-colorful__hue) {
|
||||
@@ -23,25 +22,30 @@
|
||||
}
|
||||
|
||||
.control:global(.react-colorful) {
|
||||
--saturation-height: clamp(104px, 36vh, 152px);
|
||||
|
||||
display: grid;
|
||||
grid-template-columns: 104px minmax(0, 1fr);
|
||||
grid-template-rows: minmax(0, 1fr) 27px 27px;
|
||||
grid-template-columns: 88px minmax(0, 1fr);
|
||||
grid-template-rows: var(--saturation-height) 24px 24px;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 262px;
|
||||
height: auto;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.control :global(.react-colorful__saturation) {
|
||||
grid-column: 1 / -1;
|
||||
grid-row: 1;
|
||||
align-self: stretch;
|
||||
overflow: hidden;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.control :global(.react-colorful__hue),
|
||||
.control :global(.react-colorful__alpha) {
|
||||
grid-column: 2;
|
||||
height: 14px;
|
||||
margin: 6px 14px 7px 2px;
|
||||
height: 12px;
|
||||
margin-inline-end: var(--space-3);
|
||||
border-radius: var(--radius-small);
|
||||
}
|
||||
|
||||
@@ -53,6 +57,12 @@
|
||||
grid-row: 3;
|
||||
}
|
||||
|
||||
.control :global(.react-colorful__hue-pointer),
|
||||
.control :global(.react-colorful__alpha-pointer) {
|
||||
width: var(--h-control-small);
|
||||
height: var(--h-control-small);
|
||||
}
|
||||
|
||||
.sampleRow {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
@@ -60,14 +70,14 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
width: 104px;
|
||||
height: 54px;
|
||||
padding: 0 10px;
|
||||
width: 88px;
|
||||
height: 48px;
|
||||
padding-inline: var(--space-2);
|
||||
}
|
||||
|
||||
.preview {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: 1px solid var(--border-strong);
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
@@ -84,8 +94,8 @@
|
||||
.fields {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(78px, 1.65fr);
|
||||
gap: 7px;
|
||||
padding: 0 12px;
|
||||
gap: var(--space-1);
|
||||
padding-inline: var(--space-3);
|
||||
}
|
||||
|
||||
.field {
|
||||
@@ -101,13 +111,14 @@
|
||||
.field input {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
height: 28px;
|
||||
height: var(--h-control);
|
||||
border: 1px solid var(--border-input, var(--border));
|
||||
border-radius: var(--radius-small);
|
||||
padding: 0 3px;
|
||||
background: var(--bg-input);
|
||||
color: var(--fg-strong);
|
||||
font: inherit;
|
||||
font-family: inherit;
|
||||
font-size: var(--fs-ui);
|
||||
font-variant-numeric: tabular-nums;
|
||||
text-align: center;
|
||||
outline: none;
|
||||
@@ -122,24 +133,29 @@
|
||||
}
|
||||
|
||||
.actions {
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: var(--space-2);
|
||||
padding: var(--space-3) var(--space-3) 0;
|
||||
padding: var(--space-2) var(--space-3) var(--space-3);
|
||||
background: var(--bg-popup);
|
||||
}
|
||||
|
||||
.recent {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(10, minmax(0, 1fr));
|
||||
gap: var(--space-2) 5px;
|
||||
margin: 12px 12px 0;
|
||||
padding-top: 10px;
|
||||
grid-template-columns: repeat(auto-fill, minmax(24px, 1fr));
|
||||
justify-items: center;
|
||||
gap: var(--space-1);
|
||||
margin: var(--space-2) var(--space-3) 0;
|
||||
padding-top: var(--space-2);
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.recentColor {
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: 1px solid var(--border-strong);
|
||||
border-radius: var(--radius-small);
|
||||
padding: 0;
|
||||
|
||||
Reference in New Issue
Block a user