@instructure/ui-motion 8.33.1 → 8.33.2

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 CHANGED
@@ -3,6 +3,10 @@
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.33.2](https://github.com/instructure/instructure-ui/compare/v8.33.1...v8.33.2) (2023-01-25)
7
+
8
+ **Note:** Version bump only for package @instructure/ui-motion
9
+
6
10
  ## [8.33.1](https://github.com/instructure/instructure-ui/compare/v8.33.0...v8.33.1) (2023-01-06)
7
11
 
8
12
  **Note:** Version bump only for package @instructure/ui-motion
@@ -21,6 +21,7 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import React from 'react';
25
26
  import { getClassList, findDOMNode } from '@instructure/ui-dom-utils';
26
27
  import { ensureSingleChild, safeCloneElement } from '@instructure/ui-react-utils';
@@ -31,6 +32,7 @@ const STATES = {
31
32
  ENTERING: 1,
32
33
  ENTERED: 2
33
34
  };
35
+
34
36
  /**
35
37
  ---
36
38
  private: true
@@ -38,11 +40,9 @@ private: true
38
40
  Note: this is forked from https://github.com/react-bootstrap/react-overlays/blob/master/src/Transition.js
39
41
  so that it works with css modules. The internals are pretty different now, but it has roughly the same api.
40
42
  **/
41
-
42
43
  class BaseTransition extends React.Component {
43
44
  constructor() {
44
45
  var _this;
45
-
46
46
  super(...arguments);
47
47
  _this = this;
48
48
  this._timeouts = [];
@@ -51,75 +51,58 @@ class BaseTransition extends React.Component {
51
51
  transitioning: false
52
52
  };
53
53
  this.ref = null;
54
-
55
54
  this.handleRef = el => {
56
55
  const elementRef = this.props.elementRef;
57
56
  this.ref = el;
58
-
59
57
  if (typeof elementRef === 'function') {
60
58
  elementRef(el);
61
59
  }
62
60
  };
63
-
64
61
  this.startTransition = (transitionIn, transitionOnStart) => {
65
62
  const _this$props = this.props,
66
- transitionEnter = _this$props.transitionEnter,
67
- transitionExit = _this$props.transitionExit;
68
-
63
+ transitionEnter = _this$props.transitionEnter,
64
+ transitionExit = _this$props.transitionExit;
69
65
  if (transitionIn) {
70
66
  this.enter(transitionEnter && transitionOnStart ? STATES.EXITED : null);
71
67
  } else {
72
68
  this.exit(transitionExit && transitionOnStart ? STATES.ENTERED : null);
73
69
  }
74
70
  };
75
-
76
71
  this.transition = function (toState, fromState, transitionCallback) {
77
72
  let transitionDuration = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
78
73
  if (_this._unmounted) return;
79
74
  const onTransition = _this.props.onTransition;
80
75
  const classList = getClassList(_this.ref);
81
-
82
76
  const transitionClassName = _this.getTransitionClassName(toState);
83
-
84
77
  const prevTransitionClassName = _this.getTransitionClassName(fromState);
85
-
86
78
  const baseTransitionClassName = _this.props.transitionClassName;
87
-
88
79
  if (fromState && transitionDuration && _this.transitionEnabled(toState)) {
89
80
  baseTransitionClassName && classList.add(baseTransitionClassName);
90
81
  } else {
91
82
  baseTransitionClassName && classList.remove(baseTransitionClassName);
92
83
  }
93
-
94
84
  if (prevTransitionClassName) {
95
85
  classList.remove(prevTransitionClassName);
96
86
  }
97
-
98
87
  if (transitionClassName) {
99
88
  classList.add(transitionClassName);
100
89
  }
101
-
102
90
  if (toState && fromState && typeof onTransition === 'function') {
103
91
  onTransition(toState, fromState);
104
92
  }
105
-
106
93
  _this._timeouts.push(setTimeout(() => {
107
94
  if (_this._unmounted) return;
108
-
109
95
  if (typeof transitionCallback === 'function') {
110
96
  transitionCallback();
111
97
  }
112
98
  }, transitionDuration));
113
99
  };
114
-
115
100
  this.enter = initialState => {
116
101
  if (this.state.transitioning || this._unmounted) return;
117
102
  const props = this.props;
118
-
119
103
  if (typeof props.onEnter === 'function') {
120
104
  props.onEnter();
121
105
  }
122
-
123
106
  if (props.transitionEnter) {
124
107
  this.setState({
125
108
  transitioning: true
@@ -128,7 +111,6 @@ class BaseTransition extends React.Component {
128
111
  if (typeof props.onEntering === 'function') {
129
112
  props.onEntering();
130
113
  }
131
-
132
114
  this.transition(STATES.ENTERED, STATES.ENTERING, () => {
133
115
  this.setState({
134
116
  transitioning: false
@@ -139,7 +121,6 @@ class BaseTransition extends React.Component {
139
121
  });
140
122
  });
141
123
  };
142
-
143
124
  if (initialState) {
144
125
  this.transition(initialState, null, () => {
145
126
  this.transition(STATES.ENTERING, initialState, enter, props.enterDelay);
@@ -153,22 +134,18 @@ class BaseTransition extends React.Component {
153
134
  transitioning: false
154
135
  }, () => {
155
136
  this.transition(STATES.ENTERED, STATES.EXITED);
156
-
157
137
  if (typeof props.onEntered === 'function') {
158
138
  props.onEntered();
159
139
  }
160
140
  });
161
141
  }
162
142
  };
163
-
164
143
  this.exit = initialState => {
165
144
  if (this.state.transitioning) return;
166
145
  const props = this.props;
167
-
168
146
  if (typeof props.onExit === 'function') {
169
147
  props.onExit();
170
148
  }
171
-
172
149
  if (props.transitionExit) {
173
150
  this.setState({
174
151
  transitioning: true
@@ -177,7 +154,6 @@ class BaseTransition extends React.Component {
177
154
  if (typeof props.onExiting === 'function') {
178
155
  props.onExiting();
179
156
  }
180
-
181
157
  this.transition(STATES.EXITED, STATES.EXITING, () => {
182
158
  this.setState({
183
159
  transitioning: false
@@ -188,7 +164,6 @@ class BaseTransition extends React.Component {
188
164
  });
189
165
  });
190
166
  };
191
-
192
167
  if (initialState) {
193
168
  this.transition(initialState, null, () => {
194
169
  this.transition(STATES.EXITING, initialState, exit, props.exitDelay);
@@ -202,7 +177,6 @@ class BaseTransition extends React.Component {
202
177
  transitioning: false
203
178
  }, () => {
204
179
  this.transition(STATES.EXITED, STATES.ENTERED);
205
-
206
180
  if (typeof props.onExited === 'function') {
207
181
  props.onExited();
208
182
  }
@@ -210,43 +184,34 @@ class BaseTransition extends React.Component {
210
184
  }
211
185
  };
212
186
  }
213
-
214
187
  componentDidMount() {
215
188
  this.startTransition(this.props.in, this.props.transitionOnMount);
216
189
  this._unmounted = false;
217
190
  }
218
-
219
191
  getSnapshotBeforeUpdate(prevProps, prevState) {
220
192
  if (this.props.in !== prevProps.in && prevState.transitioning) {
221
193
  // direction changed before previous transition finished
222
194
  return true;
223
195
  }
224
-
225
196
  return null;
226
197
  }
227
-
228
198
  componentDidUpdate(prevProps, _prevState, cancelPrematurely) {
229
199
  if (cancelPrematurely) {
230
200
  this.clearTransition(prevProps.transitionClassName);
231
201
  }
232
-
233
202
  if (this.props.transitionClassName !== prevProps.transitionClassName) {
234
203
  this.clearTransition(prevProps.transitionClassName);
235
204
  }
236
-
237
205
  if (prevProps.in !== this.props.in) {
238
206
  this.startTransition(this.props.in, true);
239
207
  }
240
208
  }
241
-
242
209
  componentWillUnmount() {
243
210
  this._timeouts.forEach(timeout => {
244
211
  clearTimeout(timeout);
245
212
  });
246
-
247
213
  this._unmounted = true;
248
214
  }
249
-
250
215
  clearTransition(transitionClassName) {
251
216
  if (this._unmounted) return;
252
217
  this.setState({
@@ -256,7 +221,6 @@ class BaseTransition extends React.Component {
256
221
  const classList = getClassList(this.ref);
257
222
  Object.values(STATES).forEach(state => {
258
223
  const className = this.getTransitionClassName(state);
259
-
260
224
  if (className) {
261
225
  classList.remove(className);
262
226
  }
@@ -264,45 +228,34 @@ class BaseTransition extends React.Component {
264
228
  classList.remove(transitionClassName);
265
229
  });
266
230
  }
267
-
268
231
  transitionEnabled(toState) {
269
232
  const props = this.props;
270
-
271
233
  switch (toState) {
272
234
  case STATES.EXITED:
273
235
  case STATES.EXITING:
274
236
  return props.transitionExit;
275
-
276
237
  case STATES.ENTERED:
277
238
  case STATES.ENTERING:
278
239
  return props.transitionEnter;
279
-
280
240
  default:
281
241
  return false;
282
242
  }
283
243
  }
284
-
285
244
  getTransitionClassName(transitionState) {
286
245
  const props = this.props;
287
-
288
246
  switch (transitionState) {
289
247
  case STATES.EXITED:
290
248
  return props.exitedClassName;
291
-
292
249
  case STATES.ENTERING:
293
250
  return props.enteringClassName;
294
-
295
251
  case STATES.ENTERED:
296
252
  return props.enteredClassName;
297
-
298
253
  case STATES.EXITING:
299
254
  return props.exitingClassName;
300
-
301
255
  default:
302
256
  return void 0;
303
257
  }
304
258
  }
305
-
306
259
  renderChildren() {
307
260
  return this.props.children ? safeCloneElement(ensureSingleChild(this.props.children), {
308
261
  'aria-hidden': !this.props.in ? true : void 0,
@@ -312,7 +265,6 @@ class BaseTransition extends React.Component {
312
265
  }
313
266
  }) : null;
314
267
  }
315
-
316
268
  render() {
317
269
  if (!this.props.in && this.props.unmountOnExit && !this.state.transitioning) {
318
270
  return null;
@@ -320,9 +272,7 @@ class BaseTransition extends React.Component {
320
272
  return this.renderChildren();
321
273
  }
322
274
  }
323
-
324
275
  }
325
-
326
276
  BaseTransition.displayName = "BaseTransition";
327
277
  BaseTransition.propTypes = propTypes;
328
278
  BaseTransition.allowedProps = allowedProps;
@@ -21,6 +21,7 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import PropTypes from 'prop-types';
25
26
  const transitionCommonPropTypes = {
26
27
  in: PropTypes.bool,
@@ -38,7 +39,8 @@ const transitionCommonPropTypes = {
38
39
  children: PropTypes.node,
39
40
  elementRef: PropTypes.func
40
41
  };
41
- const propTypes = { ...transitionCommonPropTypes,
42
+ const propTypes = {
43
+ ...transitionCommonPropTypes,
42
44
  enterDelay: PropTypes.number,
43
45
  exitDelay: PropTypes.number,
44
46
  transitionClassName: PropTypes.string.isRequired,
@@ -22,6 +22,7 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
  import { locator } from '@instructure/ui-test-locator';
25
- import { Transition } from './index'; // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
25
+ import { Transition } from './index';
26
26
 
27
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
27
28
  export const TransitionLocator = locator(Transition.selector);
@@ -1,8 +1,6 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
2
  const _excluded = ["type", "children", "styles"];
3
-
4
3
  var _dec, _dec2, _class, _class2;
5
-
6
4
  /*
7
5
  * The MIT License (MIT)
8
6
  *
@@ -28,7 +26,6 @@ var _dec, _dec2, _class, _class2;
28
26
  */
29
27
 
30
28
  /** @jsx jsx */
31
-
32
29
  /** @jsxFrag React.Fragment */
33
30
  // test is breaking without importing React here
34
31
  // eslint-disable-next-line no-unused-vars
@@ -40,7 +37,6 @@ import generateStyle from './styles';
40
37
  import generateComponentTheme from './theme';
41
38
  import { BaseTransition } from './BaseTransition';
42
39
  import { allowedProps, propTypes } from './props';
43
-
44
40
  /**
45
41
  ---
46
42
  category: components/utilities
@@ -52,28 +48,23 @@ let Transition = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2
52
48
  constructor() {
53
49
  super(...arguments);
54
50
  this.ref = null;
55
-
56
51
  this.handleRef = el => {
57
52
  const elementRef = this.props.elementRef;
58
53
  this.ref = el;
59
-
60
54
  if (typeof elementRef === 'function') {
61
55
  elementRef(el);
62
56
  }
63
57
  };
64
-
65
58
  this.handleExited = () => {
66
59
  if (typeof this.props.onExited === 'function') {
67
60
  this.props.onExited(this.props.type);
68
61
  }
69
62
  };
70
-
71
63
  this.handleEntered = () => {
72
64
  if (typeof this.props.onEntered === 'function') {
73
65
  this.props.onEntered(this.props.type);
74
66
  }
75
67
  };
76
-
77
68
  this.renderTransitionHelper = () => {
78
69
  const styles = this.props.styles;
79
70
  return jsx(Global, {
@@ -81,26 +72,20 @@ let Transition = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2
81
72
  });
82
73
  };
83
74
  }
84
-
85
75
  componentDidMount() {
86
76
  var _this$props$makeStyle, _this$props;
87
-
88
77
  (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
89
78
  }
90
-
91
79
  componentDidUpdate() {
92
80
  var _this$props$makeStyle2, _this$props2;
93
-
94
81
  (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
95
82
  }
96
-
97
83
  render() {
98
84
  const _this$props3 = this.props,
99
- type = _this$props3.type,
100
- children = _this$props3.children,
101
- styles = _this$props3.styles,
102
- props = _objectWithoutProperties(_this$props3, _excluded);
103
-
85
+ type = _this$props3.type,
86
+ children = _this$props3.children,
87
+ styles = _this$props3.styles,
88
+ props = _objectWithoutProperties(_this$props3, _excluded);
104
89
  const duration = ms(styles.duration);
105
90
  return jsx(React.Fragment, null, this.renderTransitionHelper(), jsx(BaseTransition, Object.assign({}, props, {
106
91
  enterDelay: duration,
@@ -115,7 +100,6 @@ let Transition = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2
115
100
  elementRef: this.handleRef
116
101
  }), children));
117
102
  }
118
-
119
103
  }, _class2.displayName = "Transition", _class2.componentId = 'Transition', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
120
104
  type: 'fade',
121
105
  in: false,
@@ -21,6 +21,7 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import PropTypes from 'prop-types';
25
26
  import { transitionCommonPropTypes } from './BaseTransition/props';
26
27
  const transitionTypes = ['fade', 'scale', 'slide-down', 'slide-up', 'slide-left', 'slide-right'];
@@ -21,6 +21,7 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  const getClassNames = type => ({
25
26
  transitioning: `transition--${type}-transitioning`,
26
27
  exited: `transition--${type}-exited`,
@@ -28,6 +29,7 @@ const getClassNames = type => ({
28
29
  entered: `transition--${type}-entered`,
29
30
  entering: `transition--${type}-entering`
30
31
  });
32
+
31
33
  /**
32
34
  * ---
33
35
  * private: true
@@ -38,10 +40,9 @@ const getClassNames = type => ({
38
40
  * @param {Object} state the state of the component, the style is applied to
39
41
  * @return {Object} The final style object, which will be used in the component
40
42
  */
41
-
42
-
43
43
  const generateStyle = (componentTheme, props) => {
44
44
  const type = props.type;
45
+
45
46
  /**
46
47
  * After emotion migration the only way to keep
47
48
  * the old BaseTransition functionality with adding and removing
@@ -51,8 +52,8 @@ const generateStyle = (componentTheme, props) => {
51
52
  */
52
53
 
53
54
  const baseTransition = `opacity ${componentTheme.duration} ${componentTheme.timing}, transform ${componentTheme.duration} ${componentTheme.timing}`;
54
- /* Animation type: fade */
55
55
 
56
+ /* Animation type: fade */
56
57
  const fadeAnimation = {
57
58
  [`.transition--fade-transitioning`]: {
58
59
  transition: baseTransition
@@ -66,8 +67,8 @@ const generateStyle = (componentTheme, props) => {
66
67
  opacity: 1
67
68
  }
68
69
  };
69
- /* Animation type: scale */
70
70
 
71
+ /* Animation type: scale */
71
72
  const scaleAnimation = {
72
73
  [`.transition--scale-transitioning`]: {
73
74
  transition: baseTransition
@@ -83,6 +84,7 @@ const generateStyle = (componentTheme, props) => {
83
84
  opacity: 1
84
85
  }
85
86
  };
87
+
86
88
  /* Animation type: slide */
87
89
 
88
90
  /*
@@ -94,7 +96,6 @@ const generateStyle = (componentTheme, props) => {
94
96
  The base transition class enables/disables transitions
95
97
  from one state to another, so transitions should be set there.
96
98
  */
97
-
98
99
  const slideAnimation = {
99
100
  [`.transition--slide-right-transitioning,
100
101
  .transition--slide-left-transitioning,
@@ -139,12 +140,12 @@ const generateStyle = (componentTheme, props) => {
139
140
  return {
140
141
  duration: componentTheme.duration,
141
142
  classNames: getClassNames(type),
142
- globalStyles: { ...fadeAnimation,
143
+ globalStyles: {
144
+ ...fadeAnimation,
143
145
  ...scaleAnimation,
144
146
  ...slideAnimation
145
147
  }
146
148
  };
147
149
  };
148
-
149
150
  export { generateStyle, getClassNames };
150
151
  export default generateStyle;
@@ -33,8 +33,8 @@ const generateComponentTheme = theme => {
33
33
  duration: transitions === null || transitions === void 0 ? void 0 : transitions.duration,
34
34
  timing: transitions === null || transitions === void 0 ? void 0 : transitions.timing
35
35
  };
36
- return { ...componentVariables
36
+ return {
37
+ ...componentVariables
37
38
  };
38
39
  };
39
-
40
40
  export default generateComponentTheme;