@terraware/web-components 5.2.1-rc.1 → 5.2.2

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.
@@ -14,10 +14,9 @@ export interface Props {
14
14
  cancelButtonText?: string;
15
15
  saveButtonText: string;
16
16
  saveDisabled?: boolean;
17
- cancelDisabled?: boolean;
18
17
  onSave: () => void;
19
18
  additionalRightButtons?: FormButton[];
20
19
  desktopOffset?: string;
21
20
  }
22
- export default function FormBottomBar({ cancelID, saveID, onCancel, cancelButtonText, saveButtonText, saveDisabled, cancelDisabled, onSave, additionalRightButtons, desktopOffset, }: Props): JSX.Element;
21
+ export default function FormBottomBar({ cancelID, saveID, onCancel, cancelButtonText, saveButtonText, saveDisabled, onSave, additionalRightButtons, desktopOffset, }: Props): JSX.Element;
23
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FormBottomBar/index.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AASxC,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,cAAc,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IACzC,UAAU,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,aAAa,CAAC;CACvD;AAED,MAAM,WAAW,KAAK;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,sBAAsB,CAAC,EAAE,UAAU,EAAE,CAAC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,cAAc,EACd,MAAM,EACN,sBAAsB,EACtB,aAAa,GACd,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CA6ErB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FormBottomBar/index.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AASxC,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,cAAc,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IACzC,UAAU,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,aAAa,CAAC;CACvD;AAED,MAAM,WAAW,KAAK;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,sBAAsB,CAAC,EAAE,UAAU,EAAE,CAAC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,MAAM,EACN,sBAAsB,EACtB,aAAa,GACd,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CA4ErB"}
@@ -4,7 +4,7 @@ import { AppBar, Box, useTheme } from "@mui/material";
4
4
  import useDeviceInfo from "../../utils/useDeviceInfo.js";
5
5
  import Button from "../Button/Button.js";
6
6
  const defaultDesktopOffset = '200px';
