playbook_ui 14.6.0.pre.rc.14 → 14.6.0.pre.rc.16
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_dropdown/_dropdown.tsx +20 -4
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_clear_selection.jsx +45 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_clear_selection.md +1 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownOption.tsx +1 -1
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownTrigger.tsx +2 -2
- data/app/pb_kits/playbook/pb_filter/Filter/ResultsCount.tsx +4 -2
- data/app/pb_kits/playbook/pb_filter/docs/_filter_default.jsx +1 -1
- data/dist/chunks/_weekday_stacked-u3y7B_ZI.js +45 -0
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +5 -3
- data/dist/chunks/_weekday_stacked-Div3Fpd3.js +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84ab1606aafdcd4bfc9c89a95163a577c361ff6b75d08f50c82ba589a15c255e
|
4
|
+
data.tar.gz: b503766bdb02868c3d6697694f708cd2295b54fa58b7e034b1dc97f2e193e487
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4593e305a3a9f237a3a26ecf83416dcf716f1383c1d1f22ce66c8b6131adb954c1798c207f4ac2dd7f5eb77f7a5c371b95f6610c7299a8548d42db433649cd4
|
7
|
+
data.tar.gz: 69a71de2cbdc8389426872a7dc2fd8eb1ba8ac6082731e96e655acaaba126dc2f0d647ea5e03f2859846364541ceee950cc6ec597f26c6850e85e5ca2ef5258c
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useState, useRef, useEffect } from "react";
|
1
|
+
import React, { useState, useRef, useEffect, forwardRef, useImperativeHandle } from "react";
|
2
2
|
import classnames from "classnames";
|
3
3
|
import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from "../utilities/props";
|
4
4
|
import { globalProps } from "../utilities/globalProps";
|
@@ -38,7 +38,14 @@ type DropdownProps = {
|
|
38
38
|
triggerRef?: any;
|
39
39
|
};
|
40
40
|
|
41
|
-
|
41
|
+
interface DropdownComponent
|
42
|
+
extends React.ForwardRefExoticComponent<DropdownProps & React.RefAttributes<unknown>> {
|
43
|
+
Option: typeof DropdownOption;
|
44
|
+
Trigger: typeof DropdownTrigger;
|
45
|
+
Container: typeof DropdownContainer;
|
46
|
+
}
|
47
|
+
|
48
|
+
const Dropdown = forwardRef((props: DropdownProps, ref: any) => {
|
42
49
|
const {
|
43
50
|
aria = {},
|
44
51
|
autocomplete = false,
|
@@ -125,7 +132,7 @@ const Dropdown = (props: DropdownProps) => {
|
|
125
132
|
const filteredOptions = optionsWithBlankSelection?.filter((option: GenericObject) => {
|
126
133
|
const label = typeof option.label === 'string' ? option.label.toLowerCase() : option.label;
|
127
134
|
return String(label).toLowerCase().includes(filterItem.toLowerCase());
|
128
|
-
});
|
135
|
+
});
|
129
136
|
|
130
137
|
// For keyboard accessibility: Set focus within dropdown to selected item if it exists
|
131
138
|
useEffect(() => {
|
@@ -175,6 +182,14 @@ const Dropdown = (props: DropdownProps) => {
|
|
175
182
|
dark
|
176
183
|
});
|
177
184
|
|
185
|
+
useImperativeHandle(ref, () => ({
|
186
|
+
clearSelected: () => {
|
187
|
+
setSelected({});
|
188
|
+
setFilterItem("");
|
189
|
+
setIsDropDownClosed(true);
|
190
|
+
onSelect && onSelect(null);
|
191
|
+
},
|
192
|
+
}));
|
178
193
|
|
179
194
|
return (
|
180
195
|
<div {...ariaProps}
|
@@ -258,8 +273,9 @@ const Dropdown = (props: DropdownProps) => {
|
|
258
273
|
</DropdownContext.Provider>
|
259
274
|
</div>
|
260
275
|
)
|
261
|
-
}
|
276
|
+
}) as DropdownComponent
|
262
277
|
|
278
|
+
Dropdown.displayName = "Dropdown";
|
263
279
|
Dropdown.Option = DropdownOption;
|
264
280
|
Dropdown.Trigger = DropdownTrigger;
|
265
281
|
Dropdown.Container = DropdownContainer;
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import React, { useRef } from 'react'
|
2
|
+
import { Button, Dropdown } from 'playbook-ui'
|
3
|
+
|
4
|
+
const options = [
|
5
|
+
{
|
6
|
+
label: "United States",
|
7
|
+
value: "United States",
|
8
|
+
},
|
9
|
+
{
|
10
|
+
label: "Canada",
|
11
|
+
value: "Canada",
|
12
|
+
},
|
13
|
+
{
|
14
|
+
label: "Pakistan",
|
15
|
+
value: "Pakistan",
|
16
|
+
}
|
17
|
+
]
|
18
|
+
|
19
|
+
const DropdownClearSelection = (props) => {
|
20
|
+
const dropdownRef = useRef(null)
|
21
|
+
|
22
|
+
const handleReset = () => {
|
23
|
+
if (dropdownRef.current) {
|
24
|
+
dropdownRef.current.clearSelected()
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
return (
|
29
|
+
<>
|
30
|
+
<Dropdown
|
31
|
+
defaultValue={options[2]}
|
32
|
+
options={options}
|
33
|
+
ref={dropdownRef}
|
34
|
+
{...props}
|
35
|
+
/>
|
36
|
+
<Button
|
37
|
+
marginTop="md"
|
38
|
+
onClick={handleReset}
|
39
|
+
text="Reset"
|
40
|
+
/>
|
41
|
+
</>
|
42
|
+
)
|
43
|
+
}
|
44
|
+
|
45
|
+
export default DropdownClearSelection
|
@@ -0,0 +1 @@
|
|
1
|
+
To use an external control (like a reset button) to clear Dropdown selection, you can make use of the `useRef` hook. You must pass a ref to the Dropdown component and use that ref within the onClick for the external control in the way shown in the code snippet below.
|
@@ -22,6 +22,7 @@ examples:
|
|
22
22
|
- dropdown_error: Dropdown with Error
|
23
23
|
- dropdown_default_value: Default Value
|
24
24
|
- dropdown_blank_selection: Blank Selection
|
25
|
+
- dropdown_clear_selection: Clear Selection
|
25
26
|
# - dropdown_with_autocomplete: Autocomplete
|
26
27
|
# - dropdown_with_autocomplete_and_custom_display: Autocomplete with Custom Display
|
27
28
|
# - dropdown_with_external_control: useDropdown Hook
|
@@ -12,3 +12,4 @@ export { default as DropdownSubcomponentStructure } from './_dropdown_subcompone
|
|
12
12
|
export { default as DropdownError } from './_dropdown_error.jsx'
|
13
13
|
export { default as DropdownDefaultValue } from './_dropdown_default_value.jsx'
|
14
14
|
export { default as DropdownBlankSelection } from './_dropdown_blank_selection.jsx'
|
15
|
+
export { default as DropdownClearSelection } from './_dropdown_clear_selection.jsx'
|
@@ -73,7 +73,7 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
73
73
|
!autocomplete && "select_only"
|
74
74
|
);
|
75
75
|
|
76
|
-
const customDisplayPlaceholder = selected
|
76
|
+
const customDisplayPlaceholder = selected?.label ? (
|
77
77
|
<b>{selected.label}</b>
|
78
78
|
) : autocomplete ? (
|
79
79
|
""
|
@@ -83,7 +83,7 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
83
83
|
"Select..."
|
84
84
|
);
|
85
85
|
|
86
|
-
const defaultDisplayPlaceholder = selected
|
86
|
+
const defaultDisplayPlaceholder = selected?.label
|
87
87
|
? selected.label
|
88
88
|
: autocomplete
|
89
89
|
? ""
|
@@ -13,6 +13,7 @@ type ResultsCountProps = {
|
|
13
13
|
const ResultsCount = ({ dark, results, title }: ResultsCountProps): React.ReactElement => {
|
14
14
|
|
15
15
|
const resultTitle = () => {
|
16
|
+
if (results == null) return null
|
16
17
|
return (
|
17
18
|
<TitleCount
|
18
19
|
align="center"
|
@@ -24,6 +25,7 @@ const ResultsCount = ({ dark, results, title }: ResultsCountProps): React.ReactE
|
|
24
25
|
}
|
25
26
|
|
26
27
|
const justResults = () => {
|
28
|
+
if (results == null) return null
|
27
29
|
return (
|
28
30
|
<Caption
|
29
31
|
className="filter-results"
|
@@ -35,13 +37,13 @@ const ResultsCount = ({ dark, results, title }: ResultsCountProps): React.ReactE
|
|
35
37
|
}
|
36
38
|
|
37
39
|
const displayResultsCount = () => {
|
38
|
-
if (results && title) {
|
40
|
+
if (results != null && results >=0 && title) {
|
39
41
|
return (
|
40
42
|
<>
|
41
43
|
{resultTitle()}
|
42
44
|
</>
|
43
45
|
)
|
44
|
-
} else if (results) {
|
46
|
+
} else if (results !=null && results >=0 ) {
|
45
47
|
return (
|
46
48
|
<>
|
47
49
|
{justResults()}
|