@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.js CHANGED
@@ -5479,12 +5479,14 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5479
5479
  return; const t = e.touches[0]; updateFromArea(t.clientX, t.clientY); };
5480
5480
  const onAreaTouchEnd = () => { dragging.current = false; };
5481
5481
  /** 슬라이더 */
5482
- const onHueChange = (e) => setH(parseInt(e.target.value, 10));
5483
- const onAlphaChange = (e) => {
5482
+ const onHueChange = React.useCallback((e) => {
5483
+ setH(parseInt(e.target.value, 10));
5484
+ }, []);
5485
+ const onAlphaChange = React.useCallback((e) => {
5484
5486
  const newAlpha = parseInt(e.target.value, 10);
5485
5487
  setA(newAlpha);
5486
5488
  setAlphaInput(String(newAlpha)); // 실시간 동기화
5487
- };
5489
+ }, []);
5488
5490
  /** 컬러 인풋: 엔터로만 확정 */
5489
5491
  const tryCommitColorInput = () => {
5490
5492
  const str = colorInput.trim();
@@ -5553,7 +5555,7 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5553
5555
  setAlphaInput(String(a));
5554
5556
  };
5555
5557
  /** 복사 */
5556
- const onCopy = async () => {
5558
+ const onCopy = React.useCallback(async () => {
5557
5559
  try {
5558
5560
  await navigator.clipboard.writeText(formatted);
5559
5561
  setIsCopied(true);
@@ -5562,9 +5564,9 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5562
5564
  catch (e) {
5563
5565
  console.error(e);
5564
5566
  }
5565
- };
5567
+ }, [formatted]);
5566
5568
  /** EyeDropper */
5567
- const onEyedrop = async () => {
5569
+ const onEyedrop = React.useCallback(async () => {
5568
5570
  try {
5569
5571
  if ('EyeDropper' in window) {
5570
5572
  const eye = new window.EyeDropper();
@@ -5582,21 +5584,21 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5582
5584
  catch (e) {
5583
5585
  console.error(e);
5584
5586
  }
5585
- };
5587
+ }, []);
5586
5588
  /** 모달용 핸들러 */
5587
- const handleModalOpen = () => {
5589
+ const handleModalOpen = React.useCallback(() => {
5588
5590
  if (type === 'modal') {
5589
5591
  setTempColor(formatted);
5590
5592
  }
5591
5593
  setIsOpen(true);
5592
- };
5593
- const handleModalApply = () => {
5594
+ }, [type, formatted]);
5595
+ const handleModalApply = React.useCallback(() => {
5594
5596
  if (type === 'modal') {
5595
5597
  onApply?.(formatted);
5596
5598
  setIsOpen(false);
5597
5599
  }
5598
- };
5599
- const handleModalCancel = () => {
5600
+ }, [type, formatted, onApply]);
5601
+ const handleModalCancel = React.useCallback(() => {
5600
5602
  if (type === 'modal') {
5601
5603
  // 원래 색상으로 복원
5602
5604
  const rgb = hexToRgb(tempColor);
@@ -5609,9 +5611,9 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5609
5611
  onCancel?.();
5610
5612
  setIsOpen(false);
5611
5613
  }
5612
- };
5614
+ }, [type, tempColor, onCancel]);
5613
5615
  /** 배경 스타일 */
5614
- const hueTrackStyle = {
5616
+ const hueTrackStyle = React.useMemo(() => ({
5615
5617
  background: `linear-gradient(to right,
5616
5618
  hsl(0,100%,50%),
5617
5619
  hsl(60,100%,50%),
@@ -5620,15 +5622,15 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5620
5622
  hsl(240,100%,50%),
5621
5623
  hsl(300,100%,50%),
5622
5624
  hsl(360,100%,50%))`,
5623
- };
5624
- const areaBackground = {
5625
+ }), []);
5626
+ const areaBackground = React.useMemo(() => ({
5625
5627
  backgroundImage: `
5626
5628
  linear-gradient(to top, rgba(0,0,0,1), rgba(0,0,0,0)),
5627
5629
  linear-gradient(to right, #ffffff, hsl(${h}, 100%, 50%))
5628
5630
  `,
5629
- };
5631
+ }), [h]);
5630
5632
  /** ✔︎ 알파 트랙: 색상 무관, 고정 흑백 그라디언트 */
5631
- const alphaTrackStyle = {
5633
+ const alphaTrackStyle = React.useMemo(() => ({
5632
5634
  backgroundImage: `
5633
5635
  linear-gradient(45deg, var(--db-border-base) 25%, transparent 25%),
5634
5636
  linear-gradient(-45deg, var(--db-border-base) 25%, transparent 25%),
@@ -5639,7 +5641,7 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5639
5641
  backgroundSize: '8px 8px,8px 8px,8px 8px,8px 8px,100% 100%',
5640
5642
  backgroundPosition: '0 0,0 4px,4px -4px,-4px 0,0 0',
5641
5643
  backgroundColor: 'var(--db-surface-base)',
5642
- };
5644
+ }), []);
5643
5645
  const classes = clsx('designbase-color-picker', `designbase-color-picker--${size}`, `designbase-color-picker--${position}`, {
5644
5646
  'designbase-color-picker--disabled': disabled,
5645
5647
  'designbase-color-picker--readonly': readonly,
@@ -5647,13 +5649,13 @@ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left',
5647
5649
  'designbase-color-picker--no-input': !showInput,
5648
5650
  }, className);
5649
5651
  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 }) })] }));
5650
- 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: [
5652
+ 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: [
5651
5653
  { label: 'HEX', value: 'hex' },
5652
5654
  { label: 'RGB', value: 'rgb' },
5653
5655
  { label: 'RGBA', value: 'rgba' },
5654
5656
  { label: 'HSL', value: 'hsl' },
5655
5657
  { label: 'HSLA', value: 'hsla' },
5656
- ], 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, {}) }))] })] }));
5658
+ ], 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, {}) }))] })] }));
5657
5659
  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" })] }) })] }))] }));
5658
5660
  };
5659
5661
  ColorPicker.displayName = 'ColorPicker';