@instructure/ui-motion 8.11.2-snapshot.3 → 8.11.2-snapshot.45

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.
@@ -9,6 +9,8 @@ exports.transitionTypePropType = exports.allowedProps = exports.propTypes = void
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
+ var _props = require("./BaseTransition/props");
13
+
12
14
  /*
13
15
  * The MIT License (MIT)
14
16
  *
@@ -32,77 +34,14 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
32
34
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
35
  * SOFTWARE.
34
36
  */
35
- const transitionTypePropType = _propTypes.default.oneOf(['fade', 'scale', 'slide-down', 'slide-up', 'slide-left', 'slide-right']);
37
+ const transitionTypes = ['fade', 'scale', 'slide-down', 'slide-up', 'slide-left', 'slide-right'];
38
+
39
+ const transitionTypePropType = _propTypes.default.oneOf(transitionTypes);
36
40
 
37
41
  exports.transitionTypePropType = transitionTypePropType;
38
42
  const propTypes = {
39
43
  type: transitionTypePropType,
40
-
41
- /**
42
- * A single element to animate in and out
43
- */
44
- children: _propTypes.default.element,
45
-
46
- /**
47
- * Show the component; triggers the enter or exit animation
48
- */
49
- in: _propTypes.default.bool,
50
-
51
- /**
52
- * Unmount the component (remove it from the DOM) when it is not shown
53
- */
54
- unmountOnExit: _propTypes.default.bool,
55
-
56
- /**
57
- * Run the enter animation when the component mounts, if it is initially
58
- * shown
59
- */
60
- transitionOnMount: _propTypes.default.bool,
61
-
62
- /**
63
- * Run the enter animation
64
- */
65
- transitionEnter: _propTypes.default.bool,
66
-
67
- /**
68
- * Run the exit animation
69
- */
70
- transitionExit: _propTypes.default.bool,
71
-
72
- /**
73
- * Callback fired when transitioning to the next state
74
- */
75
- onTransition: _propTypes.default.func,
76
-
77
- /**
78
- * Callback fired before the "entering" classes are applied
79
- */
80
- onEnter: _propTypes.default.func,
81
-
82
- /**
83
- * Callback fired after the "entering" classes are applied
84
- */
85
- onEntering: _propTypes.default.func,
86
-
87
- /**
88
- * Callback fired after the "enter" classes are applied
89
- */
90
- onEntered: _propTypes.default.func,
91
-
92
- /**
93
- * Callback fired before the "exiting" classes are applied
94
- */
95
- onExit: _propTypes.default.func,
96
-
97
- /**
98
- * Callback fired after the "exiting" classes are applied
99
- */
100
- onExiting: _propTypes.default.func,
101
-
102
- /**
103
- * Callback fired after the "exited" classes are applied
104
- */
105
- onExited: _propTypes.default.func
44
+ ..._props.transitionCommonPropTypes
106
45
  };
107
46
  exports.propTypes = propTypes;
108
47
  const allowedProps = ['type', 'children', 'in', 'unmountOnExit', 'transitionOnMount', 'transitionEnter', 'transitionExit', 'onTransition', 'onEnter', 'onEntering', 'onEntered', 'onExit', 'onExiting', 'onExited'];
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.getClassNames = exports.generateStyle = void 0;
7
7
 
8
8
  /*
9
9
  * The MIT License (MIT)
@@ -28,7 +28,13 @@ exports.default = void 0;
28
28
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
29
  * SOFTWARE.
30
30
  */
31
-
31
+ const getClassNames = type => ({
32
+ transitioning: `transition--${type}-transitioning`,
33
+ exited: `transition--${type}-exited`,
34
+ exiting: `transition--${type}-exiting`,
35
+ entered: `transition--${type}-entered`,
36
+ entering: `transition--${type}-entering`
37
+ });
32
38
  /**
33
39
  * ---
34
40
  * private: true
@@ -39,6 +45,10 @@ exports.default = void 0;
39
45
  * @param {Object} state the state of the component, the style is applied to
40
46
  * @return {Object} The final style object, which will be used in the component
41
47
  */
