@instructure/ui-tree-browser 8.14.1-snapshot.7 → 8.15.1-snapshot.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/es/TreeBrowser/TreeBrowserLocator.js +2 -1
  3. package/es/TreeBrowser/TreeButton/index.js +14 -15
  4. package/es/TreeBrowser/TreeCollection/index.js +18 -31
  5. package/es/TreeBrowser/TreeCollection/props.js +1 -9
  6. package/es/TreeBrowser/TreeNode/index.js +10 -13
  7. package/es/TreeBrowser/TreeNode/props.js +0 -8
  8. package/es/TreeBrowser/index.js +36 -32
  9. package/es/TreeBrowser/props.js +0 -55
  10. package/lib/TreeBrowser/TreeBrowserLocator.js +2 -1
  11. package/lib/TreeBrowser/TreeButton/index.js +14 -14
  12. package/lib/TreeBrowser/TreeCollection/index.js +17 -30
  13. package/lib/TreeBrowser/TreeCollection/props.js +1 -9
  14. package/lib/TreeBrowser/TreeNode/index.js +10 -12
  15. package/lib/TreeBrowser/TreeNode/props.js +0 -8
  16. package/lib/TreeBrowser/index.js +37 -33
  17. package/lib/TreeBrowser/props.js +0 -55
  18. package/package.json +15 -15
  19. package/src/TreeBrowser/TreeButton/index.tsx +21 -36
  20. package/src/TreeBrowser/TreeButton/props.ts +11 -10
  21. package/src/TreeBrowser/TreeCollection/index.tsx +57 -108
  22. package/src/TreeBrowser/TreeCollection/props.ts +17 -32
  23. package/src/TreeBrowser/TreeNode/index.tsx +10 -21
  24. package/src/TreeBrowser/TreeNode/props.ts +5 -7
  25. package/src/TreeBrowser/index.tsx +81 -108
  26. package/src/TreeBrowser/props.ts +133 -59
  27. package/tsconfig.build.tsbuildinfo +1 -1
  28. package/types/TreeBrowser/TreeBrowserLocator.d.ts +14 -14
  29. package/types/TreeBrowser/TreeButton/index.d.ts +5 -51
  30. package/types/TreeBrowser/TreeButton/index.d.ts.map +1 -1
  31. package/types/TreeBrowser/TreeButton/props.d.ts +11 -10
  32. package/types/TreeBrowser/TreeButton/props.d.ts.map +1 -1
  33. package/types/TreeBrowser/TreeCollection/index.d.ts +33 -85
  34. package/types/TreeBrowser/TreeCollection/index.d.ts.map +1 -1
  35. package/types/TreeBrowser/TreeCollection/props.d.ts +11 -25
  36. package/types/TreeBrowser/TreeCollection/props.d.ts.map +1 -1
  37. package/types/TreeBrowser/TreeNode/index.d.ts +4 -12
  38. package/types/TreeBrowser/TreeNode/index.d.ts.map +1 -1
  39. package/types/TreeBrowser/TreeNode/props.d.ts +5 -1
  40. package/types/TreeBrowser/TreeNode/props.d.ts.map +1 -1
  41. package/types/TreeBrowser/index.d.ts +35 -73
  42. package/types/TreeBrowser/index.d.ts.map +1 -1
  43. package/types/TreeBrowser/props.d.ts +113 -16
  44. package/types/TreeBrowser/props.d.ts.map +1 -1
@@ -32,6 +32,7 @@ var _dec, _dec2, _class, _class2, _temp;
32
32
  parent: TreeBrowser
33
33
  id: TreeBrowser.Collection
34
34
  ---
35
+ @tsProps
35
36
  **/
36
37
  let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeCollection extends _react.Component {
37
38
  constructor(props) {
@@ -45,7 +46,7 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
45
46
  });
46
47
  };
47
48
 
