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

139 lines
3.4 KiB
JavaScript
Raw Normal View History

/** @jsx jsx */
import { jsx } from "@emotion/core";
import { forwardRef } from "react";
2020-01-20 00:37:04 -07:00
import { Button, Heading, Image, Stack, useColorMode } from "@chakra-ui/core";
import useConfig from "~/components/HyperglassProvider";
import useMedia from "~/components/MediaProvider";
2020-01-17 02:50:57 -07:00
const titleSize = { true: ["2xl", "2xl", "5xl", "5xl"], false: "2xl" };
2020-01-20 00:37:04 -07:00
const titleMargin = { true: 2, false: 0 };
2020-03-29 20:04:37 -07:00
const textAlignment = { false: ["right", "center"], true: ["left", "center"] };
const logoName = { light: "dark", dark: "light" };
const justifyMap = {
true: ["flex-end", "center", "center", "center"],
false: ["flex-start", "center", "center", "center"]
};
const logoFallback = {
light:
"https://res.cloudinary.com/hyperglass/image/upload/v1593916013/logo-dark.svg",
dark:
"https://res.cloudinary.com/hyperglass/image/upload/v1593916013/logo-light.svg"
};
2020-01-20 00:37:04 -07:00
const TitleOnly = ({ text, showSubtitle }) => (
2020-05-02 13:38:00 -07:00
<Heading
as="h1"
mb={titleMargin[showSubtitle]}
fontSize={titleSize[showSubtitle]}
2020-05-02 13:38:00 -07:00
>
{text}
2020-05-02 13:38:00 -07:00
</Heading>
2020-01-17 02:50:57 -07:00
);
const SubtitleOnly = ({ text, mediaSize, ...props }) => (
<Heading
as="h3"
fontSize={["md", "md", "xl", "xl"]}
whiteSpace="break-spaces"
textAlign={["left", "left", "center", "center"]}
{...props}
>
{text}
</Heading>
2020-05-02 13:38:00 -07:00
);
2020-01-20 00:37:04 -07:00
const TextOnly = ({ text, mediaSize, showSubtitle, ...props }) => (
2020-05-02 13:38:00 -07:00
<Stack
spacing={2}
maxW="100%"
textAlign={textAlignment[showSubtitle]}
{...props}
>
<TitleOnly text={text.title} showSubtitle={showSubtitle} />
{showSubtitle && (
<SubtitleOnly text={text.subtitle} mediaSize={mediaSize} />
)}
2020-05-02 13:38:00 -07:00
</Stack>
2020-01-17 02:50:57 -07:00
);
2020-06-22 18:07:00 -07:00
const Logo = ({ text, logo }) => {
2020-05-02 13:38:00 -07:00
const { colorMode } = useColorMode();
const { width, dark_format, light_format } = logo;
const logoExt = { light: dark_format, dark: light_format };
2020-06-22 18:07:00 -07:00
return (
<Image
css={{
userDrag: "none",
userSelect: "none",
msUserSelect: "none",
MozUserSelect: "none",
WebkitUserDrag: "none",
WebkitUserSelect: "none"
}}
2020-06-22 18:07:00 -07:00
alt={text.title}
width={width ?? "auto"}
fallbackSrc={logoFallback[colorMode]}
2020-06-22 18:07:00 -07:00
src={`/images/${logoName[colorMode]}${logoExt[colorMode]}`}
/>
);
2020-01-17 02:50:57 -07:00
};
const LogoSubtitle = ({ text, logo, mediaSize }) => (
2020-05-02 13:38:00 -07:00
<>
2020-06-22 18:07:00 -07:00
<Logo text={text} logo={logo} mediaSize={mediaSize} />
<SubtitleOnly mt={6} text={text.subtitle} />
2020-05-02 13:38:00 -07:00
</>
2020-01-17 02:50:57 -07:00
);
2020-01-20 00:37:04 -07:00
const All = ({ text, logo, mediaSize, showSubtitle }) => (
2020-05-02 13:38:00 -07:00
<>
2020-06-22 18:07:00 -07:00
<Logo text={text} logo={logo} />
2020-05-02 13:38:00 -07:00
<TextOnly
mediaSize={mediaSize}
showSubtitle={showSubtitle}
mt={2}
text={text}
/>
</>
2020-01-17 02:50:57 -07:00
);
2020-05-02 13:38:00 -07:00
const modeMap = {
text_only: TextOnly,
logo_only: Logo,
logo_subtitle: LogoSubtitle,
all: All
};
2020-01-17 02:50:57 -07:00
const Title = forwardRef(({ onClick, isSubmitting, ...props }, ref) => {
2020-05-02 13:38:00 -07:00
const { web } = useConfig();
const { mediaSize } = useMedia();
const titleMode = web.text.title_mode;
const MatchedMode = modeMap[titleMode];
return (
<Button
2020-07-04 19:31:05 -07:00
px={0}
w="100%"
2020-05-02 13:38:00 -07:00
ref={ref}
variant="link"
flexWrap="wrap"
2020-07-04 19:31:05 -07:00
flexDir="column"
onClick={onClick}
2020-05-02 13:38:00 -07:00
_focus={{ boxShadow: "none" }}
_hover={{ textDecoration: "none" }}
justifyContent={justifyMap[isSubmitting]}
2020-07-04 19:31:05 -07:00
alignItems={["flex-start", "flex-start", "center"]}
2020-05-02 13:38:00 -07:00
{...props}
>
<MatchedMode
mediaSize={mediaSize}
showSubtitle={!isSubmitting}
text={web.text}
logo={web.logo}
/>
</Button>
);
2020-01-17 02:50:57 -07:00
});
2020-05-02 13:38:00 -07:00
export default Title;