// Color picker from screen elements using EyeDropper API
const { isSupported, isOpen, color, error, open } = useEyeDropper();Perfect for design tools, color palette generators, accessibility tools, or any app requiring color selection from screen elements.
import { useEyeDropper } from '@usegrand/react-hokss';
function ColorPicker() {
const { isSupported, isOpen, color, error, open } = useEyeDropper();
const handlePickColor = async () => {
if (isSupported) {
await open();
}
};
return (
<div>
<button
onClick={handlePickColor}
disabled={!isSupported || isOpen}
>
{isOpen ? 'Picking...' : 'Pick Color'}
</button>
{!isSupported && (
<p>EyeDropper API not supported in this browser</p>
)}
{color && (
<div style={{ display: 'flex', alignItems: 'center', gap: '10px' }}>
<div
style={{
width: '50px',
height: '50px',
backgroundColor: color,
border: '1px solid #ccc'
}}
/>
<span>Selected: {color}</span>
</div>
)}
{error && <p style={{ color: 'red' }}>Error: {error}</p>}
</div>
);
}Object containing eye dropper state and control function
Boolean indicating if EyeDropper API is supported
Boolean indicating if color picker is currently open
Selected color in sRGBHex format (e.g., '#ff0000')
Error message if color selection failed
Function to open the native color picker