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

99 lines
3.1 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 { Button, Heading, Image, Stack, useColorMode } from "@chakra-ui/core";
import { motion, AnimatePresence } from "framer-motion";
import useConfig from "~/components/HyperglassProvider";
import useMedia from "~/components/MediaProvider";
2020-01-17 02:50:57 -07:00
2020-01-20 00:37:04 -07:00
const subtitleAnimation = {
transition: { duration: 0.2, type: "tween" },
initial: { opacity: 1, scale: 1 },
animate: { opacity: 1, scale: 1 },
exit: { opacity: 0, scale: 0.3 }
};
const titleSize = { true: "2xl", false: "lg" };
const titleMargin = { true: 2, false: 0 };
const TitleOnly = ({ text, showSubtitle }) => (
<Heading as="h1" mb={titleMargin[showSubtitle]} size={titleSize[showSubtitle]}>
2020-01-17 02:50:57 -07:00
{text}
</Heading>
);
2020-01-20 00:37:04 -07:00
const SubtitleOnly = React.forwardRef(({ text, size = "md", ...props }, ref) => (
<Heading ref={ref} as="h3" size={size} {...props}>
2020-01-17 02:50:57 -07:00
{text}
</Heading>
2020-01-20 00:37:04 -07:00
));
const AnimatedSubtitle = motion.custom(SubtitleOnly);
2020-01-17 02:50:57 -07:00
2020-01-20 00:37:04 -07:00
const textAlignment = { false: ["right", "center"], true: ["left", "center"] };
const TextOnly = ({ text, mediaSize, showSubtitle, ...props }) => (
<Stack spacing={2} textAlign={textAlignment[showSubtitle]} {...props}>
<TitleOnly text={text.title} showSubtitle={showSubtitle} />
<AnimatePresence>
{showSubtitle && <AnimatedSubtitle text={text.subtitle} {...subtitleAnimation} />}
</AnimatePresence>
2020-01-17 02:50:57 -07:00
</Stack>
);
2020-01-20 00:37:04 -07:00
const Logo = ({ text, logo }) => {
2020-01-17 02:50:57 -07:00
const { colorMode } = useColorMode();
const logoColor = { light: logo.dark, dark: logo.light };
const logoPath = logoColor[colorMode];
2020-01-20 00:37:04 -07:00
return <Image src={logoPath} alt={text.title} />;
2020-01-17 02:50:57 -07:00
};
2020-01-20 00:37:04 -07:00
const LogoTitle = ({ text, logo, showSubtitle }) => (
2020-01-17 02:50:57 -07:00
<>
2020-01-20 00:37:04 -07:00
<Logo text={text} logo={logo} />
<AnimatePresence>
{showSubtitle && (
<AnimatedSubtitle mt={2} text={text.subtitle} {...subtitleAnimation} />
)}
</AnimatePresence>
2020-01-17 02:50:57 -07:00
</>
);
2020-01-20 00:37:04 -07:00
const All = ({ text, logo, mediaSize, showSubtitle }) => (
2020-01-17 02:50:57 -07:00
<>
2020-01-20 00:37:04 -07:00
<Logo text={text} logo={logo} />
<TextOnly mediaSize={mediaSize} showSubtitle={showSubtitle} mt={2} text={text} />
2020-01-17 02:50:57 -07:00
</>
);
2020-01-20 00:37:04 -07:00
const modeMap = { text_only: TextOnly, logo_only: Logo, logo_title: LogoTitle, all: All };
2020-01-17 02:50:57 -07:00
2020-01-20 00:37:04 -07:00
const btnJustify = {
true: ["flex-end", "center"],
false: ["flex-start", "center"]
};
export default React.forwardRef(({ onClick, isSubmitting, ...props }, ref) => {
const { web } = useConfig();
2020-01-20 00:37:04 -07:00
const { mediaSize } = useMedia();
const titleMode = web.text.title_mode;
2020-01-20 00:37:04 -07:00
const MatchedMode = modeMap[titleMode];
2020-01-17 02:50:57 -07:00
return (
2020-01-20 00:37:04 -07:00
<Button
ref={ref}
variant="link"
onClick={onClick}
flexWrap="wrap"
_focus={{ boxShadow: "none" }}
_hover={{ textDecoration: "none" }}
justifyContent={btnJustify[isSubmitting]}
px={0}
{...props}
>
<MatchedMode
mediaSize={mediaSize}
showSubtitle={!isSubmitting}
text={web.text}
logo={web.logo}
2020-01-20 00:37:04 -07:00
/>
2020-01-17 02:50:57 -07:00
</Button>
);
});