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

Revue Block #14645

Merged
merged 25 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bbdc557
[not verified] [not verified] Create a new Revue block
Copons Feb 11, 2020
5af45e8
[not verified] Use the official subscription form
Copons Feb 12, 2020
540a6ef
[not verified] [not verified] Use the subscription link in AJAX
Copons Feb 13, 2020
5b25d7c
Update the form to open Revue in a new tab
Copons Feb 18, 2020
b22c701
Add a proper icon
Copons Feb 21, 2020
57d688c
Use the proper icon in the placeholder state
Copons Feb 21, 2020
d649794
Update block description
Copons Feb 21, 2020
b646000
Fix placeholder state form positioning
Copons Feb 21, 2020
1ebb82a
Fix typo in the block settings
Copons Feb 21, 2020
65f50b0
Improve copy
Copons Feb 21, 2020
c8d8db0
Add an option to toggle the name fields
Copons Feb 21, 2020
c608a48
Use getValidatedAttributes pattern
Copons Feb 21, 2020
e4b888b
Fix typo in the icon
Copons Feb 21, 2020
5e74e03
Clarify that button settings are for the button
Copons Feb 21, 2020
417323f
Fix too much copypasta
Copons Feb 21, 2020
9de8808
Add missing wp-block-button class and disable inline formatting
Copons Feb 21, 2020
6585c02
Add a support link
Copons Feb 21, 2020
20c3bbe
Add a block preview
Copons Feb 21, 2020
d95c9f0
Switch form settings to toggle
Feb 23, 2020
838662b
Add a preview only watermark to editor preview
Feb 24, 2020
6a94f24
Fix class naming
Feb 24, 2020
b49c0bf
Simplify the block's view
Copons Feb 24, 2020
f1a155d
Improve button preview and save
Copons Feb 24, 2020
8e665f9
In the editor, make the form work similar to the Contact Form block
Copons Feb 24, 2020
b9aa5a0
Properly escape all the strings
Copons Feb 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion extensions/blocks/contact-form/components/jetpack-field-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@ import { __ } from '@wordpress/i18n';
import { PlainText } from '@wordpress/block-editor';
import { ToggleControl } from '@wordpress/components';

