@instructure/ui-motion 8.25.1-snapshot-10 → 8.25.1-snapshot-13
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.
- package/CHANGELOG.md +1 -1
- package/es/Transition/BaseTransition/index.js +176 -171
- package/es/Transition/index.js +42 -47
- package/lib/Transition/BaseTransition/index.js +176 -171
- package/lib/Transition/index.js +42 -47
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [8.25.1-snapshot-
|
|
6
|
+
## [8.25.1-snapshot-13](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-13) (2022-06-22)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-motion
|
|
9
9
|
|
|
@@ -40,84 +40,40 @@ private: true
|
|
|
40
40
|
**/
|
|
41
41
|
|
|
42
42
|
class BaseTransition extends React.Component {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
static states = STATES;
|
|
56
|
-
_timeouts = [];
|
|
57
|
-
_unmounted = false;
|
|
58
|
-
state = {
|
|
59
|
-
transitioning: false
|
|
60
|
-
};
|
|
61
|
-
ref = null;
|
|
62
|
-
handleRef = el => {
|
|
63
|
-
const elementRef = this.props.elementRef;
|
|
64
|
-
this.ref = el;
|
|
65
|
-
|
|
66
|
-
if (typeof elementRef === 'function') {
|
|
67
|
-
elementRef(el);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
componentDidMount() {
|
|
72
|
-
this.startTransition(this.props.in, this.props.transitionOnMount);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getSnapshotBeforeUpdate(prevProps, prevState) {
|
|
76
|
-
if (this.props.in !== prevProps.in && prevState.transitioning) {
|
|
77
|
-
// direction changed before previous transition finished
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
componentDidUpdate(prevProps, _prevState, cancelPrematurely) {
|
|
85
|
-
if (cancelPrematurely) {
|
|
86
|
-
this.clearTransition(prevProps.transitionClassName);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (this.props.transitionClassName !== prevProps.transitionClassName) {
|
|
90
|
-
this.clearTransition(prevProps.transitionClassName);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (prevProps.in !== this.props.in) {
|
|
94
|
-
this.startTransition(this.props.in, true);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
43
|
+
constructor() {
|
|
44
|
+
var _this;
|
|
45
|
+
|
|
46
|
+
super(...arguments);
|
|
47
|
+
_this = this;
|
|
48
|
+
this._timeouts = [];
|
|
49
|
+
this._unmounted = false;
|
|
50
|
+
this.state = {
|
|
51
|
+
transitioning: false
|
|
52
|
+
};
|
|
53
|
+
this.ref = null;
|
|
97
54
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
55
|
+
this.handleRef = el => {
|
|
56
|
+
const elementRef = this.props.elementRef;
|
|
57
|
+
this.ref = el;
|
|
102
58
|
|
|
103
|
-
|
|
104
|
-
|
|
59
|
+
if (typeof elementRef === 'function') {
|
|
60
|
+
elementRef(el);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
105
63
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
64
|
+
this.startTransition = (transitionIn, transitionOnStart) => {
|
|
65
|
+
const _this$props = this.props,
|
|
66
|
+
transitionEnter = _this$props.transitionEnter,
|
|
67
|
+
transitionExit = _this$props.transitionExit;
|
|
110
68
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
transition = (() => {
|
|
118
|
-
var _this = this;
|
|
69
|
+
if (transitionIn) {
|
|
70
|
+
this.enter(transitionEnter && transitionOnStart ? STATES.EXITED : null);
|
|
71
|
+
} else {
|
|
72
|
+
this.exit(transitionExit && transitionOnStart ? STATES.ENTERED : null);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
119
75
|
|
|
120
|
-
|
|
76
|
+
this.transition = function (toState, fromState, transitionCallback) {
|
|
121
77
|
let transitionDuration = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
|
|
122
78
|
if (_this._unmounted) return;
|
|
123
79
|
const onTransition = _this.props.onTransition;
|
|
@@ -155,7 +111,140 @@ class BaseTransition extends React.Component {
|
|
|
155
111
|
}
|
|
156
112
|
}, transitionDuration));
|
|
157
113
|
};
|
|
158
|
-
|
|
114
|
+
|
|
115
|
+
this.enter = initialState => {
|
|
116
|
+
if (this.state.transitioning || this._unmounted) return;
|
|
117
|
+
const props = this.props;
|
|
118
|
+
|
|
119
|
+
if (typeof props.onEnter === 'function') {
|
|
120
|
+
props.onEnter();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (props.transitionEnter) {
|
|
124
|
+
this.setState({
|
|
125
|
+
transitioning: true
|
|
126
|
+
}, () => {
|
|
127
|
+
const enter = () => {
|
|
128
|
+
if (typeof props.onEntering === 'function') {
|
|
129
|
+
props.onEntering();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this.transition(STATES.ENTERED, STATES.ENTERING, () => {
|
|
133
|
+
this.setState({
|
|
134
|
+
transitioning: false
|
|
135
|
+
}, () => {
|
|
136
|
+
if (typeof props.onEntered === 'function') {
|
|
137
|
+
props.onEntered();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
if (initialState) {
|
|
144
|
+
this.transition(initialState, null, () => {
|
|
145
|
+
this.transition(STATES.ENTERING, initialState, enter, props.enterDelay);
|
|
146
|
+
});
|
|
147
|
+
} else {
|
|
148
|
+
enter();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
this.setState({
|
|
153
|
+
transitioning: false
|
|
154
|
+
}, () => {
|
|
155
|
+
this.transition(STATES.ENTERED, STATES.EXITED);
|
|
156
|
+
|
|
157
|
+
if (typeof props.onEntered === 'function') {
|
|
158
|
+
props.onEntered();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
this.exit = initialState => {
|
|
165
|
+
if (this.state.transitioning) return;
|
|
166
|
+
const props = this.props;
|
|
167
|
+
|
|
168
|
+
if (typeof props.onExit === 'function') {
|
|
169
|
+
props.onExit();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (props.transitionExit) {
|
|
173
|
+
this.setState({
|
|
174
|
+
transitioning: true
|
|
175
|
+
}, () => {
|
|
176
|
+
const exit = () => {
|
|
177
|
+
if (typeof props.onExiting === 'function') {
|
|
178
|
+
props.onExiting();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.transition(STATES.EXITED, STATES.EXITING, () => {
|
|
182
|
+
this.setState({
|
|
183
|
+
transitioning: false
|
|
184
|
+
}, () => {
|
|
185
|
+
if (typeof props.onExited === 'function') {
|
|
186
|
+
props.onExited();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
if (initialState) {
|
|
193
|
+
this.transition(initialState, null, () => {
|
|
194
|
+
this.transition(STATES.EXITING, initialState, exit, props.exitDelay);
|
|
195
|
+
});
|
|
196
|
+
} else {
|
|
197
|
+
exit();
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
} else {
|
|
201
|
+
this.setState({
|
|
202
|
+
transitioning: false
|
|
203
|
+
}, () => {
|
|
204
|
+
this.transition(STATES.EXITED, STATES.ENTERED);
|
|
205
|
+
|
|
206
|
+
if (typeof props.onExited === 'function') {
|
|
207
|
+
props.onExited();
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
componentDidMount() {
|
|
215
|
+
this.startTransition(this.props.in, this.props.transitionOnMount);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
getSnapshotBeforeUpdate(prevProps, prevState) {
|
|
219
|
+
if (this.props.in !== prevProps.in && prevState.transitioning) {
|
|
220
|
+
// direction changed before previous transition finished
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
componentDidUpdate(prevProps, _prevState, cancelPrematurely) {
|
|
228
|
+
if (cancelPrematurely) {
|
|
229
|
+
this.clearTransition(prevProps.transitionClassName);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (this.props.transitionClassName !== prevProps.transitionClassName) {
|
|
233
|
+
this.clearTransition(prevProps.transitionClassName);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (prevProps.in !== this.props.in) {
|
|
237
|
+
this.startTransition(this.props.in, true);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
componentWillUnmount() {
|
|
242
|
+
this._timeouts.forEach(timeout => {
|
|
243
|
+
clearTimeout(timeout);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
this._unmounted = true;
|
|
247
|
+
}
|
|
159
248
|
|
|
160
249
|
clearTransition(transitionClassName) {
|
|
161
250
|
if (this._unmounted) return;
|
|
@@ -175,103 +264,6 @@ class BaseTransition extends React.Component {
|
|
|
175
264
|
});
|
|
176
265
|
}
|
|
177
266
|
|
|
178
|
-
enter = initialState => {
|
|
179
|
-
if (this.state.transitioning || this._unmounted) return;
|
|
180
|
-
const props = this.props;
|
|
181
|
-
|
|
182
|
-
if (typeof props.onEnter === 'function') {
|
|
183
|
-
props.onEnter();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (props.transitionEnter) {
|
|
187
|
-
this.setState({
|
|
188
|
-
transitioning: true
|
|
189
|
-
}, () => {
|
|
190
|
-
const enter = () => {
|
|
191
|
-
if (typeof props.onEntering === 'function') {
|
|
192
|
-
props.onEntering();
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
this.transition(STATES.ENTERED, STATES.ENTERING, () => {
|
|
196
|
-
this.setState({
|
|
197
|
-
transitioning: false
|
|
198
|
-
}, () => {
|
|
199
|
-
if (typeof props.onEntered === 'function') {
|
|
200
|
-
props.onEntered();
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
if (initialState) {
|
|
207
|
-
this.transition(initialState, null, () => {
|
|
208
|
-
this.transition(STATES.ENTERING, initialState, enter, props.enterDelay);
|
|
209
|
-
});
|
|
210
|
-
} else {
|
|
211
|
-
enter();
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
} else {
|
|
215
|
-
this.setState({
|
|
216
|
-
transitioning: false
|
|
217
|
-
}, () => {
|
|
218
|
-
this.transition(STATES.ENTERED, STATES.EXITED);
|
|
219
|
-
|
|
220
|
-
if (typeof props.onEntered === 'function') {
|
|
221
|
-
props.onEntered();
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
exit = initialState => {
|
|
227
|
-
if (this.state.transitioning) return;
|
|
228
|
-
const props = this.props;
|
|
229
|
-
|
|
230
|
-
if (typeof props.onExit === 'function') {
|
|
231
|
-
props.onExit();
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (props.transitionExit) {
|
|
235
|
-
this.setState({
|
|
236
|
-
transitioning: true
|
|
237
|
-
}, () => {
|
|
238
|
-
const exit = () => {
|
|
239
|
-
if (typeof props.onExiting === 'function') {
|
|
240
|
-
props.onExiting();
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
this.transition(STATES.EXITED, STATES.EXITING, () => {
|
|
244
|
-
this.setState({
|
|
245
|
-
transitioning: false
|
|
246
|
-
}, () => {
|
|
247
|
-
if (typeof props.onExited === 'function') {
|
|
248
|
-
props.onExited();
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
if (initialState) {
|
|
255
|
-
this.transition(initialState, null, () => {
|
|
256
|
-
this.transition(STATES.EXITING, initialState, exit, props.exitDelay);
|
|
257
|
-
});
|
|
258
|
-
} else {
|
|
259
|
-
exit();
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
} else {
|
|
263
|
-
this.setState({
|
|
264
|
-
transitioning: false
|
|
265
|
-
}, () => {
|
|
266
|
-
this.transition(STATES.EXITED, STATES.ENTERED);
|
|
267
|
-
|
|
268
|
-
if (typeof props.onExited === 'function') {
|
|
269
|
-
props.onExited();
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
|
|
275
267
|
transitionEnabled(toState) {
|
|
276
268
|
const props = this.props;
|
|
277
269
|
|
|
@@ -330,5 +322,18 @@ class BaseTransition extends React.Component {
|
|
|
330
322
|
|
|
331
323
|
}
|
|
332
324
|
|
|
325
|
+
BaseTransition.displayName = "BaseTransition";
|
|
326
|
+
BaseTransition.propTypes = propTypes;
|
|
327
|
+
BaseTransition.allowedProps = allowedProps;
|
|
328
|
+
BaseTransition.defaultProps = {
|
|
329
|
+
in: false,
|
|
330
|
+
unmountOnExit: false,
|
|
331
|
+
transitionOnMount: false,
|
|
332
|
+
transitionEnter: true,
|
|
333
|
+
transitionExit: true,
|
|
334
|
+
enterDelay: 300,
|
|
335
|
+
exitDelay: 300
|
|
336
|
+
};
|
|
337
|
+
BaseTransition.states = STATES;
|
|
333
338
|
export default BaseTransition;
|
|
334
339
|
export { BaseTransition };
|
package/es/Transition/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
const _excluded = ["type", "children", "styles"];
|
|
3
3
|
|
|
4
|
-
var _dec, _dec2, _class;
|
|
4
|
+
var _dec, _dec2, _class, _class2;
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* The MIT License (MIT)
|
|
@@ -48,29 +48,39 @@ category: components/utilities
|
|
|
48
48
|
@module Transition
|
|
49
49
|
@tsProps
|
|
50
50
|
**/
|
|
51
|
-
let Transition = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = class Transition extends Component {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
51
|
+
let Transition = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_class2 = class Transition extends Component {
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments);
|
|
54
|
+
this.ref = null;
|
|
55
|
+
|
|
56
|
+
this.handleRef = el => {
|
|
57
|
+
const elementRef = this.props.elementRef;
|
|
58
|
+
this.ref = el;
|
|
59
|
+
|
|
60
|
+
if (typeof elementRef === 'function') {
|
|
61
|
+
elementRef(el);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
this.handleExited = () => {
|
|
66
|
+
if (typeof this.props.onExited === 'function') {
|
|
67
|
+
this.props.onExited(this.props.type);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
this.handleEntered = () => {
|
|
72
|
+
if (typeof this.props.onEntered === 'function') {
|
|
73
|
+
this.props.onEntered(this.props.type);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
this.renderTransitionHelper = () => {
|
|
78
|
+
const styles = this.props.styles;
|
|
79
|
+
return jsx(Global, {
|
|
80
|
+
styles: styles === null || styles === void 0 ? void 0 : styles.globalStyles
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
}
|
|
74
84
|
|
|
75
85
|
componentDidMount() {
|
|
76
86
|
var _this$props$makeStyle, _this$props;
|
|
@@ -84,28 +94,6 @@ let Transition = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2
|
|
|
84
94
|
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
85
95
|
}
|
|
86
96
|
|
|
87
|
-
handleExited = () => {
|
|
88
|
-
if (typeof this.props.onExited === 'function') {
|
|
89
|
-
this.props.onExited(this.props.type);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
handleEntered = () => {
|
|
93
|
-
if (typeof this.props.onEntered === 'function') {
|
|
94
|
-
this.props.onEntered(this.props.type);
|
|
95
|
-
}
|
|
96
|
-
}; // Transition helper:
|
|
97
|
-
// After emotion migration the only way to keep
|
|
98
|
-
// the old BaseTransition functionality with adding and removing
|
|
99
|
-
// classes was to add the `Global` helper of `emotion`
|
|
100
|
-
// Todo: try to refactor or replace Transition/BaseTransition component in v9.0.0. so that it is not class based
|
|
101
|
-
|
|
102
|
-
renderTransitionHelper = () => {
|
|
103
|
-
const styles = this.props.styles;
|
|
104
|
-
return jsx(Global, {
|
|
105
|
-
styles: styles === null || styles === void 0 ? void 0 : styles.globalStyles
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
|
|
109
97
|
render() {
|
|
110
98
|
const _this$props3 = this.props,
|
|
111
99
|
type = _this$props3.type,
|
|
@@ -128,6 +116,13 @@ let Transition = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2
|
|
|
128
116
|
}), children));
|
|
129
117
|
}
|
|
130
118
|
|
|
131
|
-
}
|
|
119
|
+
}, _class2.displayName = "Transition", _class2.componentId = 'Transition', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
|
|
120
|
+
type: 'fade',
|
|
121
|
+
in: false,
|
|
122
|
+
unmountOnExit: false,
|
|
123
|
+
transitionOnMount: false,
|
|
124
|
+
transitionEnter: true,
|
|
125
|
+
transitionExit: true
|
|
126
|
+
}, _class2.states = BaseTransition.states, _class2)) || _class) || _class);
|
|
132
127
|
export default Transition;
|
|
133
128
|
export { Transition };
|
|
@@ -57,84 +57,40 @@ private: true
|
|
|
57
57
|
**/
|
|
58
58
|
|
|
59
59
|
class BaseTransition extends _react.default.Component {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
static states = STATES;
|
|
73
|
-
_timeouts = [];
|
|
74
|
-
_unmounted = false;
|
|
75
|
-
state = {
|
|
76
|
-
transitioning: false
|
|
77
|
-
};
|
|
78
|
-
ref = null;
|
|
79
|
-
handleRef = el => {
|
|
80
|
-
const elementRef = this.props.elementRef;
|
|
81
|
-
this.ref = el;
|
|
82
|
-
|
|
83
|
-
if (typeof elementRef === 'function') {
|
|
84
|
-
elementRef(el);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
componentDidMount() {
|
|
89
|
-
this.startTransition(this.props.in, this.props.transitionOnMount);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
getSnapshotBeforeUpdate(prevProps, prevState) {
|
|
93
|
-
if (this.props.in !== prevProps.in && prevState.transitioning) {
|
|
94
|
-
// direction changed before previous transition finished
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
componentDidUpdate(prevProps, _prevState, cancelPrematurely) {
|
|
102
|
-
if (cancelPrematurely) {
|
|
103
|
-
this.clearTransition(prevProps.transitionClassName);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (this.props.transitionClassName !== prevProps.transitionClassName) {
|
|
107
|
-
this.clearTransition(prevProps.transitionClassName);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (prevProps.in !== this.props.in) {
|
|
111
|
-
this.startTransition(this.props.in, true);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
60
|
+
constructor() {
|
|
61
|
+
var _this;
|
|
62
|
+
|
|
63
|
+
super(...arguments);
|
|
64
|
+
_this = this;
|
|
65
|
+
this._timeouts = [];
|
|
66
|
+
this._unmounted = false;
|
|
67
|
+
this.state = {
|
|
68
|
+
transitioning: false
|
|
69
|
+
};
|
|
70
|
+
this.ref = null;
|
|
114
71
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
72
|
+
this.handleRef = el => {
|
|
73
|
+
const elementRef = this.props.elementRef;
|
|
74
|
+
this.ref = el;
|
|
119
75
|
|
|
120
|
-
|
|
121
|
-
|
|
76
|
+
if (typeof elementRef === 'function') {
|
|
77
|
+
elementRef(el);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
122
80
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
81
|
+
this.startTransition = (transitionIn, transitionOnStart) => {
|
|
82
|
+
const _this$props = this.props,
|
|
83
|
+
transitionEnter = _this$props.transitionEnter,
|
|
84
|
+
transitionExit = _this$props.transitionExit;
|
|
127
85
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
transition = (() => {
|
|
135
|
-
var _this = this;
|
|
86
|
+
if (transitionIn) {
|
|
87
|
+
this.enter(transitionEnter && transitionOnStart ? STATES.EXITED : null);
|
|
88
|
+
} else {
|
|
89
|
+
this.exit(transitionExit && transitionOnStart ? STATES.ENTERED : null);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
136
92
|
|
|
137
|
-
|
|
93
|
+
this.transition = function (toState, fromState, transitionCallback) {
|
|
138
94
|
let transitionDuration = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
|
|
139
95
|
if (_this._unmounted) return;
|
|
140
96
|
const onTransition = _this.props.onTransition;
|
|
@@ -172,7 +128,140 @@ class BaseTransition extends _react.default.Component {
|
|
|
172
128
|
}
|
|
173
129
|
}, transitionDuration));
|
|
174
130
|
};
|
|
175
|
-
|
|
131
|
+
|
|
132
|
+
this.enter = initialState => {
|
|
133
|
+
if (this.state.transitioning || this._unmounted) return;
|
|
134
|
+
const props = this.props;
|
|
135
|
+
|
|
136
|
+
if (typeof props.onEnter === 'function') {
|
|
137
|
+
props.onEnter();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (props.transitionEnter) {
|
|
141
|
+
this.setState({
|
|
142
|
+
transitioning: true
|
|
143
|
+
}, () => {
|
|
144
|
+
const enter = () => {
|
|
145
|
+
if (typeof props.onEntering === 'function') {
|
|
146
|
+
props.onEntering();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this.transition(STATES.ENTERED, STATES.ENTERING, () => {
|
|
150
|
+
this.setState({
|
|
151
|
+
transitioning: false
|
|
152
|
+
}, () => {
|
|
153
|
+
if (typeof props.onEntered === 'function') {
|
|
154
|
+
props.onEntered();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
if (initialState) {
|
|
161
|
+
this.transition(initialState, null, () => {
|
|
162
|
+
this.transition(STATES.ENTERING, initialState, enter, props.enterDelay);
|
|
163
|
+
});
|
|
164
|
+
} else {
|
|
165
|
+
enter();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
} else {
|
|
169
|
+
this.setState({
|
|
170
|
+
transitioning: false
|
|
171
|
+
}, () => {
|
|
172
|
+
this.transition(STATES.ENTERED, STATES.EXITED);
|
|
173
|
+
|
|
174
|
+
if (typeof props.onEntered === 'function') {
|
|
175
|
+
props.onEntered();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
this.exit = initialState => {
|
|
182
|
+
if (this.state.transitioning) return;
|
|
183
|
+
const props = this.props;
|
|
184
|
+
|
|
185
|
+
if (typeof props.onExit === 'function') {
|
|
186
|
+
props.onExit();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (props.transitionExit) {
|
|
190
|
+
this.setState({
|
|
191
|
+
transitioning: true
|
|
192
|
+
}, () => {
|
|
193
|
+
const exit = () => {
|
|
194
|
+
if (typeof props.onExiting === 'function') {
|
|
195
|
+
props.onExiting();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this.transition(STATES.EXITED, STATES.EXITING, () => {
|
|
199
|
+
this.setState({
|
|
200
|
+
transitioning: false
|
|
201
|
+
}, () => {
|
|
202
|
+
if (typeof props.onExited === 'function') {
|
|
203
|
+
props.onExited();
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
if (initialState) {
|
|
210
|
+
this.transition(initialState, null, () => {
|
|
211
|
+
this.transition(STATES.EXITING, initialState, exit, props.exitDelay);
|
|
212
|
+
});
|
|
213
|
+
} else {
|
|
214
|
+
exit();
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
} else {
|
|
218
|
+
this.setState({
|
|
219
|
+
transitioning: false
|
|
220
|
+
}, () => {
|
|
221
|
+
this.transition(STATES.EXITED, STATES.ENTERED);
|
|
222
|
+
|
|
223
|
+
if (typeof props.onExited === 'function') {
|
|
224
|
+
props.onExited();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
componentDidMount() {
|
|
232
|
+
this.startTransition(this.props.in, this.props.transitionOnMount);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
getSnapshotBeforeUpdate(prevProps, prevState) {
|
|
236
|
+
if (this.props.in !== prevProps.in && prevState.transitioning) {
|
|
237
|
+
// direction changed before previous transition finished
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
componentDidUpdate(prevProps, _prevState, cancelPrematurely) {
|
|
245
|
+
if (cancelPrematurely) {
|
|
246
|
+
this.clearTransition(prevProps.transitionClassName);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (this.props.transitionClassName !== prevProps.transitionClassName) {
|
|
250
|
+
this.clearTransition(prevProps.transitionClassName);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (prevProps.in !== this.props.in) {
|
|
254
|
+
this.startTransition(this.props.in, true);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
componentWillUnmount() {
|
|
259
|
+
this._timeouts.forEach(timeout => {
|
|
260
|
+
clearTimeout(timeout);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
this._unmounted = true;
|
|
264
|
+
}
|
|
176
265
|
|
|
177
266
|
clearTransition(transitionClassName) {
|
|
178
267
|
if (this._unmounted) return;
|
|
@@ -192,103 +281,6 @@ class BaseTransition extends _react.default.Component {
|
|
|
192
281
|
});
|
|
193
282
|
}
|
|
194
283
|
|
|
195
|
-
enter = initialState => {
|
|
196
|
-
if (this.state.transitioning || this._unmounted) return;
|
|
197
|
-
const props = this.props;
|
|
198
|
-
|
|
199
|
-
if (typeof props.onEnter === 'function') {
|
|
200
|
-
props.onEnter();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (props.transitionEnter) {
|
|
204
|
-
this.setState({
|
|
205
|
-
transitioning: true
|
|
206
|
-
}, () => {
|
|
207
|
-
const enter = () => {
|
|
208
|
-
if (typeof props.onEntering === 'function') {
|
|
209
|
-
props.onEntering();
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
this.transition(STATES.ENTERED, STATES.ENTERING, () => {
|
|
213
|
-
this.setState({
|
|
214
|
-
transitioning: false
|
|
215
|
-
}, () => {
|
|
216
|
-
if (typeof props.onEntered === 'function') {
|
|
217
|
-
props.onEntered();
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
if (initialState) {
|
|
224
|
-
this.transition(initialState, null, () => {
|
|
225
|
-
this.transition(STATES.ENTERING, initialState, enter, props.enterDelay);
|
|
226
|
-
});
|
|
227
|
-
} else {
|
|
228
|
-
enter();
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
} else {
|
|
232
|
-
this.setState({
|
|
233
|
-
transitioning: false
|
|
234
|
-
}, () => {
|
|
235
|
-
this.transition(STATES.ENTERED, STATES.EXITED);
|
|
236
|
-
|
|
237
|
-
if (typeof props.onEntered === 'function') {
|
|
238
|
-
props.onEntered();
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
exit = initialState => {
|
|
244
|
-
if (this.state.transitioning) return;
|
|
245
|
-
const props = this.props;
|
|
246
|
-
|
|
247
|
-
if (typeof props.onExit === 'function') {
|
|
248
|
-
props.onExit();
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (props.transitionExit) {
|
|
252
|
-
this.setState({
|
|
253
|
-
transitioning: true
|
|
254
|
-
}, () => {
|
|
255
|
-
const exit = () => {
|
|
256
|
-
if (typeof props.onExiting === 'function') {
|
|
257
|
-
props.onExiting();
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
this.transition(STATES.EXITED, STATES.EXITING, () => {
|
|
261
|
-
this.setState({
|
|
262
|
-
transitioning: false
|
|
263
|
-
}, () => {
|
|
264
|
-
if (typeof props.onExited === 'function') {
|
|
265
|
-
props.onExited();
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
if (initialState) {
|
|
272
|
-
this.transition(initialState, null, () => {
|
|
273
|
-
this.transition(STATES.EXITING, initialState, exit, props.exitDelay);
|
|
274
|
-
});
|
|
275
|
-
} else {
|
|
276
|
-
exit();
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
} else {
|
|
280
|
-
this.setState({
|
|
281
|
-
transitioning: false
|
|
282
|
-
}, () => {
|
|
283
|
-
this.transition(STATES.EXITED, STATES.ENTERED);
|
|
284
|
-
|
|
285
|
-
if (typeof props.onExited === 'function') {
|
|
286
|
-
props.onExited();
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
|
|
292
284
|
transitionEnabled(toState) {
|
|
293
285
|
const props = this.props;
|
|
294
286
|
|
|
@@ -348,5 +340,18 @@ class BaseTransition extends _react.default.Component {
|
|
|
348
340
|
}
|
|
349
341
|
|
|
350
342
|
exports.BaseTransition = BaseTransition;
|
|
343
|
+
BaseTransition.displayName = "BaseTransition";
|
|
344
|
+
BaseTransition.propTypes = _props.propTypes;
|
|
345
|
+
BaseTransition.allowedProps = _props.allowedProps;
|
|
346
|
+
BaseTransition.defaultProps = {
|
|
347
|
+
in: false,
|
|
348
|
+
unmountOnExit: false,
|
|
349
|
+
transitionOnMount: false,
|
|
350
|
+
transitionEnter: true,
|
|
351
|
+
transitionExit: true,
|
|
352
|
+
enterDelay: 300,
|
|
353
|
+
exitDelay: 300
|
|
354
|
+
};
|
|
355
|
+
BaseTransition.states = STATES;
|
|
351
356
|
var _default = BaseTransition;
|
|
352
357
|
exports.default = _default;
|
package/lib/Transition/index.js
CHANGED
|
@@ -29,7 +29,7 @@ var _props = require("./props");
|
|
|
29
29
|
|
|
30
30
|
const _excluded = ["type", "children", "styles"];
|
|
31
31
|
|
|
32
|
-
var _dec, _dec2, _class;
|
|
32
|
+
var _dec, _dec2, _class, _class2;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
---
|
|
@@ -38,29 +38,39 @@ category: components/utilities
|
|
|
38
38
|
@module Transition
|
|
39
39
|
@tsProps
|
|
40
40
|
**/
|
|
41
|
-
let Transition = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = class Transition extends _react.Component {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
41
|
+
let Transition = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class Transition extends _react.Component {
|
|
42
|
+
constructor() {
|
|
43
|
+
super(...arguments);
|
|
44
|
+
this.ref = null;
|
|
45
|
+
|
|
46
|
+
this.handleRef = el => {
|
|
47
|
+
const elementRef = this.props.elementRef;
|
|
48
|
+
this.ref = el;
|
|
49
|
+
|
|
50
|
+
if (typeof elementRef === 'function') {
|
|
51
|
+
elementRef(el);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
this.handleExited = () => {
|
|
56
|
+
if (typeof this.props.onExited === 'function') {
|
|
57
|
+
this.props.onExited(this.props.type);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
this.handleEntered = () => {
|
|
62
|
+
if (typeof this.props.onEntered === 'function') {
|
|
63
|
+
this.props.onEntered(this.props.type);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
this.renderTransitionHelper = () => {
|
|
68
|
+
const styles = this.props.styles;
|
|
69
|
+
return (0, _emotion.jsx)(_emotion.Global, {
|
|
70
|
+
styles: styles === null || styles === void 0 ? void 0 : styles.globalStyles
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
}
|
|
64
74
|
|
|
65
75
|
componentDidMount() {
|
|
66
76
|
var _this$props$makeStyle, _this$props;
|
|
@@ -74,28 +84,6 @@ let Transition = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
|
|
|
74
84
|
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
75
85
|
}
|
|
76
86
|
|
|
77
|
-
handleExited = () => {
|
|
78
|
-
if (typeof this.props.onExited === 'function') {
|
|
79
|
-
this.props.onExited(this.props.type);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
handleEntered = () => {
|
|
83
|
-
if (typeof this.props.onEntered === 'function') {
|
|
84
|
-
this.props.onEntered(this.props.type);
|
|
85
|
-
}
|
|
86
|
-
}; // Transition helper:
|
|
87
|
-
// After emotion migration the only way to keep
|
|
88
|
-
// the old BaseTransition functionality with adding and removing
|
|
89
|
-
// classes was to add the `Global` helper of `emotion`
|
|
90
|
-
// Todo: try to refactor or replace Transition/BaseTransition component in v9.0.0. so that it is not class based
|
|
91
|
-
|
|
92
|
-
renderTransitionHelper = () => {
|
|
93
|
-
const styles = this.props.styles;
|
|
94
|
-
return (0, _emotion.jsx)(_emotion.Global, {
|
|
95
|
-
styles: styles === null || styles === void 0 ? void 0 : styles.globalStyles
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
|
|
99
87
|
render() {
|
|
100
88
|
const _this$props3 = this.props,
|
|
101
89
|
type = _this$props3.type,
|
|
@@ -117,7 +105,14 @@ let Transition = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
|
|
|
117
105
|
}), children));
|
|
118
106
|
}
|
|
119
107
|
|
|
120
|
-
}
|
|
108
|
+
}, _class2.displayName = "Transition", _class2.componentId = 'Transition', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
|
|
109
|
+
type: 'fade',
|
|
110
|
+
in: false,
|
|
111
|
+
unmountOnExit: false,
|
|
112
|
+
transitionOnMount: false,
|
|
113
|
+
transitionEnter: true,
|
|
114
|
+
transitionExit: true
|
|
115
|
+
}, _class2.states = _BaseTransition.BaseTransition.states, _class2)) || _class) || _class);
|
|
121
116
|
exports.Transition = Transition;
|
|
122
117
|
var _default = Transition;
|
|
123
118
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-motion",
|
|
3
|
-
"version": "8.25.1-snapshot-
|
|
3
|
+
"version": "8.25.1-snapshot-13",
|
|
4
4
|
"description": "A UI component library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-babel-preset": "8.25.1-snapshot-
|
|
27
|
-
"@instructure/ui-test-locator": "8.25.1-snapshot-
|
|
28
|
-
"@instructure/ui-test-utils": "8.25.1-snapshot-
|
|
29
|
-
"@instructure/ui-themes": "8.25.1-snapshot-
|
|
26
|
+
"@instructure/ui-babel-preset": "8.25.1-snapshot-13",
|
|
27
|
+
"@instructure/ui-test-locator": "8.25.1-snapshot-13",
|
|
28
|
+
"@instructure/ui-test-utils": "8.25.1-snapshot-13",
|
|
29
|
+
"@instructure/ui-themes": "8.25.1-snapshot-13"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.13.10",
|
|
33
|
-
"@instructure/emotion": "8.25.1-snapshot-
|
|
34
|
-
"@instructure/shared-types": "8.25.1-snapshot-
|
|
35
|
-
"@instructure/ui-dom-utils": "8.25.1-snapshot-
|
|
36
|
-
"@instructure/ui-react-utils": "8.25.1-snapshot-
|
|
37
|
-
"@instructure/ui-testable": "8.25.1-snapshot-
|
|
38
|
-
"@instructure/ui-utils": "8.25.1-snapshot-
|
|
33
|
+
"@instructure/emotion": "8.25.1-snapshot-13",
|
|
34
|
+
"@instructure/shared-types": "8.25.1-snapshot-13",
|
|
35
|
+
"@instructure/ui-dom-utils": "8.25.1-snapshot-13",
|
|
36
|
+
"@instructure/ui-react-utils": "8.25.1-snapshot-13",
|
|
37
|
+
"@instructure/ui-testable": "8.25.1-snapshot-13",
|
|
38
|
+
"@instructure/ui-utils": "8.25.1-snapshot-13",
|
|
39
39
|
"prop-types": "^15"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|