@box/blueprint-web 18.4.0 → 18.5.1

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.
@@ -1,8 +1,13 @@
1
- import { jsx } from 'react/jsx-runtime';
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { TabList as TabList$1 } from '@ariakit/react';
3
3
  import clsx from 'clsx';
4
- import { forwardRef } from 'react';
4
+ import { forwardRef, useRef } from 'react';
5
+ import '../../blueprint-configuration-context/blueprint-configuration-context.js';
6
+ import '../../blueprint-configuration-context/consts.js';
7
+ import { useBlueprintConfiguration } from '../../blueprint-configuration-context/useBlueprintConfiguration.js';
8
+ import { useForkRef } from '../../utils/useForkRef.js';
5
9
  import styles from './tabs.module.js';
10
+ import { useTabIndicatorStyle } from './use-tab-indicator.js';
6
11
  import { useTabs } from './use-tabs.js';
7
12
 
8
13
  const TabList = /*#__PURE__*/forwardRef(function TabList(props, ref) {
@@ -10,19 +15,40 @@ const TabList = /*#__PURE__*/forwardRef(function TabList(props, ref) {
10
15
  className,
11
16
  variant = 'default',
12
17
  containerClassname,
18
+ children,
13
19
  ...rest
14
20
  } = props;
15
21
  const tab = useTabs();
22
+ const listRef = useRef(null);
23
+ const {
24
+ componentsWithAnimationEnabled
25
+ } = useBlueprintConfiguration();
26
+ const isAnimationEnabled = componentsWithAnimationEnabled.includes('Tabs');
27
+ const selectedTabElement = tab?.useState(state => state.items.find(item => item.id === state.selectedId)?.element ?? null);
28
+ const indicatorStyle = useTabIndicatorStyle({
29
+ enabled: isAnimationEnabled,
30
+ listRef,
31
+ selectedTabElement
32
+ });
33
+ const listRefs = useForkRef(ref, listRef);
16
34
  if (!tab) {
17
35
  throw new Error('TabList must be wrapped in a Tabs component');
18
36
  }
19
37
  return jsx("div", {
20
38
  className: clsx(styles.tabsListContainer, containerClassname),
21
- children: jsx(TabList$1, {
39
+ children: jsxs(TabList$1, {
22
40
  ...rest,
23
- ref: ref,
41
+ ref: listRefs,
24
42
  className: clsx(variant === 'contentSwitcher' ? styles.contentSwitchTabList : styles.tabList, className),
25
- store: tab
43
+ "data-bp-animated": isAnimationEnabled ? 'true' : 'false',
44
+ store: tab,
45
+ children: [isAnimationEnabled && indicatorStyle ? jsx("div", {
46
+ "aria-hidden": "true",
47
+ className: styles.tabIndicator,
48
+ "data-bp-tab-indicator": "",
49
+ role: "presentation",
50
+ style: indicatorStyle
51
+ }) : null, children]
26
52
  })
27
53
  });
28
54
  });
@@ -1,4 +1,4 @@
1
1
  import '../../index.css';
2
- var styles = {"hiddenWidthSetter":"bp_tabs_module_hiddenWidthSetter--22ec8","contentSwitchTabList":"bp_tabs_module_contentSwitchTabList--22ec8","contentSwitchTab":"bp_tabs_module_contentSwitchTab--22ec8","tabsListContainer":"bp_tabs_module_tabsListContainer--22ec8","tabList":"bp_tabs_module_tabList--22ec8","tabSeparator":"bp_tabs_module_tabSeparator--22ec8","tab":"bp_tabs_module_tab--22ec8"};
2
+ var styles = {"hiddenWidthSetter":"bp_tabs_module_hiddenWidthSetter--13d72","contentSwitchTabList":"bp_tabs_module_contentSwitchTabList--13d72","contentSwitchTab":"bp_tabs_module_contentSwitchTab--13d72","tabIndicator":"bp_tabs_module_tabIndicator--13d72","tabsListContainer":"bp_tabs_module_tabsListContainer--13d72","tabList":"bp_tabs_module_tabList--13d72","tabSeparator":"bp_tabs_module_tabSeparator--13d72","tab":"bp_tabs_module_tab--13d72"};
3
3
 
4
4
  export { styles as default };
@@ -0,0 +1,17 @@
1
+ import { type CSSProperties, type RefObject } from 'react';
2
+ export type TabIndicatorStyle = Pick<CSSProperties, 'transform' | 'width'>;
3
+ /**
4
+ * Measures the selected tab and returns the sliding-indicator `transform` +
5
+ * `width`. `useContentSizeObserver` is a threshold/`data-large` helper, so
6
+ * ResizeObserver lives here: the list for container resize, the selected tab
7
+ * for label/size changes that do not change the list box.
8
+ *
9
+ * The indicator must be a child of the scrolling tab list (or subtract
10
+ * `scrollLeft`). `offsetLeft` is relative to that list and does not include
11
+ * scroll, so horizontal scroll stays correct without extra math.
12
+ */
13
+ export declare const useTabIndicatorStyle: ({ enabled, listRef, selectedTabElement, }: {
14
+ enabled: boolean;
15
+ listRef: RefObject<HTMLElement | null>;
16
+ selectedTabElement: HTMLElement | null | undefined;
17
+ }) => TabIndicatorStyle | undefined;
@@ -0,0 +1,62 @@
1
+ import { useState } from 'react';
2
+ import { useEnhancedEffect } from '../../utils/useEnhancedEffect.js';
3
+
4
+ /**
5
+ * Measures the selected tab and returns the sliding-indicator `transform` +
6
+ * `width`. `useContentSizeObserver` is a threshold/`data-large` helper, so
7
+ * ResizeObserver lives here: the list for container resize, the selected tab
8
+ * for label/size changes that do not change the list box.
9
+ *
10
+ * The indicator must be a child of the scrolling tab list (or subtract
11
+ * `scrollLeft`). `offsetLeft` is relative to that list and does not include
12
+ * scroll, so horizontal scroll stays correct without extra math.
13
+ */
14
+ const useTabIndicatorStyle = ({
15
+ enabled,
16
+ listRef,
17
+ selectedTabElement
18
+ }) => {
19
+ const [style, setStyle] = useState(undefined);
20
+ useEnhancedEffect(() => {
21
+ if (!enabled) {
22
+ setStyle(undefined);
23
+ return undefined;
24
+ }
25
+ const list = listRef.current;
26
+ const selectedTab = selectedTabElement ?? null;
27
+ const measure = () => {
28
+ if (!selectedTab) {
29
+ setStyle(undefined);
30
+ return;
31
+ }
32
+ const transform = `translateX(${selectedTab.offsetLeft}px)`;
33
+ const width = selectedTab.offsetWidth;
34
+ setStyle(previous => {
35
+ if (previous?.transform === transform && previous.width === width) {
36
+ return previous;
37
+ }
38
+ return {
39
+ transform,
40
+ width
41
+ };
42
+ });
43
+ };
44
+ measure();
45
+ if (typeof ResizeObserver === 'undefined') {
46
+ return undefined;
47
+ }
48
+ const observer = new ResizeObserver(measure);
49
+ if (list) {
50
+ observer.observe(list);
51
+ }
52
+ if (selectedTab) {
53
+ observer.observe(selectedTab);
54
+ }
55
+ return () => {
56
+ observer.disconnect();
57
+ };
58
+ }, [enabled, listRef, selectedTabElement]);
59
+ return style;
60
+ };
61
+
62
+ export { useTabIndicatorStyle };
@@ -1,7 +1,6 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { PencilCrossed, ChevronDown, Checkmark } from '@box/blueprint-web-assets/icons/Medium';
3
3
  import { bpSize030, bpIconIconOnLight } from '@box/blueprint-web-assets/tokens/tokens';
4
- import * as ScrollArea from '@radix-ui/react-scroll-area';
5
4
  import * as SelectPrimitive from '@radix-ui/react-select';
6
5
  import clsx from 'clsx';
7
6
  import { forwardRef, useEffect, useCallback, useLayoutEffect } from 'react';
@@ -244,19 +243,14 @@ const Content = /*#__PURE__*/forwardRef((props, forwardedRef) => {
244
243
  }),
245
244
  position: "popper",
246
245
  sideOffset: 8,
247
- children: jsx(ScrollArea.Root, {
248
- type: "auto",
249
- children: jsx(SelectPrimitive.Viewport, {
250
- asChild: true,
251
- className: styles.viewport,
252
- children: jsx(ScrollArea.Viewport, {
253
- asChild: truncateText,
254
- className: clsx({
255
- [styles.withTruncatedText]: truncateText
256
- }),
257
- children: children
258
- })
259
- })
246
+ children: jsx(SelectPrimitive.Viewport, {
247
+ className: clsx(styles.viewport, {
248
+ [styles.withTruncatedText]: truncateText
249
+ }),
250
+ style: {
251
+ flex: 'none'
252
+ },
253
+ children: children
260
254
  })
261
255
  })
262
256
  });
@@ -1,4 +1,4 @@
1
1
  import '../index.css';
2
- var styles = {"ellipsis":"bp_select_module_ellipsis--08722","container":"bp_select_module_container--08722","disabled":"bp_select_module_disabled--08722","label":"bp_select_module_label--08722","triggerBtn":"bp_select_module_triggerBtn--08722","triggerValue":"bp_select_module_triggerValue--08722","triggerLeftElement":"bp_select_module_triggerLeftElement--08722","readonly":"bp_select_module_readonly--08722","error":"bp_select_module_error--08722","iconWrapper":"bp_select_module_iconWrapper--08722","iconCaret":"bp_select_module_iconCaret--08722","iconPencilCrossed":"bp_select_module_iconPencilCrossed--08722","content":"bp_select_module_content--08722","viewport":"bp_select_module_viewport--08722","option":"bp_select_module_option--08722","secondaryText":"bp_select_module_secondaryText--08722","textWrapper":"bp_select_module_textWrapper--08722","leftElement":"bp_select_module_leftElement--08722","hasLeftElement":"bp_select_module_hasLeftElement--08722","indicator":"bp_select_module_indicator--08722","separator":"bp_select_module_separator--08722","withTruncatedText":"bp_select_module_withTruncatedText--08722"};
2
+ var styles = {"ellipsis":"bp_select_module_ellipsis--69358","container":"bp_select_module_container--69358","disabled":"bp_select_module_disabled--69358","label":"bp_select_module_label--69358","triggerBtn":"bp_select_module_triggerBtn--69358","triggerValue":"bp_select_module_triggerValue--69358","triggerLeftElement":"bp_select_module_triggerLeftElement--69358","readonly":"bp_select_module_readonly--69358","error":"bp_select_module_error--69358","iconWrapper":"bp_select_module_iconWrapper--69358","iconCaret":"bp_select_module_iconCaret--69358","iconPencilCrossed":"bp_select_module_iconPencilCrossed--69358","content":"bp_select_module_content--69358","viewport":"bp_select_module_viewport--69358","option":"bp_select_module_option--69358","secondaryText":"bp_select_module_secondaryText--69358","textWrapper":"bp_select_module_textWrapper--69358","leftElement":"bp_select_module_leftElement--69358","hasLeftElement":"bp_select_module_hasLeftElement--69358","indicator":"bp_select_module_indicator--69358","separator":"bp_select_module_separator--69358","withTruncatedText":"bp_select_module_withTruncatedText--69358"};
3
3
 
4
4
  export { styles as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/blueprint-web",
3
- "version": "18.4.0",
3
+ "version": "18.5.1",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "publishConfig": {
@@ -55,7 +55,7 @@
55
55
  "dependencies": {
56
56
  "@ariakit/react": "0.4.21",
57
57
  "@ariakit/react-core": "0.4.21",
58
- "@box/blueprint-web-assets": "^5.12.3",
58
+ "@box/blueprint-web-assets": "^5.12.5",
59
59
  "@internationalized/date": "^3.12.0",
60
60
  "@radix-ui/react-accordion": "1.1.2",
61
61
  "@radix-ui/react-checkbox": "1.0.4",
@@ -66,7 +66,6 @@
66
66
  "@radix-ui/react-focus-scope": "1.0.4",
67
67
  "@radix-ui/react-popover": "1.0.7",
68
68
  "@radix-ui/react-radio-group": "1.1.3",
69
- "@radix-ui/react-scroll-area": "1.0.5",
70
69
  "@radix-ui/react-select": "2.0.0",
71
70
  "@radix-ui/react-slider": "1.1.2",
72
71
  "@radix-ui/react-switch": "1.0.3",
@@ -86,7 +85,7 @@
86
85
  "devDependencies": {
87
86
  "@box/box-test-client": "^3.2.7",
88
87
  "@box/playwright-utils": "^2.8.5",
89
- "@box/storybook-utils": "^1.4.15",
88
+ "@box/storybook-utils": "^1.4.17",
90
89
  "@figma/code-connect": "1.4.4",
91
90
  "@playwright/test": "1.46.1",
92
91
  "@types/js-yaml": "^4.0.9",