@xqmsg/ui-core 0.25.0 → 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.
@@ -6,6 +6,7 @@ export interface TokenProps {
6
6
  truncateLength?: number;
7
7
  showClose?: boolean;
8
8
  maxWidth?: string | number;
9
+ isSelected?: boolean;
9
10
  }
10
11
  declare const Token: React.FC<TokenProps>;
11
12
  export default Token;
@@ -1273,9 +1273,12 @@ var Close = function Close(_ref) {
1273
1273
  return /*#__PURE__*/React__default.createElement(Memo$7, {
1274
1274
  width: boxSize,
1275
1275
  height: boxSize,
1276
- flexBasis: boxSize,
1277
1276
  onClick: onClick,
1278
- cursor: "pointer"
1277
+ cursor: "pointer",
1278
+ style: {
1279
+ flexBasis: boxSize,
1280
+ cursor: 'pointer'
1281
+ }
1279
1282
  });
1280
1283
  };
1281
1284
 
@@ -1290,36 +1293,53 @@ var Token = function Token(_ref) {
1290
1293
  _ref$showClose = _ref.showClose,
1291
1294
  showClose = _ref$showClose === void 0 ? true : _ref$showClose,
1292
1295
  _ref$maxWidth = _ref.maxWidth,
1293
- maxWidth = _ref$maxWidth === void 0 ? 'auto' : _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;
1294
1303
  return /*#__PURE__*/React__default.createElement(react.Flex, {
1295
1304
  key: label,
1296
- borderRadius: 'full',
1305
+ borderRadius: 'md',
1297
1306
  backgroundColor: "#7676801F",
1298
1307
  alignItems: "center",
1299
1308
  width: "fit-content",
1300
1309
  w: "auto",
1301
1310
  maxWidth: maxWidth,
1302
- h: isMobile ? '18px' : '16px',
1303
- pl: "6px",
1304
- pr: "2px",
1311
+ h: '18px',
1312
+ px: "4px",
1305
1313
  py: "2px",
1306
- position: "relative"
1314
+ pr: showClose ? closeBoxPadding : '4px',
1315
+ position: "relative",
1316
+ cursor: "default"
1307
1317
  }, /*#__PURE__*/React__default.createElement(react.Text, {
1308
1318
  whiteSpace: "nowrap",
1309
1319
  wordBreak: "break-word",
1310
1320
  color: colors.label.primary.light,
1311
1321
  fontSize: isMobile ? '17px' : '13px',
1312
- pr: "4px",
1322
+ lineHeight: isMobile ? '17px' : '13px',
1323
+ pr: "2px",
1313
1324
  maxWidth: maxWidth,
1314
1325
  overflow: "hidden",
1315
1326
  textOverflow: "ellipsis"
1316
1327
  }, lodash.truncate(label.trim(), {
1317
1328
  length: truncateLength,
1318
1329
  omission: '...'
1319
- })), showClose && /*#__PURE__*/React__default.createElement(Close, {
1320
- 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",
1321
1341
  onClick: onDelete
1322
- }));
1342
+ })));
1323
1343
  };
1324
1344
 
1325
1345
  /**
@@ -1699,18 +1719,50 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1699
1719
  shouldDirty: true
1700
1720
  });
1701
1721
  }
1702
- if (!localValue.trim().length && lastestFormValueToArray.length) {
1703
- if (e.key === 'Backspace' && tokenIndex !== null) {
1704
- setLocalValue(lastestFormValueToArray[tokenIndex].substring(0, lastestFormValueToArray[tokenIndex].length));
1705
- var _filteredUniqueValues2 = Array.from(new Set([].concat(lastestFormValueToArray).filter(function (value) {
1706
- 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;
1707
1755
  })));
1708
- setValue(name, _filteredUniqueValues2.toString(), {
1756
+ setValue(name, _filteredUniqueValues4.toString(), {
1709
1757
  shouldValidate: true,
1710
1758
  shouldDirty: true
1711
1759
  });
1712
- return setTokenIndex(null);
1760
+ setTokenIndex(null);
1761
+ e.preventDefault();
1762
+ return;
1713
1763
  }
1764
+ }
1765
+ if (!localValue.trim().length && lastestFormValueToArray.length) {
1714
1766
  if (e.key === 'ArrowLeft') {
1715
1767
  if (tokenIndex === 0) return;
1716
1768
  if (!tokenIndex) {
@@ -1824,24 +1876,30 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1824
1876
  }
1825
1877
  },
1826
1878
  ref: scrollRef,
1827
- zIndex: 99,
1828
1879
  onKeyDown: onHandleKeyDown
1829
1880
  }, lastestFormValueToArray.length ? lastestFormValueToArray.map(function (label, index) {
1830
1881
  return /*#__PURE__*/React__default.createElement(react.Box, {
1831
1882
  key: index,
1832
- mr: "4px",
1883
+ mr: "2px",
1833
1884
  border: tokenIndex === index ? "1px solid " + colors.border.focus : 'none',
1834
- borderRadius: "full",
1835
- onClick: function onClick() {
1836
- 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);
1837
1893
  },
1838
1894
  width: scrollMode ? '100%' : 'auto',
1839
1895
  maxWidth: '100%',
1840
- id: name + "_token_" + index
1896
+ id: name + "_token_" + index,
1897
+ cursor: "default"
1841
1898
  }, /*#__PURE__*/React__default.createElement(Token, {
1842
1899
  maxWidth: '100%',
1843
1900
  label: label,
1844
- showClose: !isFocussed || tokenIndex === index,
1901
+ showClose: true,
1902
+ isSelected: tokenIndex === index,
1845
1903
  onDelete: function onDelete(e) {
1846
1904
  e.stopPropagation();
1847
1905
  e.preventDefault();
@@ -1852,7 +1910,8 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1852
1910
  }));
1853
1911
  }) : null, !lastestFormValueToArray.length && !isFocussed ? /*#__PURE__*/React__default.createElement(react.Text, {
1854
1912
  color: colors.label.secondary.light,
1855
- fontSize: isMobile ? '17px' : '13px'
1913
+ fontSize: isMobile ? '17px' : '13px',
1914
+ pointerEvents: "none"
1856
1915
  }, placeholder) : null), !disabled && /*#__PURE__*/React__default.createElement(react.Flex, {
1857
1916
  flex: 1,
1858
1917
  minWidth: isFocussed && !tokenIndex ? '20%' : 0
@@ -1874,10 +1933,6 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1874
1933
  onFocus: function onFocus() {
1875
1934
  return setIsFocussed(true);
1876
1935
  },
1877
- onBlur: function onBlur() {
1878
- setIsFocussed(false);
1879
- return setTokenIndex(null);
1880
- },
1881
1936
  placeholder: isMobile && label && lastestFormValueToArray.length === 0 ? label : '',
1882
1937
  variant: variant,
1883
1938
  style: isMobile ? {