@instructure/ui-drawer-layout 8.33.1 → 8.33.2-snapshot-5

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/es/DrawerLayout/DrawerContent/DrawerContentLocator.js +3 -1
  3. package/es/DrawerLayout/DrawerContent/index.js +7 -26
  4. package/es/DrawerLayout/DrawerContent/props.js +1 -0
  5. package/es/DrawerLayout/DrawerContent/styles.js +0 -1
  6. package/es/DrawerLayout/DrawerContent/theme.js +0 -1
  7. package/es/DrawerLayout/DrawerLayoutLocator.js +3 -3
  8. package/es/DrawerLayout/DrawerTray/DrawerTrayLocator.js +3 -1
  9. package/es/DrawerLayout/DrawerTray/index.js +33 -64
  10. package/es/DrawerLayout/DrawerTray/props.js +1 -0
  11. package/es/DrawerLayout/DrawerTray/styles.js +0 -1
  12. package/es/DrawerLayout/DrawerTray/theme.js +5 -5
  13. package/es/DrawerLayout/__examples__/DrawerLayout.examples.js +1 -1
  14. package/es/DrawerLayout/__fixtures__/DrawerLayout.fixture.js +6 -7
  15. package/es/DrawerLayout/index.js +3 -41
  16. package/es/DrawerLayout/locator.js +1 -0
  17. package/es/DrawerLayout/props.js +1 -0
  18. package/es/DrawerLayout/styles.js +0 -1
  19. package/es/index.js +1 -0
  20. package/lib/DrawerLayout/DrawerContent/DrawerContentLocator.js +1 -3
  21. package/lib/DrawerLayout/DrawerContent/index.js +7 -36
  22. package/lib/DrawerLayout/DrawerContent/props.js +1 -3
  23. package/lib/DrawerLayout/DrawerContent/styles.js +0 -2
  24. package/lib/DrawerLayout/DrawerContent/theme.js +0 -2
  25. package/lib/DrawerLayout/DrawerLayoutLocator.js +1 -7
  26. package/lib/DrawerLayout/DrawerTray/DrawerTrayLocator.js +1 -3
  27. package/lib/DrawerLayout/DrawerTray/index.js +33 -78
  28. package/lib/DrawerLayout/DrawerTray/props.js +1 -5
  29. package/lib/DrawerLayout/DrawerTray/styles.js +0 -2
  30. package/lib/DrawerLayout/DrawerTray/theme.js +5 -6
  31. package/lib/DrawerLayout/__examples__/DrawerLayout.examples.js +0 -6
  32. package/lib/DrawerLayout/__fixtures__/DrawerLayout.fixture.js +5 -14
  33. package/lib/DrawerLayout/index.js +3 -62
  34. package/lib/DrawerLayout/locator.js +0 -2
  35. package/lib/DrawerLayout/props.js +1 -7
  36. package/lib/DrawerLayout/styles.js +0 -2
  37. package/lib/index.js +0 -1
  38. package/package.json +21 -21
  39. package/tsconfig.build.tsbuildinfo +1 -1
@@ -1,5 +1,4 @@
1
1
  var _dec, _dec2, _dec3, _dec4, _class, _class2;
