@activecollab/components 2.0.244 → 2.0.246

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/dist/index.js CHANGED
@@ -19243,7 +19243,7 @@
19243
19243
  });
19244
19244
  Chip.displayName = "Chip";
19245
19245
 
19246
- var _excluded$C = ["options", "selected", "loading", "loadingText", "onChange", "onInputChange", "placeholder", "handleEmptyAction", "disabled", "size", "invalid", "type", "renderChip", "forceCloseMenu", "renderOption", "limitChips", "hiddenNumberText", "inPortal", "inputWrapperClassName", "scrollWrapper", "onClose", "onClear", "onDeselect", "defaultValue", "open", "onOpen", "triggerMode", "noResultText", "emptyValue", "disableVirtualization", "hideClearButton", "errorMessage"];
19246
+ var _excluded$C = ["options", "selected", "loading", "loadingText", "onChange", "onInputChange", "placeholder", "handleEmptyAction", "disabled", "size", "invalid", "type", "renderChip", "forceCloseMenu", "renderOption", "limitChips", "hiddenNumberText", "inPortal", "inputWrapperClassName", "scrollWrapper", "onClose", "onClear", "onDeselect", "defaultValue", "open", "onOpen", "triggerMode", "noResultText", "emptyValue", "disableVirtualization", "hideClearButton", "errorMessage", "onCancel"];
19247
19247
  var sizeMap = {
19248
19248
  small: 18,
19249
19249
  regular: 24,
@@ -19295,6 +19295,7 @@
19295
19295
  _ref$hideClearButton = _ref.hideClearButton,
19296
19296
  hideClearButton = _ref$hideClearButton === void 0 ? false : _ref$hideClearButton,
19297
19297
  errorMessage = _ref.errorMessage,
19298
+ onCancel = _ref.onCancel,
19298
19299
  prop = _objectWithoutProperties(_ref, _excluded$C);
19299
19300
  var selectedName = React.useMemo(function () {
19300
19301
  var value = "";
@@ -19346,12 +19347,14 @@
19346
19347
  if (e.target && (_comboBoxRef$current = comboBoxRef.current) !== null && _comboBoxRef$current !== void 0 && _comboBoxRef$current.contains(e.target)) {
19347
19348
  return;
19348
19349
  }
19350
+ onCancel === null || onCancel === void 0 || onCancel(selectedName);
19349
19351
  setOpen(false);
19350
19352
  });
19351
19353
  var handleOnKeyDown = React.useCallback(function (e) {
19352
19354
  if (e.key === "Escape" && open) {
19353
19355
  setOpen(false);
19354
19356
  setValue(selectedName);
19357
+ onCancel === null || onCancel === void 0 || onCancel(selectedName);
19355
19358
  e.stopPropagation();
19356
19359
  }
19357
19360
  if (e.key === "Enter" && type === "multiple") {
@@ -19361,7 +19364,7 @@
19361
19364
  setOpen(true);
19362
19365
  onOpen === null || onOpen === void 0 || onOpen();
19363
19366
  }
19364
- }, [focused, onOpen, open, selectedName, type]);
19367
+ }, [focused, onCancel, onOpen, open, selectedName, type]);
19365
19368
  React.useEffect(function () {
19366
19369
  var _childNode$current, _childNode$current2;
19367
19370
  open && (childNode === null || childNode === void 0 || (_childNode$current = childNode.current) === null || _childNode$current === void 0 ? void 0 : _childNode$current.focus());
@@ -20416,7 +20419,7 @@
20416
20419
  var StyledHeader = styled__default["default"](Paper).withConfig({
20417
20420
  displayName: "Styles__StyledHeader",
20418
20421
  componentId: "sc-xrlqib-0"
20419
- })(["", " ", " padding:0 1rem;display:flex;overflow:hidden;min-width:350px;@media screen and (max-width:350px){overflow:auto;}"], function (props) {
20422
+ })(["", " ", " padding:0 1rem;display:flex;overflow:hidden;@media screen and (max-width:350px){overflow:auto;}"], function (props) {
20420
20423
  return props.size === "big" && styled.css(["height:140px;"]);
20421
20424
  }, function (props) {
20422
20425
  return props.size === "small" && styled.css(["height:4rem;"]);
@@ -22335,14 +22338,46 @@
22335
22338
  });
22336
22339
  EditableContent.displayName = "EditableContent";
22337
22340
 
22338
- var _excluded$f = ["onSave", "onCancel", "value", "inputProps", "allowEmptyString"];
22339
- var EditableText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
22340
- var onSave = _ref.onSave,
22341
- onCancel = _ref.onCancel,
22342
- value = _ref.value,
22343
- inputProps = _ref.inputProps,
22344
- allowEmptyString = _ref.allowEmptyString,
22345
- props = _objectWithoutProperties(_ref, _excluded$f);
22341
+ var _excluded$f = ["onSave", "onCancel", "value", "inputProps", "allowEmptyString", "multiline", "variant", "weight", "disabled", "invalid", "wrapRef", "children"];
22342
+ var StyledTextareaSpan = styled__default["default"](Typography).withConfig({
22343
+ displayName: "EditableText__StyledTextareaSpan",
22344
+ componentId: "sc-j2ewzm-0"
22345
+ })(["", " background-color:var(--input-background-color,#ffffff);padding-left:4px;padding-right:4px;padding-top:1px;padding-bottom:1px;font-variant-numeric:tabular-nums;outline-width:0px;outline:none;resize:none;white-space:pre-wrap;overflow-wrap:break-word;height:calc(1.5em * 3 + 2px);min-height:calc(1.5em * 3 + 2px);opacity:0;&:focus{opacity:1;background-color:var(--input-background-color,#f8f9fa);}&:disabled{opacity:0;}", ""], {
22346
+ "position": "absolute",
22347
+ "inset": "0px",
22348
+ "boxSizing": "border-box",
22349
+ "width": "100%",
22350
+ "borderRadius": "0.375rem",
22351
+ "borderWidth": "1px",
22352
+ "borderStyle": "solid",
22353
+ "borderColor": "transparent",
22354
+ ":focus-within": {
22355
+ "borderColor": "var(--color-theme-700)"
22356
+ },
22357
+ ":hover": {
22358
+ "borderColor": "var(--color-theme-700)"
22359
+ }
22360
+ }, function (_ref) {
22361
+ var invalid = _ref.invalid;
22362
+ return invalid && styled.css(["border-color:var(--red-alert) !important;"]);
22363
+ });
22364
+ var EditableText = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
22365
+ var onSave = _ref2.onSave,
22366
+ onCancel = _ref2.onCancel,
22367
+ value = _ref2.value,
22368
+ inputProps = _ref2.inputProps,
22369
+ allowEmptyString = _ref2.allowEmptyString,
22370
+ _ref2$multiline = _ref2.multiline,
22371
+ multiline = _ref2$multiline === void 0 ? false : _ref2$multiline,
22372
+ _ref2$variant = _ref2.variant,
22373
+ variant = _ref2$variant === void 0 ? "Body 2" : _ref2$variant,
22374
+ weight = _ref2.weight,
22375
+ _ref2$disabled = _ref2.disabled,
22376
+ disabled = _ref2$disabled === void 0 ? false : _ref2$disabled,
22377
+ invalid = _ref2.invalid,
22378
+ wrapRef = _ref2.wrapRef,
22379
+ children = _ref2.children,
22380
+ props = _objectWithoutProperties(_ref2, _excluded$f);
22346
22381
  var _useState = React.useState(value),
22347
22382
  _useState2 = _slicedToArray(_useState, 2),
22348
22383
  currentValue = _useState2[0],
@@ -22352,6 +22387,11 @@
22352
22387
  prevValue = _useState4[0],
22353
22388
  setPrevValue = _useState4[1];
22354
22389
  var escapeRef = React.useRef(false);
22390
+ var intTextareaRef = React.useRef(null);
22391
+ var _useState5 = React.useState(false),
22392
+ _useState6 = _slicedToArray(_useState5, 2),
22393
+ isTextareaFocused = _useState6[0],
22394
+ setIsTextareaFocused = _useState6[1];
22355
22395
  React.useEffect(function () {
22356
22396
  if (currentValue !== value) {
22357
22397
  setCurrentValue(value);
@@ -22360,6 +22400,7 @@
22360
22400
  // eslint-disable-next-line react-hooks/exhaustive-deps
22361
22401
  }, [value]);
22362
22402
  var handleBlur = React.useCallback(function (e) {
22403
+ setIsTextareaFocused(false);
22363
22404
  if (escapeRef.current) {
22364
22405
  setCurrentValue(prevValue);
22365
22406
  escapeRef.current = false;
@@ -22372,9 +22413,16 @@
22372
22413
  !allowEmptyString ? setCurrentValue(prevValue) : typeof onSave === "function" && prevValue !== e.target.value && onSave(e);
22373
22414
  }
22374
22415
  }
22375
- }, [allowEmptyString, onSave, prevValue]);
22416
+ // Reset scroll position for textarea
22417
+ if (multiline && intTextareaRef !== null && intTextareaRef !== void 0 && intTextareaRef.current) {
22418
+ intTextareaRef.current.scrollLeft = 0;
22419
+ }
22420
+ }, [allowEmptyString, onSave, prevValue, multiline]);
22421
+ var handleFocus = React.useCallback(function () {
22422
+ setIsTextareaFocused(true);
22423
+ }, []);
22376
22424
  var handleKeyDown = React.useCallback(function (e) {
22377
- if (e.key === "Enter") {
22425
+ if (e.key === "Enter" && !multiline) {
22378
22426
  e.target.blur();
22379
22427
  }
22380
22428
  if (e.key === "Escape") {
@@ -22382,11 +22430,43 @@
22382
22430
  e.target.blur();
22383
22431
  typeof onCancel === "function" && onCancel();
22384
22432
  }
22385
- }, [onCancel]);
22433
+ }, [onCancel, multiline]);
22386
22434
  var handleChange = React.useCallback(function (e) {
22387
22435
  setCurrentValue(e.target.value);
22388
22436
  }, []);