48
- this.handleBlur = (e, item) => {
49
+ this.handleBlur = (e, _item) => {
49
50
  e.stopPropagation();
50
51
  this.setState({
51
52
  focused: ''
@@ -164,12 +165,13 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
164
165
  id: key,
165
166
  role: "treeitem",
166
167
  css: styles === null || styles === void 0 ? void 0 : styles.item,
167
- tabIndex: "-1",
168
+ tabIndex: -1,
168
169
  key: key,
169
170
  "aria-posinset": position,
170
171
  "aria-setsize": this.childCount,
171
172
  "aria-level": this.itemsLevel
172
173
  }, ariaSelected, {
174
+ // @ts-expect-error ts-migrate(2322) FIXME: Type '(e: any, n: any) => void' is not assignable ... Remove this comment to see the full error message
173
175
  onClick: (e, n) => {
174
176
  if (typeof child.props.onClick === 'function') {
175
177
  child.props.onClick(e, n);
@@ -177,15 +179,16 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
177
179
  e.stopPropagation();
178
180
  }
179
181
  },
180
- onFocus: (e, n) => this.handleFocus(e, itemHash),
182
+ onFocus: e => this.handleFocus(e, itemHash) // @ts-expect-error ts-migrate(2322) FIXME: Type '(e: any, n: any) => void' is not assignable ... Remove this comment to see the full error message
183
+ ,
181
184
  onKeyDown: (e, n) => {
182
185
  if (typeof child.props.onKeyDown === 'function') {
183
186
  child.props.onKeyDown(e, n);
184
187
  } else {
185
- onKeyDown(e, itemHash);
188
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e, itemHash);
186
189
  }
187
190
  },
188
- onBlur: (e, n) => this.handleBlur(e, itemHash)
191
+ onBlur: e => this.handleBlur(e, itemHash)
189
192
  }), (0, _safeCloneElement.safeCloneElement)(child, itemProps));
190
193
  }
191
194
 
@@ -237,17 +240,17 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
237
240
  });
238
241
  return (0, _emotion.jsx)("li", Object.assign({
239
242
  key: `i${position}`,
240
- tabIndex: "-1",
243
+ tabIndex: -1,
241
244
  role: "treeitem",
242
245
  "aria-label": item.name,
243
246
  css: styles === null || styles === void 0 ? void 0 : styles.item,
244
247
  "aria-level": this.itemsLevel,
245
248
  "aria-posinset": position,
246
249
  "aria-setsize": this.childCount,
247
- onClick: (e, n) => onItemClick(e, itemHash),
248
- onKeyDown: (e, n) => onKeyDown(e, itemHash),
249
- onFocus: (e, n) => this.handleFocus(e, itemHash),
250
- onBlur: (e, n) => this.handleBlur(e, itemHash)
250
+ onClick: e => onItemClick === null || onItemClick === void 0 ? void 0 : onItemClick(e, itemHash),
251
+ onKeyDown: e => onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e, itemHash),
252
+ onFocus: e => this.handleFocus(e, itemHash),
253
+ onBlur: e => this.handleBlur(e, itemHash)
251
254
  }, ariaSelected), (0, _emotion.jsx)(_TreeButton.TreeButton, itemProps));
252
255
  }
253
256
 
@@ -293,7 +296,7 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
293
296
  this.ref = el;
294
297
  },
295
298
  css: styles === null || styles === void 0 ? void 0 : styles.treeCollection,
296
- tabIndex: "-1",
299
+ tabIndex: -1,
297
300
  role: "treeitem",
298
301
  "aria-label": this.props.name,
299
302
  "aria-level": level,
@@ -302,11 +305,11 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
302
305
  "aria-expanded": expanded,
303
306
  onClick: this.handleCollectionClick,
304
307
  onKeyDown: this.handleCollectionKeyDown,
