Skip to content

Commit efc8bb7

Browse files
committed
Fix hsl color preview and improved color-picker UI for connect playground (#5193)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the color selection functionality in the `ColorInput` component by integrating a new `Popover` UI from `@radix-ui/react-popover` and a color picker from `react-pick-color`. It also updates the dependencies in `package.json`. ### Detailed summary - Removed the `ColorInput.module.css` file. - Added `@radix-ui/react-popover` and `react-pick-color` to `package.json`. - Updated `ColorInput` component to use `Popover` for color selection. - Integrated `ColorPicker` within the `PopoverContent`. - Refactored `onChange` handling in `ColorInput`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 74d113c commit efc8bb7

File tree

6 files changed

+132
-77
lines changed

6 files changed

+132
-77
lines changed

apps/playground-web/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@radix-ui/react-dialog": "1.1.2",
1919
"@radix-ui/react-dropdown-menu": "^2.1.2",
2020
"@radix-ui/react-label": "^2.1.0",
21+
"@radix-ui/react-popover": "^1.1.2",
2122
"@radix-ui/react-radio-group": "^1.2.1",
2223
"@radix-ui/react-scroll-area": "^1.2.0",
2324
"@radix-ui/react-select": "^2.1.2",
@@ -35,6 +36,7 @@
3536
"prettier": "^3.3.2",
3637
"react": "18.3.1",
3738
"react-dom": "18.3.1",
39+
"react-pick-color": "^2.0.0",
3840
"server-only": "^0.0.1",
3941
"shiki": "1.22.0",
4042
"tailwind-merge": "^2.5.4",

apps/playground-web/src/app/connect/sign-in/components/ColorFormGroup.tsx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,29 @@ export function ColorFormGroup(props: {
6969
className="flex cursor-pointer items-center gap-3 rounded-lg p-2 transition-colors hover:bg-secondary"
7070
key={color.colorId}
7171
>
72-
<div className="rounded-full border">
73-
<ColorInput
74-
className="size-10"
75-
value={themeObj.colors[color.colorId]}
76-
onChange={(value) => {
77-
setConnectOptions((v) => {
78-
const overridesKey =
79-
v.theme.type === "dark"
80-
? "darkColorOverrides"
81-
: "lightColorOverrides";
72+
<ColorInput
73+
className="size-10"
74+
value={themeObj.colors[color.colorId]}
75+
onChange={(value) => {
76+
setConnectOptions((v) => {
77+
const overridesKey =
78+
v.theme.type === "dark"
79+
? "darkColorOverrides"
80+
: "lightColorOverrides";
8281

83-
return {
84-
...v,
85-
theme: {
86-
...v.theme,
87-
[overridesKey]: {
88-
...v.theme[overridesKey],
89-
[color.colorId]: value,
90-
},
82+
return {
83+
...v,
84+
theme: {
85+
...v.theme,
86+
[overridesKey]: {
87+
...v.theme[overridesKey],
88+
[color.colorId]: value,
9189
},
92-
};
93-
});
94-
}}
95-
/>
96-
</div>
90+
},
91+
};
92+
});
93+
}}
94+
/>
9795
<div>
9896
<div>{color.label}</div>
9997
<div className="ml-auto font-mono text-muted-foreground text-xs">

apps/playground-web/src/app/connect/sign-in/components/ColorInput/ColorInput.module.css

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,56 @@
1+
import {
2+
Popover,
3+
PopoverContent,
4+
PopoverTrigger,
5+
} from "@/components/ui/popover";
6+
import ColorPicker from "react-pick-color";
17
import { useDebouncedCallback } from "use-debounce";
28
import { cn } from "../../../../../lib/utils";
3-
import styles from "./ColorInput.module.css";
49

510
export function ColorInput(props: {
611
value: string;
712
onChange: (value: string) => void;
813
onClick?: () => void;
914
className?: string;
1015
}) {
11-
const debouncedOnChange = useDebouncedCallback((value) => {
16+
const debouncedOnChange = useDebouncedCallback((value: string) => {
1217
props.onChange(value);
1318
}, 100);
1419

1520
return (
16-
<input
17-
onChange={(e) => {
18-
debouncedOnChange(e.target.value);
19-
}}
20-
type="color"
21-
className={cn(styles.ColorInput, props.className)}
22-
value={props.value}
23-
/>
21+
<Popover>
22+
<PopoverTrigger>
23+
<div
24+
className={cn(
25+
"size-10 rounded-full border transition-colors duration-100",
26+
props.className,
27+
)}
28+
style={{
29+
background: props.value,
30+
}}
31+
/>
32+
</PopoverTrigger>
33+
<PopoverContent className="w-auto border-none p-0">
34+
<ColorPicker
35+
color={props.value}
36+
hideAlpha
37+
onChange={({ hsl }) =>
38+
debouncedOnChange(
39+
`hsl(${Math.round(hsl.h)}, ${Math.round(hsl.s * 100)}%, ${Math.round(hsl.l * 100)}%)`,
40+
)
41+
}
42+
theme={{
43+
background: "hsl(var(--background))",
44+
borderColor: "hsl(var(--border))",
45+
borderRadius: "var(--radius)",
46+
boxShadow: "var(--shadow)",
47+
inputBackground: "hsl(var(--input))",
48+
color: "hsl(var(--foreground))",
49+
width: "300px",
50+
}}
51+
className="p-2"
52+
/>
53+
</PopoverContent>
54+
</Popover>
2455
);
2556
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use client";
2+
3+
import * as PopoverPrimitive from "@radix-ui/react-popover";
4+
import * as React from "react";
5+
6+
import { cn } from "@/lib/utils";
7+
8+
const Popover = PopoverPrimitive.Root;
9+
10+
const PopoverTrigger = PopoverPrimitive.Trigger;
11+
12+
const PopoverContent = React.forwardRef<
13+
React.ElementRef<typeof PopoverPrimitive.Content>,
14+
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
15+
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
16+
<PopoverPrimitive.Portal>
17+
<PopoverPrimitive.Content
18+
ref={ref}
19+
align={align}
20+
sideOffset={sideOffset}
21+
className={cn(
22+
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",
23+
className,
24+
)}
25+
{...props}
26+
/>
27+
</PopoverPrimitive.Portal>
28+
));
29+
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
30+
31+
export { Popover, PopoverTrigger, PopoverContent };

pnpm-lock.yaml

Lines changed: 37 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)