@hero-design/rn 8.3.0 → 8.3.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/.turbo/turbo-build.log +9 -9
- package/es/index.js +88 -88
- package/lib/index.js +85 -85
- package/package.json +5 -5
- package/src/components/Carousel/CarouselItem.tsx +1 -6
- package/src/components/Carousel/CarouselPaginator/StyledCarouselPaginator.tsx +10 -9
- package/src/components/Carousel/CarouselPaginator/index.tsx +2 -3
- package/src/components/Carousel/StyledCarousel.tsx +9 -6
- package/src/components/Carousel/__tests__/StyledCarousel.spec.tsx +3 -3
- package/src/components/Carousel/__tests__/__snapshots__/StyledCarousel.spec.tsx.snap +1 -2
- package/src/components/Carousel/__tests__/__snapshots__/index.spec.tsx.snap +600 -0
- package/src/components/Carousel/__tests__/index.spec.tsx +15 -7
- package/src/components/Carousel/index.tsx +65 -84
- package/src/components/TextInput/index.tsx +199 -197
- package/src/components/Typography/Text/StyledText.tsx +1 -0
- package/src/components/Typography/Text/index.tsx +1 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +9 -2
- package/src/theme/components/carousel.ts +5 -2
- package/src/theme/components/typography.ts +2 -0
- package/src/theme/global/typography.ts +3 -0
- package/types/components/Carousel/CarouselItem.d.ts +1 -2
- package/types/components/Carousel/CarouselPaginator/StyledCarouselPaginator.d.ts +0 -2
- package/types/components/Carousel/StyledCarousel.d.ts +6 -4
- package/types/components/Carousel/index.d.ts +9 -23
- package/types/components/TextInput/index.d.ts +2 -2
- package/types/components/Typography/Text/StyledText.d.ts +1 -1
- package/types/components/Typography/Text/index.d.ts +1 -1
- package/types/theme/components/carousel.d.ts +3 -0
- package/types/theme/components/typography.d.ts +2 -0
- package/types/theme/global/typography.d.ts +1 -0
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
Dispatch,
|
|
3
|
+
SetStateAction,
|
|
4
|
+
useCallback,
|
|
5
|
+
useRef,
|
|
6
|
+
useEffect,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
2
9
|
import {
|
|
3
10
|
Animated,
|
|
4
11
|
FlatList,
|
|
5
12
|
StyleProp,
|
|
6
13
|
useWindowDimensions,
|
|
14
|
+
View,
|
|
7
15
|
ViewProps,
|
|
8
16
|
ViewStyle,
|
|
9
17
|
} from 'react-native';
|
|
@@ -11,11 +19,10 @@ import {
|
|
|
11
19
|
import { CarouselData } from './types';
|
|
12
20
|
import CarouselPaginator from './CarouselPaginator';
|
|
13
21
|
import {
|
|
14
|
-
|
|
22
|
+
StyledBackDrop,
|
|
15
23
|
StyledCarouselFooterWrapper,
|
|
16
24
|
StyledCarouselView,
|
|
17
25
|
} from './StyledCarousel';
|
|
18
|
-
import Button from '../Button';
|
|
19
26
|
import CarouselItem from './CarouselItem';
|
|
20
27
|
|
|
21
28
|
interface CarouselProps extends ViewProps {
|
|
@@ -27,101 +34,86 @@ interface CarouselProps extends ViewProps {
|
|
|
27
34
|
* Testing id of the component.
|
|
28
35
|
*/
|
|
29
36
|
testID?: string;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Callback to be called when the user slides to the next slide.
|
|
33
|
-
*/
|
|
34
|
-
onSlideChange?: (currentSlide?: CarouselData) => void;
|
|
35
|
-
|
|
36
37
|
/**
|
|
37
|
-
*
|
|
38
|
+
* onItemIndexChange event handler receiving index of selected Item.
|
|
38
39
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Callback to be called when the user finishes the intro carousel.
|
|
43
|
-
*/
|
|
44
|
-
onFinishPress?: (currentSlide?: CarouselData) => void;
|
|
45
|
-
|
|
40
|
+
onItemIndexChange?: Dispatch<SetStateAction<number>>;
|
|
46
41
|
/**
|
|
47
42
|
* Carousel data.
|
|
48
43
|
*/
|
|
49
44
|
items: CarouselData[];
|
|
50
|
-
|
|
51
45
|
/**
|
|
52
|
-
*
|
|
46
|
+
* Render action elements function.
|
|
53
47
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
renderActions?: (pageIndex: number) => JSX.Element;
|
|
56
49
|
/**
|
|
57
|
-
*
|
|
50
|
+
* Current selected item index.
|
|
58
51
|
*/
|
|
59
|
-
|
|
52
|
+
selectedItemIndex?: number;
|
|
53
|
+
}
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
export function useStateFromProp<T>(
|
|
56
|
+
initialValue: T
|
|
57
|
+
): [T, Dispatch<SetStateAction<T>>] {
|
|
58
|
+
const [value, setValue] = useState(initialValue);
|
|
65
59
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
minContentHeight?: number;
|
|
60
|
+
useEffect(() => setValue(initialValue), [initialValue]);
|
|
61
|
+
|
|
62
|
+
return [value, setValue];
|
|
70
63
|
}
|
|
71
64
|
|
|
72
65
|
const Carousel = ({
|
|
73
66
|
items,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
skipButtonLabel = 'Skip',
|
|
79
|
-
footerHeight = 70,
|
|
80
|
-
minContentHeight = 250,
|
|
67
|
+
onItemIndexChange,
|
|
68
|
+
renderActions,
|
|
69
|
+
selectedItemIndex = 0,
|
|
70
|
+
style,
|
|
81
71
|
...nativeProps
|
|
82
72
|
}: CarouselProps) => {
|
|
83
|
-
const carouselRef = useRef(null);
|
|
84
|
-
const [currentSlideIndex, setCurrentSlideIndex] = useState(0);
|
|
85
|
-
const { width } = useWindowDimensions();
|
|
73
|
+
const carouselRef = useRef<FlatList>(null);
|
|
86
74
|
|
|
87
|
-
const
|
|
75
|
+
const [currentSlideIndex, setCurrentSlideIndex] =
|
|
76
|
+
useStateFromProp(selectedItemIndex);
|
|
88
77
|
|
|
89
|
-
const
|
|
90
|
-
(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const currentSlide = items[currentIndex];
|
|
95
|
-
if (onSlideChange) {
|
|
96
|
-
onSlideChange(currentSlide);
|
|
78
|
+
const internalOnItemIndexChange = useCallback(
|
|
79
|
+
(index: number) => {
|
|
80
|
+
setCurrentSlideIndex(index);
|
|
81
|
+
if (onItemIndexChange) {
|
|
82
|
+
onItemIndexChange(index);
|
|
97
83
|
}
|
|
98
84
|
},
|
|
99
|
-
[
|
|
85
|
+
[setCurrentSlideIndex, onItemIndexChange]
|
|
100
86
|
);
|
|
87
|
+
const { width } = useWindowDimensions();
|
|
101
88
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
89
|
+
const scrollX = useRef(new Animated.Value(0)).current;
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
// must use setTimeout since when layout is mounted, the pagination dots are not set correct scrollX
|
|
92
|
+
const handle = setTimeout(() => {
|
|
93
|
+
scrollX.setValue(currentSlideIndex * width);
|
|
94
|
+
carouselRef.current?.scrollToOffset({
|
|
95
|
+
offset: currentSlideIndex * width,
|
|
96
|
+
animated: true,
|
|
97
|
+
});
|
|
98
|
+
}, 100);
|
|
99
|
+
return () => {
|
|
100
|
+
clearTimeout(handle);
|
|
101
|
+
};
|
|
102
|
+
}, [currentSlideIndex, carouselRef]);
|
|
103
|
+
|
|
104
|
+
const visibleSlideChanged = useCallback(({ viewableItems }) => {
|
|
105
|
+
if (!viewableItems || (viewableItems && !viewableItems.length)) return;
|
|
106
|
+
const { index } = viewableItems[0];
|
|
107
|
+
internalOnItemIndexChange(index);
|
|
108
|
+
}, []);
|
|
115
109
|
|
|
116
110
|
const viewConfig = useRef({ viewAreaCoveragePercentThreshold: 50 }).current;
|
|
117
111
|
|
|
118
|
-
const isLastSlide = currentSlideIndex === items.length - 1;
|
|
119
|
-
|
|
120
112
|
return (
|
|
121
|
-
<
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
113
|
+
<View style={style} {...nativeProps}>
|
|
114
|
+
<StyledBackDrop
|
|
115
|
+
themeSlideBackground={items[currentSlideIndex].background}
|
|
116
|
+
/>
|
|
125
117
|
<StyledCarouselView>
|
|
126
118
|
<FlatList
|
|
127
119
|
horizontal
|
|
@@ -148,28 +140,17 @@ const Carousel = ({
|
|
|
148
140
|
heading={heading}
|
|
149
141
|
body={body}
|
|
150
142
|
content={content}
|
|
151
|
-
minHeight={minContentHeight}
|
|
152
143
|
width={width}
|
|
153
144
|
/>
|
|
154
145
|
);
|
|
155
146
|
}}
|
|
156
147
|
/>
|
|
157
|
-
<StyledCarouselFooterWrapper
|
|
158
|
-
|
|
159
|
-
flexDirection="row"
|
|
160
|
-
justifyContent="space-between"
|
|
161
|
-
style={{ height: footerHeight }}
|
|
162
|
-
>
|
|
163
|
-
<Button
|
|
164
|
-
variant={isLastSlide ? 'filled' : 'text'}
|
|
165
|
-
intent="primary"
|
|
166
|
-
onPress={isLastSlide ? finishCarousel : skipCarousel}
|
|
167
|
-
text={isLastSlide ? finishButtonLabel : skipButtonLabel}
|
|
168
|
-
/>
|
|
148
|
+
<StyledCarouselFooterWrapper>
|
|
149
|
+
{renderActions && renderActions(currentSlideIndex)}
|
|
169
150
|
<CarouselPaginator numberOfSlides={items.length} scrollX={scrollX} />
|
|
170
151
|
</StyledCarouselFooterWrapper>
|
|
171
152
|
</StyledCarouselView>
|
|
172
|
-
</
|
|
153
|
+
</View>
|
|
173
154
|
);
|
|
174
155
|
};
|
|
175
156
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
1
|
+
import React, { useMemo, forwardRef } from 'react';
|
|
2
2
|
import { StyleSheet, TextInput as RNTextInput } from 'react-native';
|
|
3
3
|
import type {
|
|
4
4
|
TextInputProps as NativeTextInputProps,
|
|
@@ -141,225 +141,227 @@ export const getVariant = ({
|
|
|
141
141
|
// https://github.com/callstack/react-native-paper/pull/3331
|
|
142
142
|
const EMPTY_PLACEHOLDER_VALUE = ' ';
|
|
143
143
|
|
|
144
|
-
const TextInput = (
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
144
|
+
const TextInput = forwardRef<TextInputHandles, TextInputProps>(
|
|
145
|
+
(
|
|
146
|
+
{
|
|
147
|
+
label,
|
|
148
|
+
prefix,
|
|
149
|
+
suffix,
|
|
150
|
+
style,
|
|
151
|
+
textStyle,
|
|
152
|
+
testID,
|
|
153
|
+
accessibilityLabelledBy,
|
|
154
|
+
error,
|
|
155
|
+
required,
|
|
156
|
+
editable = true,
|
|
157
|
+
disabled = false,
|
|
158
|
+
loading = false,
|
|
159
|
+
maxLength,
|
|
160
|
+
helpText,
|
|
161
|
+
value,
|
|
162
|
+
defaultValue,
|
|
163
|
+
renderInputValue,
|
|
164
|
+
...nativeProps
|
|
165
|
+
}: TextInputProps,
|
|
166
|
+
ref?: React.Ref<TextInputHandles>
|
|
167
|
+
) => {
|
|
168
|
+
const displayText = (value !== undefined ? value : defaultValue) ?? '';
|
|
169
|
+
const isEmptyValue = displayText.length === 0;
|
|
170
|
+
const actualSuffix = loading ? 'loading' : suffix;
|
|
170
171
|
|
|
171
|
-
|
|
172
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
172
173
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
174
|
+
const variant = getVariant({
|
|
175
|
+
disabled,
|
|
176
|
+
error,
|
|
177
|
+
editable,
|
|
178
|
+
loading,
|
|
179
|
+
isFocused,
|
|
180
|
+
isEmptyValue,
|
|
181
|
+
});
|
|
181
182
|
|
|
182
|
-
|
|
183
|
+
const shouldShowMaxLength = maxLength !== undefined;
|
|
183
184
|
|
|
184
|
-
|
|
185
|
+
const theme = useTheme();
|
|
185
186
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
187
|
+
const innerTextInput = React.useRef<RNTextInput | undefined | null>();
|
|
188
|
+
React.useImperativeHandle(
|
|
189
|
+
ref,
|
|
190
|
+
() => ({
|
|
191
|
+
// we don't expose this method, it's for testing https://medium.com/developer-rants/how-to-test-useref-without-mocking-useref-699165f4994e
|
|
192
|
+
getNativeTextInputRef: () => innerTextInput.current,
|
|
193
|
+
focus: () => {
|
|
194
|
+
innerTextInput.current?.focus();
|
|
195
|
+
},
|
|
196
|
+
clear: () => innerTextInput.current?.clear(),
|
|
197
|
+
setNativeProps: (args: NativeTextInputProps) =>
|
|
198
|
+
innerTextInput.current?.setNativeProps(args),
|
|
199
|
+
isFocused: () => innerTextInput.current?.isFocused() || false,
|
|
200
|
+
blur: () => innerTextInput.current?.blur(),
|
|
201
|
+
}),
|
|
202
|
+
[innerTextInput]
|
|
203
|
+
);
|
|
203
204
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
const { borderStyle, textStyleWithoutBorderStyle } = useMemo(() => {
|
|
206
|
+
if (!textStyle) {
|
|
207
|
+
return {};
|
|
208
|
+
}
|
|
208
209
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
210
|
+
const flattenTextStyle = StyleSheet.flatten(textStyle);
|
|
211
|
+
const borderKeys = Object.keys(flattenTextStyle).filter((key) => {
|
|
212
|
+
return key.startsWith('border');
|
|
213
|
+
}) as Array<keyof TextStyle>;
|
|
214
|
+
return {
|
|
215
|
+
borderStyle: pick(borderKeys, flattenTextStyle),
|
|
216
|
+
textStyleWithoutBorderStyle: omit(borderKeys, flattenTextStyle),
|
|
217
|
+
};
|
|
218
|
+
}, [textStyle]);
|
|
218
219
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
220
|
+
const nativeInputProps: NativeTextInputProps = {
|
|
221
|
+
style: StyleSheet.flatten([
|
|
222
|
+
{ color: theme.__hd__.textInput.colors.text },
|
|
223
|
+
textStyleWithoutBorderStyle,
|
|
224
|
+
]),
|
|
225
|
+
testID: 'text-input',
|
|
226
|
+
accessibilityState: {
|
|
227
|
+
disabled: variant === 'disabled' || variant === 'readonly',
|
|
228
|
+
},
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
230
|
+
// @ts-ignore
|
|
231
|
+
accessibilityLabelledBy,
|
|
232
|
+
...nativeProps,
|
|
233
|
+
onFocus: (event) => {
|
|
234
|
+
setIsFocused(true);
|
|
235
|
+
nativeProps.onFocus?.(event);
|
|
236
|
+
},
|
|
237
|
+
onBlur: (event) => {
|
|
238
|
+
setIsFocused(false);
|
|
239
|
+
nativeProps.onBlur?.(event);
|
|
240
|
+
},
|
|
241
|
+
editable,
|
|
242
|
+
maxLength,
|
|
243
|
+
value,
|
|
244
|
+
onChangeText: (text) => {
|
|
245
|
+
nativeProps.onChangeText?.(text);
|
|
246
|
+
},
|
|
247
|
+
defaultValue,
|
|
248
|
+
placeholder:
|
|
249
|
+
isFocused || label === undefined
|
|
250
|
+
? nativeProps.placeholder
|
|
251
|
+
: EMPTY_PLACEHOLDER_VALUE,
|
|
252
|
+
};
|
|
252
253
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
/>
|
|
267
|
-
{(isFocused || (label && !isEmptyValue)) && (
|
|
268
|
-
<StyledLabelContainer pointerEvents="none">
|
|
269
|
-
{required && (
|
|
270
|
-
<StyledAsteriskLabel themeVariant={variant} fontSize="small">
|
|
271
|
-
*
|
|
272
|
-
</StyledAsteriskLabel>
|
|
273
|
-
)}
|
|
274
|
-
{!!label && (
|
|
275
|
-
<StyledLabel
|
|
276
|
-
nativeID={accessibilityLabelledBy}
|
|
277
|
-
testID="input-label"
|
|
278
|
-
fontSize="small"
|
|
279
|
-
themeVariant={variant}
|
|
280
|
-
>
|
|
281
|
-
{label}
|
|
282
|
-
</StyledLabel>
|
|
283
|
-
)}
|
|
284
|
-
</StyledLabelContainer>
|
|
285
|
-
)}
|
|
286
|
-
{typeof prefix === 'string' ? (
|
|
287
|
-
<Icon
|
|
288
|
-
intent={variant === 'disabled' ? 'disabled-text' : 'text'}
|
|
289
|
-
testID="input-prefix"
|
|
290
|
-
icon={prefix}
|
|
291
|
-
size="xsmall"
|
|
254
|
+
return (
|
|
255
|
+
<StyledContainer
|
|
256
|
+
style={style}
|
|
257
|
+
pointerEvents={
|
|
258
|
+
variant === 'disabled' || variant === 'readonly' ? 'none' : 'auto'
|
|
259
|
+
}
|
|
260
|
+
testID={testID}
|
|
261
|
+
>
|
|
262
|
+
<StyledTextInputContainer>
|
|
263
|
+
<StyledBorderBackDrop
|
|
264
|
+
themeFocused={isFocused}
|
|
265
|
+
themeVariant={variant}
|
|
266
|
+
style={borderStyle}
|
|
292
267
|
/>
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
)}
|
|
296
|
-
<StyledTextInputAndLabelContainer>
|
|
297
|
-
{!isFocused && isEmptyValue && (
|
|
298
|
-
<StyledLabelContainerInsideTextInput pointerEvents="none">
|
|
268
|
+
{(isFocused || (label && !isEmptyValue)) && (
|
|
269
|
+
<StyledLabelContainer pointerEvents="none">
|
|
299
270
|
{required && (
|
|
300
|
-
<
|
|
271
|
+
<StyledAsteriskLabel themeVariant={variant} fontSize="small">
|
|
301
272
|
*
|
|
302
|
-
</
|
|
273
|
+
</StyledAsteriskLabel>
|
|
303
274
|
)}
|
|
304
275
|
{!!label && (
|
|
305
|
-
<
|
|
276
|
+
<StyledLabel
|
|
306
277
|
nativeID={accessibilityLabelledBy}
|
|
307
278
|
testID="input-label"
|
|
308
|
-
fontSize="
|
|
279
|
+
fontSize="small"
|
|
309
280
|
themeVariant={variant}
|
|
310
281
|
>
|
|
311
282
|
{label}
|
|
312
|
-
</
|
|
283
|
+
</StyledLabel>
|
|
313
284
|
)}
|
|
314
|
-
</
|
|
285
|
+
</StyledLabelContainer>
|
|
315
286
|
)}
|
|
316
|
-
{
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
{
|
|
321
|
-
|
|
322
|
-
innerTextInput.current = reference;
|
|
323
|
-
}}
|
|
287
|
+
{typeof prefix === 'string' ? (
|
|
288
|
+
<Icon
|
|
289
|
+
intent={variant === 'disabled' ? 'disabled-text' : 'text'}
|
|
290
|
+
testID="input-prefix"
|
|
291
|
+
icon={prefix}
|
|
292
|
+
size="xsmall"
|
|
324
293
|
/>
|
|
294
|
+
) : (
|
|
295
|
+
prefix
|
|
325
296
|
)}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
297
|
+
<StyledTextInputAndLabelContainer>
|
|
298
|
+
{!isFocused && isEmptyValue && (
|
|
299
|
+
<StyledLabelContainerInsideTextInput pointerEvents="none">
|
|
300
|
+
{required && (
|
|
301
|
+
<StyledAsteriskLabelInsideTextInput themeVariant={variant}>
|
|
302
|
+
*
|
|
303
|
+
</StyledAsteriskLabelInsideTextInput>
|
|
304
|
+
)}
|
|
305
|
+
{!!label && (
|
|
306
|
+
<StyledLabelInsideTextInput
|
|
307
|
+
nativeID={accessibilityLabelledBy}
|
|
308
|
+
testID="input-label"
|
|
309
|
+
fontSize="medium"
|
|
310
|
+
themeVariant={variant}
|
|
311
|
+
>
|
|
312
|
+
{label}
|
|
313
|
+
</StyledLabelInsideTextInput>
|
|
314
|
+
)}
|
|
315
|
+
</StyledLabelContainerInsideTextInput>
|
|
316
|
+
)}
|
|
317
|
+
{renderInputValue ? (
|
|
318
|
+
renderInputValue(nativeInputProps)
|
|
319
|
+
) : (
|
|
320
|
+
<StyledTextInput
|
|
321
|
+
{...nativeInputProps}
|
|
322
|
+
ref={(reference) => {
|
|
323
|
+
innerTextInput.current = reference;
|
|
324
|
+
}}
|
|
348
325
|
/>
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
{
|
|
356
|
-
|
|
326
|
+
)}
|
|
327
|
+
</StyledTextInputAndLabelContainer>
|
|
328
|
+
{typeof actualSuffix === 'string' ? (
|
|
329
|
+
<Icon
|
|
330
|
+
intent={variant === 'disabled' ? 'disabled-text' : 'text'}
|
|
331
|
+
testID="input-suffix"
|
|
332
|
+
icon={actualSuffix}
|
|
333
|
+
spin={actualSuffix === 'loading'}
|
|
334
|
+
size="xsmall"
|
|
335
|
+
/>
|
|
336
|
+
) : (
|
|
337
|
+
suffix
|
|
357
338
|
)}
|
|
358
|
-
</
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
339
|
+
</StyledTextInputContainer>
|
|
340
|
+
<StyledErrorAndHelpTextContainer>
|
|
341
|
+
<StyledErrorAndMaxLengthContainer>
|
|
342
|
+
{!!error && (
|
|
343
|
+
<StyledErrorContainer>
|
|
344
|
+
<Icon
|
|
345
|
+
testID="input-error-icon"
|
|
346
|
+
icon="circle-info"
|
|
347
|
+
size="xsmall"
|
|
348
|
+
intent="danger"
|
|
349
|
+
/>
|
|
350
|
+
|
|
351
|
+
<StyledError testID="input-error-message">{error}</StyledError>
|
|
352
|
+
</StyledErrorContainer>
|
|
353
|
+
)}
|
|
354
|
+
{shouldShowMaxLength && (
|
|
355
|
+
<StyledMaxLengthMessage themeVariant={variant} fontSize="small">
|
|
356
|
+
{displayText.length}/{maxLength}
|
|
357
|
+
</StyledMaxLengthMessage>
|
|
358
|
+
)}
|
|
359
|
+
</StyledErrorAndMaxLengthContainer>
|
|
360
|
+
{!!helpText && <StyledHelperText>{helpText}</StyledHelperText>}
|
|
361
|
+
</StyledErrorAndHelpTextContainer>
|
|
362
|
+
</StyledContainer>
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
);
|
|
364
366
|
|
|
365
|
-
export default
|
|
367
|
+
export default TextInput;
|