2020-07-05 17:20:10 -07:00
|
|
|
/** @jsx jsx */
|
2020-10-07 09:41:58 -07:00
|
|
|
import { jsx } from '@emotion/core';
|
|
|
|
import { forwardRef } from 'react';
|
|
|
|
import { Button, Heading, Image, Stack, useColorMode } from '@chakra-ui/core';
|
|
|
|
import { useConfig, useMedia } from 'app/context';
|
2020-01-17 02:50:57 -07:00
|
|
|
|
2020-10-07 09:41:58 -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-10-07 09:41:58 -07:00
|
|
|
const textAlignment = { false: ['right', 'center'], true: ['left', 'center'] };
|
|
|
|
const logoName = { light: 'dark', dark: 'light' };
|
2020-07-05 17:20:10 -07:00
|
|
|
const justifyMap = {
|
2020-10-07 09:41:58 -07:00
|
|
|
true: ['flex-end', 'center', 'center', 'center'],
|
|
|
|
false: ['flex-start', 'center', 'center', 'center'],
|
2020-07-05 17:20:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const logoFallback = {
|
2020-10-07 09:41:58 -07:00
|
|
|
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-07-05 17:20:10 -07:00
|
|
|
};
|
2020-01-20 00:37:04 -07:00
|
|
|
|
|
|
|
const TitleOnly = ({ text, showSubtitle }) => (
|
2020-10-07 09:41:58 -07:00
|
|
|
<Heading as="h1" mb={titleMargin[showSubtitle]} fontSize={titleSize[showSubtitle]}>
|
2020-07-05 17:20:10 -07:00
|
|
|
{text}
|
2020-05-02 13:38:00 -07:00
|
|
|
</Heading>
|
2020-01-17 02:50:57 -07:00
|
|
|
);
|
|
|
|
|
2020-07-05 17:20:10 -07:00
|
|
|
const SubtitleOnly = ({ text, mediaSize, ...props }) => (
|
|
|
|
<Heading
|
|
|
|
as="h3"
|
2020-10-07 09:41:58 -07:00
|
|
|
fontSize={['md', 'md', 'xl', 'xl']}
|
2020-07-05 17:20:10 -07:00
|
|
|
whiteSpace="break-spaces"
|
2020-10-07 09:41:58 -07:00
|
|
|
textAlign={['left', 'left', 'center', 'center']}
|
|
|
|
{...props}>
|
2020-07-05 17:20:10 -07:00
|
|
|
{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-10-07 09:41:58 -07:00
|
|
|
<Stack spacing={2} maxW="100%" textAlign={textAlignment[showSubtitle]} {...props}>
|
2020-07-05 17:20:10 -07:00
|
|
|
<TitleOnly text={text.title} showSubtitle={showSubtitle} />
|
2020-10-07 09:41:58 -07:00
|
|
|
{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();
|
2020-07-05 17:20:10 -07:00
|
|
|
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
|
2020-07-05 17:20:10 -07:00
|
|
|
css={{
|
2020-10-07 09:41:58 -07:00
|
|
|
userDrag: 'none',
|
|
|
|
userSelect: 'none',
|
|
|
|
msUserSelect: 'none',
|
|
|
|
MozUserSelect: 'none',
|
|
|
|
WebkitUserDrag: 'none',
|
|
|
|
WebkitUserSelect: 'none',
|
2020-07-05 17:20:10 -07:00
|
|
|
}}
|
2020-06-22 18:07:00 -07:00
|
|
|
alt={text.title}
|
2020-10-07 09:41:58 -07:00
|
|
|
width={width ?? 'auto'}
|
2020-07-05 17:20:10 -07:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-07-05 17:20:10 -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} />
|
2020-07-05 17:20:10 -07:00
|
|
|
<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-10-07 09:41:58 -07:00
|
|
|
<TextOnly mediaSize={mediaSize} showSubtitle={showSubtitle} mt={2} text={text} />
|
2020-05-02 13:38:00 -07:00
|
|
|
</>
|
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,
|
2020-10-07 09:41:58 -07:00
|
|
|
all: All,
|
2020-05-02 13:38:00 -07:00
|
|
|
};
|
2020-01-17 02:50:57 -07:00
|
|
|
|
2020-09-28 11:54:00 -07:00
|
|
|
export 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}
|
2020-07-04 14:59:35 -07:00
|
|
|
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-10-07 09:41:58 -07:00
|
|
|
_focus={{ boxShadow: 'none' }}
|
|
|
|
_hover={{ textDecoration: 'none' }}
|
2020-05-02 13:38:00 -07:00
|
|
|
justifyContent={justifyMap[isSubmitting]}
|
2020-10-07 09:41:58 -07:00
|
|
|
alignItems={['flex-start', 'flex-start', 'center']}
|
|
|
|
{...props}>
|
2020-05-02 13:38:00 -07:00
|
|
|
<MatchedMode
|
|
|
|
mediaSize={mediaSize}
|
|
|
|
showSubtitle={!isSubmitting}
|
|
|
|
text={web.text}
|
|
|
|
logo={web.logo}
|
|
|
|
/>
|
|
|
|
</Button>
|
|
|
|
);
|
2020-01-17 02:50:57 -07:00
|
|
|
});
|