@moving-walls/design-system 1.0.21 → 1.0.22

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.esm.js CHANGED
@@ -36303,15 +36303,17 @@ function formatDate(date) {
36303
36303
  var monthShort = monthNames[date.getMonth()];
36304
36304
  var day = String(date.getDate()).padStart(2, '0');
36305
36305
  var year = date.getFullYear();
36306
- // Replace longer tokens first using placeholders to avoid substring conflicts
36307
- // (e.g. 'MMM' contains 'MM', so naive chaining can break)
36306
+ // Use placeholders to avoid substring conflicts (MMM contains MM, yyyy contains yy)
36308
36307
  var result = format;
36309
- if (result.includes('MMM')) {
36310
- result = result.replace('MMM', monthShort);
36311
- } else {
36312
- result = result.replace('MM', month);
36313
- }
36314
- return result.replace('dd', day).replace('yyyy', String(year));
36308
+ result = result.replace('MMM', '\x01');
36309
+ result = result.replace('MM', '\x02');
36310
+ result = result.replace('dd', '\x03');
36311
+ result = result.replace('yyyy', '\x04');
36312
+ result = result.replace('\x01', monthShort);
36313
+ result = result.replace('\x02', month);
36314
+ result = result.replace('\x03', day);
36315
+ result = result.replace('\x04', String(year));
36316
+ return result;
36315
36317
  }
