@telus-uds/components-base 4.0.0-alpha.1 → 4.0.0-alpha.2
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/CHANGELOG.md +28 -1
- package/lib/cjs/Footnote/FootnoteLink.js +18 -17
- package/lib/cjs/Progress/Progress.js +30 -5
- package/lib/cjs/Scroll/Scroll.js +472 -0
- package/lib/cjs/Scroll/ScrollContext.js +55 -0
- package/lib/cjs/Scroll/ScrollItem.js +106 -0
- package/lib/cjs/Scroll/ScrollProgress.js +100 -0
- package/lib/cjs/Scroll/dictionary.js +18 -0
- package/lib/cjs/index.js +14 -0
- package/lib/cjs/utils/animation/useAnimatedValue.js +46 -0
- package/lib/cjs/utils/children.js +2 -1
- package/lib/esm/Footnote/FootnoteLink.js +18 -17
- package/lib/esm/Progress/Progress.js +30 -5
- package/lib/esm/Scroll/Scroll.js +465 -0
- package/lib/esm/Scroll/ScrollContext.js +46 -0
- package/lib/esm/Scroll/ScrollItem.js +100 -0
- package/lib/esm/Scroll/ScrollProgress.js +93 -0
- package/lib/esm/Scroll/dictionary.js +12 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/utils/animation/useAnimatedValue.js +38 -0
- package/lib/esm/utils/children.js +2 -1
- package/lib/package.json +2 -2
- package/package.json +2 -2
- package/src/Footnote/FootnoteLink.jsx +17 -12
- package/src/Progress/Progress.jsx +22 -3
- package/src/Scroll/Scroll.jsx +483 -0
- package/src/Scroll/ScrollContext.jsx +39 -0
- package/src/Scroll/ScrollItem.jsx +87 -0
- package/src/Scroll/ScrollProgress.jsx +74 -0
- package/src/Scroll/dictionary.js +12 -0
- package/src/index.js +2 -0
- package/src/utils/animation/useAnimatedValue.js +35 -0
- package/src/utils/children.jsx +4 -1
- package/types/Scroll.d.ts +66 -0
- package/types/index.d.ts +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,36 @@
|
|
|
1
1
|
# Change Log - @telus-uds/components-base
|
|
2
2
|
|
|
3
|
-
This log was last generated on Fri,
|
|
3
|
+
This log was last generated on Fri, 17 Apr 2026 23:54:32 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 4.0.0-alpha.2
|
|
8
|
+
|
|
9
|
+
Fri, 17 Apr 2026 23:54:32 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- `Scroll`: add component (guillermo.peitzner@telus.com)
|
|
14
|
+
- Bump @telus-uds/system-theme-tokens to v5.0.0-alpha.2
|
|
15
|
+
|
|
16
|
+
### Patches
|
|
17
|
+
|
|
18
|
+
- `FootnoteLink`: fixed superscript text positioning on native to correctly align with surrounding text (josue.higueroscalderon@telus.com)
|
|
19
|
+
|
|
20
|
+
## 3.30.0
|
|
21
|
+
|
|
22
|
+
Thu, 16 Apr 2026 21:04:33 GMT
|
|
23
|
+
|
|
24
|
+
### Minor changes
|
|
25
|
+
|
|
26
|
+
- `Carousel`: Add `isVideo` prop to thumbnail navigation to display a play icon overlay on video thumbnails (josue.higueros@telus.com)
|
|
27
|
+
- `Scroll`: add component (guillermo.peitzner@telus.com)
|
|
28
|
+
- Bump @telus-uds/system-theme-tokens to v4.21.0
|
|
29
|
+
|
|
30
|
+
### Patches
|
|
31
|
+
|
|
32
|
+
- `FootnoteLink`: fixed superscript text positioning on native to correctly align with surrounding text (josue.higueroscalderon@telus.com)
|
|
33
|
+
|
|
7
34
|
## 4.0.0-alpha.1
|
|
8
35
|
|
|
9
36
|
Fri, 10 Apr 2026 17:20:02 GMT
|
|
@@ -22,28 +22,28 @@ var _useThemeTokens = require("../ThemeProvider/useThemeTokens");
|
|
|
22
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
23
23
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
24
|
const [selectProps, selectedSystemPropTypes] = (0, _selectSystemProps.selectSystemProps)([_htmlAttrs.htmlAttrs, _viewProps.viewProps]);
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const HALF_FONT_SIZE = 2;
|
|
26
|
+
const QUARTER_FONT_SIZE = 4;
|
|
27
|
+
const DEFAULT_LINE_HEIGHT = 1;
|
|
28
|
+
const LINE_HEIGHT_MULTIPLIER = 2;
|
|
27
29
|
const selectTextStyle = _ref => {
|
|
28
30
|
let {
|
|
29
31
|
fontSize,
|
|
30
32
|
lineHeight
|
|
31
33
|
} = _ref;
|
|
32
|
-
return {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
})
|
|
46
|
-
};
|
|
34
|
+
return _Platform.default.select({
|
|
35
|
+
native: {
|
|
36
|
+
fontSize: fontSize / HALF_FONT_SIZE,
|
|
37
|
+
lineHeight: fontSize,
|
|
38
|
+
position: 'relative',
|
|
39
|
+
top: -(fontSize * lineHeight) / HALF_FONT_SIZE
|
|
40
|
+
},
|
|
41
|
+
web: {
|
|
42
|
+
fontSize,
|
|
43
|
+
lineHeight: lineHeight !== DEFAULT_LINE_HEIGHT ? lineHeight : fontSize * LINE_HEIGHT_MULTIPLIER,
|
|
44
|
+
top: -fontSize / QUARTER_FONT_SIZE
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
47
|
};
|
|
48
48
|
const FootnoteLink = exports.FootnoteLink = /*#__PURE__*/_react.default.forwardRef((_ref2, ref) => {
|
|
49
49
|
let {
|
|
@@ -87,6 +87,7 @@ const FootnoteLink = exports.FootnoteLink = /*#__PURE__*/_react.default.forwardR
|
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
89
|
FootnoteLink.displayName = 'FootnoteLink';
|
|
90
|
+
FootnoteLink.__UDS_COMPONENT_NAME__ = 'FootnoteLink';
|
|
90
91
|
const copyShape = _propTypes.default.shape({
|
|
91
92
|
a11yLabel: _propTypes.default.string.isRequired
|
|
92
93
|
});
|
|
@@ -19,6 +19,8 @@ var _ProgressContext = require("./ProgressContext");
|
|
|
19
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
20
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
21
|
const [selectProps, selectedSystemPropTypes] = (0, _selectSystemProps.selectSystemProps)([_a11yProps.a11yProps, _viewProps.viewProps]);
|
|
22
|
+
const BORDER_SIDES = 2;
|
|
23
|
+
const CENTER_DIVISOR = 2;
|
|
22
24
|
const selectProgressStyles = _ref => {
|
|
23
25
|
let {
|
|
24
26
|
backgroundColor,
|
|
@@ -37,6 +39,21 @@ const selectProgressStyles = _ref => {
|
|
|
37
39
|
...(0, _styles.applyShadowToken)(shadow)
|
|
38
40
|
};
|
|
39
41
|
};
|
|
42
|
+
const selectBarWrapperStyles = _ref2 => {
|
|
43
|
+
let {
|
|
44
|
+
barHeight,
|
|
45
|
+
borderRadius,
|
|
46
|
+
borderWidth,
|
|
47
|
+
height
|
|
48
|
+
} = _ref2;
|
|
49
|
+
return {
|
|
50
|
+
height: barHeight,
|
|
51
|
+
width: '100%',
|
|
52
|
+
position: 'absolute',
|
|
53
|
+
top: (height - borderWidth * BORDER_SIDES - barHeight) / CENTER_DIVISOR,
|
|
54
|
+
borderRadius
|
|
55
|
+
};
|
|
56
|
+
};
|
|
40
57
|
|
|
41
58
|
/**
|
|
42
59
|
* The `Progress` is a container for displaying one or several `ProgressBar`s.
|
|
@@ -50,10 +67,11 @@ const selectProgressStyles = _ref => {
|
|
|
50
67
|
*
|
|
51
68
|
* - Use the following tokens to customize the appearance:
|
|
52
69
|
* - `backgroundColor` for the background color of the progress container,
|
|
70
|
+
* - `barHeight` to control the height of the progress bars displayed within the container,
|
|
53
71
|
* - `borderColor` to control the color of the border,
|
|
54
72
|
* - `borderRadius` for the rounded corners,
|
|
55
73
|
* - `borderWidth` to change the border width.
|
|
56
|
-
* - `height` to control the height of the progress
|
|
74
|
+
* - `height` to control the height of the progress bar container.
|
|
57
75
|
* - `shadow` to apply a box shadow to the progress bar container.
|
|
58
76
|
*
|
|
59
77
|
* ## Variants
|
|
@@ -74,16 +92,23 @@ const selectProgressStyles = _ref => {
|
|
|
74
92
|
* role.
|
|
75
93
|
*
|
|
76
94
|
*/
|
|
77
|
-
const Progress = exports.Progress = /*#__PURE__*/_react.default.forwardRef((
|
|
95
|
+
const Progress = exports.Progress = /*#__PURE__*/_react.default.forwardRef((_ref3, ref) => {
|
|
78
96
|
let {
|
|
79
97
|
children,
|
|
80
98
|
tokens,
|
|
81
99
|
variant,
|
|
82
100
|
...rest
|
|
83
|
-
} =
|
|
101
|
+
} = _ref3;
|
|
84
102
|
const themeTokens = (0, _useThemeTokens.useThemeTokens)('Progress', tokens, variant);
|
|
85
|
-
// Default to false (vertical layout) to preserve existing behavior and avoid breaking changes
|
|
86
103
|
const layers = variant?.layers ?? false;
|
|
104
|
+
const {
|
|
105
|
+
barHeight,
|
|
106
|
+
height
|
|
107
|
+
} = themeTokens;
|
|
108
|
+
const content = barHeight && barHeight !== height ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
109
|
+
style: selectBarWrapperStyles(themeTokens),
|
|
110
|
+
children: children
|
|
111
|
+
}) : children;
|
|
87
112
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ProgressContext.ProgressContext.Provider, {
|
|
88
113
|
value: {
|
|
89
114
|
layers
|
|
@@ -92,7 +117,7 @@ const Progress = exports.Progress = /*#__PURE__*/_react.default.forwardRef((_ref
|
|
|
92
117
|
ref: ref,
|
|
93
118
|
style: [staticStyles.progressContainer, selectProgressStyles(themeTokens)],
|
|
94
119
|
...selectProps(rest),
|
|
95
|
-
children:
|
|
120
|
+
children: content
|
|
96
121
|
})
|
|
97
122
|
});
|
|
98
123
|
});
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Scroll = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
|
|
10
|
+
var _Pressable = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Pressable"));
|
|
11
|
+
var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
|
|
12
|
+
var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
|
|
13
|
+
var _useThemeTokens = require("../ThemeProvider/useThemeTokens");
|
|
14
|
+
var _a11yProps = require("../utils/props/a11yProps");
|
|
15
|
+
var _copyPropTypes = require("../utils/props/copyPropTypes");
|
|
16
|
+
var _tokens = require("../utils/props/tokens");
|
|
17
|
+
var _selectSystemProps = require("../utils/props/selectSystemProps");
|
|
18
|
+
var _useCopy = require("../utils/useCopy");
|
|
19
|
+
var _useUniqueId = require("../utils/useUniqueId");
|
|
20
|
+
var _variantProp = require("../utils/props/variantProp");
|
|
21
|
+
var _viewProps = require("../utils/props/viewProps");
|
|
22
|
+
var _A11yText = require("../A11yText/A11yText");
|
|
23
|
+
var _ScrollViewEnd = require("../HorizontalScroll/ScrollViewEnd");
|
|
24
|
+
var _dictionary = require("./dictionary");
|
|
25
|
+
var _ScrollProgress = require("./ScrollProgress");
|
|
26
|
+
var _ScrollContext = require("./ScrollContext");
|
|
27
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
28
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
29
|
+
const [selectProps, selectedSystemPropTypes] = (0, _selectSystemProps.selectSystemProps)([_a11yProps.a11yProps, _viewProps.viewProps]);
|
|
30
|
+
const SCROLL_DESCRIPTION_PREFIX = 'scroll-description';
|
|
31
|
+
const KEY_ARROW_RIGHT = 'ArrowRight';
|
|
32
|
+
const KEY_ARROW_LEFT = 'ArrowLeft';
|
|
33
|
+
const KEY_SPACE = ' ';
|
|
34
|
+
const MAX_PERCENTAGE = 100;
|
|
35
|
+
const MIN_BAR_PERCENTAGE = 1;
|
|
36
|
+
const ROLE_REGION = 'region';
|
|
37
|
+
const ROLE_NONE = 'none';
|
|
38
|
+
const COMPONENT_NAME = 'Scroll';
|
|
39
|
+
const SCROLL_ITEM_SELECTOR = '[data-scroll-item]';
|
|
40
|
+
const TAB_INDEX = 0;
|
|
41
|
+
const INITIAL_DIMENSION = 0;
|
|
42
|
+
const HALF_DIVISOR = 2;
|
|
43
|
+
const selectPressableStyles = _ref => {
|
|
44
|
+
let {
|
|
45
|
+
progressHitAreaHeight,
|
|
46
|
+
progressSpacing
|
|
47
|
+
} = _ref;
|
|
48
|
+
return {
|
|
49
|
+
height: progressHitAreaHeight,
|
|
50
|
+
marginTop: progressSpacing
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
const selectThumbWrapperStyles = _ref2 => {
|
|
54
|
+
let {
|
|
55
|
+
thumbWidthPercent,
|
|
56
|
+
thumbPositionPercent
|
|
57
|
+
} = _ref2;
|
|
58
|
+
return {
|
|
59
|
+
width: `${thumbWidthPercent}%`,
|
|
60
|
+
marginLeft: `${thumbPositionPercent}%`
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const selectContainerA11yProps = _ref3 => {
|
|
64
|
+
let {
|
|
65
|
+
accessibilityLabel,
|
|
66
|
+
descriptionId,
|
|
67
|
+
handleKeyDown
|
|
68
|
+
} = _ref3;
|
|
69
|
+
return _Platform.default.OS === 'web' ? {
|
|
70
|
+
role: ROLE_REGION,
|
|
71
|
+
'aria-label': accessibilityLabel,
|
|
72
|
+
'aria-describedby': descriptionId,
|
|
73
|
+
tabIndex: TAB_INDEX,
|
|
74
|
+
onKeyDown: handleKeyDown
|
|
75
|
+
} : {
|
|
76
|
+
accessibilityRole: ROLE_NONE,
|
|
77
|
+
accessibilityLabel
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const selectScrollContentStyle = itemGap => ({
|
|
81
|
+
columnGap: itemGap
|
|
82
|
+
});
|
|
83
|
+
const calculateThumbWidth = _ref4 => {
|
|
84
|
+
let {
|
|
85
|
+
containerWidth,
|
|
86
|
+
contentWidth
|
|
87
|
+
} = _ref4;
|
|
88
|
+
if (contentWidth <= INITIAL_DIMENSION) return MAX_PERCENTAGE;
|
|
89
|
+
return Math.max(MIN_BAR_PERCENTAGE, Math.min(MAX_PERCENTAGE, containerWidth / contentWidth * MAX_PERCENTAGE));
|
|
90
|
+
};
|
|
91
|
+
const calculateThumbPosition = _ref5 => {
|
|
92
|
+
let {
|
|
93
|
+
scrollOffset,
|
|
94
|
+
scrollMax,
|
|
95
|
+
thumbWidthPercent
|
|
96
|
+
} = _ref5;
|
|
97
|
+
if (scrollMax <= INITIAL_DIMENSION) return INITIAL_DIMENSION;
|
|
98
|
+
return scrollOffset / scrollMax * (MAX_PERCENTAGE - thumbWidthPercent);
|
|
99
|
+
};
|
|
100
|
+
const getScrollableNode = ref => ref.current?.getScrollableNode?.() ?? null;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The `Scroll` component provides a continuous horizontal scrollable container with a progress
|
|
104
|
+
* bar indicator. Items are displayed in a flow layout where all items share the width of the
|
|
105
|
+
* widest item and the height of the tallest item.
|
|
106
|
+
*
|
|
107
|
+
* ## Props
|
|
108
|
+
*
|
|
109
|
+
* - Use `children` to pass `ScrollItem` components
|
|
110
|
+
* - Use `accessibilityLabel` to provide a meaningful label for the scrollable region
|
|
111
|
+
* - Use `copy` to select English or French for accessible labels
|
|
112
|
+
* - Use `dictionary` to override the default translations
|
|
113
|
+
*
|
|
114
|
+
* ## Usability and A11y guidelines
|
|
115
|
+
*
|
|
116
|
+
* - The scroll container is keyboard-focusable with `tabIndex="0"`
|
|
117
|
+
* - Each `ScrollItem` is individually focusable via Tab navigation
|
|
118
|
+
* - Use left and right arrow keys to scroll by one item width
|
|
119
|
+
* - Press Space bar to scroll right
|
|
120
|
+
* - When tabbing through items, the scroll follows focus to keep the active item visible
|
|
121
|
+
* - Screen readers announce the component as a region with a descriptive label
|
|
122
|
+
* - Touch and swipe gestures are supported on mobile and mobile web
|
|
123
|
+
*
|
|
124
|
+
*/
|
|
125
|
+
const Scroll = exports.Scroll = /*#__PURE__*/_react.default.forwardRef((_ref6, ref) => {
|
|
126
|
+
let {
|
|
127
|
+
children,
|
|
128
|
+
tokens,
|
|
129
|
+
variant,
|
|
130
|
+
copy,
|
|
131
|
+
dictionary: customDictionary = _dictionary.dictionary,
|
|
132
|
+
accessibilityLabel,
|
|
133
|
+
...rest
|
|
134
|
+
} = _ref6;
|
|
135
|
+
const getCopy = (0, _useCopy.useCopy)({
|
|
136
|
+
dictionary: customDictionary,
|
|
137
|
+
copy
|
|
138
|
+
});
|
|
139
|
+
const resolvedAccessibilityLabel = accessibilityLabel || getCopy('accessibilityLabel');
|
|
140
|
+
const getTokens = (0, _useThemeTokens.useThemeTokensCallback)(COMPONENT_NAME, tokens, variant);
|
|
141
|
+
const defaultTokens = _react.default.useMemo(() => getTokens(), [getTokens]);
|
|
142
|
+
const descriptionId = (0, _useUniqueId.useUniqueId)(SCROLL_DESCRIPTION_PREFIX);
|
|
143
|
+
const scrollRef = _react.default.useRef(null);
|
|
144
|
+
const pressableRef = _react.default.useRef(null);
|
|
145
|
+
const scrollContainerRef = _react.default.useRef(null);
|
|
146
|
+
const scrollMaxRef = _react.default.useRef(INITIAL_DIMENSION);
|
|
147
|
+
const scrollOffsetRef = _react.default.useRef(INITIAL_DIMENSION);
|
|
148
|
+
const thumbWidthPercentRef = _react.default.useRef(MAX_PERCENTAGE);
|
|
149
|
+
const thumbRef = _react.default.useRef(null);
|
|
150
|
+
const isDraggingRef = _react.default.useRef(false);
|
|
151
|
+
const dragStartRef = _react.default.useRef({
|
|
152
|
+
mouseX: INITIAL_DIMENSION,
|
|
153
|
+
scrollOffset: INITIAL_DIMENSION
|
|
154
|
+
});
|
|
155
|
+
const [scrollOffset, setScrollOffset] = _react.default.useState(INITIAL_DIMENSION);
|
|
156
|
+
const [containerWidth, setContainerWidth] = _react.default.useState(INITIAL_DIMENSION);
|
|
157
|
+
const [contentWidth, setContentWidth] = _react.default.useState(INITIAL_DIMENSION);
|
|
158
|
+
const [itemWidth, setItemWidth] = _react.default.useState(INITIAL_DIMENSION);
|
|
159
|
+
const [itemHeight, setItemHeight] = _react.default.useState(INITIAL_DIMENSION);
|
|
160
|
+
const {
|
|
161
|
+
itemGap
|
|
162
|
+
} = defaultTokens;
|
|
163
|
+
const scrollMax = Math.max(INITIAL_DIMENSION, contentWidth - containerWidth);
|
|
164
|
+
_react.default.useEffect(() => {
|
|
165
|
+
scrollMaxRef.current = scrollMax;
|
|
166
|
+
}, [scrollMax]);
|
|
167
|
+
const thumbWidthPercent = calculateThumbWidth({
|
|
168
|
+
containerWidth,
|
|
169
|
+
contentWidth
|
|
170
|
+
});
|
|
171
|
+
thumbWidthPercentRef.current = thumbWidthPercent;
|
|
172
|
+
const thumbPositionPercent = calculateThumbPosition({
|
|
173
|
+
scrollOffset,
|
|
174
|
+
scrollMax,
|
|
175
|
+
thumbWidthPercent
|
|
176
|
+
});
|
|
177
|
+
const thumbWrapperStyle = _react.default.useMemo(() => [staticStyles.thumbWrapper, selectThumbWrapperStyles({
|
|
178
|
+
thumbWidthPercent,
|
|
179
|
+
thumbPositionPercent
|
|
180
|
+
}), _Platform.default.OS === 'web' ? staticStyles.thumbCursor : null], [thumbWidthPercent, thumbPositionPercent]);
|
|
181
|
+
const handleScroll = _react.default.useCallback(_ref7 => {
|
|
182
|
+
let {
|
|
183
|
+
nativeEvent: {
|
|
184
|
+
contentOffset: {
|
|
185
|
+
x
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
} = _ref7;
|
|
189
|
+
scrollOffsetRef.current = x;
|
|
190
|
+
setScrollOffset(x);
|
|
191
|
+
}, []);
|
|
192
|
+
const handleContainerLayout = _react.default.useCallback(_ref8 => {
|
|
193
|
+
let {
|
|
194
|
+
nativeEvent: {
|
|
195
|
+
layout: {
|
|
196
|
+
width
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} = _ref8;
|
|
200
|
+
setContainerWidth(width);
|
|
201
|
+
}, []);
|
|
202
|
+
const handleContentWidth = _react.default.useCallback(width => {
|
|
203
|
+
setContentWidth(width);
|
|
204
|
+
}, []);
|
|
205
|
+
const handleItemLayout = _react.default.useCallback((width, height) => {
|
|
206
|
+
setItemWidth(prev => Math.max(prev, width));
|
|
207
|
+
setItemHeight(prev => Math.max(prev, height));
|
|
208
|
+
}, []);
|
|
209
|
+
_react.default.useEffect(() => {
|
|
210
|
+
if (_Platform.default.OS !== 'web') return undefined;
|
|
211
|
+
const element = scrollContainerRef.current;
|
|
212
|
+
if (!element) return undefined;
|
|
213
|
+
const handleWheel = event => {
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
event.stopPropagation();
|
|
216
|
+
const isHorizontal = Math.abs(event.deltaX) > Math.abs(event.deltaY);
|
|
217
|
+
const delta = isHorizontal ? event.deltaX : event.deltaY;
|
|
218
|
+
const scrollableNode = getScrollableNode(scrollRef);
|
|
219
|
+
if (scrollableNode) {
|
|
220
|
+
const maxScroll = scrollMaxRef.current;
|
|
221
|
+
const newScrollLeft = Math.max(INITIAL_DIMENSION, Math.min(maxScroll, scrollableNode.scrollLeft + delta));
|
|
222
|
+
scrollableNode.scrollLeft = newScrollLeft;
|
|
223
|
+
scrollOffsetRef.current = newScrollLeft;
|
|
224
|
+
setScrollOffset(newScrollLeft);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
element.addEventListener('wheel', handleWheel, {
|
|
228
|
+
passive: false
|
|
229
|
+
});
|
|
230
|
+
return () => element.removeEventListener('wheel', handleWheel);
|
|
231
|
+
}, []);
|
|
232
|
+
_react.default.useEffect(() => {
|
|
233
|
+
if (_Platform.default.OS !== 'web') return undefined;
|
|
234
|
+
const element = scrollContainerRef.current;
|
|
235
|
+
if (!element) return undefined;
|
|
236
|
+
const handleFocusIn = event => {
|
|
237
|
+
const scrollableNode = getScrollableNode(scrollRef);
|
|
238
|
+
if (!scrollableNode) return;
|
|
239
|
+
const focusedItem = event.target.closest(SCROLL_ITEM_SELECTOR);
|
|
240
|
+
if (!focusedItem) return;
|
|
241
|
+
const itemLeft = focusedItem.offsetLeft;
|
|
242
|
+
const itemRight = itemLeft + focusedItem.offsetWidth;
|
|
243
|
+
const visibleLeft = scrollableNode.scrollLeft;
|
|
244
|
+
const currentContainerWidth = containerWidth;
|
|
245
|
+
const visibleRight = visibleLeft + currentContainerWidth;
|
|
246
|
+
if (itemRight > visibleRight) {
|
|
247
|
+
scrollRef.current.scrollTo({
|
|
248
|
+
x: itemRight - currentContainerWidth,
|
|
249
|
+
animated: true
|
|
250
|
+
});
|
|
251
|
+
} else if (itemLeft < visibleLeft) {
|
|
252
|
+
scrollRef.current.scrollTo({
|
|
253
|
+
x: itemLeft,
|
|
254
|
+
animated: true
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
element.addEventListener('focusin', handleFocusIn);
|
|
259
|
+
return () => element.removeEventListener('focusin', handleFocusIn);
|
|
260
|
+
}, [containerWidth]);
|
|
261
|
+
const hasScrollbar = scrollMax > INITIAL_DIMENSION;
|
|
262
|
+
_react.default.useEffect(() => {
|
|
263
|
+
if (_Platform.default.OS !== 'web' || !hasScrollbar) return undefined;
|
|
264
|
+
const thumbElement = thumbRef.current;
|
|
265
|
+
if (!thumbElement) return undefined;
|
|
266
|
+
const handleMouseDown = event => {
|
|
267
|
+
event.preventDefault();
|
|
268
|
+
event.stopPropagation();
|
|
269
|
+
isDraggingRef.current = true;
|
|
270
|
+
dragStartRef.current = {
|
|
271
|
+
mouseX: event.clientX,
|
|
272
|
+
scrollOffset: getScrollableNode(scrollRef)?.scrollLeft ?? INITIAL_DIMENSION
|
|
273
|
+
};
|
|
274
|
+
thumbElement.style.cursor = 'grabbing';
|
|
275
|
+
document.body.style.cursor = 'grabbing';
|
|
276
|
+
document.body.style.userSelect = 'none';
|
|
277
|
+
};
|
|
278
|
+
const handleMouseMove = event => {
|
|
279
|
+
if (!isDraggingRef.current) return;
|
|
280
|
+
const trackElement = pressableRef.current;
|
|
281
|
+
if (!trackElement) return;
|
|
282
|
+
const trackWidth = trackElement.offsetWidth;
|
|
283
|
+
const thumbPixelWidth = thumbWidthPercentRef.current / MAX_PERCENTAGE * trackWidth;
|
|
284
|
+
const availableTrackPixels = trackWidth - thumbPixelWidth;
|
|
285
|
+
if (availableTrackPixels <= INITIAL_DIMENSION) return;
|
|
286
|
+
const mouseDelta = event.clientX - dragStartRef.current.mouseX;
|
|
287
|
+
const scrollDelta = mouseDelta / availableTrackPixels * scrollMaxRef.current;
|
|
288
|
+
const targetScroll = Math.max(INITIAL_DIMENSION, Math.min(scrollMaxRef.current, dragStartRef.current.scrollOffset + scrollDelta));
|
|
289
|
+
const scrollableNode = getScrollableNode(scrollRef);
|
|
290
|
+
if (scrollableNode) {
|
|
291
|
+
scrollableNode.scrollLeft = targetScroll;
|
|
292
|
+
scrollOffsetRef.current = targetScroll;
|
|
293
|
+
setScrollOffset(targetScroll);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
const handleMouseUp = () => {
|
|
297
|
+
if (!isDraggingRef.current) return;
|
|
298
|
+
isDraggingRef.current = false;
|
|
299
|
+
thumbElement.style.cursor = '';
|
|
300
|
+
document.body.style.cursor = '';
|
|
301
|
+
document.body.style.userSelect = '';
|
|
302
|
+
};
|
|
303
|
+
thumbElement.addEventListener('mousedown', handleMouseDown);
|
|
304
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
305
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
306
|
+
return () => {
|
|
307
|
+
thumbElement.removeEventListener('mousedown', handleMouseDown);
|
|
308
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
309
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
310
|
+
};
|
|
311
|
+
}, [hasScrollbar]);
|
|
312
|
+
const handleKeyDown = _react.default.useCallback(event => {
|
|
313
|
+
if (event.key === KEY_ARROW_RIGHT || event.key === KEY_SPACE) {
|
|
314
|
+
event.preventDefault();
|
|
315
|
+
if (scrollRef.current) {
|
|
316
|
+
scrollRef.current.scrollTo({
|
|
317
|
+
x: scrollOffsetRef.current + itemWidth,
|
|
318
|
+
animated: true
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
} else if (event.key === KEY_ARROW_LEFT) {
|
|
322
|
+
event.preventDefault();
|
|
323
|
+
if (scrollRef.current) {
|
|
324
|
+
scrollRef.current.scrollTo({
|
|
325
|
+
x: Math.max(INITIAL_DIMENSION, scrollOffsetRef.current - itemWidth),
|
|
326
|
+
animated: true
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}, [itemWidth]);
|
|
331
|
+
const handleProgressPress = _react.default.useCallback(event => {
|
|
332
|
+
if (scrollMax <= INITIAL_DIMENSION || isDraggingRef.current) return;
|
|
333
|
+
if (_Platform.default.OS === 'web' && pressableRef.current) {
|
|
334
|
+
const {
|
|
335
|
+
offsetX
|
|
336
|
+
} = event.nativeEvent;
|
|
337
|
+
const {
|
|
338
|
+
offsetWidth
|
|
339
|
+
} = pressableRef.current;
|
|
340
|
+
const thumbPixelWidth = thumbWidthPercent / MAX_PERCENTAGE * offsetWidth;
|
|
341
|
+
const availableTrack = offsetWidth - thumbPixelWidth;
|
|
342
|
+
if (availableTrack <= INITIAL_DIMENSION) return;
|
|
343
|
+
const clickPosition = Math.max(INITIAL_DIMENSION, Math.min(availableTrack, offsetX - thumbPixelWidth / HALF_DIVISOR));
|
|
344
|
+
const targetX = clickPosition / availableTrack * scrollMax;
|
|
345
|
+
if (scrollRef.current) {
|
|
346
|
+
scrollRef.current.scrollTo({
|
|
347
|
+
x: targetX,
|
|
348
|
+
animated: true
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
} else if (pressableRef.current) {
|
|
352
|
+
const {
|
|
353
|
+
locationX
|
|
354
|
+
} = event.nativeEvent;
|
|
355
|
+
pressableRef.current.measure((_x, _y, width) => {
|
|
356
|
+
const thumbPixelWidth = thumbWidthPercent / MAX_PERCENTAGE * width;
|
|
357
|
+
const availableTrack = width - thumbPixelWidth;
|
|
358
|
+
if (availableTrack <= INITIAL_DIMENSION) return;
|
|
359
|
+
const clickPosition = Math.max(INITIAL_DIMENSION, Math.min(availableTrack, locationX - thumbPixelWidth / HALF_DIVISOR));
|
|
360
|
+
const targetX = clickPosition / availableTrack * scrollMax;
|
|
361
|
+
if (scrollRef.current) {
|
|
362
|
+
scrollRef.current.scrollTo({
|
|
363
|
+
x: targetX,
|
|
364
|
+
animated: true
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
}, [scrollMax, thumbWidthPercent]);
|
|
370
|
+
const handleContainerRef = _react.default.useCallback(node => {
|
|
371
|
+
scrollContainerRef.current = node;
|
|
372
|
+
if (typeof ref === 'function') ref(node);else if (ref) Object.assign(ref, {
|
|
373
|
+
current: node
|
|
374
|
+
});
|
|
375
|
+
}, [ref]);
|
|
376
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_View.default, {
|
|
377
|
+
ref: handleContainerRef,
|
|
378
|
+
style: staticStyles.container,
|
|
379
|
+
...selectContainerA11yProps({
|
|
380
|
+
accessibilityLabel: resolvedAccessibilityLabel,
|
|
381
|
+
descriptionId,
|
|
382
|
+
handleKeyDown
|
|
383
|
+
}),
|
|
384
|
+
...selectProps(rest),
|
|
385
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_A11yText.A11yText, {
|
|
386
|
+
text: getCopy('instructionText'),
|
|
387
|
+
nativeID: descriptionId
|
|
388
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
389
|
+
style: staticStyles.scrollContainer,
|
|
390
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ScrollViewEnd.ScrollViewEnd, {
|
|
391
|
+
ref: scrollRef,
|
|
392
|
+
horizontal: true,
|
|
393
|
+
onScrollEnd: handleScroll,
|
|
394
|
+
onScroll: handleScroll,
|
|
395
|
+
onContentSizeChange: handleContentWidth,
|
|
396
|
+
onLayout: handleContainerLayout,
|
|
397
|
+
showsHorizontalScrollIndicator: false,
|
|
398
|
+
contentContainerStyle: [staticStyles.scrollContent, selectScrollContentStyle(itemGap)],
|
|
399
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ScrollContext.ScrollProvider, {
|
|
400
|
+
itemWidth: itemWidth,
|
|
401
|
+
itemHeight: itemHeight,
|
|
402
|
+
onItemLayout: handleItemLayout,
|
|
403
|
+
children: children
|
|
404
|
+
})
|
|
405
|
+
})
|
|
406
|
+
}), scrollMax > INITIAL_DIMENSION && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Pressable.default, {
|
|
407
|
+
ref: pressableRef,
|
|
408
|
+
style: [staticStyles.pressable, selectPressableStyles(defaultTokens)],
|
|
409
|
+
onPress: handleProgressPress,
|
|
410
|
+
children: pressableState => /*#__PURE__*/(0, _jsxRuntime.jsx)(_ScrollProgress.ScrollProgress, {
|
|
411
|
+
ref: thumbRef,
|
|
412
|
+
pressableState: pressableState,
|
|
413
|
+
getTokens: getTokens,
|
|
414
|
+
thumbWrapperStyle: thumbWrapperStyle,
|
|
415
|
+
getCopy: getCopy
|
|
416
|
+
})
|
|
417
|
+
})]
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
Scroll.displayName = 'Scroll';
|
|
421
|
+
Scroll.propTypes = {
|
|
422
|
+
...selectedSystemPropTypes,
|
|
423
|
+
/**
|
|
424
|
+
* Scroll items to display. Should be `ScrollItem` components.
|
|
425
|
+
*/
|
|
426
|
+
children: _propTypes.default.node.isRequired,
|
|
427
|
+
/**
|
|
428
|
+
* Theme tokens for customizing the Scroll appearance
|
|
429
|
+
*/
|
|
430
|
+
tokens: (0, _tokens.getTokensPropType)('Scroll'),
|
|
431
|
+
/**
|
|
432
|
+
* Variant for the Scroll component
|
|
433
|
+
*/
|
|
434
|
+
variant: _variantProp.variantProp.propType,
|
|
435
|
+
/**
|
|
436
|
+
* Select English or French copy for accessible labels.
|
|
437
|
+
*/
|
|
438
|
+
copy: _copyPropTypes.copyPropTypes,
|
|
439
|
+
/**
|
|
440
|
+
* Override the default dictionary by passing the complete dictionary object for `en` and `fr`.
|
|
441
|
+
*/
|
|
442
|
+
dictionary: _propTypes.default.shape({
|
|
443
|
+
en: _propTypes.default.object,
|
|
444
|
+
fr: _propTypes.default.object
|
|
445
|
+
}),
|
|
446
|
+
/**
|
|
447
|
+
* Accessibility label for the scrollable region
|
|
448
|
+
*/
|
|
449
|
+
accessibilityLabel: _propTypes.default.string
|
|
450
|
+
};
|
|
451
|
+
const staticStyles = _StyleSheet.default.create({
|
|
452
|
+
container: {
|
|
453
|
+
width: '100%'
|
|
454
|
+
},
|
|
455
|
+
scrollContainer: {
|
|
456
|
+
width: '100%'
|
|
457
|
+
},
|
|
458
|
+
pressable: {
|
|
459
|
+
justifyContent: 'center',
|
|
460
|
+
width: '100%'
|
|
461
|
+
},
|
|
462
|
+
scrollContent: {
|
|
463
|
+
alignSelf: 'flex-start',
|
|
464
|
+
flexGrow: 1
|
|
465
|
+
},
|
|
466
|
+
thumbWrapper: {
|
|
467
|
+
height: '100%'
|
|
468
|
+
},
|
|
469
|
+
thumbCursor: {
|
|
470
|
+
cursor: 'grab'
|
|
471
|
+
}
|
|
472
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ScrollProvider = void 0;
|
|
7
|
+
exports.useScroll = useScroll;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
const ScrollContext = /*#__PURE__*/_react.default.createContext();
|
|
13
|
+
const ScrollProvider = _ref => {
|
|
14
|
+
let {
|
|
15
|
+
children,
|
|
16
|
+
itemWidth,
|
|
17
|
+
itemHeight,
|
|
18
|
+
onItemLayout
|
|
19
|
+
} = _ref;
|
|
20
|
+
const value = _react.default.useMemo(() => ({
|
|
21
|
+
itemWidth,
|
|
22
|
+
itemHeight,
|
|
23
|
+
onItemLayout
|
|
24
|
+
}), [itemWidth, itemHeight, onItemLayout]);
|
|
25
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ScrollContext.Provider, {
|
|
26
|
+
value: value,
|
|
27
|
+
children: children
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
exports.ScrollProvider = ScrollProvider;
|
|
31
|
+
function useScroll() {
|
|
32
|
+
const context = _react.default.useContext(ScrollContext);
|
|
33
|
+
if (context === undefined) {
|
|
34
|
+
throw new Error(`'useScroll' must be used within a 'ScrollProvider'`);
|
|
35
|
+
}
|
|
36
|
+
return context;
|
|
37
|
+
}
|
|
38
|
+
ScrollProvider.propTypes = {
|
|
39
|
+
/**
|
|
40
|
+
* Content to be rendered within the scroll context provider.
|
|
41
|
+
*/
|
|
42
|
+
children: _propTypes.default.node.isRequired,
|
|
43
|
+
/**
|
|
44
|
+
* Width of each scroll item in pixels.
|
|
45
|
+
*/
|
|
46
|
+
itemWidth: _propTypes.default.number.isRequired,
|
|
47
|
+
/**
|
|
48
|
+
* Height of each scroll item in pixels.
|
|
49
|
+
*/
|
|
50
|
+
itemHeight: _propTypes.default.number.isRequired,
|
|
51
|
+
/**
|
|
52
|
+
* Callback invoked when a scroll item layout is measured.
|
|
53
|
+
*/
|
|
54
|
+
onItemLayout: _propTypes.default.func.isRequired
|
|
55
|
+
};
|