@itwin/itwinui-react 1.24.0 → 1.27.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 (130) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/cjs/core/Buttons/Button/Button.d.ts +1 -1
  3. package/cjs/core/Buttons/Button/Button.js +4 -5
  4. package/cjs/core/Buttons/IconButton/IconButton.js +2 -3
  5. package/cjs/core/Checkbox/Checkbox.d.ts +11 -0
  6. package/cjs/core/Checkbox/Checkbox.js +14 -4
  7. package/cjs/core/ColorPicker/ColorBuilder.js +1 -1
  8. package/cjs/core/ColorPicker/ColorInputPanel.js +43 -21
  9. package/cjs/core/ColorPicker/ColorPalette.js +1 -1
  10. package/cjs/core/ColorPicker/ColorPicker.js +2 -2
  11. package/cjs/core/ColorPicker/ColorPickerContext.d.ts +2 -2
  12. package/cjs/core/ColorPicker/ColorSwatch.d.ts +1 -1
  13. package/cjs/core/ColorPicker/ColorSwatch.js +10 -6
  14. package/cjs/core/ComboBox/ComboBox.d.ts +2 -2
  15. package/cjs/core/DatePicker/DatePicker.d.ts +1 -1
  16. package/cjs/core/ErrorPage/ErrorPage.d.ts +2 -1
  17. package/cjs/core/ErrorPage/ErrorPage.js +3 -2
  18. package/cjs/core/InformationPanel/InformationPanel.d.ts +4 -1
  19. package/cjs/core/InformationPanel/InformationPanel.js +4 -1
  20. package/cjs/core/InformationPanel/InformationPanelContent.d.ts +42 -0
  21. package/cjs/core/InformationPanel/InformationPanelContent.js +66 -0
  22. package/cjs/core/InformationPanel/index.d.ts +2 -0
  23. package/cjs/core/InformationPanel/index.js +3 -1
  24. package/cjs/core/Label/Label.d.ts +31 -0
  25. package/cjs/core/Label/Label.js +53 -0
  26. package/cjs/core/Label/index.d.ts +4 -0
  27. package/cjs/core/Label/index.js +10 -0
  28. package/cjs/core/LabeledInput/LabeledInput.d.ts +2 -2
  29. package/cjs/core/LabeledTextarea/LabeledTextarea.d.ts +1 -1
  30. package/cjs/core/Menu/MenuItem.d.ts +1 -1
  31. package/cjs/core/Modal/ModalButtonBar.d.ts +2 -1
  32. package/cjs/core/Modal/ModalButtonBar.js +3 -2
  33. package/cjs/core/Table/Table.d.ts +8 -0
  34. package/cjs/core/Table/Table.js +71 -10
  35. package/cjs/core/Table/TableCell.js +1 -1
  36. package/cjs/core/Table/TablePaginator.d.ts +7 -7
  37. package/cjs/core/Table/TablePaginator.js +20 -10
  38. package/cjs/core/Table/TableRowMemoized.d.ts +21 -0
  39. package/cjs/core/Table/TableRowMemoized.js +6 -3
  40. package/cjs/core/Table/actionHandlers/resizeHandler.d.ts +51 -0
  41. package/cjs/core/Table/actionHandlers/resizeHandler.js +22 -0
  42. package/cjs/core/Table/actionHandlers/selectHandler.d.ts +10 -7
  43. package/cjs/core/Table/hooks/index.d.ts +1 -0
  44. package/cjs/core/Table/hooks/index.js +3 -1
  45. package/cjs/core/Table/hooks/useResizeColumns.d.ts +5 -0
  46. package/cjs/core/Table/hooks/useResizeColumns.js +271 -0
  47. package/cjs/core/Table/utils.d.ts +1 -1
  48. package/cjs/core/Table/utils.js +8 -2
  49. package/cjs/core/Tabs/Tabs.d.ts +4 -0
  50. package/cjs/core/Tabs/Tabs.js +23 -29
  51. package/cjs/core/index.d.ts +6 -4
  52. package/cjs/core/index.js +6 -2
  53. package/cjs/core/utils/color/ColorValue.d.ts +1 -0
  54. package/cjs/core/utils/color/ColorValue.js +96 -84
  55. package/cjs/core/utils/components/MiddleTextTruncation.d.ts +21 -0
  56. package/cjs/core/utils/components/MiddleTextTruncation.js +56 -0
  57. package/cjs/core/utils/components/index.d.ts +1 -0
  58. package/cjs/core/utils/components/index.js +1 -0
  59. package/cjs/core/utils/hooks/index.d.ts +1 -0
  60. package/cjs/core/utils/hooks/index.js +1 -0
  61. package/cjs/core/utils/hooks/useContainerWidth.d.ts +17 -0
  62. package/cjs/core/utils/hooks/useContainerWidth.js +50 -0
  63. package/cjs/core/utils/hooks/useOverflow.d.ts +1 -1
  64. package/cjs/core/utils/hooks/useOverflow.js +30 -17
  65. package/cjs/types/react-table-config.d.ts +16 -3
  66. package/esm/core/Buttons/Button/Button.d.ts +1 -1
  67. package/esm/core/Buttons/Button/Button.js +4 -5
  68. package/esm/core/Buttons/IconButton/IconButton.js +2 -3
  69. package/esm/core/Checkbox/Checkbox.d.ts +11 -0
  70. package/esm/core/Checkbox/Checkbox.js +14 -4
  71. package/esm/core/ColorPicker/ColorBuilder.js +1 -1
  72. package/esm/core/ColorPicker/ColorInputPanel.js +43 -21
  73. package/esm/core/ColorPicker/ColorPalette.js +1 -1
  74. package/esm/core/ColorPicker/ColorPicker.js +2 -2
  75. package/esm/core/ColorPicker/ColorPickerContext.d.ts +2 -2
  76. package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
  77. package/esm/core/ColorPicker/ColorSwatch.js +10 -6
  78. package/esm/core/ComboBox/ComboBox.d.ts +2 -2
  79. package/esm/core/DatePicker/DatePicker.d.ts +1 -1
  80. package/esm/core/ErrorPage/ErrorPage.d.ts +2 -1
  81. package/esm/core/ErrorPage/ErrorPage.js +3 -2
  82. package/esm/core/InformationPanel/InformationPanel.d.ts +4 -1
  83. package/esm/core/InformationPanel/InformationPanel.js +4 -1
  84. package/esm/core/InformationPanel/InformationPanelContent.d.ts +42 -0
  85. package/esm/core/InformationPanel/InformationPanelContent.js +59 -0
  86. package/esm/core/InformationPanel/index.d.ts +2 -0
  87. package/esm/core/InformationPanel/index.js +1 -0
  88. package/esm/core/Label/Label.d.ts +31 -0
  89. package/esm/core/Label/Label.js +46 -0
  90. package/esm/core/Label/index.d.ts +4 -0
  91. package/esm/core/Label/index.js +6 -0
  92. package/esm/core/LabeledInput/LabeledInput.d.ts +2 -2
  93. package/esm/core/LabeledTextarea/LabeledTextarea.d.ts +1 -1
  94. package/esm/core/Menu/MenuItem.d.ts +1 -1
  95. package/esm/core/Modal/ModalButtonBar.d.ts +2 -1
  96. package/esm/core/Modal/ModalButtonBar.js +3 -2
  97. package/esm/core/Table/Table.d.ts +8 -0
  98. package/esm/core/Table/Table.js +73 -12
  99. package/esm/core/Table/TableCell.js +1 -1
  100. package/esm/core/Table/TablePaginator.d.ts +7 -7
  101. package/esm/core/Table/TablePaginator.js +21 -11
  102. package/esm/core/Table/TableRowMemoized.d.ts +21 -0
  103. package/esm/core/Table/TableRowMemoized.js +4 -2
  104. package/esm/core/Table/actionHandlers/resizeHandler.d.ts +51 -0
  105. package/esm/core/Table/actionHandlers/resizeHandler.js +17 -0
  106. package/esm/core/Table/actionHandlers/selectHandler.d.ts +10 -7
  107. package/esm/core/Table/hooks/index.d.ts +1 -0
  108. package/esm/core/Table/hooks/index.js +1 -0
  109. package/esm/core/Table/hooks/useResizeColumns.d.ts +5 -0
  110. package/esm/core/Table/hooks/useResizeColumns.js +267 -0
  111. package/esm/core/Table/utils.d.ts +1 -1
  112. package/esm/core/Table/utils.js +8 -2
  113. package/esm/core/Tabs/Tabs.d.ts +4 -0
  114. package/esm/core/Tabs/Tabs.js +24 -30
  115. package/esm/core/index.d.ts +6 -4
  116. package/esm/core/index.js +3 -2
  117. package/esm/core/utils/color/ColorValue.d.ts +1 -0
  118. package/esm/core/utils/color/ColorValue.js +96 -84
  119. package/esm/core/utils/components/MiddleTextTruncation.d.ts +21 -0
  120. package/esm/core/utils/components/MiddleTextTruncation.js +49 -0
  121. package/esm/core/utils/components/index.d.ts +1 -0
  122. package/esm/core/utils/components/index.js +1 -0
  123. package/esm/core/utils/hooks/index.d.ts +1 -0
  124. package/esm/core/utils/hooks/index.js +1 -0
  125. package/esm/core/utils/hooks/useContainerWidth.d.ts +17 -0
  126. package/esm/core/utils/hooks/useContainerWidth.js +43 -0
  127. package/esm/core/utils/hooks/useOverflow.d.ts +1 -1
  128. package/esm/core/utils/hooks/useOverflow.js +30 -17
  129. package/esm/types/react-table-config.d.ts +16 -3
  130. package/package.json +13 -5
