@symply.io/basic-components 1.0.0-alpha.17 → 1.0.0-alpha.18
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/FeinInput/index.d.ts +6 -0
- package/FeinInput/index.js +73 -0
- package/FeinInput/types.d.ts +9 -0
- package/FeinInput/types.js +1 -0
- package/FeinInput/useInteractions.d.ts +8 -0
- package/FeinInput/useInteractions.js +16 -0
- package/README.md +24 -2
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +1 -1
@@ -0,0 +1,6 @@
|
|
1
|
+
import { FeinInputProps } from "./types";
|
2
|
+
export declare function FeinInputFormat(str: string): string;
|
3
|
+
export declare function verifyFein(feinString: string): boolean;
|
4
|
+
declare function FeinInput(props: FeinInputProps): JSX.Element;
|
5
|
+
export default FeinInput;
|
6
|
+
export * from "./types";
|
@@ -0,0 +1,73 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
+
var t = {};
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
+
t[p] = s[p];
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
+
t[p[i]] = s[p[i]];
|
20
|
+
}
|
21
|
+
return t;
|
22
|
+
};
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
24
|
+
import { useRifm } from "rifm";
|
25
|
+
import ThemeProvider from "@mui/material/styles/ThemeProvider";
|
26
|
+
import TextField from "@mui/material/TextField";
|
27
|
+
import useInteractions from "./useInteractions";
|
28
|
+
import useCustomTheme from "../useCustomTheme";
|
29
|
+
export function FeinInputFormat(str) {
|
30
|
+
var digits = (str.match(/\d+/g) || []).join("");
|
31
|
+
var chars = digits.split("");
|
32
|
+
return chars.reduce(function (prev, curr, index) {
|
33
|
+
if (index === 2) {
|
34
|
+
return "".concat(prev, " - ").concat(curr);
|
35
|
+
}
|
36
|
+
else {
|
37
|
+
return "".concat(prev).concat(curr);
|
38
|
+
}
|
39
|
+
}, "");
|
40
|
+
}
|
41
|
+
export function verifyFein(feinString) {
|
42
|
+
var reg = /^\d{2}\s?-\s?\d{7}$/g;
|
43
|
+
return reg.test(feinString);
|
44
|
+
}
|
45
|
+
function FeinInput(props) {
|
46
|
+
var value = props.value, _a = props.error, error = _a === void 0 ? false : _a, _b = props.helperText, helperText = _b === void 0 ? "Please enter a valid FEIN" : _b, onChange = props.onChange, verifyFn = props.verifyFn, onFocus = props.onFocus, onBlur = props.onBlur, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, rest = __rest(props, ["value", "error", "helperText", "onChange", "verifyFn", "onFocus", "onBlur", "primaryColor", "secondaryColor"]);
|
47
|
+
var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
|
48
|
+
var _c = useInteractions({ value: value }), valLength = _c.valLength, addMask = _c.addMask;
|
49
|
+
var rifm = useRifm({
|
50
|
+
mask: true,
|
51
|
+
value: String(value),
|
52
|
+
onChange: onChange,
|
53
|
+
replace: addMask,
|
54
|
+
format: FeinInputFormat
|
55
|
+
});
|
56
|
+
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(TextField, __assign({ value: rifm.value, onChange: rifm.onChange, error: error ||
|
57
|
+
(valLength > 0 && (verifyFn ? !verifyFn(value) : verifyFein(value))), helperText: valLength > 0 && (verifyFn ? !verifyFn(value) : verifyFein(value))
|
58
|
+
? helperText
|
59
|
+
: "", onFocus: function (event) {
|
60
|
+
if (onFocus) {
|
61
|
+
onFocus(event);
|
62
|
+
}
|
63
|
+
}, onBlur: function (event) {
|
64
|
+
onChange(value.trim());
|
65
|
+
if (onBlur) {
|
66
|
+
onBlur(event);
|
67
|
+
}
|
68
|
+
}, InputLabelProps: {
|
69
|
+
shrink: true
|
70
|
+
} }, rest)) })));
|
71
|
+
}
|
72
|
+
export default FeinInput;
|
73
|
+
export * from "./types";
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { CSSProperties } from "react";
|
2
|
+
import { TextFieldProps } from "@mui/material/TextField";
|
3
|
+
export interface FeinInputProps extends Omit<TextFieldProps, "onChange"> {
|
4
|
+
onChange: (value: string) => void;
|
5
|
+
verifyFn?: (value?: string) => boolean;
|
6
|
+
value: string;
|
7
|
+
primaryColor?: CSSProperties["color"];
|
8
|
+
secondaryColor?: CSSProperties["color"];
|
9
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
2
|
+
function useInteractions(props) {
|
3
|
+
var value = props.value;
|
4
|
+
var addMask = useCallback(function (str) {
|
5
|
+
var digits = (str.match(/\d+/g) || []).join("");
|
6
|
+
var areaCode = digits.slice(0, 2).padEnd(2, "_");
|
7
|
+
var prefixCode = digits.slice(2, 9).padEnd(7, "_");
|
8
|
+
return "".concat(areaCode, " - ").concat(prefixCode);
|
9
|
+
}, []);
|
10
|
+
var valLength = useMemo(function () {
|
11
|
+
var digitsArr = String(value).match(/\d/g);
|
12
|
+
return digitsArr ? digitsArr.length : 0;
|
13
|
+
}, [value]);
|
14
|
+
return { valLength: valLength, addMask: addMask };
|
15
|
+
}
|
16
|
+
export default useInteractions;
|
package/README.md
CHANGED
@@ -237,8 +237,6 @@ import { CheckBox } from '@symply.io/basic-components/CheckBox';
|
|
237
237
|
|
238
238
|
|
239
239
|
|
240
|
-
|
241
|
-
|
242
240
|
<h3>CheckBoxGroup</h3>
|
243
241
|
|
244
242
|
Checkboxes allow the user to select one or more items from a set for a group.
|
@@ -302,6 +300,30 @@ import DigitInput from '@symply.io/basic-components/DigitInput';
|
|
302
300
|
|
303
301
|
|
304
302
|
|
303
|
+
<h3>FeinInput</h3>
|
304
|
+
|
305
|
+
Input component for FEIN.
|
306
|
+
|
307
|
+
It is extended from `@mui/material/TextField`, so it includes all properties of `@mui/material/TextField`.
|
308
|
+
|
309
|
+
<h5>Import</h5>
|
310
|
+
|
311
|
+
```typescript
|
312
|
+
import { FeinInput } from '@symply.io/basic-components/';
|
313
|
+
// or
|
314
|
+
import FeinInput from '@symply.io/basic-components/FeinInput';
|
315
|
+
```
|
316
|
+
|
317
|
+
<h5>Props</h5>
|
318
|
+
|
319
|
+
| Name | Type | Default | Required | Description |
|
320
|
+
| -------- | ------ | ------- | -------- | ------------------------------------------------------------ |
|
321
|
+
| onChange | func | | true | Callback fired when the `Input` value is changed.<br />**Signature:**<br/>`function(value: string) => void`<br/>*value:* The value of the `Input` element. |
|
322
|
+
| value | string | | true | The value of the `Input` element. |
|
323
|
+
| verifyFn | func | | false | Customized verification function. |
|
324
|
+
|
325
|
+
|
326
|
+
|
305
327
|
<h3>FormRadioGroup</h3>
|
306
328
|
|
307
329
|
Radio Group allow the user to select one option from a set.
|
package/index.d.ts
CHANGED
@@ -7,6 +7,7 @@ export * from "./CheckBox";
|
|
7
7
|
export * from "./Copyright";
|
8
8
|
export * from "./DigitInput";
|
9
9
|
export * from "./DynamicHeaderBar";
|
10
|
+
export * from "./FeinInput";
|
10
11
|
export * from "./FormRadioGroup";
|
11
12
|
export * from "./FormSelector";
|
12
13
|
export * from "./HelpCaption";
|
@@ -28,6 +29,7 @@ export { default as BreadCrumbs } from "./BreadCrumbs";
|
|
28
29
|
export { default as Copyright } from "./Copyright";
|
29
30
|
export { default as DigitInput } from "./DigitInput";
|
30
31
|
export { default as DynamicHeaderBar } from "./DynamicHeaderBar";
|
32
|
+
export { default as FeinInput } from "./FeinInput";
|
31
33
|
export { default as FormRadioGroup } from "./FormRadioGroup";
|
32
34
|
export { default as HelpCaption } from "./HelpCaption";
|
33
35
|
export { default as LoadingModal } from "./LoadingModal";
|
package/index.js
CHANGED
@@ -7,6 +7,7 @@ export * from "./CheckBox";
|
|
7
7
|
export * from "./Copyright";
|
8
8
|
export * from "./DigitInput";
|
9
9
|
export * from "./DynamicHeaderBar";
|
10
|
+
export * from "./FeinInput";
|
10
11
|
export * from "./FormRadioGroup";
|
11
12
|
export * from "./FormSelector";
|
12
13
|
export * from "./HelpCaption";
|
@@ -28,6 +29,7 @@ export { default as BreadCrumbs } from "./BreadCrumbs";
|
|
28
29
|
export { default as Copyright } from "./Copyright";
|
29
30
|
export { default as DigitInput } from "./DigitInput";
|
30
31
|
export { default as DynamicHeaderBar } from "./DynamicHeaderBar";
|
32
|
+
export { default as FeinInput } from "./FeinInput";
|
31
33
|
export { default as FormRadioGroup } from "./FormRadioGroup";
|
32
34
|
export { default as HelpCaption } from "./HelpCaption";
|
33
35
|
export { default as LoadingModal } from "./LoadingModal";
|