@instructure/ui-motion 11.7.3-snapshot-7 → 11.7.3-snapshot-26

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.
@@ -49,146 +49,33 @@ private: true
49
49
  so that it works with css modules. The internals are pretty different now, but it has roughly the same api.
50
50
  **/
51
51
  class BaseTransition extends _react.Component {
52
- constructor(...args) {
53
- super(...args);
54
- this._timeouts = [];
55
- this._unmounted = false;
56
- this.state = {
57
- transitioning: false
58
- };
59
- this.ref = null;
60
- this.handleRef = el => {
61
- const elementRef = this.props.elementRef;
62
- this.ref = el;
63
- if (typeof elementRef === 'function') {
64
- elementRef(el);
65
- }
66
- };
67
- this.startTransition = (transitionIn, transitionOnStart) => {
68
- const _this$props = this.props,
69
- transitionEnter = _this$props.transitionEnter,
70
- transitionExit = _this$props.transitionExit;
71
- if (transitionIn) {
72
- this.enter(transitionEnter && transitionOnStart ? STATES.EXITED : null);
73
- } else {
74
- this.exit(transitionExit && transitionOnStart ? STATES.ENTERED : null);
75
- }
76
- };
77
- this.transition = (toState, fromState, transitionCallback, transitionDuration = 0) => {
78
- if (this._unmounted) return;
79
- const onTransition = this.props.onTransition;
80
- const classList = (0, _getClassList.getClassList)(this.ref);
81
- const transitionClassName = this.getTransitionClassName(toState);
82
- const prevTransitionClassName = this.getTransitionClassName(fromState);
83
- const baseTransitionClassName = this.props.transitionClassName;
84
- if (fromState && transitionDuration && this.transitionEnabled(toState)) {
85
- baseTransitionClassName && classList.add(baseTransitionClassName);
86
- } else {
87
- baseTransitionClassName && classList.remove(baseTransitionClassName);
88
- }
89
- if (prevTransitionClassName) {
90
- classList.remove(prevTransitionClassName);
91
- }
92
- if (transitionClassName) {
93
- classList.add(transitionClassName);
94
- }
95
- if (toState && fromState && typeof onTransition === 'function') {
96
- onTransition(toState, fromState);
97
- }
98
- this._timeouts.push(setTimeout(() => {
99
- if (this._unmounted) return;
100
- if (typeof transitionCallback === 'function') {
101
- transitionCallback();
102
- }
103
- }, transitionDuration));
104
- };
105
- this.enter = initialState => {
106
- if (this.state.transitioning || this._unmounted) return;
107
- const props = this.props;
108
- if (typeof props.onEnter === 'function') {
109
- props.onEnter();
110
- }
111
- if (props.transitionEnter) {
112
- this.setState({
113
- transitioning: true
114
- }, () => {
115
- const enter = () => {
116
- if (typeof props.onEntering === 'function') {
117
- props.onEntering();
118
- }
119
- this.transition(STATES.ENTERED, STATES.ENTERING, () => {
120
- this.setState({
121
- transitioning: false
122
- }, () => {
123
- if (typeof props.onEntered === 'function') {
124
- props.onEntered();
125
- }
126
- });
127
- });
128
- };
129
- if (initialState) {
130
- this.transition(initialState, null, () => {
131
- this.transition(STATES.ENTERING, initialState, enter, props.enterDelay);
132
- });
133
- } else {
134
- enter();
135
- }
136
- });
137
- } else {
138
- this.setState({
139
- transitioning: false
140
- }, () => {
141
- this.transition(STATES.ENTERED, STATES.EXITED);
142
- if (typeof props.onEntered === 'function') {
143
- props.onEntered();
144
- }
145
- });
146
- }
147
- };
148
- this.exit = initialState => {
149
- if (this.state.transitioning) return;
150
- const props = this.props;
151
- if (typeof props.onExit === 'function') {
152
- props.onExit();
153
- }
154
- if (props.transitionExit) {
155
- this.setState({
156
- transitioning: true
157
- }, () => {
158
- const exit = () => {
159
- if (typeof props.onExiting === 'function') {
160
- props.onExiting();
161
- }
162
- this.transition(STATES.EXITED, STATES.EXITING, () => {
163
- this.setState({
164
- transitioning: false
165
- }, () => {
166
- if (typeof props.onExited === 'function') {
167
- props.onExited();
168
- }
169
- });
170
- });
171
- };
172
- if (initialState) {
173
- this.transition(initialState, null, () => {
174
- this.transition(STATES.EXITING, initialState, exit, props.exitDelay);
175
- });
176
- } else {
177
- exit();
178
- }
179
- });
180
- } else {
181
- this.setState({
182
- transitioning: false
183
- }, () => {
184
- this.transition(STATES.EXITED, STATES.ENTERED);
185
- if (typeof props.onExited === 'function') {
186
- props.onExited();
187
- }
188
- });
189
- }
190
- };
191
- }
52
+ static displayName = "BaseTransition";
53
+ static allowedProps = _props.allowedProps;
54
+ static defaultProps = {
55
+ in: false,
56
+ unmountOnExit: false,
57
+ transitionOnMount: false,
58
+ transitionEnter: true,
59
+ transitionExit: true,
60
+ enterDelay: 300,
61
+ exitDelay: 300
62
+ };
63
+ static states = STATES;
64
+ _timeouts = [];
65
+ _unmounted = false;
66
+ state = {
67
+ transitioning: false
68
+ };
69
+ ref = null;
70
+ handleRef = el => {
71
+ const {
72
+ elementRef
73
+ } = this.props;
74
+ this.ref = el;
75
+ if (typeof elementRef === 'function') {
76
+ elementRef(el);
77
+ }
78
+ };
192
79
  componentDidMount() {
193
80
  this.startTransition(this.props.in, this.props.transitionOnMount);
194
81
  this._unmounted = false;
@@ -223,6 +110,47 @@ class BaseTransition extends _react.Component {
223
110
  });
224
111
  this._unmounted = true;
225
112
  }
