@indico-data/design-system 1.0.55 → 1.0.56

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/lib/index.js CHANGED
@@ -2342,6 +2342,42 @@ const SingleCombobox = React__namespace.default.forwardRef((props, ref) => {
2342
2342
  return jsxRuntime$1.jsx(ComboboxComponent, {});
2343
2343
  });
2344
2344
 
2345
+ const mix = function (color_1, color_2, weight) {
2346
+ function d2h(d) {
2347
+ return d.toString(16);
2348
+ } // convert a decimal value to hex
2349
+ function h2d(h) {
2350
+ return parseInt(h, 16);
2351
+ } // convert a hex value to decimal
2352
+ function s2l(hex) {
2353
+ return `${hex}${hex}`;
2354
+ }
2355
+ weight = typeof weight !== 'undefined' ? weight : 50; // set the weight to 50%, if that argument is omitted
2356
+ color_1 = color_1.replace(/#/g, '');
2357
+ color_2 = color_2.replace(/#/g, '');
2358
+ // check if colors are shorthand or longhand - covert to longhand
2359
+ color_1 = color_1.length === 3 ? s2l(color_1) : color_1;
2360
+ color_2 = color_2.length === 3 ? s2l(color_2) : color_2;
2361
+ let color = '#';
2362
+ for (let i = 0; i <= 5; i += 2) {
2363
+ // loop through each of the 3 hex pairs—red, green, and blue
2364
+ const v1 = h2d(color_1.substr(i, 2)); // extract the current pairs
2365
+ const v2 = h2d(color_2.substr(i, 2));
2366
+ // combine the current pairs from each source color, according to the specified weight
2367
+ let val = d2h(Math.floor(v2 + (v1 - v2) * (weight / 100.0)));
2368
+ while (val.length < 2) {
2369
+ val = '0' + val;
2370
+ } // prepend a '0' if val results in a single digit
2371
+ color += val; // concatenate val to our new color string
2372
+ }
2373
+ return color; // PROFIT!
2374
+ };
2375
+ const shade = (color, percentage) => {
2376
+ return mix('#000000', color, percentage);
2377
+ };
2378
+ const tint = (color, percentage) => {
2379
+ return mix('#ffffff', color, percentage);
2380
+ };
2345
2381
  /**
2346
2382
  * Converts hex color values to rgb or rgba values if a opacity is supplied
2347
2383
  * @param hex
@@ -2362,7 +2398,120 @@ const hexToRgb = (hex, opacity) => {
2362
2398
  }
2363
2399
  return undefined;
2364
2400
  };
2401
+ /**
2402
+ * Takes a 3- or 6-character hex color value, and returns an object containing
2403
+ * its equivalent HSL values.
2404
+ *
2405
+ * @see {@link https://css-tricks.com/converting-color-spaces-in-javascript/}
2406
+ * @see {@link https://gist.github.com/mjackson/5311256}
2407
+ */
2408
+ function hexToHsl(hexColor) {
2409
+ // convert to 6-character hex string, if necessary
2410
+ const fullHexColor = (() => {
2411
+ if (hexColor.length === 4) {
2412
+ return ('#' +
2413
+ hexColor
2414
+ .replace('#', '')
2415
+ .split('')
2416
+ .reduce((acc, char) => (acc += char + char), ''));
2417
+ }
2418
+ return hexColor;
2419
+ })();
2420
+ const rgbValues = {
2421
+ red: parseInt(fullHexColor.slice(1, 3), 16) / 255,
2422
+ green: parseInt(fullHexColor.slice(3, 5), 16) / 255,
2423
+ blue: parseInt(fullHexColor.slice(-2), 16) / 255,
2424
+ };
2425
+ const allValues = Object.values(rgbValues);
2426
+ const channelMax = Math.max(...allValues);
2427
+ const channelMin = Math.min(...allValues);
2428
+ const channelDelta = channelMax - channelMin;
2429
+ const hslValues = {
2430
+ hue: 0,
2431
+ saturation: 0,
2432
+ lightness: (channelMax + channelMin) / 2,
2433
+ };
2434
+ if (channelDelta !== 0) {
2435
+ // calculate hue
2436
+ if (channelMax === rgbValues.red) {
2437
+ hslValues.hue = ((rgbValues.green - rgbValues.blue) / channelDelta) % 6;
2438
+ }
2439
+ else if (channelMax === rgbValues.green) {
2440
+ hslValues.hue = (rgbValues.blue - rgbValues.red) / channelDelta + 2;
2441
+ }
2442
+ else {
2443
+ hslValues.hue = (rgbValues.red - rgbValues.green) / channelDelta + 4;
2444
+ }
2445
+ // calculate saturation
2446
+ hslValues.saturation = channelDelta / (1 - Math.abs(2 * hslValues.lightness - 1));
2447
+ }
2448
+ hslValues.hue = Math.round(hslValues.hue * 60);
2449
+ hslValues.saturation = +(hslValues.saturation * 100).toFixed(0);
2450
+ hslValues.lightness = +(hslValues.lightness * 100).toFixed(0);
2451
+ // make negative hues positive
2452
+ if (hslValues.hue < 0) {
2453
+ hslValues.hue += 360;
2454
+ }
2455
+ return hslValues;
2456
+ }
2365
2457
 
2458
+ var color = /*#__PURE__*/Object.freeze({
2459
+ __proto__: null,
2460
+ hexToHsl: hexToHsl,
2461
+ hexToRgb: hexToRgb,
2462
+ mix: mix,
2463
+ shade: shade,
2464
+ tint: tint
2465
+ });
2466
+
2467
+ const camelCaseToUpperUnderscore = (string) => {
2468
+ return string
2469
+ .replace(/([A-Z])/g, function ($1) {
2470
+ return '_' + $1;
2471
+ })
2472
+ .toUpperCase();
2473
+ };
2474
+ const camelCaseToSpaceUpper = (string) => {
2475
+ return (string
2476
+ // insert a space before all caps
2477
+ .replace(/([A-Z])/g, ' $1')
2478
+ // uppercase the first character
2479
+ .replace(/^./, function (str) {
2480
+ return str.toUpperCase();
2481
+ }));
2482
+ };
2483
+ const underscoreToCapitalize = (string) => {
2484
+ return (string
2485
+ // replace all _ with spaces
2486
+ .replace(/_/g, ' ')
2487
+ // uppercase the first character
2488
+ .replace(/^./, function (str) {
2489
+ return str.toUpperCase();
2490
+ }));
2491
+ };
2492
+ const snakeCaseToCamelCase = (string) => {
2493
+ const parts = string.split('_').map((part, i) => {
2494
+ if (i > 0) {
2495
+ return part.replace(/^./, function (str) {
2496
+ return str.toUpperCase();
2497
+ });
2498
+ }
2499
+ else {
2500
+ return part;
2501
+ }
2502
+ });
2503
+ return parts.join().replace(/,/g, '');
2504
+ };
2505
+ function capitalize(string) {
2506
+ if (typeof string !== 'string')
2507
+ return '';
2508
+ return string.slice(0, 1).toUpperCase() + string.slice(1).toLowerCase();
2509
+ }
2510
+ function capitalizeFirstOnly(string) {
2511
+ if (typeof string !== 'string')
2512
+ return '';
2513
+ return string.slice(0, 1).toUpperCase() + string.slice(1);
2514
+ }
2366
2515
  /**
2367
2516
  * Generates a random string of English alphabet characters. Defaults to a length of 8.
2368
2517
  */
@@ -2374,6 +2523,33 @@ function createRandomString(length) {
2374
2523
  }
2375
2524
  return result;
2376
2525
  }
2526
+ const maxLengthWithEllipse = (string, maxLength) => {
2527
+ if (string.length <= maxLength) {
2528
+ return string;
2529
+ }
2530
+ else {
2531
+ return string.slice(0, maxLength - 2).concat('...');
2532
+ }
2533
+ };
2534
+ const maxLengthWithMiddleEllipsis = (string, maxLength) => {
2535
+ const frontSegment = string.slice(0, Math.floor(maxLength / 2) - 2);
2536
+ const endSegmentLength = string.length - (Math.floor(maxLength / 2) - 1);
2537
+ const endSegment = string.slice(endSegmentLength, string.length);
2538
+ return string.length <= maxLength ? string : `${frontSegment}...${endSegment}`;
2539
+ };
2540
+
2541
+ var string = /*#__PURE__*/Object.freeze({
2542
+ __proto__: null,
2543
+ camelCaseToSpaceUpper: camelCaseToSpaceUpper,
2544
+ camelCaseToUpperUnderscore: camelCaseToUpperUnderscore,
2545
+ capitalize: capitalize,
2546
+ capitalizeFirstOnly: capitalizeFirstOnly,
2547
+ createRandomString: createRandomString,
2548
+ maxLengthWithEllipse: maxLengthWithEllipse,
2549
+ maxLengthWithMiddleEllipsis: maxLengthWithMiddleEllipsis,
2550
+ snakeCaseToCamelCase: snakeCaseToCamelCase,
2551
+ underscoreToCapitalize: underscoreToCapitalize
2552
+ });
2377
2553
 
2378
2554
  /**
2379
2555
  * Takes a number and formats it nicely.
@@ -2384,6 +2560,31 @@ function createRandomString(length) {
2384
2560
  function numberWithCommas(value) {
2385
2561
  return new Intl.NumberFormat(navigator.language || 'en-US').format(value);
2386
2562
  }
2563
+ /**
2564
+ * Takes a number and returns it, rounded up to the maximum decimal places specified.
2565
+ *
2566
+ * @example maxDecimalPlaces(0.1694915254237288, 2)
2567
+ * // returns 0.17
2568
+ *
2569
+ * @example maxDecimalPlaces(0.1694915254237288, 3)
2570
+ * // returns 0.169
2571
+ *
2572
+ * @example maxDecimalPlaces(12.902, 2)
2573
+ * // returns 12.9
2574
+ */
2575
+ function maxDecimalPlaces(value, decimalPlaces) {
2576
+ return +value.toFixed(decimalPlaces);
2577
+ }
2578
+ function formatConfidence(confidence) {
2579
+ return Math.min(Math.floor(confidence * 100), 99);
2580
+ }
2581
+
2582
+ var number = /*#__PURE__*/Object.freeze({
2583
+ __proto__: null,
2584
+ formatConfidence: formatConfidence,
2585
+ maxDecimalPlaces: maxDecimalPlaces,
2586
+ numberWithCommas: numberWithCommas
2587
+ });
2387
2588
 
2388
2589
  const cardTableLoading = styled.keyframes `
2389
2590
  25% {
@@ -25958,6 +26159,9 @@ exports.Wizard = Wizard;
25958
26159
  exports.WizardCard = WizardCard;
25959
26160
  exports.WizardSection = WizardSection;
25960
26161
  exports.WizardWithSidebar = WizardWithSidebar;
26162
+ exports.colorUtils = color;
25961
26163
  exports.faIcons = faIcons;
25962
26164
  exports.indicons = indicons;
26165
+ exports.numberUtils = number;
26166
+ exports.stringUtils = string;
25963
26167
  //# sourceMappingURL=index.js.map