p5.js-web-editor/client/modules/User/components/SocialAuthButton.jsx

57 lines
1.3 KiB
React
Raw Permalink Normal View History

import PropTypes from 'prop-types';
import React from 'react';
import styled from 'styled-components';
import i18n from 'i18next';
import { withTranslation } from 'react-i18next';
import { remSize } from '../../../theme';
2020-05-26 22:17:24 +02:00
import { GithubIcon, GoogleIcon } from '../../../common/icons';
import Button from '../../../common/Button';
const authUrls = {
2020-05-11 22:28:18 +02:00
github: '/auth/github',
google: '/auth/google'
};
2020-05-11 22:28:18 +02:00
const icons = {
github: GithubIcon,
google: GoogleIcon
};
const services = {
2020-05-11 22:28:18 +02:00
github: 'github',
google: 'google'
};
const StyledButton = styled(Button)`
width: ${remSize(300)};
`;
function SocialAuthButton({ service, t }) {
2020-05-11 22:28:18 +02:00
const ServiceIcon = icons[service];
const labels = {
github: t('SocialAuthButton.Github'),
google: t('SocialAuthButton.Google')
};
return (
<StyledButton
iconBefore={<ServiceIcon aria-label={t('SocialAuthButton.LogoARIA', { serviceauth: service })} />}
href={authUrls[service]}
>
{labels[service]}
</StyledButton>
);
}
SocialAuthButton.services = services;
SocialAuthButton.propTypes = {
service: PropTypes.oneOf(['github', 'google']).isRequired,
t: PropTypes.func.isRequired
};
const SocialAuthButtonPublic = withTranslation()(SocialAuthButton);
SocialAuthButtonPublic.services = services;
export default SocialAuthButtonPublic;