@xqmsg/ui-core 0.24.11 → 0.25.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.
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ReadonlyTableColumns, TableBody, TableColumns, TableHeaders } from './TableTypes';
2
+ import { ReadonlyTableColumns, TableBody, TableColumns, TableColumnsWidths, TableHeaders } from './TableTypes';
3
3
  export interface SimpleTableProps<T extends ReadonlyTableColumns> {
4
4
  columns: TableColumns;
5
5
  headers?: TableHeaders<T>;
@@ -7,8 +7,10 @@ export interface SimpleTableProps<T extends ReadonlyTableColumns> {
7
7
  loading?: boolean;
8
8
  loadMore?: () => void;
9
9
  placeholder?: string;
10
+ layout?: 'fixed' | 'auto';
11
+ columnsWidths?: TableColumnsWidths<T>;
10
12
  }
11
13
  /**
12
14
  * A React component utilized to render the `Table` component
13
15
  */
14
- export declare function SimpleTable<T extends ReadonlyTableColumns>({ columns, headers, body, loading, loadMore, }: SimpleTableProps<T>): React.JSX.Element;
16
+ export declare function SimpleTable<T extends ReadonlyTableColumns>({ columns, headers, body, loading, loadMore, layout, columnsWidths, }: SimpleTableProps<T>): React.JSX.Element;
@@ -4,6 +4,9 @@ export declare type ReadonlyTableColumns = Readonly<TableColumns>;
4
4
  export declare type TableHeaders<K extends ReadonlyTableColumns> = {
5
5
  [k in K[number]]: ReactNode;
6
6
  };
7
+ export declare type TableColumnsWidths<K extends ReadonlyTableColumns> = {
8
+ [k in K[number]]: string | number;
9
+ };
7
10
  export declare type TableRow<K extends ReadonlyTableColumns> = {
8
11
  [k in K[number]]: ReactNode;
9
12
  };
@@ -10,6 +10,7 @@ export interface StackedPilledInputProps extends InputFieldProps {
10
10
  variant?: string;
11
11
  label?: string;
12
12
  truncatePillLength?: number;
13
+ mode?: 'scroll' | 'wrap';
13
14
  }
14
15
  /**
15
16
  * A functional React component utilized to render the `StackedPilledInput` component.
@@ -4,6 +4,9 @@ export interface TokenProps {
4
4
  onDelete: any;
5
5
  isMobile?: boolean;
6
6
  truncateLength?: number;
7
+ showClose?: boolean;
8
+ maxWidth?: string | number;
9
+ isSelected?: boolean;
7
10
  }
8
11
  declare const Token: React.FC<TokenProps>;
9
12
  export default Token;
@@ -27,9 +27,10 @@ export interface InputProps<T extends FieldValues = FieldValues> extends Validat
27
27
  loadingOptions?: boolean;
28
28
  truncatePillLength?: number;
29
29
  searchable?: boolean;
30
+ overflowMode?: 'scroll' | 'wrap';
30
31
  }
31
32
  /**
32
33
  * A functional React component utilized to render the `Input` component. Utilizes a switch statement
33
34
  * to render the correct input based on the `inputType`.
34
35
  */
35
- export declare function Input<T extends FieldValues>({ inputType, label, ariaLabel, className, placeholder, name, helperText, options, tooltipText, isInvalid, errorText, isRequired, maxLength, defaultValue, fullOptions, control, disabled, rightElement, leftElement, variant, onChange, setValue, setError, clearErrors, separators, loadingOptions, truncatePillLength, searchable, }: InputProps<T>): React.JSX.Element;
36
+ export declare function Input<T extends FieldValues>({ inputType, label, ariaLabel, className, placeholder, name, helperText, options, tooltipText, isInvalid, errorText, isRequired, maxLength, defaultValue, fullOptions, control, disabled, rightElement, leftElement, variant, onChange, setValue, setError, clearErrors, separators, loadingOptions, truncatePillLength, searchable, overflowMode, }: InputProps<T>): React.JSX.Element;
@@ -1274,7 +1274,11 @@ var Close = function Close(_ref) {
1274
1274
  width: boxSize,
1275
1275
  height: boxSize,
1276
1276
  onClick: onClick,
1277
- cursor: "pointer"
1277
+ cursor: "pointer",
1278
+ style: {
1279
+ flexBasis: boxSize,
1280
+ cursor: 'pointer'
1281
+ }
1278
1282
  });