7
- function FormBottomBar({ cancelID, saveID, onCancel, cancelButtonText, saveButtonText, saveDisabled, cancelDisabled, onSave, additionalRightButtons, desktopOffset }) {
7
+ function FormBottomBar({ cancelID, saveID, onCancel, cancelButtonText, saveButtonText, saveDisabled, onSave, additionalRightButtons, desktopOffset }) {
8
8
  const { isMobile, isDesktop } = useDeviceInfo();
9
9
  const theme = useTheme();
10
10
  return /*#__PURE__*/ jsxs(AppBar, {
@@ -35,7 +35,6 @@ function FormBottomBar({ cancelID, saveID, onCancel, cancelButtonText, saveButto
35
35
  size: "medium",
36
36
  label: cancelButtonText,
37
37
  onClick: onCancel,
38
- disabled: cancelDisabled,
39
38
  priority: "secondary",
40
39
  type: "passive",
41
40
  style: {
@@ -7,6 +7,7 @@ export type MultiSelectProps<K, V> = {
7
7
  fullWidth?: boolean;
8
8
  helperText?: string;
9
9
  errorText?: string;
10
+ fixedMenu?: boolean;
10
11
  id?: string;
11
12
  label?: string;
12
13
  missingValuePlaceholder?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/MultiSelect/index.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,GAAG,EAAuB,MAAM,OAAO,CAAC;AAE7D,OAAO,EAAO,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAK3D,OAAO,eAAe,CAAC;AAEvB,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,IAAI;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAA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MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAChC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,OAAO,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,CAAC,EAAE,CAAC;IACrB,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,YAAY,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,aAAa,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;CACrC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CAmLpF"}
@@ -1,13 +1,50 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useEffect, useState } from "react";
2
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
3
3
  import { Box } from "@mui/material";
4
4
  import Icon from "../Icon/Icon.js";
5
5
  import IconTooltip from "../IconTooltip/index.js";
6
6
  import PillList from "../PillList/index.js";
7
7
  import "./styles.scss";
8
+ const OPTIONS_MAX_HEIGHT = 140;
9
+ const VIEWPORT_MARGIN = 8;
10
+ const getVerticalFrameHeight = (element)=>{
11
+ const style = getComputedStyle(element);
12
+ const spacing = [
13
+ style.paddingTop,
14
+ style.paddingBottom,
15
+ style.marginTop,
16
+ style.marginBottom
17
+ ].reduce((total, value)=>total + (parseFloat(value) || 0), 0);
18
+ return element.offsetHeight - element.clientHeight + spacing;
19
+ };
8
20
  function MultiSelect(props) {
9
- const { className, disabled, fullWidth, helperText, errorText, id, label, missingValuePlaceholder, onAdd, onRemove, onPillClick, options, optionsVisible, pillListClassName, placeHolder, selectedOptions, sx, tooltipTitle, valueRenderer } = props;
21
+ const { className, disabled, fullWidth, helperText, errorText, fixedMenu, id, label, missingValuePlaceholder, onAdd, onRemove, onPillClick, options, optionsVisible, pillListClassName, placeHolder, selectedOptions, sx, tooltipTitle, valueRenderer } = props;
10
22
  const [openedOptions, setOpenedOptions] = useState(false);
23
+ const [fixedMenuStyle, setFixedMenuStyle] = useState();
24
+ const optionsContainerRef = useRef(null);
25
+ const optionsRef = useRef(null);
26
+ const positionFixedMenu = useCallback(()=>{
27
+ const trigger = optionsContainerRef.current?.parentElement;
28
+ if (!optionsContainerRef.current || !trigger) return;
29
+ const { top, left, width } = optionsContainerRef.current.getBoundingClientRect();
30
+ const triggerTop = trigger.getBoundingClientRect().top;
31
+ const spaceBelow = window.innerHeight - top - VIEWPORT_MARGIN;
32
+ const spaceAbove = triggerTop - VIEWPORT_MARGIN;
33
+ const placeAbove = spaceBelow < OPTIONS_MAX_HEIGHT && spaceAbove > spaceBelow;
34
+ const menuFrameHeight = optionsRef.current ? getVerticalFrameHeight(optionsRef.current) : 0;
35
+ setFixedMenuStyle({
36
+ position: 'fixed',
37
+ left,
38
+ width: width - 2,
39
+ maxHeight: Math.max(0, Math.min(OPTIONS_MAX_HEIGHT, (placeAbove ? spaceAbove : spaceBelow) - menuFrameHeight)),
40
+ ...placeAbove ? {
41
+ top: 'auto',
42
+ bottom: window.innerHeight - triggerTop
43
+ } : {
44
+ top
45
+ }
46
+ });
47
+ }, []);
11
48
  const toggleOptions = ()=>{
12
49
  setOpenedOptions((isOpen)=>!isOpen && !disabled);
13
50
  if (props.onFocus) props.onFocus();
@@ -17,12 +54,30 @@ function MultiSelect(props) {
17
54
  }, [
18
55
  optionsVisible
19
56
  ]);
57
+ const unselectedOptions = Array.from(options.keys()).filter((key)=>!selectedOptions.includes(key));
58
+ const optionsShown = options && unselectedOptions.length > 0 && openedOptions;
59
+ useLayoutEffect(()=>{
60
+ if (!fixedMenu || !optionsShown) return;
61
+ positionFixedMenu();
62
+ window.addEventListener('scroll', positionFixedMenu, true);
63
+ window.addEventListener('resize', positionFixedMenu);
64
+ const triggerObserver = new ResizeObserver(positionFixedMenu);
65
+ if (optionsContainerRef.current?.parentElement) triggerObserver.observe(optionsContainerRef.current.parentElement);
66
+ return ()=>{
67
+ window.removeEventListener('scroll', positionFixedMenu, true);
68
+ window.removeEventListener('resize', positionFixedMenu);
69
+ triggerObserver.disconnect();
70
+ };
71
+ }, [
72
+ fixedMenu,
73
+ optionsShown,
74
+ positionFixedMenu
75
+ ]);
20
76
  const onBlurHandler = (event)=>{
21
77
  if (event.currentTarget.contains(event.relatedTarget)) return;
22
78
  setOpenedOptions(false);
23
79
  if (props.onBlur) props.onBlur();
24
80
  };
25
- const unselectedOptions = Array.from(options.keys()).filter((key)=>!selectedOptions.includes(key));
26
81
  const valuesPillData = selectedOptions.map((item)=>{
27
82
  const value = options.get(item);
28
83
  return {
@@ -74,10 +129,13 @@ function MultiSelect(props) {
74
129
  })
75
130
  ]
76
131
  }),
77
- options && unselectedOptions.length > 0 && openedOptions && /*#__PURE__*/ jsx("div", {
132
+ optionsShown && /*#__PURE__*/ jsx("div", {
78
133
  className: "multi-select__options-container",
134
+ ref: optionsContainerRef,
79
135
  children: /*#__PURE__*/ jsx("ul", {
80
- className: 'multi-select__options',
136
+ className: `multi-select__options${fixedMenu && fixedMenuStyle?.bottom !== void 0 ? ' multi-select__options--above' : ''}`,
137
+ ref: optionsRef,
138
+ style: fixedMenu ? fixedMenuStyle : void 0,
81
139
  children: unselectedOptions.map((optionKey, index)=>{
82
140
  const optionValue = options.get(optionKey);
83
141
  return /*#__PURE__*/ jsx("li", {
@@ -155,6 +155,10 @@
155
155
  max-height: 140px;
156
156
  overflow-y: auto;
157
157
 
158
+ &--above {
159
+ margin: 0 0 terraware.$tw-spc-base-xx-small;
160
+ }
161
+
158
162
  .select-value {
159
163
  font-family: terraware.$tw-fnt-frm-fld-select-value-font-family;
160
164
  font-size: terraware.$tw-fnt-frm-fld-select-value-font-size;
@@ -5,11 +5,10 @@ export type PageFormProps = {
5
5
  cancelID: string;
6
6
  saveID: string;
7
7
  onCancel: () => void;
8
- onSave: () => void | Promise<unknown>;
8
+ onSave: () => void;
9
9
  cancelButtonText: string;
10
10
  saveButtonText: string;
11
11
  saveDisabled?: boolean;
12
- cancelDisabled?: boolean;
13
12
  className?: string;
14
13
  hideEdit?: boolean;
15
14
  additionalRightButtons?: FormButton[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PageForm/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,KAAK,GAAG,EAAoB,MAAM,OAAO,CAAC;AAMzE,OAAsB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACt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O,CA2BlE"}
@@ -1,5 +1,5 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { useRef, useState } from "react";
2
+ import { useState } from "react";
3
3
  import { Box, useTheme } from "@mui/material";
4
4
  import useDeviceInfo from "../../utils/useDeviceInfo.js";
5
5
  import BusySpinner from "../BusySpinner/index.js";
@@ -9,19 +9,10 @@ function PageForm(props) {
9
9
  const theme = useTheme();
10
10
  const { isMobile } = useDeviceInfo();
11
11
  const [processing, setProcessing] = useState(false);
12
- const processingRef = useRef(false);
13
12
  const handleSave = async ()=>{
14
- if (processingRef.current) return;
15
- processingRef.current = true;
16
13
  setProcessing(true);
17
- try {
18
- await onSave();
19
- } catch (error) {
20
- console.error(error);
21
- } finally{
22
- processingRef.current = false;
23
- setProcessing(false);
24
- }
14
+ await onSave();
15
+ setProcessing(false);
25
16
  };
26
17
  return /*#__PURE__*/ jsxs(Fragment, {
27
18
  children: [
@@ -35,14 +26,8 @@ function PageForm(props) {
35
26
  children: children
36
27
  }),
37
28
  !hideEdit && /*#__PURE__*/ jsx(FormBottomBar, {
38
- ...bottomBarProps,
39
- onSave: ()=>void handleSave(),
40
- saveDisabled: processing || bottomBarProps.saveDisabled,
41
- cancelDisabled: processing || bottomBarProps.cancelDisabled,
42
- additionalRightButtons: bottomBarProps.additionalRightButtons?.map((button)=>({
43
- ...button,
44
- disabled: processing || button.disabled
45
- }))
29
+ onSave: handleSave,
30
+ ...bottomBarProps
46
31
  })
47
32
  ]
48
33
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terraware/web-components",
3
- "version": "5.2.1-rc.1",
3
+ "version": "5.2.2",
4
4
  "author": "Terraformation Inc.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {