Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact Form Gutenblock #10256

Closed
wants to merge 142 commits into from
Closed
Show file tree
Hide file tree
Changes from 86 commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
5e25b34
Ignore node_modules regardless of depth
georgestephanis Oct 2, 2018
52e1173
Add build tools for contact form
georgestephanis Oct 2, 2018
cc8a8db
First pass.
georgestephanis Oct 2, 2018
7238d2c
Redo fields.
georgestephanis Oct 2, 2018
f15a3f8
Update some icons, renders, etc.
georgestephanis Oct 2, 2018
4479c89
Correct how I'm grabbing the label.
georgestephanis Oct 2, 2018
73713a4
Assorted changes.
georgestephanis Oct 2, 2018
c20c2a3
d'oh copypasta fail
georgestephanis Oct 2, 2018
97e64d9
Do it the easy way, not the tidy way.
georgestephanis Oct 2, 2018
b9d9dd3
Begin saving `to` and `subject` fields, add `required` toggle.
georgestephanis Oct 3, 2018
1b04126
whitespace tidying / reorg
georgestephanis Oct 3, 2018
47dc2d5
Abstract out the label stuff for simpler components and reusability.
georgestephanis Oct 3, 2018
01e9b30
Add the compiled version to make for easier testing.
georgestephanis Oct 3, 2018
dbe61c0
Start experimenting with options parameters and rendering.
georgestephanis Oct 3, 2018
71d652d
Have each option save its value.
georgestephanis Oct 3, 2018
f075497
compile!
georgestephanis Oct 3, 2018
31e6e6e
tabs
georgestephanis Oct 3, 2018
89d4059
whitespace tidying
georgestephanis Oct 3, 2018
dfadbe4
update build file
georgestephanis Oct 3, 2018
7a8f38a
Stub out render functions
georgestephanis Oct 3, 2018
c67b7e4
Get radio control working
georgestephanis Oct 3, 2018
bbabdb1
Get Select fields running, and make "Add New" translateable
georgestephanis Oct 3, 2018
bddab06
Compile!
georgestephanis Oct 3, 2018
710ca7c
Add more php parsing for varied block types.
georgestephanis Oct 4, 2018
413aa1d
Handle arrays for atts as gutenberg uses json
georgestephanis Oct 4, 2018
0170466
whitespace tidying
georgestephanis Oct 4, 2018
d51d26b
We don't need this for numeric attrs, as gutenberg won't make it numeric
georgestephanis Oct 4, 2018
f35025e
add a bool handler for required
georgestephanis Oct 4, 2018
a8f46bd
Consolidate the multi select options
georgestephanis Oct 4, 2018
df8fdd1
Add some rudimentary styles to the back-end form editor.
georgestephanis Oct 4, 2018
a7e7a36
build
georgestephanis Oct 4, 2018
888411f
Tidy up legacy supportHTML option to object and change widgets to common
georgestephanis Oct 5, 2018
198d26b
Minor styling changes for labels and spacing.
mapk Oct 5, 2018
be901ba
Merge branch 'gm18/grunionblock' of github.com:Automattic/jetpack int…
mapk Oct 5, 2018
3ba151f
Purge some of the local build tools
georgestephanis Oct 8, 2018
7e6fc72
Start experimenting with Block Transforms.
georgestephanis Oct 8, 2018
a5a95f6
Merge branch 'gm18/grunionblock' of https://github.com/Automattic/jet…
georgestephanis Oct 8, 2018
c3e6f3a
Change methodology to use Calypso build tool SDK?
georgestephanis Oct 8, 2018
fa9c5d7
Build via calypso builder instead.
georgestephanis Oct 8, 2018
b391042
spaces 👉🏼 tabs 🆒
georgestephanis Oct 8, 2018
0b11ea3
Remove map file no longer generated by calypso
georgestephanis Oct 8, 2018
e4aa2de
Make the 'submit' button editable.
georgestephanis Oct 8, 2018
f02943e
Tidy up some code standards stuff
georgestephanis Oct 9, 2018
5da01df
Make it possible to swap the button text, and some whitespace tidying.
georgestephanis Oct 11, 2018
7e14f16
Tidy up how we're passing around functions to set attributes.
georgestephanis Oct 11, 2018
3a0e9bb
Whitespace
georgestephanis Oct 11, 2018
cd1d669
Ignore the cform gutenblock while I'm working on it.
georgestephanis Oct 11, 2018
f609b6f
Whitespace tidying and change option add button.
georgestephanis Oct 11, 2018
3b16cd6
Update the styling of some elements.
georgestephanis Oct 11, 2018
4afc7e1
Enhancement: add ability to delete options from multi select field types
georgestephanis Oct 11, 2018
3ef297d
Add placeholder to multi fields
georgestephanis Oct 11, 2018
d8a3a72
Add alternate transforms.
georgestephanis Oct 15, 2018
0da9b34
whitespace formatting / tidying
georgestephanis Oct 15, 2018
800dc05
Switch to
georgestephanis Oct 15, 2018
204c4da
Build.
georgestephanis Oct 15, 2018
b2ef95c
Add matches and transforms for single/multi field types
georgestephanis Oct 15, 2018
8f7ea33
Abstract out the processing logic.
georgestephanis Oct 15, 2018
0e31a45
build
georgestephanis Oct 15, 2018
2de2f7e
Punt jQuery.
georgestephanis Oct 15, 2018
e1d9bc0
Stop using underscore for `_.map()`
georgestephanis Oct 15, 2018
1d8c40f
Vanilla js way of cloning an object in js.
georgestephanis Oct 15, 2018
639d7ae
Remove last vestiges of underscore.
georgestephanis Oct 15, 2018
d924a31
build
georgestephanis Oct 15, 2018
3d845f6
Simplify some classes down to functions.
georgestephanis Oct 15, 2018
796fae5
Simplify out how we're adding new items
georgestephanis Oct 15, 2018
756512e
Add wp global back in -- oops
georgestephanis Oct 15, 2018
31ca531
Pull out setAttributes fn call.
georgestephanis Oct 15, 2018
f36bf93
Abstract out onChanges
georgestephanis Oct 15, 2018
c7bb399
Switch to placeholders
georgestephanis Oct 15, 2018
7156524
tabs > spaces
georgestephanis Oct 15, 2018
c6ae74e
Build
georgestephanis Oct 15, 2018
a25e3ff
Simplify the disabled attribute so we don't need the `true` assignment
georgestephanis Oct 16, 2018
3ae96a8
Update some naming and patterns
georgestephanis Oct 16, 2018
bd0b78d
Add missing textdomains.
georgestephanis Oct 16, 2018
a425c1d
Use the Gutenberg generated className as well.
georgestephanis Oct 16, 2018
b96942d
Better scope some CSS
georgestephanis Oct 16, 2018
ccdaa56
Build.
georgestephanis Oct 16, 2018
368686e
Rearrange some icons and tidy some whitespace.
georgestephanis Oct 16, 2018
4073815
Build.
georgestephanis Oct 16, 2018
cca93bb
Renamespace everything from Grunion to Jetpack
georgestephanis Oct 16, 2018
f0352a7
Build.
georgestephanis Oct 16, 2018
3de7e2a
First attempt at extracting to sub file
georgestephanis Oct 16, 2018
919cbff
Minor bookkeeping
georgestephanis Oct 16, 2018
a13597b
Build.
georgestephanis Oct 16, 2018
25a8f30
Extract out components for maintainability.
georgestephanis Oct 16, 2018
f8cc516
Build.
georgestephanis Oct 16, 2018
3010d3e
Make scss version of gutenblock css
georgestephanis Oct 16, 2018
c5bfaa2
Shuffle around files to match Calypso structure.
georgestephanis Oct 17, 2018
5acf98d
Build.
georgestephanis Oct 17, 2018
7c1b4da
These changes are no longer necessary.
georgestephanis Oct 17, 2018
096c56f
Make sure we're building the scss as well.
georgestephanis Oct 17, 2018
a9213a2
Build.
georgestephanis Oct 17, 2018
c782ddc
Convert the css to scss and build back to css.
georgestephanis Oct 17, 2018
9d1b6b4
Add RTL
georgestephanis Oct 17, 2018
7e1f18e
Don't scan these files -- they're synced with Calypso and actually js…
georgestephanis Oct 17, 2018
488dfac
Style revised to match default G blocks on elements for hover and foc…
mapk Oct 17, 2018
d5dd3e1
Rebuild editor.css
georgestephanis Oct 18, 2018
af4e42d
Minor styling for the multiple checkbox.
mapk Oct 18, 2018
4c4b0ad
Add a conditional for how the innerblocks are passed back up.
georgestephanis Oct 18, 2018
794f45f
Merge branch 'gm18/grunionblock' of https://github.com/Automattic/jet…
georgestephanis Oct 18, 2018
aeb16b9
More form styling for the checkbox and radio options. Made checkbox f…
mapk Oct 18, 2018
2945f64
Merge branch 'gm18/grunionblock' of github.com:Automattic/jetpack int…
mapk Oct 18, 2018
5bb2730
Removed arrow from form submit btn
mapk Oct 18, 2018
16ac9ba
Styled the appender to hide with the block is not selected. Added som…
mapk Oct 22, 2018
89dcd71
Build.
georgestephanis Oct 22, 2018
cb0e74d
Change "Type here..." to a placeholder instead of value.
georgestephanis Oct 22, 2018
0d53322
Tidy up some missing options
georgestephanis Oct 22, 2018
7c2e7dd
Default the label value to the field type.
georgestephanis Oct 22, 2018
042adaa
Build.
georgestephanis Oct 22, 2018
c0d4d9e
Switch checkbox and multiple components to use `BaseControl`
georgestephanis Oct 23, 2018
4f0ac3e
Populate multis with the actual check and radio boxes
georgestephanis Oct 23, 2018
98e9b91
Build.
georgestephanis Oct 23, 2018
1a52835
Switch submit button to ContentEditable instead.
georgestephanis Oct 23, 2018
755d286
Spaces to tabs
georgestephanis Oct 23, 2018
b22d14d
Build.
georgestephanis Oct 23, 2018
7bccaf1
Bump this around for scss structure nesting.
georgestephanis Oct 23, 2018
9bd82d6
Build.
georgestephanis Oct 23, 2018
64b6da6
Fix the case of the vanishing appender.
georgestephanis Oct 23, 2018
eef9480
Build.
georgestephanis Oct 23, 2018
4ad8207
suppressContentEditableWarning
georgestephanis Oct 23, 2018
9087614
Build.
georgestephanis Oct 23, 2018
cbf5a51
Fixed minor bug with alignment of 'x' btn for multiple radios and che…
mapk Oct 23, 2018
cb81c9f
Merge branch 'gm18/grunionblock' of github.com:Automattic/jetpack int…
mapk Oct 23, 2018
55f4e04
Reorganize scss for better hierarchy and make submit button not conte…
georgestephanis Oct 24, 2018
d702c1d
Build.
georgestephanis Oct 24, 2018
a12356b
Add in a new caveat for block rendering.
georgestephanis Oct 24, 2018
8fe6139
Oops, the type was getting lost on these fields. Better add in A Bet…
georgestephanis Oct 24, 2018
88c0173
TABS TABS TABS
georgestephanis Oct 24, 2018
e6399c7
Correcting the default fieldset to match historical configurations.
georgestephanis Oct 24, 2018
7fa62e7
Whitespace
georgestephanis Oct 24, 2018
223e8c3
Allow all blocks inside a Contact Form.
georgestephanis Oct 24, 2018
85d25a4
Build.
georgestephanis Oct 24, 2018
cb701ad
Clear the last vestiges of `»` away from the submit button.
georgestephanis Oct 24, 2018
6d0bb05
Fixed submit btn padding
mapk Oct 24, 2018
ab72871
Disallow non-field child blocks for now.
georgestephanis Oct 25, 2018
57d8906
Build.
georgestephanis Oct 25, 2018
919462b
Swap in most SVGs from Material Design for fields.
georgestephanis Oct 25, 2018
2e229e5
Build.
georgestephanis Oct 25, 2018
44a0ef6
Swap to the specified outline style icons.
georgestephanis Oct 25, 2018
3c26a29
Switch over to Gutenberg's SVG primitives for accessibility.
georgestephanis Oct 25, 2018
86b2869
Build.
georgestephanis Oct 25, 2018
6d2c04e
Strip out legacy ways of rendering -- no longer useful.
georgestephanis Oct 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -46,3 +46,5 @@ phpcs.xml
_inc/jetpack-strings.php
/modules/**/*/block.js