48
+
49
+
50
+ exports.getClassNames = getClassNames;
51
+
42
52
  const generateStyle = (componentTheme, props) => {
43
53
  const type = props.type;
44
54
  /**
@@ -137,13 +147,7 @@ const generateStyle = (componentTheme, props) => {
137
147
  };
138
148
  return {
139
149
  duration: componentTheme.duration,
140
- classNames: type ? {
141
- transitioning: `transition--${type}-transitioning`,
142
- exited: `transition--${type}-exited`,
143
- exiting: `transition--${type}-exiting`,
144
- entered: `transition--${type}-entered`,
145
- entering: `transition--${type}-entering`
146
- } : {},
150
+ classNames: getClassNames(type),
147
151
  globalStyles: { ...fadeAnimation,
148
152
  ...scaleAnimation,
149
153
  ...slideAnimation
@@ -151,5 +155,6 @@ const generateStyle = (componentTheme, props) => {
151
155
  };
152
156
  };
153
157
 
158
+ exports.generateStyle = generateStyle;
154
159
  var _default = generateStyle;
155
160
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-motion",
3
- "version": "8.11.2-snapshot.3+6c8116bbe",
3
+ "version": "8.11.2-snapshot.45+e3249d228",
4
4
  "description": "A UI component library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "type": "commonjs",
@@ -24,19 +24,19 @@
24
24
  },
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "@instructure/ui-babel-preset": "8.11.2-snapshot.3+6c8116bbe",
28
- "@instructure/ui-test-locator": "8.11.2-snapshot.3+6c8116bbe",
29
- "@instructure/ui-test-utils": "8.11.2-snapshot.3+6c8116bbe",
30
- "@instructure/ui-themes": "8.11.2-snapshot.3+6c8116bbe"
27
+ "@instructure/ui-babel-preset": "8.11.2-snapshot.45+e3249d228",
28
+ "@instructure/ui-test-locator": "8.11.2-snapshot.45+e3249d228",
29
+ "@instructure/ui-test-utils": "8.11.2-snapshot.45+e3249d228",
30
+ "@instructure/ui-themes": "8.11.2-snapshot.45+e3249d228"
31
31
  },
32
32
  "dependencies": {
33
33
  "@babel/runtime": "^7.13.10",
34
- "@instructure/emotion": "8.11.2-snapshot.3+6c8116bbe",
35
- "@instructure/shared-types": "8.11.2-snapshot.3+6c8116bbe",
36
- "@instructure/ui-dom-utils": "8.11.2-snapshot.3+6c8116bbe",
37
- "@instructure/ui-react-utils": "8.11.2-snapshot.3+6c8116bbe",
38
- "@instructure/ui-testable": "8.11.2-snapshot.3+6c8116bbe",
39
- "@instructure/ui-utils": "8.11.2-snapshot.3+6c8116bbe",
34
+ "@instructure/emotion": "8.11.2-snapshot.45+e3249d228",
35
+ "@instructure/shared-types": "8.11.2-snapshot.45+e3249d228",
36
+ "@instructure/ui-dom-utils": "8.11.2-snapshot.45+e3249d228",
37
+ "@instructure/ui-react-utils": "8.11.2-snapshot.45+e3249d228",
38
+ "@instructure/ui-testable": "8.11.2-snapshot.45+e3249d228",
39
+ "@instructure/ui-utils": "8.11.2-snapshot.45+e3249d228",
40
40
  "prop-types": "^15"
41
41
  },
42
42
  "peerDependencies": {
@@ -46,5 +46,5 @@
46
46
  "access": "public"
47
47
  },
48
48
  "sideEffects": false,
49
- "gitHead": "6c8116bbe87878c77fca03bf26de932b40e21302"
49
+ "gitHead": "e3249d228eabac5bb98ff5d22e5881f2fe042606"
50
50
  }
@@ -22,7 +22,7 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- import React, { createRef } from 'react'
25
+ import React, { createRef, ReactElement } from 'react'
26
26
 
27
27
  import { getClassList } from '@instructure/ui-dom-utils'
28
28
  import {
@@ -31,9 +31,14 @@ import {
31
31
  } from '@instructure/ui-react-utils'
32
32
 
33
33
  import { allowedProps, propTypes } from './props'
34
- import type { BaseTransitionProps } from './props'
35
-
36
- const STATES = {
34
+ import type {
35
+ BaseTransitionProps,
36
+ BaseTransitionState,
37
+ BaseTransitionStateValue,
38
+ BaseTransitionStatesType
39
+ } from './props'
40
+
41
+ const STATES: Record<BaseTransitionStateValue, BaseTransitionStatesType> = {
37
42
  EXITED: -2,
38
43
  EXITING: -1,
39
44
  ENTERING: 1,
@@ -47,35 +52,26 @@ private: true
47
52
  Note: this is forked from https://github.com/react-bootstrap/react-overlays/blob/master/src/Transition.js
48
53
  so that it works with css modules. The internals are pretty different now, but it has roughly the same api.
49
54
  **/
50
- class BaseTransition extends React.Component<BaseTransitionProps> {
55
+ class BaseTransition extends React.Component<
56
+ BaseTransitionProps,
57
+ BaseTransitionState
58
+ > {
51
59
  static propTypes = propTypes
52
60
  static allowedProps = allowedProps
53
61
  static defaultProps = {
54
62
  in: false,
55
- component: 'div',
56
63
  unmountOnExit: false,
57
64
  transitionOnMount: false,
58
65
  transitionEnter: true,
59
66
  transitionExit: true,
60
-
61
67
  enterDelay: 300,
62
- exitDelay: 300,
63
-
64
- onEnter: function () {},
65
- onEntering: function () {},
66
- onEntered: function () {},
67
-
68
- onExit: function () {},
69
- onExiting: function () {},
70
- onExited: function () {},
71
- onTransition: function () {},
72
-
73
- children: null
68
+ exitDelay: 300
74
69
  }
75
70
 
76
71
  static states = STATES
77
72
 
78
- _timeouts = []
73
+ _timeouts: ReturnType<typeof setTimeout>[] = []
74
+ _unmounted = false
79
75
 
80
76
  state = {
81
77
  transitioning: false
@@ -85,8 +81,10 @@ class BaseTransition extends React.Component<BaseTransitionProps> {
85
81
  this.startTransition(this.props.in, this.props.transitionOnMount)
86
82
  }
87
83
 
88
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'prevProps' implicitly has an 'any' type... Remove this comment to see the full error message
89
- getSnapshotBeforeUpdate(prevProps, prevState) {
84
+ getSnapshotBeforeUpdate(
85
+ prevProps: BaseTransitionProps,
86
+ prevState: BaseTransitionState
87
+ ) {
90
88
  if (this.props.in !== prevProps.in && prevState.transitioning) {
91
89
  // direction changed before previous transition finished
92
90
  return true
@@ -94,8 +92,11 @@ class BaseTransition extends React.Component<BaseTransitionProps> {
94
92
  return null
95
93
  }
96
94
 
97
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'prevProps' implicitly has an 'any' type... Remove this comment to see the full error message
98
- componentDidUpdate(prevProps, prevState, cancelPrematurely) {
95
+ componentDidUpdate(
96
+ prevProps: BaseTransitionProps,
97
+ _prevState: BaseTransitionState,
98
+ cancelPrematurely: boolean
99
+ ) {
99
100
  if (cancelPrematurely) {
100
101
  this.clearTransition(prevProps.transitionClassName)
101
102
  }
@@ -113,12 +114,13 @@ class BaseTransition extends React.Component<BaseTransitionProps> {
113
114
  this._timeouts.forEach((timeout) => {
114
115
  clearTimeout(timeout)
115
116
  })
116
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_unmounted' does not exist on type 'Base... Remove this comment to see the full error message
117
117
  this._unmounted = true
118
118
  }
119
119
 
120
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'transitionIn' implicitly has an 'any' t... Remove this comment to see the full error message
121
- startTransition = (transitionIn, transitionOnStart) => {
120
+ startTransition = (
121
+ transitionIn: BaseTransitionProps['in'],
122
+ transitionOnStart: BaseTransitionProps['transitionOnMount']
123
+ ) => {
122
124
  const { transitionEnter, transitionExit } = this.props
123
125
  if (transitionIn) {
124
126
  this.enter(transitionEnter && transitionOnStart ? STATES.EXITED : null)
@@ -128,17 +130,15 @@ class BaseTransition extends React.Component<BaseTransitionProps> {
128
130
  }
129
131
 
130
132
  transition = (
131
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'toState' implicitly has an 'any' type.
132
- toState,
133
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'fromState' implicitly has an 'any' type... Remove this comment to see the full error message
134
- fromState,
135
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'transitionCallback' implicitly has an '... Remove this comment to see the full error message
136
- transitionCallback,
133
+ toState: BaseTransitionStatesType | null,
134
+ fromState: BaseTransitionStatesType | null,
135
+ transitionCallback?: () => void,
137
136
  transitionDuration = 0
138
137
  ) => {
139
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_unmounted' does not exist on type 'Base... Remove this comment to see the full error message
140
138
  if (this._unmounted) return
141
139
 
140
+ const { onTransition } = this.props
141
+
142
142
  const classList = getClassList(this)
143
143
 
144
144
  const transitionClassName = this.getTransitionClassName(toState)
@@ -159,15 +159,12 @@ class BaseTransition extends React.Component<BaseTransitionProps> {
159
159
  classList.add(transitionClassName)
160
160
  }
161
161
 
162
- if (toState && fromState) {
163
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'onTransition' does not exist on type 'Re... Remove this comment to see the full error message
164
- this.props.onTransition(toState, fromState)
162
+ if (toState && fromState && typeof onTransition === 'function') {
163
+ onTransition(toState, fromState)
165
164
  }
166
165
 
167
166
  this._timeouts.push(
168
- // @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Timeout' is not assignable to pa... Remove this comment to see the full error message
169
167
  setTimeout(() => {
170
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_unmounted' does not exist on type 'Base... Remove this comment to see the full error message
171
168
  if (this._unmounted) return
172
169
 
173
170
  if (typeof transitionCallback === 'function') {
@@ -177,44 +174,47 @@ class BaseTransition extends React.Component<BaseTransitionProps> {
177
174
  )
178
175
  }
179
176
 
180
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'transitionClassName' implicitly has an ... Remove this comment to see the full error message
181
- clearTransition(transitionClassName) {
182
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_unmounted' does not exist on type 'Base... Remove this comment to see the full error message
177
+ clearTransition(transitionClassName: string) {
183
178
  if (this._unmounted) return
184
179
 
185
180
  this.setState({ transitioning: false }, () => {
186
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_unmounted' does not exist on type 'Base... Remove this comment to see the full error message
187
181
  if (this._unmounted) return
188
182
 
189
183
  const classList = getClassList(this)
190
184
 
191
- Object.keys(STATES).forEach((state) => {
192
- // @ts-expect-error FIXME: type
193
- classList.remove(this.getTransitionClassName(state))
194
- })
185
+ ;(Object.values(STATES) as BaseTransitionStatesType[]).forEach(
186
+ (state) => {
187
+ const className = this.getTransitionClassName(state)
188
+ if (className) {
189
+ classList.remove(className)
190
+ }
191
+ }
192
+ )
195
193
 
196
194
  classList.remove(transitionClassName)
197
195
  })
198
196
  }
199
197
 
200
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'initialState' implicitly has an 'any' t... Remove this comment to see the full error message
201
- enter = (initialState) => {
202
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_unmounted' does not exist on type 'Base... Remove this comment to see the full error message
198
+ enter = (initialState: BaseTransitionStatesType | null) => {
203
199
  if (this.state.transitioning || this._unmounted) return
204
200
 
205
201
  const { props } = this
206
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'onEnter' does not exist on type 'Readonl... Remove this comment to see the full error message
207
- props.onEnter()
202
+
203
+ if (typeof props.onEnter === 'function') {
204
+ props.onEnter()
205
+ }
208
206
 
209
207
  if (props.transitionEnter) {
210
208
  this.setState({ transitioning: true }, () => {
211
209
  const enter = () => {
212
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'onEntering' does not exist on type 'Read... Remove this comment to see the full error message
213
- props.onEntering()
210
+ if (typeof props.onEntering === 'function') {
211
+ props.onEntering()
212
+ }
214
213
  this.transition(STATES.ENTERED, STATES.ENTERING, () => {
215
214
  this.setState({ transitioning: false }, () => {
216
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'onEntered' does not exist on type 'Reado... Remove this comment to see the full error message
217
- props.onEntered()
215
+ if (typeof props.onEntered === 'function') {
216
+ props.onEntered()
217
+ }
218
218
  })
219
219
  })
220
220
  }
@@ -233,31 +233,34 @@ class BaseTransition extends React.Component<BaseTransitionProps> {
233
233
  })
234
234
  } else {
235
235
  this.setState({ transitioning: false }, () => {
236
- // @ts-expect-error ts-migrate(2554) FIXME: Expected 3-4 arguments, but got 2.
237
236
  this.transition(STATES.ENTERED, STATES.EXITED)
238
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'onEntered' does not exist on type 'Reado... Remove this comment to see the full error message
239
- props.onEntered()
237
+ if (typeof props.onEntered === 'function') {
238
+ props.onEntered()
239
+ }
240
240
  })
241
241
  }
242
242
  }
243
243
 
244
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'initialState' implicitly has an 'any' t... Remove this comment to see the full error message
245
- exit = (initialState) => {
244
+ exit = (initialState: BaseTransitionStatesType | null) => {
246
245
  if (this.state.transitioning) return
247
246
 
248
247
  const { props } = this
249
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'onExit' does not exist on type 'Readonly... Remove this comment to see the full error message
250
- props.onExit()
248
+
249
+ if (typeof props.onExit === 'function') {
250
+ props.onExit()
251
+ }
251
252
 
252
253
  if (props.transitionExit) {
253
254
  this.setState({ transitioning: true }, () => {
254
255
  const exit = () => {
255
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'onExiting' does not exist on type 'Reado... Remove this comment to see the full error message
256
- props.onExiting()
256
+ if (typeof props.onExiting === 'function') {
257
+ props.onExiting()
258
+ }
257
259
  this.transition(STATES.EXITED, STATES.EXITING, () => {
258
260
  this.setState({ transitioning: false }, () => {
259
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'onExited' does not exist on type 'Readon... Remove this comment to see the full error message
260
- props.onExited()
261
+ if (typeof props.onExited === 'function') {
262
+ props.onExited()
263
+ }
261
264
  })
262
265
  })
263
266
  }
@@ -271,16 +274,15 @@ class BaseTransition extends React.Component<BaseTransitionProps> {
271
274
  })
272
275
  } else {
273
276
  this.setState({ transitioning: false }, () => {
274
- // @ts-expect-error ts-migrate(2554) FIXME: Expected 3-4 arguments, but got 2.
275
277
  this.transition(STATES.EXITED, STATES.ENTERED)
276
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'onExited' does not exist on type 'Readon... Remove this comment to see the full error message
277
- props.onExited()
278
+ if (typeof props.onExited === 'function') {
279
+ props.onExited()
280
+ }
278
281
  })
279
282
  }
280
283
  }
281
284
 
282
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'toState' implicitly has an 'any' type.
283
- transitionEnabled(toState) {
285
+ transitionEnabled(toState: BaseTransitionStatesType | null) {
284
286
  const { props } = this
285
287
 
286
288
  switch (toState) {
@@ -295,9 +297,9 @@ class BaseTransition extends React.Component<BaseTransitionProps> {
295
297
  }
296
298
  }
297
299
 
298
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'transitionState' implicitly has an 'any... Remove this comment to see the full error message
299
- getTransitionClassName(transitionState) {
300
+ getTransitionClassName(transitionState: BaseTransitionStatesType | null) {
300
301
  const { props } = this
302
+
301
303
  switch (transitionState) {
302
304
  case STATES.EXITED:
303
305
  return props.exitedClassName
@@ -308,15 +310,22 @@ class BaseTransition extends React.Component<BaseTransitionProps> {
308
310
  case STATES.EXITING:
309
311
  return props.exitingClassName
310
312
  default:
311
- return null
313
+ return undefined
312
314
  }
313
315
  }
316
+
314
317
  ref = createRef()
318
+
315
319
  renderChildren() {
316
- return safeCloneElement(ensureSingleChild(this.props.children)!, {
317
- 'aria-hidden': !this.props.in ? true : null,
318
- ref: this.ref
319
- })
320
+ return this.props.children
321
+ ? safeCloneElement(
322
+ ensureSingleChild(this.props.children) as ReactElement,
323
+ {
324
+ 'aria-hidden': !this.props.in ? true : undefined,
325
+ ref: this.ref
326
+ }
327
+ )
328
+ : null
320
329
  }
321
330
 
322
331
  render() {