PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.0.0
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.0.0
3.6.0 3.5.3 3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / src / dashboard / components / IntersectionObserver / IntersectionObserver.js
everest-forms / src / dashboard / components / IntersectionObserver Last commit date
IntersectionObserver.js 2 years ago
IntersectionObserver.js
182 lines
1 /**
2 * External Dependencies
3 */
4 import React, { useEffect, useRef, useState } from "react";
5 import {
6 HStack,
7 IconButton,
8 Menu,
9 MenuButton,
10 MenuItem,
11 MenuList,
12 } from "@chakra-ui/react";
13 import { NavLink, useLocation } from "react-router-dom";
14 import PropTypes from "prop-types";
15
16 /**
17 * Internal Dependencies
18 */
19 import { DotsHorizontal } from "../Icon/Icon";
20
21 const IntersectionStyles = {
22 visible: {
23 order: 0,
24 visibility: "visible",
25 opacity: 1,
26 },
27 inVisible: {
28 order: 100,
29 visibility: "hidden",
30 pointerEvents: "none",
31 },
32 toolbarWrapper: {
33 overflow: "hidden",
34 display: "flex",
35 border: "1px solid black",
36 alignItem: "center",
37 },
38 overflowStyle: {
39 order: 99,
40 position: "sticky",
41 right: "0",
42 backgroundColor: "white",
43 },
44 };
45
46 const IntersectObserver = ({ children, routes }) => {
47 const ref = useRef(null);
48 const [visibleMap, setVisibleMap] = useState({});
49 const location = useLocation();
50 const hiddenRoutes = routes.filter((route) => !visibleMap[route.route]);
51
52 const selectedHiddenRoute = hiddenRoutes.find(
53 (h) => h.route === location.pathname
54 );
55
56 useEffect(() => {
57 if (!ref.current) return;
58 const observer = new IntersectionObserver(
59 (entries) => {
60 const updatedEntries = {};
61 entries.forEach((entry) => {
62 const target = entry.target.dataset?.["target"];
63 if (entry.isIntersecting && target) {
64 updatedEntries[target] = true;
65 }
66 if (!entry.isIntersecting && target) {
67 updatedEntries[target] = false;
68 }
69 });
70
71 setVisibleMap((prev) => ({
72 ...prev,
73 ...updatedEntries,
74 }));
75 },
76 {
77 root: ref.current,
78 threshold: 0.98,
79 }
80 );
81
82 Array.from(ref.current.children).forEach((item) => {
83 if (item.getAttribute("data-target")) {
84 observer.observe(item);
85 }
86 });
87
88 return () => observer.disconnect();
89 }, []);
90
91 const shouldShowMenu = Object.values(visibleMap).some((v) => v === false);
92
93 return (
94 <HStack
95 ref={ref}
96 width={{
97 base: "50px",
98 sm: "240px",
99 md: "520px",
100 lg: "570px",
101 xl: "680px",
102 }}
103 overflow={"hidden"}
104 h="full"
105 >
106 {React.Children.map(children, (child) => {
107 const otherSX = visibleMap[child.props["data-target"]]
108 ? IntersectionStyles.visible
109 : IntersectionStyles.inVisible;
110
111 return React.cloneElement(child, {
112 sx: { ...children?.props?.sx, ...otherSX },
113 });
114 })}
115
116 {shouldShowMenu && (
117 <Menu>
118 <MenuButton
119 as={IconButton}
120 aria-label="Options"
121 sx={IntersectionStyles.overflowStyle}
122 style={{
123 background: "#FFFFFF",
124 boxShadow: "none",
125 marginLeft: "0px",
126 }}
127 color={
128 !!selectedHiddenRoute ? "primary.500" : "#383838"
129 }
130 visibility={"visible"}
131 icon={<DotsHorizontal w="24px" h="24px" />}
132 ></MenuButton>
133 <MenuList display="flex" flexDirection="column">
134 {hiddenRoutes.map(({ label, route }) => {
135 return (
136 <MenuItem
137 key={route}
138 as={NavLink}
139 to={route}
140 marginBottom={"0px"}
141 data-target={route}
142 fontSize="sm"
143 fontWeight="semibold"
144 lineHeight="150%"
145 color="#383838"
146 _hover={{
147 color: "primary.500",
148 }}
149 _focus={{
150 boxShadow: "none",
151 }}
152 _activeLink={{
153 color: "primary.500",
154 }}
155 display="inline-flex"
156 alignItems="center"
157 px="2"
158 py="10px"
159 >
160 {label}
161 </MenuItem>
162 );
163 })}
164 </MenuList>
165 </Menu>
166 )}
167 </HStack>
168 );
169 };
170
171 IntersectObserver.propTypes = {
172 children: PropTypes.any,
173 routes: PropTypes.arrayOf(
174 PropTypes.shape({
175 label: PropTypes.string.isRequired,
176 route: PropTypes.string.isRequired,
177 })
178 ).isRequired,
179 };
180
181 export default IntersectObserver;
182