playbook_ui 12.5.0.pre.alpha.phonerails1 → 12.5.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.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +47 -61
- data/app/pb_kits/playbook/pb_phone_number_input/docs/example.yml +1 -4
- data/app/pb_kits/playbook/pb_phone_number_input/phone_number_input.html.erb +15 -1
- data/lib/playbook/version.rb +2 -2
- metadata +4 -7
- data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_initial_country.html.erb +0 -3
- data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_only_countries.html.erb +0 -4
- data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_preferred_countries.html.erb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92319a3771d2aa0a3198e988dc95b91e977ee532db2884cd6197912cb045caae
|
4
|
+
data.tar.gz: caaa026385dd1d94a65175ba00ef818caab6a901c5bb0da90cd24920158e885f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7469df006da7d11b70de500123a4d260db2a2c8c0b79ee80766dde6a760eaa81c71b59880aad14ee48a7d9ee91b2c6237e766b8c046a19b088b61830b0e5f2b6
|
7
|
+
data.tar.gz: 7e0f3a0e05f403da3b31e8b21ab01ee92fb4139a5223af663a62f9672ff381009a75cd1a9f30ea57289e28ffda043f23cab7364eae1e54973e9f4922d8884f28
|
@@ -1,32 +1,32 @@
|
|
1
1
|
/* @flow */
|
2
|
-
import React, { useEffect, useRef, useState } from
|
3
|
-
import classnames from
|
4
|
-
import { buildAriaProps, buildCss, buildDataProps } from
|
5
|
-
import { globalProps } from
|
6
|
-
import intlTelInput from
|
7
|
-
import
|
8
|
-
import TextInput from
|
2
|
+
import React, { useEffect, useRef, useState } from 'react'
|
3
|
+
import classnames from 'classnames'
|
4
|
+
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
5
|
+
import { globalProps } from '../utilities/globalProps'
|
6
|
+
import intlTelInput from 'intl-tel-input'
|
7
|
+
import 'intl-tel-input/build/css/intlTelInput.css'
|
8
|
+
import TextInput from '../pb_text_input/_text_input'
|
9
9
|
|
10
10
|
declare global {
|
11
11
|
interface Window {
|
12
|
-
intlTelInputGlobals: any
|
12
|
+
intlTelInputGlobals: any,
|
13
13
|
}
|
14
14
|
}
|
15
15
|
|
16
16
|
type PhoneNumberInputProps = {
|
17
|
-
aria?: { [key: string]: string }
|
18
|
-
className?: string
|
19
|
-
data?: { [key: string]: string }
|
20
|
-
disabled?: boolean
|
21
|
-
id?: string
|
22
|
-
initialCountry?: string
|
23
|
-
isValid?: (valid: boolean) => void
|
24
|
-
label?: string
|
25
|
-
name?: string
|
26
|
-
onChange?: (e: React.FormEvent<HTMLInputElement>) => void
|
27
|
-
onlyCountries: string[]
|
28
|
-
preferredCountries?: string[]
|
29
|
-
value?: string
|
17
|
+
aria?: { [key: string]: string },
|
18
|
+
className?: string,
|
19
|
+
data?: { [key: string]: string },
|
20
|
+
disabled?: boolean,
|
21
|
+
id?: string,
|
22
|
+
initialCountry?: string,
|
23
|
+
isValid?: (valid: boolean) => void,
|
24
|
+
label?: string,
|
25
|
+
name?: string,
|
26
|
+
onChange?: (e: React.FormEvent<HTMLInputElement>) => void,
|
27
|
+
onlyCountries: string[],
|
28
|
+
preferredCountries?: string[],
|
29
|
+
value?: string,
|
30
30
|
}
|
31
31
|
|
32
32
|
enum ValidationError {
|
@@ -35,20 +35,17 @@ enum ValidationError {
|
|
35
35
|
}
|
36
36
|
|
37
37
|
const formatToGlobalCountryName = (countryName: string) => {
|
38
|
-
return countryName.split(
|
38
|
+
return countryName.split('(')[0].trim()
|
39
39
|
}
|
40
40
|
|
41
41
|
const formatAllCountries = () => {
|
42
42
|
let countryData = window.intlTelInputGlobals.getCountryData()
|
43
|
-
|
44
43
|
for (let i = 0; i < countryData.length; i++) {
|
45
44
|
let country = countryData[i]
|
46
45
|
country.name = formatToGlobalCountryName(country.name)
|
47
46
|
}
|
48
47
|
}
|
49
48
|
|
50
|
-
formatAllCountries()
|
51
|
-
|
52
49
|
const containOnlyNumbers = (value: string) => {
|
53
50
|
return /^(\++)*(\d+)$/.test(value)
|
54
51
|
}
|
@@ -59,33 +56,25 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
59
56
|
className,
|
60
57
|
data = {},
|
61
58
|
disabled = false,
|
62
|
-
id =
|
63
|
-
initialCountry =
|
64
|
-
isValid = () => {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
name = "",
|
69
|
-
onChange = () => {
|
70
|
-
void 0
|
71
|
-
},
|
59
|
+
id = '',
|
60
|
+
initialCountry = '',
|
61
|
+
isValid = () => {void 0 },
|
62
|
+
label = '',
|
63
|
+
name = '',
|
64
|
+
onChange = () => { void 0 },
|
72
65
|
onlyCountries = [],
|
73
66
|
preferredCountries = [],
|
74
|
-
value =
|
67
|
+
value = '',
|
75
68
|
} = props
|
76
69
|
|
77
70
|
const ariaProps = buildAriaProps(aria)
|
78
71
|
const dataProps = buildDataProps(data)
|
79
|
-
const classes = classnames(
|
80
|
-
buildCss("pb_phone_number_input"),
|
81
|
-
globalProps(props),
|
82
|
-
className
|
83
|
-
)
|
72
|
+
const classes = classnames(buildCss('pb_phone_number_input'), globalProps(props), className)
|
84
73
|
|
85
74
|
const inputRef = useRef<HTMLInputElement>()
|
86
75
|
const [inputValue, setInputValue] = useState(value)
|
87
76
|
const [itiInit, setItiInit] = useState<any>()
|
88
|
-
const [error, setError] = useState(
|
77
|
+
const [error, setError] = useState('')
|
89
78
|
|
90
79
|
const validateTooLongNumber = (itiInit: any) => {
|
91
80
|
const error = itiInit.getValidationError()
|
@@ -94,7 +83,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
94
83
|
const countryName = itiInit.getSelectedCountryData().name
|
95
84
|
setError(`Invalid ${countryName} phone number (too long)`)
|
96
85
|
} else {
|
97
|
-
setError(
|
86
|
+
setError('')
|
98
87
|
}
|
99
88
|
}
|
100
89
|
|
@@ -109,7 +98,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
109
98
|
|
110
99
|
const validateOnlyNumbers = () => {
|
111
100
|
if (inputValue && !containOnlyNumbers(inputValue)) {
|
112
|
-
setError(
|
101
|
+
setError('Invalid phone number. Enter numbers only.')
|
113
102
|
}
|
114
103
|
}
|
115
104
|
|
@@ -125,32 +114,29 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
125
114
|
isValid(itiInit.isValidNumber())
|
126
115
|
}
|
127
116
|
|
128
|
-
// Separating Concerns as React Docs Recommend
|
129
|
-
// This also Fixes things for our react_component rendering on the Rails Side
|
130
117
|
useEffect(() => {
|
131
118
|
formatAllCountries()
|
132
|
-
}, [])
|
133
119
|
|
134
|
-
useEffect(() => {
|
135
120
|
const telInputInit = new intlTelInput(inputRef.current, {
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
})
|
144
|
-
|
145
|
-
inputRef.current.addEventListener("countrychange", () =>
|
146
|
-
validateTooLongNumber(telInputInit)
|
121
|
+
utilsScript: 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.19/js/utils.js',
|
122
|
+
separateDialCode: true,
|
123
|
+
preferredCountries,
|
124
|
+
allowDropdown: !disabled,
|
125
|
+
initialCountry,
|
126
|
+
onlyCountries,
|
127
|
+
}
|
147
128
|
)
|
148
|
-
|
129
|
+
|
130
|
+
inputRef.current.addEventListener("countrychange", () => validateTooLongNumber(telInputInit))
|
149
131
|
setItiInit(telInputInit)
|
150
132
|
}, [])
|
151
133
|
|
152
134
|
return (
|
153
|
-
<div
|
135
|
+
<div
|
136
|
+
{...ariaProps}
|
137
|
+
{...dataProps}
|
138
|
+
className={classes}
|
139
|
+
>
|
154
140
|
<TextInput
|
155
141
|
disabled={disabled}
|
156
142
|
error={error}
|
@@ -7,7 +7,4 @@ examples:
|
|
7
7
|
- phone_number_input_only_countries: Limited Countries
|
8
8
|
|
9
9
|
rails:
|
10
|
-
- phone_number_input_default: Default
|
11
|
-
- phone_number_input_preferred_countries: Preferred Countries
|
12
|
-
- phone_number_input_initial_country: Initial Country
|
13
|
-
- phone_number_input_only_countries: Limited Countries
|
10
|
+
- phone_number_input_default: Default
|
@@ -1 +1,15 @@
|
|
1
|
-
<%= react_component("PhoneNumberInput", object.phone_number_input_options) %>
|
1
|
+
<%= react_component("PhoneNumberInput", object.phone_number_input_options) %>
|
2
|
+
|
3
|
+
<script>
|
4
|
+
const formatToGlobalCountryName = () => {
|
5
|
+
return countryName.split('(')[0].trim()
|
6
|
+
}
|
7
|
+
|
8
|
+
const formatAllCountries = () => {
|
9
|
+
let countryData = window.intlTelInputGlobals.getCountryData()
|
10
|
+
for (let i = 0; i < countryData.length; i++) {
|
11
|
+
let country = countryData[i]
|
12
|
+
country.name = formatToGlobalCountryName(country.name)
|
13
|
+
}
|
14
|
+
}
|
15
|
+
</script>
|
data/lib/playbook/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: playbook_ui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 12.5.0
|
4
|
+
version: 12.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Power UX
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -1561,13 +1561,10 @@ files:
|
|
1561
1561
|
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_default.html.erb
|
1562
1562
|
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_default.jsx
|
1563
1563
|
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_default.md
|
1564
|
-
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_initial_country.html.erb
|
1565
1564
|
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_initial_country.jsx
|
1566
1565
|
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_initial_country.md
|
1567
|
-
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_only_countries.html.erb
|
1568
1566
|
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_only_countries.jsx
|
1569
1567
|
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_only_countries.md
|
1570
|
-
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_preferred_countries.html.erb
|
1571
1568
|
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_preferred_countries.jsx
|
1572
1569
|
- app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_preferred_countries.md
|
1573
1570
|
- app/pb_kits/playbook/pb_phone_number_input/docs/example.yml
|
@@ -2431,9 +2428,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
2431
2428
|
version: '0'
|
2432
2429
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
2433
2430
|
requirements:
|
2434
|
-
- - "
|
2431
|
+
- - ">="
|
2435
2432
|
- !ruby/object:Gem::Version
|
2436
|
-
version:
|
2433
|
+
version: '0'
|
2437
2434
|
requirements: []
|
2438
2435
|
rubygems_version: 3.3.7
|
2439
2436
|
signing_key:
|