# Unignore a few specific files.
!/modules/contact-form/js/gutenblock.js
2 changes: 1 addition & 1 deletion gulpfile.babel.js
Expand Up @@ -41,7 +41,7 @@ import {} from './tools/builder/frontend-css';
import {} from './tools/builder/admin-css';

// These paths should alawys be ignored when watching files
const alwaysIgnoredPaths = [ '!node_modules/**', '!vendor/**', '!docker/**' ];
const alwaysIgnoredPaths = [ '!node_modules/**', '!vendor/**', '!docker/**', '!modules/contact-form/gutenblock.js*' ];

function onBuild( done ) {
return function( err, stats ) {
Expand Down
84 changes: 84 additions & 0 deletions modules/contact-form/css/gutenblock.css
@@ -0,0 +1,84 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose this file is CSS instead of SCSS just to make building easier for now?

Let's switch it to SCSS as soon as we can so that we can rely on nesting, colour variables and other things like that so that as the CSS grows, we don't need to do too much refactoring.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yarp, that's the plan.


.jetpack-field-label.jetpack-field-label.jetpack-field-label {
border-color: #fff;
font-weight: bold;
margin: 0;
margin-bottom: 2px;
padding-left: 1px;
width: calc( 100% - 100px );
}

.jetpack-field-label.jetpack-field-label.jetpack-field-label:focus,
.jetpack-field-label.jetpack-field-label.jetpack-field-label:hover {
border-color: #8d96a0;
}

.jetpack-field input:disabled,
.jetpack-field textarea:disabled {
border-color: #8d96a0;
padding: 10px 8px;
}

.jetpack-form .components-base-control * {
margin: 0;
}

.jetpack-form span.required {
float: right;
}

.editor-block-list__block[data-type="jetpack/field-checkbox-multiple"] ol,
.editor-block-list__block[data-type="jetpack/field-radio"] ol,
.editor-block-list__block[data-type="jetpack/field-select"] ol {
list-style-type: none;
}
.editor-block-list__block[data-type="jetpack/field-checkbox-multiple"] ol:empty,
.editor-block-list__block[data-type="jetpack/field-radio"] ol:empty,
.editor-block-list__block[data-type="jetpack/field-select"] ol:empty {
display: none;
}
.editor-block-list__block[data-type="jetpack/field-select"] ol {
border: 1px solid #8d96a0;
border-radius: 4px;
padding: 4px;
}


.editor-block-list__block input.option {
border-color: #fff;
width: calc( 100% - 7em );
display: inline-block;
}
.editor-block-list__block input.option:focus,
.editor-block-list__block input.option:hover {
border-color: #8d96a0;
}


.editor-block-list__block[data-type="jetpack/field-checkbox-multiple"] ol li:before {
content: '☐ ';
}
.editor-block-list__block[data-type="jetpack/field-radio"] ol li:before {
content: '🔘 ';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like something we shouldn't need to do — what was the reasoning of using CSS content instead of having them inline at HTML?

(I didn't yet try running the block so I might be missing something)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using css means that we can have the same Component rendering the markup for Multiple Checkboxes, Radio Buttons, and Select Boxes -- just using styling to make them visually representative of their outputs.


.editor-block-list__block ol li button.components-icon-button {
display: inline-block;
}

.jetpack-submit-button {
padding: 5px;
}
.jetpack-submit-button.jetpack-submit-button .components-text-control__input {
background: transparent;
border: none;
outline: none;
text-align: center;
color: #fff;
}

.jetpack-submit-button.jetpack-submit-button .components-text-control__input:focus,
.jetpack-submit-button.jetpack-submit-button .components-text-control__input::placeholder{
color: #fff;
}
92 changes: 91 additions & 1 deletion modules/contact-form/grunion-contact-form.php
Expand Up @@ -232,6 +232,90 @@ function __construct() {
*/
wp_register_style( 'grunion.css', GRUNION_PLUGIN_URL . 'css/grunion.css', array(), JETPACK__VERSION );
wp_style_add_data( 'grunion.css', 'rtl', 'replace' );

add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_assets' ) );
if ( function_exists( 'register_block_type' ) ) {
register_block_type( 'jetpack/form', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_form' ),
) );

// These can all use a common render method.
register_block_type( 'jetpack/field-text', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_field' ),
) );
register_block_type( 'jetpack/field-name', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_field' ),
) );
register_block_type( 'jetpack/field-email', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_field' ),
) );
register_block_type( 'jetpack/field-url', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_field' ),
) );
register_block_type( 'jetpack/field-date', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_field' ),
) );
register_block_type( 'jetpack/field-telephone', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_field' ),
) );

