@vygruppen/spor-react 11.3.6 → 11.3.8

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": "@vygruppen/spor-react",
3
- "version": "11.3.6",
3
+ "version": "11.3.8",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -31,9 +31,9 @@
31
31
  "react-aria": "^3.33.1",
32
32
  "react-stately": "^3.31.1",
33
33
  "react-swipeable": "^7.0.1",
34
- "@vygruppen/spor-icon-react": "3.13.0",
35
- "@vygruppen/spor-loader": "0.5.0",
36
- "@vygruppen/spor-design-tokens": "3.10.0"
34
+ "@vygruppen/spor-design-tokens": "3.10.0",
35
+ "@vygruppen/spor-icon-react": "3.14.0",
36
+ "@vygruppen/spor-loader": "0.5.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@react-types/datepicker": "^3.10.0",
@@ -5,18 +5,23 @@ import { AttachedInputs } from "./AttachedInputs";
5
5
  import { CountryCodeSelect } from "./CountryCodeSelect";
6
6
  import { As } from "@chakra-ui/system";
7
7
 
8
- type CountryCodeAndPhoneNumber = {
8
+ export type CountryCodeAndPhoneNumber = {
9
9
  countryCode: string;
10
10
  nationalNumber: string;
11
11
  };
12
- type PhoneNumberInputProps = Omit<BoxProps, "onChange"> & {
12
+ export type PhoneNumberInputProps = Omit<BoxProps, "onChange"> & {
13
13
  /** The label. Defaults to a localized version of "Phone number" */
14
14
  label?: string;
15
15
  /** The root name.
16
16
  *
17
- * Please note that when specifying the name, the rendered names will be `${name}-country-code` and `${name}-phone-number`, respectively
17
+ * Please note that when specifying the name, the rendered names will be `${name}-country-code` and `${name}-phone-number` unless a name is provided for both countryCode and nationalNumber.
18
18
  */
19
- name?: string;
19
+ name?:
20
+ | string
21
+ | {
22
+ countryCode: string;
23
+ nationalNumber: string;
24
+ };
20
25
  /** Callback for when the country code or phone number changes */
21
26
  onChange?: (change: CountryCodeAndPhoneNumber) => void;
22
27
  /** The optional value of the country code and phone number */
@@ -31,7 +36,7 @@ type PhoneNumberInputProps = Omit<BoxProps, "onChange"> & {
31
36
  * <PhoneNumberInput name="phone" />
32
37
  * ```
33
38
  *
34
- * > Please note that when specifying the name, the rendered names will be `${name}-country-code` and `${name}-phone-number`, respectively
39
+ * > Please note that when specifying the name, the rendered names will be `${name}-country-code` and `${name}-phone-number` unless a name is provided for both countryCode and nationalNumber.
35
40
  *
36
41
  * The field can be controlled as well:
37
42
  * ```tsx
@@ -76,7 +81,13 @@ export const PhoneNumberInput = forwardRef<PhoneNumberInputProps, As>(
76
81
  nationalNumber: value.nationalNumber,
77
82
  })
78
83
  }
79
- name={name ? `${name}-country-code` : "country-code"}
84
+ name={
85
+ name
86
+ ? typeof name !== "string" && name.countryCode
87
+ ? name.countryCode
88
+ : `${name}-country-code`
89
+ : "country-code"
90
+ }
80
91
  height="100%"
81
92
  width="6.25rem"
82
93
  variant={variant}
@@ -86,7 +97,13 @@ export const PhoneNumberInput = forwardRef<PhoneNumberInputProps, As>(
86
97
  type="tel"
87
98
  label={label}
88
99
  value={value.nationalNumber}
89
- name={name ? `${name}-phone-number` : "phone-number"}
100
+ name={
101
+ name
102
+ ? typeof name !== "string" && name.nationalNumber
103
+ ? name.nationalNumber
104
+ : `${name}-phone-number`
105
+ : "phone-number"
106
+ }
90
107
  onChange={(e) => {
91
108
  // Removes everything but numbers, spaces and dashes
92
109
  const strippedValue = e.target.value.replace(/[^\d\s-]/g, "");