Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions extensions/shared/register-jetpack-block.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/**
* External dependencies
*/
import { addFilter } from '@wordpress/hooks';
import { registerBlockType } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import extensionList from '../index.json';
import getJetpackExtensionAvailability from './get-jetpack-extension-availability';
import withHasWarningIsInteractiveClassNames from './with-has-warning-is-interactive-class-names';
import wrapPaidBlock from './wrap-paid-block';

const betaExtensions = extensionList.beta || [];
Expand Down Expand Up @@ -48,6 +50,14 @@ export default function registerJetpackBlock( name, settings, childBlocks = [] )
edit: requiredPlan ? wrapPaidBlock( { requiredPlan } )( settings.edit ) : settings.edit,
} );

if ( requiredPlan ) {
addFilter(
'editor.BlockListBlock',
`jetpack/${ name }-with-has-warning-is-interactive-class-names`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha that's a mouthful!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, same for the component name 😬 Happy to change it something more palatable!

withHasWarningIsInteractiveClassNames( `jetpack/${ name }` )
);
}

// Register child blocks. Using `registerBlockType()` directly avoids availability checks -- if
// their parent is available, we register them all, without checking for their individual availability.
childBlocks.forEach( childBlock =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* External dependencies
*/
import { createHigherOrderComponent } from '@wordpress/compose';

import './style.scss';

// Injecting the `has-warning` class into the block wrapper component gives us
// the right kind of borders around the block, both visually and conceptually.
// However, it also adds styling to prevent user interaction with that block.
// We thus add a new `is-interactive` class to be able to override that behavior.
export default name =>
createHigherOrderComponent(
BlockListBlock => props => (
<BlockListBlock
{ ...props }
className={ props.name === name ? 'has-warning is-interactive' : '' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is-interactive isn't a core class, right? Therefore I'd jetpack-prefix it. Not a blocker tho.

/>
),
'withHasWarningIsInteractiveClassNames'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.block-editor-block-list__layout
// Override core styles inherited from `.has-warning`:
// we do want blocks with upgrade nudge warning to be interactive
.block-editor-block-list__block.has-warning.is-interactive
.block-editor-block-list__block-edit {
> * {
pointer-events: auto;
user-select: auto;
}

&:after {
content: none;
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
/**
* External dependencies
*/
import classNames from 'classnames';
import { Fragment } from '@wordpress/element';
import { createHigherOrderComponent } from '@wordpress/compose';

/**
* Internal dependencies
*/
import UpgradeNudge from '../upgrade-nudge';

import './style.scss';
import UpgradeNudge from './upgrade-nudge';

export default ( { requiredPlan } ) =>
createHigherOrderComponent(
WrappedComponent => props => (
// Wraps the input component in a container, without mutating it. Good!
<div
className={ classNames( 'jetpack-paid-block__wrapper', {
'is-selected': props.isSelected,
} ) }
>
<Fragment>
<UpgradeNudge plan={ requiredPlan } />
<WrappedComponent { ...props } />
</div>
</Fragment>
),
'wrapPaidBlock'
);
12 changes: 0 additions & 12 deletions extensions/shared/wrap-paid-block/style.scss

This file was deleted.