305
- onFocus: (e, n) => this.handleFocus(e, {
308
+ onFocus: e => this.handleFocus(e, {
306
309
  id: id,
307
310
  type: 'collection'
308
311
  }),
309
- onBlur: (e, n) => this.handleBlur(e, {
312
+ onBlur: e => this.handleBlur(e, {
310
313
  id: id,
311
314
  type: 'collection'
312
315
  })
@@ -324,25 +327,9 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
324
327
  selection: '',
325
328
  size: 'medium',
326
329
  variant: 'folderTree',
327
- onItemClick: function () {},
328
- onCollectionClick: function () {},
329
- onKeyDown: function () {},
330
- id: void 0,
331
- name: void 0,
332
- descriptor: void 0,
333
- collectionIconExpanded: void 0,
334
- collectionIcon: void 0,
335
- itemIcon: void 0,
336
330
  getItemProps: props => props,
337
331
  getCollectionProps: props => props,
338
- numChildren: void 0,
339
- level: void 0,
340
- position: void 0,
341
- renderBeforeItems: null,
342
- renderAfterItems: null,
343
- containerRef: function () {},
344
- isCollectionFlattened: false,
345
- renderContent: void 0
332
+ isCollectionFlattened: false
346
333
  }, _temp)) || _class) || _class);
347
334
  exports.TreeCollection = TreeCollection;
348
335
  var _default = TreeCollection;
@@ -55,17 +55,9 @@ const propTypes = {
55
55
  onCollectionClick: _propTypes.default.func,
56
56
  onKeyDown: _propTypes.default.func,
57
57
  numChildren: _propTypes.default.number,
58
- level: _propTypes.default.number,
58
+ level: _propTypes.default.number.isRequired,
59
59
  position: _propTypes.default.number,
60
-
61
- /**
62
- * children of type TreeNode
63
- */
64
60
  renderBeforeItems: _Children.Children.oneOf([_TreeNode.TreeNode]),
65
-
66
- /**
67
- * children of type TreeNode
68
- */
69
61
  renderAfterItems: _Children.Children.oneOf([_TreeNode.TreeNode]),
70
62
  containerRef: _propTypes.default.func,
71
63
  isCollectionFlattened: _propTypes.default.bool,
@@ -25,22 +25,27 @@ var _props = require("./props");
25
25
 
26
26
  var _dec, _dec2, _class, _class2, _temp;
27
27
 
28
+ // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
29
+
28
30
  /**
29
31
  ---
30
32
  parent: TreeBrowser
31
33
  id: TreeBrowser.Node
32
34
  ---
35
+ @tsProps
33
36
  A helper class used to render the :renderBeforeItems and :renderAfterItems
34
37
  in the TreeBrowser.
35
38
  **/
36
- // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
37
39
  let TreeNode = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeNode extends _react.Component {
38
40
  constructor() {
39
41
  super(...arguments);
40
42
  this.ref = null;
41
43
 
42
44
  this.handleRef = el => {
43
- el && this.props.containerRef(el.parentElement);
45
+ if (el && typeof this.props.containerRef === 'function') {
46
+ this.props.containerRef(el.parentElement);
47
+ }
48
+
44
49
  this.ref = el;
45
50
  };
46
51
  }
@@ -80,6 +85,8 @@ let TreeNode = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default),
80
85
  css: styles === null || styles === void 0 ? void 0 : styles.icon
81
86
  }, (0, _callRenderProp.callRenderProp)(itemIcon));
82
87
  }
88
+
89
+ return void 0;
83
90
  }
84
91
 
85
92
  render() {
@@ -98,19 +105,10 @@ let TreeNode = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default),
98
105
  }
99
106
 
100
107
  }, _class2.displayName = "TreeNode", _class2.componentId = 'TreeBrowser.Node', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
101
- id: void 0,
102
108
  size: 'medium',
103
109
  variant: 'folderTree',
104
110
  selected: false,
105
- focused: false,
106
- children: void 0,
107
- itemIcon: void 0,
108
- thumbnail: void 0,
109
- level: void 0,
110
- containerRef: function () {},
111
- parentRef: void 0,
112
- onKeyDown: void 0,
113
- onClick: void 0
111
+ focused: false
114
112
  }, _temp)) || _class) || _class);
