playbook_ui 15.1.0 → 15.2.0.pre.alpha.PLAY2428advancedtablerailscellpadding11387
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_advanced_table/Hooks/useTableState.ts +7 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_background_control_rails.html.erb +113 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_background_control_rails.md +1 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_rails.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_per_row_rails.html.erb +51 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_per_row_rails.md +1 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_rails.html.erb +40 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_rails.md +1 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_row_styling_rails.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_row_styling_react.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +3 -0
- data/app/pb_kits/playbook/pb_advanced_table/table_row.html.erb +2 -1
- data/app/pb_kits/playbook/pb_advanced_table/table_row.rb +44 -0
- data/app/pb_kits/playbook/pb_button/_button.scss +6 -0
- data/app/pb_kits/playbook/pb_button/docs/_button_loading.html.erb +7 -3
- data/app/pb_kits/playbook/pb_button/docs/_button_loading.jsx +29 -0
- data/app/pb_kits/playbook/pb_button/docs/_button_managed_disabled.html.erb +31 -0
- data/app/pb_kits/playbook/pb_button/docs/_button_managed_disabled.md +7 -0
- data/app/pb_kits/playbook/pb_button/docs/_button_managed_disabled_helper.html.erb +21 -0
- data/app/pb_kits/playbook/pb_button/docs/_button_managed_disabled_helper.md +7 -0
- data/app/pb_kits/playbook/pb_button/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_button/index.js +99 -0
- data/app/pb_kits/playbook/pb_date_picker/_date_picker.scss +4 -0
- data/app/pb_kits/playbook/pb_dialog/docs/_dialog_stacked_alert.html.erb +16 -16
- data/app/pb_kits/playbook/pb_dialog/docs/_dialog_stacked_alert.jsx +2 -1
- data/app/pb_kits/playbook/pb_dialog/docs/_dialog_status.html.erb +31 -31
- data/app/pb_kits/playbook/pb_dialog/docs/_dialog_status.jsx +4 -3
- data/app/pb_kits/playbook/pb_draggable/_draggable.scss +8 -0
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +105 -29
- data/app/pb_kits/playbook/pb_form/docs/_form_form_with_validate.html.erb +12 -1
- data/app/pb_kits/playbook/pb_icon_circle/_icon_circle.tsx +2 -2
- data/app/pb_kits/playbook/pb_icon_stat_value/_icon_stat_value.scss +15 -21
- data/app/pb_kits/playbook/pb_icon_stat_value/_icon_stat_value.tsx +6 -5
- data/app/pb_kits/playbook/pb_icon_stat_value/icon_stat_value.html.erb +2 -0
- data/app/pb_kits/playbook/pb_icon_stat_value/icon_stat_value.rb +11 -3
- data/app/pb_kits/playbook/pb_icon_stat_value/icon_stat_value.test.js +9 -8
- data/app/pb_kits/playbook/pb_multiple_users_stacked/_multiple_users_stacked.scss +36 -9
- data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +105 -22
- data/app/pb_kits/playbook/pb_text_input/_text_input.scss +3 -0
- data/app/pb_kits/playbook/pb_text_input/_text_input.tsx +14 -6
- data/app/pb_kits/playbook/pb_text_input/docs/_text_input_default.html.erb +8 -4
- data/app/pb_kits/playbook/pb_text_input/docs/_text_input_default.jsx +5 -0
- data/app/pb_kits/playbook/pb_text_input/docs/_text_input_default.md +1 -0
- data/app/pb_kits/playbook/pb_text_input/text_input.html.erb +3 -1
- data/app/pb_kits/playbook/pb_text_input/text_input.rb +6 -0
- data/app/pb_kits/playbook/pb_timeline/_timeline.scss +250 -233
- data/app/pb_kits/playbook/pb_timeline/_timeline.tsx +1 -1
- data/app/pb_kits/playbook/pb_timeline/timeline.test.js +2 -2
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.scss +10 -10
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +39 -1
- data/app/pb_kits/playbook/pb_typeahead/typeahead.rb +2 -0
- data/app/pb_kits/playbook/utilities/_hover.scss +2 -2
- data/app/pb_kits/playbook/utilities/globalProps.ts +2 -2
- data/dist/chunks/{_line_graph-CW8Ygzyq.js → _line_graph-DY4PK6AH.js} +1 -1
- data/dist/chunks/_typeahead-fQDb_yVO.js +6 -0
- data/dist/chunks/{_weekday_stacked-3-FtXg76.js → _weekday_stacked-D_bGbWtk.js} +3 -3
- data/dist/chunks/{lib-izYrkvOQ.js → lib-QZuu1ltS.js} +2 -2
- data/dist/chunks/{pb_form_validation-Cah5Z5J3.js → pb_form_validation-CleM960_.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/menu.yml +1 -1
- data/dist/playbook-doc.js +2 -2
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/dist/playbook.css +1 -1
- data/lib/playbook/hover.rb +5 -1
- data/lib/playbook/pb_forms_helper.rb +7 -6
- data/lib/playbook/version.rb +2 -2
- metadata +19 -7
- data/dist/chunks/_typeahead-DUIMqJiu.js +0 -6
|
@@ -9,8 +9,8 @@ module Playbook
|
|
|
9
9
|
values: %w[sm md lg],
|
|
10
10
|
default: "sm"
|
|
11
11
|
prop :variant, type: Playbook::Props::Enum,
|
|
12
|
-
values: %w[default royal blue purple teal red yellow green orange
|
|
13
|
-
default: "
|
|
12
|
+
values: %w[default royal blue purple teal red yellow green orange],
|
|
13
|
+
default: "default"
|
|
14
14
|
|
|
15
15
|
prop :orientation, type: Playbook::Props::Enum,
|
|
16
16
|
values: %w[vertical horizontal],
|
|
@@ -25,7 +25,7 @@ module Playbook
|
|
|
25
25
|
prop :value
|
|
26
26
|
|
|
27
27
|
def classname
|
|
28
|
-
generate_classname("pb_icon_stat_value_kit", orientation
|
|
28
|
+
generate_classname("pb_icon_stat_value_kit", orientation)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def value_string
|
|
@@ -41,6 +41,14 @@ module Playbook
|
|
|
41
41
|
3
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
|
+
|
|
45
|
+
def icon_margin_right
|
|
46
|
+
orientation === "horizontal" && "sm"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def icon_margin_bottom
|
|
50
|
+
orientation === "vertical" && "xs"
|
|
51
|
+
end
|
|
44
52
|
end
|
|
45
53
|
end
|
|
46
54
|
end
|
|
@@ -18,7 +18,7 @@ describe("IconStatValue Kit", () => {
|
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
const kit = screen.getByTestId(testId)
|
|
21
|
-
expect(kit).toHaveClass("
|
|
21
|
+
expect(kit).toHaveClass("pb_icon_stat_value_kit_horizontal")
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
test("renders icon", () => {
|
|
@@ -99,9 +99,10 @@ describe("IconStatValue Kit", () => {
|
|
|
99
99
|
value={64.18}
|
|
100
100
|
/>
|
|
101
101
|
)
|
|
102
|
-
|
|
102
|
+
const size = sizeProp === "sm" ? "3" : sizeProp === "md" ? "2" : "1"
|
|
103
103
|
const kit = screen.getByTestId(testId)
|
|
104
|
-
|
|
104
|
+
const title = kit.querySelector(".pb_title_kit")
|
|
105
|
+
expect(title).toHaveClass(`pb_title_${size}`)
|
|
105
106
|
|
|
106
107
|
cleanup()
|
|
107
108
|
})
|
|
@@ -115,8 +116,7 @@ describe("IconStatValue Kit", () => {
|
|
|
115
116
|
"teal",
|
|
116
117
|
"red",
|
|
117
118
|
"yellow",
|
|
118
|
-
"green"
|
|
119
|
-
"lighter"].forEach(
|
|
119
|
+
"green"].forEach(
|
|
120
120
|
(colorProp) => {
|
|
121
121
|
render(
|
|
122
122
|
<IconStatValue
|
|
@@ -128,9 +128,10 @@ describe("IconStatValue Kit", () => {
|
|
|
128
128
|
variant={colorProp}
|
|
129
129
|
/>
|
|
130
130
|
)
|
|
131
|
-
|
|
131
|
+
|
|
132
132
|
const kit = screen.getByTestId(testId)
|
|
133
|
-
|
|
133
|
+
const iconCircle = kit.querySelector(`.pb_icon_circle_kit_size_sm_${colorProp}`)
|
|
134
|
+
expect(iconCircle).toBeInTheDocument()
|
|
134
135
|
|
|
135
136
|
cleanup()
|
|
136
137
|
})
|
|
@@ -149,7 +150,7 @@ describe("IconStatValue Kit", () => {
|
|
|
149
150
|
)
|
|
150
151
|
|
|
151
152
|
const kit = screen.getByTestId(testId)
|
|
152
|
-
expect(kit).toHaveClass("
|
|
153
|
+
expect(kit).toHaveClass("pb_icon_stat_value_kit_vertical")
|
|
153
154
|
})
|
|
154
155
|
|
|
155
156
|
})
|
|
@@ -89,7 +89,18 @@ $positions: (
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
.pb_multiple_users_stacked_kit,
|
|
93
|
+
.pb_multiple_users_stacked_kit_single,
|
|
94
|
+
.pb_multiple_users_stacked_kit_bubble,
|
|
95
|
+
.pb_multiple_users_stacked_kit_single_bubble,
|
|
96
|
+
.pb_multiple_users_stacked_kit_bubble_size_sm,
|
|
97
|
+
.pb_multiple_users_stacked_kit_bubble_size_md,
|
|
98
|
+
.pb_multiple_users_stacked_kit_bubble_size_lg,
|
|
99
|
+
.pb_multiple_users_stacked_kit_bubble_size_xl,
|
|
100
|
+
.pb_multiple_users_stacked_kit_single_bubble_size_sm,
|
|
101
|
+
.pb_multiple_users_stacked_kit_single_bubble_size_md,
|
|
102
|
+
.pb_multiple_users_stacked_kit_single_bubble_size_lg,
|
|
103
|
+
.pb_multiple_users_stacked_kit_single_bubble_size_xl {
|
|
93
104
|
$container_size: map-get($avatar-sizes, "xs");
|
|
94
105
|
$bubble_container_size: map-get($avatar-sizes, "sm");
|
|
95
106
|
$overlap: -15px;
|
|
@@ -103,7 +114,8 @@ $positions: (
|
|
|
103
114
|
position: relative;
|
|
104
115
|
flex-shrink: 0;
|
|
105
116
|
flex-grow: 0;
|
|
106
|
-
|
|
117
|
+
.pb_avatar_kit_size_xs.pb_multiple_users_stacked_item,
|
|
118
|
+
.pb_avatar_kit_size_md.pb_multiple_users_stacked_item {
|
|
107
119
|
@include avatar-size($stacked_size);
|
|
108
120
|
&.dark {
|
|
109
121
|
.avatar_wrapper {
|
|
@@ -117,10 +129,17 @@ $positions: (
|
|
|
117
129
|
}
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
|
-
|
|
132
|
+
&.pb_multiple_users_stacked_kit_single .pb_multiple_users_stacked_item,
|
|
133
|
+
&.pb_multiple_users_stacked_kit_single_bubble .pb_multiple_users_stacked_item,
|
|
134
|
+
&.pb_multiple_users_stacked_kit_single_bubble_size_sm .pb_multiple_users_stacked_item,
|
|
135
|
+
&.pb_multiple_users_stacked_kit_single_bubble_size_md .pb_multiple_users_stacked_item,
|
|
136
|
+
&.pb_multiple_users_stacked_kit_single_bubble_size_lg .pb_multiple_users_stacked_item,
|
|
137
|
+
&.pb_multiple_users_stacked_kit_single_bubble_size_xl .pb_multiple_users_stacked_item {
|
|
121
138
|
@include avatar-size(28px);
|
|
122
139
|
}
|
|
123
|
-
|
|
140
|
+
.pb_avatar_kit_size_xs.second_item,
|
|
141
|
+
.pb_avatar_kit_size_md.second_item,
|
|
142
|
+
.pb_badge_kit_primary_rounded.second_item {
|
|
124
143
|
@include position((bottom: 0, right: 0));
|
|
125
144
|
z-index: 2;
|
|
126
145
|
background: tint($primary, 90%);
|
|
@@ -143,7 +162,8 @@ $positions: (
|
|
|
143
162
|
|
|
144
163
|
// Iterate over each size to adjust the bubble container only when class contains "_bubble_"
|
|
145
164
|
@each $size_name, $size_value in $avatar-sizes {
|
|
146
|
-
|
|
165
|
+
&.pb_multiple_users_stacked_kit_bubble_size_#{$size_name},
|
|
166
|
+
&.pb_multiple_users_stacked_kit_single_bubble_size_#{$size_name} {
|
|
147
167
|
// Set bubble container size based on the class
|
|
148
168
|
$bubble_container_size: $size_value;
|
|
149
169
|
$container_size: $size_value;
|
|
@@ -161,7 +181,8 @@ $positions: (
|
|
|
161
181
|
background-color: $card_dark;
|
|
162
182
|
}
|
|
163
183
|
|
|
164
|
-
|
|
184
|
+
.pb_avatar_kit_size_xs.pb_multiple_users_stacked_item,
|
|
185
|
+
.pb_avatar_kit_size_md.pb_multiple_users_stacked_item {
|
|
165
186
|
@include avatar-size($bubble_container_size * 0.45); // Adjust the size of stacked avatars
|
|
166
187
|
|
|
167
188
|
&.dark {
|
|
@@ -175,7 +196,8 @@ $positions: (
|
|
|
175
196
|
}
|
|
176
197
|
}
|
|
177
198
|
|
|
178
|
-
|
|
199
|
+
.pb_avatar_kit_size_xs,
|
|
200
|
+
.pb_avatar_kit_size_md {
|
|
179
201
|
// First Item
|
|
180
202
|
&.first_item {
|
|
181
203
|
@include position(map-get(map-get($positions, 'first-item-double'), $size_name));
|
|
@@ -235,8 +257,13 @@ $positions: (
|
|
|
235
257
|
}
|
|
236
258
|
}
|
|
237
259
|
|
|
238
|
-
|
|
239
|
-
|
|
260
|
+
&.pb_multiple_users_stacked_kit_single_bubble,
|
|
261
|
+
&.pb_multiple_users_stacked_kit_single_bubble_size_sm,
|
|
262
|
+
&.pb_multiple_users_stacked_kit_single_bubble_size_md,
|
|
263
|
+
&.pb_multiple_users_stacked_kit_single_bubble_size_lg,
|
|
264
|
+
&.pb_multiple_users_stacked_kit_single_bubble_size_xl {
|
|
265
|
+
.pb_avatar_kit_size_xs.first_item,
|
|
266
|
+
.pb_avatar_kit_size_md.first_item {
|
|
240
267
|
@include position((top: 0, left: 0));
|
|
241
268
|
@include avatar-size($bubble_container_size);
|
|
242
269
|
}
|
|
@@ -111,7 +111,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
111
111
|
const inputRef = useRef<HTMLInputElement | null>(null)
|
|
112
112
|
const itiRef = useRef<any>(null);
|
|
113
113
|
const [inputValue, setInputValue] = useState(value)
|
|
114
|
-
const [error, setError] = useState(props.error)
|
|
114
|
+
const [error, setError] = useState(props.error || "")
|
|
115
115
|
const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
|
|
116
116
|
const [selectedData, setSelectedData] = useState()
|
|
117
117
|
const [hasTyped, setHasTyped] = useState(false)
|
|
@@ -124,24 +124,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
124
124
|
}
|
|
125
125
|
}, [error, onValidate])
|
|
126
126
|
|
|
127
|
-
/*
|
|
128
|
-
useImperativeHandle exposes the kit's input element to a parent component via a ref.
|
|
129
|
-
See the Playbook docs for use cases.
|
|
130
|
-
Read: https://react.dev/reference/react/useImperativeHandle
|
|
131
|
-
*/
|
|
132
|
-
useImperativeHandle(ref, () => {
|
|
133
|
-
return {
|
|
134
|
-
clearField() {
|
|
135
|
-
setInputValue("")
|
|
136
|
-
setError("")
|
|
137
|
-
setHasTyped(false)
|
|
138
|
-
},
|
|
139
|
-
inputNode() {
|
|
140
|
-
return inputRef.current
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
|
|
145
127
|
const unformatNumber = (formattedNumber: any) => {
|
|
146
128
|
return formattedNumber.replace(/\D/g, "")
|
|
147
129
|
}
|
|
@@ -164,6 +146,13 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
164
146
|
|
|
165
147
|
const validateTooShortNumber = (itiInit: any) => {
|
|
166
148
|
if (!itiInit) return
|
|
149
|
+
|
|
150
|
+
// If field is empty, don't show "too short" error
|
|
151
|
+
if (!inputValue || inputValue.trim() === '') {
|
|
152
|
+
setError('')
|
|
153
|
+
return false
|
|
154
|
+
}
|
|
155
|
+
|
|
167
156
|
if (itiInit.getValidationError() === ValidationError.TooShort) {
|
|
168
157
|
return showFormattedError('too short')
|
|
169
158
|
} else {
|
|
@@ -183,7 +172,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
183
172
|
}
|
|
184
173
|
|
|
185
174
|
const validateUnhandledError = (itiInit: any) => {
|
|
186
|
-
if (!
|
|
175
|
+
if (!itiInit) return
|
|
187
176
|
if (itiInit.getValidationError() === ValidationError.SomethingWentWrong) {
|
|
188
177
|
if (inputValue.length === 1) {
|
|
189
178
|
return showFormattedError('too short')
|
|
@@ -206,14 +195,27 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
206
195
|
|
|
207
196
|
const validateRepeatCountryCode = (itiInit: any) => {
|
|
208
197
|
if (!itiInit) return
|
|
209
|
-
const countryDialCode =
|
|
198
|
+
const countryDialCode = itiRef.current.getSelectedCountryData().dialCode;
|
|
210
199
|
if (unformatNumber(inputValue).startsWith(countryDialCode)) {
|
|
211
200
|
return showFormattedError('repeat country code')
|
|
212
201
|
}
|
|
213
202
|
}
|
|
214
203
|
|
|
204
|
+
const validateRequiredField = () => {
|
|
205
|
+
if (!inputValue || inputValue.trim() === '') {
|
|
206
|
+
setError('Missing phone number')
|
|
207
|
+
return true
|
|
208
|
+
}
|
|
209
|
+
return false
|
|
210
|
+
}
|
|
215
211
|
|
|
216
212
|
const validateErrors = () => {
|
|
213
|
+
// If field is empty, show error message
|
|
214
|
+
if (!inputValue || inputValue.trim() === '') {
|
|
215
|
+
if (validateRequiredField()) return
|
|
216
|
+
return
|
|
217
|
+
}
|
|
218
|
+
|
|
217
219
|
if (!hasTyped && !error) return
|
|
218
220
|
|
|
219
221
|
if (itiRef.current) isValid(itiRef.current.isValidNumber())
|
|
@@ -225,6 +227,87 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
225
227
|
if (validateRepeatCountryCode(itiRef.current)) return
|
|
226
228
|
}
|
|
227
229
|
|
|
230
|
+
/*
|
|
231
|
+
useImperativeHandle exposes the kit's input element to a parent component via a ref.
|
|
232
|
+
See the Playbook docs for use cases.
|
|
233
|
+
Read: https://react.dev/reference/react/useImperativeHandle
|
|
234
|
+
*/
|
|
235
|
+
useImperativeHandle(ref, () => {
|
|
236
|
+
return {
|
|
237
|
+
clearField() {
|
|
238
|
+
setInputValue("")
|
|
239
|
+
setError("")
|
|
240
|
+
setHasTyped(false)
|
|
241
|
+
},
|
|
242
|
+
inputNode() {
|
|
243
|
+
return inputRef.current
|
|
244
|
+
},
|
|
245
|
+
// Expose validation method for React Hook Form
|
|
246
|
+
validate() {
|
|
247
|
+
// Run validation and return error message or true
|
|
248
|
+
const isEmpty = !inputValue || inputValue.trim() === ''
|
|
249
|
+
|
|
250
|
+
if (isEmpty) {
|
|
251
|
+
// Show missing phone number error
|
|
252
|
+
const errorMessage = 'Missing phone number'
|
|
253
|
+
setError(errorMessage)
|
|
254
|
+
setHasTyped(true)
|
|
255
|
+
// Only return error for React Hook Form if field is required
|
|
256
|
+
return required ? errorMessage : true
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (!itiRef.current) {
|
|
260
|
+
return true
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Check for repeat country code first
|
|
264
|
+
const countryDialCode = itiRef.current.getSelectedCountryData().dialCode;
|
|
265
|
+
if (unformatNumber(inputValue).startsWith(countryDialCode)) {
|
|
266
|
+
const countryName = itiRef.current.getSelectedCountryData().name
|
|
267
|
+
const errorMessage = `Invalid ${countryName} phone number (repeat country code)`
|
|
268
|
+
setError(errorMessage)
|
|
269
|
+
setHasTyped(true)
|
|
270
|
+
return errorMessage
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Check if it only contains valid characters
|
|
274
|
+
if (!containOnlyNumbers(inputValue)) {
|
|
275
|
+
const countryName = itiRef.current.getSelectedCountryData().name
|
|
276
|
+
const errorMessage = `Invalid ${countryName} phone number (enter numbers only)`
|
|
277
|
+
setError(errorMessage)
|
|
278
|
+
setHasTyped(true)
|
|
279
|
+
return errorMessage
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Check if valid number
|
|
283
|
+
if (!itiRef.current.isValidNumber()) {
|
|
284
|
+
const countryName = itiRef.current.getSelectedCountryData().name
|
|
285
|
+
const validationError = itiRef.current.getValidationError()
|
|
286
|
+
let errorMessage = ''
|
|
287
|
+
|
|
288
|
+
if (validationError === ValidationError.TooShort) {
|
|
289
|
+
errorMessage = `Invalid ${countryName} phone number (too short)`
|
|
290
|
+
} else if (validationError === ValidationError.TooLong) {
|
|
291
|
+
errorMessage = `Invalid ${countryName} phone number (too long)`
|
|
292
|
+
} else if (validationError === ValidationError.MissingAreaCode) {
|
|
293
|
+
errorMessage = `Invalid ${countryName} phone number (missing area code)`
|
|
294
|
+
} else {
|
|
295
|
+
errorMessage = `Invalid ${countryName} phone number`
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
setError(errorMessage)
|
|
299
|
+
setHasTyped(true)
|
|
300
|
+
|
|
301
|
+
return errorMessage
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Clear error if valid
|
|
305
|
+
setError('')
|
|
306
|
+
return true
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
})
|
|
310
|
+
|
|
228
311
|
const getCurrentSelectedData = (itiInit: any, inputValue: string) => {
|
|
229
312
|
return { ...itiInit.getSelectedCountryData(), number: inputValue }
|
|
230
313
|
}
|
|
@@ -300,7 +383,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
300
383
|
dark,
|
|
301
384
|
"data-phone-number": JSON.stringify(selectedData),
|
|
302
385
|
disabled,
|
|
303
|
-
error,
|
|
386
|
+
error: hasTyped ? error : props.error,
|
|
304
387
|
type: 'tel',
|
|
305
388
|
id,
|
|
306
389
|
label,
|
|
@@ -140,10 +140,14 @@ const TextInput = (props: TextInputProps, ref: React.LegacyRef<HTMLInputElement>
|
|
|
140
140
|
formattedValue = value
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
const errorId = error ? `${id}-error` : undefined
|
|
144
|
+
|
|
143
145
|
const textInput = (
|
|
144
146
|
childInput ? React.cloneElement(children, { className: "text_input" }) :
|
|
145
147
|
(<input
|
|
146
148
|
{...domSafeProps(props)}
|
|
149
|
+
aria-describedby={errorId}
|
|
150
|
+
aria-invalid={!!error}
|
|
147
151
|
autoComplete={typeof autoComplete === "string" ? autoComplete : ( autoComplete ? undefined : "off" )}
|
|
148
152
|
className="text_input"
|
|
149
153
|
disabled={disabled}
|
|
@@ -202,16 +206,20 @@ const TextInput = (props: TextInputProps, ref: React.LegacyRef<HTMLInputElement>
|
|
|
202
206
|
{...htmlProps}
|
|
203
207
|
className={css}
|
|
204
208
|
>
|
|
205
|
-
{label &&
|
|
206
|
-
<
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
{label && (
|
|
210
|
+
<label htmlFor={id}>
|
|
211
|
+
<Caption className="pb_text_input_kit_label"
|
|
212
|
+
text={label}
|
|
213
|
+
/>
|
|
214
|
+
</label>
|
|
215
|
+
)}
|
|
211
216
|
<div className={`${addOnCss} text_input_wrapper`}>
|
|
212
217
|
{render}
|
|
213
218
|
|
|
214
219
|
{error && <Body
|
|
220
|
+
aria={{ atomic: "true", live: "polite" }}
|
|
221
|
+
htmlOptions={{ role: "alert" }}
|
|
222
|
+
id={errorId}
|
|
215
223
|
status="negative"
|
|
216
224
|
text={error}
|
|
217
225
|
variant={null}
|
|
@@ -9,23 +9,27 @@
|
|
|
9
9
|
|
|
10
10
|
<%= pb_rails("text_input", props: {
|
|
11
11
|
label: "Last Name",
|
|
12
|
-
placeholder: "Enter last name"
|
|
12
|
+
placeholder: "Enter last name",
|
|
13
|
+
id: "last-name"
|
|
13
14
|
}) %>
|
|
14
15
|
|
|
15
16
|
<%= pb_rails("text_input", props: {
|
|
16
17
|
label: "Phone Number",
|
|
17
18
|
type: "phone",
|
|
18
|
-
placeholder: "Enter phone number"
|
|
19
|
+
placeholder: "Enter phone number",
|
|
20
|
+
id: "phone"
|
|
19
21
|
}) %>
|
|
20
22
|
|
|
21
23
|
<%= pb_rails("text_input", props: {
|
|
22
24
|
label: "Email Address",
|
|
23
25
|
type: "email",
|
|
24
|
-
placeholder: "Enter email address"
|
|
26
|
+
placeholder: "Enter email address",
|
|
27
|
+
id: "email"
|
|
25
28
|
}) %>
|
|
26
29
|
|
|
27
30
|
<%= pb_rails("text_input", props: {
|
|
28
31
|
label: "Zip Code",
|
|
29
32
|
type: "number",
|
|
30
|
-
placeholder: "Enter zip code"
|
|
33
|
+
placeholder: "Enter zip code",
|
|
34
|
+
id: "zip"
|
|
31
35
|
}) %>
|
|
@@ -38,6 +38,7 @@ const TextInputDefault = (props) => {
|
|
|
38
38
|
{...props}
|
|
39
39
|
/>
|
|
40
40
|
<TextInput
|
|
41
|
+
id="last-name"
|
|
41
42
|
label="Last Name"
|
|
42
43
|
name="lastName"
|
|
43
44
|
onChange={handleOnChangeFormField}
|
|
@@ -46,6 +47,7 @@ const TextInputDefault = (props) => {
|
|
|
46
47
|
{...props}
|
|
47
48
|
/>
|
|
48
49
|
<TextInput
|
|
50
|
+
id="phone"
|
|
49
51
|
label="Phone Number"
|
|
50
52
|
name="phone"
|
|
51
53
|
onChange={handleOnChangeFormField}
|
|
@@ -55,6 +57,7 @@ const TextInputDefault = (props) => {
|
|
|
55
57
|
{...props}
|
|
56
58
|
/>
|
|
57
59
|
<TextInput
|
|
60
|
+
id="email"
|
|
58
61
|
label="Email Address"
|
|
59
62
|
name="email"
|
|
60
63
|
onChange={handleOnChangeFormField}
|
|
@@ -64,6 +67,7 @@ const TextInputDefault = (props) => {
|
|
|
64
67
|
{...props}
|
|
65
68
|
/>
|
|
66
69
|
<TextInput
|
|
70
|
+
id="zip"
|
|
67
71
|
label="Zip Code"
|
|
68
72
|
name="zip"
|
|
69
73
|
onChange={handleOnChangeFormField}
|
|
@@ -84,6 +88,7 @@ const TextInputDefault = (props) => {
|
|
|
84
88
|
<br />
|
|
85
89
|
|
|
86
90
|
<TextInput
|
|
91
|
+
id="first-name"
|
|
87
92
|
label="First Name"
|
|
88
93
|
onChange={handleOnChangeFirstName}
|
|
89
94
|
placeholder="Enter first name"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Add an `id` to your Text Input so that clicking the label will move focus directly to the input.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<%= pb_content_tag(:div, id: nil ) do %>
|
|
2
2
|
<% if object.label.present? %>
|
|
3
|
+
<label for="<%= object.input_options[:id] || object.id %>" >
|
|
3
4
|
<%= pb_rails("caption", props: { text: object.label, dark: object.dark, classname: "pb_text_input_kit_label" }) %>
|
|
5
|
+
</label>
|
|
4
6
|
<% end %>
|
|
5
7
|
<%= content_tag(:div, class: "#{add_on_class} text_input_wrapper") do %>
|
|
6
8
|
<% if content.present? %>
|
|
@@ -15,7 +17,7 @@
|
|
|
15
17
|
<% else %>
|
|
16
18
|
<%= input_tag %>
|
|
17
19
|
<% end %>
|
|
18
|
-
<%= pb_rails("body", props: {dark: object.dark, status: "negative", text: object.error}) if object.error %>
|
|
20
|
+
<%= pb_rails("body", props: {dark: object.dark, status: "negative", text: object.error, id: object.error_id, aria: { atomic: "true", live: "polite" }, html_options: { role: "alert" }}) if object.error %>
|
|
19
21
|
<% end %>
|
|
20
22
|
<% end %>
|
|
21
23
|
|
|
@@ -64,10 +64,16 @@ module Playbook
|
|
|
64
64
|
"#{object.id}-sanitized" if id.present?
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
def error_id
|
|
68
|
+
"#{id}-error" if error.present?
|
|
69
|
+
end
|
|
70
|
+
|
|
67
71
|
private
|
|
68
72
|
|
|
69
73
|
def all_input_options
|
|
70
74
|
{
|
|
75
|
+
'aria-describedby': error.present? ? error_id : nil,
|
|
76
|
+
'aria-invalid': error.present?,
|
|
71
77
|
autocomplete: autocomplete == true ? nil : (autocomplete.presence || "off"),
|
|
72
78
|
class: "text_input #{input_options.dig(:classname) || ''}",
|
|
73
79
|
data: validation_data,
|