2
-
3
2
  /*
4
3
  * The MIT License (MIT)
5
4
  *
@@ -38,7 +37,6 @@ import { DrawerTray } from './DrawerTray';
38
37
  import { withStyle, jsx } from '@instructure/emotion';
39
38
  import generateStyle from './styles';
40
39
  import { propTypes, allowedProps } from './props';
41
-
42
40
  /**
43
41
  ---
44
42
  category: components
@@ -52,59 +50,46 @@ let DrawerLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyl
52
50
  this._content = null;
53
51
  this._tray = null;
54
52
  this.ref = null;
55
-
56
53
  this.handleRef = el => {
57
54
  this.ref = el;
58
55
  };
59
-
60
56
  this.handleTrayContentRef = el => {
61
57
  this._tray = el;
62
58
  };
63
-
64
59
  this.handleContentSizeChange = _ref => {
65
60
  let width = _ref.width;
66
61
  this.setState((state, props) => {
67
62
  const nextState = this.getNextState(props.minWidth, state.trayWidth, width, state.shouldOverlayTray);
68
-
69
63
  if (state.shouldOverlayTray !== nextState.shouldOverlayTray) {
70
64
  this.notifyOverlayTrayChange(nextState.shouldOverlayTray);
71
65
  }
72
-
73
66
  return nextState;
74
67
  });
75
68
  };
76
-
77
69
  this.handleTraySizeChange = _ref2 => {
78
70
  let width = _ref2.width;
79
71
  this.setState((state, props) => {
80
72
  const nextState = this.getNextState(props.minWidth, width, state.contentWidth, true);
81
-
82
73
  if (state.shouldOverlayTray !== nextState.shouldOverlayTray) {
83
74
  this.notifyOverlayTrayChange(nextState.shouldOverlayTray);
84
75
  }
85
-
86
76
  return nextState;
87
77
  });
88
78
  };
89
-
90
79
  this.handleTrayTransitionEnter = () => {
91
80
  let width = 0;
92
-
93
81
  if (this._tray) {
94
82
  width = getBoundingClientRect(this._tray).width;
95
83
  }
96
-
97
84
  this.handleTraySizeChange({
98
85
  width
99
86
  });
100
87
  };
101
-
102
88
  this.handleTrayTransitionExit = () => {
103
89
  this.handleTraySizeChange({
104
90
  width: 0
105
91
  });
106
92
  };
107
-
108
93
  this.state = {
109
94
  shouldOverlayTray: false,
110
95
  trayWidth: 0,
@@ -112,70 +97,56 @@ let DrawerLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyl
112
97
  };
113
98
  this._id = _props.deterministicId();
114
99
  }
115
-
116
100
  componentDidMount() {
117
101
  var _this$props$makeStyle, _this$props;
118
-
119
102
  (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
120
103
  }
121
-
122
104
  componentDidUpdate() {
123
105
  var _this$props$makeStyle2, _this$props2;
124
-
125
106
  (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
126
107
  }
127
-
128
108
  get trayProps() {
129
109
  const tray = Children.toArray(this.props.children).filter(child => matchComponentTypes(child, [DrawerTray]))[0];
130
110
  return tray.props;
131
111
  }
132
-
133
112
  get trayPlacement() {
134
113
  const _this$trayProps = this.trayProps,
135
- placement = _this$trayProps.placement,
136
- _this$trayProps$dir = _this$trayProps.dir,
137
- dir = _this$trayProps$dir === void 0 ? this.props.dir : _this$trayProps$dir;
114
+ placement = _this$trayProps.placement,
115
+ _this$trayProps$dir = _this$trayProps.dir,
116
+ dir = _this$trayProps$dir === void 0 ? this.props.dir : _this$trayProps$dir;
138
117
  const isRtl = dir === textDirectionContextConsumer.DIRECTION.rtl;
139
118
  return isRtl ? mirrorHorizontalPlacement(placement, ' ') : placement;
140
119
  }
141
-
142
120
  get contentMargin() {
143
121
  const trayWidth = this.state.trayWidth || 0;
144
122
  return this.state.shouldOverlayTray ? 0 : trayWidth;
145
123
  }
146
-
147
124
  get contentStyle() {
148
125
  const shouldOverlayTray = this.shouldOverlayTray(this.props.minWidth, this.state.trayWidth, this.state.contentWidth, this.state.shouldOverlayTray);
149
126
  let marginLeft = 0;
150
127
  let marginRight = 0;
151
-
152
128
  if (!shouldOverlayTray) {
153
129
  if (this.trayPlacement === 'start') {
154
130
  marginLeft = this.contentMargin;
155
131
  }
156
-
157
132
  if (this.trayPlacement === 'end') {
158
133
  marginRight = this.contentMargin;
159
134
  }
160
135
  }
161
-
162
136
  return {
163
137
  marginLeft: `${marginLeft}px`,
164
138
  marginRight: `${marginRight}px`
165
139
  };
166
140
  }
167
-
168
141
  shouldOverlayTray(minWidth, trayWidth, contentWidth, trayIsOverlayed) {
169
142
  if (!this._content) return false;
170
143
  const minWidthPx = px(minWidth, this._content);
171
-
172
144
  if (trayIsOverlayed) {
173
145
  return contentWidth - trayWidth < minWidthPx;
174
146
  } else {
175
147
  return contentWidth < minWidthPx;
176
148
  }
177
149
  }
178
-
179
150
  getNextState(minWidth, trayWidth, contentWidth, trayIsOverlayed) {
180
151
  const shouldOverlayTray = this.shouldOverlayTray(minWidth, trayWidth, contentWidth, trayIsOverlayed);
181
152
  return {
@@ -184,15 +155,12 @@ let DrawerLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyl
184
155
  shouldOverlayTray
185
156
  };
186
157
  }
187
-
188
158
  notifyOverlayTrayChange(shouldOverlayTray) {
189
159
  const onOverlayTrayChange = this.props.onOverlayTrayChange;
190
-
191
160
  if (typeof onOverlayTrayChange === 'function') {
192
161
  onOverlayTrayChange(shouldOverlayTray);
193
162
  }
194
163
  }
195
-
196
164
  renderChildren() {
197
165
  let trayCount = 0;
198
166
  let contentCount = 0;
@@ -209,16 +177,13 @@ let DrawerLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyl
209
177
  });
210
178
  } else if (matchComponentTypes(child, [DrawerContent])) {
211
179
  contentCount++;
212
-
213
180
  const handleContentRef = el => {
214
181
  const contentRef = child.props.contentRef;
215
182
  this._content = el;
216
-
217
183
  if (typeof contentRef === 'function') {
218
184
  contentRef(el);
219
185
  }
220
186
  };
221
-
222
187
  return this.state.trayWidth !== null ? safeCloneElement(child, {
223
188
  label: child.props.label,
224
189
  key: child.props.label,
@@ -235,10 +200,8 @@ let DrawerLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyl
235
200
  error(contentCount <= 1, `[DrawerLayout] Only one 'DrawerContent' per 'DrawerLayout' is supported.`);
236
201
  return children;
237
202
  }
238
-
239
203
  render() {
240
204
  var _this$props$styles;
241
-
242
205
  const props = {
243
206
  [DrawerLayout.locatorAttribute]: this._id
244
207
  };
@@ -249,7 +212,6 @@ let DrawerLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyl
249
212
  ref: this.handleRef
250
213
  }), this.renderChildren()));
251
214
  }
252
-
253
215
  }, _class2.displayName = "DrawerLayout", _class2.componentId = 'DrawerLayout', _class2.locatorAttribute = 'data-drawer-layout', _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.defaultProps = {
254
216
  minWidth: '30rem'
255
217
  }, _class2.Content = DrawerContent, _class2.Tray = DrawerTray, _class2)) || _class) || _class) || _class) || _class);
@@ -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 { DrawerLayoutLocator } from './DrawerLayoutLocator';
25
26
  export { DrawerContentLocator, DrawerTrayLocator } from './DrawerLayoutLocator';
26
27
  export { DrawerLayoutLocator };
@@ -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 { Children as ChildrenPropTypes } from '@instructure/ui-prop-types';
26
27
  import { textDirectionContextConsumer } from '@instructure/ui-i18n';
@@ -41,5 +41,4 @@ const generateStyle = () => {
41
41
  }
42
42
  };
43
43
  };
44
-
45
44
  export default generateStyle;
package/es/index.js CHANGED
@@ -21,4 +21,5 @@
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
  export { DrawerLayout, DrawerContent } from './DrawerLayout';
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DrawerContentLocator = void 0;
7
-
8
7
  var _locator = require("@instructure/ui-test-locator/lib/utils/locator.js");
9
-
10
8
  var _index = require("./index");
11
-
12
9
  /*
13
10
  * The MIT License (MIT)
14
11
  *
@@ -32,6 +29,7 @@ var _index = require("./index");
32
29
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
30
  * SOFTWARE.
34
31
  */