115
113
  exports.TreeNode = TreeNode;
116
114
  var _default = TreeNode;
@@ -41,15 +41,7 @@ const propTypes = {
41
41
  itemIcon: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]),
42
42
  thumbnail: _propTypes.default.string,
43
43
  level: _propTypes.default.number,
44
-
45
- /**
46
- * The children to be rendered within the `<TreeNode />`
47
- */
48
44
  children: _propTypes.default.node,
49
-
50
- /**
51
- * A function that returns a reference to the parent li element
52
- */
53
45
  containerRef: _propTypes.default.func,
54
46
  onKeyDown: _propTypes.default.func,
55
47
  onClick: _propTypes.default.func
@@ -15,10 +15,10 @@ var _IconFolderLine = require("@instructure/ui-icons/lib/IconFolderLine.js");
15
15
 
16
16
  var _IconDocumentLine = require("@instructure/ui-icons/lib/IconDocumentLine.js");
17
17
 
18
- var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
19
-
20
18
  var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
21
19
 
20
+ var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
21
+
22
22
  var _testable = require("@instructure/ui-testable/lib/testable.js");
23
23
 
24
24
  var _emotion = require("@instructure/emotion");
@@ -41,6 +41,7 @@ var _dec, _dec2, _class, _class2, _temp;
41
41
  ---
42
42
  category: components
43
43
  ---
44
+ @tsProps
44
45
  **/
45
46
  let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeBrowser extends _react.Component {
46
47
  constructor(props) {
@@ -55,16 +56,17 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
55
56
  e.stopPropagation();
56
57
  const onCollectionClick = _this.props.onCollectionClick;
57
58
  if (expand) _this.expandOrCollapseNode(collection);
58
- onCollectionClick(collection.id, collection); // TODO: this should pass the event as the first arg
59
+ onCollectionClick === null || onCollectionClick === void 0 ? void 0 : onCollectionClick(collection.id, collection); // TODO: this should pass the event as the first arg
59
60
 
60
61
  _this.handleSelection(collection.id, 'collection');
61
62
  };
62
63
 
63
64
  this.handleItemClick = (e, item) => {
65
+ var _this$props$onItemCli, _this$props;
66
+
64
67
  e.stopPropagation();
65
- const onItemClick = this.props.onItemClick;
66
- onItemClick(item);
67
- this.handleSelection(item.id, 'item'); // TODO: this should pass the event as the first arg
68
+ (_this$props$onItemCli = (_this$props = this.props).onItemClick) === null || _this$props$onItemCli === void 0 ? void 0 : _this$props$onItemCli.call(_this$props, item);
69
+ this.handleSelection(item.id, 'item');
68
70
  };
69
71
 
70
72
  this.handleKeyDown = (event, node) => {
@@ -104,31 +106,34 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
104
106
  };
105
107
 
106
108
  this.getIsFlattened = collection => {
107
- const _this$props = this.props,
108
- rootId = _this$props.rootId,
109
- showRootCollection = _this$props.showRootCollection;
109
+ const _this$props2 = this.props,
110
+ rootId = _this$props2.rootId,
111
+ showRootCollection = _this$props2.showRootCollection;
110
112
  return !showRootCollection && typeof rootId !== 'undefined' && collection.id === rootId;
111
113
  };
112
114
 
113
- this.state = {
114
- selection: ''
115
- };
116
-
117
115
  if (typeof this.props.expanded === 'undefined') {
118
- this.state.expanded = props.defaultExpanded;
116
+ this.state = {
117
+ expanded: this.props.defaultExpanded,
118
+ selection: ''
119
+ };
120
+ } else {
121
+ this.state = {
122
+ selection: ''
123
+ };
119
124
  }
120
125
  }
121
126
 
