playbook_ui 12.24.0.pre.alpha.play824733 → 12.24.0.pre.alpha.railsmultilevelimprovements741
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 +26 -52
- 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 -5
- data/app/pb_kits/playbook/pb_phone_number_input/phone_number_input.test.js +62 -110
- data/dist/playbook-rails.js +51 -0
- data/lib/playbook/forms/builder/multi_level_select_field.rb +12 -0
- data/lib/playbook/forms/builder.rb +2 -1
- data/lib/playbook/version.rb +1 -1
- data/lib/playbook.rb +1 -2
- metadata +8 -40
- 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/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 -61
- data/app/pb_kits/playbook/utilities/object.ts +0 -3
- data/lib/playbook/forms/builder/intl_telephone_field.rb +0 -12
- 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: da9354cafa403b90e25fad73dc219e98daf8daa09d49ea12b51bfd537a2221f8
|
4
|
+
data.tar.gz: 347e207c228a8bb42406003a64f811c115c14ab0abd8e60de3399014fc60752c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 066a9da18630f39904e91a4807ac6941ebc6ea111c174208c34c21cb6ac9de1eaccb4c6d1b79f77ca7181c674fa6d7fd0740446166b0a06137f9070f1804fdd5
|
7
|
+
data.tar.gz: b6ee20cdcf777fe7405ff203719b0ce03592f71631406df7c682dba5e6d14e95543a30bbac23b489efb1016f06fcb7bb1bcee5e545df4bc9651c19ab0148a0be
|
@@ -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
|
@@ -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,17 +19,14 @@ 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
|
|
@@ -48,10 +40,10 @@ const formatToGlobalCountryName = (countryName: string) => {
|
|
48
40
|
}
|
49
41
|
|
50
42
|
const formatAllCountries = () => {
|
51
|
-
|
43
|
+
let countryData = window.intlTelInputGlobals.getCountryData()
|
52
44
|
|
53
45
|
for (let i = 0; i < countryData.length; i++) {
|
54
|
-
|
46
|
+
let country = countryData[i]
|
55
47
|
country.name = formatToGlobalCountryName(country.name)
|
56
48
|
}
|
57
49
|
}
|
@@ -79,9 +71,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
79
71
|
onChange = () => {
|
80
72
|
void 0
|
81
73
|
},
|
82
|
-
onValidate = () => null,
|
83
74
|
onlyCountries = [],
|
84
|
-
required = false,
|
85
75
|
preferredCountries = [],
|
86
76
|
value = "",
|
87
77
|
} = props
|
@@ -97,18 +87,10 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
97
87
|
const inputRef = useRef<HTMLInputElement>()
|
98
88
|
const [inputValue, setInputValue] = useState(value)
|
99
89
|
const [itiInit, setItiInit] = useState<any>()
|
100
|
-
const [error, setError] = useState(
|
90
|
+
const [error, setError] = useState('')
|
101
91
|
const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
|
102
92
|
const [selectedData, setSelectedData] = useState()
|
103
93
|
|
104
|
-
useEffect(() => {
|
105
|
-
if (error?.length > 0) {
|
106
|
-
onValidate(false)
|
107
|
-
} else {
|
108
|
-
onValidate(true)
|
109
|
-
}
|
110
|
-
}, [error, onValidate])
|
111
|
-
|
112
94
|
const validateTooLongNumber = (itiInit: any) => {
|
113
95
|
const error = itiInit.getValidationError()
|
114
96
|
|
@@ -155,7 +137,9 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
155
137
|
|
156
138
|
// Separating Concerns as React Docs Recommend
|
157
139
|
// This also Fixes things for our react_component rendering on the Rails Side
|
158
|
-
useEffect(
|
140
|
+
useEffect(() => {
|
141
|
+
formatAllCountries()
|
142
|
+
}, [])
|
159
143
|
|
160
144
|
useEffect(() => {
|
161
145
|
const telInputInit = new intlTelInput(inputRef.current, {
|
@@ -164,14 +148,14 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
164
148
|
allowDropdown: !disabled,
|
165
149
|
initialCountry,
|
166
150
|
onlyCountries,
|
167
|
-
}
|
151
|
+
}
|
152
|
+
)
|
168
153
|
|
169
154
|
inputRef.current.addEventListener("countrychange", (evt: Event) => {
|
170
155
|
validateTooLongNumber(telInputInit)
|
171
156
|
const phoneNumberData = getCurrentSelectedData(telInputInit, (evt.target as HTMLInputElement).value)
|
172
157
|
setSelectedData(phoneNumberData)
|
173
158
|
onChange(phoneNumberData)
|
174
|
-
isValid(telInputInit.isValidNumber())
|
175
159
|
})
|
176
160
|
|
177
161
|
inputRef.current.addEventListener("open:countrydropdown", () => setDropDownIsOpen(true))
|
@@ -180,34 +164,24 @@ const PhoneNumberInput = (props: PhoneNumberInputProps) => {
|
|
180
164
|
setItiInit(telInputInit)
|
181
165
|
}, [])
|
182
166
|
|
183
|
-
let textInputProps: {[key: string]: any} = {
|
184
|
-
className: dropDownIsOpen ? 'dropdown_open' : '',
|
185
|
-
dark,
|
186
|
-
"data-phone-number": JSON.stringify(selectedData),
|
187
|
-
disabled,
|
188
|
-
error,
|
189
|
-
id,
|
190
|
-
label,
|
191
|
-
name,
|
192
|
-
onBlur: validateErrors,
|
193
|
-
onChange: handleOnChange,
|
194
|
-
value: inputValue
|
195
|
-
}
|
196
|
-
|
197
|
-
let wrapperProps: Record<string, unknown> = { className: classes }
|
198
|
-
|
199
|
-
if (!isEmpty(aria)) textInputProps = {...textInputProps, ...ariaProps}
|
200
|
-
if (!isEmpty(data)) wrapperProps = {...wrapperProps, ...dataProps}
|
201
|
-
if (required) textInputProps.required = true
|
202
|
-
|
203
167
|
return (
|
204
|
-
<div {...
|
168
|
+
<div {...ariaProps} {...dataProps} className={classes}>
|
205
169
|
<TextInput
|
206
|
-
|
207
|
-
|
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}
|
208
182
|
/>
|
209
183
|
</div>
|
210
184
|
)
|
211
185
|
}
|
212
186
|
|
213
|
-
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,7 +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
18
|
prop :value, type: Playbook::Props::String,
|
22
19
|
default: ""
|
23
20
|
|
@@ -30,13 +27,11 @@ module Playbook
|
|
30
27
|
id: id,
|
31
28
|
dark: dark,
|
32
29
|
disabled: disabled,
|
33
|
-
error: error,
|
34
30
|
initialCountry: initial_country,
|
35
31
|
label: label,
|
36
32
|
name: name,
|
37
33
|
onlyCountries: only_countries,
|
38
34
|
preferredCountries: preferred_countries,
|
39
|
-
required: required,
|
40
35
|
value: value,
|
41
36
|
}
|
42
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
|
+
})
|