@homefile/components-v2 2.40.15 → 2.40.17
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/components/homeAssistant/HomeMonitorButton.js +11 -28
- package/dist/components/homeBoard/HomeCardWithRecipent.js +1 -1
- package/dist/hooks/homeAssistant/useHomeMonitorButton.d.ts +18 -0
- package/dist/hooks/homeAssistant/useHomeMonitorButton.js +85 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,33 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
3
2
|
import { Box, Center, Image, Stack, Text } from '@chakra-ui/react';
|
|
4
3
|
import { keyframes } from '@emotion/react';
|
|
5
|
-
import { getIconAltText } from '../../utils';
|
|
6
4
|
import { IconMenu, MoreHorizontal } from '../../components';
|
|
7
|
-
import {
|
|
8
|
-
const COLLAPSE_AFTER_MS = 2000;
|
|
9
|
-
const INITIAL_BOTTOM = 0;
|
|
10
|
-
const COLLAPSED_BOTTOM = -60;
|
|
5
|
+
import { useHomeMonitorButton } from '../../hooks';
|
|
11
6
|
export const HomeMonitorButton = ({ alertCount = 0, currentStep, onStepClick, status = 'ok', step, menuItems = [], index, }) => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
setBottomOffset(COLLAPSED_BOTTOM);
|
|
23
|
-
}, COLLAPSE_AFTER_MS);
|
|
24
|
-
return () => window.clearTimeout(timeout);
|
|
25
|
-
}, []);
|
|
26
|
-
const handleStepClick = () => {
|
|
27
|
-
setIsHovered(false);
|
|
28
|
-
onStepClick(currentStep);
|
|
29
|
-
};
|
|
30
|
-
return (_jsx(Box, Object.assign({ position: "relative", id: buttonId, boxShadow: "lg", bottom: `${bottomOffset}px`, minH: "106px", onMouseEnter: () => setIsHovered(true), onMouseLeave: () => setIsHovered(false), onPointerEnter: () => setIsHovered(true), onPointerLeave: () => setIsHovered(false) }, getContainerStyles(status), { children: _jsxs(Box, { position: "relative", bg: "neutral.white", borderRadius: "lg", children: [_jsx(Box, { bg: alert ? 'error.2' : 'green.1', boxSize: "10px", borderRadius: "full", position: "absolute", top: "10px", left: "8px" }), _jsx(Box, { position: "absolute", top: "2px", right: "6px", zIndex: "1400", children: _jsx(IconMenu, { icon: _jsx(MoreHorizontal, { size: 26 }), itemForm: index + 1, menuItems: menuItems, disabled: isDisabled, onClick: () => setSelectedId(`homeMonitorButton-${index + 1}`), placement: "top" }) }), !isCollapsed && (_jsxs(Stack, { position: "relative", as: "button", spacing: "7px", border: "1px solid transparent", align: "center", justify: "center", w: "100%", p: "base", pt: "20px", onClick: handleStepClick, children: [!alert && (_jsx(Box, { boxSize: "36px", children: _jsx(Image, { src: step.icon, alt: iconAltText, w: "100%", h: "100%", fit: "contain" }) })), alert && (_jsx(Center, { boxSize: "36px", bg: "error.2", borderRadius: "full", color: "neutral.white", lineHeight: "1", fontWeight: "bold", children: alertCount })), _jsx(Center, { h: "28px", children: _jsx(Text, { fontSize: "14px", textTransform: "uppercase", textAlign: "center", lineHeight: "14px", fontFamily: "secondary", children: step.title }) })] }))] }) })));
|
|
7
|
+
const { alert, alertCount: displayAlertCount, bottomOffset, buttonId, handleEnter, handleLeave, handleMenuClick, handleStepClick, iconAltText, isCollapsed, isDisabled, wrappedMenuItems, } = useHomeMonitorButton({
|
|
8
|
+
alertCount,
|
|
9
|
+
currentStep,
|
|
10
|
+
onStepClick,
|
|
11
|
+
status,
|
|
12
|
+
step,
|
|
13
|
+
menuItems,
|
|
14
|
+
index,
|
|
15
|
+
});
|
|
16
|
+
return (_jsx(Box, Object.assign({ position: "relative", id: buttonId, boxShadow: "lg", bottom: `${bottomOffset}px`, minH: "106px", onMouseEnter: handleEnter, onMouseLeave: handleLeave, onPointerEnter: handleEnter, onPointerLeave: handleLeave }, getContainerStyles(status), { children: _jsxs(Box, { position: "relative", bg: "neutral.white", borderRadius: "lg", children: [_jsx(Box, { bg: alert ? 'error.2' : 'green.1', boxSize: "14px", borderRadius: "full", position: "absolute", top: "13px", left: "13px" }), _jsx(Box, { position: "absolute", top: "2px", right: "7px", zIndex: "1400", children: _jsx(IconMenu, { width: "fit-content", icon: _jsx(MoreHorizontal, { size: 32 }), itemForm: index + 1, menuItems: wrappedMenuItems, disabled: isDisabled, onClick: handleMenuClick, placement: "top" }) }), !isCollapsed && (_jsxs(Stack, { position: "relative", as: "button", spacing: "7px", border: "1px solid transparent", align: "center", justify: "center", w: "100%", p: "base", pt: "20px", onClick: handleStepClick, children: [!alert && (_jsx(Box, { boxSize: "36px", children: _jsx(Image, { src: step.icon, alt: iconAltText, w: "100%", h: "100%", fit: "contain" }) })), alert && (_jsx(Center, { boxSize: "36px", bg: "error.2", borderRadius: "full", color: "neutral.white", lineHeight: "1", fontWeight: "bold", children: displayAlertCount })), _jsx(Center, { h: "28px", children: _jsx(Text, { fontSize: "14px", textTransform: "uppercase", textAlign: "center", lineHeight: "14px", fontFamily: "secondary", children: step.title }) })] }))] }) })));
|
|
31
17
|
};
|
|
32
18
|
const alertGradient = keyframes `
|
|
33
19
|
0% { background-position: 0% 50%; }
|
|
@@ -40,9 +26,6 @@ const getContainerStyles = (status) => {
|
|
|
40
26
|
borderRadius: 'lg',
|
|
41
27
|
border: '2px solid transparent',
|
|
42
28
|
boxSizing: 'border-box',
|
|
43
|
-
_hover: {
|
|
44
|
-
bottom: 0,
|
|
45
|
-
},
|
|
46
29
|
};
|
|
47
30
|
if (status === 'alert') {
|
|
48
31
|
return Object.assign(Object.assign({}, base), { background: `linear-gradient(#FFFFFF, #FFFFFF) padding-box, ` +
|
|
@@ -21,5 +21,5 @@ export const HomeCardWithRecipent = ({ address: { city, state, street, number =
|
|
|
21
21
|
component: (_jsx(HomeCardRecipients, { recipients: recipients, menu: menu, onEditClick: handleEditAccountType })),
|
|
22
22
|
},
|
|
23
23
|
];
|
|
24
|
-
return (_jsxs(Container, { variant: "launchpad", children: [_jsx(HomeCard, { city: city, externalLink: externalLink, imageUrl: image, name: name, number: number, street: street, state: state, zip: zip, handleEditClick: () => handleEdit(_id), addImage: addImage, loading: loading, edit: !disabled, editImage: false }), _jsx(TabsHeader, { tabList: propertyDisabled ? noPropertyTabs : tabs }), handleDeleteAccountType && handleSubmitAccountType && (_jsx(RightPanel, { isOpen: isRightOpen, onClose: onRightClose, size: panelSize, children: _jsx(EditAccountType, { associateAccount: editingAccountType, handleClose: onRightClose, handleDelete: handleDeleteAccountType, handleSubmit: handleSubmitAccountType, isLoading: loading }) }))] }));
|
|
24
|
+
return (_jsxs(Container, { variant: "launchpad", overflow: 'hidden', children: [_jsx(HomeCard, { city: city, externalLink: externalLink, imageUrl: image, name: name, number: number, street: street, state: state, zip: zip, handleEditClick: () => handleEdit(_id), addImage: addImage, loading: loading, edit: !disabled, editImage: false }), _jsx(TabsHeader, { tabList: propertyDisabled ? noPropertyTabs : tabs }), handleDeleteAccountType && handleSubmitAccountType && (_jsx(RightPanel, { isOpen: isRightOpen, onClose: onRightClose, size: panelSize, children: _jsx(EditAccountType, { associateAccount: editingAccountType, handleClose: onRightClose, handleDelete: handleDeleteAccountType, handleSubmit: handleSubmitAccountType, isLoading: loading }) }))] }));
|
|
25
25
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HomeMonitorButtonI } from '../../interfaces';
|
|
2
|
+
export declare const useHomeMonitorButton: ({ alertCount, currentStep, onStepClick, status, step, menuItems, index, }: HomeMonitorButtonI) => {
|
|
3
|
+
alert: boolean;
|
|
4
|
+
alertCount: number;
|
|
5
|
+
bottomOffset: number;
|
|
6
|
+
buttonId: string;
|
|
7
|
+
handleEnter: () => void;
|
|
8
|
+
handleLeave: () => void;
|
|
9
|
+
handleMenuClick: () => void;
|
|
10
|
+
handleStepClick: () => void;
|
|
11
|
+
iconAltText: string;
|
|
12
|
+
isCollapsed: boolean;
|
|
13
|
+
isDisabled: boolean;
|
|
14
|
+
wrappedMenuItems: {
|
|
15
|
+
handleClick: (form: any) => void;
|
|
16
|
+
label: string;
|
|
17
|
+
}[];
|
|
18
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { getIconAltText } from '../../utils';
|
|
3
|
+
import { homeAssistantProxy } from '../../proxies';
|
|
4
|
+
const COLLAPSE_AFTER_MS = 2000;
|
|
5
|
+
const HOLD_ON_TOP_MS = 2000;
|
|
6
|
+
const INITIAL_BOTTOM = 0;
|
|
7
|
+
const COLLAPSED_BOTTOM = -65;
|
|
8
|
+
export const useHomeMonitorButton = ({ alertCount = 0, currentStep, onStepClick, status = 'ok', step, menuItems = [], index, }) => {
|
|
9
|
+
const [bottomOffset, setBottomOffset] = useState(INITIAL_BOTTOM);
|
|
10
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
11
|
+
const initialCollapseTimeoutRef = useRef(null);
|
|
12
|
+
const collapseTimeoutRef = useRef(null);
|
|
13
|
+
const buttonId = `homeMonitorButton-${currentStep}`;
|
|
14
|
+
const iconAltText = useMemo(() => getIconAltText(step.icon), [step.icon]);
|
|
15
|
+
const alert = status === 'alert';
|
|
16
|
+
const isDisabled = menuItems.length === 0;
|
|
17
|
+
const { setSelectedId } = homeAssistantProxy;
|
|
18
|
+
const isCollapsed = bottomOffset < 0 && !isHovered;
|
|
19
|
+
const clearInitialCollapseTimeout = () => {
|
|
20
|
+
if (initialCollapseTimeoutRef.current) {
|
|
21
|
+
window.clearTimeout(initialCollapseTimeoutRef.current);
|
|
22
|
+
initialCollapseTimeoutRef.current = null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const clearCollapseTimeout = () => {
|
|
26
|
+
if (collapseTimeoutRef.current) {
|
|
27
|
+
window.clearTimeout(collapseTimeoutRef.current);
|
|
28
|
+
collapseTimeoutRef.current = null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const scheduleCollapse = (delay = HOLD_ON_TOP_MS) => {
|
|
32
|
+
clearCollapseTimeout();
|
|
33
|
+
collapseTimeoutRef.current = window.setTimeout(() => {
|
|
34
|
+
setBottomOffset(COLLAPSED_BOTTOM);
|
|
35
|
+
}, delay);
|
|
36
|
+
};
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
initialCollapseTimeoutRef.current = window.setTimeout(() => {
|
|
39
|
+
setBottomOffset(COLLAPSED_BOTTOM);
|
|
40
|
+
}, COLLAPSE_AFTER_MS);
|
|
41
|
+
return () => {
|
|
42
|
+
clearInitialCollapseTimeout();
|
|
43
|
+
clearCollapseTimeout();
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
46
|
+
const handleEnter = () => {
|
|
47
|
+
clearInitialCollapseTimeout();
|
|
48
|
+
clearCollapseTimeout();
|
|
49
|
+
setIsHovered(true);
|
|
50
|
+
setBottomOffset(INITIAL_BOTTOM);
|
|
51
|
+
};
|
|
52
|
+
const handleLeave = () => {
|
|
53
|
+
setIsHovered(false);
|
|
54
|
+
scheduleCollapse(HOLD_ON_TOP_MS);
|
|
55
|
+
};
|
|
56
|
+
const handleStepClick = () => {
|
|
57
|
+
setIsHovered(false);
|
|
58
|
+
scheduleCollapse(HOLD_ON_TOP_MS);
|
|
59
|
+
onStepClick(currentStep);
|
|
60
|
+
};
|
|
61
|
+
const handleMenuClick = () => {
|
|
62
|
+
setSelectedId(`homeMonitorButton-${index + 1}`);
|
|
63
|
+
};
|
|
64
|
+
const wrappedMenuItems = useMemo(() => {
|
|
65
|
+
return menuItems.map((item) => (Object.assign(Object.assign({}, item), { handleClick: (form) => {
|
|
66
|
+
setIsHovered(false);
|
|
67
|
+
scheduleCollapse(HOLD_ON_TOP_MS);
|
|
68
|
+
item.handleClick(form);
|
|
69
|
+
} })));
|
|
70
|
+
}, [menuItems]);
|
|
71
|
+
return {
|
|
72
|
+
alert,
|
|
73
|
+
alertCount,
|
|
74
|
+
bottomOffset,
|
|
75
|
+
buttonId,
|
|
76
|
+
handleEnter,
|
|
77
|
+
handleLeave,
|
|
78
|
+
handleMenuClick,
|
|
79
|
+
handleStepClick,
|
|
80
|
+
iconAltText,
|
|
81
|
+
isCollapsed,
|
|
82
|
+
isDisabled,
|
|
83
|
+
wrappedMenuItems,
|
|
84
|
+
};
|
|
85
|
+
};
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED