-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storybook): make stories prettier
- Loading branch information
1 parent
30f41fc
commit d78e113
Showing
8 changed files
with
132 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,97 @@ | ||
import { action } from '@storybook/addon-actions'; | ||
import { storiesOf } from '@storybook/react'; | ||
import * as React from 'react'; | ||
// tslint:disable-next-line:no-duplicate-imports | ||
import { ChangeEvent } from 'react'; | ||
|
||
import { PaymentResponse, ReblocksButton } from './ReblocksButton'; | ||
import { ACCOUNT_ID, PaymentResponse, ReblocksButton } from '../reblocks'; | ||
|
||
interface State { | ||
accountId: string; | ||
amount: number; | ||
} | ||
|
||
class PaymentForm extends React.Component<{}, State> { | ||
constructor(props: {}) { | ||
super(props); | ||
this.state = { accountId: ACCOUNT_ID, amount: 10000 }; | ||
} | ||
|
||
onChangeAccountId = (event: ChangeEvent<HTMLInputElement>) => { | ||
console.log(event.currentTarget.value); | ||
this.setState({ accountId: event.currentTarget.value }); | ||
}; | ||
|
||
onChangeAmount = (event: ChangeEvent<HTMLInputElement>) => { | ||
console.log(event.currentTarget.value); | ||
this.setState({ amount: parseFloat(event.currentTarget.value) }); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<form> | ||
<p> | ||
Filling in the form below will dynamically change the payment button with the new account | ||
and amount specified | ||
</p> | ||
<fieldset> | ||
<label>Account ID</label> | ||
<input | ||
type="text" | ||
value={this.state.accountId} | ||
placeholder="Account ID" | ||
onChange={this.onChangeAccountId} | ||
/> | ||
<label>Amount (in rai, 1,000,000 rai = 1 XRB)</label> | ||
|
||
<input | ||
type="number" | ||
value={this.state.amount} | ||
placeholder="Amount of rai" | ||
onChange={this.onChangeAmount} | ||
/> | ||
<ReblocksButton | ||
accountId={this.state.accountId} | ||
amount={this.state.amount} | ||
onPaymentSuccess={onSuccess} | ||
/> | ||
</fieldset> | ||
</form> | ||
); | ||
} | ||
} | ||
|
||
const onSuccess = (data: PaymentResponse) => { | ||
console.log('Got transaction token', data.token); | ||
action('Payment successful.')(); | ||
action(`Transaction ID: ${data.token}`)(); | ||
}; | ||
|
||
storiesOf('ReblocksButton', module).add('Interactive', () => { | ||
return ( | ||
<ReblocksButton | ||
accountId="xrb_3ritoyx4zcixshfbezg4aycb49xbupw9ggink1rfm43tm6uh87t4ifuxg5dm" | ||
amountXrb={200000} | ||
onPaymentSuccess={onSuccess} | ||
/> | ||
); | ||
}); | ||
storiesOf('ReblocksButton', module) | ||
.add('Small test transaction', () => { | ||
action('Click the button to start payment')(); | ||
|
||
return ( | ||
<div> | ||
<p>The button below will prompt you to send a test transaction of 1000 rai (~2 cents)</p> | ||
<ReblocksButton accountId={ACCOUNT_ID} amount={1000} onPaymentSuccess={onSuccess} /> | ||
</div> | ||
); | ||
}) | ||
.add('Dynamic Button', () => { | ||
return <PaymentForm />; | ||
}) | ||
.add('Buy Dan a 🍺', () => { | ||
return ( | ||
<div> | ||
<p> | ||
If you want to help support the project, you can donate a beer's worth of rai using this | ||
form | ||
</p> | ||
<ReblocksButton accountId={ACCOUNT_ID} amount={250000} onPaymentSuccess={onSuccess} /> | ||
<p style={{ marginTop: 30 }}> | ||
...or you can donate a different amount to | ||
xrb_3ritoyx4zcixshfbezg4aycb49xbupw9ggink1rfm43tm6uh87t4ifuxg5dm | ||
</p> | ||
</div> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { ReblocksButton } from './ReblocksButton/ReblocksButton'; | ||
export { PaymentResponse, ReblocksButton } from './ReblocksButton/ReblocksButton'; | ||
|
||
export const ACCOUNT_ID = 'xrb_3ritoyx4zcixshfbezg4aycb49xbupw9ggink1rfm43tm6uh87t4ifuxg5dm'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters