@instructure/ui-position 8.10.1 → 8.10.3-snapshot.3

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.10.2](https://github.com/instructure/instructure-ui/compare/v8.10.1...v8.10.2) (2021-10-01)
7
+
8
+ **Note:** Version bump only for package @instructure/ui-position
9
+
6
10
  ## [8.10.1](https://github.com/instructure/instructure-ui/compare/v8.10.0...v8.10.1) (2021-10-01)
7
11
 
8
12
  **Note:** Version bump only for package @instructure/ui-position
package/LICENSE.md ADDED
@@ -0,0 +1,27 @@
1
+ ---
2
+ title: The MIT License (MIT)
3
+ category: Getting Started
4
+ order: 9
5
+ ---
6
+
7
+ # The MIT License (MIT)
8
+
9
+ Copyright (c) 2015 Instructure, Inc.
10
+
11
+ **Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions.**
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
@@ -48,12 +48,20 @@ category: components/utilities
48
48
  let Position = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class Position extends Component {
49
49
  constructor(props) {
50
50
  super(props);
51
+ this.ref = null;
51
52
  this._id = void 0;
52
53
  this._timeouts = [];
53
54
  this._listener = null;
54
55
  this._content = void 0;
55
56
  this._target = void 0;
56
57
 
58
+ this.handleRef = el => {
59
+ var _this$props$elementRe, _this$props;
60
+
61
+ this.ref = el;
62
+ (_this$props$elementRe = (_this$props = this.props).elementRef) === null || _this$props$elementRe === void 0 ? void 0 : _this$props$elementRe.call(_this$props, el);
63
+ };
64
+
57
65
  this.handlePortalOpen = () => {
58
66
  this.position();
59
67
 
@@ -95,14 +103,14 @@ let Position = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 =
95
103
  }
96
104
 
97
105
  componentDidMount() {
98
- var _this$props$makeStyle, _this$props;
106
+ var _this$props$makeStyle, _this$props2;
99
107
 
100
108
  this.toggleLocatorAttributes(true);
101
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
109
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
102
110
  }
103
111
 
104
112
  componentDidUpdate(prevProps, prevState) {
105
- var _this$props$makeStyle2, _this$props3;
113
+ var _this$props$makeStyle2, _this$props4;
106
114
 
107
115
  this.position();
108
116
  this.toggleLocatorAttributes(true);
@@ -116,16 +124,16 @@ let Position = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 =
116
124
  placement = _this$state.placement;
117
125
 
118
126
  if (style && prevState.style && (placement !== prevState.placement || style.top !== prevState.style.top || style.left !== prevState.style.left)) {
119
- var _this$props$onPositio, _this$props2;
127
+ var _this$props$onPositio, _this$props3;
120
128
 
121
- (_this$props$onPositio = (_this$props2 = this.props).onPositionChanged) === null || _this$props$onPositio === void 0 ? void 0 : _this$props$onPositio.call(_this$props2, {
129
+ (_this$props$onPositio = (_this$props3 = this.props).onPositionChanged) === null || _this$props$onPositio === void 0 ? void 0 : _this$props$onPositio.call(_this$props3, {
122
130
  top: style.top,
123
131
  left: style.left,
124
132
  placement
125
133
  });
126
134
  }
127
135
 
128
- (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
136
+ (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
129
137
  }
130
138
 
131
139
  componentWillUnmount() {
@@ -181,7 +189,8 @@ let Position = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 =
181
189
 
182
190
  this._listener = null;
183
191
  }
184
- }
192
+ } // content that needs to be positioned relative to the target
193
+
185
194
 
186
195
  renderContent() {
187
196
  let content = ensureSingleChild(this.props.children);
@@ -236,7 +245,9 @@ let Position = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 =
236
245
  const props = {
237
246
  [Position.locatorAttribute]: this._id
238
247
  };
239
- return jsx("span", props, this.renderTarget(), this.renderContent());
248
+ return jsx("span", Object.assign({}, props, {
249
+ ref: this.handleRef
250
+ }), this.renderTarget(), this.renderContent());
240
251
  }
241
252
 
242
253
  }, _class2.displayName = "Position", _class2.componentId = 'Position', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
@@ -38,7 +38,8 @@ const propTypes = {
38
38
  shouldPositionOverTarget: PropTypes.bool,
39
39
  onPositionChanged: PropTypes.func,
40
40
  onPositioned: PropTypes.func,
41
- children: PropTypes.node
41
+ children: PropTypes.node,
42
+ elementRef: PropTypes.func
42
43
  };
43
- const allowedProps = ['renderTarget', 'target', 'placement', 'mountNode', 'insertAt', 'constrain', 'offsetX', 'offsetY', 'id', 'shouldTrackPosition', 'shouldPositionOverTarget', 'onPositionChanged', 'onPositioned', 'children'];
44
+ const allowedProps = ['renderTarget', 'target', 'placement', 'mountNode', 'insertAt', 'constrain', 'offsetX', 'offsetY', 'id', 'shouldTrackPosition', 'shouldPositionOverTarget', 'onPositionChanged', 'onPositioned', 'children', 'elementRef'];
44
45
  export { propTypes, allowedProps };
@@ -52,12 +52,20 @@ category: components/utilities
52
52
  let Position = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class Position extends _react.Component {
53
53
  constructor(props) {
54
54
  super(props);
55
+ this.ref = null;
55
56
  this._id = void 0;
56
57
  this._timeouts = [];
57
58
  this._listener = null;
58
59
  this._content = void 0;
59
60
  this._target = void 0;
60
61
 
62
+ this.handleRef = el => {
63
+ var _this$props$elementRe, _this$props;
64
+
65
+ this.ref = el;
66
+ (_this$props$elementRe = (_this$props = this.props).elementRef) === null || _this$props$elementRe === void 0 ? void 0 : _this$props$elementRe.call(_this$props, el);
67
+ };
68
+
61
69
  this.handlePortalOpen = () => {
62
70
  this.position();
63
71
 
@@ -99,14 +107,14 @@ let Position = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default),
99
107
  }
100
108
 
101
109
  componentDidMount() {
102
- var _this$props$makeStyle, _this$props;
110
+ var _this$props$makeStyle, _this$props2;
103
111
 
104
112
  this.toggleLocatorAttributes(true);
105
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
113
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
106
114
  }
107
115
 
108
116
  componentDidUpdate(prevProps, prevState) {
109
- var _this$props$makeStyle2, _this$props3;
117
+ var _this$props$makeStyle2, _this$props4;
110
118
 
111
119
  this.position();
112
120
  this.toggleLocatorAttributes(true);
@@ -120,16 +128,16 @@ let Position = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default),
120
128
  placement = _this$state.placement;
121
129
 
122
130
  if (style && prevState.style && (placement !== prevState.placement || style.top !== prevState.style.top || style.left !== prevState.style.left)) {
123
- var _this$props$onPositio, _this$props2;
131
+ var _this$props$onPositio, _this$props3;
124
132
 
125
- (_this$props$onPositio = (_this$props2 = this.props).onPositionChanged) === null || _this$props$onPositio === void 0 ? void 0 : _this$props$onPositio.call(_this$props2, {
133
+ (_this$props$onPositio = (_this$props3 = this.props).onPositionChanged) === null || _this$props$onPositio === void 0 ? void 0 : _this$props$onPositio.call(_this$props3, {
126
134
  top: style.top,
127
135
  left: style.left,
128
136
  placement
129
137
  });
130
138
  }
131
139
 
132
- (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
140
+ (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
133
141
  }
134
142
 
135
143
  componentWillUnmount() {
@@ -185,7 +193,8 @@ let Position = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default),
185
193
 
186
194
  this._listener = null;
187
195
  }
188
- }
196
+ } // content that needs to be positioned relative to the target
197
+
189
198
 
190
199
  renderContent() {
191
200
  let content = (0, _ensureSingleChild.ensureSingleChild)(this.props.children);
@@ -240,7 +249,9 @@ let Position = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default),
240
249
  const props = {
241
250
  [Position.locatorAttribute]: this._id
242
251
  };
243
- return (0, _emotion.jsx)("span", props, this.renderTarget(), this.renderContent());
252
+ return (0, _emotion.jsx)("span", Object.assign({}, props, {
253
+ ref: this.handleRef
254
+ }), this.renderTarget(), this.renderContent());
244
255
  }
245
256
 
246
257
  }, _class2.displayName = "Position", _class2.componentId = 'Position', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
@@ -50,8 +50,9 @@ const propTypes = {
50
50
  shouldPositionOverTarget: _propTypes.default.bool,
51
51
  onPositionChanged: _propTypes.default.func,
52
52
  onPositioned: _propTypes.default.func,
53
- children: _propTypes.default.node
53
+ children: _propTypes.default.node,
54
+ elementRef: _propTypes.default.func
54
55
  };
55
56
  exports.propTypes = propTypes;
56
- const allowedProps = ['renderTarget', 'target', 'placement', 'mountNode', 'insertAt', 'constrain', 'offsetX', 'offsetY', 'id', 'shouldTrackPosition', 'shouldPositionOverTarget', 'onPositionChanged', 'onPositioned', 'children'];
57
+ const allowedProps = ['renderTarget', 'target', 'placement', 'mountNode', 'insertAt', 'constrain', 'offsetX', 'offsetY', 'id', 'shouldTrackPosition', 'shouldPositionOverTarget', 'onPositionChanged', 'onPositioned', 'children', 'elementRef'];
57
58
  exports.allowedProps = allowedProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-position",
3
- "version": "8.10.1",
3
+ "version": "8.10.3-snapshot.3+2ee813492",
4
4
  "description": "A component for positioning content with respect to a designated target.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "type": "commonjs",
@@ -25,24 +25,24 @@
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
27
  "@babel/runtime": "^7.13.10",
28
- "@instructure/debounce": "8.10.1",
29
- "@instructure/emotion": "8.10.1",
30
- "@instructure/shared-types": "8.10.1",
31
- "@instructure/ui-dom-utils": "8.10.1",
32
- "@instructure/ui-portal": "8.10.1",
33
- "@instructure/ui-prop-types": "8.10.1",
34
- "@instructure/ui-react-utils": "8.10.1",
35
- "@instructure/ui-testable": "8.10.1",
36
- "@instructure/ui-utils": "8.10.1",
37
- "@instructure/uid": "8.10.1",
28
+ "@instructure/debounce": "8.10.3-snapshot.3+2ee813492",
29
+ "@instructure/emotion": "8.10.3-snapshot.3+2ee813492",
30
+ "@instructure/shared-types": "8.10.3-snapshot.3+2ee813492",
31
+ "@instructure/ui-dom-utils": "8.10.3-snapshot.3+2ee813492",
32
+ "@instructure/ui-portal": "8.10.3-snapshot.3+2ee813492",
33
+ "@instructure/ui-prop-types": "8.10.3-snapshot.3+2ee813492",
34
+ "@instructure/ui-react-utils": "8.10.3-snapshot.3+2ee813492",
35
+ "@instructure/ui-testable": "8.10.3-snapshot.3+2ee813492",
36
+ "@instructure/ui-utils": "8.10.3-snapshot.3+2ee813492",
37
+ "@instructure/uid": "8.10.3-snapshot.3+2ee813492",
38
38
  "prop-types": "^15"
39
39
  },
40
40
  "devDependencies": {
41
- "@instructure/ui-babel-preset": "8.10.1",
42
- "@instructure/ui-color-utils": "8.10.1",
43
- "@instructure/ui-test-locator": "8.10.1",
44
- "@instructure/ui-test-utils": "8.10.1",
45
- "@instructure/ui-themes": "8.10.1"
41
+ "@instructure/ui-babel-preset": "8.10.3-snapshot.3+2ee813492",
42
+ "@instructure/ui-color-utils": "8.10.3-snapshot.3+2ee813492",
43
+ "@instructure/ui-test-locator": "8.10.3-snapshot.3+2ee813492",
44
+ "@instructure/ui-test-utils": "8.10.3-snapshot.3+2ee813492",
45
+ "@instructure/ui-themes": "8.10.3-snapshot.3+2ee813492"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "react": ">=16.8 <=17"
@@ -50,5 +50,6 @@
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "sideEffects": false
53
+ "sideEffects": false,
54
+ "gitHead": "2ee8134925b02efbc5d39662a8b1edb2c83a420d"
54
55
  }
@@ -100,12 +100,18 @@ class Position extends Component<PositionProps, PositionState> {
100
100
  this._id = this.props.id || uid('Position')
101
101
  }
102
102
 
103
+ ref: Element | null = null
103
104
  _id: string
104
105
  _timeouts: NodeJS.Timeout[] = []
105
106
  _listener: PositionChangeListenerType | null = null
106
107
  _content?: PositionElement
107
108
  _target?: PositionElement
108
109
 
110
+ handleRef = (el: Element | null) => {
111
+ this.ref = el
112
+ this.props.elementRef?.(el)
113
+ }
114
+
109
115
  shouldComponentUpdate(
110
116
  nextProps: PositionProps,
111
117
  nextState: PositionState,
@@ -246,6 +252,7 @@ class Position extends Component<PositionProps, PositionState> {
246
252
  }
247
253
  }
248
254
 
255
+ // content that needs to be positioned relative to the target
249
256
  renderContent() {
250
257
  let content = ensureSingleChild(this.props.children)
251
258
 
@@ -298,7 +305,7 @@ class Position extends Component<PositionProps, PositionState> {
298
305
  render() {
299
306
  const props = { [Position.locatorAttribute]: this._id }
300
307
  return (
301
- <span {...props}>
308
+ <span {...props} ref={this.handleRef}>
302
309
  {this.renderTarget()}
303
310
  {this.renderContent()}
304
311
  </span>
@@ -111,6 +111,11 @@ type PositionOwnProps = {
111
111
  * The content to be positioned
112
112
  */
113
113
  children?: React.ReactNode
114
+
115
+ /**
116
+ * Provides a reference to the underlying HTML root element (the target)
117
+ */
118
+ elementRef?: (element: Element | null) => void
114
119
  }
115
120
 
116
121
  type PositionState = {
@@ -127,7 +132,8 @@ type PropKeys = keyof PositionOwnProps
127
132
 
128
133
  type AllowedPropKeys = Readonly<Array<PropKeys>>
129
134
 
130
- type PositionProps = PositionOwnProps & WithStyleProps<PositionTheme, PositionStyle>
135
+ type PositionProps = PositionOwnProps &
136
+ WithStyleProps<PositionTheme, PositionStyle>
131
137
 
132
138
  const propTypes: PropValidators<PropKeys> = {
133
139
  renderTarget: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
@@ -143,7 +149,8 @@ const propTypes: PropValidators<PropKeys> = {
143
149
  shouldPositionOverTarget: PropTypes.bool,
144
150
  onPositionChanged: PropTypes.func,
145
151
  onPositioned: PropTypes.func,
146
- children: PropTypes.node
152
+ children: PropTypes.node,
153
+ elementRef: PropTypes.func
147
154
  }
148
155
 
149
156
  const allowedProps: AllowedPropKeys = [
@@ -160,7 +167,8 @@ const allowedProps: AllowedPropKeys = [
160
167
  'shouldPositionOverTarget',
161
168
  'onPositionChanged',
162
169
  'onPositioned',
163
- 'children'
170
+ 'children',
171
+ 'elementRef'
164
172
  ]
165
173
 
166
174
  export type { PositionProps, PositionState, PositionStyle }