sapo-components-ui-rn 1.0.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/README.md +69 -0
- package/dist/assets/error.png +0 -0
- package/dist/assets/icon-checkbox-active.svg +4 -0
- package/dist/assets/icon-checkbox.svg +3 -0
- package/dist/assets/image_default.png +0 -0
- package/dist/assets/images/error.png +0 -0
- package/dist/assets/images/image_default.png +0 -0
- package/dist/assets/images/info.png +0 -0
- package/dist/assets/images/success.png +0 -0
- package/dist/assets/images/warning.png +0 -0
- package/dist/assets/info.png +0 -0
- package/dist/assets/success.png +0 -0
- package/dist/assets/svg/icon-checkbox-active.svg +4 -0
- package/dist/assets/svg/icon-checkbox.svg +3 -0
- package/dist/assets/warning.png +0 -0
- package/dist/components/ActivityIndicator.d.ts +28 -0
- package/dist/components/Avatar/index.d.ts +17 -0
- package/dist/components/Badge/index.d.ts +13 -0
- package/dist/components/Button/index.d.ts +23 -0
- package/dist/components/ButtonIcon/index.d.ts +18 -0
- package/dist/components/Checkbox/index.d.ts +14 -0
- package/dist/components/ChipBar/index.d.ts +16 -0
- package/dist/components/CountingDot/index.d.ts +13 -0
- package/dist/components/FloatingButton/index.d.ts +17 -0
- package/dist/components/Icon/index.d.ts +17 -0
- package/dist/components/IconSvg/index.d.ts +12 -0
- package/dist/components/Image/index.d.ts +14 -0
- package/dist/components/ProgressBar.d.ts +42 -0
- package/dist/components/RadioButton/index.d.ts +13 -0
- package/dist/components/ScaleButton/index.d.ts +4 -0
- package/dist/components/SelectionField/index.d.ts +24 -0
- package/dist/components/Spacer/index.d.ts +9 -0
- package/dist/components/Switch/Switch.d.ts +47 -0
- package/dist/components/Switch/utils.d.ts +14 -0
- package/dist/components/Text/index.d.ts +14 -0
- package/dist/components/TextInput/Addons/Outline.d.ts +15 -0
- package/dist/components/TextInput/Addons/Underline.d.ts +19 -0
- package/dist/components/TextInput/Adornment/TextInputAdornment.d.ts +43 -0
- package/dist/components/TextInput/Adornment/TextInputAffix.d.ts +72 -0
- package/dist/components/TextInput/Adornment/enums.d.ts +12 -0
- package/dist/components/TextInput/Adornment/types.d.ts +11 -0
- package/dist/components/TextInput/Adornment/utils.d.ts +11 -0
- package/dist/components/TextInput/Label/InputLabel.d.ts +4 -0
- package/dist/components/TextInput/Label/LabelBackground.d.ts +4 -0
- package/dist/components/TextInput/TextInput.d.ts +171 -0
- package/dist/components/TextInput/TextInputDefault.d.ts +4 -0
- package/dist/components/TextInput/TextInputFlat.d.ts +4 -0
- package/dist/components/TextInput/constants.d.ts +31 -0
- package/dist/components/TextInput/helpers.d.ts +95 -0
- package/dist/components/TextInput/types.d.ts +154 -0
- package/dist/components/Toast/ToastProvider.d.ts +21 -0
- package/dist/components/Toast/index.d.ts +3 -0
- package/dist/components/Typography/AnimatedText.d.ts +34 -0
- package/dist/components/Typography/StyledText.d.ts +12 -0
- package/dist/components/Typography/Text.d.ts +35 -0
- package/dist/components/Typography/types.d.ts +2 -0
- package/dist/components/View/index.d.ts +38 -0
- package/dist/components/ViewVisibleAnimated/index.d.ts +25 -0
- package/dist/constants.d.ts +1 -0
- package/dist/core/theming.d.ts +43 -0
- package/dist/icons/IconArrowDown.d.ts +4 -0
- package/dist/icons/IconCheckbox.d.ts +4 -0
- package/dist/icons/IconCheckboxActive.d.ts +4 -0
- package/dist/icons/IconClearText.d.ts +4 -0
- package/dist/icons/IconRadio.d.ts +4 -0
- package/dist/icons/IconRadioActive.d.ts +4 -0
- package/dist/icons/IconRadioDisable.d.ts +4 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.esm.js +6758 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +6823 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/fonts.d.ts +78 -0
- package/dist/styles/overlay.d.ts +3 -0
- package/dist/styles/shadow.d.ts +18 -0
- package/dist/styles/themes/DarkTheme.d.ts +2 -0
- package/dist/styles/themes/LightTheme.d.ts +2 -0
- package/dist/styles/themes/index.d.ts +2 -0
- package/dist/styles/themes/tokens.d.ts +830 -0
- package/dist/theme/blue.d.ts +14 -0
- package/dist/theme/colors.d.ts +99 -0
- package/dist/theme/container-styles.d.ts +124 -0
- package/dist/theme/dimensions.d.ts +36 -0
- package/dist/theme/green.d.ts +15 -0
- package/dist/theme/icon.d.ts +5 -0
- package/dist/theme/ink.d.ts +11 -0
- package/dist/theme/orange.d.ts +14 -0
- package/dist/theme/purple.d.ts +6 -0
- package/dist/theme/red.d.ts +15 -0
- package/dist/theme/themes.d.ts +277 -0
- package/dist/theme/white.d.ts +10 -0
- package/dist/theme/yellow.d.ts +15 -0
- package/dist/types/index.d.ts +65 -0
- package/dist/types.d.ts +220 -0
- package/dist/utils/BackHandler/BackHandler.d.ts +9 -0
- package/dist/utils/BackHandler/BackHandler.native.d.ts +2 -0
- package/dist/utils/addEventListener.d.ts +12 -0
- package/dist/utils/forwardRef.d.ts +11 -0
- package/dist/utils/function-utils.d.ts +12 -0
- package/dist/utils/getContrastingColor.d.ts +2 -0
- package/dist/utils/hasTouchHandler.d.ts +5 -0
- package/dist/utils/roundLayoutSize.d.ts +1 -0
- package/dist/utils/splitStyles.d.ts +19 -0
- package/dist/utils/toast-manager.d.ts +21 -0
- package/dist/utils/useAnimatedValue.d.ts +2 -0
- package/dist/utils/useAnimatedValueArray.d.ts +2 -0
- package/dist/utils/useIsKeyboardShown.d.ts +6 -0
- package/dist/utils/useLayout.d.ts +6 -0
- package/dist/utils/useLazyRef.d.ts +2 -0
- package/package.json +104 -0
- package/src/.DS_Store +0 -0
- package/src/assets/images/error.png +0 -0
- package/src/assets/images/image_default.png +0 -0
- package/src/assets/images/info.png +0 -0
- package/src/assets/images/success.png +0 -0
- package/src/assets/images/warning.png +0 -0
- package/src/assets/svg/icon-checkbox-active.svg +4 -0
- package/src/assets/svg/icon-checkbox.svg +3 -0
- package/src/babel/.eslintrc +7 -0
- package/src/babel/index.js +63 -0
- package/src/components/.DS_Store +0 -0
- package/src/components/ActivityIndicator.tsx +238 -0
- package/src/components/Avatar/index.tsx +102 -0
- package/src/components/Badge/index.tsx +55 -0
- package/src/components/Button/index.tsx +162 -0
- package/src/components/ButtonIcon/index.tsx +98 -0
- package/src/components/Checkbox/index.tsx +107 -0
- package/src/components/ChipBar/index.tsx +112 -0
- package/src/components/CountingDot/index.tsx +63 -0
- package/src/components/FloatingButton/index.tsx +99 -0
- package/src/components/Icon/index.tsx +135 -0
- package/src/components/IconSvg/index.tsx +42 -0
- package/src/components/Image/index.tsx +127 -0
- package/src/components/ProgressBar.tsx +272 -0
- package/src/components/RadioButton/index.tsx +105 -0
- package/src/components/ScaleButton/index.tsx +17 -0
- package/src/components/SelectionField/index.tsx +166 -0
- package/src/components/Spacer/index.tsx +19 -0
- package/src/components/Switch/Switch.tsx +110 -0
- package/src/components/Switch/utils.ts +96 -0
- package/src/components/Text/index.tsx +69 -0
- package/src/components/TextInput/.DS_Store +0 -0
- package/src/components/TextInput/Addons/Outline.tsx +62 -0
- package/src/components/TextInput/Addons/Underline.tsx +71 -0
- package/src/components/TextInput/Adornment/TextInputAdornment.tsx +191 -0
- package/src/components/TextInput/Adornment/TextInputAffix.tsx +212 -0
- package/src/components/TextInput/Adornment/enums.tsx +12 -0
- package/src/components/TextInput/Adornment/types.tsx +11 -0
- package/src/components/TextInput/Adornment/utils.ts +39 -0
- package/src/components/TextInput/Label/InputLabel.tsx +216 -0
- package/src/components/TextInput/Label/LabelBackground.tsx +100 -0
- package/src/components/TextInput/TextInput.tsx +564 -0
- package/src/components/TextInput/TextInputDefault.tsx +187 -0
- package/src/components/TextInput/TextInputFlat.tsx +452 -0
- package/src/components/TextInput/constants.tsx +48 -0
- package/src/components/TextInput/helpers.tsx +546 -0
- package/src/components/TextInput/types.tsx +155 -0
- package/src/components/Toast/ToastProvider.tsx +69 -0
- package/src/components/Toast/index.tsx +239 -0
- package/src/components/Typography/AnimatedText.tsx +84 -0
- package/src/components/Typography/StyledText.tsx +53 -0
- package/src/components/Typography/Text.tsx +189 -0
- package/src/components/Typography/types.tsx +5 -0
- package/src/components/View/index.tsx +175 -0
- package/src/components/ViewVisibleAnimated/index.tsx +199 -0
- package/src/constants.tsx +16 -0
- package/src/core/theming.tsx +144 -0
- package/src/icons/IconArrowDown.tsx +14 -0
- package/src/icons/IconCheckbox.tsx +20 -0
- package/src/icons/IconCheckboxActive.tsx +18 -0
- package/src/icons/IconClearText.tsx +14 -0
- package/src/icons/IconRadio.tsx +11 -0
- package/src/icons/IconRadioActive.tsx +12 -0
- package/src/icons/IconRadioDisable.tsx +12 -0
- package/src/index.ts +51 -0
- package/src/index.tsx +50 -0
- package/src/styles/fonts.tsx +89 -0
- package/src/styles/overlay.tsx +69 -0
- package/src/styles/shadow.tsx +47 -0
- package/src/styles/themes/DarkTheme.tsx +157 -0
- package/src/styles/themes/LightTheme.tsx +160 -0
- package/src/styles/themes/index.ts +3 -0
- package/src/styles/themes/tokens.tsx +481 -0
- package/src/theme/blue.ts +25 -0
- package/src/theme/colors.ts +21 -0
- package/src/theme/container-styles.tsx +126 -0
- package/src/theme/dimensions.ts +44 -0
- package/src/theme/green.ts +27 -0
- package/src/theme/icon.ts +7 -0
- package/src/theme/ink.ts +18 -0
- package/src/theme/orange.ts +24 -0
- package/src/theme/purple.ts +8 -0
- package/src/theme/red.ts +26 -0
- package/src/theme/themes.tsx +287 -0
- package/src/theme/white.ts +16 -0
- package/src/theme/yellow.ts +26 -0
- package/src/types/index.ts +71 -0
- package/src/types/svg.d.ts +5 -0
- package/src/types.ts +259 -0
- package/src/types.tsx +284 -0
- package/src/utils/BackHandler/BackHandler.native.tsx +3 -0
- package/src/utils/BackHandler/BackHandler.tsx +11 -0
- package/src/utils/addEventListener.tsx +56 -0
- package/src/utils/forwardRef.tsx +23 -0
- package/src/utils/function-utils.tsx +108 -0
- package/src/utils/getContrastingColor.tsx +15 -0
- package/src/utils/hasTouchHandler.tsx +23 -0
- package/src/utils/roundLayoutSize.ts +2 -0
- package/src/utils/splitStyles.ts +60 -0
- package/src/utils/toast-manager.tsx +46 -0
- package/src/utils/useAnimatedValue.tsx +9 -0
- package/src/utils/useAnimatedValueArray.tsx +13 -0
- package/src/utils/useIsKeyboardShown.tsx +55 -0
- package/src/utils/useLayout.tsx +29 -0
- package/src/utils/useLazyRef.tsx +11 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AdornmentSide, AdornmentType } from './enums';
|
|
2
|
+
|
|
3
|
+
export type AdornmentConfig = {
|
|
4
|
+
side: AdornmentSide;
|
|
5
|
+
type: AdornmentType;
|
|
6
|
+
};
|
|
7
|
+
export type AdornmentStyleAdjustmentForNativeInput = {
|
|
8
|
+
adornmentStyleAdjustmentForNativeInput: Array<
|
|
9
|
+
{ paddingRight: number; paddingLeft: number } | {}
|
|
10
|
+
>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
import type { InternalTheme } from '../../../types';
|
|
3
|
+
|
|
4
|
+
type BaseProps = {
|
|
5
|
+
theme: InternalTheme;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function getTextColor({ theme, disabled }: BaseProps) {
|
|
10
|
+
if (disabled) {
|
|
11
|
+
return theme.colors.textSecondary;
|
|
12
|
+
}
|
|
13
|
+
return theme.colors.textDefault;
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getIconColor({
|
|
18
|
+
theme,
|
|
19
|
+
isTextInputFocused,
|
|
20
|
+
disabled,
|
|
21
|
+
customColor,
|
|
22
|
+
}: BaseProps & {
|
|
23
|
+
isTextInputFocused: boolean;
|
|
24
|
+
customColor?: ((isTextInputFocused: boolean) => string | undefined) | string;
|
|
25
|
+
}) {
|
|
26
|
+
if (typeof customColor === 'function') {
|
|
27
|
+
return customColor(isTextInputFocused);
|
|
28
|
+
}
|
|
29
|
+
if (customColor) {
|
|
30
|
+
return customColor;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if (disabled) {
|
|
35
|
+
return theme.colors.textBrandDefault;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return theme.colors.textDefault;
|
|
39
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
Animated,
|
|
4
|
+
ColorValue,
|
|
5
|
+
Platform,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
useWindowDimensions,
|
|
8
|
+
View,
|
|
9
|
+
} from "react-native";
|
|
10
|
+
|
|
11
|
+
import AnimatedText from "../../Typography/AnimatedText";
|
|
12
|
+
import { getConstants } from "../helpers";
|
|
13
|
+
import type { InputLabelProps } from "../types";
|
|
14
|
+
|
|
15
|
+
const InputLabel = (props: InputLabelProps) => {
|
|
16
|
+
const {
|
|
17
|
+
labeled,
|
|
18
|
+
wiggle,
|
|
19
|
+
error,
|
|
20
|
+
focused,
|
|
21
|
+
opacity,
|
|
22
|
+
labelLayoutWidth,
|
|
23
|
+
labelLayoutHeight,
|
|
24
|
+
labelBackground,
|
|
25
|
+
label,
|
|
26
|
+
labelError,
|
|
27
|
+
onLayoutAnimatedText,
|
|
28
|
+
onLabelTextLayout,
|
|
29
|
+
hasActiveOutline,
|
|
30
|
+
activeColor,
|
|
31
|
+
placeholderStyle,
|
|
32
|
+
baseLabelTranslateX,
|
|
33
|
+
baseLabelTranslateY,
|
|
34
|
+
font,
|
|
35
|
+
fontSize,
|
|
36
|
+
lineHeight,
|
|
37
|
+
fontWeight,
|
|
38
|
+
placeholderOpacity,
|
|
39
|
+
wiggleOffsetX,
|
|
40
|
+
labelScale,
|
|
41
|
+
topPosition,
|
|
42
|
+
paddingLeft,
|
|
43
|
+
paddingRight,
|
|
44
|
+
backgroundColor,
|
|
45
|
+
roundness,
|
|
46
|
+
placeholderColor,
|
|
47
|
+
errorColor,
|
|
48
|
+
labelTranslationXOffset,
|
|
49
|
+
maxFontSizeMultiplier,
|
|
50
|
+
testID,
|
|
51
|
+
inputContainerLayout,
|
|
52
|
+
scaledLabel,
|
|
53
|
+
} = props;
|
|
54
|
+
|
|
55
|
+
const { INPUT_PADDING_HORIZONTAL } = getConstants();
|
|
56
|
+
const { width } = useWindowDimensions();
|
|
57
|
+
|
|
58
|
+
const paddingOffset =
|
|
59
|
+
paddingLeft && paddingRight ? { paddingLeft, paddingRight } : {};
|
|
60
|
+
|
|
61
|
+
const labelTranslationX = {
|
|
62
|
+
transform: [
|
|
63
|
+
{
|
|
64
|
+
// Offset label scale since RN doesn't support transform origin
|
|
65
|
+
translateX: labeled.interpolate({
|
|
66
|
+
inputRange: [0, 1],
|
|
67
|
+
outputRange: [baseLabelTranslateX, labelTranslationXOffset || 0],
|
|
68
|
+
}),
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const labelStyle = {
|
|
74
|
+
...font,
|
|
75
|
+
fontSize,
|
|
76
|
+
lineHeight,
|
|
77
|
+
fontWeight,
|
|
78
|
+
opacity: labeled.interpolate({
|
|
79
|
+
inputRange: [0, 1],
|
|
80
|
+
outputRange: [hasActiveOutline ? 1 : 0, 0],
|
|
81
|
+
}),
|
|
82
|
+
transform: [
|
|
83
|
+
{
|
|
84
|
+
// Wiggle the label when there's an error
|
|
85
|
+
translateX: wiggle
|
|
86
|
+
? error.interpolate({
|
|
87
|
+
inputRange: [0, 0.5, 1],
|
|
88
|
+
outputRange: [0, wiggleOffsetX, 0],
|
|
89
|
+
})
|
|
90
|
+
: 0,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
// Move label to top
|
|
94
|
+
translateY:
|
|
95
|
+
baseLabelTranslateY !== 0
|
|
96
|
+
? labeled.interpolate({
|
|
97
|
+
inputRange: [0, 1],
|
|
98
|
+
outputRange: [baseLabelTranslateY, 0],
|
|
99
|
+
})
|
|
100
|
+
: 0,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
// Make label smaller
|
|
104
|
+
scale:
|
|
105
|
+
labelScale !== 0
|
|
106
|
+
? labeled.interpolate({
|
|
107
|
+
inputRange: [0, 1],
|
|
108
|
+
outputRange: [labelScale, 1],
|
|
109
|
+
})
|
|
110
|
+
: labeled,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const labelWidth =
|
|
116
|
+
(inputContainerLayout.width + INPUT_PADDING_HORIZONTAL / 2) /
|
|
117
|
+
(scaledLabel ? labelScale : 1);
|
|
118
|
+
|
|
119
|
+
const commonStyles = [
|
|
120
|
+
placeholderStyle,
|
|
121
|
+
{
|
|
122
|
+
top: topPosition,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
maxWidth: labelWidth,
|
|
126
|
+
},
|
|
127
|
+
labelStyle,
|
|
128
|
+
paddingOffset || {},
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
const textColor = (
|
|
132
|
+
labelError && errorColor ? errorColor : placeholderColor
|
|
133
|
+
) as ColorValue;
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
// Position colored placeholder and gray placeholder on top of each other and crossfade them
|
|
137
|
+
// This gives the effect of animating the color, but allows us to use native driver
|
|
138
|
+
<View
|
|
139
|
+
pointerEvents="none"
|
|
140
|
+
style={[StyleSheet.absoluteFill, styles.overflow, styles.labelContainer]}
|
|
141
|
+
>
|
|
142
|
+
<Animated.View
|
|
143
|
+
pointerEvents="none"
|
|
144
|
+
style={[
|
|
145
|
+
StyleSheet.absoluteFill,
|
|
146
|
+
Platform.OS !== "web" && { width },
|
|
147
|
+
{ opacity },
|
|
148
|
+
labelTranslationX,
|
|
149
|
+
]}
|
|
150
|
+
>
|
|
151
|
+
<View
|
|
152
|
+
style={{
|
|
153
|
+
width: labelWidth,
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
{labelBackground?.({
|
|
157
|
+
labeled,
|
|
158
|
+
labelLayoutWidth,
|
|
159
|
+
labelLayoutHeight,
|
|
160
|
+
labelStyle,
|
|
161
|
+
placeholderStyle,
|
|
162
|
+
baseLabelTranslateX,
|
|
163
|
+
topPosition,
|
|
164
|
+
label,
|
|
165
|
+
backgroundColor,
|
|
166
|
+
roundness,
|
|
167
|
+
maxFontSizeMultiplier: maxFontSizeMultiplier,
|
|
168
|
+
testID,
|
|
169
|
+
})}
|
|
170
|
+
<AnimatedText
|
|
171
|
+
variant="bodySmall"
|
|
172
|
+
onLayout={onLayoutAnimatedText}
|
|
173
|
+
onTextLayout={onLabelTextLayout}
|
|
174
|
+
style={[
|
|
175
|
+
commonStyles,
|
|
176
|
+
{
|
|
177
|
+
color: activeColor,
|
|
178
|
+
},
|
|
179
|
+
]}
|
|
180
|
+
numberOfLines={1}
|
|
181
|
+
maxFontSizeMultiplier={maxFontSizeMultiplier}
|
|
182
|
+
testID={`${testID}-label-active`}
|
|
183
|
+
>
|
|
184
|
+
{label}
|
|
185
|
+
</AnimatedText>
|
|
186
|
+
<AnimatedText
|
|
187
|
+
variant={focused ? "bodyLarge" : "bodySmall"}
|
|
188
|
+
style={[
|
|
189
|
+
commonStyles,
|
|
190
|
+
{
|
|
191
|
+
color: textColor,
|
|
192
|
+
opacity: placeholderOpacity,
|
|
193
|
+
},
|
|
194
|
+
]}
|
|
195
|
+
numberOfLines={1}
|
|
196
|
+
maxFontSizeMultiplier={maxFontSizeMultiplier}
|
|
197
|
+
testID={`${testID}-label-inactive`}
|
|
198
|
+
>
|
|
199
|
+
{label}
|
|
200
|
+
</AnimatedText>
|
|
201
|
+
</View>
|
|
202
|
+
</Animated.View>
|
|
203
|
+
</View>
|
|
204
|
+
);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const styles = StyleSheet.create({
|
|
208
|
+
overflow: {
|
|
209
|
+
overflow: "hidden",
|
|
210
|
+
},
|
|
211
|
+
labelContainer: {
|
|
212
|
+
zIndex: 3,
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
export default React.memo(InputLabel);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Animated, StyleSheet } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import AnimatedText from '../../Typography/AnimatedText';
|
|
5
|
+
import type { LabelBackgroundProps } from '../types';
|
|
6
|
+
|
|
7
|
+
const LabelBackground = ({
|
|
8
|
+
labeled,
|
|
9
|
+
labelLayoutWidth,
|
|
10
|
+
labelLayoutHeight,
|
|
11
|
+
placeholderStyle,
|
|
12
|
+
baseLabelTranslateX,
|
|
13
|
+
topPosition,
|
|
14
|
+
backgroundColor,
|
|
15
|
+
roundness,
|
|
16
|
+
labelStyle,
|
|
17
|
+
maxFontSizeMultiplier,
|
|
18
|
+
testID,
|
|
19
|
+
}: LabelBackgroundProps) => {
|
|
20
|
+
const opacity = labeled.interpolate({
|
|
21
|
+
inputRange: [0, 0.6],
|
|
22
|
+
outputRange: [1, 0],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const labelTranslationX = {
|
|
26
|
+
translateX: labeled.interpolate({
|
|
27
|
+
inputRange: [0, 1],
|
|
28
|
+
outputRange: [-baseLabelTranslateX, 0],
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const labelTextScaleY = {
|
|
33
|
+
scaleY: labeled.interpolate({
|
|
34
|
+
inputRange: [0, 1],
|
|
35
|
+
outputRange: [0.2, 1],
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const labelTextTransform = [...labelStyle.transform, labelTextScaleY];
|
|
40
|
+
|
|
41
|
+
const isRounded = roundness > 6;
|
|
42
|
+
const roundedEdgeCover = isRounded ? (
|
|
43
|
+
<Animated.View
|
|
44
|
+
key="labelBackground-view"
|
|
45
|
+
pointerEvents="none"
|
|
46
|
+
style={[
|
|
47
|
+
StyleSheet.absoluteFill,
|
|
48
|
+
styles.view,
|
|
49
|
+
{
|
|
50
|
+
backgroundColor,
|
|
51
|
+
maxHeight: Math.max(roundness / 3, 2),
|
|
52
|
+
bottom: Math.max(roundness, 2),
|
|
53
|
+
transform: [labelTranslationX],
|
|
54
|
+
opacity,
|
|
55
|
+
},
|
|
56
|
+
]}
|
|
57
|
+
/>
|
|
58
|
+
) : null;
|
|
59
|
+
|
|
60
|
+
return [
|
|
61
|
+
roundedEdgeCover,
|
|
62
|
+
<AnimatedText
|
|
63
|
+
key="labelBackground-text"
|
|
64
|
+
testID={`${testID}-label-background`}
|
|
65
|
+
style={[
|
|
66
|
+
placeholderStyle,
|
|
67
|
+
labelStyle,
|
|
68
|
+
styles.outlinedLabel,
|
|
69
|
+
{
|
|
70
|
+
top: topPosition + 1,
|
|
71
|
+
width: labelLayoutWidth - placeholderStyle.paddingHorizontal,
|
|
72
|
+
height: labelLayoutHeight,
|
|
73
|
+
backgroundColor,
|
|
74
|
+
opacity,
|
|
75
|
+
transform: labelTextTransform,
|
|
76
|
+
},
|
|
77
|
+
]}
|
|
78
|
+
numberOfLines={1}
|
|
79
|
+
maxFontSizeMultiplier={maxFontSizeMultiplier}
|
|
80
|
+
/>,
|
|
81
|
+
];
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default LabelBackground;
|
|
85
|
+
|
|
86
|
+
const styles = StyleSheet.create({
|
|
87
|
+
view: {
|
|
88
|
+
position: 'absolute',
|
|
89
|
+
top: 6,
|
|
90
|
+
left: 10,
|
|
91
|
+
width: 12,
|
|
92
|
+
},
|
|
93
|
+
// eslint-disable-next-line react-native/no-color-literals
|
|
94
|
+
outlinedLabel: {
|
|
95
|
+
position: 'absolute',
|
|
96
|
+
left: 8,
|
|
97
|
+
paddingHorizontal: 0,
|
|
98
|
+
color: 'transparent',
|
|
99
|
+
},
|
|
100
|
+
});
|