@designbasekorea/ui 0.2.18 → 0.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +26 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +26 -8
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +26 -8
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -5286,8 +5286,16 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
|
|
|
5286
5286
|
const [alpha, setAlpha] = useState(100);
|
|
5287
5287
|
const [colorFormat, setColorFormat] = useState('hex');
|
|
5288
5288
|
const [isCopied, setIsCopied] = useState(false);
|
|
5289
|
-
const [inputValue, setInputValue] = useState(defaultValue);
|
|
5289
|
+
const [inputValue, setInputValue] = useState(value || defaultValue);
|
|
5290
5290
|
const pickerRef = useRef(null);
|
|
5291
|
+
// 초기화: defaultValue가 있으면 HSL 값으로 변환
|
|
5292
|
+
useEffect(() => {
|
|
5293
|
+
const initialColor = value || defaultValue;
|
|
5294
|
+
if (initialColor) {
|
|
5295
|
+
updateHSLFromHex(initialColor);
|
|
5296
|
+
setInputValue(initialColor);
|
|
5297
|
+
}
|
|
5298
|
+
}, []); // 컴포넌트 마운트 시에만 실행
|
|
5291
5299
|
// value prop이 변경되면 업데이트
|
|
5292
5300
|
useEffect(() => {
|
|
5293
5301
|
if (value) {
|
|
@@ -5314,7 +5322,7 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
|
|
|
5314
5322
|
b: parseInt(result[3], 16)
|
|
5315
5323
|
} : null;
|
|
5316
5324
|
};
|
|
5317
|
-
// RGB를 HSL로 변환
|
|
5325
|
+
// RGB를 HSL로 변환 (정밀도 개선)
|
|
5318
5326
|
const rgbToHsl = (r, g, b) => {
|
|
5319
5327
|
r /= 255;
|
|
5320
5328
|
g /= 255;
|
|
@@ -5336,9 +5344,14 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
|
|
|
5336
5344
|
break;
|
|
5337
5345
|
}
|
|
5338
5346
|
}
|
|
5339
|
-
|
|
5347
|
+
// 정밀도 개선: 반올림 대신 더 정확한 계산
|
|
5348
|
+
return {
|
|
5349
|
+
h: Math.round(h * 360 * 100) / 100,
|
|
5350
|
+
s: Math.round(s * 100 * 100) / 100,
|
|
5351
|
+
l: Math.round(l * 100 * 100) / 100
|
|
5352
|
+
};
|
|
5340
5353
|
};
|
|
5341
|
-
// HSL을 RGB로 변환
|
|
5354
|
+
// HSL을 RGB로 변환 (정밀도 개선)
|
|
5342
5355
|
const hslToRgb = (h, s, l) => {
|
|
5343
5356
|
l /= 100;
|
|
5344
5357
|
const a = s * Math.min(l, 1 - l) / 100;
|
|
@@ -5349,10 +5362,14 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
|
|
|
5349
5362
|
};
|
|
5350
5363
|
return { r: f(0), g: f(8), b: f(4) };
|
|
5351
5364
|
};
|
|
5352
|
-
// HSL을 HEX로 변환
|
|
5365
|
+
// HSL을 HEX로 변환 (정밀도 개선)
|
|
5353
5366
|
const hslToHex = (h, s, l) => {
|
|
5354
5367
|
const rgb = hslToRgb(h, s, l);
|
|
5355
|
-
const toHex = (n) =>
|
|
5368
|
+
const toHex = (n) => {
|
|
5369
|
+
// RGB 값을 0-255 범위로 제한하고 HEX로 변환
|
|
5370
|
+
const clamped = Math.max(0, Math.min(255, Math.round(n)));
|
|
5371
|
+
return clamped.toString(16).padStart(2, '0');
|
|
5372
|
+
};
|
|
5356
5373
|
return `#${toHex(rgb.r)}${toHex(rgb.g)}${toHex(rgb.b)}`.toUpperCase();
|
|
5357
5374
|
};
|
|
5358
5375
|
// 현재 포맷에 따른 색상 문자열 반환
|
|
@@ -5425,8 +5442,9 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
|
|
|
5425
5442
|
setInputValue(newValue);
|
|
5426
5443
|
// HEX 값이 유효하면 실시간으로 색상 업데이트
|
|
5427
5444
|
if (/^#[0-9A-F]{6}$/i.test(newValue)) {
|
|
5428
|
-
|
|
5429
|
-
|
|
5445
|
+
const normalizedHex = newValue.toUpperCase();
|
|
5446
|
+
handleColorChange(normalizedHex);
|
|
5447
|
+
updateHSLFromHex(normalizedHex);
|
|
5430
5448
|
}
|
|
5431
5449
|
};
|
|
5432
5450
|
// 입력 필드에서 포커스 아웃 시 검증 및 적용
|