// Special per-field-type render methods.
register_block_type( 'jetpack/field-textarea', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_field_textarea' ),
) );
register_block_type( 'jetpack/field-checkbox', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_field_checkbox' ),
) );
register_block_type( 'jetpack/field-checkbox-multiple', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_field_checkbox_multiple' ),
) );
register_block_type( 'jetpack/field-radio', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_field_radio' ),
) );
register_block_type( 'jetpack/field-select', array(
'render_callback' => array( __CLASS__, 'gutenblock_render_field_select' ),
) );
}
}

public static function enqueue_block_editor_assets() {
wp_enqueue_script( 'jetpack-cf-gutenblock', plugins_url( 'js/gutenblock.js', __FILE__ ), array(
'wp-blocks',
'wp-i18n',
'wp-element',
), filemtime( dirname( __FILE__ ) . '/js/gutenblock.js' ) );

wp_enqueue_style( 'jetpack-cf-gutenblock', plugins_url( 'css/gutenblock.css', __FILE__ ), array(
'wp-blocks',
), filemtime( dirname( __FILE__ ) . '/css/gutenblock.css' ) );
}

public static function gutenblock_render_form( $atts, $content ) {
return Grunion_Contact_Form::parse( $atts, $content );
}

public static function gutenblock_render_field( $atts, $content ) {
return Grunion_Contact_Form::parse_contact_field( $atts, $content );
}
public static function gutenblock_render_field_textarea( $atts, $content ) {
$atts['type'] = 'textarea';
return Grunion_Contact_Form::parse_contact_field( $atts, $content );
}
public static function gutenblock_render_field_checkbox( $atts, $content ) {
$atts['type'] = 'checkbox';
return Grunion_Contact_Form::parse_contact_field( $atts, $content );
}
public static function gutenblock_render_field_checkbox_multiple( $atts, $content ) {
$atts['type'] = 'checkbox-multiple';
return Grunion_Contact_Form::parse_contact_field( $atts, $content );
}
public static function gutenblock_render_field_radio( $atts, $content ) {
$atts['type'] = 'radio';
return Grunion_Contact_Form::parse_contact_field( $atts, $content );
}
public static function gutenblock_render_field_select( $atts, $content ) {
$atts['type'] = 'select';
return Grunion_Contact_Form::parse_contact_field( $atts, $content );
}

