@workday/canvas-kit-react 7.2.0-next.0 → 7.2.0

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 (95) hide show
  1. package/action-bar/lib/ActionBarList.tsx +2 -9
  2. package/action-bar/package.json +2 -1
  3. package/avatar/package.json +2 -1
  4. package/badge/package.json +2 -1
  5. package/banner/package.json +2 -1
  6. package/button/lib/TertiaryButton.tsx +18 -7
  7. package/button/package.json +2 -1
  8. package/card/package.json +2 -1
  9. package/checkbox/package.json +2 -1
  10. package/collection/index.ts +2 -0
  11. package/collection/lib/useBaseListModel.tsx +1 -1
  12. package/collection/lib/useCursorListModel.tsx +88 -20
  13. package/collection/lib/useGridModel.ts +34 -0
  14. package/collection/lib/useListItemRovingFocus.tsx +6 -4
  15. package/collection/package.json +2 -1
  16. package/color-picker/package.json +2 -1
  17. package/common/package.json +2 -1
  18. package/dialog/package.json +2 -1
  19. package/disclosure/package.json +2 -1
  20. package/dist/commonjs/action-bar/lib/ActionBarList.d.ts +0 -58
  21. package/dist/commonjs/action-bar/lib/ActionBarList.d.ts.map +1 -1
  22. package/dist/commonjs/action-bar/lib/ActionBarList.js +2 -3
  23. package/dist/commonjs/button/lib/TertiaryButton.d.ts +9 -0
  24. package/dist/commonjs/button/lib/TertiaryButton.d.ts.map +1 -1
  25. package/dist/commonjs/button/lib/TertiaryButton.js +9 -8
  26. package/dist/commonjs/collection/index.d.ts +2 -0
  27. package/dist/commonjs/collection/index.d.ts.map +1 -1
  28. package/dist/commonjs/collection/index.js +5 -1
  29. package/dist/commonjs/collection/lib/useBaseListModel.js +1 -1
  30. package/dist/commonjs/collection/lib/useCursorListModel.d.ts +64 -101
  31. package/dist/commonjs/collection/lib/useCursorListModel.d.ts.map +1 -1
  32. package/dist/commonjs/collection/lib/useCursorListModel.js +64 -23
  33. package/dist/commonjs/collection/lib/useGridModel.d.ts +955 -0
  34. package/dist/commonjs/collection/lib/useGridModel.d.ts.map +1 -0
  35. package/dist/commonjs/collection/lib/useGridModel.js +52 -0
  36. package/dist/commonjs/collection/lib/useListItemRovingFocus.d.ts.map +1 -1
  37. package/dist/commonjs/collection/lib/useListItemRovingFocus.js +6 -4
  38. package/dist/commonjs/pagination/lib/Pagination/PageButton.d.ts.map +1 -1
  39. package/dist/commonjs/pagination/lib/Pagination/PageButton.js +0 -1
  40. package/dist/commonjs/pagination/lib/Pagination/common/useLiveRegion.d.ts +0 -1
  41. package/dist/commonjs/pagination/lib/Pagination/common/useLiveRegion.d.ts.map +1 -1
  42. package/dist/commonjs/pagination/lib/Pagination/common/useLiveRegion.js +1 -1
  43. package/dist/commonjs/radio/lib/RadioGroup.d.ts.map +1 -1
  44. package/dist/commonjs/radio/lib/RadioGroup.js +5 -1
  45. package/dist/es6/action-bar/lib/ActionBarList.d.ts +0 -58
  46. package/dist/es6/action-bar/lib/ActionBarList.d.ts.map +1 -1
  47. package/dist/es6/action-bar/lib/ActionBarList.js +3 -4
  48. package/dist/es6/button/lib/TertiaryButton.d.ts +9 -0
  49. package/dist/es6/button/lib/TertiaryButton.d.ts.map +1 -1
  50. package/dist/es6/button/lib/TertiaryButton.js +9 -8
  51. package/dist/es6/collection/index.d.ts +2 -0
  52. package/dist/es6/collection/index.d.ts.map +1 -1
  53. package/dist/es6/collection/index.js +2 -0
  54. package/dist/es6/collection/lib/useBaseListModel.js +1 -1
  55. package/dist/es6/collection/lib/useCursorListModel.d.ts +64 -101
  56. package/dist/es6/collection/lib/useCursorListModel.d.ts.map +1 -1
  57. package/dist/es6/collection/lib/useCursorListModel.js +64 -23
  58. package/dist/es6/collection/lib/useGridModel.d.ts +955 -0
  59. package/dist/es6/collection/lib/useGridModel.d.ts.map +1 -0
  60. package/dist/es6/collection/lib/useGridModel.js +49 -0
  61. package/dist/es6/collection/lib/useListItemRovingFocus.d.ts.map +1 -1
  62. package/dist/es6/collection/lib/useListItemRovingFocus.js +6 -4
  63. package/dist/es6/pagination/lib/Pagination/PageButton.d.ts.map +1 -1
  64. package/dist/es6/pagination/lib/Pagination/PageButton.js +0 -1
  65. package/dist/es6/pagination/lib/Pagination/common/useLiveRegion.d.ts +0 -1
  66. package/dist/es6/pagination/lib/Pagination/common/useLiveRegion.d.ts.map +1 -1
  67. package/dist/es6/pagination/lib/Pagination/common/useLiveRegion.js +1 -1
  68. package/dist/es6/radio/lib/RadioGroup.d.ts.map +1 -1
  69. package/dist/es6/radio/lib/RadioGroup.js +5 -1
  70. package/form-field/package.json +2 -1
  71. package/icon/package.json +2 -1
  72. package/layout/package.json +2 -1
  73. package/loading-animation/package.json +2 -1
  74. package/menu/package.json +2 -1
  75. package/modal/package.json +2 -1
  76. package/package.json +5 -5
  77. package/pagination/lib/Pagination/PageButton.tsx +0 -1
  78. package/pagination/lib/Pagination/common/useLiveRegion.tsx +0 -2
  79. package/pagination/package.json +2 -1
  80. package/popup/package.json +2 -1
  81. package/radio/lib/RadioGroup.tsx +5 -1
  82. package/radio/package.json +2 -1
  83. package/segmented-control/package.json +2 -1
  84. package/select/package.json +2 -1
  85. package/side-panel/package.json +2 -1
  86. package/skeleton/package.json +2 -1
  87. package/status-indicator/package.json +2 -1
  88. package/switch/package.json +2 -1
  89. package/table/package.json +2 -1
  90. package/tabs/package.json +2 -1
  91. package/text-area/package.json +2 -1
  92. package/text-input/package.json +2 -1
  93. package/toast/package.json +2 -1
  94. package/tokens/package.json +2 -1
  95. package/tooltip/package.json +2 -1
