Skip to content

Commit 96ecb3e

Browse files
committed
Replace User form buttons with shared Button component
1 parent b61bd69 commit 96ecb3e

15 files changed

+129
-118
lines changed

Diff for: client/modules/User/components/GithubButton.jsx

-23
This file was deleted.

Diff for: client/modules/User/components/GoogleButton.jsx

-23
This file was deleted.

Diff for: client/modules/User/components/NewPasswordForm.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3+
34
import { domOnlyProps } from '../../../utils/reduxFormUtils';
5+
import Button from '../../../common/Button';
46

57
function NewPasswordForm(props) {
68
const {
@@ -34,7 +36,7 @@ function NewPasswordForm(props) {
3436
<span className="form-error">{confirmPassword.error}</span>
3537
}
3638
</p>
37-
<input type="submit" disabled={submitting || invalid || pristine} value="Set New Password" aria-label="sign up" />
39+
<Button type="submit" disabled={submitting || invalid || pristine} label="sign up">Set New Password</Button>
3840
</form>
3941
);
4042
}

Diff for: client/modules/User/components/ResetPasswordForm.jsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3+
34
import { domOnlyProps } from '../../../utils/reduxFormUtils';
5+
import Button from '../../../common/Button';
46

57
function ResetPasswordForm(props) {
68
const {
@@ -19,12 +21,12 @@ function ResetPasswordForm(props) {
1921
/>
2022
{email.touched && email.error && <span className="form-error">{email.error}</span>}
2123
</p>
22-
<input
24+
<Button
2325
type="submit"
2426
disabled={submitting || invalid || pristine || props.user.resetPasswordInitiate}
25-
value="Send Password Reset Email"
26-
aria-label="Send email to reset password"
27-
/>
27+
label="Send email to reset password"
28+
>Send Password Reset Email
29+
</Button>
2830
</form>
2931
);
3032
}

Diff for: client/modules/User/components/SignupForm.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3+
34
import { domOnlyProps } from '../../../utils/reduxFormUtils';
5+
import Button from '../../../common/Button';
46

57
function SignupForm(props) {
68
const {
@@ -58,7 +60,12 @@ function SignupForm(props) {
5860
<span className="form-error">{confirmPassword.error}</span>
5961
}
6062
</p>
61-
<input type="submit" disabled={submitting || invalid || pristine} value="Sign Up" aria-label="sign up" />
63+
<Button
64+
type="submit"
65+
disabled={submitting || invalid || pristine}
66+
label="sign up"
67+
>Sign Up
68+
</Button>
6269
</form>
6370
);
6471
}

Diff for: client/modules/User/components/SocialAuthButton.jsx

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import PropTypes from 'prop-types';
2+
import React from 'react';
3+
import styled from 'styled-components';
4+
5+
import { remSize, prop } from '../../../theme';
6+
7+
import Button from '../../../common/Button';
8+
import Icon from '../../../common/Icon';
9+
10+
const authUrls = {
11+
github: '/auth-github',
12+
google: '/auth/google/'
13+
};
14+
15+
const labels = {
16+
github: 'Login with GitHub',
17+
google: 'Login with Google'
18+
};
19+
20+
const services = {
21+
github: 'github',
22+
google: 'google'
23+
};
24+
25+
const StyledButton = styled(Button)`
26+
width: ${remSize(300)};
27+
28+
> * + * {
29+
margin-left: ${remSize(10)};
30+
}
31+
`;
32+
33+
const StyledIcon = styled(Icon)`
34+
width: ${remSize(32)};
35+
height: ${remSize(32)};
36+
`;
37+
38+
function SocialAuthButton({ service }) {
39+
return (
40+
<StyledButton
41+
href={authUrls[service]}
42+
>
43+
<StyledIcon name={Icon.names[service]} />
44+
<span>{labels[service]}</span>
45+
</StyledButton>
46+
);
47+
}
48+
49+
SocialAuthButton.services = services;
50+
51+
SocialAuthButton.propTypes = {
52+
service: PropTypes.oneOf(['github', 'google']).isRequired
53+
};
54+
55+
export default SocialAuthButton;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
3+
import SocialAuthButton from './SocialAuthButton';
4+
5+
export default {
6+
title: 'User/components/SocialAuthButton',
7+
component: SocialAuthButton
8+
};
9+
10+
export const Github = () => (
11+
<SocialAuthButton service={SocialAuthButton.services.github}>Log in with Github</SocialAuthButton>
12+
);
13+
14+
export const Google = () => (
15+
<SocialAuthButton service={SocialAuthButton.services.google}>Sign up with Google</SocialAuthButton>
16+
);

Diff for: client/modules/User/pages/AccountView.jsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import { Helmet } from 'react-helmet';
88
import { updateSettings, initiateVerification, createApiKey, removeApiKey } from '../actions';
99
import AccountForm from '../components/AccountForm';
1010
import { validateSettings } from '../../../utils/reduxFormUtils';
11-
import GithubButton from '../components/GithubButton';
12-
import GoogleButton from '../components/GoogleButton';
11+
import SocialAuthButton from '../components/SocialAuthButton';
1312
import APIKeyForm from '../components/APIKeyForm';
1413
import Nav from '../../../components/Nav';
1514

@@ -24,8 +23,8 @@ function SocialLoginPanel(props) {
2423
<p className="account__social-text">
2524
Use your GitHub or Google account to log into the p5.js Web Editor.
2625
</p>
27-
<GithubButton buttonText="Login with GitHub" />
28-
<GoogleButton buttonText="Login with Google" />
26+
<SocialAuthButton service={SocialAuthButton.services.github} />
27+
<SocialAuthButton service={SocialAuthButton.services.google} />
2928
</React.Fragment>
3029
);
3130
}

