playbook_ui 15.5.0 → 15.6.0.pre.alpha.play265012865
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/_advanced_table.scss +96 -6
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props.html.erb +1 -1
- data/app/pb_kits/playbook/pb_background/_background.tsx +6 -6
- data/app/pb_kits/playbook/pb_background/background.test.js +5 -1
- data/app/pb_kits/playbook/pb_background/docs/_background_light.html.erb +1 -1
- data/app/pb_kits/playbook/pb_background/docs/_background_light.jsx +0 -1
- data/app/pb_kits/playbook/pb_background/docs/_background_light.md +1 -0
- data/app/pb_kits/playbook/pb_background/docs/example.yml +2 -2
- data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.tsx +6 -0
- data/app/pb_kits/playbook/pb_dialog/docs/_dialog_compound_components.html.erb +31 -0
- data/app/pb_kits/playbook/pb_draggable/context/index.tsx +156 -6
- data/app/pb_kits/playbook/pb_draggable/context/types.ts +8 -3
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers_dropzone.jsx +180 -0
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers_dropzone.md +22 -0
- data/app/pb_kits/playbook/pb_draggable/docs/example.yml +3 -2
- data/app/pb_kits/playbook/pb_draggable/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_draggable/draggable.test.jsx +77 -1
- data/app/pb_kits/playbook/pb_file_upload/_file_upload.scss +4 -4
- data/app/pb_kits/playbook/pb_home_address_street/_home_address_street.tsx +34 -22
- data/app/pb_kits/playbook/pb_home_address_street/city_emphasis.html.erb +16 -12
- data/app/pb_kits/playbook/pb_home_address_street/docs/_home_address_street_default.html.erb +1 -1
- data/app/pb_kits/playbook/pb_home_address_street/none_emphasis.html.erb +16 -12
- data/app/pb_kits/playbook/pb_home_address_street/street_emphasis.html.erb +16 -12
- data/app/pb_kits/playbook/pb_legend/_legend.tsx +7 -1
- data/app/pb_kits/playbook/pb_multiple_users/_multiple_users.scss +10 -0
- data/app/pb_kits/playbook/pb_multiple_users/_multiple_users.tsx +66 -15
- data/app/pb_kits/playbook/pb_multiple_users/docs/_multiple_users_with_tooltip.jsx +42 -0
- data/app/pb_kits/playbook/pb_multiple_users/docs/_multiple_users_with_tooltip.md +1 -0
- data/app/pb_kits/playbook/pb_multiple_users/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_multiple_users/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_multiple_users/multiple_users.test.js +25 -0
- data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +44 -10
- data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.html.erb +34 -4
- data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx +16 -7
- data/app/pb_kits/playbook/pb_table/styles/_vertical_border.scss +49 -0
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.test.jsx +15 -0
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +3 -0
- data/app/pb_kits/playbook/pb_typeahead/components/ClearIndicator.tsx +13 -2
- data/app/pb_kits/playbook/pb_typeahead/components/MultiValue.tsx +6 -1
- data/app/pb_kits/playbook/pb_typeahead/components/ValueContainer.tsx +34 -7
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_input_display.html.erb +30 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_input_display.jsx +37 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_input_display.md +3 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_typeahead/typeahead.rb +6 -1
- data/app/pb_kits/playbook/utilities/DEPRECATION_WARNINGS.md +82 -0
- data/app/pb_kits/playbook/utilities/deprecated.ts +65 -0
- data/dist/chunks/_typeahead-Mjy3POtc.js +6 -0
- data/dist/chunks/{lib-Dk4GKPut.js → lib-CgpqUb6l.js} +2 -2
- data/dist/chunks/vendor.js +2 -2
- data/dist/menu.yml +3 -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/version.rb +2 -2
- metadata +14 -5
- data/app/pb_kits/playbook/pb_bar_graph/BarGraphStyles.scss +0 -58
- data/dist/chunks/_typeahead-Bx4QsIEU.js +0 -6
|
@@ -5,17 +5,19 @@ import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../uti
|
|
|
5
5
|
import { globalProps } from '../utilities/globalProps'
|
|
6
6
|
|
|
7
7
|
import Avatar from '../pb_avatar/_avatar'
|
|
8
|
+
import Tooltip from '../pb_tooltip/_tooltip'
|
|
8
9
|
|
|
9
10
|
type MultipleUsersProps = {
|
|
10
11
|
aria?: { [key: string]: string },
|
|
11
12
|
className?: string,
|
|
12
13
|
dark?: boolean,
|
|
13
14
|
data?: { [key: string]: string },
|
|
14
|
-
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
|
|
15
|
+
htmlOptions?: { [key: string]: string | number | boolean | (() => void) },
|
|
15
16
|
id?: string,
|
|
16
17
|
maxDisplayedUsers?: number,
|
|
17
18
|
reverse?: boolean,
|
|
18
19
|
size?: "md" | "lg" | "sm" | "xl" | "xs" | "xxs",
|
|
20
|
+
withTooltip?: boolean,
|
|
19
21
|
users: Array<{ [key: string]: string }>,
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -30,6 +32,7 @@ const MultipleUsers = (props: MultipleUsersProps): React.ReactElement => {
|
|
|
30
32
|
maxDisplayedUsers = 4,
|
|
31
33
|
reverse = false,
|
|
32
34
|
size = 'xs',
|
|
35
|
+
withTooltip = false,
|
|
33
36
|
users,
|
|
34
37
|
} = props
|
|
35
38
|
|
|
@@ -62,22 +65,70 @@ const MultipleUsers = (props: MultipleUsersProps): React.ReactElement => {
|
|
|
62
65
|
className={classes}
|
|
63
66
|
id={id}
|
|
64
67
|
>
|
|
65
|
-
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
{withTooltip ?
|
|
69
|
+
<>
|
|
70
|
+
{usersToDisplay.map((avatarData, index) => (
|
|
71
|
+
<Tooltip
|
|
72
|
+
key={"user_tooltip_" + index}
|
|
73
|
+
placement='top'
|
|
74
|
+
text={avatarData.tooltip ? avatarData.tooltip : ''}
|
|
75
|
+
zIndex={10}
|
|
76
|
+
>
|
|
77
|
+
<Avatar
|
|
78
|
+
{...avatarData}
|
|
79
|
+
className={"pb_multiple_users_item" + (withTooltip ? " user_tooltip" : "")}
|
|
80
|
+
dark={dark}
|
|
81
|
+
imageAlt={avatarData.name}
|
|
82
|
+
key={index}
|
|
83
|
+
size={size}
|
|
84
|
+
/>
|
|
85
|
+
</Tooltip>
|
|
86
|
+
))}
|
|
75
87
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
88
|
+
{users.length > maxDisplayedUsers &&
|
|
89
|
+
<Tooltip
|
|
90
|
+
placement='top'
|
|
91
|
+
text={
|
|
92
|
+
<div>
|
|
93
|
+
{
|
|
94
|
+
usersToDisplay.length < users.length ?
|
|
95
|
+
users.slice(displayCount).map((u, i) => (
|
|
96
|
+
<div key={i}>{u.tooltip}</div>
|
|
97
|
+
))
|
|
98
|
+
:
|
|
99
|
+
''
|
|
100
|
+
}
|
|
101
|
+
</div>
|
|
102
|
+
}
|
|
103
|
+
zIndex={10}
|
|
104
|
+
>
|
|
105
|
+
<div className={itemClasses + (withTooltip ? " user_count_tooltip" : "")}>
|
|
106
|
+
{`+${users.length - displayCount}`}
|
|
107
|
+
</div>
|
|
108
|
+
</Tooltip>
|
|
109
|
+
}
|
|
110
|
+
</>
|
|
111
|
+
:
|
|
112
|
+
<>
|
|
113
|
+
{usersToDisplay.map((avatarData, index) => (
|
|
114
|
+
<Avatar
|
|
115
|
+
{...avatarData}
|
|
116
|
+
className="pb_multiple_users_item"
|
|
117
|
+
dark={dark}
|
|
118
|
+
imageAlt={avatarData.name}
|
|
119
|
+
key={index}
|
|
120
|
+
size={size}
|
|
121
|
+
/>
|
|
122
|
+
))}
|
|
123
|
+
|
|
124
|
+
{users.length > maxDisplayedUsers &&
|
|
125
|
+
<div className={itemClasses}>
|
|
126
|
+
{`+${users.length - 3}`}
|
|
127
|
+
</div>
|
|
128
|
+
}
|
|
129
|
+
</>
|
|
80
130
|
}
|
|
131
|
+
|
|
81
132
|
</div>
|
|
82
133
|
)
|
|
83
134
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import MultipleUsers from '../../pb_multiple_users/_multiple_users'
|
|
3
|
+
|
|
4
|
+
const MultipleUsersWithTooltip = (props) => {
|
|
5
|
+
return (
|
|
6
|
+
<div>
|
|
7
|
+
<MultipleUsers
|
|
8
|
+
users={[
|
|
9
|
+
{
|
|
10
|
+
name: 'Patrick Welch',
|
|
11
|
+
imageUrl: 'https://randomuser.me/api/portraits/men/9.jpg',
|
|
12
|
+
tooltip: "Patrick Welch - Online"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'Lucille Sanchez',
|
|
16
|
+
imageUrl: 'https://randomuser.me/api/portraits/women/6.jpg',
|
|
17
|
+
tooltip: "Lucille Sanchez - Offline"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'Beverly Reyes',
|
|
21
|
+
imageUrl: 'https://randomuser.me/api/portraits/women/74.jpg',
|
|
22
|
+
tooltip: "Beverly Reyes - Online"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'Keith Craig',
|
|
26
|
+
imageUrl: 'https://randomuser.me/api/portraits/men/40.jpg',
|
|
27
|
+
tooltip: "Keith Craig - Away"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'Alicia Cooper',
|
|
31
|
+
imageUrl: 'https://randomuser.me/api/portraits/women/46.jpg',
|
|
32
|
+
tooltip: "Alicia Cooper - Busy"
|
|
33
|
+
},
|
|
34
|
+
]}
|
|
35
|
+
withTooltip
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
38
|
+
</div>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
``
|
|
42
|
+
export default MultipleUsersWithTooltip
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Use the `withTooltip` boolean prop to enable setting user-specific tooltip content via the `tooltip` property in the users array.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { default as MultipleUsersDefault } from './_multiple_users_default.jsx'
|
|
2
2
|
export { default as MultipleUsersReverse } from './_multiple_users_reverse.jsx'
|
|
3
3
|
export { default as MultipleUsersSize } from './_multiple_users_size.jsx'
|
|
4
|
+
export { default as MultipleUsersWithTooltip } from './_multiple_users_with_tooltip.jsx'
|
|
@@ -49,4 +49,29 @@ test('should render aria-label', () => {
|
|
|
49
49
|
|
|
50
50
|
const kit = screen.getByTestId(testId)
|
|
51
51
|
expect(kit).toHaveAttribute('aria-label', testId)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('should render withTooltip prop', () => {
|
|
55
|
+
render(
|
|
56
|
+
<MultipleUsers
|
|
57
|
+
data={{ testid: testId }}
|
|
58
|
+
users={[
|
|
59
|
+
{
|
|
60
|
+
name: 'Patrick Welch',
|
|
61
|
+
imageUrl: 'https://randomuser.me/api/portraits/men/9.jpg',
|
|
62
|
+
tooltip: "Patrick Welch - Online"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'Lucille Sanchez',
|
|
66
|
+
imageUrl: 'https://randomuser.me/api/portraits/women/6.jpg',
|
|
67
|
+
tooltip: "Lucille Sanchez - Offline"
|
|
68
|
+
},
|
|
69
|
+
]}
|
|
70
|
+
withTooltip
|
|
71
|
+
/>
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
const kit = screen.getByTestId(testId)
|
|
75
|
+
const childWithTooltip = kit.querySelector('.pb_tooltip_kit')
|
|
76
|
+
expect(childWithTooltip).not.toBeNull()
|
|
52
77
|
})
|
|
@@ -110,13 +110,25 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
110
110
|
const inputRef = useRef<HTMLInputElement | null>(null)
|
|
111
111
|
const itiRef = useRef<any>(null);
|
|
112
112
|
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
|
113
|
+
const hasBlurredRef = useRef<boolean>(false);
|
|
114
|
+
const formSubmittedRef = useRef<boolean>(false);
|
|
113
115
|
const [inputValue, setInputValue] = useState(value)
|
|
114
116
|
const [error, setError] = useState(props.error || "")
|
|
115
117
|
const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
|
|
116
118
|
const [selectedData, setSelectedData] = useState()
|
|
117
119
|
const [hasTyped, setHasTyped] = useState(false)
|
|
120
|
+
const [hasBlurred, setHasBlurred] = useState(false)
|
|
118
121
|
const [formSubmitted, setFormSubmitted] = useState(false)
|
|
119
122
|
const [hasStartedValidating, setHasStartedValidating] = useState(false)
|
|
123
|
+
|
|
124
|
+
// Keep refs in sync with state for use in event listeners
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
hasBlurredRef.current = hasBlurred
|
|
127
|
+
}, [hasBlurred])
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
formSubmittedRef.current = formSubmitted
|
|
131
|
+
}, [formSubmitted])
|
|
120
132
|
|
|
121
133
|
// Only sync initial error from props, not continuous updates
|
|
122
134
|
// Once validation starts, internal validation takes over
|
|
@@ -143,8 +155,8 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
143
155
|
}
|
|
144
156
|
|
|
145
157
|
// Determine which error to display
|
|
146
|
-
// Show internal errors
|
|
147
|
-
const shouldShowInternalError = (
|
|
158
|
+
// Show internal errors only after blur (hasBlurred) or on form submission (formSubmitted)
|
|
159
|
+
const shouldShowInternalError = (hasBlurred || formSubmitted) && error
|
|
148
160
|
const displayError = shouldShowInternalError ? error : ""
|
|
149
161
|
|
|
150
162
|
useEffect(() => {
|
|
@@ -259,7 +271,9 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
259
271
|
return
|
|
260
272
|
}
|
|
261
273
|
|
|
262
|
-
if
|
|
274
|
+
// Only validate if field has been blurred or form has been submitted
|
|
275
|
+
// Use refs here since state updates are async and we need current values
|
|
276
|
+
if (!hasBlurredRef.current && !formSubmittedRef.current) return
|
|
263
277
|
|
|
264
278
|
// Run validation checks
|
|
265
279
|
if (itiRef.current) isValid(itiRef.current.isValidNumber())
|
|
@@ -280,6 +294,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
280
294
|
if (phoneNumberContainer && phoneNumberContainer === wrapperRef.current) {
|
|
281
295
|
const invalidInputName = target.name || target.getAttribute('name')
|
|
282
296
|
if (invalidInputName === name) {
|
|
297
|
+
formSubmittedRef.current = true
|
|
283
298
|
setFormSubmitted(true)
|
|
284
299
|
// Trigger validation when form is submitted
|
|
285
300
|
validateErrors()
|
|
@@ -305,6 +320,9 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
305
320
|
setInputValue("")
|
|
306
321
|
setError("")
|
|
307
322
|
setHasTyped(false)
|
|
323
|
+
hasBlurredRef.current = false
|
|
324
|
+
setHasBlurred(false)
|
|
325
|
+
formSubmittedRef.current = false
|
|
308
326
|
setFormSubmitted(false)
|
|
309
327
|
setHasStartedValidating(false)
|
|
310
328
|
// Only clear validation state if field was required
|
|
@@ -322,6 +340,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
322
340
|
|
|
323
341
|
if (required && isEmpty) {
|
|
324
342
|
setError('Missing phone number')
|
|
343
|
+
formSubmittedRef.current = true
|
|
325
344
|
setFormSubmitted(true)
|
|
326
345
|
return 'Missing phone number'
|
|
327
346
|
}
|
|
@@ -378,6 +397,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
378
397
|
|
|
379
398
|
// Set the error state so the validation attribute gets added
|
|
380
399
|
setError(errorMessage)
|
|
400
|
+
formSubmittedRef.current = true
|
|
381
401
|
setFormSubmitted(true)
|
|
382
402
|
setHasTyped(true)
|
|
383
403
|
|
|
@@ -401,6 +421,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
401
421
|
|
|
402
422
|
// Reset form submitted state when user types
|
|
403
423
|
if (formSubmitted) {
|
|
424
|
+
formSubmittedRef.current = false
|
|
404
425
|
setFormSubmitted(false)
|
|
405
426
|
}
|
|
406
427
|
|
|
@@ -416,11 +437,15 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
416
437
|
|
|
417
438
|
setSelectedData(phoneNumberData)
|
|
418
439
|
onChange(phoneNumberData)
|
|
419
|
-
|
|
440
|
+
|
|
441
|
+
// Don't call isValid callback on change - only on blur or form submission
|
|
442
|
+
// This prevents triggering validation while typing
|
|
443
|
+
// Use refs to get current values in case this is called from event listener
|
|
444
|
+
if (hasBlurredRef.current || formSubmittedRef.current) {
|
|
445
|
+
isValid(itiRef.current.isValidNumber())
|
|
446
|
+
}
|
|
420
447
|
|
|
421
|
-
//
|
|
422
|
-
// This ensures validation state is up-to-date
|
|
423
|
-
setTimeout(() => validateErrors(), 0)
|
|
448
|
+
// Don't validate on change - only validate on blur or form submission
|
|
424
449
|
}
|
|
425
450
|
|
|
426
451
|
// Separating Concerns as React Docs Recommend
|
|
@@ -482,7 +507,12 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
482
507
|
|
|
483
508
|
setSelectedData(phoneNumberData)
|
|
484
509
|
onChange(phoneNumberData)
|
|
485
|
-
|
|
510
|
+
|
|
511
|
+
// Don't call isValid callback on change - only on blur or form submission
|
|
512
|
+
// Use refs to check current blur state in the event listener (closure issue)
|
|
513
|
+
if (hasBlurredRef.current || formSubmittedRef.current) {
|
|
514
|
+
isValid(telInputInit.isValidNumber())
|
|
515
|
+
}
|
|
486
516
|
})
|
|
487
517
|
}
|
|
488
518
|
}
|
|
@@ -492,12 +522,16 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
492
522
|
dark,
|
|
493
523
|
"data-phone-number": JSON.stringify(selectedData),
|
|
494
524
|
disabled,
|
|
495
|
-
error:
|
|
525
|
+
error: displayError || props.error || "",
|
|
496
526
|
type: 'tel',
|
|
497
527
|
id,
|
|
498
528
|
label,
|
|
499
529
|
name,
|
|
500
|
-
onBlur:
|
|
530
|
+
onBlur: () => {
|
|
531
|
+
hasBlurredRef.current = true
|
|
532
|
+
setHasBlurred(true)
|
|
533
|
+
validateErrors()
|
|
534
|
+
},
|
|
501
535
|
onChange: formatAsYouType ? undefined : handleOnChange,
|
|
502
536
|
value: inputValue
|
|
503
537
|
}
|
data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.html.erb
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
1
|
<form id="example-form-validation" action="" method="get">
|
|
2
|
-
<%= pb_rails("phone_number_input", props: {
|
|
2
|
+
<%= pb_rails("phone_number_input", props: {
|
|
3
|
+
id: "validation",
|
|
4
|
+
initial_country: "af",
|
|
5
|
+
value: "",
|
|
6
|
+
required: true
|
|
7
|
+
}) %>
|
|
3
8
|
<%= pb_rails("button", props: {html_type: "submit", text: "Save Phone Number"}) %>
|
|
4
9
|
</form>
|
|
5
10
|
|
|
6
11
|
<%= javascript_tag do %>
|
|
7
12
|
document.addEventListener('DOMContentLoaded', function () {
|
|
8
|
-
document.querySelector('#example-form-validation')
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
const form = document.querySelector('#example-form-validation');
|
|
14
|
+
|
|
15
|
+
// Wait for React component to mount
|
|
16
|
+
function waitForComponent() {
|
|
17
|
+
const phoneInput = form.querySelector('#validation');
|
|
18
|
+
|
|
19
|
+
if (!phoneInput) {
|
|
20
|
+
setTimeout(waitForComponent, 100);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Wait for intl-tel-input to initialize, then focus and blur to trigger validation
|
|
25
|
+
setTimeout(function() {
|
|
26
|
+
phoneInput.focus({ preventScroll: true });
|
|
27
|
+
setTimeout(function() {
|
|
28
|
+
phoneInput.blur();
|
|
29
|
+
}, 100);
|
|
30
|
+
}, 500);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
waitForComponent();
|
|
34
|
+
|
|
35
|
+
// Prevent form submission if there are validation errors
|
|
36
|
+
form.addEventListener('submit', function (e) {
|
|
37
|
+
if (e.target.querySelectorAll('[error]:not([error=""])').length > 0) {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
11
41
|
})
|
|
12
42
|
<% end %>
|
|
@@ -10,8 +10,19 @@ const PhoneNumberInputValidation = (props) => {
|
|
|
10
10
|
const [showFormErrors, setShowFormErrors] = useState(false);
|
|
11
11
|
const [phoneNumber, setPhoneNumber] = useState("");
|
|
12
12
|
const [countryCode, setCountryCode] = useState("af");
|
|
13
|
+
const [isValid, setIsValid] = useState(false);
|
|
14
|
+
const [hasInteracted, setHasInteracted] = useState(false);
|
|
15
|
+
|
|
16
|
+
// Start with initial error - will be cleared on blur if valid
|
|
17
|
+
const initialError = (
|
|
18
|
+
<>
|
|
19
|
+
<Icon icon="warning" /> Missing phone number.
|
|
20
|
+
</>
|
|
21
|
+
);
|
|
13
22
|
|
|
14
23
|
const handleOnValidate = (valid) => {
|
|
24
|
+
setIsValid(valid);
|
|
25
|
+
setHasInteracted(true);
|
|
15
26
|
setFormErrors(
|
|
16
27
|
valid ? "" : "Please correct the fields below and try again."
|
|
17
28
|
);
|
|
@@ -23,18 +34,16 @@ const PhoneNumberInputValidation = (props) => {
|
|
|
23
34
|
};
|
|
24
35
|
|
|
25
36
|
const handleOnSubmit = (e) => {
|
|
26
|
-
if (
|
|
37
|
+
if (!isValid) e.preventDefault()
|
|
27
38
|
}
|
|
28
39
|
|
|
29
40
|
useEffect(() => {
|
|
30
41
|
setShowFormErrors(formErrors.length > 0);
|
|
31
42
|
}, [formErrors]);
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
</>
|
|
37
|
-
)
|
|
44
|
+
// Only show error prop initially, or if invalid after interaction
|
|
45
|
+
// Clear error prop once valid (component handles validation on blur)
|
|
46
|
+
const shouldShowError = !hasInteracted || (hasInteracted && !isValid);
|
|
38
47
|
|
|
39
48
|
return (
|
|
40
49
|
<form
|
|
@@ -50,7 +59,7 @@ const PhoneNumberInputValidation = (props) => {
|
|
|
50
59
|
/>
|
|
51
60
|
)}
|
|
52
61
|
<PhoneNumberInput
|
|
53
|
-
error={
|
|
62
|
+
error={shouldShowError ? initialError : undefined}
|
|
54
63
|
id="validation"
|
|
55
64
|
initialCountry={countryCode}
|
|
56
65
|
onChange={handleOnChange}
|
|
@@ -8,6 +8,25 @@
|
|
|
8
8
|
border-right: 1px solid $border_light !important;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
// **Advanced Table** specific rules to eliminate double borders when vertical-border is active
|
|
12
|
+
.pb_advanced_table &,
|
|
13
|
+
&[data-vertical-border="true"] {
|
|
14
|
+
// Remove first column box-shadow (preserve border-right in Chrome and use CSS var to respect column group border colors)
|
|
15
|
+
.table-header-cells:first-child,
|
|
16
|
+
.table-header-cells-custom:first-child,
|
|
17
|
+
td:first-child,
|
|
18
|
+
.pb_table_td:first-child,
|
|
19
|
+
.checkbox-cell.checkbox-cell-header:first-child {
|
|
20
|
+
box-shadow: none !important;
|
|
21
|
+
border-right: 1px solid var(--column-border-color, #{$border_light}) !important;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.pb_table_td:nth-child(2) {
|
|
25
|
+
box-shadow: none !important;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// --- End Advanced Table First Column Code Section ---
|
|
29
|
+
|
|
11
30
|
@media screen and (min-width: $screen-xs-min) {
|
|
12
31
|
tr:hover, .pb_table_tr:hover {
|
|
13
32
|
td:last-child, .pb_table_td:last-child {
|
|
@@ -63,5 +82,35 @@
|
|
|
63
82
|
}
|
|
64
83
|
}
|
|
65
84
|
}
|
|
85
|
+
|
|
86
|
+
// Dark mode support for advanced tables
|
|
87
|
+
.pb_advanced_table.dark & {
|
|
88
|
+
td, th, .pb_table_td, .pb_table_th {
|
|
89
|
+
border-right: 1px solid $border_dark !important;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
thead tr th {
|
|
93
|
+
border-right: 1px solid $border_dark !important;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
&[data-vertical-border="true"] {
|
|
97
|
+
.table-header-cells:first-child,
|
|
98
|
+
.table-header-cells-custom:first-child,
|
|
99
|
+
td:first-child,
|
|
100
|
+
.pb_table_td:first-child,
|
|
101
|
+
.checkbox-cell.checkbox-cell-header:first-child {
|
|
102
|
+
border-right: 1px solid var(--column-border-color, #{$border_dark}) !important;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@media screen and (min-width: $screen-xs-min) {
|
|
107
|
+
tr:hover, .pb_table_tr:hover {
|
|
108
|
+
td:last-child, .pb_table_td:last-child {
|
|
109
|
+
border-right-color: darken($border_dark, 10%) !important;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// --- End Advanced Table Dark Mode Code Section ---
|
|
66
115
|
}
|
|
67
116
|
}
|
|
@@ -276,3 +276,18 @@ test('multi-value badges have tabIndex and focus class when focused', () => {
|
|
|
276
276
|
})
|
|
277
277
|
})
|
|
278
278
|
|
|
279
|
+
test('input display none shows number of selected items', () => {
|
|
280
|
+
render(
|
|
281
|
+
<Typeahead
|
|
282
|
+
data={{ testid: 'input-display-none-test' }}
|
|
283
|
+
defaultValue={[options[0], options[1]]}
|
|
284
|
+
inputDisplay="none"
|
|
285
|
+
isMulti
|
|
286
|
+
options={options}
|
|
287
|
+
/>
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
const kit = screen.getByTestId('input-display-none-test')
|
|
291
|
+
const inputDisplayDiv = kit.querySelector(".pb_typeahead_selection_count")
|
|
292
|
+
expect(inputDisplayDiv).toHaveTextContent("2 items selected")
|
|
293
|
+
})
|
|
@@ -43,6 +43,7 @@ type TypeaheadProps = {
|
|
|
43
43
|
error?: string,
|
|
44
44
|
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
|
|
45
45
|
id?: string,
|
|
46
|
+
inputDisplay?: "pills" | "none",
|
|
46
47
|
label?: string,
|
|
47
48
|
loadOptions?: string | Noop,
|
|
48
49
|
getOptionLabel?: string | (() => string),
|
|
@@ -89,6 +90,7 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
|
|
|
89
90
|
getOptionValue,
|
|
90
91
|
htmlOptions = {},
|
|
91
92
|
id,
|
|
93
|
+
inputDisplay = "pills",
|
|
92
94
|
name,
|
|
93
95
|
loadOptions = noop,
|
|
94
96
|
marginBottom = "sm",
|
|
@@ -238,6 +240,7 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
|
|
|
238
240
|
getOptionValue: isString(getOptionValue) ? get(window, getOptionValue) : getOptionValue,
|
|
239
241
|
defaultOptions: true,
|
|
240
242
|
id: id || uniqueId(),
|
|
243
|
+
inputDisplay: inputDisplay,
|
|
241
244
|
inline: false,
|
|
242
245
|
isClearable: true,
|
|
243
246
|
isSearchable: true,
|
|
@@ -7,18 +7,29 @@ type ClearContainerProps = {
|
|
|
7
7
|
id: string,
|
|
8
8
|
},
|
|
9
9
|
clearValue: () => void,
|
|
10
|
+
innerProps?: any,
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
const ClearContainer = (props: ClearContainerProps): React.ReactElement => {
|
|
13
|
-
const { selectProps, clearValue } = props
|
|
13
|
+
const ClearContainer = (props: ClearContainerProps | any): React.ReactElement => {
|
|
14
|
+
const { selectProps, clearValue, innerProps } = props
|
|
14
15
|
useEffect(() => {
|
|
15
16
|
document.addEventListener(`pb-typeahead-kit-${selectProps.id}:clear`, clearValue)
|
|
16
17
|
}, [clearValue, selectProps.id])
|
|
17
18
|
|
|
19
|
+
// To stop this from bubbling up when inside a dialog or other modal
|
|
20
|
+
const handleMouseDown = (event: React.MouseEvent) => {
|
|
21
|
+
event.stopPropagation()
|
|
22
|
+
innerProps?.onMouseDown?.(event)
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
return (
|
|
19
26
|
<components.ClearIndicator
|
|
20
27
|
className="clear_indicator"
|
|
21
28
|
{...props}
|
|
29
|
+
innerProps={{
|
|
30
|
+
...innerProps,
|
|
31
|
+
onMouseDown: handleMouseDown,
|
|
32
|
+
}}
|
|
22
33
|
/>
|
|
23
34
|
)
|
|
24
35
|
}
|
|
@@ -19,7 +19,12 @@ type Props = {
|
|
|
19
19
|
const MultiValue = (props: Props) => {
|
|
20
20
|
const { removeProps, isFocused } = props
|
|
21
21
|
const { imageUrl, label } = props.data
|
|
22
|
-
const { dark, multiKit, pillColor, truncate, wrapped } = props.selectProps
|
|
22
|
+
const { dark, multiKit, pillColor, truncate, wrapped, inputDisplay } = props.selectProps
|
|
23
|
+
|
|
24
|
+
// If inputDisplay is "none", don't render the pill/badge, just return null (the count handled in ValueContainer file)
|
|
25
|
+
if (inputDisplay === 'none') {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
23
28
|
|
|
24
29
|
const formPillProps = {
|
|
25
30
|
marginRight: 'xs',
|
|
@@ -1,15 +1,42 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { components } from 'react-select'
|
|
3
|
+
import Body from '../../pb_body/_body'
|
|
3
4
|
|
|
4
5
|
type ValueContainerProps = {
|
|
5
|
-
children: React.ReactNode,
|
|
6
|
+
children: React.ReactNode | React.ReactNode[],
|
|
7
|
+
selectProps?: Record<string, unknown>,
|
|
8
|
+
hasValue?: boolean,
|
|
6
9
|
}
|
|
7
10
|
|
|
8
|
-
const ValueContainer = (props: ValueContainerProps): React.ReactElement =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
)
|
|
11
|
+
const ValueContainer = (props: ValueContainerProps | any): React.ReactElement => {
|
|
12
|
+
const { children, selectProps, hasValue } = props
|
|
13
|
+
const inputDisplay = (selectProps as any)?.inputDisplay
|
|
14
|
+
const value = (selectProps as any)?.value
|
|
15
|
+
|
|
16
|
+
// When inputDisplay is "none" and there are selected values, show count text (this is for multi-select only)
|
|
17
|
+
if (inputDisplay === 'none' && hasValue && value) {
|
|
18
|
+
const selectedCount = Array.isArray(value) ? value.length : 0
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<components.ValueContainer
|
|
22
|
+
className="text_input_value_container"
|
|
23
|
+
{...props}
|
|
24
|
+
>
|
|
25
|
+
<Body
|
|
26
|
+
className="pb_typeahead_selection_count"
|
|
27
|
+
text={`${selectedCount} item${selectedCount !== 1 ? 's' : ''} selected`}
|
|
28
|
+
/>
|
|
29
|
+
{children}
|
|
30
|
+
</components.ValueContainer>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<components.ValueContainer
|
|
36
|
+
className="text_input_value_container"
|
|
37
|
+
{...props}
|
|
38
|
+
/>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
14
41
|
|
|
15
42
|
export default ValueContainer
|