@thecb/components 10.7.3-beta.0 → 10.7.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +30 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +30 -10
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/atoms/form-layouts/FormInput.js +25 -11
- package/src/components/molecules/payment-form-card/PaymentFormCard.js +1 -0
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useContext } from "react";
|
|
1
|
+
import React, { useState, useContext, useEffect } from "react";
|
|
2
2
|
import styled, { ThemeContext, css } from "styled-components";
|
|
3
3
|
import { FormattedInput } from "formatted-input";
|
|
4
4
|
import { fallbackValues } from "./FormLayouts.theme.js";
|
|
@@ -120,22 +120,35 @@ const FormInput = ({
|
|
|
120
120
|
...props
|
|
121
121
|
}) => {
|
|
122
122
|
const [showPassword, setShowPassword] = useState(false);
|
|
123
|
+
const [initialValue, setInitialValue] = useState(field?.rawValue || "");
|
|
123
124
|
const { isMobile } = useContext(ThemeContext);
|
|
124
125
|
|
|
125
|
-
const setValue =
|
|
126
|
-
if (
|
|
127
|
-
|
|
126
|
+
const setValue = currentValue => {
|
|
127
|
+
if (currentValue !== initialValue) {
|
|
128
|
+
setInitialValue(currentValue);
|
|
128
129
|
}
|
|
129
|
-
return fieldActions.set(value);
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
const handleBlur = currentValue => {
|
|
133
|
+
if (currentValue === "" || currentValue !== initialValue) {
|
|
134
|
+
if (currentValue && removeFromValue !== undefined) {
|
|
135
|
+
fieldActions.set(currentValue.replace(removeFromValue, ""));
|
|
136
|
+
} else {
|
|
137
|
+
fieldActions.set(currentValue);
|
|
138
|
+
}
|
|
136
139
|
}
|
|
137
140
|
};
|
|
138
141
|
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (initialValue) {
|
|
144
|
+
if (removeFromValue !== undefined) {
|
|
145
|
+
fieldActions.set(initialValue.replace(removeFromValue, ""));
|
|
146
|
+
} else {
|
|
147
|
+
fieldActions.set(initialValue);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}, [initialValue]);
|
|
151
|
+
|
|
139
152
|
return (
|
|
140
153
|
<Stack childGap="0.25rem">
|
|
141
154
|
<Box padding="0">
|
|
@@ -211,8 +224,9 @@ const FormInput = ({
|
|
|
211
224
|
(field.dirty && field.hasErrors) ||
|
|
212
225
|
(field.hasErrors && showErrors)
|
|
213
226
|
}
|
|
227
|
+
onFocus={e => setValue(e.target?.value)}
|
|
214
228
|
onChange={value => setValue(value)}
|
|
215
|
-
onBlur={e =>
|
|
229
|
+
onBlur={e => handleBlur(e.target.value)}
|
|
216
230
|
type={type}
|
|
217
231
|
value={field.rawValue}
|
|
218
232
|
pattern={isNum ? "[0-9]*" : ""}
|
|
@@ -240,7 +254,7 @@ const FormInput = ({
|
|
|
240
254
|
(field.hasErrors && showErrors)
|
|
241
255
|
}
|
|
242
256
|
onChange={e => setValue(e.target.value)}
|
|
243
|
-
onBlur={e =>
|
|
257
|
+
onBlur={e => handleBlur(e.target.value)}
|
|
244
258
|
type={type === "password" && showPassword ? "text" : type}
|
|
245
259
|
value={field.rawValue}
|
|
246
260
|
pattern={isNum ? "[0-9]*" : ""}
|