@itwin/itwinui-react 1.23.2 → 1.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/cjs/core/Buttons/Button/Button.d.ts +1 -1
- package/cjs/core/ColorPicker/ColorBuilder.js +40 -15
- package/cjs/core/ColorPicker/ColorInputPanel.js +125 -46
- package/cjs/core/ColorPicker/ColorPicker.d.ts +5 -0
- package/cjs/core/ColorPicker/ColorPicker.js +7 -6
- package/cjs/core/ColorPicker/ColorPickerContext.d.ts +4 -2
- package/cjs/core/ColorPicker/ColorSwatch.d.ts +1 -1
- package/cjs/core/ColorPicker/ColorSwatch.js +10 -4
- package/cjs/core/DatePicker/DatePicker.d.ts +1 -1
- package/cjs/core/InformationPanel/InformationPanel.d.ts +4 -1
- package/cjs/core/InformationPanel/InformationPanel.js +4 -1
- package/cjs/core/InformationPanel/InformationPanelContent.d.ts +42 -0
- package/cjs/core/InformationPanel/InformationPanelContent.js +66 -0
- package/cjs/core/InformationPanel/index.d.ts +2 -0
- package/cjs/core/InformationPanel/index.js +3 -1
- package/cjs/core/Label/Label.d.ts +31 -0
- package/cjs/core/Label/Label.js +53 -0
- package/cjs/core/Label/index.d.ts +4 -0
- package/cjs/core/Label/index.js +10 -0
- package/cjs/core/LabeledInput/LabeledInput.d.ts +2 -2
- package/cjs/core/LabeledTextarea/LabeledTextarea.d.ts +1 -1
- package/cjs/core/Menu/MenuItem.d.ts +1 -1
- package/cjs/core/Table/TablePaginator.d.ts +1 -1
- package/cjs/core/Table/TablePaginator.js +9 -4
- package/cjs/core/Tabs/Tabs.js +23 -29
- package/cjs/core/index.d.ts +6 -4
- package/cjs/core/index.js +6 -2
- package/cjs/core/utils/color/ColorValue.d.ts +1 -0
- package/cjs/core/utils/color/ColorValue.js +101 -85
- package/cjs/core/utils/components/MiddleTextTruncation.d.ts +21 -0
- package/cjs/core/utils/components/MiddleTextTruncation.js +56 -0
- package/cjs/core/utils/components/index.d.ts +1 -0
- package/cjs/core/utils/components/index.js +1 -0
- package/cjs/core/utils/hooks/index.d.ts +1 -0
- package/cjs/core/utils/hooks/index.js +1 -0
- package/cjs/core/utils/hooks/useContainerWidth.d.ts +17 -0
- package/cjs/core/utils/hooks/useContainerWidth.js +50 -0
- package/cjs/core/utils/hooks/useOverflow.d.ts +1 -1
- package/cjs/core/utils/hooks/useOverflow.js +30 -17
- package/esm/core/Buttons/Button/Button.d.ts +1 -1
- package/esm/core/ColorPicker/ColorBuilder.js +40 -15
- package/esm/core/ColorPicker/ColorInputPanel.js +125 -46
- package/esm/core/ColorPicker/ColorPicker.d.ts +5 -0
- package/esm/core/ColorPicker/ColorPicker.js +7 -6
- package/esm/core/ColorPicker/ColorPickerContext.d.ts +4 -2
- package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
- package/esm/core/ColorPicker/ColorSwatch.js +10 -4
- package/esm/core/DatePicker/DatePicker.d.ts +1 -1
- package/esm/core/InformationPanel/InformationPanel.d.ts +4 -1
- package/esm/core/InformationPanel/InformationPanel.js +4 -1
- package/esm/core/InformationPanel/InformationPanelContent.d.ts +42 -0
- package/esm/core/InformationPanel/InformationPanelContent.js +59 -0
- package/esm/core/InformationPanel/index.d.ts +2 -0
- package/esm/core/InformationPanel/index.js +1 -0
- package/esm/core/Label/Label.d.ts +31 -0
- package/esm/core/Label/Label.js +46 -0
- package/esm/core/Label/index.d.ts +4 -0
- package/esm/core/Label/index.js +6 -0
- package/esm/core/LabeledInput/LabeledInput.d.ts +2 -2
- package/esm/core/LabeledTextarea/LabeledTextarea.d.ts +1 -1
- package/esm/core/Menu/MenuItem.d.ts +1 -1
- package/esm/core/Table/TablePaginator.d.ts +1 -1
- package/esm/core/Table/TablePaginator.js +9 -4
- package/esm/core/Tabs/Tabs.js +24 -30
- package/esm/core/index.d.ts +6 -4
- package/esm/core/index.js +3 -2
- package/esm/core/utils/color/ColorValue.d.ts +1 -0
- package/esm/core/utils/color/ColorValue.js +101 -85
- package/esm/core/utils/components/MiddleTextTruncation.d.ts +21 -0
- package/esm/core/utils/components/MiddleTextTruncation.js +49 -0
- package/esm/core/utils/components/index.d.ts +1 -0
- package/esm/core/utils/components/index.js +1 -0
- package/esm/core/utils/hooks/index.d.ts +1 -0
- package/esm/core/utils/hooks/index.js +1 -0
- package/esm/core/utils/hooks/useContainerWidth.d.ts +17 -0
- package/esm/core/utils/hooks/useContainerWidth.js +43 -0
- package/esm/core/utils/hooks/useOverflow.d.ts +1 -1
- package/esm/core/utils/hooks/useOverflow.js +30 -17
- package/package.json +2 -2
|
@@ -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
|
-
|
|
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
|
|
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])
|
|
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
|
|
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
|
|
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
|
|
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
|
};
|
|
@@ -315,7 +330,11 @@ var ColorValue = /** @class */ (function () {
|
|
|
315
330
|
*/
|
|
316
331
|
ColorValue.prototype.toHexString = function (includeAlpha) {
|
|
317
332
|
if (includeAlpha) {
|
|
318
|
-
|
|
333
|
+
var value = this.getRgb(includeAlpha);
|
|
334
|
+
if (value < 0) {
|
|
335
|
+
value = 0xffffffff + value + 1;
|
|
336
|
+
}
|
|
337
|
+
return "#" + ("00000000" + value.toString(16)).slice(-8);
|
|
319
338
|
}
|
|
320
339
|
return "#" + ("000000" + this.getRgb().toString(16)).slice(-6);
|
|
321
340
|
};
|
|
@@ -372,40 +391,40 @@ var ColorValue = /** @class */ (function () {
|
|
|
372
391
|
};
|
|
373
392
|
/** Create an HslColor from this ColorValue */
|
|
374
393
|
ColorValue.toHsl = function (tbgr) {
|
|
375
|
-
|
|
376
|
-
var
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
var
|
|
381
|
-
var
|
|
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;
|
|
382
401
|
var hue = 0;
|
|
383
|
-
var saturation;
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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;
|
|
387
411
|
}
|
|
388
412
|
else {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
hue = (col.g - col.b) / delta + (col.g < col.b ? 6 : 0);
|
|
395
|
-
break;
|
|
396
|
-
case col.g:
|
|
397
|
-
hue = (col.b - col.r) / delta + 2;
|
|
398
|
-
break;
|
|
399
|
-
case col.b:
|
|
400
|
-
hue = (col.r - col.g) / delta + 4;
|
|
401
|
-
break;
|
|
402
|
-
}
|
|
403
|
-
hue /= 6;
|
|
413
|
+
hue = (red - green) / delta + 4;
|
|
414
|
+
}
|
|
415
|
+
hue = Math.round(hue * 60);
|
|
416
|
+
if (hue < 0) {
|
|
417
|
+
hue += 360;
|
|
404
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));
|
|
405
424
|
return {
|
|
406
|
-
h:
|
|
407
|
-
s:
|
|
408
|
-
l:
|
|
425
|
+
h: hue,
|
|
426
|
+
s: saturation,
|
|
427
|
+
l: lightness,
|
|
409
428
|
a: this.getAlpha(tbgr) / 255,
|
|
410
429
|
};
|
|
411
430
|
};
|
|
@@ -427,54 +446,51 @@ var ColorValue = /** @class */ (function () {
|
|
|
427
446
|
*/
|
|
428
447
|
ColorValue.toHsv = function (tbgr) {
|
|
429
448
|
var _a = ColorValue.getColors(tbgr), r = _a.r, g = _a.g, b = _a.b;
|
|
430
|
-
var
|
|
431
|
-
|
|
432
|
-
|
|
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;
|
|
433
458
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
max = b;
|
|
459
|
+
else if (red === cMax) {
|
|
460
|
+
hue = ((green - blue) / delta) % 6;
|
|
437
461
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
var deltaRgb = max - min;
|
|
441
|
-
var s = max !== 0.0 ? Math.floor((deltaRgb / max) * 100 + 0.5) : 0;
|
|
442
|
-
var h = 0;
|
|
443
|
-
if (s) {
|
|
444
|
-
var redDistance = (max - r) / deltaRgb;
|
|
445
|
-
var greenDistance = (max - g) / deltaRgb;
|
|
446
|
-
var blueDistance = (max - b) / deltaRgb;
|
|
447
|
-
var intermediateHue = void 0;
|
|
448
|
-
if (r === max) {
|
|
449
|
-
/* color between yellow & magenta */
|
|
450
|
-
intermediateHue = blueDistance - greenDistance;
|
|
451
|
-
}
|
|
452
|
-
else if (g === max) {
|
|
453
|
-
/* color between cyan & yellow */
|
|
454
|
-
intermediateHue = 2.0 + redDistance - blueDistance;
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
/* color between magenta & cyan */
|
|
458
|
-
intermediateHue = 4.0 + greenDistance - redDistance;
|
|
459
|
-
}
|
|
460
|
-
/* intermediate hue is [0..6] */
|
|
461
|
-
intermediateHue *= 60;
|
|
462
|
-
if (intermediateHue < 0.0) {
|
|
463
|
-
intermediateHue += 360;
|
|
464
|
-
}
|
|
465
|
-
h = Math.floor(intermediateHue + 0.5);
|
|
466
|
-
if (h >= 360) {
|
|
467
|
-
h = 0;
|
|
468
|
-
}
|
|
462
|
+
else if (green === cMax) {
|
|
463
|
+
hue = (blue - red) / delta + 2;
|
|
469
464
|
}
|
|
470
465
|
else {
|
|
471
|
-
|
|
466
|
+
hue = (red - green) / delta + 4;
|
|
467
|
+
}
|
|
468
|
+
hue = Math.round(hue * 60);
|
|
469
|
+
if (hue < 0) {
|
|
470
|
+
hue += 360;
|
|
472
471
|
}
|
|
473
|
-
|
|
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
|
+
};
|
|
474
483
|
};
|
|
475
484
|
/** True if the value of this ColorValue is the same as another ColorValue. */
|
|
476
485
|
ColorValue.prototype.equals = function (other) {
|
|
477
|
-
return this._tbgr === other._tbgr
|
|
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();
|
|
478
494
|
};
|
|
479
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. */
|
|
480
496
|
ColorValue.prototype.toRgbString = function (includeAlpha) {
|
|
@@ -483,7 +499,7 @@ var ColorValue = /** @class */ (function () {
|
|
|
483
499
|
var rgbString = rgb.r + ", " + rgb.g + ", " + rgb.b;
|
|
484
500
|
if (includeAlpha) {
|
|
485
501
|
var alpha = (_a = rgb.a) !== null && _a !== void 0 ? _a : 1;
|
|
486
|
-
return "rgba(" + rgbString + ", " +
|
|
502
|
+
return "rgba(" + rgbString + ", " + ColorValue.getFormattedColorNumber(alpha, 2) + ")";
|
|
487
503
|
}
|
|
488
504
|
return "rgb(" + rgbString + ")";
|
|
489
505
|
};
|
|
@@ -491,10 +507,10 @@ var ColorValue = /** @class */ (function () {
|
|
|
491
507
|
ColorValue.prototype.toHslString = function (includeAlpha) {
|
|
492
508
|
var _a, _b;
|
|
493
509
|
var hsl = this.toHslColor();
|
|
494
|
-
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) + "%";
|
|
495
511
|
if (includeAlpha) {
|
|
496
512
|
var alpha = (_b = hsl.a) !== null && _b !== void 0 ? _b : 1;
|
|
497
|
-
return "hsla(" + hslString + ", " +
|
|
513
|
+
return "hsla(" + hslString + ", " + ColorValue.getFormattedColorNumber(alpha, 2) + ")";
|
|
498
514
|
}
|
|
499
515
|
return "hsl(" + hslString + ")";
|
|
500
516
|
};
|
|
@@ -505,7 +521,7 @@ var ColorValue = /** @class */ (function () {
|
|
|
505
521
|
var hsvString = ((_a = this._hue) !== null && _a !== void 0 ? _a : hsv.h) + ", " + hsv.s + "%, " + hsv.v + "%";
|
|
506
522
|
if (includeAlpha) {
|
|
507
523
|
var alpha = (_b = hsv.a) !== null && _b !== void 0 ? _b : 1;
|
|
508
|
-
return "hsva(" + hsvString + ", " +
|
|
524
|
+
return "hsva(" + hsvString + ", " + ColorValue.getFormattedColorNumber(alpha, 2) + ")";
|
|
509
525
|
}
|
|
510
526
|
return "hsv(" + hsvString + ")";
|
|
511
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;
|
|
@@ -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(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
if (availableWidth < requiredWidth) {
|
|
70
|
+
var avgItemWidth = requiredWidth / visibleCount;
|
|
71
|
+
var visibleItems = Math.floor(availableWidth / avgItemWidth);
|
|
72
|
+
setVisibleCount(visibleItems);
|
|
64
73
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -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?: "
|
|
46
|
+
styleType?: "default" | "cta" | "high-visibility" | "borderless" | undefined;
|
|
47
47
|
/**
|
|
48
48
|
* Icon shown before the main button content.
|
|
49
49
|
*/
|