-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44c031d
commit 452d38e
Showing
7 changed files
with
114 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* globals pronamic_payment_form */ | ||
( function ( wp, blocks, components, editor, element ) { | ||
var el = element.createElement; | ||
var Fragment = element.Fragment; | ||
var InspectorControls = editor.InspectorControls; | ||
var Button = components.Button; | ||
var Placeholder = components.Placeholder; | ||
var TextControl = components.TextControl; | ||
var ServerSideRender = wp.serverSideRender; | ||
|
||
/** | ||
* Register payment form block type. | ||
* | ||
* @param string name Block name. | ||
* @param object settings Block settings. | ||
* | ||
* @return WPBlock Block if registered successfully, otherwise "undefined". | ||
*/ | ||
blocks.registerBlockType( 'pronamic-pay/payment-form', { | ||
title: pronamic_payment_form.title, | ||
icon: 'money', | ||
category: 'pronamic-pay', | ||
|
||
// Attributes. | ||
attributes: { | ||
amount: { | ||
type: 'string' | ||
} | ||
}, | ||
|
||
// Feature supports. | ||
supports: { | ||
// Remove support for an HTML mode. | ||
html: false | ||
}, | ||
|
||
// Edit. | ||
edit: function ( props ) { | ||
var amount = props.attributes.amount; | ||
var hasSettingsSet = props.attributes && parseInt( amount ) > 0; | ||
|
||
function onChangeAmount( updatedAmount ) { | ||
props.setAttributes( { amount: updatedAmount } ); | ||
} | ||
|
||
return el( Fragment, null, | ||
|
||
// Inspector controls. | ||
el( InspectorControls, null, | ||
el( Fragment, null, | ||
el( TextControl, { | ||
type: 'number', | ||
step: 'any', | ||
label: pronamic_payment_form.label_amount, | ||
value: amount, | ||
onChange: onChangeAmount | ||
} ) | ||
) | ||
), | ||
|
||
// Setup required props. | ||
! hasSettingsSet && | ||
el( Placeholder, { | ||
label: pronamic_payment_form.title, | ||
icon: 'money' | ||
}, | ||
el( Fragment, null, | ||
el( TextControl, { | ||
type: 'number', | ||
step: 'any', | ||
label: pronamic_payment_form.label_amount, | ||
onChange: function ( value ) { | ||
}, | ||
onBlur: function () { | ||
onChangeAmount( event.target.value ); | ||
} | ||
} ), | ||
el( 'div', | ||
{ | ||
style: { width: '100%' } | ||
}, | ||
el( Button, | ||
{ isPrimary: true }, | ||
el( Fragment, null, pronamic_payment_form.label_add_form ) | ||
) | ||
) | ||
) | ||
), | ||
|
||
// Server side render. | ||
hasSettingsSet && el( ServerSideRender, { | ||
block: 'pronamic-pay/payment-form', | ||
attributes: props.attributes | ||
} ) | ||
); | ||
}, | ||
|
||
// Save. | ||
save: function () { | ||
return null; | ||
} | ||
} ); | ||
} )( | ||
window.wp, | ||
window.wp.blocks, | ||
window.wp.components, | ||
window.wp.blockEditor, | ||
window.wp.element | ||
); |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array(), 'version' => 'dcd21500c176b426e3e6'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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