playbook_ui 12.25.0.pre.alpha.play824786 → 12.25.0.pre.alpha.railsmultilevelimprovements758
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/_playbook.scss +0 -1
- data/app/pb_kits/playbook/index.js +0 -1
- data/app/pb_kits/playbook/pb_avatar/docs/_avatar_swift.md +1 -82
- data/app/pb_kits/playbook/pb_docs/kit_example.html.erb +13 -14
- data/app/pb_kits/playbook/pb_form_pill/_form_pill.tsx +2 -3
- data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.scss +98 -58
- data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +102 -337
- data/app/pb_kits/playbook/pb_multi_level_select/_multi_select_helper.tsx +31 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_default.html.erb +4 -4
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_default.md +1 -1
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_return_all_selected.html.erb +0 -1
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_with_form.html.erb +72 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_multi_level_select/helper_functions.ts +87 -0
- data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.rb +3 -0
- data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.test.jsx +1 -1
- data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +44 -109
- data/app/pb_kits/playbook/pb_phone_number_input/docs/example.yml +1 -3
- data/app/pb_kits/playbook/pb_phone_number_input/docs/index.js +0 -1
- data/app/pb_kits/playbook/pb_phone_number_input/phone_number_input.rb +0 -6
- data/app/pb_kits/playbook/pb_phone_number_input/phone_number_input.test.js +62 -110
- data/app/pb_kits/playbook/playbook-doc.js +0 -2
- data/dist/menu.yml +0 -1
- data/dist/playbook-rails.js +7 -7
- data/lib/playbook/forms/builder/{intl_telephone_field.rb → multi_level_select_field.rb} +2 -2
- data/lib/playbook/forms/builder.rb +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +6 -26
- data/app/pb_kits/playbook/pb_detail/_detail.scss +0 -44
- data/app/pb_kits/playbook/pb_detail/_detail.tsx +0 -55
- data/app/pb_kits/playbook/pb_detail/_detail_mixins.scss +0 -29
- data/app/pb_kits/playbook/pb_detail/detail.html.erb +0 -7
- data/app/pb_kits/playbook/pb_detail/detail.rb +0 -31
- data/app/pb_kits/playbook/pb_detail/detail.test.jsx +0 -46
- data/app/pb_kits/playbook/pb_detail/docs/_description.md +0 -1
- data/app/pb_kits/playbook/pb_detail/docs/_detail_bold.html.erb +0 -34
- data/app/pb_kits/playbook/pb_detail/docs/_detail_bold.jsx +0 -49
- data/app/pb_kits/playbook/pb_detail/docs/_detail_bold.md +0 -1
- data/app/pb_kits/playbook/pb_detail/docs/_detail_colors.html.erb +0 -24
- data/app/pb_kits/playbook/pb_detail/docs/_detail_colors.jsx +0 -38
- data/app/pb_kits/playbook/pb_detail/docs/_detail_colors.md +0 -6
- data/app/pb_kits/playbook/pb_detail/docs/_detail_default.html.erb +0 -3
- data/app/pb_kits/playbook/pb_detail/docs/_detail_default.jsx +0 -13
- data/app/pb_kits/playbook/pb_detail/docs/_detail_styled.html.erb +0 -22
- data/app/pb_kits/playbook/pb_detail/docs/_detail_styled.jsx +0 -32
- data/app/pb_kits/playbook/pb_detail/docs/example.yml +0 -11
- data/app/pb_kits/playbook/pb_detail/docs/index.js +0 -4
- data/app/pb_kits/playbook/pb_multi_level_select/_helper_functions.tsx +0 -212
- data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.html.erb +0 -14
- data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx +0 -60
- data/app/pb_kits/playbook/utilities/object.ts +0 -3
@@ -0,0 +1,87 @@
|
|
1
|
+
export const findItemById = (
|
2
|
+
items: { [key: string]: any }[],
|
3
|
+
id: string
|
4
|
+
): any => {
|
5
|
+
for (const item of items) {
|
6
|
+
if (item.id === id) {
|
7
|
+
return item;
|
8
|
+
}
|
9
|
+
if (item.children) {
|
10
|
+
const found = findItemById(item.children, id);
|
11
|
+
if (found) {
|
12
|
+
return found;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
return null;
|
17
|
+
};
|
18
|
+
|
19
|
+
export const checkIt = (
|
20
|
+
foundItem: { [key: string]: any },
|
21
|
+
selectedItems: any[],
|
22
|
+
setSelectedItems: Function,
|
23
|
+
expand: boolean
|
24
|
+
) => {
|
25
|
+
if (!foundItem) {
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
|
29
|
+
foundItem.checked = true;
|
30
|
+
foundItem.expanded = expand;
|
31
|
+
selectedItems.push(foundItem);
|
32
|
+
|
33
|
+
if (foundItem.children) {
|
34
|
+
foundItem.children.map((x: any) => {
|
35
|
+
checkIt(x, selectedItems, setSelectedItems, expand);
|
36
|
+
});
|
37
|
+
}
|
38
|
+
|
39
|
+
setSelectedItems([...selectedItems]);
|
40
|
+
};
|
41
|
+
|
42
|
+
export const unCheckIt = (
|
43
|
+
foundItem: { [key: string]: any },
|
44
|
+
selectedItems: any,
|
45
|
+
setSelectedItems: any,
|
46
|
+
expand: boolean
|
47
|
+
) => {
|
48
|
+
if (!foundItem) {
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
|
52
|
+
foundItem.checked = false;
|
53
|
+
foundItem.expanded = false;
|
54
|
+
const newSelectedItems = selectedItems.filter(
|
55
|
+
(item: any) => item.id !== foundItem.id
|
56
|
+
);
|
57
|
+
if (foundItem.children) {
|
58
|
+
foundItem.children.map((x: any) => {
|
59
|
+
unCheckIt(x, selectedItems, setSelectedItems, expand);
|
60
|
+
});
|
61
|
+
}
|
62
|
+
setSelectedItems([...newSelectedItems]);
|
63
|
+
};
|
64
|
+
|
65
|
+
|
66
|
+
export const getParentAndAncestorsIds = (itemId:string, items:{ [key: string]: string; }[], ancestors:string[] = []):any => {
|
67
|
+
for (let i = 0; i < items.length; i++) {
|
68
|
+
const item:any = items[i];
|
69
|
+
if (item.id === itemId) {
|
70
|
+
// item found in current level of items array
|
71
|
+
return [...ancestors, item.id];
|
72
|
+
}
|
73
|
+
if (item.children && item.children.length > 0) {
|
74
|
+
// recursively search through children
|
75
|
+
const foundAncestors = getParentAndAncestorsIds(
|
76
|
+
itemId,
|
77
|
+
item.children,
|
78
|
+
[...ancestors, item.id]
|
79
|
+
);
|
80
|
+
if (foundAncestors) {
|
81
|
+
return foundAncestors;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
// item not found in this level of items array or its children
|
86
|
+
return null;
|
87
|
+
}
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module Playbook
|
4
4
|
module PbMultiLevelSelect
|
5
5
|
class MultiLevelSelect < Playbook::KitBase
|
6
|
+
prop :id
|
7
|
+
prop :name
|
6
8
|
prop :tree_data, type: Playbook::Props::Array,
|
7
9
|
default: []
|
8
10
|
prop :return_all_selected, type: Playbook::Props::Boolean,
|
@@ -15,6 +17,7 @@ module Playbook
|
|
15
17
|
def multi_level_select_options
|
16
18
|
{
|
17
19
|
id: id,
|
20
|
+
name: name,
|
18
21
|
treeData: tree_data,
|
19
22
|
returnAllSelected: return_all_selected,
|
20
23
|
}
|
@@ -1,16 +1,11 @@
|
|
1
|
-
import React, {
|
1
|
+
import React, { useEffect, useRef, useState } from 'react'
|
2
2
|
import classnames from 'classnames'
|
3
|
-
|
4
|
-
import intlTelInput from 'intl-tel-input'
|
5
|
-
import 'intl-tel-input/build/css/intlTelInput.css'
|
6
|
-
import 'intl-tel-input/build/js/utils.js'
|
7
|
-
|
8
3
|
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
9
4
|
import { globalProps } from '../utilities/globalProps'
|
10
|
-
|
5
|
+
import intlTelInput from 'intl-tel-input'
|
6
|
+
import 'intl-tel-input/build/css/intlTelInput.css'
|
11
7
|
import TextInput from '../pb_text_input/_text_input'
|
12
|
-
import
|
13
|
-
import { isEmpty } from '../utilities/object'
|
8
|
+
import 'intl-tel-input/build/js/utils.js'
|
14
9
|
|
15
10
|
declare global {
|
16
11
|
interface Window {
|
@@ -24,25 +19,20 @@ type PhoneNumberInputProps = {
|
|
24
19
|
dark?: boolean,
|
25
20
|
data?: { [key: string]: string },
|
26
21
|
disabled?: boolean,
|
27
|
-
error?: string,
|
28
22
|
id?: string,
|
29
23
|
initialCountry?: string,
|
30
24
|
isValid?: (valid: boolean) => void,
|
31
25
|
label?: string,
|
32
26
|
name?: string,
|
33
27
|
onChange?: (e: React.FormEvent<HTMLInputElement>) => void,
|
34
|
-
onValidate?: Callback<boolean, void>,
|
35
28
|
onlyCountries: string[],
|
36
29
|
preferredCountries?: string[],
|
37
|
-
required?: boolean,
|
38
30
|
value?: string,
|
39
31
|
}
|
40
32
|
|
41
33
|
enum ValidationError {
|
42
34
|
TooShort = 2,
|
43
35
|
TooLong = 3,
|
44
|
-
MissingAreaCode = 4,
|
45
|
-
SomethingWentWrong = -99
|
46
36
|
}
|
47
37
|
|
48
38
|
const formatToGlobalCountryName = (countryName: string) => {
|
@@ -50,10 +40,10 @@ const formatToGlobalCountryName = (countryName: string) => {
|
|
50
40
|
}
|
51
41
|
|
52
42
|
const formatAllCountries = () => {
|
53
|
-
|
43
|
+
let countryData = window.intlTelInputGlobals.getCountryData()
|
54
44
|
|
55
45
|
for (let i = 0; i < countryData.length; i++) {
|
56
|
-
|
46
|
+
let country = countryData[i]
|
57
47
|
country.name = formatToGlobalCountryName(country.name)
|
58
48
|
}
|
59
49
|
}
|
@@ -81,9 +71,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
81
71
|
onChange = () => {
|
82
72
|
void 0
|
83
73
|
},
|
84
|
-
onValidate = () => null,
|
85
74
|
onlyCountries = [],
|
86
|
-
required = false,
|
87
75
|
preferredCountries = [],
|
88
76
|
value = "",
|
89
77
|
} = props
|
@@ -99,83 +87,39 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
99
87
|
const inputRef = useRef<HTMLInputElement>()
|
100
88
|
const [inputValue, setInputValue] = useState(value)
|
101
89
|
const [itiInit, setItiInit] = useState<any>()
|
102
|
-
const [error, setError] = useState(
|
90
|
+
const [error, setError] = useState('')
|
103
91
|
const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
|
104
92
|
const [selectedData, setSelectedData] = useState()
|
105
93
|
|
106
|
-
useEffect(() => {
|
107
|
-
if (error?.length > 0) {
|
108
|
-
onValidate(false)
|
109
|
-
} else {
|
110
|
-
onValidate(true)
|
111
|
-
}
|
112
|
-
}, [error, onValidate])
|
113
|
-
|
114
|
-
const showFormattedError = (reason = '') => {
|
115
|
-
const countryName = itiInit.getSelectedCountryData().name
|
116
|
-
const reasonText = reason.length > 0 ? ` (${reason})` : ''
|
117
|
-
setError(`Invalid ${countryName} phone number${reasonText}`)
|
118
|
-
return true
|
119
|
-
}
|
120
|
-
|
121
94
|
const validateTooLongNumber = (itiInit: any) => {
|
122
|
-
|
123
|
-
if (itiInit.getValidationError() === ValidationError.TooLong) {
|
124
|
-
return showFormattedError('too long')
|
125
|
-
} else {
|
126
|
-
setError('')
|
127
|
-
}
|
128
|
-
}
|
95
|
+
const error = itiInit.getValidationError()
|
129
96
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
return showFormattedError('too short')
|
97
|
+
if (error === ValidationError.TooLong) {
|
98
|
+
const countryName = itiInit.getSelectedCountryData().name
|
99
|
+
setError(`Invalid ${countryName} phone number (too long)`)
|
134
100
|
} else {
|
135
|
-
|
136
|
-
return showFormattedError('too short')
|
137
|
-
} else {
|
138
|
-
setError('')
|
139
|
-
}
|
101
|
+
setError("")
|
140
102
|
}
|
141
103
|
}
|
142
104
|
|
143
|
-
const
|
144
|
-
|
145
|
-
if (inputValue && !containOnlyNumbers(inputValue)) {
|
146
|
-
return showFormattedError('enter numbers only')
|
147
|
-
}
|
148
|
-
}
|
105
|
+
const validateTooShortNumber = () => {
|
106
|
+
const error = itiInit.getValidationError()
|
149
107
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
if (inputValue.length === 1) {
|
154
|
-
return showFormattedError('too short')
|
155
|
-
} else if (inputValue.length === 0) {
|
156
|
-
setError('Missing phone number')
|
157
|
-
return true
|
158
|
-
} else {
|
159
|
-
return showFormattedError()
|
160
|
-
}
|
108
|
+
if (error === ValidationError.TooShort) {
|
109
|
+
const countryName = itiInit.getSelectedCountryData().name
|
110
|
+
setError(`Invalid ${countryName} phone number (too short)`)
|
161
111
|
}
|
162
112
|
}
|
163
113
|
|
164
|
-
const
|
165
|
-
if (
|
166
|
-
|
167
|
-
showFormattedError('missing area code')
|
168
|
-
return true
|
114
|
+
const validateOnlyNumbers = () => {
|
115
|
+
if (inputValue && !containOnlyNumbers(inputValue)) {
|
116
|
+
setError("Invalid phone number. Enter numbers only.")
|
169
117
|
}
|
170
118
|
}
|
171
119
|
|
172
120
|
const validateErrors = () => {
|
173
|
-
|
174
|
-
|
175
|
-
if (validateTooLongNumber(itiInit)) return
|
176
|
-
if (validateTooShortNumber(itiInit)) return
|
177
|
-
if (validateUnhandledError(itiInit)) return
|
178
|
-
if (validateMissingAreaCode(itiInit)) return
|
121
|
+
validateTooShortNumber()
|
122
|
+
validateOnlyNumbers()
|
179
123
|
}
|
180
124
|
|
181
125
|
const getCurrentSelectedData = (itiInit: any, inputValue: string) => {
|
@@ -184,6 +128,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
184
128
|
|
185
129
|
const handleOnChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
|
186
130
|
setInputValue(evt.target.value)
|
131
|
+
validateTooLongNumber(itiInit)
|
187
132
|
const phoneNumberData = getCurrentSelectedData(itiInit, evt.target.value)
|
188
133
|
setSelectedData(phoneNumberData)
|
189
134
|
onChange(phoneNumberData)
|
@@ -192,24 +137,25 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
192
137
|
|
193
138
|
// Separating Concerns as React Docs Recommend
|
194
139
|
// This also Fixes things for our react_component rendering on the Rails Side
|
195
|
-
useEffect(
|
140
|
+
useEffect(() => {
|
141
|
+
formatAllCountries()
|
142
|
+
}, [])
|
196
143
|
|
197
144
|
useEffect(() => {
|
198
|
-
const telInputInit = intlTelInput(inputRef.current, {
|
145
|
+
const telInputInit = new intlTelInput(inputRef.current, {
|
199
146
|
separateDialCode: true,
|
200
147
|
preferredCountries,
|
201
148
|
allowDropdown: !disabled,
|
202
|
-
autoInsertDialCode: false,
|
203
149
|
initialCountry,
|
204
150
|
onlyCountries,
|
205
|
-
|
206
|
-
|
151
|
+
}
|
152
|
+
)
|
207
153
|
|
208
154
|
inputRef.current.addEventListener("countrychange", (evt: Event) => {
|
155
|
+
validateTooLongNumber(telInputInit)
|
209
156
|
const phoneNumberData = getCurrentSelectedData(telInputInit, (evt.target as HTMLInputElement).value)
|
210
157
|
setSelectedData(phoneNumberData)
|
211
158
|
onChange(phoneNumberData)
|
212
|
-
validateErrors()
|
213
159
|
})
|
214
160
|
|
215
161
|
inputRef.current.addEventListener("open:countrydropdown", () => setDropDownIsOpen(true))
|
@@ -218,35 +164,24 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
218
164
|
setItiInit(telInputInit)
|
219
165
|
}, [])
|
220
166
|
|
221
|
-
let textInputProps: {[key: string]: any} = {
|
222
|
-
className: dropDownIsOpen ? 'dropdown_open' : '',
|
223
|
-
dark,
|
224
|
-
"data-phone-number": JSON.stringify(selectedData),
|
225
|
-
disabled,
|
226
|
-
error,
|
227
|
-
type: 'tel',
|
228
|
-
id,
|
229
|
-
label,
|
230
|
-
name,
|
231
|
-
onBlur: validateErrors,
|
232
|
-
onChange: handleOnChange,
|
233
|
-
value: inputValue
|
234
|
-
}
|
235
|
-
|
236
|
-
let wrapperProps: Record<string, unknown> = { className: classes }
|
237
|
-
|
238
|
-
if (!isEmpty(aria)) textInputProps = {...textInputProps, ...ariaProps}
|
239
|
-
if (!isEmpty(data)) wrapperProps = {...wrapperProps, ...dataProps}
|
240
|
-
if (required) textInputProps.required = true
|
241
|
-
|
242
167
|
return (
|
243
|
-
<div {...
|
168
|
+
<div {...ariaProps} {...dataProps} className={classes}>
|
244
169
|
<TextInput
|
245
|
-
|
246
|
-
|
170
|
+
className={dropDownIsOpen ? 'dropdown_open' : ''}
|
171
|
+
dark={dark}
|
172
|
+
data-phone-number={JSON.stringify(selectedData)}
|
173
|
+
disabled={disabled}
|
174
|
+
error={error}
|
175
|
+
id={id}
|
176
|
+
label={label}
|
177
|
+
name={name}
|
178
|
+
onBlur={() => validateErrors()}
|
179
|
+
onChange={handleOnChange}
|
180
|
+
ref={inputRef}
|
181
|
+
value={inputValue}
|
247
182
|
/>
|
248
183
|
</div>
|
249
184
|
)
|
250
185
|
}
|
251
186
|
|
252
|
-
export default
|
187
|
+
export default PhoneNumberInput
|
@@ -5,11 +5,9 @@ examples:
|
|
5
5
|
- phone_number_input_preferred_countries: Preferred Countries
|
6
6
|
- phone_number_input_initial_country: Initial Country
|
7
7
|
- phone_number_input_only_countries: Limited Countries
|
8
|
-
- phone_number_input_validation: Form Validation
|
9
8
|
|
10
9
|
rails:
|
11
10
|
- phone_number_input_default: Default
|
12
11
|
- phone_number_input_preferred_countries: Preferred Countries
|
13
12
|
- phone_number_input_initial_country: Initial Country
|
14
|
-
- phone_number_input_only_countries: Limited Countries
|
15
|
-
- phone_number_input_validation: Form Validation
|
13
|
+
- phone_number_input_only_countries: Limited Countries
|
@@ -2,4 +2,3 @@ export { default as PhoneNumberInputDefault } from './_phone_number_input_defaul
|
|
2
2
|
export { default as PhoneNumberInputPreferredCountries } from './_phone_number_input_preferred_countries'
|
3
3
|
export { default as PhoneNumberInputInitialCountry } from './_phone_number_input_initial_country'
|
4
4
|
export { default as PhoneNumberInputOnlyCountries } from './_phone_number_input_only_countries'
|
5
|
-
export { default as PhoneNumberInputValidation } from './_phone_number_input_validation'
|
@@ -5,8 +5,6 @@ module Playbook
|
|
5
5
|
class PhoneNumberInput < Playbook::KitBase
|
6
6
|
prop :disabled, type: Playbook::Props::Boolean,
|
7
7
|
default: false
|
8
|
-
prop :required, type: Playbook::Props::Boolean,
|
9
|
-
default: false
|
10
8
|
prop :initial_country, type: Playbook::Props::String,
|
11
9
|
default: ""
|
12
10
|
prop :label, type: Playbook::Props::String,
|
@@ -17,8 +15,6 @@ module Playbook
|
|
17
15
|
default: []
|
18
16
|
prop :preferred_countries, type: Playbook::Props::Array,
|
19
17
|
default: []
|
20
|
-
prop :error, type: Playbook::Props::String,
|
21
|
-
default: ""
|
22
18
|
prop :value, type: Playbook::Props::String,
|
23
19
|
default: ""
|
24
20
|
|
@@ -31,13 +27,11 @@ module Playbook
|
|
31
27
|
id: id,
|
32
28
|
dark: dark,
|
33
29
|
disabled: disabled,
|
34
|
-
error: error,
|
35
30
|
initialCountry: initial_country,
|
36
31
|
label: label,
|
37
32
|
name: name,
|
38
33
|
onlyCountries: only_countries,
|
39
34
|
preferredCountries: preferred_countries,
|
40
|
-
required: required,
|
41
35
|
value: value,
|
42
36
|
}
|
43
37
|
end
|
@@ -1,122 +1,74 @@
|
|
1
|
-
import React from
|
2
|
-
import { render, screen } from
|
3
|
-
import PhoneNumberInput from
|
1
|
+
import React from 'react'
|
2
|
+
import { render, screen } from '../utilities/test-utils'
|
3
|
+
import PhoneNumberInput from './_phone_number_input'
|
4
4
|
|
5
|
-
const testId = "phoneNumberInput"
|
5
|
+
const testId = "phoneNumberInput"
|
6
6
|
|
7
|
-
test(
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
render(<PhoneNumberInput {...props} />);
|
14
|
-
const kit = screen.getByRole("textbox");
|
15
|
-
expect(kit).toBeDisabled();
|
16
|
-
});
|
17
|
-
|
18
|
-
test("should be enabled by default", () => {
|
19
|
-
const props = {
|
20
|
-
id: testId,
|
21
|
-
};
|
22
|
-
|
23
|
-
render(<PhoneNumberInput {...props} />);
|
24
|
-
const kit = screen.getByRole("textbox");
|
25
|
-
expect(kit).not.toBeDisabled();
|
26
|
-
});
|
27
|
-
|
28
|
-
test("should have label", () => {
|
29
|
-
const label = "Phone Number";
|
30
|
-
const props = {
|
31
|
-
id: testId,
|
32
|
-
label,
|
33
|
-
};
|
34
|
-
|
35
|
-
render(<PhoneNumberInput {...props} />);
|
36
|
-
const kit = screen.getByText(label);
|
37
|
-
expect(kit).toBeInTheDocument();
|
38
|
-
});
|
39
|
-
|
40
|
-
test("should pass data prop", () => {
|
41
|
-
const props = {
|
42
|
-
data: { testid: testId },
|
43
|
-
id: testId,
|
44
|
-
};
|
45
|
-
|
46
|
-
render(<PhoneNumberInput {...props} />);
|
47
|
-
const kit = screen.getByTestId(testId);
|
48
|
-
expect(kit).toBeInTheDocument();
|
49
|
-
});
|
50
|
-
|
51
|
-
test("should pass className prop", () => {
|
52
|
-
const className = "custom-class-name";
|
53
|
-
const props = {
|
54
|
-
className,
|
55
|
-
data: { testid: testId },
|
56
|
-
id: testId,
|
57
|
-
};
|
58
|
-
|
59
|
-
render(<PhoneNumberInput {...props} />);
|
60
|
-
const kit = screen.getByTestId(testId);
|
61
|
-
expect(kit).toHaveClass(className);
|
62
|
-
});
|
63
|
-
|
64
|
-
test("should pass value prop", () => {
|
65
|
-
const value = "1234567890";
|
66
|
-
const props = {
|
67
|
-
id: testId,
|
68
|
-
value,
|
69
|
-
};
|
7
|
+
test('should be disabled', () => {
|
8
|
+
const props = {
|
9
|
+
disabled: true,
|
10
|
+
id: testId,
|
11
|
+
}
|
70
12
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
})
|
13
|
+
render(<PhoneNumberInput {...props} />)
|
14
|
+
const kit = screen.getByRole("textbox")
|
15
|
+
expect(kit).toBeDisabled()
|
16
|
+
})
|
75
17
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
};
|
18
|
+
test('should be enabled by default', () => {
|
19
|
+
const props = {
|
20
|
+
id: testId,
|
21
|
+
}
|
81
22
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
/>
|
87
|
-
);
|
88
|
-
const kit = screen.getByRole("textbox");
|
89
|
-
expect(kit).toHaveAttribute("required");
|
90
|
-
});
|
23
|
+
render(<PhoneNumberInput {...props} />)
|
24
|
+
const kit = screen.getByRole("textbox")
|
25
|
+
expect(kit).not.toBeDisabled()
|
26
|
+
})
|
91
27
|
|
92
|
-
test(
|
28
|
+
test('should have label', () => {
|
29
|
+
const label = 'Phone Number'
|
93
30
|
const props = {
|
94
|
-
|
95
|
-
|
96
|
-
}
|
31
|
+
id: testId,
|
32
|
+
label,
|
33
|
+
}
|
97
34
|
|
98
|
-
render(
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
);
|
103
|
-
const kit = screen.getByRole("textbox");
|
104
|
-
expect(kit).toHaveAttribute("error");
|
105
|
-
});
|
106
|
-
|
107
|
-
test("should trigger callback", () => {
|
108
|
-
const handleOnValidate = jest.fn((valid) => valid)
|
35
|
+
render(<PhoneNumberInput {...props} />)
|
36
|
+
const kit = screen.getByText(label)
|
37
|
+
expect(kit).toBeInTheDocument()
|
38
|
+
})
|
109
39
|
|
40
|
+
test('should pass data prop', () => {
|
110
41
|
const props = {
|
111
|
-
|
112
|
-
|
113
|
-
}
|
42
|
+
data: { testid: testId },
|
43
|
+
id: testId,
|
44
|
+
}
|
114
45
|
|
115
|
-
render(
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
);
|
46
|
+
render(<PhoneNumberInput {...props} />)
|
47
|
+
const kit = screen.getByTestId(testId)
|
48
|
+
expect(kit).toBeInTheDocument()
|
49
|
+
})
|
120
50
|
|
121
|
-
|
122
|
-
|
51
|
+
test('should pass className prop', () => {
|
52
|
+
const className = 'custom-class-name'
|
53
|
+
const props = {
|
54
|
+
className,
|
55
|
+
data: { testid: testId },
|
56
|
+
id: testId,
|
57
|
+
}
|
58
|
+
|
59
|
+
render(<PhoneNumberInput {...props} />)
|
60
|
+
const kit = screen.getByTestId(testId)
|
61
|
+
expect(kit).toHaveClass(className)
|
62
|
+
})
|
63
|
+
|
64
|
+
test('should pass value prop', () => {
|
65
|
+
const value = '1234567890'
|
66
|
+
const props = {
|
67
|
+
id: testId,
|
68
|
+
value,
|
69
|
+
}
|
70
|
+
|
71
|
+
render(<PhoneNumberInput {...props} />)
|
72
|
+
const kit = screen.getByRole("textbox")
|
73
|
+
expect(kit).toHaveDisplayValue(value)
|
74
|
+
})
|
@@ -30,7 +30,6 @@ import * as DateStacked from 'pb_date_stacked/docs'
|
|
30
30
|
import * as DateTime from 'pb_date_time/docs'
|
31
31
|
import * as DateTimeStacked from 'pb_date_time_stacked/docs'
|
32
32
|
import * as DateYearStacked from 'pb_date_year_stacked/docs'
|
33
|
-
import * as Detail from 'pb_detail/docs'
|
34
33
|
import * as Dialog from 'pb_dialog/docs'
|
35
34
|
import * as DistributionBarDocs from 'pb_distribution_bar/docs'
|
36
35
|
import * as FileUpload from 'pb_file_upload/docs'
|
@@ -131,7 +130,6 @@ WebpackerReact.setup({
|
|
131
130
|
...DateTime,
|
132
131
|
...DateTimeStacked,
|
133
132
|
...DateYearStacked,
|
134
|
-
...Detail,
|
135
133
|
...Dialog,
|
136
134
|
...DistributionBarDocs,
|
137
135
|
...FileUpload,
|