Skip to content

Commit 998a9a9

Browse files
committed
fix: fixed colors in color picker
1 parent cde2d1c commit 998a9a9

1 file changed

Lines changed: 49 additions & 49 deletions

File tree

src/ColorPicker.jsx

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { useState, useEffect, useRef, useCallback } from 'react';
22
import { Palette } from 'lucide-react';
33

4-
const ColorPicker = ({
5-
isVisible,
6-
onClose,
7-
onColorChange,
4+
const ColorPicker = ({
5+
isVisible,
6+
onClose,
7+
onColorChange,
88
currentColor = '#8B0000',
99
position = { x: 0, y: 0 },
1010
direction = 'down-left', // 'down-left' or 'down-right'
@@ -103,14 +103,14 @@ const ColorPicker = ({
103103
// Handle hex input change
104104
const handleHexInputChange = (e) => {
105105
let value = e.target.value;
106-
106+
107107
// Allow typing without # and add it automatically
108108
if (!value.startsWith('#') && value.length > 0) {
109109
value = '#' + value;
110110
}
111-
111+
112112
setHexInput(value);
113-
113+
114114
// Validate and apply color if valid
115115
if (/^#[0-9A-Fa-f]{6}$/.test(value)) {
116116
const hsv = hexToHsv(value);
@@ -126,7 +126,7 @@ const ColorPicker = ({
126126
const handleClickAway = (e) => {
127127
// Check if click is outside the color picker
128128
const isOutsidePicker = pickerRef.current && !pickerRef.current.contains(e.target);
129-
129+
130130
// Close whenever clicking outside the picker itself, regardless of parent container
131131
if (isOutsidePicker) {
132132
onClose();
@@ -162,62 +162,62 @@ const ColorPicker = ({
162162
const pickerWidth = 240; // minWidth from the picker style
163163
// Update pickerHeight estimate for new sliders
164164
const pickerHeight = 320;
165-
165+
166166
let left, right, top;
167-
167+
168168
// Always try to align the right edge of the color picker with the right edge of the icon
169169
// This gives a nice visual alignment
170170
right = window.innerWidth - position.x;
171171
left = undefined;
172-
172+
173173
top = position.y + offset;
174-
174+
175175
// Check if picker would go off the left edge when right-aligned
176176
if (window.innerWidth - right < pickerWidth) {
177177
// Switch to left-aligned positioning
178178
left = position.x + offset;
179179
right = undefined;
180-
180+
181181
// Ensure left-aligned version doesn't go off the right edge
182182
if (left + pickerWidth > window.innerWidth) {
183183
left = window.innerWidth - pickerWidth - offset;
184184
}
185185
}
186-
186+
187187
// Check if picker would go off the bottom edge
188188
if (top + pickerHeight > window.innerHeight) {
189189
top = position.y - pickerHeight - offset; // Position above the trigger
190190
}
191-
191+
192192
// Ensure we don't go off the top edge
193193
if (top < 0) {
194194
top = offset;
195195
}
196-
196+
197197
const style = {
198198
position: 'fixed',
199199
top: Math.max(0, top),
200200
zIndex: 30000
201201
};
202-
202+
203203
if (left !== undefined) {
204204
style.left = Math.max(0, left);
205205
} else {
206206
style.right = Math.max(0, right);
207207
}
208-
208+
209209
return style;
210210
};
211211

212212
const currentPreviewColor = hsvToHex(selectedHue, selectedSaturation / 100, selectedBrightness / 100);
213213

214214
// Generate gradient colors for saturation slider (gray to fully saturated at current hue/brightness)
215215
const saturationGradientStart = hsvToHex(selectedHue, 0, selectedBrightness / 100);
216-
const saturationGradientEnd = hsvToHex(selectedHue, 100, selectedBrightness / 100);
216+
const saturationGradientEnd = hsvToHex(selectedHue, 1, selectedBrightness / 100);
217217

218218
// Generate gradient colors for brightness slider (black to white at current hue/saturation)
219219
const brightnessGradientStart = hsvToHex(selectedHue, selectedSaturation / 100, 0);
220-
const brightnessGradientEnd = hsvToHex(selectedHue, selectedSaturation / 100, 100);
220+
const brightnessGradientEnd = hsvToHex(selectedHue, selectedSaturation / 100, 1);
221221

222222
return (
223223
<div
@@ -236,11 +236,11 @@ const ColorPicker = ({
236236
}}
237237
>
238238
{/* Color preview */}
239-
<div style={{
240-
display: 'flex',
241-
alignItems: 'center',
242-
gap: '8px',
243-
marginBottom: '12px'
239+
<div style={{
240+
display: 'flex',
241+
alignItems: 'center',
242+
gap: '8px',
243+
marginBottom: '12px'
244244
}}>
245245
<div
246246
style={{
@@ -258,12 +258,12 @@ const ColorPicker = ({
258258

259259
{/* Hue slider */}
260260
<div style={{ marginBottom: '12px' }}>
261-
<label style={{
262-
display: 'block',
263-
color: '#260000',
264-
fontSize: '12px',
265-
fontWeight: 'bold',
266-
marginBottom: '4px'
261+
<label style={{
262+
display: 'block',
263+
color: '#260000',
264+
fontSize: '12px',
265+
fontWeight: 'bold',
266+
marginBottom: '4px'
267267
}}>
268268
Hue
269269
</label>
@@ -324,12 +324,12 @@ const ColorPicker = ({
324324

325325
{/* Saturation slider */}
326326
<div style={{ marginBottom: '12px' }}>
327-
<label style={{
328-
display: 'block',
329-
color: '#260000',
330-
fontSize: '12px',
331-
fontWeight: 'bold',
332-
marginBottom: '4px'
327+
<label style={{
328+
display: 'block',
329+
color: '#260000',
330+
fontSize: '12px',
331+
fontWeight: 'bold',
332+
marginBottom: '4px'
333333
}}>
334334
Saturation
335335
</label>
@@ -382,12 +382,12 @@ const ColorPicker = ({
382382

383383
{/* Brightness slider */}
384384
<div style={{ marginBottom: '12px' }}>
385-
<label style={{
386-
display: 'block',
387-
color: '#260000',
388-
fontSize: '12px',
389-
fontWeight: 'bold',
390-
marginBottom: '4px'
385+
<label style={{
386+
display: 'block',
387+
color: '#260000',
388+
fontSize: '12px',
389+
fontWeight: 'bold',
390+
marginBottom: '4px'
391391
}}>
392392
Brightness
393393
</label>
@@ -440,12 +440,12 @@ const ColorPicker = ({
440440

441441
{/* Hex input */}
442442
<div>
443-
<label style={{
444-
display: 'block',
445-
color: '#260000',
446-
fontSize: '12px',
447-
fontWeight: 'bold',
448-
marginBottom: '4px'
443+
<label style={{
444+
display: 'block',
445+
color: '#260000',
446+
fontSize: '12px',
447+
fontWeight: 'bold',
448+
marginBottom: '4px'
449449
}}>
450450
Hex Code
451451
</label>

0 commit comments

Comments
 (0)