@designbasekorea/ui 0.2.37 → 0.2.39

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
@@ -11123,6 +11123,8 @@
11123
11123
  const [activeTabId, setActiveTabId] = React.useState(selectedId ?? defaultSelectedId ?? items[0]?.id ?? '');
11124
11124
  const [focusedTabId, setFocusedTabId] = React.useState('');
11125
11125
  const [isDragging, setIsDragging] = React.useState(false);
11126
+ const [isMouseDown, setIsMouseDown] = React.useState(false);
11127
+ const [showRightGradient, setShowRightGradient] = React.useState(false);
11126
11128
  const tabListRef = React.useRef(null);
11127
11129
  const tabRefs = React.useRef(new Map());
11128
11130
  const dragStartRef = React.useRef(null);
@@ -11133,6 +11135,29 @@
11133
11135
  setActiveTabId(selectedId);
11134
11136
  }
11135
11137
  }, [selectedId]);
11138
+ // 스크롤 가능 여부 감지
11139
+ React.useEffect(() => {
11140
+ const checkScrollable = () => {
11141
+ if (tabListRef.current) {
11142
+ const isScrollable = tabListRef.current.scrollWidth > tabListRef.current.clientWidth;
11143
+ const isScrolledToEnd = tabListRef.current.scrollLeft + tabListRef.current.clientWidth >=
11144
+ tabListRef.current.scrollWidth - 5; // 5px 여유
11145
+ setShowRightGradient(isScrollable && !isScrolledToEnd);
11146
+ }
11147
+ };
11148
+ checkScrollable();
11149
+ window.addEventListener('resize', checkScrollable);
11150
+ const listElement = tabListRef.current;
11151
+ if (listElement) {
11152
+ listElement.addEventListener('scroll', checkScrollable);
11153
+ }
11154
+ return () => {
11155
+ window.removeEventListener('resize', checkScrollable);
11156
+ if (listElement) {
11157
+ listElement.removeEventListener('scroll', checkScrollable);
11158
+ }
11159
+ };
11160
+ }, [items]);
11136
11161
  // 키보드 네비게이션
11137
11162
  const handleKeyDown = React.useCallback((event, currentTabId) => {
11138
11163
  const currentIndex = items.findIndex(item => item.id === currentTabId);
@@ -11227,6 +11252,7 @@
11227
11252
  x: e.pageX - tabListRef.current.offsetLeft,
11228
11253
  scrollLeft: tabListRef.current.scrollLeft
11229
11254
  };
11255
+ setIsMouseDown(true);
11230
11256
  }, [orientation]);
11231
11257
  const handleMouseMove = React.useCallback((e) => {
11232
11258
  if (!dragStartRef.current || !tabListRef.current)
@@ -11250,11 +11276,13 @@
11250
11276
  }, [isDragging]);
11251
11277
  const handleMouseUp = React.useCallback(() => {
11252
11278
  setIsDragging(false);
11279
+ setIsMouseDown(false);
11253
11280
  dragStartRef.current = null;
11254
11281
  clickStartRef.current = null;
11255
11282
  }, []);
11256
11283
  const handleMouseLeave = React.useCallback(() => {
11257
11284
  setIsDragging(false);
11285
+ setIsMouseDown(false);
11258
11286
  dragStartRef.current = null;
11259
11287
  clickStartRef.current = null;
11260
11288
  }, []);
@@ -11273,6 +11301,7 @@
11273
11301
  x: touch.pageX - tabListRef.current.offsetLeft,
11274
11302
  scrollLeft: tabListRef.current.scrollLeft
11275
11303
  };
11304
+ setIsMouseDown(true);
11276
11305
  }, [orientation]);
11277
11306
  const handleTouchMove = React.useCallback((e) => {
11278
11307
  if (!dragStartRef.current || !tabListRef.current)
@@ -11298,12 +11327,13 @@
11298
11327
  }, [isDragging]);
11299
11328
  const handleTouchEnd = React.useCallback(() => {
11300
11329
  setIsDragging(false);
11330
+ setIsMouseDown(false);
11301
11331
  dragStartRef.current = null;
11302
11332
  clickStartRef.current = null;
11303
11333
  }, []);
11304
11334
  // 드래그 이벤트 리스너 등록/해제