1279
1283
  };
1280
1284
 
@@ -1285,31 +1289,57 @@ var Token = function Token(_ref) {
1285
1289
  _ref$isMobile = _ref.isMobile,
1286
1290
  isMobile = _ref$isMobile === void 0 ? false : _ref$isMobile,
1287
1291
  _ref$truncateLength = _ref.truncateLength,
1288
- truncateLength = _ref$truncateLength === void 0 ? 15 : _ref$truncateLength;
1292
+ truncateLength = _ref$truncateLength === void 0 ? 15 : _ref$truncateLength,
1293
+ _ref$showClose = _ref.showClose,
1294
+ showClose = _ref$showClose === void 0 ? true : _ref$showClose,
1295
+ _ref$maxWidth = _ref.maxWidth,
1296
+ maxWidth = _ref$maxWidth === void 0 ? 'auto' : _ref$maxWidth,
1297
+ _ref$isSelected = _ref.isSelected,
1298
+ isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected;
1299
+ // in pixels
1300
+ var closeBoxSize = isMobile ? 20 : 15;
1301
+ var closeBoxGap = isMobile ? 4 : 2;
1302
+ var closeBoxPadding = closeBoxSize + closeBoxGap;
1289
1303
  return /*#__PURE__*/React__default.createElement(react.Flex, {
1290
1304
  key: label,
1291
- borderRadius: 'full',
1305
+ borderRadius: 'md',
1292
1306
  backgroundColor: "#7676801F",
1293
1307
  alignItems: "center",
1294
1308
  width: "fit-content",
1295
1309
  w: "auto",
1296
- h: isMobile ? '18px' : '16px',
1297
- pl: "6px",
1298
- pr: "2px",
1310
+ maxWidth: maxWidth,
1311
+ h: '18px',
1312
+ px: "4px",
1299
1313
  py: "2px",
1300
- position: "relative"
1314
+ pr: showClose ? closeBoxPadding : '4px',
1315
+ position: "relative",
1316
+ cursor: "default"
1301
1317
  }, /*#__PURE__*/React__default.createElement(react.Text, {
1302
1318
  whiteSpace: "nowrap",
1319
+ wordBreak: "break-word",
1303
1320
  color: colors.label.primary.light,
1304
1321
  fontSize: isMobile ? '17px' : '13px',
1305
- pr: "4px"
1322
+ lineHeight: isMobile ? '17px' : '13px',
1323
+ pr: "2px",
1324
+ maxWidth: maxWidth,
1325
+ overflow: "hidden",
1326
+ textOverflow: "ellipsis"
1306
1327
  }, lodash.truncate(label.trim(), {
1307
1328
  length: truncateLength,
1308
1329
  omission: '...'
1309
- })), /*#__PURE__*/React__default.createElement(Close, {
1310
- boxSize: isMobile ? '17px' : '11px',
1330
+ })), showClose && /*#__PURE__*/React__default.createElement(react.Flex, {
1331
+ height: "100%",
1332
+ position: "absolute",
1333
+ top: 0,
1334
+ bottom: 0,
1335
+ right: 0,
1336
+ justifyContent: "center",
1337
+ alignItems: "center",
1338
+ cursor: isSelected ? 'default' : 'pointer'
1339
+ }, /*#__PURE__*/React__default.createElement(Close, {
1340
+ boxSize: closeBoxSize + "px",
1311
1341
  onClick: onDelete
1312
- }));
1342
+ })));
1313
1343
  };