/**
Expand Down Expand Up @@ -2032,7 +2116,13 @@ static function parse_contact_field( $attributes, $content ) {
if ( is_numeric( $att ) ) { // Is a valueless attribute
$att_strs[] = esc_html( $val );
} elseif ( isset( $val ) ) { // A regular attr - value pair
$att_strs[] = esc_html( $att ) . '=\'' . esc_html( $val ) . '\'';
if ( is_array( $val ) ) {
$att_strs[] = esc_html( $att ) . '=\'' . implode( ',', array_map( 'esc_html', $val ) ) . '\'';
} elseif ( is_bool( $val ) ) {
$att_strs[] = esc_html( $att ) . '=\'' . esc_html( $val ? '1' : '' ) . '\'';
} else {
$att_strs[] = esc_html( $att ) . '=\'' . esc_html( $val ) . '\'';
}
}
}

Expand Down
44 changes: 44 additions & 0 deletions modules/contact-form/js/components/JetpackField.jsx
@@ -0,0 +1,44 @@
/*global wp*/
/** @jsx wp.element.createElement */
/** @format */

/**
* External dependencies
*/
import {
TextControl
} from '@wordpress/components';

import {
Fragment
} from '@wordpress/element';

/**
* Internal dependencies
*/
import JetpackFieldSettings from './JetpackFieldSettings';
import JetpackFieldLabel from './JetpackFieldLabel';