11305
11335
  React.useEffect(() => {
11306
- if (isDragging) {
11336
+ if (isMouseDown) {
11307
11337
  document.addEventListener('mousemove', handleMouseMove);
11308
11338
  document.addEventListener('mouseup', handleMouseUp);
11309
11339
  document.addEventListener('mouseleave', handleMouseLeave);
@@ -11317,7 +11347,7 @@
11317
11347
  document.removeEventListener('touchmove', handleTouchMove);
11318
11348
  document.removeEventListener('touchend', handleTouchEnd);
11319
11349
  };
11320
- }, [isDragging, handleMouseMove, handleMouseUp, handleMouseLeave, handleTouchMove, handleTouchEnd]);
11350
+ }, [isMouseDown, handleMouseMove, handleMouseUp, handleMouseLeave, handleTouchMove, handleTouchEnd]);
11321
11351
  const activeTab = items.find(item => item.id === activeTabId);
11322
11352
  items.findIndex(item => item.id === activeTabId);
11323
11353
  const classes = clsx('designbase-tabs', `designbase-tabs--${orientation}`, `designbase-tabs--${size}`, `designbase-tabs--${variant}`, {
@@ -11326,6 +11356,7 @@
11326
11356
  const tabListClasses = clsx('designbase-tabs__list', `designbase-tabs__list--${orientation}`, {
11327
11357
  'designbase-tabs__list--full-width': fullWidth,
11328
11358
  'designbase-tabs__list--dragging': isDragging,
11359
+ 'designbase-tabs__list--show-gradient': showRightGradient,
11329
11360
  });
11330
11361
  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) => {
11331
11362
  const isSelected = item.id === activeTabId;
@@ -11335,6 +11366,7 @@
11335
11366
  'designbase-tabs__tab--selected': isSelected,
11336
11367
  'designbase-tabs__tab--focused': isFocused,
11337
11368
  'designbase-tabs__tab--disabled': isDisabled,
11369
+ 'designbase-tabs__tab--dragging': isDragging,
11338
11370
  });
11339
11371
  return (jsxRuntime.jsxs("button", { ref: (el) => {
11340
11372
  if (el) {
@@ -11343,7 +11375,7 @@
11343
11375
  else {
11344
11376
  tabRefs.current.delete(item.id);
11345
11377
  }
11346
- }, className: tabClasses, role: "tab", "aria-selected": isSelected, "aria-disabled": isDisabled, "aria-controls": `panel-${item.id}`, id: `tab-${item.id}`, tabIndex: isSelected ? 0 : -1, disabled: isDisabled, onClick: () => handleTabSelect(item.id), onKeyDown: (e) => handleKeyDown(e, item.id), onFocus: () => handleTabFocus(item.id), onBlur: handleTabBlur, children: [item.icon && (jsxRuntime.jsx("span", { className: "designbase-tabs__tab-icon", children: jsxRuntime.jsx(item.icon, { size: size === 's' ? 16 : size === 'l' ? 20 : 18 }) })), jsxRuntime.jsx("span", { className: "designbase-tabs__tab-label", children: item.label })] }, item.id));
11378
+ }, className: tabClasses, role: "tab", "aria-selected": isSelected, "aria-disabled": isDisabled, "aria-controls": `panel-${item.id}`, id: `tab-${item.id}`, tabIndex: isSelected ? 0 : -1, disabled: isDisabled, onMouseDown: handleMouseDown, onTouchStart: handleTouchStart, onClick: () => handleTabSelect(item.id), onKeyDown: (e) => handleKeyDown(e, item.id), onFocus: () => handleTabFocus(item.id), onBlur: handleTabBlur, children: [item.icon && (jsxRuntime.jsx("span", { className: "designbase-tabs__tab-icon", children: jsxRuntime.jsx(item.icon, { size: size === 's' ? 16 : size === 'l' ? 20 : 18 }) })), jsxRuntime.jsx("span", { className: "designbase-tabs__tab-label", children: item.label })] }, item.id));
11347
11379
  }) }), activeTab && (jsxRuntime.jsx("div", { className: "designbase-tabs__panel", role: "tabpanel", id: `panel-${activeTab.id}`, "aria-labelledby": `tab-${activeTab.id}`, tabIndex: 0, children: activeTab.content }))] }));
11348
11380
  };
11349
11381
  Tabs.displayName = 'Tabs';