32
+
35
33
  // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
36
34
  const DrawerContentLocator = (0, _locator.locator)(_index.DrawerContent.selector);
37
35
  exports.DrawerContentLocator = DrawerContentLocator;
@@ -1,32 +1,20 @@
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.DrawerContent = void 0;
9
-
10
8
  var _react = require("react");
11
-
12
9
  var _debounce = require("@instructure/debounce");
13
-
14
10
  var _getBoundingClientRect = require("@instructure/ui-dom-utils/lib/getBoundingClientRect.js");
15
-
16
11
  var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
17
-
18
12
  var _testable = require("@instructure/ui-testable/lib/testable.js");
19
-
20
13
  var _emotion = require("@instructure/emotion");
21
-
22
14
  var _styles = _interopRequireDefault(require("./styles"));
23
-
24
15
  var _theme = _interopRequireDefault(require("./theme"));
25
-
26
16
  var _props = require("./props");
27
-
28
17
  var _dec, _dec2, _class, _class2;
29
-
30
18
  /**
31
19
  ---
32
20
  parent: DrawerLayout
@@ -40,85 +28,69 @@ let DrawerContent = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defa
40
28
  this.ref = null;
41
29
  this._resizeListener = void 0;
42
30
  this._debounced = void 0;
43
-
44
31
  this.makeStyleProps = shouldTransition => {
45
32
  return {
46
33
  shouldTransition
47
34
  };
48
35
  };
49
-
50
36
  this.handleContentRef = node => {
51
37
  this.ref = node;
52
-
53
38
  if (typeof this.props.contentRef === 'function') {
54
39
  this.props.contentRef(node);
55
40
  }
56
41
  };
57
42
  }
58
-
59
43
  get _content() {
60
44
  return this.ref;
61
45
  }
62
-
63
46
  componentDidMount() {
64
47
  var _this$props$makeStyle, _this$props;
65
-
66
48
  const rect = (0, _getBoundingClientRect.getBoundingClientRect)(this.ref);
67
49
  const origSize = {
68
50
  width: rect.width
69
- }; // set initial size
70
-
51
+ };
52
+ // set initial size
71
53
  if (typeof this.props.onSizeChange === 'function') {
72
54
  this.props.onSizeChange({
73
55
  width: rect.width,
74
56
  height: rect.height
75
- }); // listen for changes to size
57
+ });
76
58
 
59
+ // listen for changes to size
77
60
  this._debounced = (0, _debounce.debounce)(this.props.onSizeChange, 100, {
78
61
  leading: false,
79
62
  trailing: true
80
63
  });
81
64
  }
82
-
83
65
  this._resizeListener = new ResizeObserver(entries => {
84
66
  for (const entry of entries) {
85
67
  const size = {
86
68
  width: entry.contentRect.width
87
69
  };
88
-
89
70
  if (size.width !== origSize.width) {
90
71
  var _this$_debounced;
91
-
92
72
  (_this$_debounced = this._debounced) === null || _this$_debounced === void 0 ? void 0 : _this$_debounced.call(this, size);
93
73
  }
94
74
  }
95
75
  });
96
-
97
76
  this._resizeListener.observe(this.ref);
98
-
99
77
  (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStyleProps(false));
100
78
  }
101
-
102
79
  componentDidUpdate() {
103
80
  var _this$props$makeStyle2, _this$props2;
104
-
105
81
  (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStyleProps(true));
106
82
  }
107
-
108
83
  componentWillUnmount() {
109
84
  var _this$_resizeListener, _this$_debounced2;
110
-
111
85
  (_this$_resizeListener = this._resizeListener) === null || _this$_resizeListener === void 0 ? void 0 : _this$_resizeListener.disconnect();
112
86
  (_this$_debounced2 = this._debounced) === null || _this$_debounced2 === void 0 ? void 0 : _this$_debounced2.cancel();
113
87
  }
114
-
115
88
  render() {
116
89
  var _this$props$styles;
117
-
118
90
  const _this$props3 = this.props,
119
- style = _this$props3.style,
120
- label = _this$props3.label,
121
- role = _this$props3.role;
91
+ style = _this$props3.style,
92
+ label = _this$props3.label,
93
+ role = _this$props3.role;
122
94
  return (0, _emotion.jsx)("div", Object.assign({}, (0, _omitProps.omitProps)(this.props, DrawerContent.allowedProps), {
123
95
  role: role,
124
96
  style: style,
@@ -127,7 +99,6 @@ let DrawerContent = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defa
127
99
  css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.drawerContent
128
100
  }), this.props.children);
129
101
  }
130
-
131
102
  }, _class2.displayName = "DrawerContent", _class2.componentId = 'DrawerLayout.Content', _class2.locatorAttribute = 'data-drawer-content', _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.defaultProps = {
132
103
  role: 'region'
133
104
  }, _class2)) || _class) || _class);
@@ -1,14 +1,11 @@
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
  /*
13
10
  * The MIT License (MIT)
14
11
  *
@@ -32,6 +29,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
32
29
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
30
  * SOFTWARE.
34
31
  */