@@ -170,6 +170,7 @@ export declare class ColorValue {
170
170
  private static toHsv;
171
171
  /** True if the value of this ColorValue is the same as another ColorValue. */
172
172
  equals(other: ColorValue): boolean;
173
+ static getFormattedColorNumber(value: number, precision?: number): string;
173
174
  /** Convert the 0xTTBBGGRR color to a string of the form "rgba(r,g,b,a)" where the color components are specified in decimal and the alpha component is a fraction. */
174
175
  toRgbString(includeAlpha?: boolean): string;
175
176
  /** Convert this ColorValue to a string in the form "hsl(h,s,l) or hsla(h,s,l,a)" - i.e hsl(120,50%,50%). */
@@ -127,19 +127,20 @@ var ColorValue = /** @class */ (function () {
127
127
  * This allows component builders to know if they received bad input from user.
128
128
  */
129
129
  ColorValue.fromString = function (val, defaultColorIfNotParsed) {
130
- return this.fromTbgr(this.computeTbgrFromString(val, defaultColorIfNotParsed === null || defaultColorIfNotParsed === void 0 ? void 0 : defaultColorIfNotParsed.toTbgr()));
130
+ var _a = this.computeTbgrFromString(val, defaultColorIfNotParsed === null || defaultColorIfNotParsed === void 0 ? void 0 : defaultColorIfNotParsed.toTbgr()), tbgr = _a[0], hue = _a[1];
131
+ return new ColorValue(tbgr, hue);
131
132
  };
132
133
  /** Create a ColorValue from hue, saturation, lightness values. */
133
134
  ColorValue.fromHSL = function (hsl) {
134
135
  var _a;
135
136
  var alpha = (_a = hsl.a) !== null && _a !== void 0 ? _a : 1;
136
- return new ColorValue(this.computeTbgrFromHSL(hsl.h / 360, hsl.s / 100, hsl.l / 100, (1 - alpha) * 255), hsl.h);
137
+ return new ColorValue(this.computeTbgrFromHSL(hsl.h / 360, hsl.s / 100, hsl.l / 100, Math.round((1 - alpha) * 255)), hsl.h);
137
138
  };
138
139
  /** Create a ColorValue from an RgbColor */
139
140
  ColorValue.fromRGB = function (rgb) {
140
141
  var _a;
141
142
  var alpha = (_a = rgb.a) !== null && _a !== void 0 ? _a : 1;
142
- return ColorValue.fromRgbt(rgb.r, rgb.g, rgb.b, (1 - alpha) * 255);
143
+ return ColorValue.fromRgbt(rgb.r, rgb.g, rgb.b, Math.round((1 - alpha) * 255));
143
144
  };
144
145
  /**
145
146
  * Create a ColorValue from an HsvColor
@@ -147,7 +148,7 @@ var ColorValue = /** @class */ (function () {
147
148
  ColorValue.fromHSV = function (hsv) {
148
149
  var _a;
149
150
  var alpha = (_a = hsv.a) !== null && _a !== void 0 ? _a : 1;
150
- var transparency = (1 - alpha) * 255;
151
+ var transparency = Math.round((1 - alpha) * 255);
151
152
  // Check for simple case first.
152
153
  if (!hsv.s || hsv.h === -1) {
153
154
  // hue must be undefined, have no color only white
@@ -232,7 +233,12 @@ var ColorValue = /** @class */ (function () {
232
233
  color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components);
233
234
  if (color) {
234
235
  // rgb(255,0,0) rgba(255,0,0,0.5)
235
- return this.computeTbgrFromComponents(intOrPercent(color[1]), intOrPercent(color[2]), intOrPercent(color[3]), typeof color[4] === 'string' ? 255 - floatOrPercent(color[4]) : 0);
236
+ return [
237
+ this.computeTbgrFromComponents(intOrPercent(color[1]), intOrPercent(color[2]), intOrPercent(color[3]), typeof color[4] === 'string'
238
+ ? 255 - floatOrPercent(color[4])
239
+ : 0),
240
+ undefined,
241
+ ];
236
242
  }
237
243
  break;
238
244
  case 'hsl':
@@ -240,11 +246,11 @@ var ColorValue = /** @class */ (function () {
240
246
  color = /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components);
241
247
  if (color) {
242
248
  // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
243
- var h = parseFloat(color[1]) / 360;
249
+ var h = parseFloat(color[1]);
244
250
  var s = parseInt(color[2], 10) / 100;
245
251
  var l = parseInt(color[3], 10) / 100;
246
252
  var t = typeof color[4] === 'string' ? 255 - floatOrPercent(color[4]) : 0;
247
- return this.computeTbgrFromHSL(h, s, l, t);
253
+ return [this.computeTbgrFromHSL(h / 360, s, l, t), h];
248
254
  }
249
255
  break;
250
256
  }
@@ -256,19 +262,28 @@ var ColorValue = /** @class */ (function () {
256
262
  var size = hex.length;
257
263
  if (size === 3) {
258
264
  // #ff0
259
- return this.computeTbgrFromComponents(parseInt(hex.charAt(0) + hex.charAt(0), 16), parseInt(hex.charAt(1) + hex.charAt(1), 16), parseInt(hex.charAt(2) + hex.charAt(2), 16), 0);
265
+ return [
266
+ this.computeTbgrFromComponents(parseInt(hex.charAt(0) + hex.charAt(0), 16), parseInt(hex.charAt(1) + hex.charAt(1), 16), parseInt(hex.charAt(2) + hex.charAt(2), 16), 0),
267
+ undefined,
268
+ ];
260
269
  }
261
270
  if (size === 6) {
262
271
  // #ff0000
263
- return this.computeTbgrFromComponents(parseInt(hex.charAt(0) + hex.charAt(1), 16), parseInt(hex.charAt(2) + hex.charAt(3), 16), parseInt(hex.charAt(4) + hex.charAt(5), 16), 0);
272
+ return [
273
+ this.computeTbgrFromComponents(parseInt(hex.charAt(0) + hex.charAt(1), 16), parseInt(hex.charAt(2) + hex.charAt(3), 16), parseInt(hex.charAt(4) + hex.charAt(5), 16), 0),
274
+ undefined,
275
+ ];
264
276
  }
265
277
  if (size === 8) {
266
278
  // #ff0000ff
267
- return this.computeTbgrFromComponents(parseInt(hex.charAt(0) + hex.charAt(1), 16), parseInt(hex.charAt(2) + hex.charAt(3), 16), parseInt(hex.charAt(4) + hex.charAt(5), 16), 255 - parseInt(hex.charAt(6) + hex.charAt(7), 16));
279
+ return [
280
+ this.computeTbgrFromComponents(parseInt(hex.charAt(0) + hex.charAt(1), 16), parseInt(hex.charAt(2) + hex.charAt(3), 16), parseInt(hex.charAt(4) + hex.charAt(5), 16), 255 - parseInt(hex.charAt(6) + hex.charAt(7), 16)),
281
+ undefined,
282
+ ];
268
283
  }
269
284
  }
270
285
  if (defaultColorIfNotParsed) {
271
- return defaultColorIfNotParsed;
286
+ return [defaultColorIfNotParsed, undefined];
272
287
  }
273
288
  throw new Error('unable to parse string into ColorValue');
274
289
  };
@@ -376,40 +391,40 @@ var ColorValue = /** @class */ (function () {
376
391
  };
377
392
  /** Create an HslColor from this ColorValue */
378
393
  ColorValue.toHsl = function (tbgr) {
379
- // internally h,s,l ranges are in 0.0 - 1.0
380
- var col = ColorValue.getColors(tbgr);
381
- col.r /= 255;
382
- col.g /= 255;
383
- col.b /= 255;
384
- var max = Math.max(col.r, col.g, col.b);
385
- var min = Math.min(col.r, col.g, col.b);
394
+ var _a = ColorValue.getColors(tbgr), r = _a.r, g = _a.g, b = _a.b;
395
+ var red = r / 255;
396
+ var green = g / 255;
397
+ var blue = b / 255;
398
+ var cMin = Math.min(red, green, blue);
399
+ var cMax = Math.max(red, green, blue);
400
+ var delta = cMax - cMin;
386
401
  var hue = 0;
387
- var saturation;
388
- var lightness = (min + max) / 2.0;
389
- if (min === max) {
390
- saturation = 0;
402
+ var saturation = 0;
403
+ if (0 === delta) {
404
+ hue = 0;
405
+ }
406
+ else if (red === cMax) {
407
+ hue = ((green - blue) / delta) % 6;
408
+ }
409
+ else if (green === cMax) {
410
+ hue = (blue - red) / delta + 2;
391
411
  }
392
412
  else {
393
- var delta = max - min;
394
- saturation =
395
- lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
396
- switch (max) {
397
- case col.r:
398
- hue = (col.g - col.b) / delta + (col.g < col.b ? 6 : 0);
399
- break;
400
- case col.g:
401
- hue = (col.b - col.r) / delta + 2;
402
- break;
403
- case col.b:
404
- hue = (col.r - col.g) / delta + 4;
405
- break;
406
- }
407
- hue /= 6;
413
+ hue = (red - green) / delta + 4;
414
+ }
415
+ hue = Math.round(hue * 60);
416
+ if (hue < 0) {
417
+ hue += 360;
408
418
  }
419
+ var lightness = (cMax + cMin) / 2;
420
+ saturation = 0 === delta ? 0 : delta / (1 - Math.abs(2 * lightness - 1));
421
+ // round values to 1 decimal place
422
+ saturation = Number((saturation * 100).toFixed(1));
423
+ lightness = Number((lightness * 100).toFixed(1));
409
424
  return {
410
- h: Math.round(hue * 360),
411
- s: Math.round(saturation * 100),
412
- l: Math.round(lightness * 100),
425
+ h: hue,
426
+ s: saturation,
427
+ l: lightness,
413
428
  a: this.getAlpha(tbgr) / 255,
414
429
  };
415
430
  };
@@ -431,54 +446,51 @@ var ColorValue = /** @class */ (function () {
431
446
  */
432
447
  ColorValue.toHsv = function (tbgr) {
433
448
  var _a = ColorValue.getColors(tbgr), r = _a.r, g = _a.g, b = _a.b;
434
- var min = r < g ? r : g;
435
- if (b < min) {
436
- min = b;
449
+ var red = r / 255;
450
+ var green = g / 255;
451
+ var blue = b / 255;
452
+ var cMin = Math.min(red, green, blue);
453
+ var cMax = Math.max(red, green, blue);
454
+ var delta = cMax - cMin;
455
+ var hue = 0;
456
+ if (0 === delta) {
457
+ hue = 0;
437
458
  }
438
- var max = r > g ? r : g;
439
- if (b > max) {
440
- max = b;
459
+ else if (red === cMax) {
460
+ hue = ((green - blue) / delta) % 6;
441
461
  }
442
- /* amount of "blackness" present */
443
- var v = Math.floor((max / 255.0) * 100 + 0.5);
444
- var deltaRgb = max - min;
445
- var s = max !== 0.0 ? Math.floor((deltaRgb / max) * 100 + 0.5) : 0;
446
- var h = 0;
447
- if (s) {
448
- var redDistance = (max - r) / deltaRgb;
449
- var greenDistance = (max - g) / deltaRgb;
450
- var blueDistance = (max - b) / deltaRgb;
451
- var intermediateHue = void 0;
452
- if (r === max) {
453
- /* color between yellow & magenta */
454
- intermediateHue = blueDistance - greenDistance;
455
- }
456
- else if (g === max) {
457
- /* color between cyan & yellow */
458
- intermediateHue = 2.0 + redDistance - blueDistance;
459
- }
460
- else {
461
- /* color between magenta & cyan */
462
- intermediateHue = 4.0 + greenDistance - redDistance;
463
- }
464
- /* intermediate hue is [0..6] */
465
- intermediateHue *= 60;
466
- if (intermediateHue < 0.0) {
467
- intermediateHue += 360;
468
- }
469
- h = Math.floor(intermediateHue + 0.5);
470
- if (h >= 360) {
471
- h = 0;
472
- }
462
+ else if (green === cMax) {
463
+ hue = (blue - red) / delta + 2;
473
464
  }
474
465
  else {
475
- h = 0;
466
+ hue = (red - green) / delta + 4;
467
+ }
468
+ hue = Math.round(hue * 60);
469
+ if (hue < 0) {
470
+ hue += 360;
476
471
  }
477
- return { h: h, s: s, v: v, a: this.getAlpha(tbgr) / 255 };
472
+ var brightness = cMax;
473
+ var saturation = cMax === 0 ? 0 : delta / cMax;
474
+ // round values to 1 decimal place
475
+ saturation = Number((saturation * 100).toFixed(1));
476
+ brightness = Number((brightness * 100).toFixed(1));
477
+ return {
478
+ h: hue,
479
+ s: saturation,
480
+ v: brightness,
481
+ a: this.getAlpha(tbgr) / 255,
482
+ };
478
483
  };
479
484
  /** True if the value of this ColorValue is the same as another ColorValue. */
480
485
  ColorValue.prototype.equals = function (other) {
481
- return this._tbgr === other._tbgr && this._hue === other._hue;
486
+ return this._tbgr === other._tbgr;
487
+ };
488
+ ColorValue.getFormattedColorNumber = function (value, precision) {
489
+ if (precision === void 0) { precision = 1; }
490
+ if (0 === precision) {
491
+ Math.round(value).toString();
492
+ }
493
+ return Number(value.toFixed(precision)).toString();
482
494
  };
483
495
  /** Convert the 0xTTBBGGRR color to a string of the form "rgba(r,g,b,a)" where the color components are specified in decimal and the alpha component is a fraction. */
484
496
  ColorValue.prototype.toRgbString = function (includeAlpha) {
@@ -487,7 +499,7 @@ var ColorValue = /** @class */ (function () {
487
499
  var rgbString = rgb.r + ", " + rgb.g + ", " + rgb.b;
488
500
  if (includeAlpha) {
489
501
  var alpha = (_a = rgb.a) !== null && _a !== void 0 ? _a : 1;
490
- return "rgba(" + rgbString + ", " + alpha.toFixed(2) + ")";
502
+ return "rgba(" + rgbString + ", " + ColorValue.getFormattedColorNumber(alpha, 2) + ")";
491
503
  }
492
504
  return "rgb(" + rgbString + ")";
493
505
  };
@@ -495,10 +507,10 @@ var ColorValue = /** @class */ (function () {
495
507
  ColorValue.prototype.toHslString = function (includeAlpha) {
496
508
  var _a, _b;
497
509
  var hsl = this.toHslColor();
498
- var hslString = ((_a = this._hue) !== null && _a !== void 0 ? _a : hsl.h) + ", " + hsl.s + "%, " + hsl.l + "%";
510
+ var hslString = ColorValue.getFormattedColorNumber((_a = this._hue) !== null && _a !== void 0 ? _a : hsl.h) + ", " + ColorValue.getFormattedColorNumber(hsl.s) + "%, " + ColorValue.getFormattedColorNumber(hsl.l) + "%";
499
511
  if (includeAlpha) {
500
512
  var alpha = (_b = hsl.a) !== null && _b !== void 0 ? _b : 1;
501
- return "hsla(" + hslString + ", " + alpha.toFixed(2) + ")";
513
+ return "hsla(" + hslString + ", " + ColorValue.getFormattedColorNumber(alpha, 2) + ")";
502
514
  }
503
515
  return "hsl(" + hslString + ")";
504
516
  };
@@ -509,7 +521,7 @@ var ColorValue = /** @class */ (function () {
509
521
  var hsvString = ((_a = this._hue) !== null && _a !== void 0 ? _a : hsv.h) + ", " + hsv.s + "%, " + hsv.v + "%";
510
522
  if (includeAlpha) {
511
523
  var alpha = (_b = hsv.a) !== null && _b !== void 0 ? _b : 1;
512
- return "hsva(" + hsvString + ", " + alpha.toFixed(2) + ")";
524
+ return "hsva(" + hsvString + ", " + ColorValue.getFormattedColorNumber(alpha, 2) + ")";
513
525
  }
514
526
  return "hsv(" + hsvString + ")";
515
527
  };
@@ -0,0 +1,21 @@
1
+ /// <reference types="react" />
2
+ import { CommonProps } from '../props';
3
+ export declare type MiddleTextTruncationProps = {
4
+ /**
5
+ * Text to truncate.
6
+ */
7
+ text: string;
8
+ /**
9
+ * Number of characters to leave at the end.
10
+ * @default 6
11
+ */
12
+ endCharsCount?: number;
13
+ } & CommonProps;
14
+ /**
15
+ * Truncates text with the ellipsis in the middle,
16
+ * leaving defined number of chars at the end.
17
+ * @example
18
+ * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' />
19
+ */
20
+ export declare const MiddleTextTruncation: (props: MiddleTextTruncationProps) => JSX.Element;
21
+ export default MiddleTextTruncation;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.MiddleTextTruncation = void 0;
29
+ /*---------------------------------------------------------------------------------------------
30
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
31
+ * See LICENSE.md in the project root for license terms and full copyright notice.
32
+ *--------------------------------------------------------------------------------------------*/
33
+ var react_1 = __importDefault(require("react"));
34
+ var useOverflow_1 = require("../hooks/useOverflow");
35
+ var ELLIPSIS_CHAR = '…';
36
+ /**
37
+ * Truncates text with the ellipsis in the middle,
38
+ * leaving defined number of chars at the end.
39
+ * @example
40
+ * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' />
41
+ */
42
+ var MiddleTextTruncation = function (props) {
43
+ var text = props.text, _a = props.endCharsCount, endCharsCount = _a === void 0 ? 6 : _a, style = props.style, rest = __rest(props, ["text", "endCharsCount", "style"]);
44
+ var _b = (0, useOverflow_1.useOverflow)(text), ref = _b[0], visibleCount = _b[1];
45
+ var truncatedText = react_1.default.useMemo(function () {
46
+ if (visibleCount < text.length) {
47
+ return "" + text.substr(0, visibleCount - endCharsCount - ELLIPSIS_CHAR.length) + ELLIPSIS_CHAR + text.substr(text.length - endCharsCount);
48
+ }
49
+ else {
50
+ return text;
51
+ }
52
+ }, [endCharsCount, text, visibleCount]);
53
+ return (react_1.default.createElement("span", __assign({ style: __assign({ display: 'flex', minWidth: 0, flexGrow: 1, whiteSpace: 'nowrap' }, style), ref: ref }, rest), truncatedText));
54
+ };
55
+ exports.MiddleTextTruncation = MiddleTextTruncation;
56
+ exports.default = exports.MiddleTextTruncation;
@@ -3,3 +3,4 @@ export * from './FocusTrap';
3
3
  export * from './InputContainer';
4
4
  export * from './icons';
5
5
  export * from './WithCSSTransition';
6
+ export * from './MiddleTextTruncation';
@@ -19,3 +19,4 @@ __exportStar(require("./FocusTrap"), exports);
19
19
  __exportStar(require("./InputContainer"), exports);
20
20
  __exportStar(require("./icons"), exports);
21
21
  __exportStar(require("./WithCSSTransition"), exports);
22
+ __exportStar(require("./MiddleTextTruncation"), exports);
@@ -2,5 +2,6 @@ export * from './useEventListener';
2
2
  export * from './useMergedRefs';
3
3
  export * from './useOverflow';
4
4
  export * from './useResizeObserver';
5
+ export * from './useContainerWidth';
5
6
  export * from './useTheme';
6
7
  export * from './useIntersection';
@@ -18,5 +18,6 @@ __exportStar(require("./useEventListener"), exports);
18
18
  __exportStar(require("./useMergedRefs"), exports);
19
19
  __exportStar(require("./useOverflow"), exports);
20
20
  __exportStar(require("./useResizeObserver"), exports);
21
+ __exportStar(require("./useContainerWidth"), exports);
21
22
  __exportStar(require("./useTheme"), exports);
22
23
  __exportStar(require("./useIntersection"), exports);
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Hook that returns the width of an element in three stages:
3
+ * - initialized with 0
4
+ * - immediately set to element's initial width as soon as it's mounted
5
+ * - update to new width every time it changes (using `useResizeObserver` hook)
6
+ *
7
+ * @private
8
+ * @param watchResizes If false, ResizeObserver will not be connected and only the initial width will be returned
9
+ * @returns [ref to attach to the element, stateful width of the element]
10
+ *
11
+ * @example
12
+ * const [ref, width] = useContainerWidth();
13
+ * ... // do something with width
14
+ * return <div ref={ref}>...</div>;
15
+ */
16
+ export declare const useContainerWidth: <T extends HTMLElement>(watchResizes?: boolean) => readonly [(instance: HTMLElement | null) => void, number];
17
+ export default useContainerWidth;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useContainerWidth = void 0;
7
+ /*---------------------------------------------------------------------------------------------
8
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
9
+ * See LICENSE.md in the project root for license terms and full copyright notice.
10
+ *--------------------------------------------------------------------------------------------*/
11
+ var react_1 = __importDefault(require("react"));
12
+ var useMergedRefs_1 = require("./useMergedRefs");
13
+ var useResizeObserver_1 = require("./useResizeObserver");
14
+ /**
15
+ * Hook that returns the width of an element in three stages:
16
+ * - initialized with 0
17
+ * - immediately set to element's initial width as soon as it's mounted
18
+ * - update to new width every time it changes (using `useResizeObserver` hook)
19
+ *
20
+ * @private
21
+ * @param watchResizes If false, ResizeObserver will not be connected and only the initial width will be returned
22
+ * @returns [ref to attach to the element, stateful width of the element]
23
+ *
24
+ * @example
25
+ * const [ref, width] = useContainerWidth();
26
+ * ... // do something with width
27
+ * return <div ref={ref}>...</div>;
28
+ */
29
+ var useContainerWidth = function (watchResizes) {
30
+ if (watchResizes === void 0) { watchResizes = true; }
31
+ var _a = react_1.default.useState(0), contentWidth = _a[0], setContentWidth = _a[1];
32
+ var ref = react_1.default.useCallback(function (element) {
33
+ if (!element) {
34
+ return;
35
+ }
36
+ setContentWidth(element.getBoundingClientRect().width);
37
+ }, []);
38
+ var updateWidth = react_1.default.useCallback(function (_a) {
39
+ var width = _a.width;
40
+ return setContentWidth(width);
41
+ }, []);
42
+ var _b = (0, useResizeObserver_1.useResizeObserver)(updateWidth), resizeRef = _b[0], resizeObserver = _b[1];
43
+ if (!watchResizes) {
44
+ resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
45
+ }
46
+ var refs = (0, useMergedRefs_1.useMergedRefs)(ref, watchResizes ? resizeRef : undefined);
47
+ return [refs, contentWidth];
48
+ };
49
+ exports.useContainerWidth = useContainerWidth;
50
+ exports.default = exports.useContainerWidth;
@@ -20,4 +20,4 @@ import React from 'react';
20
20
  * </div>
21
21
  * );
22
22
  */
23
- export declare const useOverflow: <T extends HTMLElement>(items: React.ReactNode[], disabled?: boolean) => readonly [(instance: T | null) => void, number];
23
+ export declare const useOverflow: <T extends HTMLElement>(items: React.ReactNode[] | string, disabled?: boolean) => readonly [(instance: T | null) => void, number];
@@ -11,6 +11,7 @@ exports.useOverflow = void 0;
11
11
  var react_1 = __importDefault(require("react"));
12
12
  var useMergedRefs_1 = require("./useMergedRefs");
13
13
  var useResizeObserver_1 = require("./useResizeObserver");
14
+ var STARTING_MAX_ITEMS_COUNT = 20;
14
15
  /**
15
16
  * Hook that observes the size of an element and returns the number of items
16
17
  * that should be visible based on the width of the container element.
@@ -35,19 +36,27 @@ var useResizeObserver_1 = require("./useResizeObserver");
35
36
  var useOverflow = function (items, disabled) {
36
37
  if (disabled === void 0) { disabled = false; }
37
38
  var containerRef = react_1.default.useRef(null);
38
- var _a = react_1.default.useState(items.length), visibleCount = _a[0], setVisibleCount = _a[1];
39
- var overflowBreakpoints = react_1.default.useRef([]);
40
- react_1.default.useLayoutEffect(function () {
41
- setVisibleCount(items.length);
42
- overflowBreakpoints.current = [];
43
- }, [items]);
39
+ var _a = react_1.default.useState(function () {
40
+ return disabled ? items.length : Math.min(items.length, STARTING_MAX_ITEMS_COUNT);
41
+ }), visibleCount = _a[0], setVisibleCount = _a[1];
42
+ var needsFullRerender = react_1.default.useRef(true);
44
43
  var _b = react_1.default.useState(0), containerWidth = _b[0], setContainerWidth = _b[1];
44
+ var previousContainerWidth = react_1.default.useRef(0);
45
45
  var updateContainerWidth = react_1.default.useCallback(function (_a) {
46
46
  var width = _a.width;
47
47
  return setContainerWidth(width);
48
48
  }, []);
49
49
  var _c = (0, useResizeObserver_1.useResizeObserver)(updateContainerWidth), resizeRef = _c[0], observer = _c[1];
50
50
  var resizeObserverRef = react_1.default.useRef(observer);
51
+ react_1.default.useLayoutEffect(function () {
52
+ if (disabled) {
53
+ setVisibleCount(items.length);
54
+ }
55
+ else {
56
+ setVisibleCount(Math.min(items.length, STARTING_MAX_ITEMS_COUNT));
57
+ needsFullRerender.current = true;
58
+ }
59
+ }, [containerWidth, disabled, items]);
51
60
  var mergedRefs = (0, useMergedRefs_1.useMergedRefs)(containerRef, resizeRef);
52
61
  react_1.default.useLayoutEffect(function () {
53
62
  var _a;
@@ -57,19 +66,23 @@ var useOverflow = function (items, disabled) {
57
66
  }
58
67
  var availableWidth = containerRef.current.offsetWidth;
59
68
  var requiredWidth = containerRef.current.scrollWidth;
60
- // hide items when there's no space available
61
- if (availableWidth < requiredWidth && visibleCount > 1) {
62
- setVisibleCount(function (count) { return count - 1; });
63
- overflowBreakpoints.current.push(availableWidth);
69
+ if (availableWidth < requiredWidth) {
70
+ var avgItemWidth = requiredWidth / visibleCount;
71
+ var visibleItems = Math.floor(availableWidth / avgItemWidth);
72
+ setVisibleCount(visibleItems);
64
73
  }
65
- // restore items when there's enough space again
66
- else if (overflowBreakpoints.current.length > 0 &&
67
- availableWidth >
68
- overflowBreakpoints.current[overflowBreakpoints.current.length - 1]) {
69
- setVisibleCount(function (count) { return count + 1; });
70
- overflowBreakpoints.current.pop();
74
+ else if (needsFullRerender.current) {
75
+ var childrenWidth = Array.from(containerRef.current.children).reduce(function (sum, child) { return sum + child.offsetWidth; }, 0);
76
+ var avgItemWidth = childrenWidth / visibleCount;
77
+ var visibleItems = Math.floor(availableWidth / avgItemWidth);
78
+ // Doubling the visible items to overflow the container. Just to be safe.
79
+ setVisibleCount(Math.min(items.length, visibleItems * 2));
71
80
  }
72
- }, [containerWidth, visibleCount, disabled]);
81
+ needsFullRerender.current = false;
82
+ }, [containerWidth, visibleCount, disabled, items.length]);
83
+ react_1.default.useLayoutEffect(function () {
84
+ previousContainerWidth.current = containerWidth;
85
+ }, [containerWidth]);
73
86
  return [mergedRefs, visibleCount];
74
87
  };
75
88
  exports.useOverflow = useOverflow;
@@ -6,7 +6,7 @@ declare module 'react-table' {
6
6
  cellProps: CellProps<D>;
7
7
  children: React.ReactNode;
8
8
  };
9
- interface TableOptions<D extends object = {}> extends Omit<UseTableOptions<D>, 'data'>, UseRowSelectOptions<D>, UseExpandedOptions<D>, UseFiltersOptions<D>, UsePaginationOptions<D>, UseSortByOptions<D> {
9
+ interface TableOptions<D extends object = {}> extends Omit<UseTableOptions<D>, 'data'>, UseRowSelectOptions<D>, UseExpandedOptions<D>, UseFiltersOptions<D>, UsePaginationOptions<D>, Omit<UseResizeColumnsOptions<D>, 'disableResizing'>, UseSortByOptions<D> {
10
10
  /**
11
11
  * Table data list.
12
12
  * Must be memoized.
@@ -21,9 +21,19 @@ declare module 'react-table' {
21
21
  interface TableInstance<D extends object = {}> extends UseColumnOrderInstanceProps<D>, UseExpandedInstanceProps<D>, UseFiltersInstanceProps<D>, UseGlobalFiltersInstanceProps<D>, UseGroupByInstanceProps<D>, UsePaginationInstanceProps<D>, UseRowSelectInstanceProps<D>, UseRowStateInstanceProps<D>, UseSortByInstanceProps<D> {
22
22
  initialRows: Row<D>[];
23
23
  }
24
- interface TableState<D extends object = {}> extends UseColumnOrderState<D>, UseExpandedState<D>, UseFiltersState<D>, UseGlobalFiltersState<D>, UseGroupByState<D>, UsePaginationState<D>, UseResizeColumnsState<D>, UseRowSelectState<D>, UseRowStateState<D>, UseSortByState<D> {
24
+ interface TableState<D extends object = {}> extends UseColumnOrderState<D>, UseExpandedState<D>, UseFiltersState<D>, UseGlobalFiltersState<D>, UseGroupByState<D>, UsePaginationState<D>, UseRowSelectState<D>, UseRowStateState<D>, UseSortByState<D> {
25
+ columnResizing: {
26
+ startX?: number;
27
+ columnWidth?: number;
28
+ nextColumnWidth?: number;
29
+ headerIdWidths?: Array<[string, number]>;
30
+ nextHeaderIdWidths?: Array<[string, number]>;
31
+ columnWidths: Record<string, number>;
32
+ isResizingColumn?: string;
33
+ };
34
+ isTableResizing?: boolean;
25
35
  }
26
- interface ColumnInterface<D extends object = {}> extends UseSortByColumnOptions<D>, UseFiltersColumnOptions<D> {
36
+ interface ColumnInterface<D extends object = {}> extends UseSortByColumnOptions<D>, UseFiltersColumnOptions<D>, UseResizeColumnsColumnOptions<D> {
27
37
  /**
28
38
  * Custom class name applied to header column cell.
29
39
  */
@@ -59,6 +69,9 @@ declare module 'react-table' {
59
69
  cellRenderer?: (props: CellRendererProps<D>) => React.ReactNode;
60
70
  }
61
71
  interface ColumnInstance<D extends object = {}> extends UseFiltersColumnProps<D>, UseGroupByColumnProps<D>, UseResizeColumnsColumnProps<D>, UseSortByColumnProps<D> {
72
+ originalWidth: number;
73
+ resizeWidth?: number;
74
+ isResizerVisible?: boolean;
62
75
  }
63
76
  interface Cell<D extends object = {}> extends UseGroupByCellProps<D>, UseRowStateCellProps<D> {
64
77
  }
@@ -43,7 +43,7 @@ export declare const Button: React.ForwardRefExoticComponent<{
43
43
  * Use 'borderless' to hide outline.
44
44
  * @default 'default'
45
45
  */
46
- styleType?: "cta" | "high-visibility" | "default" | "borderless" | undefined;
46
+ styleType?: "default" | "cta" | "high-visibility" | "borderless" | undefined;
47
47
  /**
48
48
  * Icon shown before the main button content.
49
49
  */
@@ -41,18 +41,17 @@ export var Button = React.forwardRef(function (props, ref) {
41
41
  var _a;
42
42
  var children = props.children, className = props.className, size = props.size, style = props.style, _b = props.styleType, styleType = _b === void 0 ? 'default' : _b, _c = props.type, type = _c === void 0 ? 'button' : _c, startIcon = props.startIcon, endIcon = props.endIcon, rest = __rest(props, ["children", "className", "size", "style", "styleType", "type", "startIcon", "endIcon"]);
43
43
  useTheme();
44
- return (React.createElement("button", __assign({ ref: ref, className: cx('iui-button', (_a = {},
44
+ return (React.createElement("button", __assign({ ref: ref, className: cx('iui-button', "iui-" + styleType, (_a = {},
45
45
  _a["iui-" + size] = !!size,
46
- _a["iui-" + styleType] = styleType !== 'default',
47
46
  _a), className), style: style, type: type }, rest),
48
47
  startIcon &&
49
48
  React.cloneElement(startIcon, {
50
- className: cx('iui-icon', startIcon.props.className),
49
+ className: cx('iui-button-icon', startIcon.props.className),
51
50
  }),
52
- children && React.createElement("span", { className: 'iui-label' }, children),
51
+ children && React.createElement("span", { className: 'iui-button-label' }, children),
53
52
  endIcon &&
54
53
  React.cloneElement(endIcon, {
55
- className: cx('iui-icon', endIcon.props.className),
54
+ className: cx('iui-button-icon', endIcon.props.className),
56
55
  })));
57
56
  });
58
57
  export default Button;