122
127
  componentDidMount() {
123
- var _this$props$makeStyle, _this$props2;
128
+ var _this$props$makeStyle, _this$props3;
124
129
 
125
- (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
130
+ (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3);
126
131
  }
127
132
 
128
133
  componentDidUpdate() {
129
- var _this$props$makeStyle2, _this$props3;
134
+ var _this$props$makeStyle2, _this$props4;
130
135
 
131
- (_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);
132
137
  }
133
138
 
134
139
  get _root() {
@@ -136,9 +141,9 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
136
141
  }
137
142
 
138
143
  get collections() {
139
- const _this$props4 = this.props,
140
- collections = _this$props4.collections,
141
- rootId = _this$props4.rootId;
144
+ const _this$props5 = this.props,
145
+ collections = _this$props5.collections,
146
+ rootId = _this$props5.rootId;
142
147
 
143
148
  if (typeof rootId !== 'undefined') {
144
149
  return [collections[rootId]];
@@ -156,11 +161,13 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
156
161
  }
157
162
 
158
163
  expandOrCollapseNode(collection) {
159
- this.props.onCollectionToggle(collection);
164
+ var _this$props$onCollect, _this$props6;
165
+
166
+ (_this$props$onCollect = (_this$props6 = this.props).onCollectionToggle) === null || _this$props$onCollect === void 0 ? void 0 : _this$props$onCollect.call(_this$props6, collection);
160
167
 
161
168
  if (typeof this.props.expanded === 'undefined') {
162
169
  this.setState((state, props) => {
163
- const expanded = [].concat(this.getExpanded(state, props));
170
+ const expanded = [...this.getExpanded(state, props)];
164
171
  const expandedIndex = this.getExpandedIndex(expanded, collection.id);
165
172
 
166
173
  if (collection.expanded && expandedIndex < 0) {
@@ -261,13 +268,13 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
261
268
  }
262
269
 
263
270
  getSubCollections(collection) {
264
- const collections = [].concat(collection.collections || []);
271
+ const collections = collection.collections ? [...collection.collections] : [];
265
272
  return collections.map(id => this.getCollectionProps(this.props.collections[id])).filter(collection => collection != null).sort(this.props.sortOrder);
266
273
  }
267
274
 
268
275
  getItems(collection) {
269
276
  if (collection.items) {
270
- const items = [].concat(collection.items);
277
+ const items = collection.items ? [...collection.items] : [];
271
278
  return items.map(id => {
272
279
  return { ...this.props.items[id]
273
280
  };
@@ -281,13 +288,13 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
281
288
  return {
282
289
  id: collection.id,
283
290
  name: collection.name,
284
- descriptor: collection.descriptor,
285
- expanded: this.getExpandedIndex(this.expanded, collection.id) >= 0,
286
- items: this.getItems(collection),
287
291
  collections: this.getSubCollections(collection),
292
+ items: this.getItems(collection),
293
+ descriptor: collection.descriptor,
294
+ containerRef: collection.containerRef,
288
295
  renderBeforeItems: collection.renderBeforeItems,
289
296
  renderAfterItems: collection.renderAfterItems,
290
- containerRef: collection.containerRef,
297
+ expanded: this.getExpandedIndex(this.expanded, collection.id) >= 0,
291
298
  isCollectionFlattened: this.getIsFlattened(collection)
292
299
  };
293
300
  }
@@ -336,10 +343,7 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
336
343
  getCollectionProps: props => props,
337
344
  defaultExpanded: [],
338
345
  selectionType: 'none',
339
- onItemClick: function (item) {},
340
- onCollectionClick: function (id, collection) {},
341
- onCollectionToggle: function (collection) {},
342
- sortOrder: function (obj1, obj2) {
346
+ sortOrder: function () {
343
347
  return 0;
344
348
  }
345
349
  }, _class2.Node = _TreeNode.TreeNode, _class2.Collection = _TreeCollection.TreeCollection, _class2.Button = _TreeButton.TreeButton, _temp)) || _class) || _class);
@@ -35,80 +35,25 @@ var _controllable = require("@instructure/ui-prop-types/lib/controllable.js");
35
35
  * SOFTWARE.
36
36
  */
37
37
  const propTypes = {
38
- /**
39
- * a normalized hash of collections, keyed by id, that contain an
40
- * :id, :name, :items (an array of item ids), :collections (an array of
41
- * collection ids), optional :descriptor text, optional :containerRef function,
42
- * an optional :renderBeforeItems TreeNode, and an optional :renderAfterItems TreeNode.
43
- * Each collection must have a unique id.
44
- */
45
38
  collections: _propTypes.default.object.isRequired,
46
-
47
- /**
48
- * a hash of items, keyed by id, that contain an :id, :name,
49
- * optional :descriptor text, and optional :thumbnail url
50
- */
51
39
  items: _propTypes.default.object.isRequired,
52
-
53
- /**
54
- * specifies the id of the root level collection, if present.
55
- * if no root is specified, all collections will be rendered
56
- * at the top level
57
- **/
58
40
  rootId: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
59
-
60
- /**
61
- * an array of expanded collection ids, must be accompanied by an 'onCollectionToggle' prop
62
- */
63
41
  expanded: (0, _controllable.controllable)(_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])), 'onCollectionToggle'),
64
-
65
- /**
66
- * an array of collection ids to expand by default
67
- */
68
42
  defaultExpanded: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])),
