playbook_ui 11.19.0.pre.typeahead1 → 11.20.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_body/_body.scss +10 -1
- data/app/pb_kits/playbook/pb_body/docs/_body_styled.html.erb +9 -0
- data/app/pb_kits/playbook/pb_body/docs/_body_styled.jsx +20 -0
- data/app/pb_kits/playbook/pb_body/docs/_body_styled.md +1 -0
- data/app/pb_kits/playbook/pb_body/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_body/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_checkbox/_checkbox.tsx +7 -7
- data/app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleContent.tsx +8 -8
- data/app/pb_kits/playbook/pb_dialog/_dialog.scss +69 -3
- data/app/pb_kits/playbook/pb_dialog/_dialog.tsx +1 -1
- data/app/pb_kits/playbook/pb_dialog/dialog.rb +1 -1
- data/app/pb_kits/playbook/pb_dialog/dialog.test.jsx +12 -0
- data/app/pb_kits/playbook/pb_file_upload/_file_upload.tsx +15 -7
- data/app/pb_kits/playbook/pb_file_upload/docs/_description.md +2 -3
- data/app/pb_kits/playbook/pb_file_upload/docs/_file_upload_custom_message.jsx +40 -0
- data/app/pb_kits/playbook/pb_file_upload/docs/example.yml +2 -2
- data/app/pb_kits/playbook/pb_file_upload/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_file_upload/fileupload.test.js +12 -0
- data/app/pb_kits/playbook/pb_list/_list.tsx +97 -0
- data/app/pb_kits/playbook/pb_list/{_list_item.jsx → _list_item.tsx} +4 -6
- data/app/pb_kits/playbook/pb_popover/_popover.tsx +239 -0
- data/app/pb_kits/playbook/pb_popover/{index.js → index.ts} +10 -6
- data/app/pb_kits/playbook/pb_popover/popover.test.js +222 -0
- data/app/pb_kits/playbook/pb_radio/_radio.tsx +4 -4
- data/app/pb_kits/playbook/pb_select/_select.scss +1 -1
- data/app/pb_kits/playbook/pb_selectable_card/{_selectable_card.jsx → _selectable_card.tsx} +47 -42
- data/app/pb_kits/playbook/pb_selectable_card/docs/_selectable_card_default.jsx +1 -2
- data/app/pb_kits/playbook/pb_selectable_card/docs/_selectable_card_single_select.jsx +1 -1
- data/app/pb_kits/playbook/pb_selectable_card/selectable_card.test.js +185 -0
- data/app/pb_kits/playbook/pb_selectable_icon/{_selectable_icon.jsx → _selectable_icon.tsx} +29 -32
- data/app/pb_kits/playbook/pb_selectable_icon/docs/_selectable_icon_default.jsx +1 -5
- data/app/pb_kits/playbook/pb_selectable_icon/docs/_selectable_icon_single_select.jsx +1 -4
- data/app/pb_kits/playbook/pb_selectable_icon/selectable_icon.test.js +148 -0
- data/lib/playbook/version.rb +2 -2
- metadata +17 -10
- data/app/pb_kits/playbook/pb_list/_list.jsx +0 -98
- data/app/pb_kits/playbook/pb_popover/_popover.jsx +0 -227
@@ -0,0 +1,239 @@
|
|
1
|
+
import React, { useEffect } from "react";
|
2
|
+
import ReactDOM from "react-dom";
|
3
|
+
|
4
|
+
import {
|
5
|
+
Popper,
|
6
|
+
Manager as PopperManager,
|
7
|
+
Modifier,
|
8
|
+
PopperProps,
|
9
|
+
Reference as PopperReference,
|
10
|
+
} from "react-popper";
|
11
|
+
|
12
|
+
import {
|
13
|
+
buildAriaProps,
|
14
|
+
buildCss,
|
15
|
+
buildDataProps,
|
16
|
+
noop,
|
17
|
+
} from "../utilities/props";
|
18
|
+
|
19
|
+
import classnames from "classnames";
|
20
|
+
import { globalProps, GlobalProps } from "../utilities/globalProps";
|
21
|
+
|
22
|
+
type PbPopoverProps = {
|
23
|
+
aria?: { [key: string]: string };
|
24
|
+
className?: string;
|
25
|
+
closeOnClick?: "outside" | "inside" | "any";
|
26
|
+
data?: object;
|
27
|
+
id?: string;
|
28
|
+
offset?: boolean;
|
29
|
+
reference: PopperReference & any;
|
30
|
+
show?: boolean;
|
31
|
+
shouldClosePopover?: (arg0: boolean) => boolean | boolean;
|
32
|
+
} & GlobalProps &
|
33
|
+
PopperProps<any>;
|
34
|
+
|
35
|
+
// Prop enabled default modifiers here
|
36
|
+
// https://popper.js.org/docs/v2/modifiers
|
37
|
+
|
38
|
+
const POPOVER_MODIFIERS = {
|
39
|
+
offset: {
|
40
|
+
//https://popper.js.org/docs/v2/modifiers/offset/
|
41
|
+
enabled: true,
|
42
|
+
name: "offset",
|
43
|
+
options: {
|
44
|
+
offset: [0, 20],
|
45
|
+
},
|
46
|
+
phase: "main",
|
47
|
+
},
|
48
|
+
};
|
49
|
+
|
50
|
+
const popoverModifiers = ({
|
51
|
+
modifiers,
|
52
|
+
offset,
|
53
|
+
}: {
|
54
|
+
modifiers: Modifier<any> & any;
|
55
|
+
offset: {};
|
56
|
+
}) => {
|
57
|
+
return offset ? modifiers.concat([POPOVER_MODIFIERS.offset]) : modifiers;
|
58
|
+
};
|
59
|
+
|
60
|
+
const Popover = (props: PbPopoverProps) => {
|
61
|
+
const {
|
62
|
+
aria = {},
|
63
|
+
className,
|
64
|
+
children,
|
65
|
+
data = {},
|
66
|
+
id,
|
67
|
+
modifiers,
|
68
|
+
offset,
|
69
|
+
placement,
|
70
|
+
referenceElement,
|
71
|
+
zIndex,
|
72
|
+
maxHeight,
|
73
|
+
maxWidth,
|
74
|
+
minHeight,
|
75
|
+
minWidth,
|
76
|
+
} = props;
|
77
|
+
|
78
|
+
const popoverSpacing =
|
79
|
+
globalProps(props).includes("dark") || !globalProps(props)
|
80
|
+
? "p_sm"
|
81
|
+
: globalProps(props);
|
82
|
+
const overflowHandling = maxHeight || maxWidth ? "overflow_handling" : "";
|
83
|
+
const zIndexStyle = zIndex ? { zIndex: zIndex } : {};
|
84
|
+
const widthHeightStyles = () => {
|
85
|
+
return Object.assign(
|
86
|
+
{},
|
87
|
+
maxHeight ? { maxHeight: maxHeight } : {},
|
88
|
+
maxWidth ? { maxWidth: maxWidth } : {},
|
89
|
+
minHeight ? { minHeight: minHeight } : {},
|
90
|
+
minWidth ? { minWidth: minWidth } : {}
|
91
|
+
);
|
92
|
+
};
|
93
|
+
const ariaProps = buildAriaProps(aria);
|
94
|
+
const dataProps = buildDataProps(data);
|
95
|
+
const classes = classnames(
|
96
|
+
buildCss("pb_popover_kit"),
|
97
|
+
globalProps(props),
|
98
|
+
className
|
99
|
+
);
|
100
|
+
|
101
|
+
return (
|
102
|
+
<Popper
|
103
|
+
modifiers={popoverModifiers({ modifiers, offset })}
|
104
|
+
placement={placement}
|
105
|
+
referenceElement={referenceElement}
|
106
|
+
>
|
107
|
+
{({ placement, ref, style }) => {
|
108
|
+
return (
|
109
|
+
<div
|
110
|
+
{...ariaProps}
|
111
|
+
{...dataProps}
|
112
|
+
className={classes}
|
113
|
+
data-placement={placement}
|
114
|
+
id={id}
|
115
|
+
ref={ref}
|
116
|
+
style={Object.assign({}, style, zIndexStyle)}
|
117
|
+
>
|
118
|
+
<div
|
119
|
+
className={classnames(`${buildCss("pb_popover_tooltip")} show`)}
|
120
|
+
>
|
121
|
+
<div
|
122
|
+
className={classnames(
|
123
|
+
"pb_popover_body",
|
124
|
+
popoverSpacing,
|
125
|
+
overflowHandling
|
126
|
+
)}
|
127
|
+
style={widthHeightStyles()}
|
128
|
+
>
|
129
|
+
{children}
|
130
|
+
</div>
|
131
|
+
</div>
|
132
|
+
</div>
|
133
|
+
);
|
134
|
+
}}
|
135
|
+
</Popper>
|
136
|
+
);
|
137
|
+
};
|
138
|
+
|
139
|
+
const PbReactPopover = (props: PbPopoverProps) => {
|
140
|
+
const {
|
141
|
+
className,
|
142
|
+
children,
|
143
|
+
modifiers = [],
|
144
|
+
offset = false,
|
145
|
+
placement = "left",
|
146
|
+
portal = "body",
|
147
|
+
reference,
|
148
|
+
referenceElement,
|
149
|
+
show = false,
|
150
|
+
usePortal = true,
|
151
|
+
zIndex,
|
152
|
+
maxHeight,
|
153
|
+
maxWidth,
|
154
|
+
minHeight,
|
155
|
+
minWidth,
|
156
|
+
} = props;
|
157
|
+
|
158
|
+
useEffect(() => {
|
159
|
+
const { closeOnClick, shouldClosePopover = noop } = props;
|
160
|
+
|
161
|
+
if (!closeOnClick) return;
|
162
|
+
|
163
|
+
document.body.addEventListener(
|
164
|
+
"click",
|
165
|
+
({ target }) => {
|
166
|
+
const targetIsPopover =
|
167
|
+
(target as HTMLElement).closest("[class^=pb_popover_tooltip]") !==
|
168
|
+
null;
|
169
|
+
const targetIsReference =
|
170
|
+
(target as HTMLElement).closest(".pb_popover_reference_wrapper") !==
|
171
|
+
null;
|
172
|
+
|
173
|
+
switch (closeOnClick) {
|
174
|
+
case "outside":
|
175
|
+
if (!targetIsPopover || targetIsReference) {
|
176
|
+
shouldClosePopover(true);
|
177
|
+
}
|
178
|
+
break;
|
179
|
+
case "inside":
|
180
|
+
if (targetIsPopover || targetIsReference) {
|
181
|
+
shouldClosePopover(true);
|
182
|
+
}
|
183
|
+
break;
|
184
|
+
case "any":
|
185
|
+
shouldClosePopover(true);
|
186
|
+
break;
|
187
|
+
}
|
188
|
+
},
|
189
|
+
{ capture: true }
|
190
|
+
);
|
191
|
+
}, []);
|
192
|
+
|
193
|
+
const popoverComponent = (
|
194
|
+
<Popover
|
195
|
+
className={className}
|
196
|
+
maxHeight={maxHeight}
|
197
|
+
maxWidth={maxWidth}
|
198
|
+
minHeight={minHeight}
|
199
|
+
minWidth={minWidth}
|
200
|
+
modifiers={modifiers}
|
201
|
+
offset={offset}
|
202
|
+
placement={placement}
|
203
|
+
referenceElement={referenceElement}
|
204
|
+
zIndex={zIndex}
|
205
|
+
{...props}
|
206
|
+
>
|
207
|
+
{children}
|
208
|
+
</Popover>
|
209
|
+
);
|
210
|
+
|
211
|
+
return (
|
212
|
+
<PopperManager>
|
213
|
+
<>
|
214
|
+
{reference && !referenceElement && (
|
215
|
+
<PopperReference>
|
216
|
+
{({ ref }) => (
|
217
|
+
<span className="pb_popover_reference_wrapper" ref={ref}>
|
218
|
+
<reference.type {...reference.props} />
|
219
|
+
</span>
|
220
|
+
)}
|
221
|
+
</PopperReference>
|
222
|
+
)}
|
223
|
+
{show &&
|
224
|
+
(usePortal ? (
|
225
|
+
<>
|
226
|
+
{ReactDOM.createPortal(
|
227
|
+
popoverComponent,
|
228
|
+
document.querySelector(portal)
|
229
|
+
)}
|
230
|
+
</>
|
231
|
+
) : (
|
232
|
+
{ popoverComponent }
|
233
|
+
))}
|
234
|
+
</>
|
235
|
+
</PopperManager>
|
236
|
+
);
|
237
|
+
};
|
238
|
+
|
239
|
+
export default PbReactPopover;
|
@@ -1,9 +1,13 @@
|
|
1
1
|
import PbEnhancedElement from '../pb_enhanced_element'
|
2
|
-
import { createPopper } from '@popperjs/core'
|
2
|
+
import { createPopper, Instance, Placement } from '@popperjs/core'
|
3
3
|
|
4
4
|
const POPOVER_OFFSET_Y = [0, 20]
|
5
5
|
|
6
6
|
export default class PbPopover extends PbEnhancedElement {
|
7
|
+
popper: Instance
|
8
|
+
_triggerElement: HTMLElement
|
9
|
+
_tooltip: HTMLElement
|
10
|
+
element: HTMLElement
|
7
11
|
static get selector() {
|
8
12
|
return '[data-pb-popover-kit]'
|
9
13
|
}
|
@@ -14,8 +18,8 @@ export default class PbPopover extends PbEnhancedElement {
|
|
14
18
|
|
15
19
|
connect() {
|
16
20
|
this.moveTooltip()
|
17
|
-
this.popper = createPopper(this.triggerElement, this.tooltip, {
|
18
|
-
placement: this.position,
|
21
|
+
this.popper = createPopper (this.triggerElement, this.tooltip, {
|
22
|
+
placement: this.position as Placement,
|
19
23
|
strategy: 'fixed',
|
20
24
|
modifiers: [
|
21
25
|
{
|
@@ -27,7 +31,7 @@ export default class PbPopover extends PbEnhancedElement {
|
|
27
31
|
],
|
28
32
|
})
|
29
33
|
|
30
|
-
this.triggerElement.addEventListener('click', (event) => {
|
34
|
+
this.triggerElement.addEventListener('click', (event: Event) => {
|
31
35
|
event.preventDefault()
|
32
36
|
event.stopPropagation()
|
33
37
|
|
@@ -43,8 +47,8 @@ export default class PbPopover extends PbEnhancedElement {
|
|
43
47
|
}
|
44
48
|
|
45
49
|
checkCloseTooltip() {
|
46
|
-
document.querySelector('body').addEventListener('click', ({ target }) => {
|
47
|
-
const isTooltipElement = target.closest(`#${this.tooltipId}`) !== null
|
50
|
+
document.querySelector('body').addEventListener('click', ({ target } ) => {
|
51
|
+
const isTooltipElement = (target as HTMLElement).closest(`#${this.tooltipId}`) !== null
|
48
52
|
|
49
53
|
switch (this.closeOnClick) {
|
50
54
|
case 'any':
|
@@ -0,0 +1,222 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { render, screen, fireEvent } from "../utilities/test-utils";
|
3
|
+
import { Button, PbReactPopover } from "..";
|
4
|
+
|
5
|
+
const testId = "popover-kit";
|
6
|
+
|
7
|
+
//Test default popover
|
8
|
+
const PopoverTest = () => {
|
9
|
+
const [mockState, setMockState] = React.useState(false)
|
10
|
+
const togglePopover = () => {
|
11
|
+
setMockState(!mockState)
|
12
|
+
}
|
13
|
+
|
14
|
+
const popoverReference = (
|
15
|
+
<Button onClick={togglePopover}
|
16
|
+
text="Click Me"
|
17
|
+
/>
|
18
|
+
);
|
19
|
+
return (
|
20
|
+
<PbReactPopover
|
21
|
+
offset
|
22
|
+
reference={popoverReference}
|
23
|
+
show={mockState}
|
24
|
+
>
|
25
|
+
{"Click Anywhere"}
|
26
|
+
</PbReactPopover>
|
27
|
+
)
|
28
|
+
};
|
29
|
+
//Test popover with z-index
|
30
|
+
const PopoverTestZIndex = () => {
|
31
|
+
const [mockState, setMockState] = React.useState(false)
|
32
|
+
const togglePopover = () => {
|
33
|
+
setMockState(!mockState)
|
34
|
+
}
|
35
|
+
|
36
|
+
const popoverReference = (
|
37
|
+
<Button onClick={togglePopover}
|
38
|
+
text="Click Me"
|
39
|
+
/>
|
40
|
+
);
|
41
|
+
return (
|
42
|
+
<PbReactPopover
|
43
|
+
offset
|
44
|
+
reference={popoverReference}
|
45
|
+
show={mockState}
|
46
|
+
zIndex={3}
|
47
|
+
>
|
48
|
+
{"Click Anywhere"}
|
49
|
+
</PbReactPopover>
|
50
|
+
)
|
51
|
+
};
|
52
|
+
|
53
|
+
//Test popover with max-height and max-width
|
54
|
+
const PopoverTestHeight = () => {
|
55
|
+
const [mockState, setMockState] = React.useState(false)
|
56
|
+
const togglePopover = () => {
|
57
|
+
setMockState(!mockState)
|
58
|
+
}
|
59
|
+
|
60
|
+
const popoverReference = (
|
61
|
+
<Button onClick={togglePopover}
|
62
|
+
text="Click Me"
|
63
|
+
/>
|
64
|
+
);
|
65
|
+
return (
|
66
|
+
<PbReactPopover
|
67
|
+
maxHeight="150px"
|
68
|
+
maxWidth="240px"
|
69
|
+
offset
|
70
|
+
reference={popoverReference}
|
71
|
+
show={mockState}
|
72
|
+
>
|
73
|
+
{"Click Anywhere"}
|
74
|
+
</PbReactPopover>
|
75
|
+
)
|
76
|
+
};
|
77
|
+
|
78
|
+
//Test Popover with click to close 'anywhere'
|
79
|
+
const PopoverTestClicktoClose = () => {
|
80
|
+
const [mockState, setMockState] = React.useState(false)
|
81
|
+
const togglePopover = () => {
|
82
|
+
setMockState(!mockState)
|
83
|
+
}
|
84
|
+
const handleShouldClosePopover = (shouldClosePopover) => {
|
85
|
+
setMockState(!shouldClosePopover)
|
86
|
+
}
|
87
|
+
|
88
|
+
const popoverReference = (
|
89
|
+
<Button onClick={togglePopover}
|
90
|
+
text="Click Me"
|
91
|
+
/>
|
92
|
+
);
|
93
|
+
return (
|
94
|
+
<PbReactPopover
|
95
|
+
closeOnClick="any"
|
96
|
+
offset
|
97
|
+
reference={popoverReference}
|
98
|
+
shouldClosePopover={handleShouldClosePopover}
|
99
|
+
show={mockState}
|
100
|
+
>
|
101
|
+
{"Click Anywhere"}
|
102
|
+
</PbReactPopover>
|
103
|
+
)
|
104
|
+
};
|
105
|
+
|
106
|
+
//Test Popover with click to close 'inside'
|
107
|
+
const PopoverTestClicktoClose2 = () => {
|
108
|
+
const [mockState, setMockState] = React.useState(false)
|
109
|
+
const togglePopover = () => {
|
110
|
+
setMockState(!mockState)
|
111
|
+
}
|
112
|
+
const handleShouldClosePopover = (shouldClosePopover) => {
|
113
|
+
setMockState(!shouldClosePopover)
|
114
|
+
}
|
115
|
+
|
116
|
+
const popoverReference = (
|
117
|
+
<Button onClick={togglePopover}
|
118
|
+
text="Click Me"
|
119
|
+
/>
|
120
|
+
);
|
121
|
+
return (
|
122
|
+
<PbReactPopover
|
123
|
+
closeOnClick="inside"
|
124
|
+
offset
|
125
|
+
reference={popoverReference}
|
126
|
+
shouldClosePopover={handleShouldClosePopover}
|
127
|
+
show={mockState}
|
128
|
+
>
|
129
|
+
{"Click Inside"}
|
130
|
+
</PbReactPopover>
|
131
|
+
)
|
132
|
+
};
|
133
|
+
|
134
|
+
//Test Popover with click to close 'outside'
|
135
|
+
const PopoverTestClicktoClose3 = () => {
|
136
|
+
const [mockState, setMockState] = React.useState(false)
|
137
|
+
const togglePopover = () => {
|
138
|
+
setMockState(!mockState)
|
139
|
+
}
|
140
|
+
const handleShouldClosePopover = (shouldClosePopover) => {
|
141
|
+
setMockState(!shouldClosePopover)
|
142
|
+
}
|
143
|
+
|
144
|
+
const popoverReference = (
|
145
|
+
<Button onClick={togglePopover}
|
146
|
+
text="Click Me"
|
147
|
+
/>
|
148
|
+
);
|
149
|
+
return (
|
150
|
+
<PbReactPopover
|
151
|
+
closeOnClick="outside"
|
152
|
+
offset
|
153
|
+
reference={popoverReference}
|
154
|
+
shouldClosePopover={handleShouldClosePopover}
|
155
|
+
show={mockState}
|
156
|
+
>
|
157
|
+
{"Click Outside"}
|
158
|
+
</PbReactPopover>
|
159
|
+
)
|
160
|
+
};
|
161
|
+
|
162
|
+
|
163
|
+
test("renders Popover", () => {
|
164
|
+
render(<PopoverTest data={{ testid: testId}}/>)
|
165
|
+
const btn = screen.getByText(/click me/i)
|
166
|
+
fireEvent.click(btn);
|
167
|
+
const kit = screen.getByText("Click Anywhere");
|
168
|
+
expect(kit).toBeInTheDocument();
|
169
|
+
});
|
170
|
+
|
171
|
+
test("renders Popover with z index", () => {
|
172
|
+
render(<PopoverTestZIndex data={{ testid: testId}}/>)
|
173
|
+
const btn = screen.getByText(/click me/i)
|
174
|
+
fireEvent.click(btn);
|
175
|
+
const kit = screen.getByText("Click Anywhere");
|
176
|
+
expect(kit).toHaveClass("pb_popover_body z_index_3");
|
177
|
+
});
|
178
|
+
|
179
|
+
test("renders Popover with max height and max width", () => {
|
180
|
+
render(<PopoverTestHeight data={{ testid: testId}}/>)
|
181
|
+
const btn = screen.getByText(/click me/i)
|
182
|
+
fireEvent.click(btn);
|
183
|
+
const kit = screen.getByText("Click Anywhere");
|
184
|
+
expect(kit).toHaveClass("pb_popover_body max_width_240px overflow_handling");
|
185
|
+
});
|
186
|
+
|
187
|
+
test("closes Popover on click anywhere", () => {
|
188
|
+
render(<PopoverTestClicktoClose data={{ testid: testId}}/>)
|
189
|
+
const btn = screen.getByText(/click me/i)
|
190
|
+
fireEvent.click(btn);
|
191
|
+
const kit = screen.getByText("Click Anywhere");
|
192
|
+
expect(kit).toBeInTheDocument();
|
193
|
+
fireEvent.click(kit);
|
194
|
+
|
195
|
+
expect(kit).not.toBeInTheDocument();
|
196
|
+
|
197
|
+
});
|
198
|
+
|
199
|
+
test("closes Popover on click inside", () => {
|
200
|
+
render(<PopoverTestClicktoClose2 data={{ testid: testId}}/>)
|
201
|
+
const btn = screen.getByText(/click me/i)
|
202
|
+
fireEvent.click(btn);
|
203
|
+
const kit = screen.getByText("Click Inside");
|
204
|
+
expect(kit).toBeInTheDocument();
|
205
|
+
fireEvent.click(kit);
|
206
|
+
|
207
|
+
expect(kit).not.toBeInTheDocument();
|
208
|
+
|
209
|
+
});
|
210
|
+
|
211
|
+
test("closes Popover on click outside", () => {
|
212
|
+
render(<PopoverTestClicktoClose3 data={{ testid: testId}}/>)
|
213
|
+
const btn = screen.getByText(/click me/i)
|
214
|
+
fireEvent.click(btn);
|
215
|
+
const kit = screen.getByText("Click Outside");
|
216
|
+
expect(kit).toBeInTheDocument();
|
217
|
+
fireEvent.click(kit);
|
218
|
+
expect(kit).toBeInTheDocument();
|
219
|
+
fireEvent.click(btn);
|
220
|
+
expect(kit).not.toBeInTheDocument();
|
221
|
+
|
222
|
+
});
|
@@ -10,16 +10,16 @@ type RadioProps = {
|
|
10
10
|
aria?: {[key: string]: string},
|
11
11
|
alignment?: string,
|
12
12
|
checked?: boolean,
|
13
|
-
children?:
|
13
|
+
children?: React.ReactChild[] | React.ReactChild,
|
14
14
|
className?: string,
|
15
15
|
dark?: boolean,
|
16
16
|
data?: {[key: string]: string},
|
17
17
|
error?: boolean,
|
18
18
|
id?: string,
|
19
19
|
label: string,
|
20
|
-
name
|
21
|
-
value
|
22
|
-
text
|
20
|
+
name?: string,
|
21
|
+
value?: string,
|
22
|
+
text?: string,
|
23
23
|
onChange: (event: React.FormEvent<HTMLInputElement> | null)=>void,
|
24
24
|
} & GlobalProps
|
25
25
|
|
@@ -1,10 +1,9 @@
|
|
1
1
|
/* @flow */
|
2
2
|
|
3
|
-
import React from 'react'
|
3
|
+
import React, {useRef} from 'react'
|
4
4
|
import classnames from 'classnames'
|
5
5
|
|
6
|
-
import
|
7
|
-
import { globalProps } from '../utilities/globalProps'
|
6
|
+
import { globalProps, GlobalProps } from '../utilities/globalProps'
|
8
7
|
import {
|
9
8
|
buildAriaProps,
|
10
9
|
buildCss,
|
@@ -19,13 +18,13 @@ import Flex from '../pb_flex/_flex'
|
|
19
18
|
import Radio from '../pb_radio/_radio'
|
20
19
|
|
21
20
|
type SelectableCardProps = {
|
22
|
-
aria?:
|
23
|
-
checked
|
24
|
-
children?:
|
21
|
+
aria?: { [key: string]: string },
|
22
|
+
checked?: boolean,
|
23
|
+
children?: React.ReactChild[] | React.ReactChild,
|
25
24
|
className?: string,
|
26
|
-
customIcon?: SVGElement,
|
25
|
+
customIcon?: {[key: string] :SVGElement},
|
27
26
|
dark?: boolean,
|
28
|
-
data:
|
27
|
+
data?: { [key: string]: string },
|
29
28
|
disabled?: boolean,
|
30
29
|
error?: boolean,
|
31
30
|
icon?: boolean,
|
@@ -33,32 +32,31 @@ type SelectableCardProps = {
|
|
33
32
|
inputId?: string,
|
34
33
|
multi?: boolean,
|
35
34
|
name?: string,
|
36
|
-
onChange:
|
35
|
+
onChange: (event: React.FormEvent<HTMLInputElement>) => void,
|
37
36
|
text?: string,
|
38
37
|
value?: string,
|
39
38
|
variant?: string,
|
40
|
-
}
|
39
|
+
} & GlobalProps
|
41
40
|
|
42
|
-
const SelectableCard = ({
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
}: SelectableCardProps) => {
|
41
|
+
const SelectableCard = (props: SelectableCardProps) => {
|
42
|
+
const {
|
43
|
+
aria = {},
|
44
|
+
checked = false,
|
45
|
+
className,
|
46
|
+
customIcon,
|
47
|
+
dark = false,
|
48
|
+
data = {},
|
49
|
+
disabled = false,
|
50
|
+
error = false,
|
51
|
+
icon = false,
|
52
|
+
inputId = null,
|
53
|
+
multi = true,
|
54
|
+
name,
|
55
|
+
onChange = noop,
|
56
|
+
text,
|
57
|
+
value,
|
58
|
+
variant = 'default',
|
59
|
+
} = props
|
62
60
|
const ariaProps = buildAriaProps(aria)
|
63
61
|
const dataProps = buildDataProps(data)
|
64
62
|
|
@@ -87,7 +85,7 @@ const SelectableCard = ({
|
|
87
85
|
}
|
88
86
|
}
|
89
87
|
|
90
|
-
const inputRef =
|
88
|
+
const inputRef = useRef(null)
|
91
89
|
// Delegate clicks to hidden input from visible one
|
92
90
|
const handleClick = () => {
|
93
91
|
inputRef.current.click()
|
@@ -96,7 +94,15 @@ const SelectableCard = ({
|
|
96
94
|
const inputType = multi ? 'checkbox' : 'radio'
|
97
95
|
const inputIdPresent = inputId !== null ? inputId : name
|
98
96
|
const Input = multi ? Checkbox : Radio
|
99
|
-
|
97
|
+
|
98
|
+
const filteredProps = {...props}
|
99
|
+
delete filteredProps?.inputId
|
100
|
+
delete filteredProps?.children
|
101
|
+
delete filteredProps?.icon
|
102
|
+
delete filteredProps?.error
|
103
|
+
delete filteredProps?.dark
|
104
|
+
delete filteredProps?.multi
|
105
|
+
const labelProps: GlobalProps = variant === 'displayInput' ? { ...filteredProps, padding: 'none' } : { ...filteredProps }
|
100
106
|
|
101
107
|
return (
|
102
108
|
<div
|
@@ -105,7 +111,6 @@ const SelectableCard = ({
|
|
105
111
|
className={classes}
|
106
112
|
>
|
107
113
|
<input
|
108
|
-
{...props}
|
109
114
|
checked={checked}
|
110
115
|
disabled={disabled}
|
111
116
|
id={inputIdPresent}
|
@@ -114,6 +119,7 @@ const SelectableCard = ({
|
|
114
119
|
ref={inputRef}
|
115
120
|
type={inputType}
|
116
121
|
value={value}
|
122
|
+
{...filteredProps}
|
117
123
|
/>
|
118
124
|
|
119
125
|
<label
|
@@ -121,8 +127,7 @@ const SelectableCard = ({
|
|
121
127
|
htmlFor={inputIdPresent}
|
122
128
|
>
|
123
129
|
<div className="buffer">
|
124
|
-
|
125
|
-
<When condition={variant === 'displayInput'}>
|
130
|
+
{variant === 'displayInput' ?
|
126
131
|
<Flex vertical="center">
|
127
132
|
<Flex
|
128
133
|
orientation="column"
|
@@ -130,7 +135,9 @@ const SelectableCard = ({
|
|
130
135
|
paddingRight="xs"
|
131
136
|
vertical="center"
|
132
137
|
>
|
133
|
-
<Input
|
138
|
+
<Input
|
139
|
+
dark={dark}
|
140
|
+
>
|
134
141
|
<input
|
135
142
|
checked={checked}
|
136
143
|
disabled={disabled}
|
@@ -146,14 +153,12 @@ const SelectableCard = ({
|
|
146
153
|
padding="sm"
|
147
154
|
status={error ? 'negative' : null}
|
148
155
|
>
|
149
|
-
{text ||
|
156
|
+
{text ||props.children}
|
150
157
|
</Card.Body>
|
151
158
|
</Flex>
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
</Otherwise>
|
156
|
-
</Choose>
|
159
|
+
:
|
160
|
+
text || props.children
|
161
|
+
}
|
157
162
|
{displayIcon()}
|
158
163
|
</div>
|
159
164
|
</label>
|