1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

152 lines
5.9 KiB
JavaScript
Raw Normal View History

2020-01-17 02:50:57 -07:00
import React from "react";
2020-01-20 00:37:04 -07:00
import { Accordion, Box, Stack, useTheme } from "@chakra-ui/core";
2020-01-17 02:50:57 -07:00
import { motion, AnimatePresence } from "framer-motion";
import Label from "~/components/Label";
import Result from "~/components/Result";
2020-01-20 00:37:04 -07:00
import useConfig from "~/components/HyperglassProvider";
import useMedia from "~/components/MediaProvider";
2020-01-17 02:50:57 -07:00
const AnimatedResult = motion.custom(Result);
const AnimatedLabel = motion.custom(Label);
2020-01-20 00:37:04 -07:00
const labelInitial = {
left: {
sm: { opacity: 0, x: -100 },
md: { opacity: 0, x: -100 },
lg: { opacity: 0, x: -100 },
xl: { opacity: 0, x: -100 }
},
center: {
sm: { opacity: 0 },
md: { opacity: 0 },
lg: { opacity: 0 },
xl: { opacity: 0 }
},
right: {
sm: { opacity: 0, x: 100 },
md: { opacity: 0, x: 100 },
lg: { opacity: 0, x: 100 },
xl: { opacity: 0, x: 100 }
}
};
const labelAnimate = {
left: {
sm: { opacity: 1, x: 0 },
md: { opacity: 1, x: 0 },
lg: { opacity: 1, x: 0 },
xl: { opacity: 1, x: 0 }
},
center: {
sm: { opacity: 1 },
md: { opacity: 1 },
lg: { opacity: 1 },
xl: { opacity: 1 }
},
right: {
sm: { opacity: 1, x: 0 },
md: { opacity: 1, x: 0 },
lg: { opacity: 1, x: 0 },
xl: { opacity: 1, x: 0 }
}
};
const Results = ({ queryLocation, queryType, queryVrf, queryTarget, setSubmitting, ...props }) => {
const config = useConfig();
2020-01-17 02:50:57 -07:00
const theme = useTheme();
2020-01-20 00:37:04 -07:00
const { mediaSize } = useMedia();
2020-01-17 02:50:57 -07:00
const matchedVrf = config.vrfs.filter(v => v.id === queryVrf)[0];
return (
<>
<Box
maxW={["100%", "100%", "75%", "50%"]}
w="100%"
p={0}
mx="auto"
my={4}
textAlign="left"
{...props}
>
2020-01-20 00:37:04 -07:00
<Stack isInline align="center" justify="center" mt={4} flexWrap="wrap">
2020-01-17 02:50:57 -07:00
<AnimatePresence>
{queryLocation && (
<>
<AnimatedLabel
2020-01-20 00:37:04 -07:00
initial={labelInitial.left[mediaSize]}
animate={labelAnimate.left[mediaSize]}
2020-01-17 02:50:57 -07:00
transition={{ duration: 0.3, delay: 0.3 }}
exit={{ opacity: 0, x: -100 }}
label={config.web.text.query_type}
value={config.queries[queryType].display_name}
2020-01-17 02:50:57 -07:00
valueBg={theme.colors.cyan[500]}
2020-01-20 00:37:04 -07:00
fontSize={["xs", "sm", "sm", "sm"]}
2020-01-17 02:50:57 -07:00
/>
<AnimatedLabel
2020-01-20 00:37:04 -07:00
initial={labelInitial.center[mediaSize]}
animate={labelAnimate.center[mediaSize]}
2020-01-17 02:50:57 -07:00
transition={{ duration: 0.3, delay: 0.3 }}
exit={{ opacity: 0, scale: 0.5 }}
label={config.web.text.query_target}
2020-01-17 02:50:57 -07:00
value={queryTarget}
valueBg={theme.colors.teal[600]}
2020-01-20 00:37:04 -07:00
fontSize={["xs", "sm", "sm", "sm"]}
2020-01-17 02:50:57 -07:00
/>
<AnimatedLabel
2020-01-20 00:37:04 -07:00
initial={labelInitial.right[mediaSize]}
animate={labelAnimate.right[mediaSize]}
2020-01-17 02:50:57 -07:00
transition={{ duration: 0.3, delay: 0.3 }}
exit={{ opacity: 0, x: 100 }}
label={config.web.text.query_vrf}
2020-01-17 02:50:57 -07:00
value={matchedVrf.display_name}
valueBg={theme.colors.blue[500]}
2020-01-20 00:37:04 -07:00
fontSize={["xs", "sm", "sm", "sm"]}
2020-01-17 02:50:57 -07:00
/>
</>
)}
</AnimatePresence>
</Stack>
</Box>
<Box
2020-01-20 00:37:04 -07:00
maxW={["100%", "100%", "75%", "75%"]}
2020-01-17 02:50:57 -07:00
w="100%"
p={0}
mx="auto"
my={4}
textAlign="left"
borderWidth="1px"
rounded="lg"
overflow="hidden"
>
<Accordion
initial={{ opacity: 1 }}
transition={{ duration: 0.3 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: 300 }}
>
<AnimatePresence>
{queryLocation &&
queryLocation.map((loc, i) => (
<AnimatedResult
initial={{ opacity: 0, y: 300 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3, delay: i * 0.3 }}
exit={{ opacity: 0, y: 300 }}
key={loc}
timeout={config.request_timeout * 1000}
2020-01-17 02:50:57 -07:00
device={config.devices[loc]}
queryLocation={loc}
queryType={queryType}
queryVrf={queryVrf}
queryTarget={queryTarget}
setSubmitting={setSubmitting}
/>
))}
</AnimatePresence>
</Accordion>
</Box>
</>
);
};
2020-01-20 00:37:04 -07:00
Results.displayName = "HyperglassResults";
export default Results;