A lightweight, framework-agnostic color picker library built with TypeScript. Supports HSL, RGB, and CMYK color spaces with automatic CSS injection and 20+ CSS property targeting.
npm install @brightdotdev/color-pickerCheck out the live demo to see all features in action:
Live Demo Page
- π― Multiple Color Spaces : HSL, RGB, and CMYK support with real-time conversion
- β‘ Automatic Styling: No CSS imports needed - styles inject automatically
- π§ Framework Agnostic: Works with React, Vue, Angular, or vanilla JavaScript
- π¨ 20+ CSS Properties: Target text, backgrounds, borders, shadows, SVG, and more
- ποΈ Eye Dropper Tool: Pick colors from anywhere on your screen
- π Copy to Clipboard: One-click copy color values in multiple formats
- π― Live Preview: Real-time updates on target elements
- π Color Space Switching: Seamless conversion between color spaces
- π¦ Zero Dependencies: Lightweight and tree-shakable
npm install @brightdotdev/color-pickerimport { COLORPICKERCLASS } from '@brightdotdev/color-picker';
const container = document.getElementById('color-picker-container');
const targetElement = document.getElementById('my-element');
const picker = new COLORPICKERCLASS({
colorPickerContainer: container,
colorPickerProps: {
targetElementProps: {
targetElement: targetElement,
targetStylePorperty: 'background' // or any CSS color property
}
}
});
// Set initial color
picker.setExternalColor({ r: 255, g: 0, b: 0 });Your color picker can target these CSS properties:
color- Text colorbackground- Background shorthandbackground-color- Explicit background color
border-color- All bordersborder-top-color- Top border onlyborder-right-color- Right border onlyborder-bottom-color- Bottom border onlyborder-left-color- Left border onlyoutline-color- Focus outline color
caret-color- Input cursor coloraccent-color- Checkbox/radio/slider colortext-decoration-color- Underline/strikethrough color
fill- SVG shape fill colorstroke- SVG outline/stroke color
box-shadow- Element shadowstext-shadow- Text shadows
selection-bg- Text selection backgroundselection-text- Text selection text colorscrollbar-color- Scrollbar styling
import { COLORPICKERCLASS } from '@brightdotdev/color-picker';
const picker = new COLORPICKERCLASS({
colorPickerContainer: document.getElementById('picker-container'),
colorPickerProps: {
targetElementProps: {
targetElement: document.getElementById('target-element'),
targetStylePorperty: 'border-color'
}
}
});
// Set initial color
picker.setExternalColor({ h: 240, s: 100, l: 50 });
// Cleanup when done
picker.dispose();import { HslObject, RgbObject, CmykObject } from '@brightdotdev/color-picker';
// HSL Picker
const hslPicker = new HslObject({
colorPickerContainer: container,
targetElementProps: {
targetElement: targetElement,
targetStylePorperty: 'color'
}
});
// Get current color
const currentColor = hslPicker.getCurrentColor();
// Cleanup
hslPicker.destroyPicker();import React, { useRef, useEffect } from 'react';
import { COLORPICKERCLASS } from '@brightdotdev/color-picker';
function ColorPicker() {
const containerRef = useRef();
useEffect(() => {
const picker = new COLORPICKERCLASS({
colorPickerContainer: containerRef.current,
colorPickerProps: {
targetElementProps: {
targetElement: document.getElementById('preview'),
targetStylePorperty: 'background'
}
}
});
return () => picker.dispose();
}, []);
return <div ref={containerRef} />;
}interface RGB { r: number; g: number; b: number; } // 0-255
interface HSL { h: number; s: number; l: number; } // 0-360, 0-100, 0-100
interface CMYK { c: number; m: number; y: number; k: number; } // 0-100
type AnyColor = RGB | HSL | CMYK;setExternalColor(color: AnyColor)- Set color programmaticallygetCurrentColor()- Get current color valuesdispose()/destroyPicker()- Cleanup methods
- Chrome 60+
- Firefox 55+
- Safari 12+
- Edge 79+
Note: EyeDropper API requires Chrome 95+ or Edge 95+
This is a 100% open source project and we actively encourage community participation! Here's how you can help:
Found an issue? Please let us know!
- π Create a GitHub Issue
- π Include browser version and reproduction steps
- πΈ Screenshots are always helpful!
Have an idea to make this better?
- π¬ Start a Discussion
- π― Explain your use case
- π€ Alternative solutions you've considered
Want to contribute code? Fantastic!
- π΄ Fork the repository
- πΏ Create a feature branch (
git checkout -b feature/your-feuture) - πΎ Commit your changes (
git commit -m 'Add amazing feature') - π€ Push to the branch (
git push origin feature/your-feuture) - π Open a Pull Request
New to open source? Look for issues tagged good-first-issue to get started!
Help us test across different:
- π Browsers (Chrome, Firefox, Safari, Edge)
- π± Devices (Desktop, Tablet, Mobile)
- β‘ Frameworks (React, Vue, Angular, Vanilla JS)
Found a typo? Need better examples? Documentation contributions are especially welcome!
We follow a friendly, inclusive, and welcoming environment. Please:
- β Be respectful and constructive
- β Follow the code style and conventions
- β Add tests for new functionality
- β Update documentation when changing features
- π¬ GitHub Discussions - For ideas and questions
- π GitHub Issues - For bugs and problems
- π§ Email: [[email protected]] - For private discussions
MIT License - see LICENSE file for details. This means you can use, modify, and distribute this software freely!
β Love this project?
- Give it a star on GitHub β
- Share it with your developer friends π
- Consider contributing π€
π¦ npm Package: @brightdotdev/color-picker
π Live Demo: Check out the demo to see all features in action!
This project is maintained with by Brightdotdev | Bright (for now)