69
- // There are 2 types of tree selection: single and multi.
70
- // This is set up to allow for "multi" in the future without having to deprecate the old API.
71
43
  selectionType: _propTypes.default.oneOf(['none', 'single']),
72
44
  size: _propTypes.default.oneOf(['small', 'medium', 'large']),
73
45
  variant: _propTypes.default.oneOf(['folderTree', 'indent']),
74
46
  collectionIcon: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]),
75
47
  collectionIconExpanded: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]),
76
48
  itemIcon: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]),
77
-
78
- /**
79
- * A function called with each item's props as an argument. The return value of this function is a
80
- * props object which will be passed to the item when it is rendered. This is useful for situations where
81
- * you need to render the item differently depending on it's props. For example, if you would like to
82
- * display a different icon for items with a certain name.
83
- */
84
49
  getItemProps: _propTypes.default.func,
85
-
86
- /**
87
- * A function called with each collection's props as an argument. The return value of this function is a
88
- * props object which will be passed to the collection when it is rendered. This is useful for situations where
89
- * you need to render the collection differently depending on it's props. For example, if you would like to
90
- * display a different icon for collections with a certain name.
91
- */
92
50
  getCollectionProps: _propTypes.default.func,
93
-
94
- /**
95
- * whether or not to show the root collection specified in rootId prop or
96
- * to begin with its immediate subcollections and items instead
97
- */
98
51
  showRootCollection: _propTypes.default.bool,
99
52
  onCollectionClick: _propTypes.default.func,
100
53
  onCollectionToggle: _propTypes.default.func,
101
54
  onItemClick: _propTypes.default.func,
102
-
103
- /**
104
- * An optional label to assist visually impaired users
105
- */
106
55
  treeLabel: _propTypes.default.string,
107
56
  renderContent: _propTypes.default.func,
108
-
109
- /**
110
- * An optional compare function to specify order of the collections and the items
111
- */
112
57
  sortOrder: _propTypes.default.func
113
58
  };
114
59
  exports.propTypes = propTypes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-tree-browser",
3
- "version": "8.14.1-snapshot.7+845d7ec6c",
3
+ "version": "8.15.1-snapshot.2+00f55c738",
4
4
  "description": "A component for displaying a hierarchical view of information",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "type": "commonjs",
