sapo-components-ui-rn 1.0.2 → 1.0.3

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/dist/index.js CHANGED
@@ -3052,348 +3052,6 @@ var styles$b = reactNative.StyleSheet.create({
3052
3052
  },
3053
3053
  });
3054
3054
 
3055
- var TextInputDefault = function (_a) {
3056
- var _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.editable, editable = _c === void 0 ? true : _c; _a.label; var _d = _a.error, error = _d === void 0 ? false : _d, customSelectionColor = _a.selectionColor, cursorColor = _a.cursorColor, customOutlineColor = _a.outlineColor, activeOutlineColor = _a.activeOutlineColor; _a.outlineStyle; var textColor = _a.textColor; _a.dense; var style = _a.style, theme = _a.theme, _e = _a.render, render = _e === void 0 ? function (props) { return React__namespace.createElement(reactNative.TextInput, __assign({}, props)); } : _e, _f = _a.multiline, multiline = _f === void 0 ? false : _f, parentState = _a.parentState, innerRef = _a.innerRef, onFocus = _a.onFocus; _a.forceFocus; var onBlur = _a.onBlur, onChangeText = _a.onChangeText; _a.onLayout; var left = _a.left, right = _a.right, placeholderTextColor = _a.placeholderTextColor, _g = _a.clearButton, clearButton = _g === void 0 ? false : _g, contentStyle = _a.contentStyle, value = _a.value, rest = __rest(_a, ["disabled", "editable", "label", "error", "selectionColor", "cursorColor", "outlineColor", "activeOutlineColor", "outlineStyle", "textColor", "dense", "style", "theme", "render", "multiline", "parentState", "innerRef", "onFocus", "forceFocus", "onBlur", "onChangeText", "onLayout", "left", "right", "placeholderTextColor", "clearButton", "contentStyle", "value"]);
3057
- var colors = theme.colors;
3058
- var font = theme.fonts.bodyLarge;
3059
- var _h = (reactNative.StyleSheet.flatten(style) || {}), fontSizeStyle = _h.fontSize, fontWeight = _h.fontWeight, lineHeightStyle = _h.lineHeight, height = _h.height, _j = _h.backgroundColor; _j === void 0 ? colors === null || colors === void 0 ? void 0 : colors.backgroundPrimary : _j; var textAlign = _h.textAlign, viewStyle = __rest(_h, ["fontSize", "fontWeight", "lineHeight", "height", "backgroundColor", "textAlign"]);
3060
- var fontSize = fontSizeStyle || MAXIMIZED_LABEL_FONT_SIZE;
3061
- var lineHeight = lineHeightStyle || (reactNative.Platform.OS === "web" ? fontSize * 1.2 : undefined);
3062
- var _k = getOutlinedInputColors({
3063
- activeOutlineColor: activeOutlineColor,
3064
- customOutlineColor: customOutlineColor,
3065
- customSelectionColor: customSelectionColor,
3066
- textColor: textColor,
3067
- disabled: disabled,
3068
- error: error,
3069
- theme: theme,
3070
- }), inputTextColor = _k.inputTextColor, activeColor = _k.activeColor, selectionColor = _k.selectionColor;
3071
- var _l = React__namespace.useState(value || ""), inputValue = _l[0], setInputValue = _l[1];
3072
- React__namespace.useEffect(function () {
3073
- setInputValue(value || "");
3074
- }, [value]);
3075
- var handleChangeText = function (text) {
3076
- setInputValue(text);
3077
- onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(text);
3078
- };
3079
- var handleClear = function () {
3080
- setInputValue("");
3081
- onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText("");
3082
- };
3083
- if (height && typeof height !== "number") {
3084
- console.warn("Currently we support only numbers in height prop");
3085
- }
3086
- var placeholderTextColorBasedOnState = placeholderTextColor || colors.textSecondary;
3087
- var getBorderColor = function () {
3088
- if (disabled) {
3089
- return theme.colors.surfacePrimaryDisabled;
3090
- }
3091
- else if (parentState.focused) {
3092
- return activeColor;
3093
- }
3094
- else {
3095
- return theme.colors.borderPrimaryDefault;
3096
- }
3097
- };
3098
- return (React__namespace.createElement(View, { style: viewStyle },
3099
- React__namespace.createElement(View, { row: true, alignCenter: true, style: [
3100
- {
3101
- borderRadius: CONSTANTS.BORDER_RADIUS_6,
3102
- borderWidth: 1,
3103
- borderColor: getBorderColor(),
3104
- overflow: "hidden",
3105
- backgroundColor: disabled
3106
- ? theme.colors.surfacePrimaryDisabled
3107
- : theme.colors.surfacePrimaryDefault,
3108
- },
3109
- ] },
3110
- React__namespace.createElement(View, { paddingLeft: CONSTANTS.SPACE_12 }, left),
3111
- left && React__namespace.createElement(Spacer, { width: CONSTANTS.SPACE_8 }), render === null || render === void 0 ? void 0 :
3112
- render(__assign(__assign({}, rest), { ref: innerRef, onChangeText: handleChangeText, value: inputValue, placeholder: rest.placeholder, editable: !disabled && editable, selectionColor: selectionColor, cursorColor: typeof cursorColor === "undefined" ? activeColor : cursorColor, placeholderTextColor: placeholderTextColorBasedOnState, onFocus: onFocus, onBlur: onBlur, underlineColorAndroid: "transparent", multiline: multiline, style: [
3113
- styles$a.input,
3114
- __assign(__assign({}, font), { fontSize: fontSize, lineHeight: lineHeight, fontWeight: fontWeight, color: inputTextColor, textAlignVertical: multiline ? "top" : "center", textAlign: textAlign
3115
- ? textAlign
3116
- : reactNative.I18nManager.getConstants().isRTL
3117
- ? "right"
3118
- : "left", height: height ? height : 48 }),
3119
- contentStyle,
3120
- ] })),
3121
- !disabled && clearButton && inputValue ? (React__namespace.createElement(reactNative.TouchableOpacity, { onPress: handleClear, style: styles$a.clearButton },
3122
- React__namespace.createElement(Icon$1, { name: "IconClearText", type: "Svg", size: 24 }))) : (React__namespace.createElement(Spacer, { width: CONSTANTS.SPACE_12 })),
3123
- right && React__namespace.createElement(Spacer, { width: CONSTANTS.SPACE_8 }),
3124
- right && React__namespace.createElement(View, { paddingRight: CONSTANTS.SPACE_12 }, right))));
3125
- };
3126
- var styles$a = reactNative.StyleSheet.create({
3127
- input: {
3128
- margin: 0,
3129
- flex: 1,
3130
- height: 48,
3131
- },
3132
- clearButton: {
3133
- padding: CONSTANTS.SPACE_8,
3134
- },
3135
- });
3136
-
3137
- var roundLayoutSize = function (size) {
3138
- return Math.round(size * 1000) / 1000;
3139
- };
3140
-
3141
- var BLUR_ANIMATION_DURATION = 180;
3142
- var FOCUS_ANIMATION_DURATION = 150;
3143
- var DefaultRenderer = function (props) { return React__default["default"].createElement(reactNative.TextInput, __assign({}, props)); };
3144
- /**
3145
- * A component to allow users to input text.
3146
- *
3147
- * ## Usage
3148
- * ```js
3149
- * import * as React from 'react';
3150
- * import { TextInput } from 'react-native-paper';
3151
- *
3152
- * const MyComponent = () => {
3153
- * const [text, setText] = React.useState("");
3154
- *
3155
- * return (
3156
- * <TextInput
3157
- * label="Email"
3158
- * value={text}
3159
- * onChangeText={text => setText(text)}
3160
- * />
3161
- * );
3162
- * };
3163
- *
3164
- * export default MyComponent;
3165
- * ```
3166
- *
3167
- * @extends TextInput props https://reactnative.dev/docs/textinput#props
3168
- */
3169
- var TextInput = forwardRef(function (_a, ref) {
3170
- var _b = _a.mode, mode = _b === void 0 ? "default" : _b, _c = _a.dense, dense = _c === void 0 ? false : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.error, errorProp = _e === void 0 ? false : _e, _f = _a.multiline, multiline = _f === void 0 ? false : _f, _g = _a.editable, editable = _g === void 0 ? true : _g, contentStyle = _a.contentStyle, _h = _a.render, render = _h === void 0 ? DefaultRenderer : _h; _a.theme; var placeholderTextColor = _a.placeholderTextColor, clearButton = _a.clearButton, rest = __rest(_a, ["mode", "dense", "disabled", "error", "multiline", "editable", "contentStyle", "render", "theme", "placeholderTextColor", "clearButton"]);
3171
- var theme = useInternalTheme();
3172
- var isControlled = rest.value !== undefined;
3173
- var validInputValue = isControlled ? rest.value : rest.defaultValue;
3174
- var labeled = React__default["default"].useRef(new reactNative.Animated.Value(validInputValue ? 0 : 1)).current;
3175
- var error = React__default["default"].useRef(new reactNative.Animated.Value(errorProp ? 1 : 0)).current;
3176
- var _j = React__default["default"].useState(false), focused = _j[0], setFocused = _j[1];
3177
- var _k = React__default["default"].useState(false), displayPlaceholder = _k[0], setDisplayPlaceholder = _k[1];
3178
- var _l = React__default["default"].useState(validInputValue), uncontrolledValue = _l[0], setUncontrolledValue = _l[1];
3179
- // Use value from props instead of local state when input is controlled
3180
- var value = isControlled ? rest.value : uncontrolledValue;
3181
- var _m = React__default["default"].useState({
3182
- width: 33,
3183
- }), labelTextLayout = _m[0], setLabelTextLayout = _m[1];
3184
- var _o = React__default["default"].useState({
3185
- width: 65,
3186
- }), inputContainerLayout = _o[0], setInputContainerLayout = _o[1];
3187
- var _p = React__default["default"].useState({
3188
- measured: false,
3189
- width: 0,
3190
- height: 0,
3191
- }), labelLayout = _p[0], setLabelLayout = _p[1];
3192
- var _q = React__default["default"].useState({
3193
- width: null,
3194
- height: null,
3195
- }), leftLayout = _q[0], setLeftLayout = _q[1];
3196
- var _r = React__default["default"].useState({
3197
- width: null,
3198
- height: null,
3199
- }), rightLayout = _r[0], setRightLayout = _r[1];
3200
- var timer = React$3.useRef(undefined);
3201
- var root = React$3.useRef(null);
3202
- var scale = theme.animation.scale;
3203
- React__default["default"].useImperativeHandle(ref, function () { return ({
3204
- focus: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); },
3205
- clear: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.clear(); },
3206
- setNativeProps: function (args) { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.setNativeProps(args); },
3207
- isFocused: function () { var _a; return ((_a = root.current) === null || _a === void 0 ? void 0 : _a.isFocused()) || false; },
3208
- blur: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.blur(); },
3209
- forceFocus: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); },
3210
- }); });
3211
- React__default["default"].useEffect(function () {
3212
- // When the input has an error, we wiggle the label and apply error styles
3213
- if (errorProp) {
3214
- // show error
3215
- reactNative.Animated.timing(error, {
3216
- toValue: 1,
3217
- duration: FOCUS_ANIMATION_DURATION * scale,
3218
- // To prevent this - https://github.com/callstack/react-native-paper/issues/941
3219
- useNativeDriver: true,
3220
- }).start();
3221
- }
3222
- else {
3223
- // hide error
3224
- {
3225
- reactNative.Animated.timing(error, {
3226
- toValue: 0,
3227
- duration: BLUR_ANIMATION_DURATION * scale,
3228
- // To prevent this - https://github.com/callstack/react-native-paper/issues/941
3229
- useNativeDriver: true,
3230
- }).start();
3231
- }
3232
- }
3233
- }, [errorProp, scale, error]);
3234
- React__default["default"].useEffect(function () {
3235
- // Show placeholder text only if the input is focused, or there's no label
3236
- // We don't show placeholder if there's a label because the label acts as placeholder
3237
- // When focused, the label moves up, so we can show a placeholder
3238
- if (focused || !rest.label) {
3239
- // If the user wants to use the contextMenu, when changing the placeholder, the contextMenu is closed
3240
- // This is a workaround to mitigate this behavior in scenarios where the placeholder is not specified.
3241
- if (rest.placeholder) {
3242
- // Display placeholder in a delay to offset the label animation
3243
- // If we show it immediately, they'll overlap and look ugly
3244
- timer.current = setTimeout(function () { return setDisplayPlaceholder(true); }, 50);
3245
- }
3246
- }
3247
- else {
3248
- // hidePlaceholder
3249
- setDisplayPlaceholder(false);
3250
- }
3251
- return function () {
3252
- if (timer.current) {
3253
- clearTimeout(timer.current);
3254
- }
3255
- };
3256
- }, [focused, rest.label, rest.placeholder]);
3257
- React__default["default"].useEffect(function () {
3258
- labeled.stopAnimation();
3259
- // The label should be minimized if the text input is focused, or has text
3260
- // In minimized mode, the label moves up and becomes small
3261
- // workaround for animated regression for react native > 0.61
3262
- // https://github.com/callstack/react-native-paper/pull/1440
3263
- if (value || focused) {
3264
- // minimize label
3265
- reactNative.Animated.timing(labeled, {
3266
- toValue: 0,
3267
- duration: BLUR_ANIMATION_DURATION * scale,
3268
- // To prevent this - https://github.com/callstack/react-native-paper/issues/941
3269
- useNativeDriver: true,
3270
- }).start();
3271
- }
3272
- else {
3273
- // restore label
3274
- reactNative.Animated.timing(labeled, {
3275
- toValue: 1,
3276
- duration: FOCUS_ANIMATION_DURATION * scale,
3277
- // To prevent this - https://github.com/callstack/react-native-paper/issues/941
3278
- useNativeDriver: true,
3279
- }).start();
3280
- }
3281
- }, [focused, value, labeled, scale]);
3282
- var onLeftAffixLayoutChange = React__default["default"].useCallback(function (event) {
3283
- var height = roundLayoutSize(event.nativeEvent.layout.height);
3284
- var width = roundLayoutSize(event.nativeEvent.layout.width);
3285
- if (width !== leftLayout.width || height !== leftLayout.height) {
3286
- setLeftLayout({
3287
- width: width,
3288
- height: height,
3289
- });
3290
- }
3291
- }, [leftLayout.height, leftLayout.width]);
3292
- var onRightAffixLayoutChange = React__default["default"].useCallback(function (event) {
3293
- var width = roundLayoutSize(event.nativeEvent.layout.width);
3294
- var height = roundLayoutSize(event.nativeEvent.layout.height);
3295
- if (width !== rightLayout.width || height !== rightLayout.height) {
3296
- setRightLayout({
3297
- width: width,
3298
- height: height,
3299
- });
3300
- }
3301
- }, [rightLayout.height, rightLayout.width]);
3302
- var handleFocus = function (args) {
3303
- var _a;
3304
- if (disabled || !editable) {
3305
- return;
3306
- }
3307
- setFocused(true);
3308
- (_a = rest.onFocus) === null || _a === void 0 ? void 0 : _a.call(rest, args);
3309
- };
3310
- var handleBlur = function (args) {
3311
- var _a;
3312
- if (!editable) {
3313
- return;
3314
- }
3315
- setFocused(false);
3316
- (_a = rest.onBlur) === null || _a === void 0 ? void 0 : _a.call(rest, args);
3317
- };
3318
- var handleChangeText = function (value) {
3319
- var _a;
3320
- if (!editable || disabled) {
3321
- return;
3322
- }
3323
- if (!isControlled) {
3324
- // Keep track of value in local state when input is not controlled
3325
- setUncontrolledValue(value);
3326
- }
3327
- (_a = rest.onChangeText) === null || _a === void 0 ? void 0 : _a.call(rest, value);
3328
- };
3329
- var handleLayoutAnimatedText = React__default["default"].useCallback(function (e) {
3330
- var width = roundLayoutSize(e.nativeEvent.layout.width);
3331
- var height = roundLayoutSize(e.nativeEvent.layout.height);
3332
- if (width !== labelLayout.width || height !== labelLayout.height) {
3333
- setLabelLayout({
3334
- width: width,
3335
- height: height,
3336
- measured: true,
3337
- });
3338
- }
3339
- }, [labelLayout.height, labelLayout.width]);
3340
- var handleLabelTextLayout = React__default["default"].useCallback(function (_a) {
3341
- var nativeEvent = _a.nativeEvent;
3342
- setLabelTextLayout({
3343
- width: nativeEvent.lines.reduce(function (acc, line) { return acc + Math.ceil(line.width); }, 0),
3344
- });
3345
- }, []);
3346
- var handleInputContainerLayout = React__default["default"].useCallback(function (_a) {
3347
- var layout = _a.nativeEvent.layout;
3348
- setInputContainerLayout({
3349
- width: layout.width,
3350
- });
3351
- }, []);
3352
- var forceFocus = React__default["default"].useCallback(function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); }, []);
3353
- var _s = rest.maxFontSizeMultiplier, maxFontSizeMultiplier = _s === void 0 ? 1.5 : _s;
3354
- var scaledLabel = !!(value || focused);
3355
- if (mode === "default") {
3356
- return (React__default["default"].createElement(TextInputDefault, __assign({ dense: dense, disabled: disabled, error: errorProp, multiline: multiline, editable: editable, render: render }, rest, { theme: theme, value: value, placeholderTextColor: placeholderTextColor, clearButton: clearButton, parentState: {
3357
- labeled: labeled,
3358
- error: error,
3359
- focused: focused,
3360
- displayPlaceholder: displayPlaceholder,
3361
- value: value,
3362
- labelTextLayout: labelTextLayout,
3363
- labelLayout: labelLayout,
3364
- leftLayout: leftLayout,
3365
- rightLayout: rightLayout,
3366
- inputContainerLayout: inputContainerLayout,
3367
- }, innerRef: function (ref) {
3368
- root.current = ref;
3369
- }, onFocus: handleFocus, forceFocus: forceFocus, onBlur: handleBlur, allowFontScaling: false, onChangeText: handleChangeText, onLayoutAnimatedText: handleLayoutAnimatedText, onInputLayout: handleInputContainerLayout, onLabelTextLayout: handleLabelTextLayout, onLeftAffixLayoutChange: onLeftAffixLayoutChange, onRightAffixLayoutChange: onRightAffixLayoutChange, maxFontSizeMultiplier: maxFontSizeMultiplier, contentStyle: contentStyle, scaledLabel: scaledLabel })));
3370
- }
3371
- return (React__default["default"].createElement(TextInputFlat, __assign({ dense: dense, disabled: disabled, error: errorProp, multiline: false, editable: editable, clearButton: clearButton, render: render }, rest, { theme: theme, value: value, parentState: {
3372
- labeled: labeled,
3373
- error: error,
3374
- focused: focused,
3375
- displayPlaceholder: displayPlaceholder,
3376
- value: value,
3377
- labelTextLayout: labelTextLayout,
3378
- labelLayout: labelLayout,
3379
- leftLayout: leftLayout,
3380
- rightLayout: rightLayout,
3381
- inputContainerLayout: inputContainerLayout,
3382
- }, innerRef: function (ref) {
3383
- root.current = ref;
3384
- }, onFocus: handleFocus, forceFocus: forceFocus, onBlur: handleBlur, onInputLayout: handleInputContainerLayout, allowFontScaling: false, onChangeText: handleChangeText, onLayoutAnimatedText: handleLayoutAnimatedText, onLabelTextLayout: handleLabelTextLayout, onLeftAffixLayoutChange: onLeftAffixLayoutChange, onRightAffixLayoutChange: onRightAffixLayoutChange, maxFontSizeMultiplier: maxFontSizeMultiplier, contentStyle: contentStyle, scaledLabel: scaledLabel })));
3385
- });
3386
- // @component ./Adornment/TextInputIcon.tsx
3387
- // @component ./Adornment/TextInputAffix.tsx
3388
- // @ts-ignore Types of property 'theme' are incompatible.
3389
- TextInput.Affix = TextInputAffix;
3390
-
3391
- var ScaleButton = function (_a) {
3392
- var children = _a.children; _a.style; var _b = _a.onPress, onPress = _b === void 0 ? function () { } : _b, rest = __rest(_a, ["children", "style", "onPress"]);
3393
- return (React__default["default"].createElement(reactNative.TouchableOpacity, __assign({}, rest, { onPress: onPress }), children));
3394
- };
3395
- var ScaleButton$1 = React__default["default"].memo(ScaleButton);
3396
-
3397
3055
  /**
3398
3056
  * Removes all key-value entries from the list cache.
3399
3057
  *
@@ -5860,43 +5518,406 @@ var memoWithRef = function (component) {
5860
5518
  var Text = function (props) {
5861
5519
  var children = props.children, onPress = props.onPress; props.theme; var rest = __rest(props, ["children", "onPress", "theme"]);
5862
5520
  var theme = useInternalTheme();
5863
- delete rest.style;
5864
- var _getStyle = function () {
5865
- var style = {
5866
- fontWeight: "normal",
5867
- color: colors.ink.INK100,
5868
- fontFamily: "Inter-Regular",
5869
- };
5870
- var _a = props.size, size = _a === void 0 ? 14 : _a, center = props.center, color = props.color, bold = props.bold, medium = props.medium;
5871
- style.color = theme.colors.textDefault || "black";
5872
- if (size) {
5873
- style.fontSize = size;
5874
- }
5875
- if (color) {
5876
- style.color = color;
5521
+ delete rest.style;
5522
+ var _getStyle = function () {
5523
+ var style = {
5524
+ fontWeight: "normal",
5525
+ color: colors.ink.INK100,
5526
+ fontFamily: "Inter-Regular",
5527
+ };
5528
+ var _a = props.size, size = _a === void 0 ? 14 : _a, center = props.center, color = props.color, bold = props.bold, medium = props.medium;
5529
+ style.color = theme.colors.textDefault || "black";
5530
+ if (size) {
5531
+ style.fontSize = size;
5532
+ }
5533
+ if (color) {
5534
+ style.color = color;
5535
+ }
5536
+ if (center) {
5537
+ style.textAlign = "center";
5538
+ }
5539
+ if (bold) {
5540
+ style.fontFamily = "Inter-Bold";
5541
+ if (reactNative.Platform.OS === "ios") {
5542
+ style.fontWeight = "bold";
5543
+ }
5544
+ }
5545
+ if (medium) {
5546
+ style.fontFamily = "Inter-SemiBold";
5547
+ if (reactNative.Platform.OS === "ios") {
5548
+ style.fontWeight = "600";
5549
+ }
5550
+ }
5551
+ return reactNative.StyleSheet.create({ style: style }).style;
5552
+ };
5553
+ var defaultStyle = _getStyle();
5554
+ var Component = reactNative.Text;
5555
+ return (React__default["default"].createElement(Component, __assign({ onPress: onPress, style: [defaultStyle, props.style], allowFontScaling: false }, rest), children));
5556
+ };
5557
+ var Text$1 = memoDeepEqual(Text);
5558
+
5559
+ var TextInputDefault = function (_a) {
5560
+ var _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.editable, editable = _c === void 0 ? true : _c, label = _a.label, _d = _a.error, error = _d === void 0 ? false : _d, customSelectionColor = _a.selectionColor, cursorColor = _a.cursorColor, customOutlineColor = _a.outlineColor, activeOutlineColor = _a.activeOutlineColor; _a.outlineStyle; var textColor = _a.textColor; _a.dense; var style = _a.style, theme = _a.theme, _e = _a.render, render = _e === void 0 ? function (props) { return React__namespace.createElement(reactNative.TextInput, __assign({}, props)); } : _e, _f = _a.multiline, multiline = _f === void 0 ? false : _f, parentState = _a.parentState, innerRef = _a.innerRef, onFocus = _a.onFocus; _a.forceFocus; var onBlur = _a.onBlur, onChangeText = _a.onChangeText; _a.onLayout; var left = _a.left, right = _a.right, placeholderTextColor = _a.placeholderTextColor, _g = _a.clearButton, clearButton = _g === void 0 ? false : _g, contentStyle = _a.contentStyle, value = _a.value, rest = __rest(_a, ["disabled", "editable", "label", "error", "selectionColor", "cursorColor", "outlineColor", "activeOutlineColor", "outlineStyle", "textColor", "dense", "style", "theme", "render", "multiline", "parentState", "innerRef", "onFocus", "forceFocus", "onBlur", "onChangeText", "onLayout", "left", "right", "placeholderTextColor", "clearButton", "contentStyle", "value"]);
5561
+ var colors = theme.colors;
5562
+ var font = theme.fonts.bodyLarge;
5563
+ var _h = (reactNative.StyleSheet.flatten(style) || {}), fontSizeStyle = _h.fontSize, fontWeight = _h.fontWeight, lineHeightStyle = _h.lineHeight, height = _h.height, _j = _h.backgroundColor; _j === void 0 ? colors === null || colors === void 0 ? void 0 : colors.backgroundPrimary : _j; var textAlign = _h.textAlign, viewStyle = __rest(_h, ["fontSize", "fontWeight", "lineHeight", "height", "backgroundColor", "textAlign"]);
5564
+ var fontSize = fontSizeStyle || MAXIMIZED_LABEL_FONT_SIZE;
5565
+ var lineHeight = lineHeightStyle || (reactNative.Platform.OS === "web" ? fontSize * 1.2 : undefined);
5566
+ var _k = getOutlinedInputColors({
5567
+ activeOutlineColor: activeOutlineColor,
5568
+ customOutlineColor: customOutlineColor,
5569
+ customSelectionColor: customSelectionColor,
5570
+ textColor: textColor,
5571
+ disabled: disabled,
5572
+ error: error,
5573
+ theme: theme,
5574
+ }), inputTextColor = _k.inputTextColor, activeColor = _k.activeColor, selectionColor = _k.selectionColor;
5575
+ var _l = React__namespace.useState(value || ""), inputValue = _l[0], setInputValue = _l[1];
5576
+ React__namespace.useEffect(function () {
5577
+ setInputValue(value || "");
5578
+ }, [value]);
5579
+ var handleChangeText = function (text) {
5580
+ setInputValue(text);
5581
+ onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(text);
5582
+ };
5583
+ var handleClear = function () {
5584
+ setInputValue("");
5585
+ onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText("");
5586
+ };
5587
+ if (height && typeof height !== "number") {
5588
+ console.warn("Currently we support only numbers in height prop");
5589
+ }
5590
+ var placeholderTextColorBasedOnState = placeholderTextColor || colors.textSecondary;
5591
+ var getBorderColor = function () {
5592
+ if (disabled) {
5593
+ return theme.colors.surfacePrimaryDisabled;
5594
+ }
5595
+ else if (parentState.focused) {
5596
+ return activeColor;
5597
+ }
5598
+ else {
5599
+ return theme.colors.borderPrimaryDefault;
5600
+ }
5601
+ };
5602
+ var getLabelColor = function () {
5603
+ if (disabled) {
5604
+ return theme.colors.textSecondary;
5605
+ }
5606
+ else if (parentState.focused) {
5607
+ return activeColor;
5608
+ }
5609
+ else {
5610
+ return theme.colors.textSecondary;
5611
+ }
5612
+ };
5613
+ var renderLabel = function () {
5614
+ var _a;
5615
+ if (parentState.focused || ((_a = parentState.value) === null || _a === void 0 ? void 0 : _a.toString()) !== "") {
5616
+ return (React__namespace.createElement(View, { paddingTop: CONSTANTS.SPACE_4 },
5617
+ React__namespace.createElement(Text$1, { color: getLabelColor(), size: MINIMIZED_LABEL_FONT_SIZE }, label)));
5618
+ }
5619
+ return React__namespace.createElement(View, null);
5620
+ };
5621
+ return (React__namespace.createElement(View, { style: viewStyle },
5622
+ React__namespace.createElement(View, { row: true, alignCenter: true, style: [
5623
+ {
5624
+ borderRadius: CONSTANTS.BORDER_RADIUS_6,
5625
+ borderWidth: 1,
5626
+ borderColor: getBorderColor(),
5627
+ overflow: "hidden",
5628
+ backgroundColor: disabled
5629
+ ? theme.colors.surfacePrimaryDisabled
5630
+ : theme.colors.surfacePrimaryDefault,
5631
+ },
5632
+ ] },
5633
+ React__namespace.createElement(View, { paddingLeft: CONSTANTS.SPACE_12 }, left),
5634
+ left && React__namespace.createElement(Spacer, { width: CONSTANTS.SPACE_8 }),
5635
+ React__namespace.createElement(View, { full: true },
5636
+ renderLabel(), render === null || render === void 0 ? void 0 :
5637
+ render(__assign(__assign({}, rest), { ref: innerRef, onChangeText: handleChangeText, value: inputValue, placeholder: rest.placeholder, editable: !disabled && editable, selectionColor: selectionColor, cursorColor: typeof cursorColor === "undefined" ? activeColor : cursorColor, placeholderTextColor: placeholderTextColorBasedOnState, onFocus: onFocus, onBlur: onBlur, underlineColorAndroid: "transparent", multiline: multiline, style: [
5638
+ styles$a.input,
5639
+ __assign(__assign({}, font), { fontSize: fontSize, lineHeight: lineHeight, fontWeight: fontWeight, color: inputTextColor, textAlignVertical: multiline ? "top" : "center", textAlign: textAlign
5640
+ ? textAlign
5641
+ : reactNative.I18nManager.getConstants().isRTL
5642
+ ? "right"
5643
+ : "left", height: height ? height : 48 }),
5644
+ contentStyle,
5645
+ ] }))),
5646
+ !disabled && clearButton && inputValue ? (React__namespace.createElement(reactNative.TouchableOpacity, { onPress: handleClear, style: styles$a.clearButton },
5647
+ React__namespace.createElement(Icon$1, { name: "IconClearText", type: "Svg", size: 24 }))) : (React__namespace.createElement(Spacer, { width: CONSTANTS.SPACE_12 })),
5648
+ right && React__namespace.createElement(Spacer, { width: CONSTANTS.SPACE_8 }),
5649
+ right && React__namespace.createElement(View, { paddingRight: CONSTANTS.SPACE_12 }, right))));
5650
+ };
5651
+ var styles$a = reactNative.StyleSheet.create({
5652
+ input: {
5653
+ margin: 0,
5654
+ flex: 1,
5655
+ height: 48,
5656
+ },
5657
+ clearButton: {
5658
+ padding: CONSTANTS.SPACE_8,
5659
+ },
5660
+ });
5661
+
5662
+ var roundLayoutSize = function (size) {
5663
+ return Math.round(size * 1000) / 1000;
5664
+ };
5665
+
5666
+ var BLUR_ANIMATION_DURATION = 180;
5667
+ var FOCUS_ANIMATION_DURATION = 150;
5668
+ var DefaultRenderer = function (props) { return React__default["default"].createElement(reactNative.TextInput, __assign({}, props)); };
5669
+ /**
5670
+ * A component to allow users to input text.
5671
+ *
5672
+ * ## Usage
5673
+ * ```js
5674
+ * import * as React from 'react';
5675
+ * import { TextInput } from 'react-native-paper';
5676
+ *
5677
+ * const MyComponent = () => {
5678
+ * const [text, setText] = React.useState("");
5679
+ *
5680
+ * return (
5681
+ * <TextInput
5682
+ * label="Email"
5683
+ * value={text}
5684
+ * onChangeText={text => setText(text)}
5685
+ * />
5686
+ * );
5687
+ * };
5688
+ *
5689
+ * export default MyComponent;
5690
+ * ```
5691
+ *
5692
+ * @extends TextInput props https://reactnative.dev/docs/textinput#props
5693
+ */
5694
+ var TextInput = forwardRef(function (_a, ref) {
5695
+ var _b = _a.mode, mode = _b === void 0 ? "default" : _b, _c = _a.dense, dense = _c === void 0 ? false : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.error, errorProp = _e === void 0 ? false : _e, _f = _a.multiline, multiline = _f === void 0 ? false : _f, _g = _a.editable, editable = _g === void 0 ? true : _g, contentStyle = _a.contentStyle, _h = _a.render, render = _h === void 0 ? DefaultRenderer : _h; _a.theme; var placeholderTextColor = _a.placeholderTextColor, clearButton = _a.clearButton, rest = __rest(_a, ["mode", "dense", "disabled", "error", "multiline", "editable", "contentStyle", "render", "theme", "placeholderTextColor", "clearButton"]);
5696
+ var theme = useInternalTheme();
5697
+ var isControlled = rest.value !== undefined;
5698
+ var validInputValue = isControlled ? rest.value : rest.defaultValue;
5699
+ var labeled = React__default["default"].useRef(new reactNative.Animated.Value(validInputValue ? 0 : 1)).current;
5700
+ var error = React__default["default"].useRef(new reactNative.Animated.Value(errorProp ? 1 : 0)).current;
5701
+ var _j = React__default["default"].useState(false), focused = _j[0], setFocused = _j[1];
5702
+ var _k = React__default["default"].useState(false), displayPlaceholder = _k[0], setDisplayPlaceholder = _k[1];
5703
+ var _l = React__default["default"].useState(validInputValue), uncontrolledValue = _l[0], setUncontrolledValue = _l[1];
5704
+ // Use value from props instead of local state when input is controlled
5705
+ var value = isControlled ? rest.value : uncontrolledValue;
5706
+ var _m = React__default["default"].useState({
5707
+ width: 33,
5708
+ }), labelTextLayout = _m[0], setLabelTextLayout = _m[1];
5709
+ var _o = React__default["default"].useState({
5710
+ width: 65,
5711
+ }), inputContainerLayout = _o[0], setInputContainerLayout = _o[1];
5712
+ var _p = React__default["default"].useState({
5713
+ measured: false,
5714
+ width: 0,
5715
+ height: 0,
5716
+ }), labelLayout = _p[0], setLabelLayout = _p[1];
5717
+ var _q = React__default["default"].useState({
5718
+ width: null,
5719
+ height: null,
5720
+ }), leftLayout = _q[0], setLeftLayout = _q[1];
5721
+ var _r = React__default["default"].useState({
5722
+ width: null,
5723
+ height: null,
5724
+ }), rightLayout = _r[0], setRightLayout = _r[1];
5725
+ var timer = React$3.useRef(undefined);
5726
+ var root = React$3.useRef(null);
5727
+ var scale = theme.animation.scale;
5728
+ React__default["default"].useImperativeHandle(ref, function () { return ({
5729
+ focus: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); },
5730
+ clear: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.clear(); },
5731
+ setNativeProps: function (args) { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.setNativeProps(args); },
5732
+ isFocused: function () { var _a; return ((_a = root.current) === null || _a === void 0 ? void 0 : _a.isFocused()) || false; },
5733
+ blur: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.blur(); },
5734
+ forceFocus: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); },
5735
+ }); });
5736
+ React__default["default"].useEffect(function () {
5737
+ // When the input has an error, we wiggle the label and apply error styles
5738
+ if (errorProp) {
5739
+ // show error
5740
+ reactNative.Animated.timing(error, {
5741
+ toValue: 1,
5742
+ duration: FOCUS_ANIMATION_DURATION * scale,
5743
+ // To prevent this - https://github.com/callstack/react-native-paper/issues/941
5744
+ useNativeDriver: true,
5745
+ }).start();
5877
5746
  }
5878
- if (center) {
5879
- style.textAlign = "center";
5747
+ else {
5748
+ // hide error
5749
+ {
5750
+ reactNative.Animated.timing(error, {
5751
+ toValue: 0,
5752
+ duration: BLUR_ANIMATION_DURATION * scale,
5753
+ // To prevent this - https://github.com/callstack/react-native-paper/issues/941
5754
+ useNativeDriver: true,
5755
+ }).start();
5756
+ }
5880
5757
  }
5881
- if (bold) {
5882
- style.fontFamily = "Inter-Bold";
5883
- if (reactNative.Platform.OS === "ios") {
5884
- style.fontWeight = "bold";
5758
+ }, [errorProp, scale, error]);
5759
+ React__default["default"].useEffect(function () {
5760
+ // Show placeholder text only if the input is focused, or there's no label
5761
+ // We don't show placeholder if there's a label because the label acts as placeholder
5762
+ // When focused, the label moves up, so we can show a placeholder
5763
+ if (focused || !rest.label) {
5764
+ // If the user wants to use the contextMenu, when changing the placeholder, the contextMenu is closed
5765
+ // This is a workaround to mitigate this behavior in scenarios where the placeholder is not specified.
5766
+ if (rest.placeholder) {
5767
+ // Display placeholder in a delay to offset the label animation
5768
+ // If we show it immediately, they'll overlap and look ugly
5769
+ timer.current = setTimeout(function () { return setDisplayPlaceholder(true); }, 50);
5885
5770
  }
5886
5771
  }
5887
- if (medium) {
5888
- style.fontFamily = "Inter-SemiBold";
5889
- if (reactNative.Platform.OS === "ios") {
5890
- style.fontWeight = "600";
5772
+ else {
5773
+ // hidePlaceholder
5774
+ setDisplayPlaceholder(false);
5775
+ }
5776
+ return function () {
5777
+ if (timer.current) {
5778
+ clearTimeout(timer.current);
5891
5779
  }
5780
+ };
5781
+ }, [focused, rest.label, rest.placeholder]);
5782
+ React__default["default"].useEffect(function () {
5783
+ labeled.stopAnimation();
5784
+ // The label should be minimized if the text input is focused, or has text
5785
+ // In minimized mode, the label moves up and becomes small
5786
+ // workaround for animated regression for react native > 0.61
5787
+ // https://github.com/callstack/react-native-paper/pull/1440
5788
+ if (value || focused) {
5789
+ // minimize label
5790
+ reactNative.Animated.timing(labeled, {
5791
+ toValue: 0,
5792
+ duration: BLUR_ANIMATION_DURATION * scale,
5793
+ // To prevent this - https://github.com/callstack/react-native-paper/issues/941
5794
+ useNativeDriver: true,
5795
+ }).start();
5892
5796
  }
5893
- return reactNative.StyleSheet.create({ style: style }).style;
5797
+ else {
5798
+ // restore label
5799
+ reactNative.Animated.timing(labeled, {
5800
+ toValue: 1,
5801
+ duration: FOCUS_ANIMATION_DURATION * scale,
5802
+ // To prevent this - https://github.com/callstack/react-native-paper/issues/941
5803
+ useNativeDriver: true,
5804
+ }).start();
5805
+ }
5806
+ }, [focused, value, labeled, scale]);
5807
+ var onLeftAffixLayoutChange = React__default["default"].useCallback(function (event) {
5808
+ var height = roundLayoutSize(event.nativeEvent.layout.height);
5809
+ var width = roundLayoutSize(event.nativeEvent.layout.width);
5810
+ if (width !== leftLayout.width || height !== leftLayout.height) {
5811
+ setLeftLayout({
5812
+ width: width,
5813
+ height: height,
5814
+ });
5815
+ }
5816
+ }, [leftLayout.height, leftLayout.width]);
5817
+ var onRightAffixLayoutChange = React__default["default"].useCallback(function (event) {
5818
+ var width = roundLayoutSize(event.nativeEvent.layout.width);
5819
+ var height = roundLayoutSize(event.nativeEvent.layout.height);
5820
+ if (width !== rightLayout.width || height !== rightLayout.height) {
5821
+ setRightLayout({
5822
+ width: width,
5823
+ height: height,
5824
+ });
5825
+ }
5826
+ }, [rightLayout.height, rightLayout.width]);
5827
+ var handleFocus = function (args) {
5828
+ var _a;
5829
+ if (disabled || !editable) {
5830
+ return;
5831
+ }
5832
+ setFocused(true);
5833
+ (_a = rest.onFocus) === null || _a === void 0 ? void 0 : _a.call(rest, args);
5894
5834
  };
5895
- var defaultStyle = _getStyle();
5896
- var Component = reactNative.Text;
5897
- return (React__default["default"].createElement(Component, __assign({ onPress: onPress, style: [defaultStyle, props.style], allowFontScaling: false }, rest), children));
5835
+ var handleBlur = function (args) {
5836
+ var _a;
5837
+ if (!editable) {
5838
+ return;
5839
+ }
5840
+ setFocused(false);
5841
+ (_a = rest.onBlur) === null || _a === void 0 ? void 0 : _a.call(rest, args);
5842
+ };
5843
+ var handleChangeText = function (value) {
5844
+ var _a;
5845
+ if (!editable || disabled) {
5846
+ return;
5847
+ }
5848
+ if (!isControlled) {
5849
+ // Keep track of value in local state when input is not controlled
5850
+ setUncontrolledValue(value);
5851
+ }
5852
+ (_a = rest.onChangeText) === null || _a === void 0 ? void 0 : _a.call(rest, value);
5853
+ };
5854
+ var handleLayoutAnimatedText = React__default["default"].useCallback(function (e) {
5855
+ var width = roundLayoutSize(e.nativeEvent.layout.width);
5856
+ var height = roundLayoutSize(e.nativeEvent.layout.height);
5857
+ if (width !== labelLayout.width || height !== labelLayout.height) {
5858
+ setLabelLayout({
5859
+ width: width,
5860
+ height: height,
5861
+ measured: true,
5862
+ });
5863
+ }
5864
+ }, [labelLayout.height, labelLayout.width]);
5865
+ var handleLabelTextLayout = React__default["default"].useCallback(function (_a) {
5866
+ var nativeEvent = _a.nativeEvent;
5867
+ setLabelTextLayout({
5868
+ width: nativeEvent.lines.reduce(function (acc, line) { return acc + Math.ceil(line.width); }, 0),
5869
+ });
5870
+ }, []);
5871
+ var handleInputContainerLayout = React__default["default"].useCallback(function (_a) {
5872
+ var layout = _a.nativeEvent.layout;
5873
+ setInputContainerLayout({
5874
+ width: layout.width,
5875
+ });
5876
+ }, []);
5877
+ var forceFocus = React__default["default"].useCallback(function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); }, []);
5878
+ var _s = rest.maxFontSizeMultiplier, maxFontSizeMultiplier = _s === void 0 ? 1.5 : _s;
5879
+ var scaledLabel = !!(value || focused);
5880
+ if (mode === "default") {
5881
+ return (React__default["default"].createElement(TextInputDefault, __assign({ dense: dense, disabled: disabled, error: errorProp, multiline: multiline, editable: editable, render: render }, rest, { theme: theme, value: value, placeholderTextColor: placeholderTextColor, clearButton: clearButton, parentState: {
5882
+ labeled: labeled,
5883
+ error: error,
5884
+ focused: focused,
5885
+ displayPlaceholder: displayPlaceholder,
5886
+ value: value,
5887
+ labelTextLayout: labelTextLayout,
5888
+ labelLayout: labelLayout,
5889
+ leftLayout: leftLayout,
5890
+ rightLayout: rightLayout,
5891
+ inputContainerLayout: inputContainerLayout,
5892
+ }, innerRef: function (ref) {
5893
+ root.current = ref;
5894
+ }, onFocus: handleFocus, forceFocus: forceFocus, onBlur: handleBlur, allowFontScaling: false, onChangeText: handleChangeText, onLayoutAnimatedText: handleLayoutAnimatedText, onInputLayout: handleInputContainerLayout, onLabelTextLayout: handleLabelTextLayout, onLeftAffixLayoutChange: onLeftAffixLayoutChange, onRightAffixLayoutChange: onRightAffixLayoutChange, maxFontSizeMultiplier: maxFontSizeMultiplier, contentStyle: contentStyle, scaledLabel: scaledLabel })));
5895
+ }
5896
+ return (React__default["default"].createElement(TextInputFlat, __assign({ dense: dense, disabled: disabled, error: errorProp, multiline: false, editable: editable, clearButton: clearButton, render: render }, rest, { theme: theme, value: value, parentState: {
5897
+ labeled: labeled,
5898
+ error: error,
5899
+ focused: focused,
5900
+ displayPlaceholder: displayPlaceholder,
5901
+ value: value,
5902
+ labelTextLayout: labelTextLayout,
5903
+ labelLayout: labelLayout,
5904
+ leftLayout: leftLayout,
5905
+ rightLayout: rightLayout,
5906
+ inputContainerLayout: inputContainerLayout,
5907
+ }, innerRef: function (ref) {
5908
+ root.current = ref;
5909
+ }, onFocus: handleFocus, forceFocus: forceFocus, onBlur: handleBlur, onInputLayout: handleInputContainerLayout, allowFontScaling: false, onChangeText: handleChangeText, onLayoutAnimatedText: handleLayoutAnimatedText, onLabelTextLayout: handleLabelTextLayout, onLeftAffixLayoutChange: onLeftAffixLayoutChange, onRightAffixLayoutChange: onRightAffixLayoutChange, maxFontSizeMultiplier: maxFontSizeMultiplier, contentStyle: contentStyle, scaledLabel: scaledLabel })));
5910
+ });
5911
+ // @component ./Adornment/TextInputIcon.tsx
5912
+ // @component ./Adornment/TextInputAffix.tsx
5913
+ // @ts-ignore Types of property 'theme' are incompatible.
5914
+ TextInput.Affix = TextInputAffix;
5915
+
5916
+ var ScaleButton = function (_a) {
5917
+ var children = _a.children; _a.style; var _b = _a.onPress, onPress = _b === void 0 ? function () { } : _b, rest = __rest(_a, ["children", "style", "onPress"]);
5918
+ return (React__default["default"].createElement(reactNative.TouchableOpacity, __assign({}, rest, { onPress: onPress }), children));
5898
5919
  };
5899
- var Text$1 = memoDeepEqual(Text);
5920
+ var ScaleButton$1 = React__default["default"].memo(ScaleButton);
5900
5921
 
5901
5922
  var Button = function (_a) {
5902
5923
  var style = _a.style, title = _a.title, borderColor = _a.borderColor, isLoading = _a.isLoading, left = _a.left, right = _a.right, small = _a.small, textStyle = _a.textStyle, onPress = _a.onPress, disabled = _a.disabled, backgroundColor = _a.backgroundColor, textColor = _a.textColor, _b = _a.bold, bold = _b === void 0 ? true : _b, _c = _a.size, size = _c === void 0 ? 16 : _c, _d = _a.medium, medium = _d === void 0 ? false : _d, _e = _a.mode, mode = _e === void 0 ? "contained" : _e; _a.theme; var props = __rest(_a, ["style", "title", "borderColor", "isLoading", "left", "right", "small", "textStyle", "onPress", "disabled", "backgroundColor", "textColor", "bold", "size", "medium", "mode", "theme"]);