Merge branch 'btzr/enter-key'

This commit is contained in:
Jeremy Kauffman 2017-09-18 18:16:18 -04:00
commit c9d5e248aa
8 changed files with 146 additions and 117 deletions

View file

@ -1,5 +1,6 @@
import React from "react"; import React from "react";
import FormField from "component/formField"; import FormField from "component/formField";
import { Icon } from "component/common.js";
let formFieldCounter = 0; let formFieldCounter = 0;
@ -9,6 +10,29 @@ export function formFieldId() {
return "form-field-" + ++formFieldCounter; return "form-field-" + ++formFieldCounter;
} }
export class Form extends React.PureComponent {
static propTypes = {
onSubmit: React.PropTypes.func.isRequired,
};
constructor(props) {
super(props);
}
handleSubmit(event) {
event.preventDefault();
this.props.onSubmit();
}
render() {
return (
<form onSubmit={event => this.handleSubmit(event)}>
{this.props.children}
</form>
);
}
}
export class FormRow extends React.PureComponent { export class FormRow extends React.PureComponent {
static propTypes = { static propTypes = {
label: React.PropTypes.oneOfType([ label: React.PropTypes.oneOfType([
@ -131,3 +155,27 @@ export class FormRow extends React.PureComponent {
); );
} }
} }
export const Submit = props => {
const { title, label, icon, disabled } = props;
const className =
"button-block" +
" button-primary" +
" button-set-item" +
" button--submit" +
(disabled ? " disabled" : "");
const content = (
<span className="button__content">
{"icon" in props ? <Icon icon={icon} fixed={true} /> : null}
{label ? <span className="button-label">{label}</span> : null}
</span>
);
return (
<button type="submit" className={className} title={title}>
{content}
</button>
);
};

View file

@ -1,7 +1,6 @@
import React from "react"; import React from "react";
import { BusyMessage, CreditAmount } from "component/common"; import { BusyMessage, CreditAmount } from "component/common";
import Link from "component/link"; import { Form, FormRow, Submit } from "component/form.js";
import { FormRow } from "component/form.js";
class FormInviteNew extends React.PureComponent { class FormInviteNew extends React.PureComponent {
constructor(props) { constructor(props) {
@ -18,16 +17,16 @@ class FormInviteNew extends React.PureComponent {
}); });
} }
handleSubmit(event) { handleSubmit() {
event.preventDefault(); const { email } = this.state;
this.props.inviteNew(this.state.email); this.props.inviteNew(email);
} }
render() { render() {
const { errorMessage, isPending } = this.props; const { errorMessage, isPending } = this.props;
return ( return (
<form> <Form onSubmit={this.handleSubmit.bind(this)}>
<FormRow <FormRow
type="text" type="text"
label="Email" label="Email"
@ -40,16 +39,9 @@ class FormInviteNew extends React.PureComponent {
}} }}
/> />
<div className="form-row-submit"> <div className="form-row-submit">
<Link <Submit label={__("Send Invite")} disabled={isPending} />
button="primary"
label={__("Send Invite")}
disabled={isPending}
onClick={event => {
this.handleSubmit(event);
}}
/>
</div> </div>
</form> </Form>
); );
} }
} }

View file