@@ -24,22 +24,22 @@
24
24
  },
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "@instructure/ui-babel-preset": "8.14.1-snapshot.7+845d7ec6c",
28
- "@instructure/ui-color-utils": "8.14.1-snapshot.7+845d7ec6c",
29
- "@instructure/ui-test-locator": "8.14.1-snapshot.7+845d7ec6c",
30
- "@instructure/ui-test-utils": "8.14.1-snapshot.7+845d7ec6c",
31
- "@instructure/ui-themes": "8.14.1-snapshot.7+845d7ec6c"
27
+ "@instructure/ui-babel-preset": "8.15.1-snapshot.2+00f55c738",
28
+ "@instructure/ui-color-utils": "8.15.1-snapshot.2+00f55c738",
29
+ "@instructure/ui-test-locator": "8.15.1-snapshot.2+00f55c738",
30
+ "@instructure/ui-test-utils": "8.15.1-snapshot.2+00f55c738",
31
+ "@instructure/ui-themes": "8.15.1-snapshot.2+00f55c738"
32
32
  },
33
33
  "dependencies": {
34
34
  "@babel/runtime": "^7.13.10",
35
- "@instructure/emotion": "8.14.1-snapshot.7+845d7ec6c",
36
- "@instructure/shared-types": "8.14.1-snapshot.7+845d7ec6c",
37
- "@instructure/ui-icons": "8.14.1-snapshot.7+845d7ec6c",
38
- "@instructure/ui-img": "8.14.1-snapshot.7+845d7ec6c",
39
- "@instructure/ui-prop-types": "8.14.1-snapshot.7+845d7ec6c",
40
- "@instructure/ui-react-utils": "8.14.1-snapshot.7+845d7ec6c",
41
- "@instructure/ui-testable": "8.14.1-snapshot.7+845d7ec6c",
42
- "@instructure/ui-utils": "8.14.1-snapshot.7+845d7ec6c",
35
+ "@instructure/emotion": "8.15.1-snapshot.2+00f55c738",
36
+ "@instructure/shared-types": "8.15.1-snapshot.2+00f55c738",
37
+ "@instructure/ui-icons": "8.15.1-snapshot.2+00f55c738",
38
+ "@instructure/ui-img": "8.15.1-snapshot.2+00f55c738",
39
+ "@instructure/ui-prop-types": "8.15.1-snapshot.2+00f55c738",
40
+ "@instructure/ui-react-utils": "8.15.1-snapshot.2+00f55c738",
41
+ "@instructure/ui-testable": "8.15.1-snapshot.2+00f55c738",
42
+ "@instructure/ui-utils": "8.15.1-snapshot.2+00f55c738",
43
43
  "keycode": "^2",
44
44
  "prop-types": "^15"
45
45
  },
@@ -50,5 +50,5 @@
50
50
  "access": "public"
51
51
  },
52
52
  "sideEffects": false,
53
- "gitHead": "845d7ec6c159d8946b22caa9d8fb3d0175167a6f"
53
+ "gitHead": "00f55c7382e82209ea553c107951c4356ba202bf"
54
54
  }
@@ -35,15 +35,15 @@ import generateComponentTheme from './theme'
35
35
  import type { TreeBrowserButtonProps } from './props'
36
36
  import { allowedProps, propTypes } from './props'
37
37
 
38
+ // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
39
+
38
40
  /**
39
41
  ---
40
42
  parent: TreeBrowser
41
43
  id: TreeBrowser.Button
42
44
  ---
45
+ @tsProps
43
46
  **/
44
-
45
- // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
46
-
47
47
  @withStyle(generateStyles, generateComponentTheme)
48
48
  @testable()
