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

116 lines
3.3 KiB
JavaScript
Raw Normal View History

/** @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' };
const justifyMap = {
2020-10-07 09:41:58 -07:00
true: ['flex-end', 'center', 'center', 'center'],
false: ['flex-start', 'center', 'center', 'center'],
};
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-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]}>
{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"
2020-10-07 09:41:58 -07:00
fontSize={['md', 'md', 'xl', 'xl']}
whiteSpace="break-spaces"
2020-10-07 09:41:58 -07:00
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-10-07 09:41:58 -07:00
<Stack spacing={2} maxW="100%" textAlign={textAlignment[showSubtitle]} {...props}>
<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();
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={{
2020-10-07 09:41:58 -07:00
userDrag: 'none',
userSelect: 'none',
msUserSelect: 'none',
MozUserSelect: 'none',
WebkitUserDrag: 'none',
WebkitUserSelect: 'none',
}}
2020-06-22 18:07:00 -07:00
alt={text.title}
2020-10-07 09:41:58 -07:00
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-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
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}
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
});