diff --git a/projects/plugins/jetpack/changelog/add-styling_for_input_fields b/projects/plugins/jetpack/changelog/add-styling_for_input_fields new file mode 100644 index 000000000000..582fc7654ac3 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-styling_for_input_fields @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +Form Block: add styling of input fields 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 b7be5eef5d00..9d9759cd6e00 100644 --- a/projects/plugins/jetpack/extensions/blocks/contact-form/child-blocks.js +++ b/projects/plugins/jetpack/extensions/blocks/contact-form/child-blocks.js @@ -50,6 +50,38 @@ const FieldDefaults = { type: 'number', default: 100, }, + borderRadius: { + type: 'number', + default: '', + }, + borderWidth: { + type: 'number', + default: '', + }, + labelFontSize: { + type: 'string', + }, + fieldFontSize: { + type: 'string', + }, + lineHeight: { + type: 'number', + }, + labelLineHeight: { + type: 'number', + }, + inputColor: { + type: 'string', + }, + labelColor: { + type: 'string', + }, + fieldBackgroundColor: { + type: 'string', + }, + borderColor: { + type: 'string', + }, }, transforms: { to: [ @@ -134,6 +166,7 @@ const editField = type => props => { return ( props => { placeholder={ props.attributes.placeholder } id={ props.attributes.id } width={ props.attributes.width } + attributes={ props.attributes } /> ); }; @@ -153,6 +187,7 @@ const editMultiField = type => props => { return ( props => { isSelected={ props.isSelected } id={ props.attributes.id } width={ props.attributes.width } + attributes={ props.attributes } /> ); }; @@ -174,6 +210,7 @@ const EditTextarea = props => { label={ props.attributes.label } required={ props.attributes.required } requiredText={ props.attributes.requiredText } + attributes={ props.attributes } setAttributes={ props.setAttributes } isSelected={ props.isSelected } defaultValue={ props.attributes.defaultValue } @@ -197,6 +234,7 @@ const EditCheckbox = props => { defaultValue={ props.attributes.defaultValue } id={ props.attributes.id } width={ props.attributes.width } + attributes={ props.attributes } /> ); }; @@ -214,6 +252,7 @@ const EditConsent = ( { attributes, clientId, isSelected, name, setAttributes } implicitConsentMessage={ implicitConsentMessage } explicitConsentMessage={ explicitConsentMessage } setAttributes={ setAttributes } + attributes={ attributes } /> ); }; diff --git a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-checkbox.js b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-checkbox.js index 5be71285f5bc..eed2927f4ec5 100644 --- a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-checkbox.js +++ b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-checkbox.js @@ -1,9 +1,17 @@ -import { InspectorControls } from '@wordpress/block-editor'; +import { + FontSizePicker, + InspectorAdvancedControls, + InspectorControls, + PanelColorSettings, +} from '@wordpress/block-editor'; import { PanelBody, ToggleControl } from '@wordpress/components'; import { withInstanceId } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; -import JetpackFieldControls from './jetpack-field-controls'; +import JetpackFieldCss from './jetpack-field-css'; import JetpackFieldLabel from './jetpack-field-label'; +import JetpackFieldWidth from './jetpack-field-width'; +import JetpackManageResponsesSettings from './jetpack-manage-responses-settings'; +import { useJetpackFieldStyles } from './use-jetpack-field-styles'; function JetpackFieldCheckbox( props ) { const { @@ -15,12 +23,16 @@ function JetpackFieldCheckbox( props ) { setAttributes, width, defaultValue, + attributes, } = props; + const { blockStyle } = useJetpackFieldStyles( attributes ); + return (
- @@ -49,6 +56,50 @@ function JetpackFieldCheckbox( props ) { /> + + + + + + setAttributes( { required: value } ) } + help={ __( 'You can edit the "required" label in the editor', 'jetpack' ) } + /> + + + + setAttributes( { labelColor: value } ), + label: __( 'Label Text', 'jetpack' ), + }, + ] } + > + + setAttributes( { labelFontSize } ) } + value={ attributes.labelFontSize } + /> + + + + + +
); } diff --git a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-consent.js b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-consent.js index 86b7620ceef1..63eca578cb89 100644 --- a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-consent.js +++ b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-consent.js @@ -15,6 +15,7 @@ const JetpackFieldConsent = ( { implicitConsentMessage, explicitConsentMessage, setAttributes, + attributes, } ) => { return (
{ + const setNumberAttribute = ( key, parse = parseInt ) => value => { + const parsedValue = parse( value, 10 ); + + setAttributes( { + [ key ]: ! isNaN( parsedValue ) ? parsedValue : '', + } ); + }; + + const hasBorderControls = type !== 'radio' && type !== 'checkbox'; + + const colorSettings = [ + { + value: attributes.labelColor, + onChange: value => setAttributes( { labelColor: value } ), + label: __( 'Label Text', 'jetpack' ), + }, + { + value: attributes.inputColor, + onChange: value => setAttributes( { inputColor: value } ), + label: __( 'Field Text', 'jetpack' ), + }, + { + value: attributes.fieldBackgroundColor, + onChange: value => setAttributes( { fieldBackgroundColor: value } ), + label: __( 'Field Background', 'jetpack' ), + }, + { + value: attributes.borderColor, + onChange: value => setAttributes( { borderColor: value } ), + label: __( 'Border', 'jetpack' ), + }, + ]; + return ( <> @@ -67,8 +107,72 @@ const JetpackFieldControls = ( { 'jetpack' ) } /> - + + + + + setAttributes( { fieldFontSize } ) } + value={ attributes.fieldFontSize } + /> + + + + + { hasBorderControls && ( + <> + + + + ) } + + + + setAttributes( { labelFontSize } ) } + value={ attributes.labelFontSize } + /> + + + + diff --git a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-dropdown.js b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-dropdown.js index f3a5b165901f..d9fb61f2600d 100644 --- a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-dropdown.js +++ b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-dropdown.js @@ -6,6 +6,7 @@ import { setFocus } from '../util/focus'; import { useFormWrapper } from '../util/form'; import JetpackFieldControls from './jetpack-field-controls'; import JetpackFieldLabel from './jetpack-field-label'; +import { useJetpackFieldStyles } from './use-jetpack-field-styles'; export const JetpackDropdownEdit = ( { attributes, @@ -96,17 +97,20 @@ export const JetpackDropdownEdit = ( { // eslint-disable-next-line react-hooks/exhaustive-deps }, [] ); + const { blockStyle } = useJetpackFieldStyles( attributes ); + return ( - <> +
-
+
{ @@ -139,11 +143,13 @@ export const JetpackDropdownEdit = ( { - +
); }; diff --git a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-label.js b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-label.js index 5be24d7935ff..e04447af5935 100644 --- a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-label.js +++ b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field-label.js @@ -2,6 +2,7 @@ import { RichText } from '@wordpress/block-editor'; import { useEffect } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { isNil } from 'lodash'; +import { useJetpackFieldStyles } from './use-jetpack-field-styles'; const JetpackFieldLabel = ( { setAttributes, @@ -11,6 +12,7 @@ const JetpackFieldLabel = ( { resetFocus, required, requiredText, + attributes, } ) => { useEffect( () => { if ( isNil( requiredText ) ) { @@ -19,36 +21,40 @@ const JetpackFieldLabel = ( { // 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 && ( +
{ - setAttributes( { requiredText: value } ); + resetFocus && resetFocus(); + if ( labelFieldName ) { + setAttributes( { [ labelFieldName ]: value } ); + return; + } + setAttributes( { label: value } ); } } + placeholder={ placeholder ?? __( 'Add label…', 'jetpack' ) } withoutInteractiveFormatting allowedFormats={ [ 'core/bold', 'core/italic' ] } /> - ) } + { required && ( + { + setAttributes( { requiredText: value } ); + } } + withoutInteractiveFormatting + allowedFormats={ [ 'core/bold', 'core/italic' ] } + /> + ) } +
); }; 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 0bd0abe5b96b..52e2b31327c3 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 @@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n'; import JetpackFieldControls from './jetpack-field-controls'; import JetpackFieldLabel from './jetpack-field-label'; import JetpackOption from './jetpack-option'; +import { useJetpackFieldStyles } from './use-jetpack-field-styles'; function JetpackFieldMultiple( props ) { const { @@ -18,6 +19,7 @@ function JetpackFieldMultiple( props ) { isSelected, width, options, + attributes, } = props; const [ inFocus, setInFocus ] = useState( null ); @@ -55,8 +57,10 @@ function JetpackFieldMultiple( props ) { setAttributes( { options: newOptions } ); }; + const { blockStyle, fieldStyle } = useJetpackFieldStyles( attributes ); + return ( - <> +
setInFocus( null ) } + attributes={ attributes } />
    ) ) }
@@ -101,10 +107,12 @@ function JetpackFieldMultiple( props ) { - +
); } 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 4c22d29092ab..45fcdb82eeb9 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 @@ -4,9 +4,19 @@ import { __ } from '@wordpress/i18n'; import { isNil } from 'lodash'; 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 { id, required, requiredText, label, setAttributes, placeholder, width } = props; + const { + id, + required, + requiredText, + label, + setAttributes, + placeholder, + width, + attributes, + } = props; useEffect( () => { if ( isNil( label ) ) { @@ -15,14 +25,17 @@ export default function JetpackFieldTextarea( props ) { // eslint-disable-next-line react-hooks/exhaustive-deps }, [] ); + const { blockStyle, fieldStyle } = useJetpackFieldStyles( attributes ); + return ( <> -
+
setAttributes( { placeholder: value } ) } title={ __( 'Set the placeholder text', 'jetpack' ) } + style={ fieldStyle } />
@@ -40,6 +54,7 @@ export default function JetpackFieldTextarea( props ) { setAttributes={ setAttributes } width={ width } placeholder={ placeholder } + attributes={ attributes } /> ); diff --git a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field.js b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field.js index 4658de789923..9e40c8538776 100644 --- a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field.js +++ b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-field.js @@ -4,18 +4,32 @@ import { addFilter } from '@wordpress/hooks'; import { __ } from '@wordpress/i18n'; import JetpackFieldControls from './jetpack-field-controls'; import JetpackFieldLabel from './jetpack-field-label'; +import { useJetpackFieldStyles } from './use-jetpack-field-styles'; export default function JetpackField( props ) { - const { id, type, required, requiredText, label, setAttributes, placeholder, width } = props; + const { + id, + type, + required, + requiredText, + label, + setAttributes, + placeholder, + width, + attributes, + } = props; + + const { blockStyle, fieldStyle } = useJetpackFieldStyles( attributes ); return ( <> -
+
setAttributes( { placeholder: value } ) } title={ __( 'Set the placeholder text', 'jetpack' ) } + style={ fieldStyle } />
@@ -34,6 +49,7 @@ export default function JetpackField( props ) { width={ width } setAttributes={ setAttributes } placeholder={ placeholder } + attributes={ attributes } /> ); diff --git a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-option.js b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-option.js index 09f8f2e6e5bb..9eaa81e1cb20 100644 --- a/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-option.js +++ b/projects/plugins/jetpack/extensions/blocks/contact-form/components/jetpack-option.js @@ -46,11 +46,11 @@ class JetpackOption extends Component { } render() { - const { isSelected, option, type } = this.props; + const { isSelected, option, type, style } = this.props; return (
  • { type && type !== 'select' && ( - + ) } { isSelected && (