@box/blueprint-web 18.11.1 → 19.1.0
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/THIRD_PARTY_LICENSES +0 -612
- package/dist/lib-esm/components.css +98 -54
- package/dist/lib-esm/data-table/use-table-scroll-correction.js +44 -3
- package/dist/lib-esm/index.css +98 -54
- package/dist/lib-esm/list-item/index.d.ts +3 -3
- package/dist/lib-esm/list-item/list-item.d.ts +3 -3
- package/dist/lib-esm/primitives/date-i18n-provider/date-i18n-provider.d.ts +1 -1
- package/dist/lib-esm/primitives/date-i18n-provider/date-i18n-provider.js +1 -1
- package/dist/lib-esm/primitives/tabs/default-tab.js +0 -25
- package/dist/lib-esm/primitives/tabs/tab-list.js +65 -7
- package/dist/lib-esm/primitives/tabs/tabs.module.js +1 -1
- package/dist/lib-esm/primitives/tabs/types.d.ts +4 -0
- package/dist/lib-esm/primitives/tabs/use-tab-list-overflow.d.ts +19 -0
- package/dist/lib-esm/primitives/tabs/use-tab-list-overflow.js +141 -0
- package/dist/lib-esm/util-components/list-checkbox/list-checkbox.d.ts +2 -1
- package/dist/lib-esm/util-components/list-checkbox/list-checkbox.js +14 -2
- package/dist/lib-esm/utils/keyboardUtils.js +1 -1
- package/package.json +8 -11
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type TabListOverflowPosition = 'start' | 'end' | 'intermediate' | 'none';
|
|
2
|
+
/**
|
|
3
|
+
* Scrolls the selected tab into view once overflow buttons have been measured.
|
|
4
|
+
* No-ops when the list does not overflow or the tab is already fully visible,
|
|
5
|
+
* so a selected tab that already fits does not shove earlier tabs off screen.
|
|
6
|
+
* The chevrons sit beside the scrollport, so the visible area is the tab list itself.
|
|
7
|
+
*/
|
|
8
|
+
export declare const scrollSelectedTabIntoView: (scrollableElement: HTMLElement, tabElement: HTMLElement) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Tracks whether a horizontally scrolling tab list is overflowing and exposes
|
|
11
|
+
* page-wise scroll actions for the overflow buttons.
|
|
12
|
+
* A mutation observer re-measures when tabs are added, removed, or replaced.
|
|
13
|
+
*/
|
|
14
|
+
export declare const useTabListOverflow: (scrollableElement: HTMLElement | null) => {
|
|
15
|
+
hasMeasuredOverflow: boolean;
|
|
16
|
+
overflowPosition: TabListOverflowPosition;
|
|
17
|
+
scrollToNextTabs: () => void;
|
|
18
|
+
scrollToPreviousTabs: () => void;
|
|
19
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { noop } from '../../utils/noop.js';
|
|
3
|
+
import { useEnhancedEffect } from '../../utils/useEnhancedEffect.js';
|
|
4
|
+
|
|
5
|
+
// Chromium can report fractional scroll values at the edges.
|
|
6
|
+
const EDGE_TOLERANCE_PX = 1;
|
|
7
|
+
// Each chevron click scrolls by a share of the visible width, with a floor for narrow lists.
|
|
8
|
+
const SCROLL_STEP_RATIO = 0.6;
|
|
9
|
+
const MIN_SCROLL_STEP_PX = 120;
|
|
10
|
+
const MAX_SCROLL_STEP_RATIO = 0.85;
|
|
11
|
+
// Matches the previous mount-scroll inset: focus outline (3) + outline offset (1) + tab padding (12).
|
|
12
|
+
const SELECTED_TAB_SCROLL_INSET_PX = 16;
|
|
13
|
+
const getOverflowPosition = ({
|
|
14
|
+
scrollLeft,
|
|
15
|
+
scrollWidth,
|
|
16
|
+
clientWidth
|
|
17
|
+
}) => {
|
|
18
|
+
const maxScroll = scrollWidth - clientWidth;
|
|
19
|
+
if (maxScroll <= EDGE_TOLERANCE_PX) {
|
|
20
|
+
return 'none';
|
|
21
|
+
}
|
|
22
|
+
if (scrollLeft <= EDGE_TOLERANCE_PX) {
|
|
23
|
+
return 'start';
|
|
24
|
+
}
|
|
25
|
+
if (scrollLeft >= maxScroll - EDGE_TOLERANCE_PX) {
|
|
26
|
+
return 'end';
|
|
27
|
+
}
|
|
28
|
+
return 'intermediate';
|
|
29
|
+
};
|
|
30
|
+
const scrollElementTo = (element, left) => {
|
|
31
|
+
if (typeof element.scrollTo === 'function') {
|
|
32
|
+
element.scrollTo({
|
|
33
|
+
behavior: 'instant',
|
|
34
|
+
left
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
element.scrollLeft = left;
|
|
39
|
+
};
|
|
40
|
+
const scrollElementBy = (element, left) => {
|
|
41
|
+
if (typeof element.scrollBy === 'function') {
|
|
42
|
+
element.scrollBy({
|
|
43
|
+
left
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
element.scrollLeft += left;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Scrolls the selected tab into view once overflow buttons have been measured.
|
|
51
|
+
* No-ops when the list does not overflow or the tab is already fully visible,
|
|
52
|
+
* so a selected tab that already fits does not shove earlier tabs off screen.
|
|
53
|
+
* The chevrons sit beside the scrollport, so the visible area is the tab list itself.
|
|
54
|
+
*/
|
|
55
|
+
const scrollSelectedTabIntoView = (scrollableElement, tabElement) => {
|
|
56
|
+
const maxScroll = scrollableElement.scrollWidth - scrollableElement.clientWidth;
|
|
57
|
+
if (maxScroll <= EDGE_TOLERANCE_PX) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const parentRect = scrollableElement.getBoundingClientRect();
|
|
61
|
+
const tabRect = tabElement.getBoundingClientRect();
|
|
62
|
+
const visibleStart = parentRect.left + SELECTED_TAB_SCROLL_INSET_PX;
|
|
63
|
+
const visibleEnd = parentRect.right - SELECTED_TAB_SCROLL_INSET_PX;
|
|
64
|
+
if (tabRect.left >= visibleStart - EDGE_TOLERANCE_PX && tabRect.right <= visibleEnd + EDGE_TOLERANCE_PX) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const delta = tabRect.left < visibleStart ? tabRect.left - visibleStart : tabRect.right - visibleEnd;
|
|
68
|
+
scrollElementTo(scrollableElement, scrollableElement.scrollLeft + delta);
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Tracks whether a horizontally scrolling tab list is overflowing and exposes
|
|
72
|
+
* page-wise scroll actions for the overflow buttons.
|
|
73
|
+
* A mutation observer re-measures when tabs are added, removed, or replaced.
|
|
74
|
+
*/
|
|
75
|
+
const useTabListOverflow = scrollableElement => {
|
|
76
|
+
const [overflowPosition, setOverflowPosition] = useState('none');
|
|
77
|
+
const [hasMeasuredOverflow, setHasMeasuredOverflow] = useState(false);
|
|
78
|
+
const scrollTabs = useCallback(direction => {
|
|
79
|
+
if (!scrollableElement) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const visibleWidth = scrollableElement.clientWidth;
|
|
83
|
+
const scrollAmount = Math.min(Math.max(visibleWidth * SCROLL_STEP_RATIO, MIN_SCROLL_STEP_PX), visibleWidth * MAX_SCROLL_STEP_RATIO);
|
|
84
|
+
// Omit `behavior` so the tab list's CSS `scroll-behavior` (and reduced-motion override) applies.
|
|
85
|
+
scrollElementBy(scrollableElement, direction * scrollAmount);
|
|
86
|
+
}, [scrollableElement]);
|
|
87
|
+
const scrollToPreviousTabs = useCallback(() => scrollTabs(-1), [scrollTabs]);
|
|
88
|
+
const scrollToNextTabs = useCallback(() => scrollTabs(1), [scrollTabs]);
|
|
89
|
+
useEnhancedEffect(() => {
|
|
90
|
+
if (!scrollableElement) {
|
|
91
|
+
setOverflowPosition('none');
|
|
92
|
+
setHasMeasuredOverflow(false);
|
|
93
|
+
return noop;
|
|
94
|
+
}
|
|
95
|
+
let animationFrame = null;
|
|
96
|
+
const updateOverflowPosition = () => setOverflowPosition(getOverflowPosition(scrollableElement));
|
|
97
|
+
const handleScroll = () => {
|
|
98
|
+
if (animationFrame !== null) {
|
|
99
|
+
cancelAnimationFrame(animationFrame);
|
|
100
|
+
}
|
|
101
|
+
animationFrame = requestAnimationFrame(updateOverflowPosition);
|
|
102
|
+
};
|
|
103
|
+
const resizeObserver = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(updateOverflowPosition);
|
|
104
|
+
const observeChildren = () => {
|
|
105
|
+
resizeObserver?.observe(scrollableElement);
|
|
106
|
+
for (const child of scrollableElement.children) {
|
|
107
|
+
resizeObserver?.observe(child);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
observeChildren();
|
|
111
|
+
const mutationObserver = typeof MutationObserver === 'undefined' ? undefined : new MutationObserver(() => {
|
|
112
|
+
resizeObserver?.disconnect();
|
|
113
|
+
observeChildren();
|
|
114
|
+
updateOverflowPosition();
|
|
115
|
+
});
|
|
116
|
+
mutationObserver?.observe(scrollableElement, {
|
|
117
|
+
childList: true
|
|
118
|
+
});
|
|
119
|
+
scrollableElement.addEventListener('scroll', handleScroll, {
|
|
120
|
+
passive: true
|
|
121
|
+
});
|
|
122
|
+
updateOverflowPosition();
|
|
123
|
+
setHasMeasuredOverflow(true);
|
|
124
|
+
return () => {
|
|
125
|
+
resizeObserver?.disconnect();
|
|
126
|
+
mutationObserver?.disconnect();
|
|
127
|
+
scrollableElement.removeEventListener('scroll', handleScroll);
|
|
128
|
+
if (animationFrame !== null) {
|
|
129
|
+
cancelAnimationFrame(animationFrame);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}, [scrollableElement]);
|
|
133
|
+
return {
|
|
134
|
+
hasMeasuredOverflow,
|
|
135
|
+
overflowPosition,
|
|
136
|
+
scrollToNextTabs,
|
|
137
|
+
scrollToPreviousTabs
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export { scrollSelectedTabIntoView, useTabListOverflow };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { type CheckboxProps } from 'react-aria-components';
|
|
1
|
+
import { type CheckboxProps, type KeyboardEvent } from 'react-aria-components';
|
|
2
2
|
export interface ListCheckboxProps extends CheckboxProps {
|
|
3
3
|
className?: string;
|
|
4
4
|
isDisabled?: boolean;
|
|
5
|
+
onKeyDown?: (event: KeyboardEvent) => void;
|
|
5
6
|
}
|
|
6
7
|
/**
|
|
7
8
|
* Based on React Aria Components `Checkbox`
|
|
@@ -2,7 +2,7 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
2
2
|
import { Checkmark } from '@box/blueprint-web-assets/icons/Fill';
|
|
3
3
|
import { Size3, IconIconOnDark } from '@box/blueprint-web-assets/tokens/tokens';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
|
-
import { forwardRef } from 'react';
|
|
5
|
+
import { forwardRef, useCallback } from 'react';
|
|
6
6
|
import { Checkbox } from 'react-aria-components';
|
|
7
7
|
import styles from './list-checkbox.module.js';
|
|
8
8
|
|
|
@@ -14,12 +14,24 @@ import styles from './list-checkbox.module.js';
|
|
|
14
14
|
* @see https://react-spectrum.adobe.com/react-aria/Checkbox.html
|
|
15
15
|
*/
|
|
16
16
|
const ListCheckbox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
17
|
+
const {
|
|
18
|
+
onKeyDown,
|
|
19
|
+
...rest
|
|
20
|
+
} = props;
|
|
21
|
+
// Prevent Enter from reaching the row and triggering the row's onAction.
|
|
22
|
+
const handleKeyDown = useCallback(event => {
|
|
23
|
+
onKeyDown?.(event);
|
|
24
|
+
if (event.key !== 'Enter') {
|
|
25
|
+
event.continuePropagation();
|
|
26
|
+
}
|
|
27
|
+
}, [onKeyDown]);
|
|
17
28
|
return jsx("div", {
|
|
18
29
|
className: clsx(styles.selection, props.className),
|
|
19
30
|
children: jsx(Checkbox, {
|
|
20
|
-
...
|
|
31
|
+
...rest,
|
|
21
32
|
ref: ref,
|
|
22
33
|
className: styles.checkbox,
|
|
34
|
+
onKeyDown: handleKeyDown,
|
|
23
35
|
slot: "selection",
|
|
24
36
|
children: ({
|
|
25
37
|
isSelected
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/blueprint-web",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "19.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"publishConfig": {
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@ariakit/react": "0.4.21",
|
|
56
56
|
"@ariakit/react-core": "0.4.21",
|
|
57
|
-
"@box/blueprint-web-assets": "^5.15.
|
|
58
|
-
"@internationalized/date": "^3.12.
|
|
57
|
+
"@box/blueprint-web-assets": "^5.15.4",
|
|
58
|
+
"@internationalized/date": "^3.12.4",
|
|
59
59
|
"@radix-ui/react-accordion": "1.1.2",
|
|
60
60
|
"@radix-ui/react-checkbox": "1.0.4",
|
|
61
61
|
"@radix-ui/react-collapsible": "1.0.3",
|
|
@@ -72,19 +72,16 @@
|
|
|
72
72
|
"@radix-ui/react-toggle-group": "1.0.4",
|
|
73
73
|
"@radix-ui/react-toolbar": "1.0.4",
|
|
74
74
|
"@radix-ui/react-tooltip": "1.0.7",
|
|
75
|
-
"@react-aria/i18n": "3.12.16",
|
|
76
|
-
"@react-aria/interactions": "3.27.1",
|
|
77
|
-
"@react-aria/utils": "3.33.1",
|
|
78
75
|
"clsx": "^1.2.1",
|
|
79
76
|
"color": "2.0.1",
|
|
80
|
-
"react-aria": "3.
|
|
81
|
-
"react-aria-components": "1.
|
|
77
|
+
"react-aria": "3.53.1",
|
|
78
|
+
"react-aria-components": "1.22.1",
|
|
82
79
|
"type-fest": "^3.2.0"
|
|
83
80
|
},
|
|
84
81
|
"devDependencies": {
|
|
85
82
|
"@box/box-test-client": "^3.2.7",
|
|
86
|
-
"@box/playwright-utils": "^
|
|
87
|
-
"@box/storybook-utils": "^1.4.
|
|
83
|
+
"@box/playwright-utils": "^3.10.0",
|
|
84
|
+
"@box/storybook-utils": "^1.4.38",
|
|
88
85
|
"@figma/code-connect": "1.4.4",
|
|
89
86
|
"@playwright/test": "1.46.1",
|
|
90
87
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -93,7 +90,7 @@
|
|
|
93
90
|
"msw": ">=2.2.9 <2.11.3",
|
|
94
91
|
"react": "^18.3.0",
|
|
95
92
|
"react-dom": "^18.3.0",
|
|
96
|
-
"react-stately": "
|
|
93
|
+
"react-stately": "3.51.0",
|
|
97
94
|
"tsx": "^4.16.5"
|
|
98
95
|
}
|
|
99
96
|
}
|