@designbasekorea/ui 0.2.10 → 0.2.13

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
@@ -5278,7 +5278,7 @@
5278
5278
  };
5279
5279
  Chip.displayName = 'Chip';
5280
5280
 
5281
- const ColorPicker = ({ size = 'm', type = 'dropdown', value, defaultValue = '#006FFF', showInput = true, showAlpha = false, showFormatSelector = true, showCopyButton = true, disabled = false, readonly = false, onChange, className, }) => {
5281
+ const ColorPicker = ({ size = 'm', type = 'dropdown', position = 'bottom-left', value, defaultValue = '#006FFF', showInput = true, showAlpha = false, showFormatSelector = true, showCopyButton = true, disabled = false, readonly = false, onChange, className, }) => {
5282
5282
  const [selectedColor, setSelectedColor] = React.useState(value || defaultValue);
5283
5283
  const [isOpen, setIsOpen] = React.useState(false);
5284
5284
  const [hue, setHue] = React.useState(211);
@@ -5424,6 +5424,11 @@
5424
5424
  const handleInputChange = (e) => {
5425
5425
  const newValue = e.target.value.trim();
5426
5426
  setInputValue(newValue);
5427
+ // HEX 값이 유효하면 실시간으로 색상 업데이트
5428
+ if (/^#[0-9A-F]{6}$/i.test(newValue)) {
5429
+ handleColorChange(newValue.toUpperCase());
5430
+ updateHSLFromHex(newValue);
5431
+ }
5427
5432
  };
5428
5433
  // 입력 필드에서 포커스 아웃 시 검증 및 적용
5429
5434
  const handleInputBlur = () => {
@@ -5511,7 +5516,7 @@
5511
5516
  return;
5512
5517
  setIsOpen(!isOpen);
5513
5518
  };
5514
- const classes = clsx('designbase-color-picker', `designbase-color-picker--${size}`, {
5519
+ const classes = clsx('designbase-color-picker', `designbase-color-picker--${size}`, `designbase-color-picker--${position}`, {
5515
5520
  'designbase-color-picker--disabled': disabled,
5516
5521
  'designbase-color-picker--readonly': readonly,
5517
5522
  'designbase-color-picker--open': isOpen,
@@ -10854,8 +10859,11 @@
10854
10859
  const Tabs = ({ items, defaultSelectedId, selectedId, orientation = 'horizontal', size = 'm', fullWidth = false, variant = 'default', className, onTabChange, ...props }) => {
10855
10860
  const [activeTabId, setActiveTabId] = React.useState(selectedId ?? defaultSelectedId ?? items[0]?.id ?? '');
10856
10861
  const [focusedTabId, setFocusedTabId] = React.useState('');
10862
+ const [isDragging, setIsDragging] = React.useState(false);
10857
10863
  const tabListRef = React.useRef(null);
10858
10864
  const tabRefs = React.useRef(new Map());
10865
+ const dragStartRef = React.useRef(null);
10866
+ const clickStartRef = React.useRef(null);
10859
10867
  // 제어 컴포넌트 처리
10860
10868
  React.useEffect(() => {
10861
10869
  if (selectedId !== undefined) {
@@ -10927,18 +10935,126 @@
10927
10935
  }
10928
10936
  }, [items, orientation]);
10929
10937
  const handleTabSelect = React.useCallback((tabId) => {
10938
+ // 드래그 중이면 탭 선택 무시
10939
+ if (isDragging)
10940
+ return;
10930
10941
  const tab = items.find(item => item.id === tabId);
10931
10942
  if (tab && !tab.disabled) {
10932
10943
  setActiveTabId(tabId);
10933
10944
  onTabChange?.(tabId);
10934
10945
  }
10935
- }, [items, onTabChange]);
10946
+ }, [items, onTabChange, isDragging]);
10936
10947
  const handleTabFocus = React.useCallback((tabId) => {
10937
10948
  setFocusedTabId(tabId);
10938
10949
  }, []);
10939
10950
  const handleTabBlur = React.useCallback(() => {
10940
10951
  setFocusedTabId('');
10941
10952
  }, []);
10953
+ // 드래그 스크롤 핸들러들
10954
+ const handleMouseDown = React.useCallback((e) => {
10955
+ if (orientation !== 'horizontal' || !tabListRef.current)
10956
+ return;
10957
+ // 클릭 시작 위치와 시간 기록
10958
+ clickStartRef.current = {
10959
+ x: e.pageX,
10960
+ y: e.pageY,
10961
+ time: Date.now()
10962
+ };
10963
+ dragStartRef.current = {
10964
+ x: e.pageX - tabListRef.current.offsetLeft,
10965
+ scrollLeft: tabListRef.current.scrollLeft
10966
+ };
10967
+ }, [orientation]);
10968
+ const handleMouseMove = React.useCallback((e) => {
10969
+ if (!dragStartRef.current || !tabListRef.current)
10970
+ return;
10971
+ // 아직 드래그가 시작되지 않았다면 드래그 시작 여부 판단
10972
+ if (!isDragging && clickStartRef.current) {
10973
+ const deltaX = Math.abs(e.pageX - clickStartRef.current.x);
10974
+ const deltaY = Math.abs(e.pageY - clickStartRef.current.y);
10975
+ const deltaTime = Date.now() - clickStartRef.current.time;
10976
+ // 5px 이상 이동하거나 200ms 이상 지났으면 드래그 시작
10977
+ if (deltaX > 5 || deltaY > 5 || deltaTime > 200) {
10978
+ setIsDragging(true);
10979
+ }
10980
+ }
10981
+ if (!isDragging || !dragStartRef.current)
10982
+ return;
10983
+ e.preventDefault();
10984
+ const x = e.pageX - tabListRef.current.offsetLeft;
10985
+ const walk = (x - dragStartRef.current.x) * 2; // 스크롤 속도 조절
10986
+ tabListRef.current.scrollLeft = dragStartRef.current.scrollLeft - walk;
10987
+ }, [isDragging]);
10988
+ const handleMouseUp = React.useCallback(() => {
10989
+ setIsDragging(false);
10990
+ dragStartRef.current = null;
10991
+ clickStartRef.current = null;
10992
+ }, []);
10993
+ const handleMouseLeave = React.useCallback(() => {
10994
+ setIsDragging(false);
10995
+ dragStartRef.current = null;
10996
+ clickStartRef.current = null;
10997
+ }, []);
10998
+ // 터치 이벤트 핸들러들
10999
+ const handleTouchStart = React.useCallback((e) => {
11000
+ if (orientation !== 'horizontal' || !tabListRef.current)
11001
+ return;
11002
+ const touch = e.touches[0];
11003
+ // 클릭 시작 위치와 시간 기록
11004
+ clickStartRef.current = {
11005
+ x: touch.pageX,
11006
+ y: touch.pageY,
11007
+ time: Date.now()
11008
+ };
11009
+ dragStartRef.current = {
11010
+ x: touch.pageX - tabListRef.current.offsetLeft,
11011
+ scrollLeft: tabListRef.current.scrollLeft
11012
+ };
11013
+ }, [orientation]);
11014
+ const handleTouchMove = React.useCallback((e) => {
11015
+ if (!dragStartRef.current || !tabListRef.current)
11016
+ return;
11017
+ // 아직 드래그가 시작되지 않았다면 드래그 시작 여부 판단
11018
+ if (!isDragging && clickStartRef.current) {
11019
+ const touch = e.touches[0];
11020
+ const deltaX = Math.abs(touch.pageX - clickStartRef.current.x);
11021
+ const deltaY = Math.abs(touch.pageY - clickStartRef.current.y);
11022
+ const deltaTime = Date.now() - clickStartRef.current.time;
11023
+ // 5px 이상 이동하거나 200ms 이상 지났으면 드래그 시작
11024
+ if (deltaX > 5 || deltaY > 5 || deltaTime > 200) {
11025
+ setIsDragging(true);
11026
+ }
11027
+ }
11028
+ if (!isDragging || !dragStartRef.current)
11029
+ return;
11030
+ e.preventDefault();
11031
+ const touch = e.touches[0];
11032
+ const x = touch.pageX - tabListRef.current.offsetLeft;
11033
+ const walk = (x - dragStartRef.current.x) * 2; // 스크롤 속도 조절
11034
+ tabListRef.current.scrollLeft = dragStartRef.current.scrollLeft - walk;
11035
+ }, [isDragging]);
11036
+ const handleTouchEnd = React.useCallback(() => {
11037
+ setIsDragging(false);
11038
+ dragStartRef.current = null;
11039
+ clickStartRef.current = null;
11040
+ }, []);
11041
+ // 드래그 이벤트 리스너 등록/해제
11042
+ React.useEffect(() => {
11043
+ if (isDragging) {
11044
+ document.addEventListener('mousemove', handleMouseMove);
11045
+ document.addEventListener('mouseup', handleMouseUp);
11046
+ document.addEventListener('mouseleave', handleMouseLeave);
11047
+ document.addEventListener('touchmove', handleTouchMove, { passive: false });
11048
+ document.addEventListener('touchend', handleTouchEnd);
11049
+ }
11050
+ return () => {
11051
+ document.removeEventListener('mousemove', handleMouseMove);
11052
+ document.removeEventListener('mouseup', handleMouseUp);
11053
+ document.removeEventListener('mouseleave', handleMouseLeave);
11054
+ document.removeEventListener('touchmove', handleTouchMove);
11055
+ document.removeEventListener('touchend', handleTouchEnd);
11056
+ };
11057
+ }, [isDragging, handleMouseMove, handleMouseUp, handleMouseLeave, handleTouchMove, handleTouchEnd]);
10942
11058
  const activeTab = items.find(item => item.id === activeTabId);
10943
11059
  items.findIndex(item => item.id === activeTabId);
10944
11060
  const classes = clsx('designbase-tabs', `designbase-tabs--${orientation}`, `designbase-tabs--${size}`, `designbase-tabs--${variant}`, {
@@ -10946,8 +11062,9 @@
10946
11062
  }, className);
10947
11063
  const tabListClasses = clsx('designbase-tabs__list', `designbase-tabs__list--${orientation}`, {
10948
11064
  'designbase-tabs__list--full-width': fullWidth,
11065
+ 'designbase-tabs__list--dragging': isDragging,
10949
11066
  });
10950
- return (jsxRuntime.jsxs("div", { className: classes, ...props, children: [jsxRuntime.jsx("div", { ref: tabListRef, className: tabListClasses, role: "tablist", "aria-orientation": orientation, "aria-label": "\uD0ED \uBAA9\uB85D", children: items.map((item, index) => {
11067
+ return (jsxRuntime.jsxs("div", { className: classes, ...props, children: [jsxRuntime.jsx("div", { ref: tabListRef, className: tabListClasses, role: "tablist", "aria-orientation": orientation, "aria-label": "\uD0ED \uBAA9\uB85D", onMouseDown: handleMouseDown, onTouchStart: handleTouchStart, children: items.map((item, index) => {
10951
11068
  const isSelected = item.id === activeTabId;
10952
11069
  const isFocused = item.id === focusedTabId;
10953
11070
  const isDisabled = item.disabled;