playbook_ui 15.1.0 → 15.2.0.pre.alpha.PLAY236711331
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/_playbook.scss +4 -6
- data/app/pb_kits/playbook/pb_advanced_table/Hooks/useTableState.ts +7 -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_pb_bar_graph/_pb_bar_graph.tsx +8 -6
- data/app/pb_kits/playbook/pb_pb_bar_graph/pb_bar_graph.rb +7 -10
- data/app/pb_kits/playbook/pb_pb_bar_graph/pbbargraph.test.jsx +73 -1
- data/app/pb_kits/playbook/pb_pb_circle_chart/_pb_circle_chart.tsx +1 -1
- data/app/pb_kits/playbook/pb_pb_circle_chart/pb_circle_chart.rb +7 -10
- data/app/pb_kits/playbook/pb_pb_circle_chart/pb_circle_chart.test.jsx +47 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/_pb_line_graph.scss +3 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/_pb_line_graph.tsx +61 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_description.md +3 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_colors.html.erb +34 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_colors.jsx +52 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_colors.md +5 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_default.html.erb +34 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_default.jsx +45 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_height.html.erb +47 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_height.jsx +64 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_height.md +3 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend.html.erb +24 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend.jsx +37 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_nonclickable.html.erb +39 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_nonclickable.jsx +45 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_position.html.erb +86 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_position.jsx +116 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_position.md +11 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/example.yml +20 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/index.js +6 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/pbLineGraphTheme.ts +125 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/pb_line_graph.html.erb +1 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/pb_line_graph.rb +25 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/pb_line_graph.test.jsx +110 -0
- 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-AKTV-rqw.js} +1 -1
- data/dist/chunks/_typeahead-DCInCM2E.js +6 -0
- data/dist/chunks/{_weekday_stacked-3-FtXg76.js → _weekday_stacked-ByJl1kOQ.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 +7 -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/version.rb +2 -2
- metadata +37 -7
- data/dist/chunks/_typeahead-DUIMqJiu.js +0 -6
@@ -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,
|