1- import { useRef , useState , type KeyboardEvent , type PointerEvent } from "react" ;
1+ import { useId , useRef , useState , type KeyboardEvent , type PointerEvent } from "react" ;
22
33import type { HsvColor } from "../../lib/color" ;
44import { cn } from "../../lib/utils" ;
@@ -60,7 +60,9 @@ export function ColorSaturationValuePlane({
6060 onChange,
6161 onInteractionEnd,
6262 className,
63- } : ColorControlProps < HsvColor > ) {
63+ variant = "inset" ,
64+ } : ColorControlProps < HsvColor > & { variant ?: "inset" | "edge" } ) {
65+ const instructionsId = useId ( ) ;
6466 const { handlers, thumbTransition } = useColorDrag ( ( event ) => {
6567 const bounds = event . currentTarget . getBoundingClientRect ( ) ;
6668 if ( ! bounds . width || ! bounds . height ) return ;
@@ -86,24 +88,28 @@ export function ColorSaturationValuePlane({
8688 return (
8789 < div
8890 aria-label = { label }
91+ aria-describedby = { instructionsId }
8992 aria-valuemin = { 0 }
9093 aria-valuemax = { 100 }
9194 aria-valuenow = { Math . round ( value . s * 100 ) }
9295 aria-valuetext = { `saturation ${ Math . round ( value . s * 100 ) } %, brightness ${ Math . round ( value . v * 100 ) } %` }
9396 className = { cn (
94- "relative h-32 cursor-crosshair touch-none overflow-hidden rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-popover" ,
97+ "relative cursor-crosshair touch-none overflow-hidden bg-[linear-gradient(to_top,#000,transparent),linear-gradient(to_right,#fff,transparent)] outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-popover" ,
98+ variant === "edge" ? "h-36 rounded-none" : "h-32 rounded-lg" ,
9599 className ,
96100 ) }
97101 role = "slider"
98102 style = { {
99103 backgroundColor : `hsl(${ value . h } 100% 50%)` ,
100- backgroundImage :
101- "linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent)" ,
102104 } }
103105 tabIndex = { 0 }
104106 onKeyDown = { handleKeyDown }
105107 { ...handlers }
106108 >
109+ < span id = { instructionsId } className = "sr-only" >
110+ Use Left and Right arrows to adjust saturation, and Up and Down arrows to adjust brightness.
111+ Hold Shift for larger steps.
112+ </ span >
107113 < span
108114 className = "pointer-events-none absolute size-3 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0_0_0_1px_rgb(0_0_0/0.4)]"
109115 style = { {
@@ -154,10 +160,7 @@ export function ColorHueSlider({
154160 >
155161 < span
156162 aria-hidden
157- className = "h-2.5 w-full rounded-full shadow-[inset_0_0_0_1px_rgb(0_0_0_/_12%)]"
158- style = { {
159- background : "linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00)" ,
160- } }
163+ className = "h-2.5 w-full rounded-full bg-[linear-gradient(to_right,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00)] shadow-[inset_0_0_0_1px_rgb(0_0_0_/_12%)]"
161164 />
162165 < span
163166 className = "pointer-events-none absolute top-1/2 size-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0_0_0_1px_rgb(0_0_0/0.4)]"
0 commit comments