A fork of react-colorful enhanced with built-in color contrast detection to ensure accessibility compliance according to WCAG guidelines.
Color accessibility is crucial for creating inclusive web applications. The Contrast Color Picker extends the popular react-colorful library by adding color contrast detection functionality. This ensures that selected color combinations meet the WCAG guidelines for color contrast. Specifically, we follow a minimum contrast ratio of 4.5:1 to ensure compliance with WCAG AA level standards, enhancing the readability and usability of your applications.
- Multiple Color Formats: Supports Hex, RGB, RGBA, HSL, HSLA, HSV, HSVA, and their string equivalents.
- Built-in Contrast Analysis: Automatically calculates the contrast ratio between foreground and background colors to determine compliance with WCAG guidelines.
- Easy Integration: Simple API to integrate color pickers into your React applications with minimal setup.
- Customizable: Pass in background colors and handle color changes seamlessly.
npm install @test-party/contrast-color-pickeryarn add @test-party/contrast-color-pickerNote: Ensure that you have the necessary peer dependencies installed (
reactandreact-dom).
To utilize the Contrast Color Picker in your React application, follow the example below. This demonstrates how to integrate various color picker components with contrast analysis.
import { useState } from 'react';
import { HexColorPicker } from '@test-party/contrast-color-picker';
function App() {
const [hexForegroundColor, setHexForegroundColor] = useState("#000000");
const [hexBackgroundColor, setHexBackgroundColor] = useState("#ffffff");
return (
<div>
<h1>Testing @test-party/contrast-color-picker</h1>
<h2>Hex</h2>
<HexColorPicker
color={hexForegroundColor}
onChange={setHexForegroundColor}
backgroundColor={hexBackgroundColor}
/>
</div>
);
}
export default App;The Contrast Color Picker offers a variety of components tailored to different color formats. Each component requires the following props:
color: The current color value.onChange: Function to handle color changes.backgroundColor: The background color against which contrast is calculated.
- HexColorPicker
- HexAlphaColorPicker
- RgbColorPicker
- RgbaColorPicker
- HslColorPicker
- HslaColorPicker
- HsvColorPicker
- HsvaColorPicker
- RgbStringColorPicker
- RgbaStringColorPicker
- HslStringColorPicker
- HslaStringColorPicker
- HsvStringColorPicker
- HsvaStringColorPicker
Each color picker component accepts the following props:
color(string|object): The current color value. The type depends on the color format (e.g., hex string, RGB object).onChange(function): Callback function that receives the updated color value.backgroundColor(string|object): The background color used for contrast analysis.
<HexColorPicker
color="#ff0000"
onChange={(newColor) => setColor(newColor)}
backgroundColor="#ffffff"
/>Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature/YourFeature. - Make your changes and commit them:
git commit -m 'Add some feature'. - Push to the branch:
git push origin feature/YourFeature. - Open a pull request.
Please ensure your code follows the existing style and passes all tests.
This project is licensed under the MIT License.
To get started with the Contrast Color Picker, follow the installation instructions above and integrate the desired color picker components into your React application as demonstrated in the usage example.
For more detailed information, refer to the React Colorful documentation, as this package builds upon its foundation with added accessibility features.
If you encounter any issues or have questions, feel free to open an issue in the repository or reach out to the maintainer.