playbook_ui 13.30.0.pre.alpha.20240515remotebuildkitconversion3150 → 13.30.0
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_advanced_table/docs/example.yml +2 -3
- data/app/pb_kits/playbook/pb_advanced_table/table_header.html.erb +4 -4
- data/app/pb_kits/playbook/pb_card/_card.tsx +3 -4
- data/app/pb_kits/playbook/pb_collapsible/index.js +1 -6
- data/app/pb_kits/playbook/pb_date_time_stacked/docs/example.yml +1 -6
- data/app/pb_kits/playbook/pb_draggable/_draggable.scss +4 -2
- data/app/pb_kits/playbook/pb_draggable/context/index.tsx +50 -70
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_default.jsx +1 -2
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_default.md +1 -1
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers.jsx +1 -5
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.jsx +4 -11
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.md +2 -4
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list.jsx +2 -2
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list.md +1 -7
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list.jsx +4 -6
- data/app/pb_kits/playbook/pb_draggable/draggable.test.jsx +15 -142
- data/app/pb_kits/playbook/pb_draggable/subcomponents/DraggableItem.tsx +5 -6
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +0 -18
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +218 -228
- data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +0 -2
- data/app/pb_kits/playbook/pb_dropdown/docs/index.js +1 -2
- data/app/pb_kits/playbook/pb_dropdown/dropdown.html.erb +12 -14
- data/app/pb_kits/playbook/pb_dropdown/dropdown.rb +0 -7
- data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +2 -17
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/_fixed_confirmation_toast.tsx +3 -9
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/docs/example.yml +0 -2
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/docs/index.js +0 -1
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/fixed_confirmation_toast.rb +11 -16
- data/app/pb_kits/playbook/pb_icon/_icon.tsx +6 -37
- data/app/pb_kits/playbook/pb_icon/docs/_icon_default.html.erb +1 -6
- data/app/pb_kits/playbook/pb_icon/docs/_icon_default.jsx +5 -21
- data/app/pb_kits/playbook/pb_icon/icon.rb +1 -21
- data/app/pb_kits/playbook/pb_list/_list.tsx +4 -4
- data/app/pb_kits/playbook/pb_list/_list_item.tsx +3 -7
- data/app/pb_kits/playbook/pb_nav/docs/_collapsible_nav.html.erb +1 -1
- data/app/pb_kits/playbook/pb_nav/docs/_collapsible_nav.jsx +0 -1
- data/app/pb_kits/playbook/pb_nav/docs/_collapsible_nav.md +1 -3
- data/app/pb_kits/playbook/pb_nav/item.html.erb +1 -1
- data/app/pb_kits/playbook/pb_nav/item.rb +0 -1
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.md +4 -4
- data/app/pb_kits/playbook/pb_overlay/docs/example.yml +0 -4
- data/app/pb_kits/playbook/pb_selectable_list/_item.tsx +3 -7
- data/app/pb_kits/playbook/pb_selectable_list/_selectable_list.tsx +3 -3
- data/app/pb_kits/playbook/pb_table/table_header.html.erb +2 -16
- data/app/pb_kits/playbook/pb_timeline/_item.tsx +10 -11
- data/app/pb_kits/playbook/pb_timeline/_timeline.tsx +6 -8
- data/app/pb_kits/playbook/utilities/globalProps.ts +0 -1
- data/dist/menu.yml +2 -2
- data/dist/playbook-rails.js +7 -7
- data/lib/playbook/version.rb +2 -2
- metadata +5 -22
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta_sort.html.erb +0 -59
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta_sort.md +0 -6
- data/app/pb_kits/playbook/pb_date_time_stacked/docs/_date_time_stacked_default_swift.md +0 -33
- data/app/pb_kits/playbook/pb_date_time_stacked/docs/_date_time_stacked_props_swift.md +0 -18
- data/app/pb_kits/playbook/pb_draggable/context/types.ts +0 -26
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list.md +0 -7
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_error.html.erb +0 -9
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_error.jsx +0 -34
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/docs/_fixed_confirmation_toast_custom_icon.html.erb +0 -32
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/docs/_fixed_confirmation_toast_custom_icon.jsx +0 -48
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/fixed_confirmation_toast.test.js +0 -72
- data/app/pb_kits/playbook/pb_icon/icon_aliases.json +0 -39
- data/app/pb_kits/playbook/pb_icon/types.d.ts +0 -1
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.html.erb +0 -24
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.html.erb +0 -11
- data/app/pb_kits/playbook/pb_overlay/overlay.html.erb +0 -27
- data/app/pb_kits/playbook/pb_overlay/overlay.rb +0 -110
@@ -17,11 +17,10 @@ type DraggableItemProps = {
|
|
17
17
|
data?: { [key: string]: string };
|
18
18
|
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
|
19
19
|
id?: string;
|
20
|
-
dragId?: string;
|
21
20
|
};
|
22
21
|
|
23
22
|
const DraggableItem = (props: DraggableItemProps) => {
|
24
|
-
const { aria = {}, children, className, container, data = {}, htmlOptions = {}, id
|
23
|
+
const { aria = {}, children, className, container, data = {}, htmlOptions = {}, id } = props;
|
25
24
|
|
26
25
|
const { isDragging, handleDragStart, handleDragEnter, handleDragEnd } =
|
27
26
|
DraggableContext();
|
@@ -32,7 +31,7 @@ const DraggableItem = (props: DraggableItemProps) => {
|
|
32
31
|
|
33
32
|
const classes = classnames(
|
34
33
|
buildCss("pb_draggable_item"),
|
35
|
-
`${isDragging ===
|
34
|
+
`${isDragging === id ? "is_dragging" : ""}`,
|
36
35
|
globalProps(props),
|
37
36
|
className
|
38
37
|
);
|
@@ -45,10 +44,10 @@ const DraggableItem = (props: DraggableItemProps) => {
|
|
45
44
|
className={classes}
|
46
45
|
draggable
|
47
46
|
id={id}
|
48
|
-
key={
|
47
|
+
key={id}
|
49
48
|
onDragEnd={() => handleDragEnd()}
|
50
|
-
onDragEnter={() => handleDragEnter(
|
51
|
-
onDragStart={() => handleDragStart(
|
49
|
+
onDragEnter={() => handleDragEnter(id, container)}
|
50
|
+
onDragStart={() => handleDragStart(id, container)}
|
52
51
|
>
|
53
52
|
{children}
|
54
53
|
</div>
|
@@ -96,7 +96,6 @@
|
|
96
96
|
width: 100%;
|
97
97
|
}
|
98
98
|
}
|
99
|
-
|
100
99
|
.close {
|
101
100
|
display: none;
|
102
101
|
animation-name: fadeOut;
|
@@ -112,17 +111,6 @@
|
|
112
111
|
animation-timing-function: linear;
|
113
112
|
animation-fill-mode: forwards;
|
114
113
|
}
|
115
|
-
|
116
|
-
&.error {
|
117
|
-
[class*=pb_body_kit] {
|
118
|
-
margin-top: $space_xs / 2;
|
119
|
-
}
|
120
|
-
|
121
|
-
[class*="dropdown_trigger_wrapper"] {
|
122
|
-
border-color: $error;
|
123
|
-
box-shadow: none !important;
|
124
|
-
}
|
125
|
-
}
|
126
114
|
}
|
127
115
|
|
128
116
|
&.dark {
|
@@ -150,12 +138,6 @@
|
|
150
138
|
color: $white;
|
151
139
|
}
|
152
140
|
}
|
153
|
-
|
154
|
-
&.error {
|
155
|
-
[class*="dropdown_trigger_wrapper"] {
|
156
|
-
border-color: $error_dark;
|
157
|
-
}
|
158
|
-
}
|
159
141
|
}
|
160
142
|
.pb_dropdown_container {
|
161
143
|
background-color: $bg_dark !important;
|
@@ -4,7 +4,6 @@ import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from "../uti
|
|
4
4
|
import { globalProps } from "../utilities/globalProps";
|
5
5
|
import { GenericObject } from "../types";
|
6
6
|
|
7
|
-
import Body from '../pb_body/_body';
|
8
7
|
import Caption from "../pb_caption/_caption";
|
9
8
|
|
10
9
|
import DropdownContainer from "./subcomponents/DropdownContainer";
|
@@ -14,245 +13,236 @@ import DropdownTrigger from "./subcomponents/DropdownTrigger";
|
|
14
13
|
import useDropdown from "./hooks/useDropdown";
|
15
14
|
|
16
15
|
import {
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
separateChildComponents,
|
17
|
+
prepareSubcomponents,
|
18
|
+
handleClickOutside,
|
20
19
|
} from "./utilities";
|
21
20
|
|
22
21
|
type DropdownProps = {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
triggerRef?: any;
|
22
|
+
aria?: { [key: string]: string };
|
23
|
+
autocomplete?: boolean;
|
24
|
+
children?: React.ReactChild[] | React.ReactChild | React.ReactElement[];
|
25
|
+
className?: string;
|
26
|
+
dark?: boolean;
|
27
|
+
data?: { [key: string]: string };
|
28
|
+
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
|
29
|
+
id?: string;
|
30
|
+
isClosed?: boolean;
|
31
|
+
label?: string;
|
32
|
+
onSelect?: (arg: GenericObject) => null;
|
33
|
+
options: GenericObject;
|
34
|
+
triggerRef?: any;
|
37
35
|
};
|
38
36
|
|
39
37
|
const Dropdown = (props: DropdownProps) => {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
38
|
+
const {
|
39
|
+
aria = {},
|
40
|
+
autocomplete = false,
|
41
|
+
children,
|
42
|
+
className,
|
43
|
+
dark = false,
|
44
|
+
data = {},
|
45
|
+
htmlOptions = {},
|
46
|
+
id,
|
47
|
+
isClosed = true,
|
48
|
+
label,
|
49
|
+
onSelect,
|
50
|
+
options,
|
51
|
+
triggerRef
|
52
|
+
} = props;
|
53
|
+
|
54
|
+
const ariaProps = buildAriaProps(aria);
|
55
|
+
const dataProps = buildDataProps(data);
|
56
|
+
const htmlProps = buildHtmlProps(htmlOptions);
|
57
|
+
const classes = classnames(
|
58
|
+
buildCss("pb_dropdown"),
|
59
|
+
globalProps(props),
|
60
|
+
className
|
61
|
+
);
|
62
|
+
|
63
|
+
const [isDropDownClosed, setIsDropDownClosed, toggleDropdown] = useDropdown(isClosed);
|
64
|
+
|
65
|
+
const [filterItem, setFilterItem] = useState("");
|
66
|
+
const [selected, setSelected] = useState<GenericObject>({});
|
67
|
+
const [isInputFocused, setIsInputFocused] = useState(false);
|
68
|
+
const [hasTriggerSubcomponent, setHasTriggerSubcomponent] = useState(true);
|
69
|
+
const [hasContainerSubcomponent, setHasContainerSubcomponent] =
|
70
|
+
useState(true);
|
71
|
+
//state for keyboard events
|
72
|
+
const [focusedOptionIndex, setFocusedOptionIndex] = useState(-1);
|
73
|
+
|
74
|
+
const dropdownRef = useRef(null);
|
75
|
+
const inputRef = useRef(null);
|
76
|
+
const inputWrapperRef = useRef(null);
|
77
|
+
const dropdownContainerRef = useRef(null);
|
78
|
+
|
79
|
+
const { trigger, container, otherChildren } =
|
80
|
+
separateChildComponents(children);
|
81
|
+
|
82
|
+
useEffect(() => {
|
83
|
+
// Set the parent element of the trigger to relative to allow for absolute positioning of the dropdown
|
84
|
+
//Only needed for when useDropdown hook used with external trigger
|
85
|
+
if (triggerRef?.current) {
|
86
|
+
const parentElement = triggerRef.current.parentNode;
|
87
|
+
if (parentElement) {
|
88
|
+
parentElement.style.position = 'relative';
|
89
|
+
}
|
90
|
+
}
|
91
|
+
// Handle clicks outside the dropdown
|
92
|
+
const handleClick = handleClickOutside({
|
93
|
+
inputWrapperRef,
|
94
|
+
dropdownContainerRef,
|
95
|
+
setIsDropDownClosed,
|
96
|
+
setFocusedOptionIndex,
|
97
|
+
setIsInputFocused,
|
98
|
+
});
|
99
|
+
|
100
|
+
window.addEventListener("click", handleClick);
|
101
|
+
return () => {
|
102
|
+
window.removeEventListener("click", handleClick);
|
103
|
+
};
|
104
|
+
}, []);
|
105
|
+
|
106
|
+
useEffect(() => {
|
107
|
+
setHasTriggerSubcomponent(!!trigger);
|
108
|
+
setHasContainerSubcomponent(!!container);
|
109
|
+
}, []);
|
110
|
+
|
111
|
+
// dropdown to toggle with external control
|
112
|
+
useEffect(()=> {
|
113
|
+
setIsDropDownClosed(isClosed)
|
114
|
+
},[isClosed])
|
115
|
+
|
116
|
+
const filteredOptions = options?.filter((option: GenericObject) => {
|
117
|
+
const label = typeof option.label === 'string' ? option.label.toLowerCase() : option.label;
|
118
|
+
return String(label).toLowerCase().includes(filterItem.toLowerCase());
|
119
|
+
}
|
120
|
+
);
|
121
|
+
|
122
|
+
// For keyboard accessibility: Set focus within dropdown to selected item if it exists
|
123
|
+
useEffect(() => {
|
124
|
+
if (!isDropDownClosed) {
|
125
|
+
let newIndex = 0;
|
126
|
+
if (selected && selected?.label) {
|
127
|
+
const selectedIndex = filteredOptions.findIndex((option: GenericObject) => option.label === selected.label);
|
128
|
+
if (selectedIndex >= 0) {
|
129
|
+
newIndex = selectedIndex;
|
92
130
|
}
|
93
131
|
}
|
94
|
-
|
95
|
-
const handleClick = handleClickOutside({
|
96
|
-
inputWrapperRef,
|
97
|
-
dropdownContainerRef,
|
98
|
-
setIsDropDownClosed,
|
99
|
-
setFocusedOptionIndex,
|
100
|
-
setIsInputFocused,
|
101
|
-
});
|
102
|
-
|
103
|
-
window.addEventListener("click", handleClick);
|
104
|
-
return () => {
|
105
|
-
window.removeEventListener("click", handleClick);
|
106
|
-
};
|
107
|
-
}, []);
|
108
|
-
|
109
|
-
useEffect(() => {
|
110
|
-
setHasTriggerSubcomponent(!!trigger);
|
111
|
-
setHasContainerSubcomponent(!!container);
|
112
|
-
}, []);
|
113
|
-
|
114
|
-
// dropdown to toggle with external control
|
115
|
-
useEffect(() => {
|
116
|
-
setIsDropDownClosed(isClosed)
|
117
|
-
}, [isClosed])
|
118
|
-
|
119
|
-
const filteredOptions = options?.filter((option: GenericObject) => {
|
120
|
-
const label = typeof option.label === 'string' ? option.label.toLowerCase() : option.label;
|
121
|
-
return String(label).toLowerCase().includes(filterItem.toLowerCase());
|
132
|
+
setFocusedOptionIndex(newIndex);
|
122
133
|
}
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
134
|
+
}, [isDropDownClosed]);
|
135
|
+
|
136
|
+
|
137
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
138
|
+
setFilterItem(e.target.value);
|
139
|
+
setIsDropDownClosed(false);
|
140
|
+
};
|
141
|
+
|
142
|
+
const handleOptionClick = (selectedItem: GenericObject) => {
|
143
|
+
setSelected(selectedItem);
|
144
|
+
setFilterItem("");
|
145
|
+
setIsDropDownClosed(true);
|
146
|
+
onSelect && onSelect(selectedItem);
|
147
|
+
};
|
148
|
+
|
149
|
+
const handleWrapperClick = () => {
|
150
|
+
autocomplete && inputRef.current.focus();
|
151
|
+
toggleDropdown();
|
152
|
+
};
|
153
|
+
|
154
|
+
const handleBackspace = () => {
|
155
|
+
setSelected({});
|
156
|
+
onSelect && onSelect(null);
|
157
|
+
setFocusedOptionIndex(-1);
|
158
|
+
};
|
159
|
+
|
160
|
+
const componentsToRender = prepareSubcomponents({
|
161
|
+
children,
|
162
|
+
hasTriggerSubcomponent,
|
163
|
+
hasContainerSubcomponent,
|
164
|
+
trigger,
|
165
|
+
container,
|
166
|
+
otherChildren,
|
167
|
+
dark
|
168
|
+
});
|
169
|
+
|
170
|
+
|
171
|
+
return (
|
172
|
+
<div {...ariaProps}
|
173
|
+
{...dataProps}
|
174
|
+
{...htmlProps}
|
175
|
+
className={classes}
|
176
|
+
id={id}
|
177
|
+
style={triggerRef ? { position: "absolute"} : { position: "relative"}}
|
178
|
+
>
|
179
|
+
<DropdownContext.Provider
|
180
|
+
value={{
|
181
|
+
autocomplete,
|
182
|
+
dropdownContainerRef,
|
183
|
+
filteredOptions,
|
184
|
+
filterItem,
|
185
|
+
focusedOptionIndex,
|
186
|
+
handleBackspace,
|
187
|
+
handleChange,
|
188
|
+
handleOptionClick,
|
189
|
+
handleWrapperClick,
|
190
|
+
inputRef,
|
191
|
+
inputWrapperRef,
|
192
|
+
isDropDownClosed,
|
193
|
+
isInputFocused,
|
194
|
+
options,
|
195
|
+
selected,
|
196
|
+
setFocusedOptionIndex,
|
197
|
+
setIsDropDownClosed,
|
198
|
+
setIsInputFocused,
|
199
|
+
setSelected,
|
200
|
+
toggleDropdown,
|
201
|
+
triggerRef
|
202
|
+
}}
|
203
|
+
>
|
204
|
+
{label &&
|
205
|
+
<Caption
|
206
|
+
dark={dark}
|
207
|
+
marginBottom="xs"
|
208
|
+
text={label}
|
209
|
+
/>
|
136
210
|
}
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
};
|
144
|
-
|
145
|
-
const handleOptionClick = (selectedItem: GenericObject) => {
|
146
|
-
setSelected(selectedItem);
|
147
|
-
setFilterItem("");
|
148
|
-
setIsDropDownClosed(true);
|
149
|
-
onSelect && onSelect(selectedItem);
|
150
|
-
};
|
151
|
-
|
152
|
-
const handleWrapperClick = () => {
|
153
|
-
autocomplete && inputRef.current.focus();
|
154
|
-
toggleDropdown();
|
155
|
-
};
|
156
|
-
|
157
|
-
const handleBackspace = () => {
|
158
|
-
setSelected({});
|
159
|
-
onSelect && onSelect(null);
|
160
|
-
setFocusedOptionIndex(-1);
|
161
|
-
};
|
162
|
-
|
163
|
-
const componentsToRender = prepareSubcomponents({
|
164
|
-
children,
|
165
|
-
hasTriggerSubcomponent,
|
166
|
-
hasContainerSubcomponent,
|
167
|
-
trigger,
|
168
|
-
container,
|
169
|
-
otherChildren,
|
170
|
-
dark
|
171
|
-
});
|
172
|
-
|
173
|
-
|
174
|
-
return (
|
175
|
-
<div {...ariaProps}
|
176
|
-
{...dataProps}
|
177
|
-
{...htmlProps}
|
178
|
-
className={classes}
|
179
|
-
id={id}
|
180
|
-
style={triggerRef ? { position: "absolute" } : { position: "relative" }}
|
181
|
-
>
|
182
|
-
<DropdownContext.Provider
|
183
|
-
value={{
|
184
|
-
autocomplete,
|
185
|
-
dropdownContainerRef,
|
186
|
-
filteredOptions,
|
187
|
-
filterItem,
|
188
|
-
focusedOptionIndex,
|
189
|
-
handleBackspace,
|
190
|
-
handleChange,
|
191
|
-
handleOptionClick,
|
192
|
-
handleWrapperClick,
|
193
|
-
inputRef,
|
194
|
-
inputWrapperRef,
|
195
|
-
isDropDownClosed,
|
196
|
-
isInputFocused,
|
197
|
-
options,
|
198
|
-
selected,
|
199
|
-
setFocusedOptionIndex,
|
200
|
-
setIsDropDownClosed,
|
201
|
-
setIsInputFocused,
|
202
|
-
setSelected,
|
203
|
-
toggleDropdown,
|
204
|
-
triggerRef
|
205
|
-
}}
|
206
|
-
>
|
207
|
-
{label &&
|
208
|
-
<Caption
|
209
|
-
dark={dark}
|
210
|
-
marginBottom="xs"
|
211
|
-
text={label}
|
212
|
-
/>
|
213
|
-
}
|
214
|
-
<div className={`dropdown_wrapper ${error ? 'error' : ''}`}
|
215
|
-
onBlur={() => {
|
216
|
-
// Debounce to delay the execution to prevent jumpiness in Focus state
|
217
|
-
setTimeout(() => {
|
218
|
-
if (!dropdownRef.current.contains(document.activeElement)) {
|
219
|
-
setIsInputFocused(false);
|
220
|
-
}
|
221
|
-
}, 0);
|
222
|
-
}}
|
223
|
-
onFocus={() => setIsInputFocused(true)}
|
224
|
-
ref={dropdownRef}
|
225
|
-
>
|
226
|
-
{children ? (
|
227
|
-
<>
|
228
|
-
{componentsToRender.map((component, index) => (
|
229
|
-
<React.Fragment key={index}>{component}</React.Fragment>
|
230
|
-
))}
|
231
|
-
</>
|
232
|
-
) : (
|
233
|
-
<>
|
234
|
-
<DropdownTrigger />
|
235
|
-
<DropdownContainer>
|
236
|
-
{options &&
|
237
|
-
options?.map((option: GenericObject) => (
|
238
|
-
<Dropdown.Option key={option.id}
|
239
|
-
option={option}
|
240
|
-
/>
|
241
|
-
))}
|
242
|
-
</DropdownContainer>
|
243
|
-
</>
|
244
|
-
)}
|
245
|
-
|
246
|
-
{error &&
|
247
|
-
<Body
|
248
|
-
status="negative"
|
249
|
-
text={error}
|
250
|
-
/>
|
211
|
+
<div className="dropdown_wrapper"
|
212
|
+
onBlur={() => {
|
213
|
+
// Debounce to delay the execution to prevent jumpiness in Focus state
|
214
|
+
setTimeout(() => {
|
215
|
+
if (!dropdownRef.current.contains(document.activeElement)) {
|
216
|
+
setIsInputFocused(false);
|
251
217
|
}
|
252
|
-
|
253
|
-
|
218
|
+
}, 0);
|
219
|
+
}}
|
220
|
+
onFocus={() => setIsInputFocused(true)}
|
221
|
+
ref={dropdownRef}
|
222
|
+
>
|
223
|
+
{children ? (
|
224
|
+
<>
|
225
|
+
{componentsToRender.map((component, index) => (
|
226
|
+
<React.Fragment key={index}>{component}</React.Fragment>
|
227
|
+
))}
|
228
|
+
</>
|
229
|
+
) : (
|
230
|
+
<>
|
231
|
+
<DropdownTrigger />
|
232
|
+
<DropdownContainer>
|
233
|
+
{options &&
|
234
|
+
options?.map((option: GenericObject) => (
|
235
|
+
<Dropdown.Option key={option.id}
|
236
|
+
option={option}
|
237
|
+
/>
|
238
|
+
))}
|
239
|
+
</DropdownContainer>
|
240
|
+
</>
|
241
|
+
)}
|
254
242
|
</div>
|
255
|
-
|
243
|
+
</DropdownContext.Provider>
|
244
|
+
</div>
|
245
|
+
)
|
256
246
|
};
|
257
247
|
|
258
248
|
Dropdown.Option = DropdownOption;
|
@@ -7,7 +7,6 @@ examples:
|
|
7
7
|
- dropdown_with_custom_display_rails: Custom Display
|
8
8
|
- dropdown_with_custom_trigger_rails: Custom Trigger
|
9
9
|
- dropdown_with_custom_padding: Custom Option Padding
|
10
|
-
- dropdown_error: Dropdown with Error
|
11
10
|
|
12
11
|
react:
|
13
12
|
- dropdown_default: Default
|
@@ -17,7 +16,6 @@ examples:
|
|
17
16
|
- dropdown_with_custom_display: Custom Display
|
18
17
|
- dropdown_with_custom_trigger: Custom Trigger
|
19
18
|
- dropdown_with_custom_padding: Custom Option Padding
|
20
|
-
- dropdown_error: Dropdown with Error
|
21
19
|
# - dropdown_with_autocomplete: Autocomplete
|
22
20
|
# - dropdown_with_autocomplete_and_custom_display: Autocomplete with Custom Display
|
23
21
|
# - dropdown_with_external_control: useDropdown Hook
|
@@ -8,5 +8,4 @@ export { default as DropdownWithCustomPadding } from './_dropdown_with_custom_pa
|
|
8
8
|
export { default as DropdownWithLabel } from './_dropdown_with_label.jsx'
|
9
9
|
export { default as DropdownWithExternalControl } from './_dropdown_with_external_control.jsx'
|
10
10
|
export { default as DropdownWithHook } from './_dropdown_with_hook.jsx'
|
11
|
-
export { default as DropdownSubcomponentStructure } from './_dropdown_subcomponent_structure.jsx'
|
12
|
-
export { default as DropdownError } from './_dropdown_error.jsx'
|
11
|
+
export { default as DropdownSubcomponentStructure } from './_dropdown_subcomponent_structure.jsx'
|
@@ -7,22 +7,20 @@
|
|
7
7
|
<% if object.label.present? %>
|
8
8
|
<%= pb_rails("caption", props: {text: object.label, margin_bottom:"xs"}) %>
|
9
9
|
<% end %>
|
10
|
-
<div class="dropdown_wrapper
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
<%
|
19
|
-
|
20
|
-
<%= pb_rails("dropdown/dropdown_option", props: {option: option}) %>
|
21
|
-
<% end %>
|
10
|
+
<div class="dropdown_wrapper" style="position: relative">
|
11
|
+
<input type="hidden" name="<%= object.name %>" id="dropdown-selected-option" value=""/>
|
12
|
+
<% if content.present? %>
|
13
|
+
<%= content.presence %>
|
14
|
+
<% else %>
|
15
|
+
<%= pb_rails("dropdown/dropdown_trigger") %>
|
16
|
+
<%= pb_rails("dropdown/dropdown_container") do %>
|
17
|
+
<% if object.options.present? %>
|
18
|
+
<% object.options.each do |option| %>
|
19
|
+
<%= pb_rails("dropdown/dropdown_option", props: {option: option}) %>
|
22
20
|
<% end %>
|
23
21
|
<% end %>
|
24
|
-
|
25
|
-
<%= pb_rails("body", props: { status: "negative", text: object.error }) %>
|
26
22
|
<% end %>
|
23
|
+
<% end %>
|
27
24
|
</div>
|
28
25
|
<% end %>
|
26
|
+
|
@@ -7,7 +7,6 @@ module Playbook
|
|
7
7
|
default: []
|
8
8
|
prop :label, type: Playbook::Props::String
|
9
9
|
prop :name, type: Playbook::Props::String
|
10
|
-
prop :error, type: Playbook::Props::String
|
11
10
|
|
12
11
|
def data
|
13
12
|
Hash(prop(:data)).merge(pb_dropdown: true)
|
@@ -16,12 +15,6 @@ module Playbook
|
|
16
15
|
def classname
|
17
16
|
generate_classname("pb_dropdown")
|
18
17
|
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def error_class
|
23
|
-
error.present? ? " error" : ""
|
24
|
-
end
|
25
18
|
end
|
26
19
|
end
|
27
20
|
end
|
@@ -170,7 +170,7 @@ test('generated custom Trigger', () => {
|
|
170
170
|
options={options}
|
171
171
|
>
|
172
172
|
<Dropdown.Trigger>
|
173
|
-
<Icon icon="
|
173
|
+
<Icon icon="home" />
|
174
174
|
</Dropdown.Trigger>
|
175
175
|
{options.map((option) => (
|
176
176
|
<Dropdown.Option key={option.id}
|
@@ -182,7 +182,7 @@ test('generated custom Trigger', () => {
|
|
182
182
|
|
183
183
|
const kit = screen.getByTestId(testId)
|
184
184
|
const trigger = kit.querySelector('.pb_dropdown_trigger')
|
185
|
-
const customTrigger = trigger.querySelector('.fa-
|
185
|
+
const customTrigger = trigger.querySelector('.fa-home.pb_icon_kit.fa-fw')
|
186
186
|
expect(customTrigger).toBeInTheDocument()
|
187
187
|
})
|
188
188
|
|
@@ -204,19 +204,4 @@ test('selected option on click', () => {
|
|
204
204
|
const option = kit.querySelector('.pb_dropdown_option_list')
|
205
205
|
option.click()
|
206
206
|
expect(option).toHaveClass('pb_dropdown_option_selected')
|
207
|
-
})
|
208
|
-
|
209
|
-
test('show error message', () => {
|
210
|
-
const errorMessage = 'Please make a valid selection'
|
211
|
-
|
212
|
-
render (
|
213
|
-
<Dropdown
|
214
|
-
data={{ testid: testId }}
|
215
|
-
error={errorMessage}
|
216
|
-
options={options}
|
217
|
-
/>
|
218
|
-
)
|
219
|
-
|
220
|
-
const kit = screen.getByTestId(testId)
|
221
|
-
expect(kit).toHaveTextContent(errorMessage)
|
222
207
|
})
|