@terraware/web-components 5.2.1-rc.0 → 5.2.1-rc.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.
- package/components/FormBottomBar/index.d.ts +2 -1
- package/components/FormBottomBar/index.d.ts.map +1 -1
- package/components/FormBottomBar/index.js +2 -1
- package/components/MultiSelect/index.d.ts +0 -1
- package/components/MultiSelect/index.d.ts.map +1 -1
- package/components/MultiSelect/index.js +5 -63
- package/components/MultiSelect/styles.scss +0 -4
- package/components/PageForm/index.d.ts +2 -1
- package/components/PageForm/index.d.ts.map +1 -1
- package/components/PageForm/index.js +20 -5
- package/package.json +1 -1
|
@@ -14,9 +14,10 @@ export interface Props {
|
|
|
14
14
|
cancelButtonText?: string;
|
|
15
15
|
saveButtonText: string;
|
|
16
16
|
saveDisabled?: boolean;
|
|
17
|
+
cancelDisabled?: boolean;
|
|
17
18
|
onSave: () => void;
|
|
18
19
|
additionalRightButtons?: FormButton[];
|
|
19
20
|
desktopOffset?: string;
|
|
20
21
|
}
|
|
21
|
-
export default function FormBottomBar({ cancelID, saveID, onCancel, cancelButtonText, saveButtonText, saveDisabled, onSave, additionalRightButtons, desktopOffset, }: Props): JSX.Element;
|
|
22
|
+
export default function FormBottomBar({ cancelID, saveID, onCancel, cancelButtonText, saveButtonText, saveDisabled, cancelDisabled, onSave, additionalRightButtons, desktopOffset, }: Props): JSX.Element;
|
|
22
23
|
//# 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;IAC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AAE,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"}
|
|
@@ -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, onSave, additionalRightButtons, desktopOffset }) {
|
|
7
|
+
function FormBottomBar({ cancelID, saveID, onCancel, cancelButtonText, saveButtonText, saveDisabled, cancelDisabled, onSave, additionalRightButtons, desktopOffset }) {
|
|
8
8
|
const { isMobile, isDesktop } = useDeviceInfo();
|
|
9
9
|
const theme = useTheme();
|
|
10
10
|
return /*#__PURE__*/ jsxs(AppBar, {
|
|
@@ -35,6 +35,7 @@ function FormBottomBar({ cancelID, saveID, onCancel, cancelButtonText, saveButto
|
|
|
35
35
|
size: "medium",
|
|
36
36
|
label: cancelButtonText,
|
|
37
37
|
onClick: onCancel,
|
|
38
|
+
disabled: cancelDisabled,
|
|
38
39
|
priority: "secondary",
|
|
39
40
|
type: "passive",
|
|
40
41
|
style: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/MultiSelect/index.tsx"],"names":[],"mappings":"A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AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CAgIpF"}
|
|
@@ -1,50 +1,13 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useEffect, 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
|
-
};
|
|
20
8
|
function MultiSelect(props) {
|
|
21
|
-
const { className, disabled, fullWidth, helperText, errorText,
|
|
9
|
+
const { className, disabled, fullWidth, helperText, errorText, id, label, missingValuePlaceholder, onAdd, onRemove, onPillClick, options, optionsVisible, pillListClassName, placeHolder, selectedOptions, sx, tooltipTitle, valueRenderer } = props;
|
|
22
10
|
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
|
-
}, []);
|
|
48
11
|
const toggleOptions = ()=>{
|
|
49
12
|
setOpenedOptions((isOpen)=>!isOpen && !disabled);
|
|
50
13
|
if (props.onFocus) props.onFocus();
|
|
@@ -54,30 +17,12 @@ function MultiSelect(props) {
|
|
|
54
17
|
}, [
|
|
55
18
|
optionsVisible
|
|
56
19
|
]);
|
|
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
|
-
]);
|
|
76
20
|
const onBlurHandler = (event)=>{
|
|
77
21
|
if (event.currentTarget.contains(event.relatedTarget)) return;
|
|
78
22
|
setOpenedOptions(false);
|
|
79
23
|
if (props.onBlur) props.onBlur();
|
|
80
24
|
};
|
|
25
|
+
const unselectedOptions = Array.from(options.keys()).filter((key)=>!selectedOptions.includes(key));
|
|
81
26
|
const valuesPillData = selectedOptions.map((item)=>{
|
|
82
27
|
const value = options.get(item);
|
|
83
28
|
return {
|
|
@@ -129,13 +74,10 @@ function MultiSelect(props) {
|
|
|
129
74
|
})
|
|
130
75
|
]
|
|
131
76
|
}),
|
|
132
|
-
|
|
77
|
+
options && unselectedOptions.length > 0 && openedOptions && /*#__PURE__*/ jsx("div", {
|
|
133
78
|
className: "multi-select__options-container",
|
|
134
|
-
ref: optionsContainerRef,
|
|
135
79
|
children: /*#__PURE__*/ jsx("ul", {
|
|
136
|
-
className:
|
|
137
|
-
ref: optionsRef,
|
|
138
|
-
style: fixedMenu ? fixedMenuStyle : void 0,
|
|
80
|
+
className: 'multi-select__options',
|
|
139
81
|
children: unselectedOptions.map((optionKey, index)=>{
|
|
140
82
|
const optionValue = options.get(optionKey);
|
|
141
83
|
return /*#__PURE__*/ jsx("li", {
|
|
@@ -155,10 +155,6 @@
|
|
|
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
|
-
|
|
162
158
|
.select-value {
|
|
163
159
|
font-family: terraware.$tw-fnt-frm-fld-select-value-font-family;
|
|
164
160
|
font-size: terraware.$tw-fnt-frm-fld-select-value-font-size;
|
|
@@ -5,10 +5,11 @@ export type PageFormProps = {
|
|
|
5
5
|
cancelID: string;
|
|
6
6
|
saveID: string;
|
|
7
7
|
onCancel: () => void;
|
|
8
|
-
onSave: () => void
|
|
8
|
+
onSave: () => void | Promise<unknown>;
|
|
9
9
|
cancelButtonText: string;
|
|
10
10
|
saveButtonText: string;
|
|
11
11
|
saveDisabled?: boolean;
|
|
12
|
+
cancelDisabled?: boolean;
|
|
12
13
|
className?: string;
|
|
13
14
|
hideEdit?: boolean;
|
|
14
15
|
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,
|
|
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;IACtC,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sBAAsB,CAAC,EAAE,UAAU,EAAE,CAAC;IACtC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,GAAG,CAAC,OAAO,CA+ClE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from "react";
|
|
2
|
+
import { useRef, 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,10 +9,19 @@ 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);
|
|
12
13
|
const handleSave = async ()=>{
|
|
14
|
+
if (processingRef.current) return;
|
|
15
|
+
processingRef.current = true;
|
|
13
16
|
setProcessing(true);
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
try {
|
|
18
|
+
await onSave();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error(error);
|
|
21
|
+
} finally{
|
|
22
|
+
processingRef.current = false;
|
|
23
|
+
setProcessing(false);
|
|
24
|
+
}
|
|
16
25
|
};
|
|
17
26
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
18
27
|
children: [
|
|
@@ -26,8 +35,14 @@ function PageForm(props) {
|
|
|
26
35
|
children: children
|
|
27
36
|
}),
|
|
28
37
|
!hideEdit && /*#__PURE__*/ jsx(FormBottomBar, {
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}))
|
|
31
46
|
})
|
|
32
47
|
]
|
|
33
48
|
});
|