Diff for: client/modules/User/pages/DashboardView.jsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import PropTypes from 'prop-types';
22
import React from 'react';
33
import { connect } from 'react-redux';
44
import { bindActionCreators } from 'redux';
5-
import { browserHistory, Link } from 'react-router';
5+
import { browserHistory } from 'react-router';
66
import { updateSettings, initiateVerification, createApiKey, removeApiKey } from '../actions';
7+
8+
import Button from '../../../common/Button';
9+
710
import Nav from '../../../components/Nav';
811
import Overlay from '../../App/components/Overlay';
912

@@ -79,16 +82,16 @@ class DashboardView extends React.Component {
7982
case TabKey.collections:
8083
return this.isOwner() && (
8184
<React.Fragment>
82-
<Link className="dashboard__action-button" to={`/${username}/collections/create`}>
85+
<Button to={`/${username}/collections/create`}>
8386
Create collection
84-
</Link>
87+
</Button>
8588
<CollectionSearchbar />
8689
</React.Fragment>);
8790
case TabKey.sketches:
8891
default:
8992
return (
9093
<React.Fragment>
91-
{this.isOwner() && <Link className="dashboard__action-button" to="/">New sketch</Link>}
94+
{this.isOwner() && <Button to="/">New sketch</Button>}
9295
<SketchSearchbar />
9396
</React.Fragment>
9497
);

Diff for: client/modules/User/pages/LoginView.jsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { Helmet } from 'react-helmet';
66
import { validateAndLoginUser } from '../actions';
77
import LoginForm from '../components/LoginForm';
88
import { validateLogin } from '../../../utils/reduxFormUtils';
9-
import GithubButton from '../components/GithubButton';
10-
import GoogleButton from '../components/GoogleButton';
9+
import SocialAuthButton from '../components/SocialAuthButton';
1110
import Nav from '../../../components/Nav';
1211

1312
class LoginView extends React.Component {
@@ -41,8 +40,10 @@ class LoginView extends React.Component {
4140
<h2 className="form-container__title">Log In</h2>
4241
<LoginForm {...this.props} />
4342
<h2 className="form-container__divider">Or</h2>
44-
<GithubButton buttonText="Login with Github" />
45-
<GoogleButton buttonText="Login with Google" />
43+
<div className="form-container__stack">
44+
<SocialAuthButton service={SocialAuthButton.services.github} />
45+
<SocialAuthButton service={SocialAuthButton.services.google} />
46+
</div>
4647
<p className="form__navigation-options">
4748
Don&apos;t have an account?&nbsp;
4849
<Link className="form__signup-button" to="/signup">Sign Up</Link>

Diff for: client/styles/components/_dashboard-header.scss

-5
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,3 @@
8383
.dashboard-header__actions > *:not(:first-child) {
8484
margin-left: #{15 / $base-font-size}rem;
8585
}
86-
87-
.dashboard__action-button {
88-
flex-grow: 0;
89-
@extend %button;
90-
}

Diff for: client/styles/components/_form-container.scss

+4
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@
5757
.form-container__exit-button {
5858
@include icon();
5959
}
60+
61+
.form-container__stack > * + * {
62+
margin-top: #{10 / $base-font-size}rem;
63+
}

Diff for: client/styles/components/_forms.scss

+22-13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
}
1010
}
1111

12+
.form > * + * {
13+
margin-top: #{12 / $base-font-size}rem;
14+
}
15+
1216
.form--inline {
1317
display: flex;
1418
align-items: center;
@@ -78,20 +82,25 @@
7882
}
7983

8084
.form [type="submit"] {
81-
@extend %button;
82-
padding: #{8 / $base-font-size}rem #{25 / $base-font-size}rem;
83-
margin: #{39 / $base-font-size}rem 0 #{24 / $base-font-size}rem 0;
85+
margin-left: auto;
86+
margin-right: auto;
8487
}
8588

86-
.form [type="submit"][disabled] {
87-
cursor: not-allowed;
88-
}
89+
// .form [type="submit"] {
90+
// @extend %button;
91+
// padding: #{8 / $base-font-size}rem #{25 / $base-font-size}rem;
92+
// margin: #{39 / $base-font-size}rem 0 #{24 / $base-font-size}rem 0;
93+
// }
8994

90-
.form--inline [type="submit"] {
91-
margin: 0 0 0 #{24 / $base-font-size}rem;
92-
}
95+
// .form [type="submit"][disabled] {
96+
// cursor: not-allowed;
97+
// }
9398

94-
.form [type="submit"][disabled],
95-
.form--inline [type="submit"][disabled] {
96-
cursor: not-allowed;
97-
}
99+
// .form--inline [type="submit"] {
100+
// margin: 0 0 0 #{24 / $base-font-size}rem;
101+
// }
102+
103+
// .form [type="submit"][disabled],
104+
// .form--inline [type="submit"][disabled] {
105+
// cursor: not-allowed;
106+
// }

Diff for: client/styles/components/_github-button.scss

-35
This file was deleted.

Diff for: client/styles/main.scss

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
@import 'components/resizer';
3232
@import 'components/overlay';
3333
@import 'components/about';
34-
@import 'components/github-button';
3534
@import 'components/forms';
3635
@import 'components/toast';
3736
@import 'components/timer';

0 commit comments

Comments
 (0)