32
+
35
33
  const propTypes = {
36
34
  label: _propTypes.default.string.isRequired,
37
35
  children: _propTypes.default.node,
@@ -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
  *
@@ -54,6 +53,5 @@ const generateStyle = (componentTheme, _props, state) => {
54
53
  }
55
54
  };
56
55
  };
57
-
58
56
  var _default = generateStyle;
59
57
  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
  *
@@ -41,6 +40,5 @@ const generateComponentTheme = theme => {
41
40
  overflowY: 'auto'
42
41
  };
43
42
  };
44
-
45
43
  var _default = generateComponentTheme;
46
44
  exports.default = _default;
@@ -16,15 +16,10 @@ Object.defineProperty(exports, "DrawerTrayLocator", {
16
16
  return _DrawerTrayLocator.DrawerTrayLocator;
17
17
  }
18
18
  });
19
-
20
19
  var _locator = require("@instructure/ui-test-locator/lib/utils/locator.js");
21
-
22
20
  var _index = require("./index");
23
-
24
21
  var _DrawerContentLocator = require("./DrawerContent/DrawerContentLocator");
25
-
26
22
  var _DrawerTrayLocator = require("./DrawerTray/DrawerTrayLocator");
27
-
28
23
  /*
29
24
  * The MIT License (MIT)
30
25
  *
@@ -48,6 +43,7 @@ var _DrawerTrayLocator = require("./DrawerTray/DrawerTrayLocator");
48
43
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49
44
  * SOFTWARE.
50
45
  */
