@instructure/ui-position 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.
@@ -1,48 +1,28 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = exports.Position = void 0;
9
-
10
8
  var _react = require("react");
11
-
12
9
  var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
13
-
14
10
  var _ensureSingleChild = require("@instructure/ui-react-utils/lib/ensureSingleChild.js");
15
-
16
11
  var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
17
-
18
12
  var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
19
-
20
13
  var _addPositionChangeListener = require("@instructure/ui-dom-utils/lib/addPositionChangeListener.js");
21
-
22
14
  var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
23
-
24
15
  var _deepEqual = require("@instructure/ui-utils/lib/deepEqual.js");
25
-
26
16
  var _shallowEqual = require("@instructure/ui-utils/lib/shallowEqual.js");
27
-
28
17
  var _debounce = require("@instructure/debounce");
29
-
30
18
  var _testable = require("@instructure/ui-testable/lib/testable.js");
31
-
32
19
  var _Portal = require("@instructure/ui-portal/lib/Portal");
33
-
34
20
  var _emotion = require("@instructure/emotion");
35
-
36
21
  var _styles = _interopRequireDefault(require("./styles"));
37
-
38
22
  var _theme = _interopRequireDefault(require("./theme"));
39
-
40
23
  var _props = require("./props");
41
-
42
24
  var _calculateElementPosition = require("../calculateElementPosition");
43
-
44
25
  var _dec, _dec2, _dec3, _class, _class2;
