@beydesign/storybook 0.2.18 → 0.2.19

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.
@@ -32,25 +32,43 @@ export const TabMenu = ({ tabs, activeTab = 0, onTabChange, size = TabMenuSize.m
32
32
  const tabRefs = useRef([]);
33
33
  const [indicator, setIndicator] = useState(null);
34
34
  useLayoutEffect(() => {
35
+ const container = containerRef.current;
36
+ if (!container)
37
+ return;
35
38
  const measure = () => {
36
- const container = containerRef.current;
37
39
  const tab = tabRefs.current[activeTab];
38
- if (!container || !tab)
40
+ if (!tab)
39
41
  return;
40
- const containerRect = container.getBoundingClientRect();
41
- const tabRect = tab.getBoundingClientRect();
42
+ // Use offset* rather than getBoundingClientRect deltas: they are relative
43
+ // to the container's padding box, which is exactly the origin an absolutely
44
+ // positioned child (the indicator) is laid out from. Bounding-rect deltas
45
+ // would include the container's border and push the highlight 1px off.
42
46
  setIndicator({
43
- left: tabRect.left - containerRect.left,
44
- top: tabRect.top - containerRect.top,
45
- width: tabRect.width,
46
- height: tabRect.height,
47
+ left: tab.offsetLeft,
48
+ top: tab.offsetTop,
49
+ width: tab.offsetWidth,
50
+ height: tab.offsetHeight,
47
51
  });
48
52
  };
49
53
  measure();
50
- window.addEventListener('resize', measure);
51
- return () => window.removeEventListener('resize', measure);
54
+ // Re-measure whenever the container or a tab changes size (e.g. responsive
55
+ // reflow) so the highlight tracks the active tab.
56
+ const resizeObserver = new ResizeObserver(measure);
57
+ resizeObserver.observe(container);
58
+ tabRefs.current.forEach((tab) => tab && resizeObserver.observe(tab));
59
+ // Text metrics — and therefore tab widths — change when the fallback font is
60
+ // swapped for Figtree, so re-measure once web fonts have finished loading.
61
+ let cancelled = false;
62
+ document.fonts?.ready.then(() => {
63
+ if (!cancelled)
64
+ measure();
65
+ });
66
+ return () => {
67
+ cancelled = true;
68
+ resizeObserver.disconnect();
69
+ };
52
70
  }, [activeTab, size, showDividers, tabs]);
53
- return (_jsxs(Box, { ref: containerRef, "data-testid": testId, position: 'relative', display: 'inline-flex', flexDirection: 'row', alignItems: 'center', gap: tokens.containerGap, padding: tokens.containerPadding, bgcolor: 'var(--color-background-bg-component)', border: '1px solid var(--color-border-border-component)', borderRadius: 'var(--spacing-tokens-size-in-px-radius-radius-md)', sx: style, children: [indicator && (_jsx(Box, { "aria-hidden": true, position: 'absolute', bgcolor: 'var(--color-background-bg-brand-transparent)', borderRadius: tokens.tabRadius, sx: {
71
+ return (_jsxs(Box, { ref: containerRef, "data-testid": testId, position: 'relative', display: 'inline-flex', flexDirection: 'row', alignItems: 'center', gap: tokens.containerGap, padding: tokens.containerPadding, bgcolor: 'var(--color-background-bg-component)', border: '1px solid var(--color-border-border-component)', borderRadius: 'var(--spacing-tokens-size-in-px-radius-radius-md)', sx: { boxSizing: 'border-box', ...style }, children: [indicator && (_jsx(Box, { "aria-hidden": true, position: 'absolute', bgcolor: 'var(--color-background-bg-brand-transparent)', borderRadius: tokens.tabRadius, sx: {
54
72
  left: 0,
55
73
  top: 0,
56
74
  width: indicator.width,
@@ -67,6 +85,7 @@ export const TabMenu = ({ tabs, activeTab = 0, onTabChange, size = TabMenuSize.m
67
85
  return (_jsxs(React.Fragment, { children: [showDividers && index > 0 && (_jsx(Box, { width: '1px', height: tokens.dividerHeight, bgcolor: 'var(--color-border-border-divider)', flexShrink: 0, sx: { zIndex: 1 } })), _jsx(Box, { ref: (el) => {
68
86
  tabRefs.current[index] = el;
69
87
  }, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', position: 'relative', flexShrink: 0, height: tokens.tabHeight, paddingX: 'var(--spacing-tokens-size-in-px-spacing-spacing-4xl)', paddingY: tokens.tabPaddingY, borderRadius: tokens.tabRadius, onClick: onTabChange ? () => onTabChange(index) : undefined, sx: {
88
+ boxSizing: 'border-box',
70
89
  zIndex: 1,
71
90
  cursor: onTabChange ? 'pointer' : 'default',
72
91
  '&:hover': onTabChange && !isActive
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@beydesign/storybook",
3
3
  "private": false,
4
- "version": "0.2.18",
4
+ "version": "0.2.19",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",