diff --git a/projects/plugins/jetpack/changelog/add-form-loading b/projects/plugins/jetpack/changelog/add-form-loading new file mode 100644 index 0000000000000..5f09e874086ba --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-form-loading @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +Add a blur effect while the form is loading the styles diff --git a/projects/plugins/jetpack/changelog/add-form-style-variations b/projects/plugins/jetpack/changelog/add-form-style-variations new file mode 100644 index 0000000000000..a904856e66c7d --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-form-style-variations @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +Include style variations for the Form block diff --git a/projects/plugins/jetpack/extensions/blocks/contact-form/child-blocks.js b/projects/plugins/jetpack/extensions/blocks/contact-form/child-blocks.js index 9d9759cd6e00f..78ce30f4d81a7 100644 --- a/projects/plugins/jetpack/extensions/blocks/contact-form/child-blocks.js +++ b/projects/plugins/jetpack/extensions/blocks/contact-form/child-blocks.js @@ -207,6 +207,7 @@ const EditTextarea = props => { return ( { const { id, label, options, required, requiredText, toggleLabel, width } = attributes; const optionsWrapper = useRef(); + const formStyle = useFormStyle( clientId ); + + const classes = classnames( 'jetpack-field jetpack-field-dropdown', { + 'is-selected': isSelected, + 'has-placeholder': ! isEmpty( toggleLabel ), + } ); useFormWrapper( { attributes, clientId, name } ); @@ -100,17 +107,18 @@ export const JetpackDropdownEdit = ( { const { blockStyle } = useJetpackFieldStyles( attributes ); return ( -
- -
-
+
+
+ +
{ @@ -121,25 +129,24 @@ export const JetpackDropdownEdit = ( { />
- - { isSelected && ( -
- { options.map( ( option, index ) => ( - - ) ) } -
- ) }
+ { isSelected && ( +
+ { options.map( ( option, index ) => ( + + ) ) } +
+ ) } { - useEffect( () => { - if ( isNil( requiredText ) ) { - setAttributes( { requiredText: __( '(required)', 'jetpack' ) } ); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [] ); - const { labelStyle } = useJetpackFieldStyles( attributes ); return ( -
-
+
+ { + resetFocus && resetFocus(); + if ( labelFieldName ) { + setAttributes( { [ labelFieldName ]: value } ); + return; + } + setAttributes( { label: value } ); + } } + placeholder={ placeholder ?? __( 'Add label…', 'jetpack' ) } + withoutInteractiveFormatting + allowedFormats={ [ 'core/bold', 'core/italic' ] } + /> + { required && ( { - resetFocus && resetFocus(); - if ( labelFieldName ) { - setAttributes( { [ labelFieldName ]: value } ); - return; - } - setAttributes( { label: value } ); + setAttributes( { requiredText: value } ); } } - placeholder={ placeholder ?? __( 'Add label…', 'jetpack' ) } withoutInteractiveFormatting allowedFormats={ [ 'core/bold', 'core/italic' ] } /> - { required && ( - { - setAttributes( { requiredText: value } ); - } } - withoutInteractiveFormatting - allowedFormats={ [ 'core/bold', 'core/italic' ] } - /> - ) } -
+ ) }
); }; +const JetpackFieldLabel = props => { + const { setAttributes, requiredText, style } = props; + + const classes = classnames( { + 'notched-label__label': style === FORM_STYLE.OUTLINED, + 'animated-label__label': style === FORM_STYLE.ANIMATED, + 'below-label__label': style === FORM_STYLE.BELOW, + } ); + + useEffect( () => { + if ( isNil( requiredText ) ) { + setAttributes( { requiredText: __( '(required)', 'jetpack' ) } ); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [] ); + + if ( style === FORM_STYLE.OUTLINED ) { + return ( +
+
+
+ +
+
+
+ ); + } + + return ; +}; + export default JetpackFieldLabel; diff --git a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-multiple.js b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-multiple.js index 52e2b31327c36..46250d8f0c054 100644 --- a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-multiple.js +++ b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-multiple.js @@ -2,6 +2,8 @@ import { Button } from '@wordpress/components'; import { withInstanceId } from '@wordpress/compose'; import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import classnames from 'classnames'; +import { useFormStyle } from '../util/form'; import JetpackFieldControls from './jetpack-field-controls'; import JetpackFieldLabel from './jetpack-field-label'; import JetpackOption from './jetpack-option'; @@ -9,6 +11,7 @@ import { useJetpackFieldStyles } from './use-jetpack-field-styles'; function JetpackFieldMultiple( props ) { const { + clientId, id, type, instanceId, @@ -21,6 +24,12 @@ function JetpackFieldMultiple( props ) { options, attributes, } = props; + const formStyle = useFormStyle( clientId ); + + const classes = classnames( 'jetpack-field jetpack-field-multiple', { + 'is-selected': isSelected, + 'has-placeholder': options.length, + } ); const [ inFocus, setInFocus ] = useState( null ); @@ -60,10 +69,11 @@ function JetpackFieldMultiple( props ) { const { blockStyle, fieldStyle } = useJetpackFieldStyles( attributes ); return ( -
+ <>
setInFocus( null ) } attributes={ attributes } + style={ formStyle } />
    -
+ ); } diff --git a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-textarea.js b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-textarea.js index 45fcdb82eeb9a..23c72377b961d 100644 --- a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-textarea.js +++ b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-textarea.js @@ -1,22 +1,31 @@ -import { TextareaControl, Disabled } from '@wordpress/components'; import { useEffect } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; -import { isNil } from 'lodash'; +import classnames from 'classnames'; +import { isEmpty, isNil } from 'lodash'; +import { useFormStyle } from '../util/form'; import JetpackFieldControls from './jetpack-field-controls'; import JetpackFieldLabel from './jetpack-field-label'; import { useJetpackFieldStyles } from './use-jetpack-field-styles'; export default function JetpackFieldTextarea( props ) { const { + attributes, + clientId, id, + isSelected, required, requiredText, label, setAttributes, placeholder, width, - attributes, } = props; + const formStyle = useFormStyle( clientId ); + const { blockStyle, fieldStyle } = useJetpackFieldStyles( attributes ); + + const classes = classnames( 'jetpack-field jetpack-field-textarea', { + 'is-selected': isSelected, + 'has-placeholder': ! isEmpty( placeholder ), + } ); useEffect( () => { if ( isNil( label ) ) { @@ -25,27 +34,24 @@ export default function JetpackFieldTextarea( props ) { // eslint-disable-next-line react-hooks/exhaustive-deps }, [] ); - const { blockStyle, fieldStyle } = useJetpackFieldStyles( attributes ); - return ( <> -
+
+