-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update subscriptions block to handle CSS unit font sizes (#18936)
Due to Gutenberg updating its FontSizePicker and theme.json to handle CSS units, those values are now strings which were incompatible with the approach in the subscriptions block shortcode for custom font sizes.
- Loading branch information
1 parent
89de4d0
commit 92a66a4
Showing
10 changed files
with
195 additions
and
14 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
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
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
17 changes: 17 additions & 0 deletions
17
projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v5/index.js
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,17 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import definedAttributes from '../v3/attributes'; | ||
import save from './save'; | ||
|
||
export default { | ||
attributes: definedAttributes, | ||
migrate: attributes => { | ||
return { | ||
...attributes, | ||
fontSize: `${ attributes.fontSize }px`, | ||
customFontSize: `${ attributes.customFontSize }px`, | ||
}; | ||
}, | ||
save, | ||
}; |
147 changes: 147 additions & 0 deletions
147
projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v5/save.js
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,147 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { RawHTML } from '@wordpress/element'; | ||
import { | ||
getColorClassName, | ||
__experimentalGetGradientClass as getGradientClass, | ||
getFontSizeClass, | ||
} from '@wordpress/block-editor'; | ||
import classnames from 'classnames'; | ||
import { reduce } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import definedAttributes from '../v3/attributes'; | ||
|
||
export const DEFAULT_BORDER_RADIUS_VALUE = 0; | ||
export const DEFAULT_BORDER_WEIGHT_VALUE = 1; | ||
export const DEFAULT_PADDING_VALUE = 15; | ||
export const DEFAULT_SPACING_VALUE = 10; | ||
export const DEFAULT_FONTSIZE_VALUE = 16; | ||
|
||
export default function Save( { className, attributes } ) { | ||
const { | ||
subscribePlaceholder, | ||
showSubscribersTotal, | ||
buttonOnNewLine, | ||
submitButtonText, | ||
emailFieldBackgroundColor, | ||
customEmailFieldBackgroundColor, | ||
emailFieldGradient, | ||
customEmailFieldGradient, | ||
buttonBackgroundColor, | ||
customButtonBackgroundColor, | ||
buttonGradient, | ||
customButtonGradient, | ||
textColor, | ||
customTextColor, | ||
fontSize, | ||
customFontSize, | ||
borderRadius, | ||
borderWeight, | ||
borderColor, | ||
customBorderColor, | ||
padding, | ||
spacing, | ||
} = attributes; | ||
|
||
const isGradientAvailable = !! getGradientClass; | ||
|
||
const textColorClass = getColorClassName( 'color', textColor ); | ||
const fontSizeClass = getFontSizeClass( fontSize ); | ||
const borderClass = getColorClassName( 'border-color', borderColor ); | ||
const buttonBackgroundClass = getColorClassName( 'background-color', buttonBackgroundColor ); | ||
const buttonGradientClass = isGradientAvailable ? getGradientClass( buttonGradient ) : undefined; | ||
|
||
const emailFieldBackgroundClass = getColorClassName( | ||
'background-color', | ||
emailFieldBackgroundColor | ||
); | ||
const emailFieldGradientClass = isGradientAvailable | ||
? getGradientClass( emailFieldGradient ) | ||
: undefined; | ||
|
||
const sharedClasses = classnames( | ||
borderRadius === 0 ? 'no-border-radius' : undefined, | ||
fontSizeClass, | ||
borderClass | ||
); | ||
|
||
const submitButtonClasses = classnames( | ||
sharedClasses, | ||
textColor ? 'has-text-color' : undefined, | ||
textColorClass, | ||
buttonBackgroundColor || buttonGradient ? 'has-background' : undefined, | ||
buttonBackgroundClass, | ||
buttonGradientClass | ||
); | ||
|
||
const emailFieldClasses = classnames( | ||
sharedClasses, | ||
emailFieldBackgroundClass, | ||
emailFieldGradientClass | ||
); | ||
|
||
const emailFieldBackgroundStyle = | ||
! emailFieldBackgroundClass && customEmailFieldGradient | ||
? customEmailFieldGradient | ||
: customEmailFieldBackgroundColor; | ||
|
||
const buttonBackgroundStyle = | ||
! buttonBackgroundClass && customButtonGradient | ||
? customButtonGradient | ||
: customButtonBackgroundColor; | ||
|
||
const getBlockClassName = () => { | ||
return classnames( | ||
className, | ||
'wp-block-jetpack-subscriptions__supports-newline', | ||
buttonOnNewLine ? 'wp-block-jetpack-subscriptions__use-newline' : undefined, | ||
showSubscribersTotal ? 'wp-block-jetpack-subscriptions__show-subs' : undefined | ||
); | ||
}; | ||
|
||
const shortcodeAttributes = { | ||
subscribe_placeholder: | ||
subscribePlaceholder !== definedAttributes.subscribePlaceholder.default | ||
? subscribePlaceholder | ||
: undefined, | ||
show_subscribers_total: showSubscribersTotal, | ||
button_on_newline: buttonOnNewLine, | ||
submit_button_text: | ||
submitButtonText !== definedAttributes.submitButtonText.default | ||
? submitButtonText | ||
: undefined, | ||
custom_background_emailfield_color: emailFieldBackgroundStyle, | ||
custom_background_button_color: buttonBackgroundStyle, | ||
custom_text_button_color: customTextColor, | ||
custom_font_size: customFontSize || DEFAULT_FONTSIZE_VALUE, | ||
custom_border_radius: borderRadius || DEFAULT_BORDER_RADIUS_VALUE, | ||
custom_border_weight: borderWeight || DEFAULT_BORDER_WEIGHT_VALUE, | ||
custom_border_color: customBorderColor, | ||
custom_padding: padding || DEFAULT_PADDING_VALUE, | ||
custom_spacing: spacing || DEFAULT_SPACING_VALUE, | ||
submit_button_classes: submitButtonClasses, | ||
email_field_classes: emailFieldClasses, | ||
show_only_email_and_button: true, | ||
}; | ||
|
||
const shortcodeAttributesStringified = reduce( | ||
shortcodeAttributes, | ||
( stringifiedAttributes, value, key ) => { | ||
if ( undefined === value ) { | ||
return stringifiedAttributes; | ||
} | ||
return stringifiedAttributes + ` ${ key }="${ value }"`; | ||
}, | ||
'' | ||
); | ||
|
||
return ( | ||
<div className={ getBlockClassName() }> | ||
<RawHTML>{ `[jetpack_subscription_form${ shortcodeAttributesStringified }]` }</RawHTML> | ||
</div> | ||
); | ||
} |
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