Interactive Color Picker Component
LinkedIn often allows users to customize their profiles, company pages, or even theme settings within the platform. A robust and intuitive color picker is essential for providing a rich customization experience. This problem challenges you to build a core color picker component, focusing on interactive UI, state management, and accurate color representation.
Your task is to implement a reusable ColorPicker React component. It should allow users to select a color using a combination of a 2D saturation/value grid, a hue slider, and a hex code input field. The component should accept an initial color (hex string) and provide a callback for when the color changes.
ColorArea (Saturation & Value Picker): Create a square area where users can pick saturation (horizontal axis) and value (vertical axis). The background of this area should dynamically update its hue based on the currently selected hue from the slider.HueSlider: Create a horizontal slider to control the hue of the color. Dragging the slider's handle should update the hue and, consequently, the background of the ColorArea.#RRGGBB). The user should also be able to type a valid hex code into this input field to update the color picker's state and handles.ColorPicker component should be a controlled component, accepting a value prop (hex string) and an onChange callback that is triggered with the new hex value whenever the color changes.ColorArea, HueSlider, and Hex input field in a clear and intuitive vertical stack within a main container.ColorArea should smoothly update the selected color and the hex input.HueSlider should smoothly update the color area's background, the selected color, and the hex input.ColorArea or HueSlider should set the color to that specific point.#FF0000 or FF0000) into the input field should update the picker's handles and the displayed color. Invalid input should not break the component and ideally revert to the last valid state or be ignored until valid.ColorPicker component renders correctly with an initial hex value provided via props.ColorArea accurately updates the selected color and the hex input field.HueSlider accurately updates the selected color and the hex input field.onChange callback is reliably triggered with the new hex value whenever the color is changed through any interaction.ColorArea's background gradient correctly reflects the current hue, providing a smooth visual experience.Constraints
react-colorful). Implement the core logic yourself.MouseEvent APIs).ColorPicker component.useState, useRef, useCallback, useEffect) to manage component state, ensure synchronization, and minimize unnecessary re-renders.Loading editor...