113
+ startTransition = (transitionIn, transitionOnStart) => {
114
+ const {
115
+ transitionEnter,
116
+ transitionExit
117
+ } = this.props;
118
+ if (transitionIn) {
119
+ this.enter(transitionEnter && transitionOnStart ? STATES.EXITED : null);
120
+ } else {
121
+ this.exit(transitionExit && transitionOnStart ? STATES.ENTERED : null);
122
+ }
123
+ };
124
+ transition = (toState, fromState, transitionCallback, transitionDuration = 0) => {
125
+ if (this._unmounted) return;
126
+ const {
127
+ onTransition
128
+ } = this.props;
129
+ const classList = (0, _getClassList.getClassList)(this.ref);
130
+ const transitionClassName = this.getTransitionClassName(toState);
131
+ const prevTransitionClassName = this.getTransitionClassName(fromState);
132
+ const baseTransitionClassName = this.props.transitionClassName;
133
+ if (fromState && transitionDuration && this.transitionEnabled(toState)) {
134
+ baseTransitionClassName && classList.add(baseTransitionClassName);
135
+ } else {
136
+ baseTransitionClassName && classList.remove(baseTransitionClassName);
137
+ }
138
+ if (prevTransitionClassName) {
139
+ classList.remove(prevTransitionClassName);
140
+ }
141
+ if (transitionClassName) {
142
+ classList.add(transitionClassName);
143
+ }
144
+ if (toState && fromState && typeof onTransition === 'function') {
145
+ onTransition(toState, fromState);
146
+ }
147
+ this._timeouts.push(setTimeout(() => {
148
+ if (this._unmounted) return;
149
+ if (typeof transitionCallback === 'function') {
150
+ transitionCallback();
151
+ }
152
+ }, transitionDuration));
153
+ };
226
154
  clearTransition(transitionClassName) {
227
155
  if (this._unmounted) return;
228
156
  this.setState({
@@ -239,8 +167,100 @@ class BaseTransition extends _react.Component {
239
167
  classList.remove(transitionClassName);
240
168
  });
241
169
  }
170
+ enter = initialState => {
171
+ if (this.state.transitioning || this._unmounted) return;
172
+ const {
173
+ props
174
+ } = this;
175
+ if (typeof props.onEnter === 'function') {
176
+ props.onEnter();
177
+ }
178
+ if (props.transitionEnter) {
179
+ this.setState({
180
+ transitioning: true
181
+ }, () => {
182
+ const enter = () => {
183
+ if (typeof props.onEntering === 'function') {
184
+ props.onEntering();
185
+ }
186
+ this.transition(STATES.ENTERED, STATES.ENTERING, () => {
187
+ this.setState({
188
+ transitioning: false
189
+ }, () => {
190
+ if (typeof props.onEntered === 'function') {
191
+ props.onEntered();
192
+ }
193
+ });
194
+ });
195
+ };
196
+ if (initialState) {
197
+ this.transition(initialState, null, () => {
198
+ this.transition(STATES.ENTERING, initialState, enter, props.enterDelay);
199
+ });
200
+ } else {
201
+ enter();
202
+ }
203
+ });
204
+ } else {
205
+ this.setState({
206
+ transitioning: false
207
+ }, () => {
208
+ this.transition(STATES.ENTERED, STATES.EXITED);
209
+ if (typeof props.onEntered === 'function') {
210
+ props.onEntered();
211
+ }
212
+ });
213
+ }
214
+ };
215
+ exit = initialState => {
216
+ if (this.state.transitioning) return;
217
+ const {
218
+ props
219
+ } = this;
220
+ if (typeof props.onExit === 'function') {
221
+ props.onExit();
222
+ }
223
+ if (props.transitionExit) {
224
+ this.setState({
225
+ transitioning: true
226
+ }, () => {
227
+ const exit = () => {
228
+ if (typeof props.onExiting === 'function') {
229
+ props.onExiting();
230
+ }
231
+ this.transition(STATES.EXITED, STATES.EXITING, () => {
232
+ this.setState({
233
+ transitioning: false
234
+ }, () => {
235
+ if (typeof props.onExited === 'function') {
236
+ props.onExited();
237
+ }
238
+ });
239
+ });
240
+ };
241
+ if (initialState) {
242
+ this.transition(initialState, null, () => {
243
+ this.transition(STATES.EXITING, initialState, exit, props.exitDelay);
244
+ });
245
+ } else {
246
+ exit();
247
+ }
248
+ });
249
+ } else {
250
+ this.setState({
251
+ transitioning: false
252
+ }, () => {
253
+ this.transition(STATES.EXITED, STATES.ENTERED);
254
+ if (typeof props.onExited === 'function') {
255
+ props.onExited();
256
+ }
257
+ });
258
+ }
259
+ };
242
260
  transitionEnabled(toState) {
243
- const props = this.props;
261
+ const {
262
+ props
263
+ } = this;
244
264
  switch (toState) {
245
265
  case STATES.EXITED:
246
266
  case STATES.EXITING:
@@ -253,7 +273,9 @@ class BaseTransition extends _react.Component {
253
273
  }
254
274
  }
255
275
  getTransitionClassName(transitionState) {
256
- const props = this.props;
276
+ const {
277
+ props
278
+ } = this;
257
279
  switch (transitionState) {
258
280
  case STATES.EXITED:
259
281
  return props.exitedClassName;
@@ -264,12 +286,12 @@ class BaseTransition extends _react.Component {
264
286
  case STATES.EXITING:
265
287
  return props.exitingClassName;
266
288
  default:
267
- return void 0;
289
+ return undefined;
268
290
  }
269
291
  }
270
292
  renderChildren() {
271
293
  return this.props.children ? (0, _safeCloneElement.safeCloneElement)((0, _ensureSingleChild.ensureSingleChild)(this.props.children), {
272
- 'aria-hidden': !this.props.in ? true : void 0,
294
+ 'aria-hidden': !this.props.in ? true : undefined,
273
295
  ref: el => {
274
296
  const ref = (0, _findDOMNode.findDOMNode)(el) || null;
275
297
  this.handleRef(ref);
@@ -285,16 +307,4 @@ class BaseTransition extends _react.Component {
285
307
  }
286
308
  }
287
309
  exports.BaseTransition = BaseTransition;
288
- BaseTransition.displayName = "BaseTransition";
289
- BaseTransition.allowedProps = _props.allowedProps;
290
- BaseTransition.defaultProps = {
291
- in: false,
292
- unmountOnExit: false,
293
- transitionOnMount: false,
294
- transitionEnter: true,
295
- transitionExit: true,
296
- enterDelay: 300,
297
- exitDelay: 300
298
- };
299
- BaseTransition.states = STATES;
300
310
  var _default = exports.default = BaseTransition;
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.Transition = void 0;
8
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
8
  var _react = require("react");
10
9
  var _ms = require("@instructure/ui-utils/lib/ms.js");
11
10
  var _emotion = require("@instructure/emotion");
@@ -14,8 +13,7 @@ var _theme = _interopRequireDefault(require("./theme"));
14
13
  var _BaseTransition = require("./BaseTransition");
15
14
  var _props = require("./props");
16
15
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
17
- const _excluded = ["type", "children", "styles"];
18
- var _dec, _class, _Transition;
16
+ var _dec, _class;
19
17
  /*
20
18
  * The MIT License (MIT)
21
19
  *
@@ -46,53 +44,66 @@ category: components/utilities
46
44
  ---
47
45
  @module Transition
48
46
  **/
49
- let Transition = exports.Transition = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_Transition = class Transition extends _react.Component {
50
- constructor(...args) {
51
- super(...args);
52
- this.ref = null;
53
- this.handleRef = el => {
54
- const elementRef = this.props.elementRef;
55
- this.ref = el;
56
- if (typeof elementRef === 'function') {
57
- elementRef(el);
58
- }
59
- };
60
- this.handleExited = () => {
61
- if (typeof this.props.onExited === 'function') {
62
- this.props.onExited(this.props.type);
63
- }
64
- };
65
- this.handleEntered = () => {
66
- if (typeof this.props.onEntered === 'function') {
67
- this.props.onEntered(this.props.type);
68
- }
69
- };
70
- // Transition helper:
71
- // After emotion migration the only way to keep
72
- // the old BaseTransition functionality with adding and removing
73
- // classes was to add the `Global` helper of `emotion`
74
- // Todo: try to refactor or replace Transition/BaseTransition component in v9.0.0. so that it is not class based
75
- this.renderTransitionHelper = () => {
76
- const styles = this.props.styles;
77
- return (0, _jsxRuntime.jsx)(_emotion.Global, {
78
- styles: styles === null || styles === void 0 ? void 0 : styles.globalStyles
79
- });
80
- };
81
- }
47
+ let Transition = exports.Transition = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = class Transition extends _react.Component {
48
+ static displayName = "Transition";
49
+ static componentId = 'Transition';
50
+ static allowedProps = _props.allowedProps;
51
+ static defaultProps = {
52
+ type: 'fade',
53
+ in: false,
54
+ unmountOnExit: false,
55
+ transitionOnMount: false,
56
+ transitionEnter: true,
57
+ transitionExit: true
58
+ };
59
+ static states = _BaseTransition.BaseTransition.states;
60
+ ref = null;
61
+ handleRef = el => {
62
+ const {
63
+ elementRef
64
+ } = this.props;
65
+ this.ref = el;
66
+ if (typeof elementRef === 'function') {
67
+ elementRef(el);
68
+ }
69
+ };
82
70
  componentDidMount() {
83
- var _this$props$makeStyle, _this$props;
84
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
71
+ this.props.makeStyles?.();
85
72
  }
86
73
  componentDidUpdate() {
87
- var _this$props$makeStyle2, _this$props2;
88
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
74
+ this.props.makeStyles?.();
89
75
  }
76
+ handleExited = () => {
77
+ if (typeof this.props.onExited === 'function') {
78
+ this.props.onExited(this.props.type);
79
+ }
80
+ };
81
+ handleEntered = () => {
82
+ if (typeof this.props.onEntered === 'function') {
83
+ this.props.onEntered(this.props.type);
84
+ }
85
+ };
86
+
87
+ // Transition helper:
88
+ // After emotion migration the only way to keep
89
+ // the old BaseTransition functionality with adding and removing
90
+ // classes was to add the `Global` helper of `emotion`
91
+ // Todo: try to refactor or replace Transition/BaseTransition component in v9.0.0. so that it is not class based
92
+ renderTransitionHelper = () => {
93
+ const {
94
+ styles
95
+ } = this.props;
96
+ return (0, _jsxRuntime.jsx)(_emotion.Global, {
97
+ styles: styles?.globalStyles
98
+ });
99
+ };
90
100
  render() {
91
- const _this$props3 = this.props,
92
- type = _this$props3.type,
93
- children = _this$props3.children,
94
- styles = _this$props3.styles,
95
- props = (0, _objectWithoutProperties2.default)(_this$props3, _excluded);
101
+ const {
102
+ type,
103
+ children,
104
+ styles,
105
+ ...props
106
+ } = this.props;
96
107
  const duration = (0, _ms.ms)(styles.duration);
97
108
  return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
98
109
  children: [this.renderTransitionHelper(), (0, _jsxRuntime.jsx)(_BaseTransition.BaseTransition, {
@@ -111,12 +122,5 @@ let Transition = exports.Transition = (_dec = (0, _emotion.withStyleLegacy)(_sty
111
122
  })]
112
123
  });
113
124
  }
114
- }, _Transition.displayName = "Transition", _Transition.componentId = 'Transition', _Transition.allowedProps = _props.allowedProps, _Transition.defaultProps = {
115
- type: 'fade',
116
- in: false,
117
- unmountOnExit: false,
118
- transitionOnMount: false,
119
- transitionEnter: true,
120
- transitionExit: true
121
- }, _Transition.states = _BaseTransition.BaseTransition.states, _Transition)) || _class);
125
+ }) || _class);
122
126
  var _default = exports.default = Transition;
@@ -44,7 +44,9 @@ const getClassNames = type => ({
44
44
  */
45
45
  exports.getClassNames = getClassNames;
46
46
  const generateStyle = (componentTheme, props) => {
47
- const type = props.type;
47
+ const {
48
+ type
49
+ } = props;
48
50
 
49
51
  /**
50
52
  * After emotion migration the only way to keep
@@ -34,10 +34,12 @@ exports.default = void 0;
34
34
  * @return {Object} The final theme object with the overrides and component variables
35
35
  */
36
36
  const generateComponentTheme = theme => {
37
- const transitions = theme.transitions;
37
+ const {
38
+ transitions
39
+ } = theme;
38
40
  const componentVariables = {
39
- duration: transitions === null || transitions === void 0 ? void 0 : transitions.duration,
40
- timing: transitions === null || transitions === void 0 ? void 0 : transitions.timing
41
+ duration: transitions?.duration,
42
+ timing: transitions?.timing
41
43
  };
42
44
  return {
43
45
  ...componentVariables
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-motion",
3
- "version": "11.7.3-snapshot-7",
3
+ "version": "11.7.3-snapshot-26",
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",
@@ -14,19 +14,19 @@
14
14
  "bugs": "https://github.com/instructure/instructure-ui/issues",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@babel/runtime": "^7.27.6",
18
- "@instructure/emotion": "11.7.3-snapshot-7",
19
- "@instructure/ui-react-utils": "11.7.3-snapshot-7",
20
- "@instructure/ui-themes": "11.7.3-snapshot-7",
21
- "@instructure/shared-types": "11.7.3-snapshot-7",
22
- "@instructure/ui-dom-utils": "11.7.3-snapshot-7",
23
- "@instructure/ui-utils": "11.7.3-snapshot-7"
17
+ "@babel/runtime": "^7.29.2",
18
+ "@instructure/emotion": "11.7.3-snapshot-26",
19
+ "@instructure/ui-dom-utils": "11.7.3-snapshot-26",
20
+ "@instructure/shared-types": "11.7.3-snapshot-26",
21
+ "@instructure/ui-themes": "11.7.3-snapshot-26",
22
+ "@instructure/ui-react-utils": "11.7.3-snapshot-26",
23
+ "@instructure/ui-utils": "11.7.3-snapshot-26"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@testing-library/jest-dom": "^6.6.3",
27
27
  "@testing-library/react": "15.0.7",
28
28
  "vitest": "^3.2.2",
29
- "@instructure/ui-babel-preset": "11.7.3-snapshot-7"
29
+ "@instructure/ui-babel-preset": "11.7.3-snapshot-26"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "react": ">=18 <=19"