36316
36318
  function isSameDay(date1, date2) {
36317
36319
  if (!date1 || !date2) return false;
@@ -36338,7 +36340,7 @@ function CalendarMonth(_ref) {
36338
36340
  var weekDays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
36339
36341
  var firstDayOfMonth = new Date(currentMonth.getFullYear(), currentMonth.getMonth(), 1);
36340
36342
  var lastDayOfMonth = new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 0);
36341
- var firstDayOfWeek = firstDayOfMonth.getDay();
36343
+ var firstDayOfWeek = (firstDayOfMonth.getDay() + 6) % 7; // Convert to Monday-start (Mon=0, Sun=6)
36342
36344
  var daysInMonth = lastDayOfMonth.getDate();
36343
36345
  var days = [];
36344
36346
  // Previous month's trailing days
@@ -41294,9 +41296,7 @@ Table.Row = TableRow;
41294
41296
  Table.Head = TableHead;
41295
41297
  Table.Cell = TableCell;
41296
41298
 
41297
- var TooltipContext = /*#__PURE__*/createContext({
41298
- delayDuration: 0
41299
- });
41299
+ var PADDING = 8;
41300
41300
  function Tooltip(_ref2) {
41301
41301
  var content = _ref2.content,
41302
41302
  children = _ref2.children,
@@ -41307,42 +41307,126 @@ function Tooltip(_ref2) {
41307
41307
  _useState2 = _slicedToArray(_useState, 2),
41308
41308
  isVisible = _useState2[0],
41309
41309
  setIsVisible = _useState2[1];
41310
- var _useContext = useContext(TooltipContext);
41311
- _useContext.delayDuration;
41312
- var positionClasses = {
41313
- top: 'bottom-full left-1/2 transform -translate-x-1/2 mb-2',
41314
- bottom: 'top-full left-1/2 transform -translate-x-1/2 mt-2',
41315
- left: 'right-full top-1/2 transform -translate-y-1/2 mr-2',
41316
- right: 'left-full top-1/2 transform -translate-y-1/2 ml-2'
41310
+ var triggerRef = useRef(null);
41311
+ var tooltipRef = useRef(null);
41312
+ var _useState3 = useState(null),
41313
+ _useState4 = _slicedToArray(_useState3, 2),
41314
+ coords = _useState4[0],
41315
+ setCoords = _useState4[1];
41316
+ var _useState5 = useState(position),
41317
+ _useState6 = _slicedToArray(_useState5, 2),
41318
+ resolvedPosition = _useState6[0],
41319
+ setResolvedPosition = _useState6[1];
41320
+ useLayoutEffect(function () {
41321
+ if (!isVisible || !triggerRef.current || !tooltipRef.current) return;
41322
+ var triggerRect = triggerRef.current.getBoundingClientRect();
41323
+ var tooltipRect = tooltipRef.current.getBoundingClientRect();
41324
+ var vw = window.innerWidth;
41325
+ var vh = window.innerHeight;
41326
+ var top = 0;
41327
+ var left = 0;
41328
+ var resolved = position;
41329
+ // Calculate preferred position
41330
+ var calc = function calc(pos) {
41331
+ switch (pos) {
41332
+ case 'top':
41333
+ top = triggerRect.top - tooltipRect.height - PADDING;
41334
+ left = triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;
41335
+ break;
41336
+ case 'bottom':
41337
+ top = triggerRect.bottom + PADDING;
41338
+ left = triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;
41339
+ break;
41340
+ case 'left':
41341
+ top = triggerRect.top + triggerRect.height / 2 - tooltipRect.height / 2;
41342
+ left = triggerRect.left - tooltipRect.width - PADDING;
41343
+ break;
41344
+ case 'right':
41345
+ top = triggerRect.top + triggerRect.height / 2 - tooltipRect.height / 2;
41346
+ left = triggerRect.right + PADDING;
41347
+ break;
41348
+ }
41349
+ };
41350
+ calc(position);
41351
+ // Flip if overflowing viewport
41352
+ if (position === 'top' && top < PADDING) {
41353
+ resolved = 'bottom';
41354
+ calc('bottom');
41355
+ } else if (position === 'bottom' && top + tooltipRect.height > vh - PADDING) {
41356
+ resolved = 'top';
41357
+ calc('top');
41358
+ } else if (position === 'left' && left < PADDING) {
41359
+ resolved = 'right';
41360
+ calc('right');
41361
+ } else if (position === 'right' && left + tooltipRect.width > vw - PADDING) {
41362
+ resolved = 'left';
41363
+ calc('left');
41364
+ }
41365
+ // Clamp horizontal to stay within viewport
41366
+ if (left < PADDING) left = PADDING;
41367
+ if (left + tooltipRect.width > vw - PADDING) left = vw - PADDING - tooltipRect.width;
41368
+ // Clamp vertical
41369
+ if (top < PADDING) top = PADDING;
41370
+ if (top + tooltipRect.height > vh - PADDING) top = vh - PADDING - tooltipRect.height;
41371
+ setCoords({
41372
+ top: top,
41373
+ left: left
41374
+ });
41375
+ setResolvedPosition(resolved);
41376
+ }, [isVisible, position]);
41377
+ var show = useCallback(function () {
41378
+ return setIsVisible(true);
41379
+ }, []);
41380
+ var hide = useCallback(function () {
41381
+ setIsVisible(false);
41382
+ setCoords(null);
41383
+ }, []);
41384
+ // Arrow positioning relative to tooltip
41385
+ var arrowStyle = function arrowStyle() {
41386
+ if (!triggerRef.current || !tooltipRef.current || !coords) return {};
41387
+ var triggerRect = triggerRef.current.getBoundingClientRect();
41388
+ var tooltipRect = tooltipRef.current.getBoundingClientRect();
41389
+ if (resolvedPosition === 'top' || resolvedPosition === 'bottom') {
41390
+ var arrowLeft = triggerRect.left + triggerRect.width / 2 - coords.left - 4;
41391
+ return {
41392
+ left: Math.max(8, Math.min(arrowLeft, tooltipRect.width - 8))
41393
+ };
41394
+ }
41395
+ var arrowTop = triggerRect.top + triggerRect.height / 2 - coords.top - 4;
41396
+ return {
41397
+ top: Math.max(8, Math.min(arrowTop, tooltipRect.height - 8))
41398
+ };
41317
41399
  };
41318
41400
  var arrowClasses = {
41319
- top: 'top-full left-1/2 transform -translate-x-1/2 border-l-transparent border-r-transparent border-b-transparent border-t-white',
41320
- bottom: 'bottom-full left-1/2 transform -translate-x-1/2 border-l-transparent border-r-transparent border-t-transparent border-b-white',
41321
- left: 'left-full top-1/2 transform -translate-y-1/2 border-t-transparent border-b-transparent border-r-transparent border-l-white',
41322
- right: 'right-full top-1/2 transform -translate-y-1/2 border-t-transparent border-b-transparent border-l-transparent border-r-white'
41401
+ top: 'absolute top-full border-l-transparent border-r-transparent border-b-transparent border-t-white',
41402
+ bottom: 'absolute bottom-full border-l-transparent border-r-transparent border-t-transparent border-b-white',
41403
+ left: 'absolute left-full border-t-transparent border-b-transparent border-r-transparent border-l-white',
41404
+ right: 'absolute right-full border-t-transparent border-b-transparent border-l-transparent border-r-white'
41323
41405
  };
41324
41406
  return jsxs("div", {
41325
41407
  className: "relative inline-block",
41408
+ ref: triggerRef,
41326
41409
  children: [jsx("div", {
41327
- onMouseEnter: function onMouseEnter() {
41328
- return setIsVisible(true);
41329
- },
41330
- onMouseLeave: function onMouseLeave() {
41331
- return setIsVisible(false);
41332
- },
41333
- onFocus: function onFocus() {
41334
- return setIsVisible(true);
41335
- },
41336
- onBlur: function onBlur() {
41337
- return setIsVisible(false);
41338
- },
41410
+ onMouseEnter: show,
41411
+ onMouseLeave: hide,
41412
+ onFocus: show,
41413
+ onBlur: hide,
41339
41414
  children: children
41340
- }), isVisible && jsxs("div", {
41341
- className: clsx('absolute z-50 px-2 py-1 text-sm text-mw-neutral-500 bg-white border border-mw-neutral-100 rounded-md whitespace-nowrap shadow-sm', positionClasses[position], className),
41415
+ }), isVisible && /*#__PURE__*/createPortal(jsxs("div", {
41416
+ ref: tooltipRef,
41417
+ style: coords ? {
41418
+ top: coords.top,
41419
+ left: coords.left
41420
+ } : {
41421
+ top: -9999,
41422
+ left: -9999
41423
+ },
41424
+ className: clsx('fixed z-[9999] px-2 py-1 text-sm text-mw-neutral-500 bg-white border border-mw-neutral-100 rounded-md shadow-sm max-w-xs whitespace-normal', className),
41342
41425
  children: [content, jsx("div", {
41343
- className: clsx('absolute w-0 h-0 border-4', arrowClasses[position])
41426
+ className: clsx('w-0 h-0 border-4', arrowClasses[resolvedPosition]),
41427
+ style: arrowStyle()
41344
41428
  })]
41345
- })]
41429
+ }), document.body)]
41346
41430
  });
41347
41431
  }
41348
41432