@telus-uds/components-base 1.34.0 → 1.34.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.
- package/CHANGELOG.md +10 -2
- package/lib/MultiSelectFilter/ModalOverlay.js +34 -21
- package/lib/MultiSelectFilter/MultiSelectFilter.js +41 -3
- package/lib/utils/index.js +9 -0
- package/lib/utils/useOverlaidPosition.js +243 -0
- package/lib-module/MultiSelectFilter/ModalOverlay.js +35 -23
- package/lib-module/MultiSelectFilter/MultiSelectFilter.js +43 -5
- package/lib-module/utils/index.js +1 -0
- package/lib-module/utils/useOverlaidPosition.js +232 -0
- package/package.json +1 -1
- package/src/MultiSelectFilter/ModalOverlay.jsx +39 -16
- package/src/MultiSelectFilter/MultiSelectFilter.jsx +135 -118
- package/src/utils/index.js +1 -0
- package/src/utils/useOverlaidPosition.js +223 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import Dimensions from "react-native-web/dist/exports/Dimensions";
|
|
3
|
+
|
|
4
|
+
const adjustHorizontalToFit = (initialOffset, windowWidth, sourceWidth) => {
|
|
5
|
+
const offset = Math.max(0, initialOffset);
|
|
6
|
+
const otherEdgeOverflow = Math.max(0, offset + sourceWidth - windowWidth);
|
|
7
|
+
const tooWideBy = Math.max(0, otherEdgeOverflow - offset);
|
|
8
|
+
const adjusted = {
|
|
9
|
+
offset: Math.max(0, offset - otherEdgeOverflow)
|
|
10
|
+
};
|
|
11
|
+
if (tooWideBy) adjusted.width = Math.max(0, sourceWidth - tooWideBy);
|
|
12
|
+
return adjusted;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const getPosition = _ref => {
|
|
16
|
+
let {
|
|
17
|
+
edge,
|
|
18
|
+
fromEdge,
|
|
19
|
+
sourceSize
|
|
20
|
+
} = _ref;
|
|
21
|
+
|
|
22
|
+
switch (edge) {
|
|
23
|
+
case 'near':
|
|
24
|
+
return fromEdge;
|
|
25
|
+
|
|
26
|
+
case 'mid':
|
|
27
|
+
return fromEdge + sourceSize / 2;
|
|
28
|
+
|
|
29
|
+
case 'far':
|
|
30
|
+
return fromEdge + sourceSize;
|
|
31
|
+
|
|
32
|
+
default:
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getEdgeType = (align, alignSide) => {
|
|
38
|
+
const alignTo = align[alignSide];
|
|
39
|
+
const edge = ['center', 'middle'].includes(alignTo) && 'mid' || (alignSide === alignTo ? 'near' : 'far');
|
|
40
|
+
return edge;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Based on UDS's private getTooltipPosition but generalised.
|
|
44
|
+
*
|
|
45
|
+
* Used for absolute positioning of the tooltip. Since the tooltip is always centered relatively
|
|
46
|
+
* to the source (button) and we have a limited set of positions, an easy and consistent way
|
|
47
|
+
* of positioning it is to check all of the possible positions and pick one that will be rendered
|
|
48
|
+
* within the window bounds. This way we can also rely on the tooltip being actually rendered
|
|
49
|
+
* before it is shown, which makes it account for the width being limiting in styles, custom font
|
|
50
|
+
* rendering, etc.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
function getOverlaidPosition(_ref2) {
|
|
55
|
+
let {
|
|
56
|
+
sourceLayout,
|
|
57
|
+
targetDimensions,
|
|
58
|
+
windowDimensions,
|
|
59
|
+
offsets = {},
|
|
60
|
+
align
|
|
61
|
+
} = _ref2;
|
|
62
|
+
// Web-only: this will be difficult to mimic on native because there's no global scroll position.
|
|
63
|
+
// TODO: wire something in e.g. a scroll ref accessible from a provider included in Allium provider
|
|
64
|
+
// that can be passed to the appropriate ScrollView?
|
|
65
|
+
const {
|
|
66
|
+
scrollX = 0,
|
|
67
|
+
scrollY = 0
|
|
68
|
+
} = typeof window === 'object' ? window : {}; // Will have top, bottom, left and/or right offsets depending on `align`
|
|
69
|
+
|
|
70
|
+
const positioning = {};
|
|
71
|
+
if (align.top) positioning.top = getPosition({
|
|
72
|
+
edge: getEdgeType(align, 'top'),
|
|
73
|
+
fromEdge: sourceLayout.y + scrollY + (offsets.vertical ?? 0),
|
|
74
|
+
sourceSize: sourceLayout.height
|
|
75
|
+
});
|
|
76
|
+
if (align.middle) positioning.top = getPosition({
|
|
77
|
+
edge: getEdgeType(align, 'middle'),
|
|
78
|
+
fromEdge: sourceLayout.y + scrollY + (offsets.vertical ?? 0) - targetDimensions.height / 2,
|
|
79
|
+
sourceSize: sourceLayout.height
|
|
80
|
+
});
|
|
81
|
+
if (align.bottom) positioning.bottom = getPosition({
|
|
82
|
+
edge: getEdgeType(align, 'bottom'),
|
|
83
|
+
fromEdge: windowDimensions.height - (sourceLayout.y + scrollY + sourceLayout.height - (offsets.vertical ?? 0)),
|
|
84
|
+
sourceSize: sourceLayout.height
|
|
85
|
+
});
|
|
86
|
+
if (align.left) positioning.left = getPosition({
|
|
87
|
+
edge: getEdgeType(align, 'left'),
|
|
88
|
+
fromEdge: sourceLayout.x + scrollX + (offsets.horizontal ?? 0),
|
|
89
|
+
sourceSize: sourceLayout.width
|
|
90
|
+
});
|
|
91
|
+
if (align.center) positioning.left = getPosition({
|
|
92
|
+
edge: getEdgeType(align, 'center'),
|
|
93
|
+
fromEdge: sourceLayout.x + scrollX + (offsets.horizontal ?? 0) - targetDimensions.width / 2,
|
|
94
|
+
sourceSize: sourceLayout.width
|
|
95
|
+
});
|
|
96
|
+
if (align.right) positioning.right = getPosition({
|
|
97
|
+
edge: getEdgeType(align, 'right'),
|
|
98
|
+
fromEdge: windowDimensions.width - (sourceLayout.x + scrollX + sourceLayout.width - (offsets.horizontal ?? 0)),
|
|
99
|
+
sourceSize: sourceLayout.width
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
if (!(align.left && align.right)) {
|
|
103
|
+
// Check if the position and/or width need adjusting to fit on the screen
|
|
104
|
+
const side = align.right ? 'right' : 'left';
|
|
105
|
+
const adjusted = adjustHorizontalToFit(positioning[side], windowDimensions.width, sourceLayout.width);
|
|
106
|
+
if (typeof adjusted.width === 'number') positioning.width = adjusted.width;
|
|
107
|
+
|
|
108
|
+
if (typeof adjusted.offset === 'number') {
|
|
109
|
+
positioning[side] = adjusted.offset;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return positioning;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Positions an element in a modal or portal so that it appears tooltip-like below the
|
|
117
|
+
* target element.
|
|
118
|
+
*
|
|
119
|
+
* @TODO - add support for positioning other than 'below' like UDS's tooltip (this is not
|
|
120
|
+
* a small task because UDS's tooltip logic only really works for short text - it might be
|
|
121
|
+
* better to use a third-party library).
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
const useOverlaidPosition = _ref3 => {
|
|
126
|
+
let {
|
|
127
|
+
isShown = false,
|
|
128
|
+
offsets,
|
|
129
|
+
// By default, align the overlaid target's `top` to the bottom of the source, and center horizontally.
|
|
130
|
+
align = {
|
|
131
|
+
center: 'center',
|
|
132
|
+
top: 'bottom'
|
|
133
|
+
}
|
|
134
|
+
} = _ref3;
|
|
135
|
+
// Element in main document flow that the targetRef element is positioned around
|
|
136
|
+
const sourceRef = useRef(null);
|
|
137
|
+
const [sourceLayout, setSourceLayout] = useState(null); // Element in a modal or portal overlay positioned to appear adjacent to sourceRef
|
|
138
|
+
|
|
139
|
+
const targetRef = useRef(null);
|
|
140
|
+
const [targetDimensions, setTargetDimensions] = useState(null);
|
|
141
|
+
const [windowDimensions, setWindowDimensions] = useState(null);
|
|
142
|
+
const onTargetLayout = useCallback(_ref4 => {
|
|
143
|
+
let {
|
|
144
|
+
nativeEvent: {
|
|
145
|
+
layout: {
|
|
146
|
+
width,
|
|
147
|
+
height
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} = _ref4;
|
|
151
|
+
// NOTE: UDS's Tooltip logic injects some additional width to allow for antialiasing etc of text,
|
|
152
|
+
// avoiding adding unnecessary line breaks to text that is slightly wider than it thinks it is.
|
|
153
|
+
// That is probably something specific to text tooltips that doesn't belong in a generic hook.
|
|
154
|
+
setTargetDimensions(previousDimensions => {
|
|
155
|
+
// Re-render on first non-zero width / height: avoid infinite loops on changes, or mispositioning
|
|
156
|
+
// if user scrolls while a slidedown animation is changing the height and recalculating position.
|
|
157
|
+
if (!previousDimensions && width && height) {
|
|
158
|
+
return {
|
|
159
|
+
width,
|
|
160
|
+
height
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return previousDimensions;
|
|
165
|
+
});
|
|
166
|
+
}, []);
|
|
167
|
+
const readyToShow = Boolean(isShown && sourceRef.current);
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
const handleDimensionsChange = _ref5 => {
|
|
170
|
+
var _sourceRef$current;
|
|
171
|
+
|
|
172
|
+
let {
|
|
173
|
+
window
|
|
174
|
+
} = _ref5;
|
|
175
|
+
(_sourceRef$current = sourceRef.current) === null || _sourceRef$current === void 0 ? void 0 : _sourceRef$current.measureInWindow((x, y, width, height) => {
|
|
176
|
+
// Could add a debouncer here if there's too many rerenders during gradual resizes
|
|
177
|
+
setWindowDimensions(window);
|
|
178
|
+
setSourceLayout({
|
|
179
|
+
x,
|
|
180
|
+
y,
|
|
181
|
+
width,
|
|
182
|
+
height
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
let subscription;
|
|
188
|
+
|
|
189
|
+
const unsubscribe = () => {
|
|
190
|
+
var _subscription;
|
|
191
|
+
|
|
192
|
+
if (typeof ((_subscription = subscription) === null || _subscription === void 0 ? void 0 : _subscription.remove) === 'function') {
|
|
193
|
+
// React Native >=0.65.0
|
|
194
|
+
subscription.remove();
|
|
195
|
+
} else if (typeof Dimensions.removeEventListener === 'function') {
|
|
196
|
+
// React Native <0.65.0
|
|
197
|
+
Dimensions.removeEventListener('change', handleDimensionsChange);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
setSourceLayout(null);
|
|
201
|
+
setTargetDimensions(null);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
if (readyToShow) {
|
|
205
|
+
subscription = Dimensions.addEventListener('change', handleDimensionsChange);
|
|
206
|
+
handleDimensionsChange({
|
|
207
|
+
window: Dimensions.get('window')
|
|
208
|
+
});
|
|
209
|
+
} else {
|
|
210
|
+
unsubscribe();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return unsubscribe;
|
|
214
|
+
}, [readyToShow]);
|
|
215
|
+
const isReady = Boolean(isShown && sourceLayout && windowDimensions && targetDimensions);
|
|
216
|
+
const overlaidPosition = isReady ? getOverlaidPosition({
|
|
217
|
+
sourceLayout,
|
|
218
|
+
targetDimensions,
|
|
219
|
+
windowDimensions,
|
|
220
|
+
offsets,
|
|
221
|
+
align
|
|
222
|
+
}) : {};
|
|
223
|
+
return {
|
|
224
|
+
overlaidPosition,
|
|
225
|
+
sourceRef,
|
|
226
|
+
targetRef,
|
|
227
|
+
onTargetLayout,
|
|
228
|
+
isReady
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
export default useOverlaidPosition;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
|
-
import { View, StyleSheet } from 'react-native
|
|
3
|
+
import { View, StyleSheet } from 'react-native'
|
|
4
4
|
import { Portal } from '@gorhom/portal'
|
|
5
|
-
import {
|
|
5
|
+
import { selectTokens, useCopy, copyPropTypes, getTokensPropType, variantProp } from '../utils'
|
|
6
6
|
import { useViewport } from '../ViewportProvider'
|
|
7
7
|
import { useThemeTokens } from '../ThemeProvider'
|
|
8
8
|
import dictionary from './dictionary'
|
|
@@ -15,7 +15,6 @@ const staticStyles = StyleSheet.create({
|
|
|
15
15
|
flex: 1, // Grow to maxWidth when possible, shrink when not possible
|
|
16
16
|
position: 'absolute',
|
|
17
17
|
height: 330,
|
|
18
|
-
paddingTop: 5,
|
|
19
18
|
zIndex: 10000 // Position on top of all the other overlays, including backdrops and modals
|
|
20
19
|
},
|
|
21
20
|
closeButtonContainer: {
|
|
@@ -23,6 +22,11 @@ const staticStyles = StyleSheet.create({
|
|
|
23
22
|
top: 0,
|
|
24
23
|
right: 0,
|
|
25
24
|
zIndex: 1
|
|
25
|
+
},
|
|
26
|
+
hidden: {
|
|
27
|
+
// Use opacity not visibility to hide the dropdown during positioning
|
|
28
|
+
// so on web, children may be focused from the first render
|
|
29
|
+
opacity: 0
|
|
26
30
|
}
|
|
27
31
|
})
|
|
28
32
|
|
|
@@ -38,19 +42,31 @@ const selectPaddingContainerStyles = ({ paddingTop, paddingLeft, paddingRight })
|
|
|
38
42
|
paddingRight
|
|
39
43
|
})
|
|
40
44
|
|
|
41
|
-
const ModalOverlay = forwardRef(
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
const ModalOverlay = forwardRef(
|
|
46
|
+
(
|
|
47
|
+
{ children, isReady = false, overlaidPosition, onLayout, variant, tokens, copy, onClose },
|
|
48
|
+
ref
|
|
49
|
+
) => {
|
|
50
|
+
const viewport = useViewport()
|
|
51
|
+
const themeTokens = useThemeTokens('Modal', tokens, variant, { viewport, maxWidth: false })
|
|
44
52
|
|
|
45
|
-
|
|
53
|
+
const { closeIcon: CloseIconComponent, maxWidth } = themeTokens
|
|
46
54
|
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
const getCopy = useCopy({ dictionary, copy })
|
|
56
|
+
const closeLabel = getCopy('closeButton')
|
|
49
57
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
return (
|
|
59
|
+
<Portal>
|
|
60
|
+
<View
|
|
61
|
+
ref={ref}
|
|
62
|
+
onLayout={onLayout}
|
|
63
|
+
style={[
|
|
64
|
+
overlaidPosition,
|
|
65
|
+
{ minWidth: maxWidth },
|
|
66
|
+
staticStyles.positioner,
|
|
67
|
+
!isReady && staticStyles.hidden
|
|
68
|
+
]}
|
|
69
|
+
>
|
|
54
70
|
<Card tokens={selectPaddingContainerStyles(themeTokens)}>
|
|
55
71
|
<View
|
|
56
72
|
style={[
|
|
@@ -70,13 +86,20 @@ const ModalOverlay = forwardRef(({ children, tokens, variant, copy, onClose }, r
|
|
|
70
86
|
</Card>
|
|
71
87
|
</View>
|
|
72
88
|
</Portal>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
)
|
|
76
92
|
ModalOverlay.displayName = 'ModalOverlay'
|
|
77
93
|
|
|
78
94
|
ModalOverlay.propTypes = {
|
|
79
95
|
children: PropTypes.node.isRequired,
|
|
96
|
+
isReady: PropTypes.bool,
|
|
97
|
+
overlaidPosition: PropTypes.shape({
|
|
98
|
+
top: PropTypes.number,
|
|
99
|
+
left: PropTypes.number,
|
|
100
|
+
width: PropTypes.number
|
|
101
|
+
}),
|
|
102
|
+
onLayout: PropTypes.func,
|
|
80
103
|
variant: variantProp.propType,
|
|
81
104
|
tokens: getTokensPropType('Modal'),
|
|
82
105
|
copy: copyPropTypes,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
|
|
4
4
|
import { useThemeTokens, useThemeTokensCallback } from '../ThemeProvider'
|
|
@@ -7,8 +7,10 @@ import {
|
|
|
7
7
|
getTokensPropType,
|
|
8
8
|
getPressHandlersWithArgs,
|
|
9
9
|
selectTokens,
|
|
10
|
+
useOverlaidPosition,
|
|
10
11
|
useCopy,
|
|
11
12
|
useMultipleInputValues,
|
|
13
|
+
useResponsiveProp,
|
|
12
14
|
variantProp
|
|
13
15
|
} from '../utils'
|
|
14
16
|
import dictionary from './dictionary'
|
|
@@ -37,134 +39,149 @@ const selectDividerToknes = ({ dividerColor, width, decorative = true, weight =
|
|
|
37
39
|
weight
|
|
38
40
|
})
|
|
39
41
|
|
|
40
|
-
const MultiSelectFilter =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
maxValues,
|
|
65
|
-
onChange,
|
|
66
|
-
readOnly
|
|
67
|
-
})
|
|
42
|
+
const MultiSelectFilter = ({
|
|
43
|
+
label,
|
|
44
|
+
subtitle,
|
|
45
|
+
id = label,
|
|
46
|
+
variant,
|
|
47
|
+
tokens,
|
|
48
|
+
items = [],
|
|
49
|
+
values,
|
|
50
|
+
initialValues,
|
|
51
|
+
maxValues,
|
|
52
|
+
onChange,
|
|
53
|
+
copy = 'en',
|
|
54
|
+
readOnly = false,
|
|
55
|
+
inactive = false,
|
|
56
|
+
rowLimit = 12,
|
|
57
|
+
...rest
|
|
58
|
+
}) => {
|
|
59
|
+
const { currentValues, setValues } = useMultipleInputValues({
|
|
60
|
+
initialValues,
|
|
61
|
+
values,
|
|
62
|
+
maxValues,
|
|
63
|
+
onChange,
|
|
64
|
+
readOnly
|
|
65
|
+
})
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
const themeTokens = useThemeTokens('ButtonDropdown', tokens, variant)
|
|
68
|
+
const getItemTokens = useThemeTokensCallback('ButtonDropdown', tokens, variant)
|
|
69
|
+
const getButtonTokens = (buttonState) => selectTokens('Button', getItemTokens(buttonState))
|
|
70
|
+
const getCopy = useCopy({ dictionary, copy })
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
const [isOpen, setIsOpen] = useState(false)
|
|
73
|
+
const [checkedIds, setCheckedIds] = useState(currentValues ?? [])
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
const colSize = items.length > rowLimit ? 2 : 1
|
|
76
|
+
const isSelected = currentValues.length > 0
|
|
79
77
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
const uniqueFields = ['id', 'label']
|
|
79
|
+
if (!containUniqueFields(items, uniqueFields)) {
|
|
80
|
+
throw new Error(`MultiSelectFilter items must have unique ${uniqueFields.join(', ')}`)
|
|
81
|
+
}
|
|
84
82
|
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
// Pass an object of relevant component state as first argument for any passed-in press handlers
|
|
84
|
+
const pressHandlers = getPressHandlersWithArgs(rest, [{ id, label, currentValues }])
|
|
87
85
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
const handleChange = (event) => {
|
|
87
|
+
if (pressHandlers.onPress) pressHandlers?.onPress(event)
|
|
88
|
+
setIsOpen(!isOpen)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const onApply = (e) => {
|
|
92
|
+
setValues(e)
|
|
93
|
+
setIsOpen(false)
|
|
94
|
+
}
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
const { align, offsets } = useResponsiveProp({
|
|
97
|
+
xs: { align: { top: 'top', left: 'left', bottom: 'bottom', right: 'right' } },
|
|
98
|
+
sm: {
|
|
99
|
+
align: { top: 'bottom', left: 'left' },
|
|
100
|
+
offsets: { vertical: 4 }
|
|
96
101
|
}
|
|
102
|
+
})
|
|
97
103
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
{
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
onChange={(e) => setCheckedIds(e, i)}
|
|
140
|
-
/>
|
|
141
|
-
<Spacer size={4} />
|
|
142
|
-
</Col>
|
|
143
|
-
))}
|
|
104
|
+
const { overlaidPosition, onTargetLayout, isReady, sourceRef } = useOverlaidPosition({
|
|
105
|
+
isShown: isOpen,
|
|
106
|
+
offsets,
|
|
107
|
+
align
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<>
|
|
112
|
+
<ButtonDropdown
|
|
113
|
+
ref={sourceRef}
|
|
114
|
+
key={id}
|
|
115
|
+
{...pressHandlers}
|
|
116
|
+
value={isOpen}
|
|
117
|
+
selected={isSelected}
|
|
118
|
+
label={label}
|
|
119
|
+
onChange={handleChange}
|
|
120
|
+
tokens={getButtonTokens}
|
|
121
|
+
inactive={inactive}
|
|
122
|
+
/>
|
|
123
|
+
{isOpen && (
|
|
124
|
+
<ModalOverlay
|
|
125
|
+
overlaidPosition={overlaidPosition}
|
|
126
|
+
variant={{ width: colSize > 1 ? 'size576' : 's' }}
|
|
127
|
+
onClose={() => setIsOpen(false)}
|
|
128
|
+
tokens={tokens}
|
|
129
|
+
copy={copy}
|
|
130
|
+
isReady={isReady}
|
|
131
|
+
onLayout={onTargetLayout}
|
|
132
|
+
>
|
|
133
|
+
<Row>
|
|
134
|
+
<Typography variant={{ size: 'h4' }}>
|
|
135
|
+
{getCopy('filterByLabel').replace(/%\{filterCategory\}/g, label.toLowerCase())}
|
|
136
|
+
</Typography>
|
|
137
|
+
</Row>
|
|
138
|
+
{subtitle && (
|
|
139
|
+
<>
|
|
140
|
+
<Spacer space={5} />
|
|
141
|
+
<Row>
|
|
142
|
+
<Typography variant={{ size: 'h5' }} tokens={selectSubTitleTokens(themeTokens)}>
|
|
143
|
+
{subtitle}
|
|
144
|
+
</Typography>
|
|
144
145
|
</Row>
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
</StackView>
|
|
146
|
+
</>
|
|
147
|
+
)}
|
|
148
|
+
<Spacer space={4} />
|
|
149
|
+
<Box scroll={true}>
|
|
150
|
+
<Row distribute="between">
|
|
151
|
+
{[...Array(colSize).keys()].map((i) => (
|
|
152
|
+
<Col xs={12 / colSize} key={i}>
|
|
153
|
+
<CheckboxGroup
|
|
154
|
+
items={items.slice(i * rowLimit, (i + 1) * rowLimit)}
|
|
155
|
+
checkedIds={checkedIds}
|
|
156
|
+
onChange={(e) => setCheckedIds(e, i)}
|
|
157
|
+
/>
|
|
158
|
+
<Spacer size={4} />
|
|
159
|
+
</Col>
|
|
160
|
+
))}
|
|
161
161
|
</Row>
|
|
162
|
-
</
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
)
|
|
162
|
+
</Box>
|
|
163
|
+
<Divider variant={selectDividerToknes({ ...themeTokens, width: 'full' })} space={4} />
|
|
164
|
+
<Row>
|
|
165
|
+
<StackView direction="row" space={3} tokens={{ alignItems: 'center' }}>
|
|
166
|
+
<Button
|
|
167
|
+
onPress={() => onApply(checkedIds)}
|
|
168
|
+
variant={{ size: 'small', priority: 'high' }}
|
|
169
|
+
>
|
|
170
|
+
{getCopy('applyButtonLabel')}
|
|
171
|
+
</Button>
|
|
172
|
+
<Box>
|
|
173
|
+
<TextButton onPress={() => setCheckedIds([])}>
|
|
174
|
+
{getCopy('clearButtonLabel')}
|
|
175
|
+
</TextButton>
|
|
176
|
+
</Box>
|
|
177
|
+
</StackView>
|
|
178
|
+
</Row>
|
|
179
|
+
</ModalOverlay>
|
|
180
|
+
)}
|
|
181
|
+
</>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
168
185
|
MultiSelectFilter.displayName = 'MultiSelectFilter'
|
|
169
186
|
|
|
170
187
|
MultiSelectFilter.propTypes = {
|
package/src/utils/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { default as useCopy } from './useCopy'
|
|
|
10
10
|
export { default as useHash } from './useHash'
|
|
11
11
|
export { default as useSpacingScale } from './useSpacingScale'
|
|
12
12
|
export { default as useResponsiveProp } from './useResponsiveProp'
|
|
13
|
+
export { default as useOverlaidPosition } from './useOverlaidPosition'
|
|
13
14
|
export { default as useSafeLayoutEffect } from './useSafeLayoutEffect'
|
|
14
15
|
export { default as useScrollBlocking } from './useScrollBlocking'
|
|
15
16
|
export * from './useResponsiveProp'
|