45
-
46
26
  /**
47
27
  ---
48
28
  category: components/utilities
@@ -58,23 +38,18 @@ let Position = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
58
38
  this._listener = null;
59
39
  this._content = void 0;
60
40
  this._target = void 0;
61
-
62
41
  this.handleRef = el => {
63
42
  const elementRef = this.props.elementRef;
64
43
  this.ref = el;
65
-
66
44
  if (typeof elementRef === 'function') {
67
45
  elementRef(el);
68
46
  }
69
47
  };
70
-
71
48
  this.handlePortalOpen = () => {
72
49
  this.position();
73
-
74
50
  if (this.props.shouldTrackPosition) {
75
51
  this.startTracking();
76
52
  }
77
-
78
53
  this._timeouts.push(setTimeout(() => {
79
54
  if (this.state.positioned && typeof this.props.onPositioned === 'function') {
80
55
  this.props.onPositioned({
@@ -85,14 +60,12 @@ let Position = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
85
60
  }
86
61
  }, 0));
87
62
  };
88
-
89
63
  this.position = () => {
90
64
  this.setState({
91
65
  positioned: true,
92
66
  ...this.calculatePosition(this.props)
93
67
  });
94
68
  };
95
-
96
69
  this.state = {
97
70
  positioned: false,
98
71
  ...this.calculatePosition(props)
@@ -103,32 +76,24 @@ let Position = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
103
76
  });
104
77
  this._id = this.props.id || props.deterministicId();
105
78
  }
106
-
107
79
  shouldComponentUpdate(nextProps, nextState, nextContext) {
108
80
  return !(0, _deepEqual.deepEqual)(this.state, nextState) || !(0, _shallowEqual.shallowEqual)(this.props, nextProps) || !(0, _shallowEqual.shallowEqual)(this.context, nextContext);
109
81
  }
110
-
111
82
  componentDidMount() {
112
83
  var _this$props$makeStyle, _this$props;
113
-
114
84
  this.toggleLocatorAttributes(true);
115
85
  (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
116
86
  }
117
-
118
87
  componentDidUpdate(prevProps, prevState) {
119
88
  var _this$props$makeStyle2, _this$props2;
120
-
121
89
  this.position();
122
90
  this.toggleLocatorAttributes(true);
123
-
124
91
  if (this.props.shouldTrackPosition !== prevProps.shouldTrackPosition) {
125
92
  this.props.shouldTrackPosition ? this.startTracking() : this.stopTracking();
126
93
  }
127
-
128
94
  const _this$state = this.state,
129
- style = _this$state.style,
130
- placement = _this$state.placement;
131
-
95
+ style = _this$state.style,
96
+ placement = _this$state.placement;
132
97
  if (style && prevState.style && (placement !== prevState.placement || style.top !== prevState.style.top || style.left !== prevState.style.left) && typeof this.props.onPositionChanged === 'function') {
133
98
  this.props.onPositionChanged({
134
99
  top: style.top,
@@ -136,20 +101,15 @@ let Position = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
136
101
  placement
137
102
  });
138
103
  }
139
-
140
104
  (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
141
105
  }
142
-
143
106
  componentWillUnmount() {
144
107
  ;
145
108
  this.position.cancel();
146
109
  this.stopTracking();
147
-
148
110
  this._timeouts.forEach(timeout => clearTimeout(timeout));
149
-
150
111
  this.toggleLocatorAttributes(false);
151
112
  }
152
-
153
113
  toggleLocatorAttributes(set) {
154
114
  // We have to find the actual DOM nodes and append the attributes
155
115
  // directly, as we can't be sure when safe cloning the child that
@@ -157,21 +117,18 @@ let Position = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
157
117
  this.toggleLocatorAttribute((0, _findDOMNode.findDOMNode)(this._content), Position.contentLocatorAttribute, set);
158
118
  this.toggleLocatorAttribute((0, _findDOMNode.findDOMNode)(this._target), Position.targetLocatorAttribute, set);
159
119
  }
160
-
161
120
  toggleLocatorAttribute(node, locator, set) {
162
121
  if (node && node.hasAttribute) {
163
122
  if (set && !node.hasAttribute(locator)) {
164
123
  ;
165
124
  node.setAttribute(locator, this._id);
166
125
  }
167
-
168
126
  if (!set && node.hasAttribute(locator)) {
169
127
  ;
170
128
  node.removeAttribute(locator);
171
129
  }
172
130
  }
173
131
  }
174
-
175
132
  calculatePosition(props) {
176
133
  return (0, _calculateElementPosition.calculateElementPosition)(this._content, this._target, {
177
134
  placement: props.placement,
@@ -182,26 +139,21 @@ let Position = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
182
139
  over: props.shouldPositionOverTarget
183
140
  });
184
141
  }
185
-
186
142
  startTracking() {
187
143
  this._listener = this._listener || (0, _addPositionChangeListener.addPositionChangeListener)(this._target, this.position);
188
144
  }
189
-
190
145
  stopTracking() {
191
146
  if (this._listener) {
192
147
  this._listener.remove();
193
-
194
148
  this._listener = null;
195
149
  }
196
- } // content that needs to be positioned relative to the target
197
-
150
+ }
198
151
 
152
+ // content that needs to be positioned relative to the target
199
153
  renderContent() {
200
154
  let content = (0, _ensureSingleChild.ensureSingleChild)(this.props.children);
201
-
202
155
  if (content) {
203
156
  var _this$props$styles;
204
-
205
157
  content = (0, _safeCloneElement.safeCloneElement)(content, {
206
158
  ref: el => {
207
159
  this._content = el;
@@ -224,13 +176,10 @@ let Position = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
224
176
  insertAt: this.props.insertAt
225
177
  }, content);
226
178
  }
227
-
228
179
  return content;
229
180
  }
230
-
231
181
  renderTarget() {
232
182
  const target = (0, _callRenderProp.callRenderProp)(this.props.renderTarget);
233
-
234
183
  if (target) {
235
184
  return (0, _safeCloneElement.safeCloneElement)(target, {
236
185
  ref: el => {
@@ -241,13 +190,10 @@ let Position = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
241
190
  } else if (this.props.target) {
242
191
  this._target = (0, _callRenderProp.callRenderProp)(this.props.target);
243
192
  }
244
-
245
193
  return null;
246
194
  }
247
-
248
195
  render() {
249
196
  var _this$props$styles2;
250
-
251
197
  const props = {
252
198
  [Position.locatorAttribute]: this._id
253
199
  };
@@ -256,7 +202,6 @@ let Position = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
256
202
  ref: this.handleRef
257
203
  }), this.renderTarget(), this.renderContent());
258
204
  }
259
-
260
205
  }, _class2.displayName = "Position", _class2.componentId = 'Position', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
261
206
  placement: 'bottom center',
262
207
  mountNode: null,
@@ -28,9 +28,7 @@ Object.defineProperty(exports, "customMethods", {
28
28
  }
29
29
  });
30
30
  exports.default = void 0;
31
-
32
31
  var _PositionLocator = require("./PositionLocator");
33
-
34
32
  /*
35
33
  * The MIT License (MIT)
36
34
  *
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.propTypes = exports.allowedProps = void 0;
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _element = require("@instructure/ui-prop-types/lib/element.js");
13
-
14
10
  var _PositionPropTypes = require("../PositionPropTypes");
15
-
16
11
  /*
17
12
  * The MIT License (MIT)
18
13
  *
@@ -36,6 +31,7 @@ var _PositionPropTypes = require("../PositionPropTypes");
36
31
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
32
  * SOFTWARE.
38
33
  */