@ -2,7 +2,7 @@ import React from "react";
import lbry from "lbry"; import lbry from "lbry";
import lbryuri from "lbryuri"; import lbryuri from "lbryuri";
import FormField from "component/formField"; import FormField from "component/formField";
import { FormRow } from "component/form.js"; import { Form, FormRow, Submit } from "component/form.js";
import Link from "component/link"; import Link from "component/link";
import FormFieldPrice from "component/formFieldPrice"; import FormFieldPrice from "component/formFieldPrice";
import Modal from "modal/modal"; import Modal from "modal/modal";
@ -59,11 +59,7 @@ class PublishForm extends React.PureComponent {
if (!fetchingChannels) fetchChannelListMine(); if (!fetchingChannels) fetchChannelListMine();
} }
handleSubmit(event) { handleSubmit() {
if (typeof event !== "undefined") {
event.preventDefault();
}
this.setState({ this.setState({
submitting: true, submitting: true,
}); });
@ -534,11 +530,7 @@ class PublishForm extends React.PureComponent {
return ( return (
<main className="main--single-column"> <main className="main--single-column">
<form <Form onSubmit={this.handleSubmit.bind(this)}>
onSubmit={event => {
this.handleSubmit(event);
}}
>
<section className="card"> <section className="card">
<div className="card__title-primary"> <div className="card__title-primary">
<h4>{__("Content")}</h4> <h4>{__("Content")}</h4>
@ -872,12 +864,10 @@ class PublishForm extends React.PureComponent {
</section> </section>
<div className="card-series-submit"> <div className="card-series-submit">
<Link <Submit
button="primary" label={
label={submitLabel} !this.state.submitting ? __("Publish") : __("Publishing...")
onClick={event => { }
this.handleSubmit(event);
}}
disabled={ disabled={
this.state.submitting || this.state.submitting ||
(this.state.uri && (this.state.uri &&
@ -892,9 +882,8 @@ class PublishForm extends React.PureComponent {
onClick={this.props.back} onClick={this.props.back}
label={__("Cancel")} label={__("Cancel")}
/> />
<input type="submit" className="hidden" />
</div> </div>
</form> </Form>
<Modal <Modal
isOpen={this.state.modal == "publishStarted"} isOpen={this.state.modal == "publishStarted"}

View file

@ -1,6 +1,6 @@
import React from "react"; import React from "react";
import Link from "component/link"; import Link from "component/link";
import { FormRow } from "component/form.js"; import { Form, FormRow, Submit } from "component/form.js";
class UserEmailNew extends React.PureComponent { class UserEmailNew extends React.PureComponent {
constructor(props) { constructor(props) {
@ -17,20 +17,16 @@ class UserEmailNew extends React.PureComponent {
}); });
} }
handleSubmit(event) { handleSubmit() {
event.preventDefault(); const { email } = this.state;
this.props.addUserEmail(this.state.email); this.props.addUserEmail(email);
} }
render() { render() {
const { errorMessage, isPending } = this.props; const { errorMessage, isPending } = this.props;
return ( return (
<form <Form onSubmit={this.handleSubmit.bind(this)}>
onSubmit={event => {
this.handleSubmit(event);
}}
>
<p> <p>
{__( {__(
"This process is required to prevent abuse of the rewards program." "This process is required to prevent abuse of the rewards program."
@ -53,16 +49,9 @@ class UserEmailNew extends React.PureComponent {
}} }}
/> />
<div className="form-row-submit"> <div className="form-row-submit">
<Link <Submit label="Next" disabled={isPending} />
button="primary"
label="Next"
disabled={isPending}
onClick={event => {
this.handleSubmit(event);
}}
/>
</div> </div>
</form> </Form>
); );
} }
} }

View file

@ -1,6 +1,6 @@
import React from "react"; import React from "react";
import Link from "component/link"; import Link from "component/link";
import { FormRow } from "component/form.js"; import { Form, FormRow, Submit } from "component/form.js";
class UserEmailVerify extends React.PureComponent { class UserEmailVerify extends React.PureComponent {
constructor(props) { constructor(props) {
@ -17,19 +17,15 @@ class UserEmailVerify extends React.PureComponent {
}); });
} }
handleSubmit(event) { handleSubmit() {
event.preventDefault(); const { code } = this.state;
this.props.verifyUserEmail(this.state.code); this.props.verifyUserEmail(code);
} }
render() { render() {
const { errorMessage, isPending } = this.props; const { errorMessage, isPending } = this.props;
return ( return (
<form <Form onSubmit={this.handleSubmit.bind(this)}>
onSubmit={event => {
this.handleSubmit(event);
}}
>
<p>{__("Please enter the verification code emailed to you.")}</p> <p>{__("Please enter the verification code emailed to you.")}</p>
<FormRow <FormRow
type="text" type="text"
@ -50,16 +46,9 @@ class UserEmailVerify extends React.PureComponent {
</p> </p>
</div> </div>
<div className="form-row-submit form-row-submit--with-footer"> <div className="form-row-submit form-row-submit--with-footer">
<Link <Submit label={__("Verify")} disabled={this.state.submitting} />
button="primary"
label={__("Verify")}
disabled={this.state.submitting}
onClick={event => {
this.handleSubmit(event);
}}
/>
</div> </div>
</form> </Form>
); );
} }
} }

View file

@ -1,14 +1,31 @@
import React from "react"; import React from "react";
import Link from "component/link"; import { Form, FormRow, Submit } from "component/form";
import { FormRow } from "component/form";
import lbryuri from "lbryuri"; import lbryuri from "lbryuri";
const WalletSend = props => { class WalletSend extends React.PureComponent {
const { sendToAddress, setAmount, setAddress, amount, address } = props; handleSubmit() {
const { amount, address, sendToAddress } = this.props;
const validSubmit = parseFloat(amount) > 0.0 && address;
if (validSubmit) {
sendToAddress();
}
}
render() {
const {
closeModal,
modal,
setAmount,
setAddress,
amount,
address,
error,
} = this.props;
return ( return (
<section className="card"> <section className="card">
<form onSubmit={sendToAddress}> <Form onSubmit={this.handleSubmit.bind(this)}>
<div className="card__title-primary"> <div className="card__title-primary">
<h3>{__("Send Credits")}</h3> <h3>{__("Send Credits")}</h3>
</div> </div>
@ -37,18 +54,16 @@ const WalletSend = props => {
trim={true} trim={true}
/> />
<div className="form-row-submit"> <div className="form-row-submit">
<Link <Submit
button="primary"
label={__("Send")} label={__("Send")}
onClick={sendToAddress}
disabled={!(parseFloat(amount) > 0.0) || !address} disabled={!(parseFloat(amount) > 0.0) || !address}
/> />
<input type="submit" className="hidden" />
</div> </div>
</div> </div>
</form> </Form>
</section> </section>
); );
}; }
}
export default WalletSend; export default WalletSend;

View file

@ -3,6 +3,7 @@ html
height: 100%; height: 100%;
font-size: var(--font-size); font-size: var(--font-size);
} }
body body
{ {
color: var(--text-color); color: var(--text-color);

View file

@ -86,3 +86,9 @@ $button-focus-shift: 12%;
{ {
box-shadow: none !important; box-shadow: none !important;
} }
.button--submit {
font-family: inherit;
font-size: inherit;
line-height: 0;
}