@bigbinary/neeto-molecules 1.0.17 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-molecules",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "A package of reusable molecular components for neeto products.",
5
5
  "repository": "git@github.com:bigbinary/neeto-molecules.git",
6
6
  "author": "Amaljith K <amaljith.k@bigbinary.com>",
@@ -84,6 +84,7 @@
84
84
  "babel-plugin-transform-react-remove-prop-types": "0.4.24",
85
85
  "babel-preset-react": "6.24.1",
86
86
  "babel-preset-typescript": "^7.0.0-alpha.19",
87
+ "countries-list": "^2.6.1",
87
88
  "css-loader": "4.3.0",
88
89
  "cypress": "11.2.0",
89
90
  "dayjs": "1.11.1",
@@ -105,6 +106,7 @@
105
106
  "jest": "27.5.1",
106
107
  "js-logger": "^1.6.1",
107
108
  "json-server": "0.17.1",
109
+ "libphonenumber-js": "^1.10.26",
108
110
  "lint-staged": "^12.3.7",
109
111
  "mixpanel-browser": "^2.45.0",
110
112
  "mousetrap": "^1.6.5",
@@ -329,6 +329,12 @@
329
329
  "emailAddress": "Please enter at least one email address"
330
330
  }
331
331
  }
332
+ },
333
+ "phoneNumberInput": {
334
+ "placeholder": "{{prefix}} type phone number",
335
+ "validations": {
336
+ "invalid": "Phone number is invalid"
337
+ }
332
338
  }
333
339
  }
334
340
  }
@@ -0,0 +1,110 @@
1
+ import React from "react";
2
+ import { InputProps, SelectProps, TypographyProps } from "@bigbinary/neetoui";
3
+ import { CountryCode } from "libphonenumber-js";
4
+ import { StringSchema } from "yup";
5
+ export interface PhoneNumberInputProps extends InputProps {
6
+ value?: string;
7
+ onChange?: (value: string) => any;
8
+ className?: string;
9
+ selectProps?: SelectProps;
10
+ error?: string;
11
+ defaultCountry?: string;
12
+ }
13
+ export interface FormikPhoneNumberInputProps extends PhoneNumberInputProps {
14
+ name: string;
15
+ }
16
+ export interface PhoneNumberProps extends TypographyProps {
17
+ className?: string;
18
+ defaultCountry?: string;
19
+ children?: React.ReactNode;
20
+ showEmoji?: boolean;
21
+ value?: string;
22
+ }
23
+ export const PhoneNumberInput: React.ForwardRefExoticComponent<PhoneNumberInputProps>;
24
+ export const FormikPhoneNumberInput: React.ForwardRefExoticComponent<FormikPhoneNumberInputProps>;
25
+ export
26
+ /**
27
+ *
28
+ * An input component to input and validate phone numbers with a country code
29
+ *
30
+ * picker.
31
+ *
32
+ * ![PhoneNumberInput](https://user-images.githubusercontent.com/35297280/231367938-93aa94b0-2a8c-44b3-b1c7-8c60843e40c4.png|height=200|width=300)
33
+ *
34
+ * Props:
35
+ *
36
+ * @example
37
+ *
38
+ * import React, { useState } from "react";
39
+ *
40
+ * import { PhoneNumberInput } from "@bigbinary/neeto-molecules/PhoneNumber";
41
+ *
42
+ * const App = () => {
43
+ * const [phoneNumber, setPhoneNumber] = useState("");
44
+ *
45
+ * return <PhoneNumberInput value={phoneNumber} onChange={setPhoneNumber} />;
46
+ * };
47
+ * @endexample
48
+ * A typography component to display phone numbers along with the flag of the
49
+ *
50
+ * country associated with it.
51
+ *
52
+ * ![PhoneNumber](https://user-images.githubusercontent.com/35297280/231367945-ee5f0921-92e3-4086-a8e2-f9ab63cf9a37.png|height=200|width=300)
53
+ *
54
+ * Props:
55
+ *
56
+ * @example
57
+ *
58
+ * import { PhoneNumber } from "@bigbinary/neeto-molecules/PhoneNumber";
59
+ *
60
+ * const App = () => <PhoneNumber showEmoji value="+919988776655" />;
61
+ * @endexample
62
+ * The PhoneNumberInput component wrapped in Formik.
63
+ *
64
+ * @example
65
+ *
66
+ * import { FormikPhoneNumberInput, validation } from "@bigbinary/neeto-molecules/PhoneNumber";
67
+ * import { Form } from "@bigbinary/neetoui/formik";
68
+ *
69
+ * const App = () => (
70
+ * return (
71
+ * <Form
72
+ * formikProps={{
73
+ * initialValues: { phoneNumber: "+919988776655" },
74
+ * validationSchema: yup.object({ phoneNumber: validation().required() }),
75
+ * onSubmit: ({ phoneNumber }) => alert(phoneNumber),
76
+ * }}
77
+ * >
78
+ * <FormikPhoneNumberInput name="phoneNumber" />
79
+ * </Form>
80
+ * );
81
+ * );
82
+ * @endexample
83
+ * A utility function that exports a Yup validation schema to be used in Formik. It
84
+ *
85
+ * accepts a string as an optional argument to override the default validation
86
+ *
87
+ * message.
88
+ *
89
+ * @example
90
+ *
91
+ * import { validation } from "@bigbinary/neeto-molecules/PhoneNumber";
92
+ * import * as yup from "yup";
93
+ *
94
+ * const VALIDATION_SCHEMA = yup.object({
95
+ * phoneNumber: validation("Phone number is invalid"),
96
+ * });
97
+ * @endexample
98
+ * A utility function to check whether a phone number is valid. It accepts a phone
99
+ *
100
+ * number and a default country as argument and returns a boolean value specifying
101
+ *
102
+ * whether the phone number is valid or not.
103
+ *
104
+ */
105
+ const PhoneNumber: React.FC<PhoneNumberProps>;
106
+ export const isPhoneNumberValid: (phoneNumber: string, defaultCountry?: CountryCode | {
107
+ defaultCountry?: CountryCode;
108
+ defaultCallingCode?: string;
109
+ }) => boolean;
110
+ export const validation: (message?: string) => StringSchema<any, any, any>;