22437
+ if (multiline) {
22438
+ return /*#__PURE__*/React__default["default"].createElement(StyledDiv, _extends({
22439
+ ref: wrapRef
22440
+ }, props), /*#__PURE__*/React__default["default"].createElement(StyledSpan, {
22441
+ variant: variant,
22442
+ forwardedAs: "span",
22443
+ weight: weight,
22444
+ $disabled: !isTextareaFocused,
22445
+ className: "presentation"
22446
+ }, children ? children : String(currentValue || "").replace(/\n/g, " ")), /*#__PURE__*/React__default["default"].createElement(StyledTextareaSpan, _extends({
22447
+ ref: intTextareaRef,
22448
+ forwardedAs: "textarea",
22449
+ variant: variant,
22450
+ weight: weight,
22451
+ value: currentValue !== null && currentValue !== void 0 ? currentValue : "",
22452
+ onFocus: handleFocus,
22453
+ onBlur: handleBlur,
22454
+ onKeyDown: handleKeyDown,
22455
+ onChange: handleChange,
22456
+ disabled: disabled,
22457
+ invalid: invalid,
22458
+ "data-form-type": "other",
22459
+ placeholder: inputProps === null || inputProps === void 0 ? void 0 : inputProps.placeholder,
22460
+ className: classNames__default["default"]("c-textarea", inputProps === null || inputProps === void 0 ? void 0 : inputProps.className),
22461
+ rows: 3
22462
+ }, inputProps)));
22463
+ }
22389
22464
  return /*#__PURE__*/React__default["default"].createElement(EditableContent, _extends({}, props, {
22465
+ variant: variant,
22466
+ weight: weight,
22467
+ disabled: disabled,
22468
+ invalid: invalid,
22469
+ wrapRef: wrapRef,
22390
22470
  ref: ref,
22391
22471
  inputProps: _objectSpread2(_objectSpread2({}, inputProps), {}, {
22392
22472
  value: currentValue !== null && currentValue !== void 0 ? currentValue : "",
@@ -22396,7 +22476,7 @@
22396
22476
  type: "text",
22397
22477
  className: classNames__default["default"]("c-input", inputProps === null || inputProps === void 0 ? void 0 : inputProps.className)
22398
22478
  })
22399
- }));
22479
+ }), children);
22400
22480
  });
22401
22481
  EditableText.displayName = "EditableText";
22402
22482