@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.js CHANGED
@@ -5288,8 +5288,16 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5288
5288
  const [alpha, setAlpha] = React.useState(100);
5289
5289
  const [colorFormat, setColorFormat] = React.useState('hex');
5290
5290
  const [isCopied, setIsCopied] = React.useState(false);
5291
- const [inputValue, setInputValue] = React.useState(defaultValue);
5291
+ const [inputValue, setInputValue] = React.useState(value || defaultValue);
5292
5292
  const pickerRef = React.useRef(null);
5293
+ // 초기화: defaultValue가 있으면 HSL 값으로 변환
5294
+ React.useEffect(() => {
5295
+ const initialColor = value || defaultValue;
5296
+ if (initialColor) {
5297
+ updateHSLFromHex(initialColor);
5298
+ setInputValue(initialColor);
5299
+ }
5300
+ }, []); // 컴포넌트 마운트 시에만 실행
5293
5301
  // value prop이 변경되면 업데이트
5294
5302
  React.useEffect(() => {
5295
5303
  if (value) {
@@ -5316,7 +5324,7 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5316
5324
  b: parseInt(result[3], 16)
5317
5325
  } : null;
5318
5326
  };
5319
- // RGB를 HSL로 변환
5327
+ // RGB를 HSL로 변환 (정밀도 개선)
5320
5328
  const rgbToHsl = (r, g, b) => {
5321
5329
  r /= 255;
5322
5330
  g /= 255;
@@ -5338,9 +5346,14 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5338
5346
  break;
5339
5347
  }
5340
5348
  }
5341
- return { h: Math.round(h * 360), s: Math.round(s * 100), l: Math.round(l * 100) };
5349
+ // 정밀도 개선: 반올림 대신 정확한 계산
5350
+ return {
5351
+ h: Math.round(h * 360 * 100) / 100,
5352
+ s: Math.round(s * 100 * 100) / 100,
5353
+ l: Math.round(l * 100 * 100) / 100
5354
+ };
5342
5355
  };
5343
- // HSL을 RGB로 변환
5356
+ // HSL을 RGB로 변환 (정밀도 개선)
5344
5357
  const hslToRgb = (h, s, l) => {
5345
5358
  l /= 100;
5346
5359
  const a = s * Math.min(l, 1 - l) / 100;
@@ -5351,10 +5364,14 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5351
5364
  };
5352
5365
  return { r: f(0), g: f(8), b: f(4) };
5353
5366
  };
5354
- // HSL을 HEX로 변환
5367
+ // HSL을 HEX로 변환 (정밀도 개선)
5355
5368
  const hslToHex = (h, s, l) => {
5356
5369
  const rgb = hslToRgb(h, s, l);
5357
- const toHex = (n) => n.toString(16).padStart(2, '0');
5370
+ const toHex = (n) => {
5371
+ // RGB 값을 0-255 범위로 제한하고 HEX로 변환
5372
+ const clamped = Math.max(0, Math.min(255, Math.round(n)));
5373
+ return clamped.toString(16).padStart(2, '0');
5374
+ };
5358
5375
  return `#${toHex(rgb.r)}${toHex(rgb.g)}${toHex(rgb.b)}`.toUpperCase();
5359
5376
  };
5360
5377
  // 현재 포맷에 따른 색상 문자열 반환
@@ -5427,8 +5444,9 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5427
5444
  setInputValue(newValue);
5428
5445
  // HEX 값이 유효하면 실시간으로 색상 업데이트
5429
5446
  if (/^#[0-9A-F]{6}$/i.test(newValue)) {
5430
- handleColorChange(newValue.toUpperCase());
5431
- updateHSLFromHex(newValue);
5447
+ const normalizedHex = newValue.toUpperCase();
5448
+ handleColorChange(normalizedHex);
5449
+ updateHSLFromHex(normalizedHex);
5432
5450
  }
5433
5451
  };
5434
5452
  // 입력 필드에서 포커스 아웃 시 검증 및 적용