@@ -50,8 +50,8 @@ export var getLast = function (_, _a) {
50
50
  export var getFirstOfRow = function (id, _a) {
51
51
  var state = _a.state;
52
52
  if (state.columnCount) {
53
- var item_1 = getItem(id, { state: state });
54
- var currentIndex = state.items.findIndex(function (i) { return getId(item_1) === getId(i); });
53
+ var item = getItem(id, { state: state });
54
+ var currentIndex = item.index;
55
55
  var offset = currentIndex % state.columnCount;
56
56
  return state.items[currentIndex - offset];
57
57
  }
@@ -63,10 +63,14 @@ export var getFirstOfRow = function (id, _a) {
63
63
  export var getLastOfRow = function (id, _a) {
64
64
  var state = _a.state;
65
65
  if (state.columnCount) {
66
- var item_2 = getItem(id, { state: state });
67
- var currentIndex = state.items.findIndex(function (i) { return getId(item_2) === getId(i); });
66
+ var item = getItem(id, { state: state });
67
+ var currentIndex = item.index;
68
68
  var offset = (currentIndex % state.columnCount) - state.columnCount + 1;
69
- return state.items[currentIndex - offset];
69
+ var nextIndex = currentIndex - offset;
70
+ if (nextIndex >= state.items.length) {
71
+ nextIndex = state.items.length - 1;
72
+ }
73
+ return state.items[nextIndex];
70
74
  }
71
75
  return getLast(id, { state: state });
72
76
  };
@@ -77,8 +81,8 @@ export var getLastOfRow = function (id, _a) {
77
81
  export var getPreviousPage = function (id, _a) {
78
82
  var state = _a.state;
79
83
  if (state.columnCount) {
80
- var item_3 = getItem(id, { state: state });
81
- var currentIndex = state.items.findIndex(function (i) { return getId(item_3) === getId(i); });
84
+ var item = getItem(id, { state: state });
85
+ var currentIndex = item.index;
82
86
  return state.items[currentIndex % state.columnCount];
83
87
  }
84
88
  return getFirst(id, { state: state });
@@ -90,8 +94,8 @@ export var getPreviousPage = function (id, _a) {
90
94
  export var getNextPage = function (id, _a) {
91
95
  var state = _a.state;
92
96
  if (state.columnCount) {
93
- var item_4 = getItem(id, { state: state });
94
- var currentIndex = state.items.findIndex(function (i) { return getId(item_4) === getId(i); });
97
+ var item = getItem(id, { state: state });
98
+ var currentIndex = item.index;
95
99
  var lastRowIndex = state.items.length - state.columnCount;
96
100
  return state.items[lastRowIndex + (currentIndex % state.columnCount)];
97
101
  }
@@ -108,13 +112,40 @@ export var getWrappingOffsetItem = function (offset) { return function (id, _a,
108
112
  if (tries === void 0) { tries = state.items.length; }
109
113
  var items = state.items;
110
114
  var item = getItem(id, { state: state });
111
- var currentIndex = items.findIndex(function (i) { return getId(item) === getId(i); });
115
+ var currentIndex = item.index;
112
116
  var nextIndex = currentIndex + offset;
117
+ // calculate idealLength as in if the grid was a perfect rectangle
118
+ var rows = Math.ceil(items.length / state.columnCount);
119
+ var idealLength = rows * state.columnCount;
113
120
  if (nextIndex < 0) {
114
- nextIndex = items.length + nextIndex;
121
+ if (offset === -1) {
122
+ // if the offset is -1, we want to wrap to the end
123
+ nextIndex = items.length - 1;
124
+ }
125
+ else {
126
+ // if the offset is smaller than -1, we want to wrap by column
127
+ if (idealLength + nextIndex >= items.length) {
128
+ // we'll overflow the grid because there isn't enough items. Move `nextIndex` up so we wrap in
129
+ // the right spot
130
+ nextIndex -= state.columnCount;
131
+ }
132
+ nextIndex = idealLength + nextIndex;
133
+ }
115
134
  }
116
135
  else if (nextIndex >= items.length) {
117
- nextIndex = nextIndex - items.length;
136
+ if (offset === 1) {
137
+ // if the offset is 1, we want to wrap to the beginning
138
+ nextIndex = 0;
139
+ }
140
+ else {
141
+ // if the offset is larger than 1, we want to wrap by column
142
+ if (nextIndex - idealLength < 0) {
143
+ // we're going to overflow the grid because there isn't enough items. Move `nextIndex` down to
144
+ // the missing item in the next row. This way we'll end up wrapping in the right spot
145
+ nextIndex += state.columnCount;
146
+ }
147
+ nextIndex = nextIndex - idealLength;
148
+ }
118
149
  }
119
150
  if (state.nonInteractiveIds.includes(getId(items[nextIndex])) && tries > 0) {
120
151
  // The next item is disabled, try again, but only if we haven't already tried everything.
@@ -128,7 +159,7 @@ export var getOffsetItem = function (offset) { return function (id, _a, tries) {
128
159
  if (tries === void 0) { tries = state.items.length; }
129
160
  var items = state.items, columnCount = state.columnCount;
130
161
  var item = getItem(id, { state: state });
131
- var currentIndex = items.findIndex(function (i) { return getId(item) === getId(i); });
162
+ var currentIndex = item.index;
132
163
  var nextIndex = currentIndex + offset;
133
164
  if (Math.abs(offset) < columnCount) {
134
165
  // if we're here, the columnCount is non-zero and the absolute value of offset is less than the
@@ -146,8 +177,13 @@ export var getOffsetItem = function (offset) { return function (id, _a, tries) {
146
177
  if (nextRow < 0 || nextRow >= columnCount) {
147
178
  nextIndex = currentIndex;
148
179
  }
180
+ // make sure we don't go out of bounds if the grid isn't a perfect rectangle
181
+ if (nextIndex > items.length - 1) {
182
+ nextIndex = currentIndex;
183
+ }
149
184
  }
150
- else if (nextIndex < 0) {
185
+ // make sure we're always in bounds
186
+ if (nextIndex < 0) {
151
187
  nextIndex = 0;
152
188
  }
153
189
  else if (nextIndex >= items.length) {
@@ -161,7 +197,9 @@ export var getOffsetItem = function (offset) { return function (id, _a, tries) {
161
197
  return items[nextIndex];
162
198
  }; };
163
199
  /**
164
- * The default navigation manager of lists
200
+ * The default navigation manager of lists. This navigation manager will wrap around when the edge
201
+ * is hit. For example, if the user is the the right-most item in a list or right-most item in a
202
+ * row, the cursor will wrap around to the beginning or the next row.
165
203
  */
166
204
  export var wrappingNavigationManager = createNavigationManager({
167
205
  getFirst: getFirst,
@@ -170,18 +208,22 @@ export var wrappingNavigationManager = createNavigationManager({
170
208
  getNext: getWrappingOffsetItem(1),
171
209
  getNextRow: function (id, _a) {
172
210
  var state = _a.state;
173
- return getWrappingOffsetItem(-state.columnCount)(id, { state: state });
211
+ return getWrappingOffsetItem(state.columnCount)(id, { state: state });
174
212
  },
175
213
  getPrevious: getWrappingOffsetItem(-1),
176
214
  getPreviousRow: function (id, _a) {
177
215
  var state = _a.state;
178
- return getWrappingOffsetItem(state.columnCount)(id, { state: state });
216
+ return getWrappingOffsetItem(-state.columnCount)(id, { state: state });
179
217
  },
180
218
  getPreviousPage: getPreviousPage,
181
219
  getNextPage: getNextPage,
182
220
  getFirstOfRow: getFirstOfRow,
183
221
  getLastOfRow: getLastOfRow,
184
222
  });
223
+ /**
224
+ * The default navigation of grids. This navigation manager will not wrap, but will stop when an
225
+ * edge is detected. This could be the last item in a list or the last item of a row in a grid.
226
+ */
185
227
  export var navigationManager = createNavigationManager({
186
228
  getFirst: getFirst,
187
229
  getLast: getLast,
@@ -189,12 +231,12 @@ export var navigationManager = createNavigationManager({
189
231
  getNext: getOffsetItem(1),
190
232
  getNextRow: function (id, _a) {
191
233
  var state = _a.state;
192
- return getOffsetItem(-state.columnCount)(id, { state: state });
234
+ return getOffsetItem(state.columnCount)(id, { state: state });
193
235
  },
194
236
  getPrevious: getOffsetItem(-1),
195
237
  getPreviousRow: function (id, _a) {
196
238
  var state = _a.state;
197
- return getOffsetItem(state.columnCount)(id, { state: state });
239
+ return getOffsetItem(-state.columnCount)(id, { state: state });
198
240
  },
199
241
  getPreviousPage: getPreviousPage,
200
242
  getNextPage: getNextPage,
@@ -223,9 +265,7 @@ export var useCursorListModel = createModelHook({
223
265
  * (left-to-right or right-to-left) and call the correct navigation method. In our example, a
224
266
  * left-to-right language would send a `getNext`. The navigation manager may return the next item
225
267
  * in the list. Different managers can be created for slightly different use cases. The default
226
- * navigation manager will accept `orientation` and directionality to determine mapping. If
227
- * `columnCount` is non-zero, it will use a grid mode where `orientation` is ignored and only
228
- * directionality matters.
268
+ * navigation manager will accept `orientation` and directionality to determine mapping.
229
269
  *
230
270
  * An example override might be a tab list with an overflow menu that is meant to be transparent
231
271
  * to screen reader users. This would require the overflow menu to accept both up/down keys as
@@ -239,15 +279,16 @@ export var useCursorListModel = createModelHook({
239
279
  var columnCount = config.columnCount || 0;
240
280
  var list = useBaseListModel(config);
241
281
  var initialCurrentRef = React.useRef(config.initialCursorId || (((_a = config.items) === null || _a === void 0 ? void 0 : _a.length) ? getId(config.items[0]) : ''));
282
+ var navigation = config.navigation;
242
283
  var state = __assign(__assign({}, list.state), {
243
284
  /** The id of the list item the cursor is pointing to */
244
285
  cursorId: cursorId,
245
286
  /**
246
287
  * Any positive non-zero value treats the list like a grid with rows and columns
247
288
  * @default 0
289
+ * @private Use useGridModel instead to make a grid instead of a list
248
290
  */
249
291
  columnCount: columnCount });
250
- var navigation = config.navigation || wrappingNavigationManager;
251
292
  var events = __assign(__assign({}, list.events), {
252
293
  /**
253
294
  * Register an item to the list. Takes in an identifier, a React.Ref and an optional index. This