34
+
39
35
  const propTypes = {
40
36
  renderTarget: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]),
41
37
  target: _propTypes.default.oneOfType([_element.element, _propTypes.default.func]),
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  /*
9
8
  * The MIT License (MIT)
10
9
  *
@@ -48,6 +47,5 @@ const generateStyle = (componentTheme, props) => {
48
47
  zIndex: componentTheme.zIndex
49
48
  };
50
49
  };
51
-
52
50
  var _default = generateStyle;
53
51
  exports.default = _default;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  /*
9
8
  * The MIT License (MIT)
10
9
  *
@@ -39,9 +38,9 @@ const generateComponentTheme = theme => {
39
38
  const componentVariables = {
40
39
  zIndex: stacking === null || stacking === void 0 ? void 0 : stacking.topmost
41
40
  };
42
- return { ...componentVariables
41
+ return {
42
+ ...componentVariables
43
43
  };
44
44
  };
45
-
46
45
  var _default = generateComponentTheme;
47
46
  exports.default = _default;
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.placementPropValues = exports.mirrorMap = exports.default = exports.PositionPropTypes = void 0;
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _element = require("@instructure/ui-prop-types/lib/element.js");
13
-
14
10
  /*
15
11
  * The MIT License (MIT)
16
12
  *
@@ -34,6 +30,7 @@ var _element = require("@instructure/ui-prop-types/lib/element.js");
34
30
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
31
  * SOFTWARE.
36
32
  */
33
+
37
34
  const placementPropValues = ['top', 'bottom', 'start', 'end', 'top start', 'top center', 'top end', 'top stretch', 'bottom start', 'bottom center', 'bottom end', 'bottom stretch', 'start top', 'start center', 'start bottom', 'start stretch', 'end top', 'end center', 'end bottom', 'end stretch', 'center start', 'center end', 'offscreen'];
38
35
  exports.placementPropValues = placementPropValues;
39
36
  const PositionPropTypes = {
@@ -41,21 +38,19 @@ const PositionPropTypes = {
41
38
  * The placement of the content in relation to the trigger
42
39
  */
43
40
  placement: _propTypes.default.oneOf(placementPropValues),
44
-
45
41
  /**
46
42
  * An element or a function returning an element to use as the mount node
47
43
  */
48
44
  mountNode: _propTypes.default.oneOfType([_element.element, _propTypes.default.func]),
49
-
50
45
  /**
51
46
  * The parent in which to constrain a placement
52
47
  */
53
48
  constrain: _propTypes.default.oneOfType([_element.element, _propTypes.default.func, _propTypes.default.oneOf(['window', 'scroll-parent', 'parent', 'none'])])
54
49
  };
50
+
55
51
  /**
56
52
  * The placement of the content in relation to the trigger
57
53
  */
58
-
59
54
  exports.PositionPropTypes = PositionPropTypes;
60
55
  const mirrorMap = {
61
56
  center: 'center',