playbook_ui 12.24.0.pre.alpha.play824733 → 12.24.0.pre.alpha.play824751
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_docs/kit_example.rb +0 -2
- data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +55 -20
- data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx +0 -1
- data/app/pb_kits/playbook/pb_phone_number_input/phone_number_input.rb +2 -1
- data/dist/playbook-rails.js +51 -0
- data/lib/playbook/version.rb +1 -1
- data/lib/playbook.rb +1 -2
- metadata +7 -36
- data/app/pb_kits/playbook/pb_docs/kit_api.html.erb +0 -311
- data/app/pb_kits/playbook/pb_docs/kit_api.rb +0 -149
- data/lib/playbook/markdown/helper.rb +0 -132
- data/lib/playbook/markdown.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5503eadd4386d152eb7752caba4840d365949ca4c5d09c43baf70cc8db2891f
|
4
|
+
data.tar.gz: e9ed9534523628eb3e10521351693c0059e0f8c76cd8191637fb3d2186ffae80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 051e744be441f6bd044f4e0a839f476ca6f5dadd5257ec09a85cd38976997c2fab5097cb64466ed3fb98168c686ad63e6626f05882a4dc3e6d74feeb209361e9
|
7
|
+
data.tar.gz: d46b69dd2c251c613f2665d9181446e7e92e7a024a80a218cab9e28f1aff2613c2da65be6bc83dba06c0da6c719186bec6d3da958095b511f008e91cf1964b4d
|
@@ -5,8 +5,6 @@
|
|
5
5
|
module Playbook
|
6
6
|
module PbDocs
|
7
7
|
class KitExample < Playbook::KitBase
|
8
|
-
include Playbook::Markdown::Helper
|
9
|
-
|
10
8
|
prop :kit, type: Playbook::Props::String, required: true
|
11
9
|
prop :example_title, type: Playbook::Props::String, required: true
|
12
10
|
prop :example_key, type: Playbook::Props::String, required: true
|
@@ -41,6 +41,8 @@ type PhoneNumberInputProps = {
|
|
41
41
|
enum ValidationError {
|
42
42
|
TooShort = 2,
|
43
43
|
TooLong = 3,
|
44
|
+
MissingAreaCode = 4,
|
45
|
+
SomethingWentWrong = -99
|
44
46
|
}
|
45
47
|
|
46
48
|
const formatToGlobalCountryName = (countryName: string) => {
|
@@ -109,35 +111,68 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
109
111
|
}
|
110
112
|
}, [error, onValidate])
|
111
113
|
|
114
|
+
if (itiInit) isValid(itiInit.isValidNumber())
|
115
|
+
|
116
|
+
const showFormattedError = (reason = '') => {
|
117
|
+
const countryName = itiInit.getSelectedCountryData().name
|
118
|
+
const reasonText = reason.length > 0 ? ` (${reason})` : ''
|
119
|
+
setError(`Invalid ${countryName} phone number${reasonText}`)
|
120
|
+
return true
|
121
|
+
}
|
122
|
+
|
112
123
|
const validateTooLongNumber = (itiInit: any) => {
|
113
|
-
|
124
|
+
if (!itiInit) return
|
125
|
+
if (itiInit.getValidationError() === ValidationError.TooLong) {
|
126
|
+
return showFormattedError('too long')
|
127
|
+
} else {
|
128
|
+
setError('')
|
129
|
+
}
|
130
|
+
}
|
114
131
|
|
115
|
-
|
116
|
-
|
117
|
-
|
132
|
+
const validateTooShortNumber = (itiInit: any) => {
|
133
|
+
if (!itiInit) return
|
134
|
+
if (itiInit.getValidationError() === ValidationError.TooShort) {
|
135
|
+
return showFormattedError('too short')
|
118
136
|
} else {
|
119
|
-
setError(
|
137
|
+
setError('')
|
120
138
|
}
|
121
139
|
}
|
122
140
|
|
123
|
-
const
|
124
|
-
|
141
|
+
const validateOnlyNumbers = (itiInit: any) => {
|
142
|
+
if (!itiInit) return
|
143
|
+
if (inputValue && !containOnlyNumbers(inputValue)) {
|
144
|
+
return showFormattedError('enter numbers only')
|
145
|
+
}
|
146
|
+
}
|
125
147
|
|
126
|
-
|
127
|
-
|
128
|
-
|
148
|
+
const validateUnhandledError = (itiInit: any) => {
|
149
|
+
if (!required || !itiInit) return
|
150
|
+
if (itiInit.getValidationError() === ValidationError.SomethingWentWrong) {
|
151
|
+
if (inputValue.length === 1) {
|
152
|
+
return showFormattedError('too short')
|
153
|
+
} else if (inputValue.length === 0) {
|
154
|
+
setError('Missing phone number')
|
155
|
+
return true
|
156
|
+
} else {
|
157
|
+
return showFormattedError()
|
158
|
+
}
|
129
159
|
}
|
130
160
|
}
|
131
161
|
|
132
|
-
const
|
133
|
-
if (
|
134
|
-
|
162
|
+
const validateMissingAreaCode = (itiInit: any) => {
|
163
|
+
if (!required || !itiInit) return
|
164
|
+
if (itiInit.getValidationError() === ValidationError.MissingAreaCode) {
|
165
|
+
showFormattedError('missing area code')
|
166
|
+
return true
|
135
167
|
}
|
136
168
|
}
|
137
169
|
|
138
170
|
const validateErrors = () => {
|
139
|
-
|
140
|
-
|
171
|
+
if (validateOnlyNumbers(itiInit)) return
|
172
|
+
if (validateTooLongNumber(itiInit)) return
|
173
|
+
if (validateTooShortNumber(itiInit)) return
|
174
|
+
if (validateUnhandledError(itiInit)) return
|
175
|
+
if (validateMissingAreaCode(itiInit)) return
|
141
176
|
}
|
142
177
|
|
143
178
|
const getCurrentSelectedData = (itiInit: any, inputValue: string) => {
|
@@ -146,11 +181,9 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
146
181
|
|
147
182
|
const handleOnChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
|
148
183
|
setInputValue(evt.target.value)
|
149
|
-
validateTooLongNumber(itiInit)
|
150
184
|
const phoneNumberData = getCurrentSelectedData(itiInit, evt.target.value)
|
151
185
|
setSelectedData(phoneNumberData)
|
152
186
|
onChange(phoneNumberData)
|
153
|
-
isValid(itiInit.isValidNumber())
|
154
187
|
}
|
155
188
|
|
156
189
|
// Separating Concerns as React Docs Recommend
|
@@ -158,20 +191,21 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
158
191
|
useEffect(formatAllCountries, [])
|
159
192
|
|
160
193
|
useEffect(() => {
|
161
|
-
const telInputInit =
|
194
|
+
const telInputInit = intlTelInput(inputRef.current, {
|
162
195
|
separateDialCode: true,
|
163
196
|
preferredCountries,
|
164
197
|
allowDropdown: !disabled,
|
198
|
+
autoInsertDialCode: false,
|
165
199
|
initialCountry,
|
166
200
|
onlyCountries,
|
201
|
+
utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/18.1.6/js/utils.min.js"
|
167
202
|
})
|
168
203
|
|
169
204
|
inputRef.current.addEventListener("countrychange", (evt: Event) => {
|
170
|
-
validateTooLongNumber(telInputInit)
|
171
205
|
const phoneNumberData = getCurrentSelectedData(telInputInit, (evt.target as HTMLInputElement).value)
|
172
206
|
setSelectedData(phoneNumberData)
|
173
207
|
onChange(phoneNumberData)
|
174
|
-
|
208
|
+
validateErrors()
|
175
209
|
})
|
176
210
|
|
177
211
|
inputRef.current.addEventListener("open:countrydropdown", () => setDropDownIsOpen(true))
|
@@ -186,6 +220,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
186
220
|
"data-phone-number": JSON.stringify(selectedData),
|
187
221
|
disabled,
|
188
222
|
error,
|
223
|
+
type: 'tel',
|
189
224
|
id,
|
190
225
|
label,
|
191
226
|
name,
|
@@ -17,7 +17,8 @@ module Playbook
|
|
17
17
|
default: []
|
18
18
|
prop :preferred_countries, type: Playbook::Props::Array,
|
19
19
|
default: []
|
20
|
-
prop :error, type: Playbook::Props::String
|
20
|
+
prop :error, type: Playbook::Props::String,
|
21
|
+
default: ""
|
21
22
|
prop :value, type: Playbook::Props::String,
|
22
23
|
default: ""
|
23
24
|
|