1314
1344
 
1315
1345
  /**
@@ -1620,7 +1650,9 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1620
1650
  separators = _ref2$separators === void 0 ? ['Enter', ' ', ',', ';', 'Tab'] : _ref2$separators,
1621
1651
  variant = _ref2.variant,
1622
1652
  label = _ref2.label,
1623
- truncatePillLength = _ref2.truncatePillLength;
1653
+ truncatePillLength = _ref2.truncatePillLength,
1654
+ _ref2$mode = _ref2.mode,
1655
+ mode = _ref2$mode === void 0 ? 'scroll' : _ref2$mode;
1624
1656
  var watchedValue = reactHookForm.useWatch({
1625
1657
  control: control,
1626
1658
  name: name
@@ -1641,6 +1673,7 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1641
1673
  localValue = _useState4[0],
1642
1674
  setLocalValue = _useState4[1];
1643
1675
  var latestTokenElement = document.getElementById(name + "_token_" + (lastestFormValueToArray.length - 1));
1676
+ var scrollMode = mode === 'scroll';
1644
1677
  // gets latest watched form value (common delimited) from RHF state and creates a list
1645
1678
  React.useEffect(function () {
1646
1679
  if (watchedValue !== undefined && !watchedValue.length) {
@@ -1686,18 +1719,50 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1686
1719
  shouldDirty: true
1687
1720
  });
1688
1721
  }
1689
- if (!localValue.trim().length && lastestFormValueToArray.length) {
1690
- if (e.key === 'Backspace' && tokenIndex !== null) {
1691
- setLocalValue(lastestFormValueToArray[tokenIndex].substring(0, lastestFormValueToArray[tokenIndex].length));
1692
- var _filteredUniqueValues2 = Array.from(new Set([].concat(lastestFormValueToArray).filter(function (value) {
1693
- return value !== lastestFormValueToArray[tokenIndex];
1722
+ if (e.key === 'Backspace') {
1723
+ // If input is empty and there are tokens
1724
+ if (!localValue.length && lastestFormValueToArray.length) {
1725
+ // If a token is selected, move it to input
1726
+ if (tokenIndex !== null) {
1727
+ setLocalValue(lastestFormValueToArray[tokenIndex].substring(0, lastestFormValueToArray[tokenIndex].length));
1728
+ var _filteredUniqueValues2 = Array.from(new Set([].concat(lastestFormValueToArray).filter(function (value) {
1729
+ return value !== lastestFormValueToArray[tokenIndex];
1730
+ })));
1731
+ setValue(name, _filteredUniqueValues2.toString(), {
1732
+ shouldValidate: true,
1733
+ shouldDirty: true
1734
+ });
1735
+ return setTokenIndex(null);
1736
+ } else {
1737
+ // No token selected, move last token to input
1738
+ var lastToken = lastestFormValueToArray[lastestFormValueToArray.length - 1];
1739
+ setLocalValue(lastToken);
1740
+ var _filteredUniqueValues3 = lastestFormValueToArray.slice(0, -1);
1741
+ setValue(name, _filteredUniqueValues3.toString(), {
1742
+ shouldValidate: true,
1743
+ shouldDirty: true
1744
+ });
1745
+ e.preventDefault();
1746
+ return;
1747
+ }
1748
+ }
1749
+ }
1750
+ if (e.key === 'Delete') {
1751
+ // If a token is selected, remove it completely
1752
+ if (tokenIndex !== null && lastestFormValueToArray.length) {
1753
+ var _filteredUniqueValues4 = Array.from(new Set([].concat(lastestFormValueToArray).filter(function (_, index) {
1754
+ return index !== tokenIndex;
1694
1755
  })));
1695
- setValue(name, _filteredUniqueValues2.toString(), {
1756
+ setValue(name, _filteredUniqueValues4.toString(), {
1696
1757
  shouldValidate: true,
1697
1758
  shouldDirty: true
1698
1759
  });
1699
- return setTokenIndex(null);
1760
+ setTokenIndex(null);
1761
+ e.preventDefault();
1762
+ return;
1700
1763
  }
1764
+ }
1765
+ if (!localValue.trim().length && lastestFormValueToArray.length) {
1701
1766
  if (e.key === 'ArrowLeft') {
1702
1767
  if (tokenIndex === 0) return;
1703
1768
  if (!tokenIndex) {
@@ -1792,11 +1857,13 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1792
1857
  bg: disabled ? colors.fill.light.quaternary : '#ffffff',
1793
1858
  cursor: disabled ? 'not-allowed' : 'pointer',
1794
1859
  ref: inputWrapperRef,
1795
- h: isMobile ? '48px' : '26px'
1860
+ h: isMobile ? '48px' : scrollMode ? '26px' : 'auto',
1861
+ minH: isMobile ? '48px' : '26px'
1796
1862
  }, /*#__PURE__*/React__default.createElement(react.Flex, {
1797
1863
  h: "100%",
1798
1864
  alignItems: "center",
1799
- overflowX: "scroll",
1865
+ overflowX: scrollMode ? 'scroll' : 'hidden',
1866
+ flexWrap: scrollMode ? 'nowrap' : 'wrap',
1800
1867
  overflowY: "hidden",
1801
1868
  maxWidth: isFocussed ? '80%' : '100%',
1802
1869
  style: {
@@ -1809,21 +1876,30 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1809
1876
  }
1810
1877
  },
1811
1878
  ref: scrollRef,
1812
- zIndex: 99,
1813
1879
  onKeyDown: onHandleKeyDown
1814
1880
  }, lastestFormValueToArray.length ? lastestFormValueToArray.map(function (label, index) {
1815
1881
  return /*#__PURE__*/React__default.createElement(react.Box, {
1816
1882
  key: index,
1817
- mr: "4px",
1883
+ mr: "2px",
1818
1884
  border: tokenIndex === index ? "1px solid " + colors.border.focus : 'none',
1819
- borderRadius: "full",
1820
- onClick: function onClick() {
1821
- return setTokenIndex(index);
1885
+ borderRadius: "md",
1886
+ onClick: function onClick(e) {
1887
+ e.stopPropagation();
1888
+ // Don't change selection if clicking on already selected token
1889
+ if (tokenIndex === index) {
1890
+ return;
1891
+ }
1892
+ setTokenIndex(index);
1822
1893
  },
1823
- width: "100%",
1824
- id: name + "_token_" + index
1894
+ width: scrollMode ? '100%' : 'auto',
1895
+ maxWidth: '100%',
1896
+ id: name + "_token_" + index,
1897
+ cursor: "default"
1825
1898
  }, /*#__PURE__*/React__default.createElement(Token, {
1899
+ maxWidth: '100%',
1826
1900
  label: label,
1901
+ showClose: true,
1902
+ isSelected: tokenIndex === index,
1827
1903
  onDelete: function onDelete(e) {
1828
1904
  e.stopPropagation();
1829
1905
  e.preventDefault();
@@ -1834,7 +1910,8 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1834
1910
  }));
1835
1911
  }) : null, !lastestFormValueToArray.length && !isFocussed ? /*#__PURE__*/React__default.createElement(react.Text, {
1836
1912
  color: colors.label.secondary.light,
1837
- fontSize: isMobile ? '17px' : '13px'
1913
+ fontSize: isMobile ? '17px' : '13px',
1914
+ pointerEvents: "none"
1838
1915
  }, placeholder) : null), !disabled && /*#__PURE__*/React__default.createElement(react.Flex, {
1839
1916
  flex: 1,
1840
1917
  minWidth: isFocussed && !tokenIndex ? '20%' : 0
@@ -1856,10 +1933,6 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1856
1933
  onFocus: function onFocus() {
1857
1934
  return setIsFocussed(true);
1858
1935
  },
1859
- onBlur: function onBlur() {
1860
- setIsFocussed(false);
1861
- return setTokenIndex(null);
1862
- },
1863
1936
  placeholder: isMobile && label && lastestFormValueToArray.length === 0 ? label : '',
1864
1937
  variant: variant,
1865
1938
  style: isMobile ? {
@@ -1951,7 +2024,9 @@ function Input(_ref) {
1951
2024
  _ref$loadingOptions = _ref.loadingOptions,
1952
2025
  loadingOptions = _ref$loadingOptions === void 0 ? false : _ref$loadingOptions,
1953
2026
  truncatePillLength = _ref.truncatePillLength,
1954
- searchable = _ref.searchable;
2027
+ searchable = _ref.searchable,
2028
+ _ref$overflowMode = _ref.overflowMode,
2029
+ overflowMode = _ref$overflowMode === void 0 ? 'scroll' : _ref$overflowMode;
1955
2030
  function selectedInputField(onChange, onBlur, ref, value) {
1956
2031
  switch (inputType) {
1957
2032
  case 'text':
@@ -2082,7 +2157,8 @@ function Input(_ref) {
2082
2157
  variant: variant,
2083
2158
  label: label,
2084
2159
  separators: separators,
2085
- truncatePillLength: truncatePillLength
2160
+ truncatePillLength: truncatePillLength,
2161
+ mode: overflowMode
2086
2162
  });
2087
2163
  case 'switch':
2088
2164
  return /*#__PURE__*/React__default.createElement(StackedSwitch, {
@@ -3588,7 +3664,10 @@ function SimpleTable(_ref) {
3588
3664
  headers = _ref.headers,
3589
3665
  body = _ref.body,
3590
3666
  loading = _ref.loading,
3591
- loadMore = _ref.loadMore;
3667
+ loadMore = _ref.loadMore,
3668
+ _ref$layout = _ref.layout,
3669
+ layout = _ref$layout === void 0 ? 'auto' : _ref$layout,
3670
+ columnsWidths = _ref.columnsWidths;
3592
3671
  var columnsAsConst = generateTableColumnsAsConst(columns);
3593
3672
  return /*#__PURE__*/React__default.createElement(react.TableContainer, {
3594
3673
  border: "none",
@@ -3600,20 +3679,18 @@ function SimpleTable(_ref) {
3600
3679
  width: "100%",
3601
3680
  style: {
3602
3681
  borderCollapse: 'separate',
3603
- borderSpacing: '0px'
3682
+ borderSpacing: '0px',
3683
+ tableLayout: layout
3604
3684
  }
3605
- }, headers && /*#__PURE__*/React__default.createElement(react.Thead, null, /*#__PURE__*/React__default.createElement(react.Tr, {
3685
+ }, (headers || columnsWidths) && /*#__PURE__*/React__default.createElement(react.Thead, null, /*#__PURE__*/React__default.createElement(react.Tr, {
3606
3686
  _odd: {
3607
3687
  bg: colors.label.primary.dark
3608
3688
  }
3609
3689
  }, columnsAsConst.map(function (column, idx) {
3610
- return (
3611
- /*#__PURE__*/
3612
- // @ts-ignore
3613
- React__default.createElement(react.Th, {
3614
- key: idx
3615
- }, headers[column])
3616
- );
3690
+ return /*#__PURE__*/React__default.createElement(react.Th, {
3691
+ key: idx,
3692
+ width: columnsWidths == null ? void 0 : columnsWidths[column]
3693
+ }, headers && headers[column]);
3617
3694
  }))), /*#__PURE__*/React__default.createElement(react.Tbody, null, body.map(function (row, idx) {
3618
3695
  return /*#__PURE__*/React__default.createElement(react.Tr, {
3619
3696
  key: idx