function JetpackField( props ) {
return (
<Fragment>
<JetpackFieldSettings
required={ props.required }
setAttributes={ props.setAttributes }
/>
<div className="jetpack-field">
<TextControl
type={ props.type }
label={ <JetpackFieldLabel
required={ props.required }
label={ props.label }
setAttributes={ props.setAttributes }
/> }
disabled
/>
</div>
</Fragment>
);
}

export default JetpackField;
43 changes: 43 additions & 0 deletions modules/contact-form/js/components/JetpackFieldCheckbox.jsx
@@ -0,0 +1,43 @@
/*global wp*/
/** @jsx wp.element.createElement */
/** @format */

/**
* External dependencies
*/
import {
CheckboxControl
} from '@wordpress/components';

import {
Fragment
} from '@wordpress/element';

/**
* Internal dependencies
*/
import JetpackFieldSettings from './JetpackFieldSettings';
import JetpackFieldLabel from './JetpackFieldLabel';

function JetpackFieldCheckbox( props ) {
return (
<Fragment>
<JetpackFieldSettings
required={ props.required }
setAttributes={ props.setAttributes }
/>
<div className="jetpack-field">
<CheckboxControl
label={ <JetpackFieldLabel
required={ props.required }
label={ props.label }
setAttributes={ props.setAttributes }
/> }
disabled
/>
</div>
</Fragment>
);
}

export default JetpackFieldCheckbox;
43 changes: 43 additions & 0 deletions modules/contact-form/js/components/JetpackFieldLabel.jsx
@@ -0,0 +1,43 @@
/*global wp*/
/** @jsx wp.element.createElement */
/** @format */

/**
* External dependencies
*/

import {
Component,
Fragment
} from '@wordpress/element';

import {
__
} from '@wordpress/i18n';

class JetpackFieldLabel extends Component {
constructor( ...args ) {
super( ...args );
this.onChangeLabel = this.onChangeLabel.bind( this );
}

onChangeLabel( event ) {
this.props.setAttributes( { label: event.target.value } );
}

render() {
return (
<Fragment>
<input
type="text"
value={ this.props.label }
className="jetpack-field-label"
onChange={ this.onChangeLabel }
/>
{ this.props.required && <span className="required">{ __( '(required)', 'jetpack' ) }</span> }
</Fragment>
);
}
}

export default JetpackFieldLabel;