@telus-uds/components-base 4.0.0-alpha.2 → 4.0.0-beta.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/CHANGELOG.md +16 -1
- package/lib/cjs/Autocomplete/Autocomplete.js +13 -1
- package/lib/cjs/Autocomplete/constants.js +1 -1
- package/lib/cjs/Listbox/ListboxOverlay.js +7 -1
- package/lib/cjs/MultiSelectFilter/ModalOverlay.js +7 -1
- package/lib/cjs/MultiSelectFilter/MultiSelectFilter.js +2 -28
- package/lib/cjs/TextInput/TextInputBase.js +2 -1
- package/lib/cjs/utils/useOverlaidPosition.js +83 -42
- package/lib/esm/Autocomplete/Autocomplete.js +13 -1
- package/lib/esm/Autocomplete/constants.js +1 -1
- package/lib/esm/Listbox/ListboxOverlay.js +7 -1
- package/lib/esm/MultiSelectFilter/ModalOverlay.js +8 -2
- package/lib/esm/MultiSelectFilter/MultiSelectFilter.js +2 -28
- package/lib/esm/TextInput/TextInputBase.js +2 -1
- package/lib/esm/utils/useOverlaidPosition.js +83 -42
- package/lib/package.json +1 -1
- package/package.json +1 -1
- package/src/Autocomplete/Autocomplete.jsx +11 -2
- package/src/Autocomplete/constants.js +1 -1
- package/src/Listbox/ListboxOverlay.jsx +6 -2
- package/src/MultiSelectFilter/ModalOverlay.jsx +9 -3
- package/src/MultiSelectFilter/MultiSelectFilter.jsx +1 -31
- package/src/TextInput/TextInputBase.jsx +2 -1
- package/src/utils/useOverlaidPosition.js +84 -34
- package/types/A11yInfoProvider.d.ts +9 -0
- package/types/A11yText.d.ts +13 -0
- package/types/ActionCard.d.ts +19 -0
- package/types/ActivityIndicator.d.ts +13 -0
- package/types/Autocomplete.d.ts +27 -0
- package/types/Badge.d.ts +15 -4
- package/types/BaseProvider.d.ts +26 -0
- package/types/Box.d.ts +13 -3
- package/types/Button.d.ts +35 -0
- package/types/Card.d.ts +19 -0
- package/types/CardGroup.d.ts +23 -0
- package/types/Carousel.d.ts +25 -0
- package/types/Checkbox.d.ts +15 -2
- package/types/CheckboxCard.d.ts +20 -0
- package/types/CheckboxCardGroup.d.ts +10 -4
- package/types/ChevronLink.d.ts +9 -2
- package/types/ColourToggle.d.ts +16 -0
- package/types/Common.d.ts +7 -3
- package/types/Divider.d.ts +13 -1
- package/types/DownloadApp.d.ts +19 -0
- package/types/ExpandCollapse.d.ts +16 -9
- package/types/ExpandCollapseMini.d.ts +16 -0
- package/types/Feedback.d.ts +16 -0
- package/types/Fieldset.d.ts +17 -0
- package/types/FileUpload.d.ts +6 -0
- package/types/FlexGrid.d.ts +57 -0
- package/types/Footnote.d.ts +18 -0
- package/types/HorizontalScroll.d.ts +15 -0
- package/types/HorizontalScrollButton.d.ts +17 -1
- package/types/Icon.d.ts +13 -2
- package/types/IconButton.d.ts +19 -0
- package/types/InputLabel.d.ts +12 -0
- package/types/InputSupports.d.ts +19 -0
- package/types/Link.d.ts +20 -4
- package/types/List.d.ts +11 -4
- package/types/Listbox.d.ts +13 -3
- package/types/Modal.d.ts +25 -0
- package/types/MultiSelectFilter.d.ts +24 -0
- package/types/Notification.d.ts +19 -0
- package/types/OrderedList.d.ts +17 -0
- package/types/Pagination.d.ts +25 -0
- package/types/Portal.d.ts +5 -1
- package/types/PriceLockup.d.ts +28 -0
- package/types/ProductCard.d.ts +20 -0
- package/types/ProductCardGroup.d.ts +21 -0
- package/types/Progress.d.ts +22 -0
- package/types/QuickLinks.d.ts +27 -0
- package/types/QuickLinksFeature.d.ts +27 -0
- package/types/Radio.d.ts +22 -0
- package/types/RadioCard.d.ts +21 -0
- package/types/Responsive.d.ts +14 -0
- package/types/Scroll.d.ts +2 -2
- package/types/Search.d.ts +15 -2
- package/types/Select.d.ts +12 -4
- package/types/SideNav.d.ts +38 -0
- package/types/Skeleton.d.ts +17 -0
- package/types/SkipLink.d.ts +14 -0
- package/types/Spacer.d.ts +8 -1
- package/types/StackView.d.ts +8 -2
- package/types/Status.d.ts +2 -3
- package/types/StepTracker.d.ts +16 -0
- package/types/TabBar.d.ts +25 -0
- package/types/Tabs.d.ts +12 -3
- package/types/Tags.d.ts +24 -0
- package/types/TextButton.d.ts +11 -4
- package/types/TextInput.d.ts +38 -0
- package/types/ThemeProvider.d.ts +29 -0
- package/types/Timeline.d.ts +16 -0
- package/types/ToggleSwitch.d.ts +11 -2
- package/types/ToolTip.d.ts +7 -3
- package/types/TooltipButton.d.ts +20 -0
- package/types/Typography.d.ts +8 -2
- package/types/Validator.d.ts +16 -0
- package/types/ViewportProvider.d.ts +12 -0
- package/types/index.d.ts +197 -50
|
@@ -54,46 +54,45 @@ function getOverlaidPosition(_ref2) {
|
|
|
54
54
|
offsets = {},
|
|
55
55
|
align
|
|
56
56
|
} = _ref2;
|
|
57
|
-
// Web-only: this will be difficult to mimic on native because there's no global scroll position.
|
|
58
|
-
// TODO: wire something in e.g. a scroll ref accessible from a provider included in Allium provider
|
|
59
|
-
// that can be passed to the appropriate ScrollView?
|
|
60
|
-
const {
|
|
61
|
-
scrollX = 0,
|
|
62
|
-
scrollY = 0
|
|
63
|
-
} = typeof window === 'object' ? window : {};
|
|
64
|
-
|
|
65
57
|
// Will have top, bottom, left and/or right offsets depending on `align`
|
|
66
58
|
const positioning = {};
|
|
67
59
|
const verticalOffset = offsets.vertical ?? 0;
|
|
68
60
|
const horizontalOffset = offsets.horizontal ?? 0;
|
|
69
61
|
if (align.top) positioning.top = getPosition({
|
|
70
62
|
edge: getEdgeType(align, 'top'),
|
|
71
|
-
fromEdge: sourceLayout.y +
|
|
63
|
+
fromEdge: sourceLayout.y + verticalOffset,
|
|
72
64
|
sourceSize: sourceLayout.height
|
|
73
65
|
});
|
|
74
66
|
if (align.middle) positioning.top = getPosition({
|
|
75
67
|
edge: getEdgeType(align, 'middle'),
|
|
76
|
-
fromEdge: sourceLayout.y +
|
|
77
|
-
sourceSize: sourceLayout.height
|
|
78
|
-
});
|
|
79
|
-
if (align.bottom) positioning.bottom = getPosition({
|
|
80
|
-
edge: getEdgeType(align, 'bottom'),
|
|
81
|
-
fromEdge: windowDimensions.height - (sourceLayout.y + scrollY + sourceLayout.height - verticalOffset),
|
|
68
|
+
fromEdge: sourceLayout.y + verticalOffset - targetDimensions.height / 2,
|
|
82
69
|
sourceSize: sourceLayout.height
|
|
83
70
|
});
|
|
71
|
+
if (align.bottom) {
|
|
72
|
+
if (Platform.OS !== 'web') {
|
|
73
|
+
// On native, position:absolute is parent-relative, so use negative top offset instead of window-based bottom math.
|
|
74
|
+
positioning.top = sourceLayout.y - targetDimensions.height - verticalOffset;
|
|
75
|
+
} else {
|
|
76
|
+
positioning.bottom = getPosition({
|
|
77
|
+
edge: getEdgeType(align, 'bottom'),
|
|
78
|
+
fromEdge: windowDimensions.height - (sourceLayout.y + sourceLayout.height - verticalOffset),
|
|
79
|
+
sourceSize: sourceLayout.height
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
84
83
|
if (align.left) positioning.left = getPosition({
|
|
85
84
|
edge: getEdgeType(align, 'left'),
|
|
86
|
-
fromEdge: sourceLayout.x +
|
|
85
|
+
fromEdge: sourceLayout.x + horizontalOffset,
|
|
87
86
|
sourceSize: sourceLayout.width
|
|
88
87
|
});
|
|
89
88
|
if (align.center) positioning.left = getPosition({
|
|
90
89
|
edge: getEdgeType(align, 'center'),
|
|
91
|
-
fromEdge: sourceLayout.x +
|
|
90
|
+
fromEdge: sourceLayout.x + horizontalOffset - targetDimensions.width / 2,
|
|
92
91
|
sourceSize: sourceLayout.width
|
|
93
92
|
});
|
|
94
93
|
if (align.right) positioning.right = getPosition({
|
|
95
94
|
edge: getEdgeType(align, 'right'),
|
|
96
|
-
fromEdge: windowDimensions.width - (sourceLayout.x +
|
|
95
|
+
fromEdge: windowDimensions.width - (sourceLayout.x + sourceLayout.width - horizontalOffset),
|
|
97
96
|
sourceSize: sourceLayout.width
|
|
98
97
|
});
|
|
99
98
|
if (!(align.left && align.right)) {
|
|
@@ -134,6 +133,32 @@ export const useOverlaidPosition = _ref3 => {
|
|
|
134
133
|
const targetRef = useRef(null);
|
|
135
134
|
const [targetDimensions, setTargetDimensions] = useState(null);
|
|
136
135
|
const [windowDimensions, setWindowDimensions] = useState(null);
|
|
136
|
+
const hasRemeasuredRef = useRef(false);
|
|
137
|
+
const applySourceLayout = useCallback((dims, x, y, width, height) => {
|
|
138
|
+
setWindowDimensions(dims);
|
|
139
|
+
setSourceLayout({
|
|
140
|
+
x,
|
|
141
|
+
y,
|
|
142
|
+
width,
|
|
143
|
+
height
|
|
144
|
+
});
|
|
145
|
+
}, []);
|
|
146
|
+
const measureSourceOnWeb = useCallback(windowDims => {
|
|
147
|
+
const el = sourceRef.current;
|
|
148
|
+
if (!el) return;
|
|
149
|
+
const domNode = el._nativeTag ?? el;
|
|
150
|
+
const dims = windowDims ?? Dimensions.get('window');
|
|
151
|
+
const rect = typeof domNode.getBoundingClientRect === 'function' ? domNode.getBoundingClientRect() : null;
|
|
152
|
+
if (rect) {
|
|
153
|
+
const x = rect.left + (typeof window.scrollX === 'number' ? window.scrollX : 0);
|
|
154
|
+
const y = rect.top + (typeof window.scrollY === 'number' ? window.scrollY : 0);
|
|
155
|
+
applySourceLayout(dims, x, y, rect.width, rect.height);
|
|
156
|
+
} else {
|
|
157
|
+
el.measureInWindow((mx, my, width, height) => {
|
|
158
|
+
applySourceLayout(dims, mx, my, width, height);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}, [applySourceLayout]);
|
|
137
162
|
const onTargetLayout = useCallback(_ref4 => {
|
|
138
163
|
let {
|
|
139
164
|
nativeEvent: {
|
|
@@ -164,16 +189,19 @@ export const useOverlaidPosition = _ref3 => {
|
|
|
164
189
|
let {
|
|
165
190
|
window
|
|
166
191
|
} = _ref5;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
192
|
+
if (Platform.OS === 'web') {
|
|
193
|
+
measureSourceOnWeb(window);
|
|
194
|
+
} else {
|
|
195
|
+
sourceRef.current?.measure((x, y, width, height) => {
|
|
196
|
+
setWindowDimensions(window);
|
|
197
|
+
setSourceLayout({
|
|
198
|
+
x,
|
|
199
|
+
y,
|
|
200
|
+
width,
|
|
201
|
+
height
|
|
202
|
+
});
|
|
175
203
|
});
|
|
176
|
-
}
|
|
204
|
+
}
|
|
177
205
|
};
|
|
178
206
|
let subscription;
|
|
179
207
|
const unsubscribe = () => {
|
|
@@ -186,6 +214,7 @@ export const useOverlaidPosition = _ref3 => {
|
|
|
186
214
|
}
|
|
187
215
|
setSourceLayout(null);
|
|
188
216
|
setTargetDimensions(null);
|
|
217
|
+
hasRemeasuredRef.current = false;
|
|
189
218
|
};
|
|
190
219
|
if (readyToShow) {
|
|
191
220
|
subscription = Dimensions.addEventListener('change', handleDimensionsChange);
|
|
@@ -196,36 +225,48 @@ export const useOverlaidPosition = _ref3 => {
|
|
|
196
225
|
unsubscribe();
|
|
197
226
|
}
|
|
198
227
|
return unsubscribe;
|
|
199
|
-
}, [readyToShow]);
|
|
228
|
+
}, [readyToShow, measureSourceOnWeb]);
|
|
229
|
+
|
|
230
|
+
// Re-measure source when targetDimensions first becomes available.
|
|
231
|
+
// Without this, there is a race condition: getBoundingClientRect() resolves faster than
|
|
232
|
+
// measureInWindow used to, so sourceLayout may be set before the dropdown has rendered
|
|
233
|
+
// and reported its dimensions via onTargetLayout. When targetDimensions finally arrives,
|
|
234
|
+
// sourceLayout is stale (no scroll has occurred to trigger handleScroll).
|
|
235
|
+
// Setting hasRemeasuredRef.current=true here also prevents the blink: isReady (on web)
|
|
236
|
+
// won't become true until this effect completes, guaranteeing the dropdown is always shown
|
|
237
|
+
// at its final correct position without an intermediate incorrect-position frame.
|
|
238
|
+
useEffect(() => {
|
|
239
|
+
if (!isShown || !sourceRef.current || !targetDimensions || Platform.OS !== 'web') return;
|
|
240
|
+
measureSourceOnWeb();
|
|
241
|
+
hasRemeasuredRef.current = true;
|
|
242
|
+
}, [targetDimensions, isShown, measureSourceOnWeb]);
|
|
200
243
|
useEffect(() => {
|
|
201
244
|
if (Platform.OS !== 'web') {
|
|
202
245
|
return undefined;
|
|
203
246
|
}
|
|
204
|
-
const handleScroll = debounce(
|
|
205
|
-
sourceRef.current?.measureInWindow((x, y, width, height) => {
|
|
206
|
-
setWindowDimensions(window);
|
|
207
|
-
setSourceLayout({
|
|
208
|
-
x,
|
|
209
|
-
y,
|
|
210
|
-
width,
|
|
211
|
-
height
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
}, DEBOUNCE_DELAY);
|
|
247
|
+
const handleScroll = debounce(measureSourceOnWeb, DEBOUNCE_DELAY);
|
|
215
248
|
window.addEventListener('scroll', handleScroll);
|
|
216
249
|
return () => {
|
|
217
250
|
window.removeEventListener('scroll', handleScroll);
|
|
218
251
|
handleScroll.cancel();
|
|
219
252
|
};
|
|
220
|
-
}, [
|
|
221
|
-
|
|
253
|
+
}, [measureSourceOnWeb]);
|
|
254
|
+
|
|
255
|
+
// On web, require hasRemeasuredRef to be true before declaring isReady. This ensures
|
|
256
|
+
// the dropdown is never shown with an intermediate stale position (the blink).
|
|
257
|
+
// On native, hasRemeasuredRef stays false (the web-only effect never runs), so we skip
|
|
258
|
+
// that check to preserve the original native behaviour.
|
|
259
|
+
const isReady = Boolean(isShown && sourceLayout && windowDimensions && targetDimensions && (Platform.OS !== 'web' || hasRemeasuredRef.current));
|
|
222
260
|
const overlaidPosition = isReady ? getOverlaidPosition({
|
|
223
261
|
sourceLayout,
|
|
224
262
|
targetDimensions,
|
|
225
263
|
windowDimensions,
|
|
226
264
|
offsets,
|
|
227
265
|
align
|
|
228
|
-
}) : {
|
|
266
|
+
}) : {
|
|
267
|
+
top: 0,
|
|
268
|
+
left: 0
|
|
269
|
+
};
|
|
229
270
|
return {
|
|
230
271
|
overlaidPosition,
|
|
231
272
|
sourceRef,
|
package/lib/package.json
CHANGED
package/package.json
CHANGED
|
@@ -129,6 +129,7 @@ export const Autocomplete = React.forwardRef(
|
|
|
129
129
|
value,
|
|
130
130
|
helpText = '',
|
|
131
131
|
loadingLabel,
|
|
132
|
+
dropdownPosition = 'bottom',
|
|
132
133
|
tokens,
|
|
133
134
|
...rest
|
|
134
135
|
},
|
|
@@ -180,7 +181,11 @@ export const Autocomplete = React.forwardRef(
|
|
|
180
181
|
isShown: isExpanded || hintExpansionEnabled,
|
|
181
182
|
offsets: {
|
|
182
183
|
vertical: Platform.OS !== 'web' && (hint || inputLabel) ? 28 : 4
|
|
183
|
-
}
|
|
184
|
+
},
|
|
185
|
+
align:
|
|
186
|
+
dropdownPosition === 'top'
|
|
187
|
+
? { center: 'center', bottom: 'top' }
|
|
188
|
+
: { center: 'center', top: 'bottom' }
|
|
184
189
|
})
|
|
185
190
|
const targetRef = React.useRef(null)
|
|
186
191
|
// We limit the number of suggestions displayed to avoid huge lists
|
|
@@ -554,5 +559,9 @@ Autocomplete.propTypes = {
|
|
|
554
559
|
/**
|
|
555
560
|
* Input value for controlled usage
|
|
556
561
|
*/
|
|
557
|
-
value: PropTypes.string
|
|
562
|
+
value: PropTypes.string,
|
|
563
|
+
/**
|
|
564
|
+
* Controls whether the dropdown renders above or below the input. Defaults to 'bottom'.
|
|
565
|
+
*/
|
|
566
|
+
dropdownPosition: PropTypes.oneOf(['top', 'bottom'])
|
|
558
567
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const DEFAULT_MIN_TO_SUGGESTION = 1
|
|
2
2
|
export const DEFAULT_MAX_SUGGESTIONS = 5
|
|
3
|
-
export const DEFAULT_MAX_DROPDOWN_HEIGHT =
|
|
3
|
+
export const DEFAULT_MAX_DROPDOWN_HEIGHT = 500
|
|
4
4
|
export const INPUT_LEFT_PADDING = 16
|
|
5
5
|
export const MIN_LISTBOX_WIDTH = 288
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
|
-
import { View, StyleSheet, Platform } from 'react-native'
|
|
3
|
+
import { View, StyleSheet, Platform, ScrollView } from 'react-native'
|
|
4
4
|
import { Portal } from '../Portal/Portal'
|
|
5
5
|
import { useThemeTokens } from '../ThemeProvider/useThemeTokens'
|
|
6
6
|
import { Card } from '../Card/Card'
|
|
@@ -69,7 +69,11 @@ const DropdownOverlay = React.forwardRef(
|
|
|
69
69
|
paddingRight: paddingHorizontal
|
|
70
70
|
}}
|
|
71
71
|
>
|
|
72
|
-
{
|
|
72
|
+
{Platform.OS !== 'web' ? (
|
|
73
|
+
<ScrollView style={{ maxHeight }}>{children}</ScrollView>
|
|
74
|
+
) : (
|
|
75
|
+
children
|
|
76
|
+
)}
|
|
73
77
|
</Card>
|
|
74
78
|
</View>
|
|
75
79
|
)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import { View, StyleSheet, Platform } from 'react-native'
|
|
4
|
-
import { Portal } from '@gorhom/portal'
|
|
4
|
+
import { Portal as GorhomPortal } from '@gorhom/portal'
|
|
5
|
+
import { Portal as LocalPortal } from '../Portal/Portal'
|
|
5
6
|
import { useCopy } from '../utils/useCopy'
|
|
6
7
|
import { copyPropTypes } from '../utils/props/copyPropTypes'
|
|
7
8
|
import { getTokensPropType } from '../utils/props/tokens'
|
|
@@ -107,8 +108,13 @@ export const ModalOverlay = React.forwardRef(
|
|
|
107
108
|
const getCopy = useCopy({ dictionary, copy })
|
|
108
109
|
const closeLabel = getCopy('closeButton')
|
|
109
110
|
|
|
111
|
+
// On web, use the local Portal (always appends to document.body) to ensure correct
|
|
112
|
+
// absolute positioning in MFE/iframe contexts. @gorhom/portal may render its host
|
|
113
|
+
// outside the iframe's document, causing coordinate mismatches when scrolled.
|
|
114
|
+
const PortalComponent = Platform.OS === 'web' ? LocalPortal : GorhomPortal
|
|
115
|
+
|
|
110
116
|
return (
|
|
111
|
-
<
|
|
117
|
+
<PortalComponent>
|
|
112
118
|
<View
|
|
113
119
|
ref={containerRef}
|
|
114
120
|
onLayout={onLayout}
|
|
@@ -137,7 +143,7 @@ export const ModalOverlay = React.forwardRef(
|
|
|
137
143
|
{children}
|
|
138
144
|
</Card>
|
|
139
145
|
</View>
|
|
140
|
-
</
|
|
146
|
+
</PortalComponent>
|
|
141
147
|
)
|
|
142
148
|
}
|
|
143
149
|
)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
|
-
import { Portal } from '@gorhom/portal'
|
|
4
3
|
import { View, StyleSheet, Dimensions, SafeAreaView, Platform, ScrollView } from 'react-native'
|
|
5
4
|
import { useThemeTokens, useThemeTokensCallback } from '../ThemeProvider/useThemeTokens'
|
|
6
5
|
import { applyTextStyles } from '../ThemeProvider/utils/styles'
|
|
@@ -218,27 +217,11 @@ export const MultiSelectFilter = React.forwardRef(
|
|
|
218
217
|
onCancel()
|
|
219
218
|
}
|
|
220
219
|
|
|
221
|
-
const appRootRef = React.useRef(null)
|
|
222
|
-
const [rootOffsets, setRootOffsets] = React.useState(null)
|
|
223
|
-
|
|
224
|
-
React.useEffect(() => {
|
|
225
|
-
if (rootOffsets) return
|
|
226
|
-
appRootRef.current?.measureInWindow((x, y) => {
|
|
227
|
-
// Only set offsets if they are positive
|
|
228
|
-
// this is because we want to avoid negative offsets that could cause
|
|
229
|
-
// the dropdown to be positioned incorrectly in some situations
|
|
230
|
-
if (y > 0) setRootOffsets({ horizontal: x, vertical: y })
|
|
231
|
-
})
|
|
232
|
-
}, [isOpen, rootOffsets])
|
|
233
|
-
|
|
234
220
|
const { align, offsets } = useResponsiveProp({
|
|
235
221
|
xs: { align: { top: 'top', left: 'left' } },
|
|
236
222
|
sm: {
|
|
237
223
|
align: { top: 'bottom', left: 'left' },
|
|
238
|
-
offsets: {
|
|
239
|
-
vertical: 4 - (rootOffsets?.vertical || 0),
|
|
240
|
-
horizontal: -rootOffsets?.horizontal || 0
|
|
241
|
-
}
|
|
224
|
+
offsets: { vertical: 4 }
|
|
242
225
|
}
|
|
243
226
|
})
|
|
244
227
|
|
|
@@ -364,14 +347,6 @@ export const MultiSelectFilter = React.forwardRef(
|
|
|
364
347
|
|
|
365
348
|
return (
|
|
366
349
|
<>
|
|
367
|
-
{/*
|
|
368
|
-
This View is rendered inside a Portal to determine the application's root position.
|
|
369
|
-
Capturing it is crucial to determine offsets to position the Modal correctly, preventing
|
|
370
|
-
misalignment that can occur when the Portal does not render the Modal at the body level.
|
|
371
|
-
*/}
|
|
372
|
-
<Portal>
|
|
373
|
-
<View ref={appRootRef} style={styles.appRootRef} />
|
|
374
|
-
</Portal>
|
|
375
350
|
<ButtonDropdown
|
|
376
351
|
ref={sourceRef}
|
|
377
352
|
key={id}
|
|
@@ -460,11 +435,6 @@ const styles = StyleSheet.create({
|
|
|
460
435
|
},
|
|
461
436
|
scrollContainer: {
|
|
462
437
|
padding: 1
|
|
463
|
-
},
|
|
464
|
-
appRootRef: {
|
|
465
|
-
position: 'absolute',
|
|
466
|
-
top: 0,
|
|
467
|
-
left: 0
|
|
468
438
|
}
|
|
469
439
|
})
|
|
470
440
|
|
|
@@ -256,7 +256,8 @@ export const TextInputBase = React.forwardRef(
|
|
|
256
256
|
|
|
257
257
|
const handleChangeText = (event) => {
|
|
258
258
|
const text = event.nativeEvent?.text ?? event.target?.value
|
|
259
|
-
|
|
259
|
+
// Do NOT use `|| undefined`: empty string is falsy and would break the controlled contract
|
|
260
|
+
let filteredText = isNumeric ? text?.replace(/[^\d]/g, '') ?? '' : text
|
|
260
261
|
if (type === 'card' && filteredText) {
|
|
261
262
|
const formattedValue = filteredText.replace(/[^a-zA-Z0-9]/g, '')
|
|
262
263
|
const regex = new RegExp(`([a-zA-Z0-9]{4})(?=[a-zA-Z0-9])`, 'g')
|
|
@@ -54,11 +54,6 @@ function getOverlaidPosition({
|
|
|
54
54
|
offsets = {},
|
|
55
55
|
align
|
|
56
56
|
}) {
|
|
57
|
-
// Web-only: this will be difficult to mimic on native because there's no global scroll position.
|
|
58
|
-
// TODO: wire something in e.g. a scroll ref accessible from a provider included in Allium provider
|
|
59
|
-
// that can be passed to the appropriate ScrollView?
|
|
60
|
-
const { scrollX = 0, scrollY = 0 } = typeof window === 'object' ? window : {}
|
|
61
|
-
|
|
62
57
|
// Will have top, bottom, left and/or right offsets depending on `align`
|
|
63
58
|
const positioning = {}
|
|
64
59
|
|
|
@@ -68,40 +63,44 @@ function getOverlaidPosition({
|
|
|
68
63
|
if (align.top)
|
|
69
64
|
positioning.top = getPosition({
|
|
70
65
|
edge: getEdgeType(align, 'top'),
|
|
71
|
-
fromEdge: sourceLayout.y +
|
|
66
|
+
fromEdge: sourceLayout.y + verticalOffset,
|
|
72
67
|
sourceSize: sourceLayout.height
|
|
73
68
|
})
|
|
74
69
|
if (align.middle)
|
|
75
70
|
positioning.top = getPosition({
|
|
76
71
|
edge: getEdgeType(align, 'middle'),
|
|
77
|
-
fromEdge: sourceLayout.y +
|
|
78
|
-
sourceSize: sourceLayout.height
|
|
79
|
-
})
|
|
80
|
-
if (align.bottom)
|
|
81
|
-
positioning.bottom = getPosition({
|
|
82
|
-
edge: getEdgeType(align, 'bottom'),
|
|
83
|
-
fromEdge:
|
|
84
|
-
windowDimensions.height - (sourceLayout.y + scrollY + sourceLayout.height - verticalOffset),
|
|
72
|
+
fromEdge: sourceLayout.y + verticalOffset - targetDimensions.height / 2,
|
|
85
73
|
sourceSize: sourceLayout.height
|
|
86
74
|
})
|
|
75
|
+
if (align.bottom) {
|
|
76
|
+
if (Platform.OS !== 'web') {
|
|
77
|
+
// On native, position:absolute is parent-relative, so use negative top offset instead of window-based bottom math.
|
|
78
|
+
positioning.top = sourceLayout.y - targetDimensions.height - verticalOffset
|
|
79
|
+
} else {
|
|
80
|
+
positioning.bottom = getPosition({
|
|
81
|
+
edge: getEdgeType(align, 'bottom'),
|
|
82
|
+
fromEdge: windowDimensions.height - (sourceLayout.y + sourceLayout.height - verticalOffset),
|
|
83
|
+
sourceSize: sourceLayout.height
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
87
|
|
|
88
88
|
if (align.left)
|
|
89
89
|
positioning.left = getPosition({
|
|
90
90
|
edge: getEdgeType(align, 'left'),
|
|
91
|
-
fromEdge: sourceLayout.x +
|
|
91
|
+
fromEdge: sourceLayout.x + horizontalOffset,
|
|
92
92
|
sourceSize: sourceLayout.width
|
|
93
93
|
})
|
|
94
94
|
if (align.center)
|
|
95
95
|
positioning.left = getPosition({
|
|
96
96
|
edge: getEdgeType(align, 'center'),
|
|
97
|
-
fromEdge: sourceLayout.x +
|
|
97
|
+
fromEdge: sourceLayout.x + horizontalOffset - targetDimensions.width / 2,
|
|
98
98
|
sourceSize: sourceLayout.width
|
|
99
99
|
})
|
|
100
100
|
if (align.right)
|
|
101
101
|
positioning.right = getPosition({
|
|
102
102
|
edge: getEdgeType(align, 'right'),
|
|
103
|
-
fromEdge:
|
|
104
|
-
windowDimensions.width - (sourceLayout.x + scrollX + sourceLayout.width - horizontalOffset),
|
|
103
|
+
fromEdge: windowDimensions.width - (sourceLayout.x + sourceLayout.width - horizontalOffset),
|
|
105
104
|
sourceSize: sourceLayout.width
|
|
106
105
|
})
|
|
107
106
|
|
|
@@ -149,6 +148,34 @@ export const useOverlaidPosition = ({
|
|
|
149
148
|
|
|
150
149
|
const [windowDimensions, setWindowDimensions] = useState(null)
|
|
151
150
|
|
|
151
|
+
const hasRemeasuredRef = useRef(false)
|
|
152
|
+
|
|
153
|
+
const applySourceLayout = useCallback((dims, x, y, width, height) => {
|
|
154
|
+
setWindowDimensions(dims)
|
|
155
|
+
setSourceLayout({ x, y, width, height })
|
|
156
|
+
}, [])
|
|
157
|
+
|
|
158
|
+
const measureSourceOnWeb = useCallback(
|
|
159
|
+
(windowDims) => {
|
|
160
|
+
const el = sourceRef.current
|
|
161
|
+
if (!el) return
|
|
162
|
+
const domNode = el._nativeTag ?? el
|
|
163
|
+
const dims = windowDims ?? Dimensions.get('window')
|
|
164
|
+
const rect =
|
|
165
|
+
typeof domNode.getBoundingClientRect === 'function' ? domNode.getBoundingClientRect() : null
|
|
166
|
+
if (rect) {
|
|
167
|
+
const x = rect.left + (typeof window.scrollX === 'number' ? window.scrollX : 0)
|
|
168
|
+
const y = rect.top + (typeof window.scrollY === 'number' ? window.scrollY : 0)
|
|
169
|
+
applySourceLayout(dims, x, y, rect.width, rect.height)
|
|
170
|
+
} else {
|
|
171
|
+
el.measureInWindow((mx, my, width, height) => {
|
|
172
|
+
applySourceLayout(dims, mx, my, width, height)
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
[applySourceLayout]
|
|
177
|
+
)
|
|
178
|
+
|
|
152
179
|
const onTargetLayout = useCallback(
|
|
153
180
|
({
|
|
154
181
|
nativeEvent: {
|
|
@@ -173,12 +200,14 @@ export const useOverlaidPosition = ({
|
|
|
173
200
|
const readyToShow = Boolean(isShown && sourceRef.current)
|
|
174
201
|
useEffect(() => {
|
|
175
202
|
const handleDimensionsChange = ({ window }) => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
203
|
+
if (Platform.OS === 'web') {
|
|
204
|
+
measureSourceOnWeb(window)
|
|
205
|
+
} else {
|
|
206
|
+
sourceRef.current?.measure((x, y, width, height) => {
|
|
207
|
+
setWindowDimensions(window)
|
|
208
|
+
setSourceLayout({ x, y, width, height })
|
|
209
|
+
})
|
|
210
|
+
}
|
|
182
211
|
}
|
|
183
212
|
|
|
184
213
|
let subscription
|
|
@@ -192,6 +221,7 @@ export const useOverlaidPosition = ({
|
|
|
192
221
|
}
|
|
193
222
|
setSourceLayout(null)
|
|
194
223
|
setTargetDimensions(null)
|
|
224
|
+
hasRemeasuredRef.current = false
|
|
195
225
|
}
|
|
196
226
|
|
|
197
227
|
if (readyToShow) {
|
|
@@ -202,19 +232,29 @@ export const useOverlaidPosition = ({
|
|
|
202
232
|
}
|
|
203
233
|
|
|
204
234
|
return unsubscribe
|
|
205
|
-
}, [readyToShow])
|
|
235
|
+
}, [readyToShow, measureSourceOnWeb])
|
|
236
|
+
|
|
237
|
+
// Re-measure source when targetDimensions first becomes available.
|
|
238
|
+
// Without this, there is a race condition: getBoundingClientRect() resolves faster than
|
|
239
|
+
// measureInWindow used to, so sourceLayout may be set before the dropdown has rendered
|
|
240
|
+
// and reported its dimensions via onTargetLayout. When targetDimensions finally arrives,
|
|
241
|
+
// sourceLayout is stale (no scroll has occurred to trigger handleScroll).
|
|
242
|
+
// Setting hasRemeasuredRef.current=true here also prevents the blink: isReady (on web)
|
|
243
|
+
// won't become true until this effect completes, guaranteeing the dropdown is always shown
|
|
244
|
+
// at its final correct position without an intermediate incorrect-position frame.
|
|
245
|
+
useEffect(() => {
|
|
246
|
+
if (!isShown || !sourceRef.current || !targetDimensions || Platform.OS !== 'web') return
|
|
247
|
+
|
|
248
|
+
measureSourceOnWeb()
|
|
249
|
+
hasRemeasuredRef.current = true
|
|
250
|
+
}, [targetDimensions, isShown, measureSourceOnWeb])
|
|
206
251
|
|
|
207
252
|
useEffect(() => {
|
|
208
253
|
if (Platform.OS !== 'web') {
|
|
209
254
|
return undefined
|
|
210
255
|
}
|
|
211
256
|
|
|
212
|
-
const handleScroll = debounce(
|
|
213
|
-
sourceRef.current?.measureInWindow((x, y, width, height) => {
|
|
214
|
-
setWindowDimensions(window)
|
|
215
|
-
setSourceLayout({ x, y, width, height })
|
|
216
|
-
})
|
|
217
|
-
}, DEBOUNCE_DELAY)
|
|
257
|
+
const handleScroll = debounce(measureSourceOnWeb, DEBOUNCE_DELAY)
|
|
218
258
|
|
|
219
259
|
window.addEventListener('scroll', handleScroll)
|
|
220
260
|
|
|
@@ -222,9 +262,19 @@ export const useOverlaidPosition = ({
|
|
|
222
262
|
window.removeEventListener('scroll', handleScroll)
|
|
223
263
|
handleScroll.cancel()
|
|
224
264
|
}
|
|
225
|
-
}, [
|
|
265
|
+
}, [measureSourceOnWeb])
|
|
226
266
|
|
|
227
|
-
|
|
267
|
+
// On web, require hasRemeasuredRef to be true before declaring isReady. This ensures
|
|
268
|
+
// the dropdown is never shown with an intermediate stale position (the blink).
|
|
269
|
+
// On native, hasRemeasuredRef stays false (the web-only effect never runs), so we skip
|
|
270
|
+
// that check to preserve the original native behaviour.
|
|
271
|
+
const isReady = Boolean(
|
|
272
|
+
isShown &&
|
|
273
|
+
sourceLayout &&
|
|
274
|
+
windowDimensions &&
|
|
275
|
+
targetDimensions &&
|
|
276
|
+
(Platform.OS !== 'web' || hasRemeasuredRef.current)
|
|
277
|
+
)
|
|
228
278
|
|
|
229
279
|
const overlaidPosition = isReady
|
|
230
280
|
? getOverlaidPosition({
|
|
@@ -234,7 +284,7 @@ export const useOverlaidPosition = ({
|
|
|
234
284
|
offsets,
|
|
235
285
|
align
|
|
236
286
|
})
|
|
237
|
-
: {}
|
|
287
|
+
: { top: 0, left: 0 }
|
|
238
288
|
|
|
239
289
|
return {
|
|
240
290
|
overlaidPosition,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ComponentType } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface A11yTextProps {
|
|
4
|
+
text: string
|
|
5
|
+
heading?: boolean
|
|
6
|
+
role?: string
|
|
7
|
+
testID?: string
|
|
8
|
+
dataSet?: Record<string, any>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare const A11yText: ComponentType<A11yTextProps>
|
|
12
|
+
|
|
13
|
+
export { A11yText }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface ActionCardProps {
|
|
4
|
+
icon?: ComponentType<any>
|
|
5
|
+
title?: string
|
|
6
|
+
children?: ReactNode
|
|
7
|
+
href?: string
|
|
8
|
+
direction?: boolean
|
|
9
|
+
accessibilityRole?: string
|
|
10
|
+
tokens?: Record<string, string | number | boolean | object>
|
|
11
|
+
variant?: Record<string, string | number | boolean | undefined>
|
|
12
|
+
testID?: string
|
|
13
|
+
dataSet?: Record<string, any>
|
|
14
|
+
onPress?: () => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare const ActionCard: ComponentType<ActionCardProps>
|
|
18
|
+
|
|
19
|
+
export { ActionCard }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ComponentType } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface ActivityIndicatorProps {
|
|
4
|
+
tokens?: Record<string, string | number | boolean | object>
|
|
5
|
+
variant?: Record<string, string | number | boolean | undefined>
|
|
6
|
+
testID?: string
|
|
7
|
+
dataSet?: Record<string, any>
|
|
8
|
+
accessibilityLabel?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare const ActivityIndicator: ComponentType<ActivityIndicatorProps>
|
|
12
|
+
|
|
13
|
+
export { ActivityIndicator }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface AutocompleteItem {
|
|
4
|
+
id: string
|
|
5
|
+
label: string
|
|
6
|
+
value?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface AutocompleteProps {
|
|
10
|
+
children?: (props: Record<string, any>) => ReactNode
|
|
11
|
+
tokens?: Record<string, string | number | boolean | object>
|
|
12
|
+
copy?: 'en' | 'fr'
|
|
13
|
+
items?: AutocompleteItem[]
|
|
14
|
+
value?: string
|
|
15
|
+
onChange?: (value: string) => void
|
|
16
|
+
onSearch?: (value: string) => void
|
|
17
|
+
onSelect?: (item: AutocompleteItem) => void
|
|
18
|
+
loading?: boolean
|
|
19
|
+
loadingMessage?: string
|
|
20
|
+
emptyText?: string
|
|
21
|
+
testID?: string
|
|
22
|
+
dataSet?: Record<string, any>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare const Autocomplete: ComponentType<AutocompleteProps>
|
|
26
|
+
|
|
27
|
+
export { Autocomplete }
|