From 2273fac6b26a5c9e87a0efcd06d1f40b6bb1a56f Mon Sep 17 00:00:00 2001 From: Herb Miller Date: Tue, 13 Sep 2022 21:20:28 +0100 Subject: [PATCH] oik/contact-field - Add 3 styles #207 --- includes/bw_metadata.php | 2 +- libs/bobbforms.php | 29 ++++++++++++++---------- libs/class-BW-.php | 14 +++++++----- oik.php | 15 +++++++++++++ shortcodes/oik-contact-field.php | 11 ++++++++- shortcodes/oik-contact-form.php | 4 ++++ src/oik-contact-field/block.json | 2 +- src/oik-contact-field/editor.scss | 29 ++++++++++++++++++------ src/oik-contact-field/index.js | 11 ++++----- src/oik-contact-field/style.scss | 37 +++++++++++++++++++++++++++++++ src/oik-contact-form/style.scss | 6 +---- 11 files changed, 120 insertions(+), 40 deletions(-) create mode 100644 src/oik-contact-field/style.scss diff --git a/includes/bw_metadata.php b/includes/bw_metadata.php index 181626c..3956ade 100644 --- a/includes/bw_metadata.php +++ b/includes/bw_metadata.php @@ -249,7 +249,7 @@ function bw_form_field_numeric( $name, $type, $title, $value, $args ) { * Format a checkbox metabox */ function bw_form_field_checkbox( $name, $type, $title, $value, $args ) { - bw_checkbox( $name, $title, $value ); + bw_checkbox( $name, $title, $value, $args ); } /** diff --git a/libs/bobbforms.php b/libs/bobbforms.php index c6f933f..ce7c2b2 100644 --- a/libs/bobbforms.php +++ b/libs/bobbforms.php @@ -1,6 +1,6 @@ 'grid', 'label' => __( 'Grid', 'oik'), 'is_default' => true ]); + register_block_style( 'oik/contact-field', [ 'name' => 'above', 'label' => __( 'Label above', 'oik') ]); + register_block_style( 'oik/contact-field', [ 'name' => 'reversed', 'label' => __( 'Reversed', 'oik')]); + +} + /** * Initiate oik processing */ diff --git a/shortcodes/oik-contact-field.php b/shortcodes/oik-contact-field.php index 748586d..b096d6c 100644 --- a/shortcodes/oik-contact-field.php +++ b/shortcodes/oik-contact-field.php @@ -21,7 +21,8 @@ * [bw_contact_form][bw_contact_field Email][/bw_contact_form] * [bw_contact_form][bw_contact_field Name][bw_contact_field Telephone][/bw_contact_form] * - * Note: The Message ( textarea ) field is automatically added. This is a required field. + * @since 4.9.0 + * Note: The Message ( textarea ) field is not automatically added. It's no longer a required field. * @param $atts * @param $content * @param $tag @@ -64,6 +65,13 @@ function bw_contact_field( $atts, $content, $tag ) { } } + /** + * The class name needs to be applied to the surrounding div. + */ + $class = bw_array_get( $atts, 'class', null); + $args['#class'] = $class . " is-style-$type"; + + $full_name = bw_contact_field_full_name( $name ); bw_register_field( $full_name, $type, $label, $args ); global $bw_contact_fields; @@ -128,5 +136,6 @@ function bw_contact_field__syntax( $shortcode='bw_contact_field') { , "required" => BW_::bw_skv( 'n', 'y', __("Required field") ) , "requiredindicator" => BW_::bw_skv( null, "" . __( "text", "oik" ) . "", __("Text to indicate the field is required. eg *") ) ]; + $syntax += _sc_classes( false ); return $syntax; } \ No newline at end of file diff --git a/shortcodes/oik-contact-form.php b/shortcodes/oik-contact-form.php index 129535e..22f250c 100644 --- a/shortcodes/oik-contact-form.php +++ b/shortcodes/oik-contact-form.php @@ -564,6 +564,10 @@ function bw_contact_field_to_shortcode( $attrs ) { $content .= ' requiredindicator="' . $requiredIndicator . '"'; } } + $class = bw_array_get( $attrs, "className", null ); + if ( $class ) { + $content .= ' class="' . $class . '"'; + } $content .= "]"; return $content; } \ No newline at end of file diff --git a/src/oik-contact-field/block.json b/src/oik-contact-field/block.json index 623df94..692ebdd 100644 --- a/src/oik-contact-field/block.json +++ b/src/oik-contact-field/block.json @@ -52,7 +52,7 @@ "supports": { "html": false, "customClassName": false, - "className": false, + "className": true, "color": { "gradients": false, "text": false, diff --git a/src/oik-contact-field/editor.scss b/src/oik-contact-field/editor.scss index 5de1a56..86cd3b4 100644 --- a/src/oik-contact-field/editor.scss +++ b/src/oik-contact-field/editor.scss @@ -1,17 +1,32 @@ /* - Display each field using as a grid layout in the block editor. + Display each field using a grid layout in the block editor. */ - -.wp-block-oik-contact-field { +.wp-block-oik-contact-field.is-style-grid > div { display: grid; gap: 10px; grid-template-columns: 1fr 3fr; +} - label { +/** + No need for any specific styling for is-style-above + since that's what happens by default. + */ - } - div.field { +/** + Styling for reversing the fields. Useful for checkboxes. + */ +.wp-block-oik-contact-field.is-style-reversed > div { + display: grid; + gap: 10px; + grid-template-columns: 1fr 3fr; +} - } +.wp-block-oik-contact-field.is-style-reversed > div .label { + grid-column-start: 2; + grid-row-start: 1; +} +.wp-block-oik-contact-field.is-style-reversed > div .field { + grid-column-start: 1; + grid-row-start: 1; } \ No newline at end of file diff --git a/src/oik-contact-field/index.js b/src/oik-contact-field/index.js index 2a74803..f3c211d 100644 --- a/src/oik-contact-field/index.js +++ b/src/oik-contact-field/index.js @@ -6,10 +6,9 @@ * @copyright (C) Copyright Bobbing Wide 2022 * @author Herb Miller @bobbingwide */ -//import './style.scss'; +import './style.scss'; import './editor.scss'; - import { __ } from '@wordpress/i18n'; import classnames from 'classnames'; @@ -61,11 +60,7 @@ registerBlockType( edit: props=> { const { attributes, setAttributes, instanceId, focus, isSelected } = props; const { textAlign, label } = props.attributes; - const blockProps = useBlockProps( { - className: classnames( { - [ `has-text-align-${ textAlign }` ]: textAlign, - } ), - } ); + const blockProps = useBlockProps(); const onChangeLabel = (event) => { props.setAttributes({label: event}); }; @@ -103,6 +98,7 @@ registerBlockType(
+
+
diff --git a/src/oik-contact-field/style.scss b/src/oik-contact-field/style.scss new file mode 100644 index 0000000..97de30b --- /dev/null +++ b/src/oik-contact-field/style.scss @@ -0,0 +1,37 @@ +.bw_contact_form .bw_grid > div, +.bw_contact_form bw_grid .is-style-grid { + display: grid; + gap: 10px; + grid-template-columns: 1fr 3fr; +} + +/** + * We don't need the vertical space between the label and the field + */ +.bw_contact_form .bw_grid .is-style-above, +.wp-block-oik-contact-field .is-style-above { + display: grid; + grid-template-columns: 1fr; +} + +/** + * Reverse the field order - primarily for checkboxes + */ +.bw_contact_form .bw_grid .is-style-reversed > div, +.bw_contact_form .bw_grid .is-style-reversed { + display: grid; + gap: 10px; + grid-template-columns: 1fr 3fr; +} + +.bw_contact_form .bw_grid .is-style-reversed > div .label, +.bw_contact_form .bw_grid .is-style-reversed > label { + grid-column-start: 2; + grid-row-start: 1; +} + +.bw_contact_form .bw_grid .is-style-reversed > div .field, +.bw_contact_form .bw_grid .is-style-reversed input { + grid-column-start: 1; + grid-row-start: 1; +} \ No newline at end of file diff --git a/src/oik-contact-form/style.scss b/src/oik-contact-form/style.scss index 0e00231..7c63a1a 100644 --- a/src/oik-contact-form/style.scss +++ b/src/oik-contact-form/style.scss @@ -4,9 +4,5 @@ div.bw_contact_form form { /* background-color: #f5f5f5; */ } -.bw_contact_form .bw_grid { - display: grid; - gap: 10px; - grid-template-columns: 1fr 3fr; -} +