100 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-07-23 12:14:53 -04:00
import React from 'react';
import PropTypes from 'prop-types';
2019-03-15 10:19:57 -04:00
import styled from '@emotion/styled';
2018-07-23 12:14:53 -04:00
import Icon from './Icon';
import { buttons, shadows } from './styles';
import { GoBackButton } from './GoBackButton';
2018-07-23 12:14:53 -04:00
const StyledAuthenticationPage = styled.section`
display: flex;
flex-flow: column nowrap;
align-items: center;
justify-content: center;
height: 100vh;
`;
2018-07-23 12:14:53 -04:00
const CustomIconWrapper = styled.span`
width: 300px;
height: 200px;
margin-top: -150px;
`;
const NetlifyLogoIcon = styled(Icon)`
2018-07-23 12:14:53 -04:00
color: #c4c6d2;
margin-top: -300px;
`;
2018-07-23 12:14:53 -04:00
const NetlifyCreditIcon = styled(Icon)`
color: #c4c6d2;
position: absolute;
bottom: 10px;
`;
const CustomLogoIcon = ({ url }) => {
return (
<CustomIconWrapper>
<img src={url} alt="Logo" />
</CustomIconWrapper>
);
};
const renderPageLogo = logoUrl => {
if (logoUrl) {
return <CustomLogoIcon url={logoUrl} />;
}
return <NetlifyLogoIcon size="300px" type="netlify-cms" />;
};
2018-07-23 12:14:53 -04:00
const LoginButton = styled.button`
${buttons.button};
${shadows.dropDeep};
${buttons.default};
${buttons.gray};
&[disabled] {
${buttons.disabled};
}
2018-07-23 12:14:53 -04:00
padding: 0 12px;
margin-top: -40px;
display: flex;
align-items: center;
position: relative;
`;
2018-07-23 12:14:53 -04:00
2018-07-23 17:13:34 -04:00
const AuthenticationPage = ({
onLogin,
loginDisabled,
loginErrorMessage,
renderButtonContent,
renderPageContent,
logoUrl,
siteUrl,
2018-07-23 17:13:34 -04:00
}) => {
return (
<StyledAuthenticationPage>
{renderPageLogo(logoUrl)}
2018-07-23 17:13:34 -04:00
{loginErrorMessage ? <p>{loginErrorMessage}</p> : null}
{!renderPageContent ? null : renderPageContent({ LoginButton })}
{!renderButtonContent ? null : (
2018-07-23 17:13:34 -04:00
<LoginButton disabled={loginDisabled} onClick={onLogin}>
{renderButtonContent()}
</LoginButton>
)}
{siteUrl && <GoBackButton href={siteUrl} />}
{logoUrl ? <NetlifyCreditIcon size="100px" type="netlify-cms" /> : null}
2018-07-23 17:13:34 -04:00
</StyledAuthenticationPage>
);
};
2018-07-23 12:14:53 -04:00
AuthenticationPage.propTypes = {
onLogin: PropTypes.func,
logoUrl: PropTypes.string,
siteUrl: PropTypes.string,
loginDisabled: PropTypes.bool,
loginErrorMessage: PropTypes.node,
renderButtonContent: PropTypes.func,
renderPageContent: PropTypes.func,
};
2018-07-23 12:14:53 -04:00
export default AuthenticationPage;