Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Commit ba2997f

Browse files
jesenkojquense
authored andcommitted
feat: use react-transition-group instead of react-overlay transitions (#61)
react-overlay ^0.8 removed transition components, and instead uses react-transition-group package. This commit introduces changes analogous to react-bootstrap/react-bootstrap#2676
1 parent 9dbc939 commit ba2997f

File tree

5 files changed

+65
-22
lines changed

5 files changed

+65
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ The main Modal Component.
8282
- `keyboard`: `Boolean(default true)` Modal is dismissible via the `esc` key
8383

8484
- `transition` `Boolean(default true)` Fade the entry and exit of the modal. You can also provide a
85-
Transition component from the `react-overlays` library to customize the animation more minutely.
85+
Transition component from the `react-transition-group` v2 library to customize the animation more minutely.
8686
- `attentionClass`: `String(default 'shake')` - an animation class added to the modal when a "static" backdrop is clicked, set to nothing if
8787
no animation is desired
8888
- `container`: `Node(default document.body)`, a DOM Node to append the modal too

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"dom-helpers": "^3.3.1",
7979
"prop-types": "^15.6.1",
8080
"prop-types-extra": "^1.1.0",
81-
"react-overlays": "^0.7.3"
81+
"react-overlays": "^0.8.0",
82+
"react-transition-group": "^2.0.0"
8283
}
8384
}

src/Fade.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
import React from 'react';
2-
import Transition from 'react-overlays/lib/Transition';
2+
import Transition, {
3+
ENTERED,
4+
ENTERING
5+
} from 'react-transition-group/Transition';
6+
import cn from 'classnames';
37

4-
class Fade extends React.Component {
8+
const fadeStyles = {
9+
[ENTERING]: 'in',
10+
[ENTERED]: 'in'
11+
};
512

6-
constructor(props, context){
13+
class Fade extends React.Component {
14+
constructor(props, context) {
715
super(props, context);
816
}
917

1018
render() {
19+
const { className, children, ...props } = this.props;
1120
return (
12-
<Transition
13-
{...this.props}
14-
className='fade'
15-
enteredClassName='in'
16-
enteringClassName='in'
17-
/>
21+
<Transition {...props}>
22+
{(status, innerProps) =>
23+
React.cloneElement(children, {
24+
...innerProps,
25+
className: cn(
26+
'fade',
27+
className,
28+
children.props.className,
29+
fadeStyles[status]
30+
)
31+
})
32+
}
33+
</Transition>
1834
);
1935
}
2036
}
2137

22-
export default Fade
38+
export default Fade;

src/Modal.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ let omit = (obj, keys) => Object.keys(obj).reduce((o, key) => {
2828
return o;
2929
}, {});
3030

31+
function DialogTransition(props) {
32+
return <Fade {...props} timeout={Modal.TRANSITION_DURATION} />;
33+
}
34+
function BackdropTransition(props) {
35+
return <Fade {...props} timeout={Modal.BACKDROP_TRANSITION_DURATION} />;
36+
}
3137

3238
class Modal extends React.Component {
3339

@@ -155,7 +161,7 @@ class Modal extends React.Component {
155161
let prefix = modalPrefix || Modal.getDefaultPrefix();
156162

157163
if (transition === true)
158-
transition = Fade;
164+
transition = DialogTransition;
159165

160166
let modal = (
161167
<div
@@ -193,19 +199,18 @@ class Modal extends React.Component {
193199
container={container}
194200
backdrop={props.backdrop}
195201
show={props.show}
202+
backdropStyle={backdrop}
203+
backdropClassName={prefix + '-backdrop'}
204+
containerClassName={prefix + '-open'}
205+
transition={transition || undefined}
206+
backdropTransition={transition ? BackdropTransition : undefined}
196207
onHide={this.props.onHide}
197208
onEnter={onEnter}
198209
onEntering={this.handleEntering}
199210
onEntered={onEntered}
200211
onExit={onExit}
201212
onExiting={this.handleExiting}
202213
onExited={onExited}
203-
backdropStyle={backdrop}
204-
backdropClassName={prefix + '-backdrop'}
205-
containerClassName={prefix + '-open'}
206-
transition={transition}
207-
dialogTransitionTimeout={Modal.TRANSITION_DURATION}
208-
backdropTransitionTimeout={Modal.BACKDROP_TRANSITION_DURATION}
209214
>
210215
{modal}
211216
</BaseModal>

yarn.lock

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7051,6 +7051,13 @@ prop-types@^15.6.1:
70517051
loose-envify "^1.3.1"
70527052
object-assign "^4.1.1"
70537053

7054+
prop-types@^15.6.2:
7055+
version "15.6.2"
7056+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
7057+
dependencies:
7058+
loose-envify "^1.3.1"
7059+
object-assign "^4.1.1"
7060+
70547061
protocols@^1.1.0, protocols@^1.4.0:
70557062
version "1.4.6"
70567063
resolved "https://registry.yarnpkg.com/protocols/-/protocols-1.4.6.tgz#f8bb263ea1b5fd7a7604d26b8be39bd77678bf8a"
@@ -7236,6 +7243,10 @@ react-is@^16.3.2, react-is@^16.4.1:
72367243
version "16.4.1"
72377244
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.4.1.tgz#d624c4650d2c65dbd52c72622bbf389435d9776e"
72387245

7246+
react-lifecycles-compat@^3.0.4:
7247+
version "3.0.4"
7248+
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
7249+
72397250
react-live@^1.7.1:
72407251
version "1.7.1"
72417252
resolved "https://registry.yarnpkg.com/react-live/-/react-live-1.7.1.tgz#a4fc7a4d23c2596cf7d4ed10f62dca9a02915e26"
@@ -7247,14 +7258,15 @@ react-live@^1.7.1:
72477258
prop-types "^15.5.8"
72487259
unescape "^0.2.0"
72497260

7250-
react-overlays@^0.7.3:
7251-
version "0.7.4"
7252-
resolved "https://registry.yarnpkg.com/react-overlays/-/react-overlays-0.7.4.tgz#ef2ec652c3444ab8aa014262b18f662068e56d5c"
7261+
react-overlays@^0.8.0:
7262+
version "0.8.3"
7263+
resolved "https://registry.yarnpkg.com/react-overlays/-/react-overlays-0.8.3.tgz#fad65eea5b24301cca192a169f5dddb0b20d3ac5"
72537264
dependencies:
72547265
classnames "^2.2.5"
72557266
dom-helpers "^3.2.1"
72567267
prop-types "^15.5.10"
72577268
prop-types-extra "^1.0.1"
7269+
react-transition-group "^2.2.0"
72587270
warning "^3.0.0"
72597271

72607272
react-reconciler@^0.7.0:
@@ -7282,6 +7294,15 @@ react-test-renderer@^16.4.1:
72827294
prop-types "^15.6.0"
72837295
react-is "^16.4.1"
72847296

7297+
react-transition-group@^2.0.0, react-transition-group@^2.2.0:
7298+
version "2.4.0"
7299+
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-2.4.0.tgz#1d9391fabfd82e016f26fabd1eec329dbd922b5a"
7300+
dependencies:
7301+
dom-helpers "^3.3.1"
7302+
loose-envify "^1.3.1"
7303+
prop-types "^15.6.2"
7304+
react-lifecycles-compat "^3.0.4"
7305+
72857306
react@^16.0.0:
72867307
version "16.0.0"
72877308
resolved "https://registry.yarnpkg.com/react/-/react-16.0.0.tgz#ce7df8f1941b036f02b2cca9dbd0cb1f0e855e2d"

0 commit comments

Comments
 (0)