@designbasekorea/ui 0.2.27 → 0.2.28

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.umd.js CHANGED
@@ -5478,12 +5478,14 @@
5478
5478
  return; const t = e.touches[0]; updateFromArea(t.clientX, t.clientY); };
5479
5479
  const onAreaTouchEnd = () => { dragging.current = false; };
5480
5480
  /** 슬라이더 */
5481
- const onHueChange = (e) => setH(parseInt(e.target.value, 10));
5482
- const onAlphaChange = (e) => {
5481
+ const onHueChange = React.useCallback((e) => {
5482
+ setH(parseInt(e.target.value, 10));
5483
+ }, []);
5484
+ const onAlphaChange = React.useCallback((e) => {
5483
5485
  const newAlpha = parseInt(e.target.value, 10);
5484
5486
  setA(newAlpha);
5485
5487
  setAlphaInput(String(newAlpha)); // 실시간 동기화
5486
- };
5488
+ }, []);
5487
5489
  /** 컬러 인풋: 엔터로만 확정 */
5488
5490
  const tryCommitColorInput = () => {
5489
5491
  const str = colorInput.trim();
@@ -5552,7 +5554,7 @@
5552
5554
  setAlphaInput(String(a));
5553
5555
  };
5554
5556
  /** 복사 */
5555
- const onCopy = async () => {
5557
+ const onCopy = React.useCallback(async () => {
5556
5558
  try {
5557
5559
  await navigator.clipboard.writeText(formatted);
5558
5560
  setIsCopied(true);
@@ -5561,9 +5563,9 @@
5561
5563
  catch (e) {
5562
5564
  console.error(e);
5563
5565
  }
5564
- };
5566
+ }, [formatted]);
5565
5567
  /** EyeDropper */
5566
- const onEyedrop = async () => {
5568
+ const onEyedrop = React.useCallback(async () => {
5567
5569
  try {
5568
5570
  if ('EyeDropper' in window) {
5569
5571
  const eye = new window.EyeDropper();
@@ -5581,21 +5583,21 @@
5581
5583
  catch (e) {
5582
5584
  console.error(e);
5583
5585
  }
5584
- };
5586
+ }, []);
5585
5587
  /** 모달용 핸들러 */
5586
- const handleModalOpen = () => {
5588
+ const handleModalOpen = React.useCallback(() => {
5587
5589
  if (type === 'modal') {
5588
5590
  setTempColor(formatted);
5589
5591
  }
5590
5592
  setIsOpen(true);
5591
- };
5592
- const handleModalApply = () => {
5593
+ }, [type, formatted]);
5594
+ const handleModalApply = React.useCallback(() => {
5593
5595
  if (type === 'modal') {
5594
5596
  onApply?.(formatted);
5595
5597
  setIsOpen(false);
5596
5598
  }
5597
- };
5598
- const handleModalCancel = () => {
5599
+ }, [type, formatted, onApply]);
5600
+ const handleModalCancel = React.useCallback(() => {
5599
5601
  if (type === 'modal') {
5600
5602
  // 원래 색상으로 복원
5601
5603
  const rgb = hexToRgb(tempColor);
@@ -5608,9 +5610,9 @@
5608
5610
  onCancel?.();
5609
5611
  setIsOpen(false);
5610
5612
  }
5611
- };
5613
+ }, [type, tempColor, onCancel]);
5612
5614
  /** 배경 스타일 */
5613
- const hueTrackStyle = {
5615
+ const hueTrackStyle = React.useMemo(() => ({
5614
5616
  background: `linear-gradient(to right,
5615
5617
  hsl(0,100%,50%),
5616
5618
  hsl(60,100%,50%),
@@ -5619,15 +5621,15 @@
5619
5621
  hsl(240,100%,50%),
5620
5622
  hsl(300,100%,50%),
5621
5623
  hsl(360,100%,50%))`,
5622
- };
5623
- const areaBackground = {
5624
+ }), []);
5625
+ const areaBackground = React.useMemo(() => ({
5624
5626
  backgroundImage: `
5625
5627
  linear-gradient(to top, rgba(0,0,0,1), rgba(0,0,0,0)),
5626
5628
  linear-gradient(to right, #ffffff, hsl(${h}, 100%, 50%))
5627
5629
  `,
5628
- };
5630
+ }), [h]);
5629
5631
  /** ✔︎ 알파 트랙: 색상 무관, 고정 흑백 그라디언트 */
5630
- const alphaTrackStyle = {
5632
+ const alphaTrackStyle = React.useMemo(() => ({
5631
5633
  backgroundImage: `
5632
5634
  linear-gradient(45deg, var(--db-border-base) 25%, transparent 25%),
5633
5635
  linear-gradient(-45deg, var(--db-border-base) 25%, transparent 25%),
@@ -5638,7 +5640,7 @@
5638
5640
  backgroundSize: '8px 8px,8px 8px,8px 8px,8px 8px,100% 100%',
5639
5641
  backgroundPosition: '0 0,0 4px,4px -4px,-4px 0,0 0',
5640
5642
  backgroundColor: 'var(--db-surface-base)',
5641
- };
5643
+ }), []);
5642
5644
  const classes = clsx('designbase-color-picker', `designbase-color-picker--${size}`, `designbase-color-picker--${position}`, {
5643
5645
  'designbase-color-picker--disabled': disabled,
5644
5646
  'designbase-color-picker--readonly': readonly,
@@ -5646,13 +5648,13 @@
5646
5648
  'designbase-color-picker--no-input': !showInput,
5647
5649
  }, className);
5648
5650
  const Trigger = (jsxRuntime.jsxs("div", { className: "designbase-color-picker__trigger", onClick: () => !disabled && !readonly && handleModalOpen(), children: [jsxRuntime.jsx("div", { className: "designbase-color-picker__color-display", children: jsxRuntime.jsx("div", { className: "designbase-color-picker__color-box", style: { backgroundColor: showAlpha ? `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${a / 100})` : hex } }) }), showInput && (jsxRuntime.jsx("input", { type: "text", value: colorInput, onChange: (e) => setColorInput(e.target.value), onKeyDown: onColorKeyDown, onBlur: onColorBlur, onClick: (e) => e.stopPropagation(), disabled: disabled, readOnly: readonly, className: "designbase-color-picker__input", placeholder: "#000000" })), showInput && showCopyButton && (jsxRuntime.jsx("button", { type: "button", className: "designbase-color-picker__copy-button-inline", onClick: (e) => { e.stopPropagation(); onCopy(); }, disabled: disabled, "aria-label": "Copy color value", children: isCopied ? jsxRuntime.jsx(icons.DoneIcon, { size: 14 }) : jsxRuntime.jsx(icons.CopyIcon, { size: 14 }) })), jsxRuntime.jsx("button", { type: "button", className: "designbase-color-picker__toggle", disabled: disabled, "aria-label": "Toggle color picker", children: jsxRuntime.jsx(icons.ChevronDownIcon, { size: 16 }) })] }));
5649
- const Selector = (jsxRuntime.jsxs("div", { className: "designbase-color-picker__selector", children: [jsxRuntime.jsx("div", { className: "designbase-color-picker__color-area", children: jsxRuntime.jsx("div", { ref: areaRef, className: "designbase-color-picker__color-field", style: areaBackground, onMouseDown: onAreaMouseDown, onMouseMove: onAreaMouseMove, onMouseUp: onAreaMouseUp, onMouseLeave: onAreaLeave, onTouchStart: onAreaTouchStart, onTouchMove: onAreaTouchMove, onTouchEnd: onAreaTouchEnd, children: jsxRuntime.jsx("div", { className: "designbase-color-picker__color-pointer", style: { left: `${s}%`, top: `${100 - v}%`, backgroundColor: `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})` } }) }) }), jsxRuntime.jsxs("div", { className: "designbase-color-picker__controls", children: [jsxRuntime.jsx(Button, { variant: "tertiary", size: "m", iconOnly: true, onClick: onEyedrop, "aria-label": "Eyedropper tool", children: jsxRuntime.jsx(icons.EyedropperIcon, {}) }), jsxRuntime.jsxs("div", { className: "designbase-color-picker__slider-container", children: [jsxRuntime.jsx("div", { className: "designbase-color-picker__hue-slider", children: jsxRuntime.jsx("input", { type: "range", min: 0, max: 360, value: h, onChange: onHueChange, className: "designbase-color-picker__slider designbase-color-picker__slider--hue", style: hueTrackStyle }) }), showAlpha && (jsxRuntime.jsx("div", { className: "designbase-color-picker__alpha-slider", children: jsxRuntime.jsx("input", { type: "range", min: 0, max: 100, value: a, onChange: onAlphaChange, className: "designbase-color-picker__slider designbase-color-picker__slider--alpha", style: alphaTrackStyle }) }))] })] }), jsxRuntime.jsxs("div", { className: "designbase-color-picker__value-display", children: [showFormatSelector && (jsxRuntime.jsx(Select, { value: format, onChange: (v) => setFormat(v), showClearButton: false, position: "top", options: [
5651
+ const Selector = (jsxRuntime.jsxs("div", { className: "designbase-color-picker__selector", children: [jsxRuntime.jsx("div", { className: "designbase-color-picker__color-area", children: jsxRuntime.jsx("div", { ref: areaRef, className: "designbase-color-picker__color-field", style: areaBackground, onMouseDown: onAreaMouseDown, onMouseMove: onAreaMouseMove, onMouseUp: onAreaMouseUp, onMouseLeave: onAreaLeave, onTouchStart: onAreaTouchStart, onTouchMove: onAreaTouchMove, onTouchEnd: onAreaTouchEnd, children: jsxRuntime.jsx("div", { className: "designbase-color-picker__color-pointer", style: { left: `${s}%`, top: `${100 - v}%`, backgroundColor: `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})` } }) }) }), jsxRuntime.jsxs("div", { className: "designbase-color-picker__controls", children: [jsxRuntime.jsx(Button, { variant: "tertiary", size: "m", iconOnly: true, onClick: onEyedrop, "aria-label": "Eyedropper tool", children: jsxRuntime.jsx(icons.EyedropperIcon, {}) }), jsxRuntime.jsxs("div", { className: "designbase-color-picker__slider-container", children: [jsxRuntime.jsx("div", { className: "designbase-color-picker__hue-slider", children: jsxRuntime.jsx("input", { type: "range", min: 0, max: 360, value: h, onChange: onHueChange, className: "designbase-color-picker__slider designbase-color-picker__slider--hue", style: hueTrackStyle }) }), showAlpha && (jsxRuntime.jsx("div", { className: "designbase-color-picker__alpha-slider", children: jsxRuntime.jsx("input", { type: "range", min: 0, max: 100, value: a, onChange: onAlphaChange, className: "designbase-color-picker__slider designbase-color-picker__slider--alpha", style: alphaTrackStyle }) }))] })] }), jsxRuntime.jsxs("div", { className: "designbase-color-picker__value-display", children: [showFormatSelector && (jsxRuntime.jsx(Select, { value: format, onChange: (v) => setFormat(v), showClearButton: false, options: [
5650
5652
  { label: 'HEX', value: 'hex' },
5651
5653
  { label: 'RGB', value: 'rgb' },
5652
5654
  { label: 'RGBA', value: 'rgba' },
5653
5655
  { label: 'HSL', value: 'hsl' },
5654
5656
  { label: 'HSLA', value: 'hsla' },
5655
- ], size: "s" })), jsxRuntime.jsx(Input, { type: "text", value: colorInput, onChange: setColorInput, onKeyDown: onColorKeyDown, onBlur: onColorBlur, placeholder: "#000000", size: "s", className: "designbase-color-picker__value-input" }), showAlpha && (jsxRuntime.jsxs("div", { className: "designbase-color-picker__alpha-input-wrap", children: [jsxRuntime.jsx(Input, { type: "text", inputMode: "numeric", value: alphaInput, onChange: (value) => setAlphaInput(value.replace(/[^\d]/g, '').slice(0, 3)), onKeyDown: onAlphaInputKeyDown, onBlur: onAlphaInputBlur, placeholder: "100", size: "s", className: "designbase-color-picker__alpha-input", "aria-label": "Alpha percent" }), jsxRuntime.jsx("span", { className: "designbase-color-picker__alpha-suffix", children: "%" })] })), showCopyButton && (jsxRuntime.jsx(Button, { variant: "tertiary", size: "m", iconOnly: true, onClick: onCopy, "aria-label": "Copy color value", children: isCopied ? jsxRuntime.jsx(icons.DoneIcon, {}) : jsxRuntime.jsx(icons.CopyIcon, {}) }))] })] }));
5657
+ ], size: "s", position: "top" })), jsxRuntime.jsx(Input, { type: "text", value: colorInput, onChange: setColorInput, onKeyDown: onColorKeyDown, onBlur: onColorBlur, placeholder: "#000000", size: "s", className: "designbase-color-picker__value-input" }), showAlpha && (jsxRuntime.jsxs("div", { className: "designbase-color-picker__alpha-input-wrap", children: [jsxRuntime.jsx(Input, { type: "text", inputMode: "numeric", value: alphaInput, onChange: (value) => setAlphaInput(value.replace(/[^\d]/g, '').slice(0, 3)), onKeyDown: onAlphaInputKeyDown, onBlur: onAlphaInputBlur, placeholder: "100", size: "s", className: "designbase-color-picker__alpha-input", "aria-label": "Alpha percent" }), jsxRuntime.jsx("span", { className: "designbase-color-picker__alpha-suffix", children: "%" })] })), showCopyButton && (jsxRuntime.jsx(Button, { variant: "tertiary", size: "m", iconOnly: true, onClick: onCopy, "aria-label": "Copy color value", children: isCopied ? jsxRuntime.jsx(icons.DoneIcon, {}) : jsxRuntime.jsx(icons.CopyIcon, {}) }))] })] }));
5656
5658
  return (jsxRuntime.jsxs("div", { ref: pickerRef, className: classes, children: [Trigger, type === 'dropdown' && isOpen && (jsxRuntime.jsx("div", { className: "designbase-color-picker__dropdown", onClick: (e) => e.stopPropagation(), children: Selector })), type === 'modal' && (jsxRuntime.jsxs(Modal, { isOpen: isOpen, onClose: handleModalCancel, title: "\uC0C9\uC0C1 \uC120\uD0DD", size: "s", children: [jsxRuntime.jsx(ModalBody, { children: Selector }), jsxRuntime.jsx(ModalFooter, { children: jsxRuntime.jsxs("div", { style: { display: 'flex', gap: '8px', justifyContent: 'flex-end' }, children: [jsxRuntime.jsx(Button, { variant: "tertiary", size: "s", onClick: handleModalCancel, children: "\uCDE8\uC18C" }), jsxRuntime.jsx(Button, { variant: "primary", size: "s", onClick: handleModalApply, children: "\uC801\uC6A9" })] }) })] }))] }));
5657
5659
  };
5658
5660
  ColorPicker.displayName = 'ColorPicker';