49
49
  class TreeButton extends Component<TreeBrowserButtonProps> {
@@ -51,44 +51,35 @@ class TreeButton extends Component<TreeBrowserButtonProps> {
51
51
 
52
52
  static allowedProps = allowedProps
53
53
  static propTypes = propTypes
54
+
54
55
  static defaultProps = {
55
56
  type: 'treeButton',
56
57
  size: 'medium',
57
58
  variant: 'folderTree',
58
59
  selected: false,
59
60
  focused: false,
60
- onClick: function () {},
61
- id: undefined,
62
- name: undefined,
63
- collectionIcon: undefined,
64
- collectionIconExpanded: undefined,
65
- itemIcon: undefined,
66
- thumbnail: undefined,
67
- expanded: false,
68
- descriptor: undefined,
69
- level: undefined,
70
- containerRef: function () {},
71
- renderContent: undefined
61
+ expanded: false
72
62
  }
63
+
73
64
  ref: Element | null = null
74
65
 
75
66
  componentDidMount() {
76
67
  this.props.makeStyles?.()
77
68
  }
69
+
78
70
  componentDidUpdate() {
79
71
  this.props.makeStyles?.()
80
72
  }
81
73
 
82
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'props' implicitly has an 'any' type.
83
- defaultContentRenderer(props) {
74
+ defaultContentRenderer(props: TreeBrowserButtonProps) {
84
75
  const { name, descriptor, styles } = props
85
76
  return (
86
- <span css={styles.layout}>
77
+ <span css={styles!.layout}>
87
78
  {this.renderImage()}
88
- <span css={styles.text}>
89
- <span css={styles.textName}>{name}</span>
79
+ <span css={styles!.text}>
80
+ <span css={styles!.textName}>{name}</span>
90
81
  {descriptor ? (
91
- <span css={styles.textDescriptor} title={descriptor}>
82
+ <span css={styles!.textDescriptor} title={descriptor}>
92
83
  {descriptor}
93
84
  </span>
94
85
  ) : null}
@@ -97,7 +88,6 @@ class TreeButton extends Component<TreeBrowserButtonProps> {
97
88
  )
98
89
  }
99
90
 
100
- // @ts-expect-error ts-migrate(7030) FIXME: Not all code paths return a value.
101
91
  renderImage() {
102
92
  const { type } = this.props
103
93
  switch (type) {
@@ -108,16 +98,12 @@ class TreeButton extends Component<TreeBrowserButtonProps> {
108
98
  default:
109
99
  break
110
100
  }
101
+ return undefined
111
102
  }
112
103
 
113
- // @ts-expect-error ts-migrate(7030) FIXME: Not all code paths return a value.
114
104
  renderCollectionIcon() {
115
- const {
116
- expanded,
117
- collectionIcon,
118
- collectionIconExpanded,
119
- styles
120
- } = this.props
105
+ const { expanded, collectionIcon, collectionIconExpanded, styles } =
106
+ this.props
121
107
 
122
108
  if (collectionIcon || collectionIconExpanded) {
123
109
  return (
@@ -126,12 +112,11 @@ class TreeButton extends Component<TreeBrowserButtonProps> {
126
112
  </div>
127
113
  )
128
114
  }
115
+ return undefined
129
116
  }
130
117
 
131
- // @ts-expect-error ts-migrate(7030) FIXME: Not all code paths return a value.
132
118
  renderItemImage() {
133
119
  const { thumbnail, itemIcon, styles } = this.props
134
-
135
120
  if (thumbnail) {
136
121
  return (
137
122
  <div css={styles?.thumbnail}>
@@ -139,16 +124,16 @@ class TreeButton extends Component<TreeBrowserButtonProps> {
139
124
  </div>
140
125
  )
141
126
  }
142
-
143
127
  if (itemIcon) {
144
128
  return <div css={styles?.icon}>{callRenderProp(itemIcon)}</div>
145
129
  }
130
+ return undefined
146
131
  }
147
132
 
148
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'el' implicitly has an 'any' type.
149
- handleRef = (el) => {
150
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
151
- el && this.props.containerRef(el.parentElement)
133
+ handleRef = (el: HTMLButtonElement) => {
134
+ if (el && typeof this.props.containerRef === 'function') {
135
+ this.props.containerRef(el.parentElement)
136
+ }
152
137
  this.ref = el
153
138
  }
154
139