const JetpackFieldLabel = ( { setAttributes, label, resetFocus, isSelected, required } ) => {
const JetpackFieldLabel = ( {
setAttributes,
label,
labelFieldName,
resetFocus,
isSelected,
required,
} ) => {
return (
<div className="jetpack-field-label">
<PlainText
value={ label }
className="jetpack-field-label__input"
onChange={ value => {
resetFocus && resetFocus();
if ( labelFieldName ) {
setAttributes( { [ labelFieldName ]: value } );
return;
}
setAttributes( { label: value } );
} }
placeholder={ __( 'Write label…', 'jetpack' ) }
Expand Down
68 changes: 68 additions & 0 deletions extensions/blocks/revue/attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-disable wpcalypso/import-docblock */
/**
* WordPress dependencies
*/
import { _x, __ } from '@wordpress/i18n';

export default {
revueUsername: {
type: 'string',
},
text: {
type: 'string',
default: _x( 'Subscribe', 'verb: e.g. subscribe to a newsletter.', 'jetpack' ),
},
emailLabel: {
type: 'string',
default: __( 'Email address', 'jetpack' ),
},
emailPlaceholder: {
type: 'string',
default: __( 'Your email address…', 'jetpack' ),
},
firstNameLabel: {
type: 'string',
default: __( 'First name', 'jetpack' ),
},
firstNamePlaceholder: {
type: 'string',
default: __( 'First name… (Optional)', 'jetpack' ),
},
firstNameShow: {
type: 'boolean',
default: true,
},
lastNameLabel: {
type: 'string',
default: __( 'Last name', 'jetpack' ),
},
lastNamePlaceholder: {
type: 'string',
default: __( 'Last name… (Optional)', 'jetpack' ),
},
lastNameShow: {
type: 'boolean',
default: true,
},
backgroundColor: {
type: 'string',
},
textColor: {
type: 'string',
},
customBackgroundColor: {
type: 'string',
},
customTextColor: {
type: 'string',
},
borderRadius: {
type: 'number',
},
gradient: {
type: 'string',
},
customGradient: {
type: 'string',
},
};
183 changes: 183 additions & 0 deletions extensions/blocks/revue/button-preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// @see https://github.com/WordPress/gutenberg/blob/015555fcdf648b13af57e08cee60bf3f3501ff63/packages/block-library/src/button/edit.js
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import {
ContrastChecker,
InspectorControls,
PanelColorSettings,
RichText,
withColors,
__experimentalPanelColorGradientSettings as PanelColorGradientSettings,
__experimentalUseGradient as useGradient,
} from '@wordpress/block-editor';
import { PanelBody, RangeControl, withFallbackStyles } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

const { getComputedStyle } = window;

const isGradientAvailable = !! useGradient;

const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { textColor, backgroundColor } = ownProps;
const backgroundColorValue = backgroundColor && backgroundColor.color;
const textColorValue = textColor && textColor.color;
//avoid the use of querySelector if textColor color is known and verify if node is available.
const textNode =
! textColorValue && node ? node.querySelector( '[contenteditable="true"]' ) : null;
return {
fallbackBackgroundColor:
backgroundColorValue || ! node ? undefined : getComputedStyle( node ).backgroundColor,
fallbackTextColor:
textColorValue || ! textNode ? undefined : getComputedStyle( textNode ).color,
};
} );

const MIN_BORDER_RADIUS_VALUE = 0;
const MAX_BORDER_RADIUS_VALUE = 50;
const INITIAL_BORDER_RADIUS_POSITION = 5;

function BorderPanel( { borderRadius = '', setAttributes } ) {
const setBorderRadius = useCallback(
newBorderRadius => {
setAttributes( { borderRadius: newBorderRadius } );
},
[ setAttributes ]
);
return (
<PanelBody title={ __( 'Button Border Settings', 'jetpack' ) }>
<RangeControl
value={ borderRadius }
label={ __( 'Border Radius', 'jetpack' ) }
min={ MIN_BORDER_RADIUS_VALUE }
max={ MAX_BORDER_RADIUS_VALUE }
initialPosition={ INITIAL_BORDER_RADIUS_POSITION }
allowReset
onChange={ setBorderRadius }
/>
</PanelBody>
);
}

function ButtonPreview( {
attributes,
backgroundColor,
className,
fallbackBackgroundColor,
fallbackTextColor,
setAttributes,
setBackgroundColor,
setTextColor,
textColor,
} ) {
const { borderRadius, text } = attributes;

const { gradientClass, gradientValue, setGradient } = isGradientAvailable ? useGradient() : {};

const classes = classnames( className, 'wp-block-button__link', {
'has-background': backgroundColor.color || gradientValue,
[ backgroundColor.class ]: ! gradientValue && backgroundColor.class,
'has-text-color': textColor.color,
[ textColor.class ]: textColor.class,
[ gradientClass ]: gradientClass,
'no-border-radius': borderRadius === 0,
} );

const styles = {
...( ! backgroundColor.color && gradientValue
? { background: gradientValue }
: { backgroundColor: backgroundColor.color } ),
color: textColor.color,
borderRadius: borderRadius ? borderRadius + 'px' : undefined,
};

return (
<div className="wp-block-button">
<RichText
allowedFormats={ [] }
className={ classes }
onChange={ value => setAttributes( { text: value } ) }
placeholder={ __( 'Add text…', 'jetpack' ) }
style={ styles }
value={ text }
withoutInteractiveFormatting
/>

<InspectorControls>
{ isGradientAvailable && (
<PanelColorGradientSettings
title={ __( 'Button Background & Text Color', 'jetpack' ) }
settings={ [
{
colorValue: textColor.color,
onColorChange: setTextColor,
label: __( 'Text Color', 'jetpack' ),
},
{
colorValue: backgroundColor.color,
onColorChange: setBackgroundColor,
gradientValue,
onGradientChange: setGradient,
label: __( 'Background', 'jetpack' ),
},
] }
>
<ContrastChecker
{ ...{
// Text is considered large if font size is greater or equal to 18pt or 24px,
// currently that's not the case for button.
isLargeText: false,
textColor: textColor.color,
backgroundColor: backgroundColor.color,
fallbackBackgroundColor,
fallbackTextColor,
} }
/>
</PanelColorGradientSettings>
) }
{ ! isGradientAvailable && (
<PanelColorSettings
title={ __( 'Button Background & Text Color', 'jetpack' ) }
colorSettings={ [
{
value: textColor.color,
onChange: setTextColor,
label: __( 'Text Color', 'jetpack' ),
},
{
value: backgroundColor.color,
onChange: setBackgroundColor,
label: __( 'Background', 'jetpack' ),
},
] }
>
<ContrastChecker
{ ...{
// Text is considered large if font size is greater or equal to 18pt or 24px,
// currently that's not the case for button.
isLargeText: false,
textColor: textColor.color,
backgroundColor: backgroundColor.color,
fallbackBackgroundColor,
fallbackTextColor,
} }
/>
</PanelColorSettings>
) }
<BorderPanel borderRadius={ borderRadius } setAttributes={ setAttributes } />
</InspectorControls>
</div>
);
}

export default compose( [
withColors( 'backgroundColor', { textColor: 'color' } ),
applyFallbackStyles,
] )( ButtonPreview );
Loading