46
+
51
47
  // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
52
48
  const DrawerLayoutLocator = (0, _locator.locator)(_index.DrawerLayout.selector, {
53
49
  findContent: function () {
@@ -56,11 +52,9 @@ const DrawerLayoutLocator = (0, _locator.locator)(_index.DrawerLayout.selector,
56
52
  findTray: function (element) {
57
53
  if (element && element.getAttribute) {
58
54
  const id = element.getAttribute(_index.DrawerLayout.locatorAttribute);
59
-
60
55
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
61
56
  args[_key - 1] = arguments[_key];
62
57
  }
63
-
64
58
  return (0, _locator.locator)(`[${_index.DrawerLayout.Tray.locatorAttribute}="${id}"]`).find(...args);
65
59
  } else {
66
60
  return null;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DrawerTrayLocator = void 0;
7
-
8
7
  var _locator = require("@instructure/ui-test-locator/lib/utils/locator.js");
9
-
10
8
  var _index = require("./index");
11
-
12
9
  /*
13
10
  * The MIT License (MIT)
14
11
  *
@@ -32,6 +29,7 @@ var _index = require("./index");
32
29
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
30
  * SOFTWARE.
34
31
  */
32
+
35
33
  // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
36
34
  const DrawerTrayLocator = (0, _locator.locator)(_index.DrawerTray.selector);
37
35
  exports.DrawerTrayLocator = DrawerTrayLocator;