@skyscanner/backpack-web 22.2.0 → 22.3.1
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.
|
@@ -33,7 +33,7 @@ export type CommonProps = {
|
|
|
33
33
|
disabled: boolean,
|
|
34
34
|
onClick: (event: SyntheticEvent<>) => mixed,
|
|
35
35
|
selected: boolean,
|
|
36
|
-
type: $
|
|
36
|
+
type: $Values<typeof CHIP_TYPES>,
|
|
37
37
|
className: ?string,
|
|
38
38
|
leadingAccessoryView: ?Node,
|
|
39
39
|
};
|
|
@@ -47,7 +47,7 @@ export const COMMON_PROP_TYPES = {
|
|
|
47
47
|
leadingAccessoryView: PropTypes.node,
|
|
48
48
|
selected: PropTypes.bool,
|
|
49
49
|
trailingAccessoryView: PropTypes.node,
|
|
50
|
-
type: PropTypes.oneOf(Object.
|
|
50
|
+
type: PropTypes.oneOf(Object.values(CHIP_TYPES)),
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
export const COMMON_DEFAULT_PROPS = {
|
|
@@ -26,30 +26,28 @@ class MyComponent extends Component {
|
|
|
26
26
|
this.state = {
|
|
27
27
|
isOpen: false,
|
|
28
28
|
};
|
|
29
|
-
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
onOpen = () => {
|
|
33
32
|
this.setState({
|
|
34
33
|
isOpen: true,
|
|
35
34
|
});
|
|
36
|
-
}
|
|
35
|
+
};
|
|
37
36
|
|
|
38
37
|
onClose = () => {
|
|
39
38
|
this.setState({
|
|
40
39
|
isOpen: false,
|
|
41
40
|
});
|
|
42
|
-
}
|
|
41
|
+
};
|
|
43
42
|
|
|
44
43
|
render() {
|
|
45
44
|
return (
|
|
46
45
|
<div>
|
|
47
46
|
<BpkButton onClick={this.onOpen}>Open portal</BpkButton>
|
|
48
|
-
<Portal
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
<div>I'm now appended to <BpkCode>document.body</BpkCode></div>
|
|
47
|
+
<Portal isOpen={this.state.isOpen} onClose={this.onClose}>
|
|
48
|
+
<div>
|
|
49
|
+
I'm now appended to <BpkCode>document.body</BpkCode>
|
|
50
|
+
</div>
|
|
53
51
|
</Portal>
|
|
54
52
|
</div>
|
|
55
53
|
);
|
|
@@ -57,19 +55,25 @@ class MyComponent extends Component {
|
|
|
57
55
|
}
|
|
58
56
|
```
|
|
59
57
|
|
|
58
|
+
**NOTE:** Events used to bubble up from the portal into the parent component. Due to the way React works, events do not
|
|
59
|
+
bubble up into the component in the DOM where the portal is rendered (i.e. render target), but instead they bubble up
|
|
60
|
+
into the parent component in the shadow DOM, that is the component where you added the `Portal` in your React code. To
|
|
61
|
+
avoid confusion and bugs caused by this behaviour, we have prevented mouse and keyboard events from bubbling up outside
|
|
62
|
+
the portal.
|
|
63
|
+
|
|
60
64
|
### Props
|
|
61
65
|
|
|
62
|
-
| Property
|
|
63
|
-
|
|
|
64
|
-
| children
|
|
65
|
-
| isOpen
|
|
66
|
-
| beforeClose
|
|
67
|
-
| onClose
|
|
68
|
-
| onOpen
|
|
69
|
-
| onRender
|
|
70
|
-
| renderTarget
|
|
71
|
-
| target
|
|
72
|
-
| closeOnEscPressed
|
|
66
|
+
| Property | PropType | Required | Default Value |
|
|
67
|
+
| ----------------- | ----------------------- | -------- | ------------- |
|
|
68
|
+
| children | node | true | - |
|
|
69
|
+
| isOpen | bool | true | - |
|
|
70
|
+
| beforeClose | func | false | null |
|
|
71
|
+
| onClose | func | false | noop |
|
|
72
|
+
| onOpen | func | false | noop |
|
|
73
|
+
| onRender | func | false | noop |
|
|
74
|
+
| renderTarget | func | false | null |
|
|
75
|
+
| target | oneOf([function, node]) | false | null |
|
|
76
|
+
| closeOnEscPressed | bool | false | true |
|
|
73
77
|
|
|
74
78
|
## `cssModules.js`
|
|
75
79
|
|
|
@@ -86,9 +90,7 @@ const getClassName = cssModules(STYLES);
|
|
|
86
90
|
|
|
87
91
|
const MyComponent = (props) => (
|
|
88
92
|
<div className={getClassName('MyComponent')}>
|
|
89
|
-
<div className={getClassName('MyComponent__inner')}>
|
|
90
|
-
{props.children}
|
|
91
|
-
</div>
|
|
93
|
+
<div className={getClassName('MyComponent__inner')}>{props.children}</div>
|
|
92
94
|
</div>
|
|
93
95
|
);
|
|
94
96
|
```
|
|
@@ -97,9 +99,7 @@ With CSS modules:
|
|
|
97
99
|
|
|
98
100
|
```html
|
|
99
101
|
<div class="_35WloynrPDta8fhSfoHEgE">
|
|
100
|
-
<div class="_1ghNYY7jOYzUneVCT4piQ9">
|
|
101
|
-
Some text.
|
|
102
|
-
</div>
|
|
102
|
+
<div class="_1ghNYY7jOYzUneVCT4piQ9">Some text.</div>
|
|
103
103
|
</div>
|
|
104
104
|
```
|
|
105
105
|
|
|
@@ -107,9 +107,7 @@ Without CSS modules:
|
|
|
107
107
|
|
|
108
108
|
```html
|
|
109
109
|
<div class="MyComponent">
|
|
110
|
-
<div class="MyComponent__inner">
|
|
111
|
-
Some text.
|
|
112
|
-
</div>
|
|
110
|
+
<div class="MyComponent__inner">Some text.</div>
|
|
113
111
|
</div>
|
|
114
112
|
```
|
|
115
113
|
|
|
@@ -123,8 +121,13 @@ import STYLES from './MyComponent.scss';
|
|
|
123
121
|
const getClassNames = cssModules(STYLES);
|
|
124
122
|
|
|
125
123
|
const MyComponent = (props) => (
|
|
126
|
-
<div
|
|
127
|
-
|
|
124
|
+
<div
|
|
125
|
+
className={getClassName(
|
|
126
|
+
'MyComponent',
|
|
127
|
+
props.disabled && 'MyComponent--disabled',
|
|
128
|
+
)}
|
|
129
|
+
>
|
|
130
|
+
{props.children}
|
|
128
131
|
</div>
|
|
129
132
|
);
|
|
130
133
|
```
|
|
@@ -263,7 +263,22 @@ class Portal extends Component {
|
|
|
263
263
|
return null;
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
|
|
266
|
+
const stopPropagationHandler = (e) => e.stopPropagation();
|
|
267
|
+
|
|
268
|
+
return createPortal(
|
|
269
|
+
<div
|
|
270
|
+
onClick={stopPropagationHandler}
|
|
271
|
+
onMouseDown={stopPropagationHandler}
|
|
272
|
+
onMouseUp={stopPropagationHandler}
|
|
273
|
+
onKeyDown={stopPropagationHandler}
|
|
274
|
+
onKeyUp={stopPropagationHandler}
|
|
275
|
+
tabIndex={-1}
|
|
276
|
+
role="none"
|
|
277
|
+
>
|
|
278
|
+
{children}
|
|
279
|
+
</div>,
|
|
280
|
+
portalElement,
|
|
281
|
+
);
|
|
267
282
|
}
|
|
268
283
|
}
|
|
269
284
|
|