Skip to content

Commit

Permalink
Add group variation for full block link
Browse files Browse the repository at this point in the history
* Use first link inside the block and expand it to full width/height
* Give separate editor styles: a dashed border round the block to show the clickable area.
* Prevent conflict with pdf and external link styles, by using :before instead of :after.
  • Loading branch information
Inwerpsel authored and mleray committed May 17, 2022
1 parent 372bb2c commit 3db0e20
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
16 changes: 16 additions & 0 deletions assets/src/editorIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SubPagesBlock } from './blocks/SubPages/SubPagesBlock';
import { blockEditorValidation } from './BlockEditorValidation';
import { registerGuestBookBlock } from './blocks/GuestBook/GuestBookBlock';
import { registerBlock as registerShareButtonsBlock } from './blocks/ShareButtons/ShareButtonsBlock';
import { Fragment } from 'react';

blockEditorValidation();
new ArticlesBlock();
Expand All @@ -47,3 +48,18 @@ replaceTaxonomyTermSelectors();
setupCustomSidebar();
setUpCssVariables();
blockEditorValidation();

const { registerBlockVariation } = wp.blocks;
const { __ } = wp.i18n;

registerBlockVariation('core/group', {
name: 'group-stretched-link',
title: __('Stretched Link', 'planet4-blocks-backend'),
description: __('Make the entire block contents clickable, using the first link inside.', 'planet4-blocks-backend'),
attributes: { className: 'is-style-stretched-link' },
scope: ['inserter', 'transform'],
isActive: (blockAttributes) => {
return blockAttributes.className === 'is-style-stretched-link';
},
icon: <Fragment>🔗</Fragment>,
});
4 changes: 3 additions & 1 deletion assets/src/styles/blocks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

// Other
@import "blocks/WideBlocks";
@import "blocks/Editor";

.is-style-small-padding {
padding: 8px;
Expand Down Expand Up @@ -58,3 +57,6 @@
.is-style-roboto-font-family {
font-family: $roboto;
}

// Variations
@import "../variations/stretched-link";
4 changes: 0 additions & 4 deletions assets/src/styles/blocks/Editor.scss

This file was deleted.

6 changes: 6 additions & 0 deletions assets/src/styles/editorStyle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@import "blocks/TakeActionBoxout/edit";
@import "blocks/CookiesEditor";
@import "blocks/core-overrides/HeadingEditor";
@import "../variations/stretched-link/edit";

@import "components/LayoutSelector";
@import "components/EmptyMessage";
Expand All @@ -27,3 +28,8 @@
@import "components/FormField";
@import "components/HTMLSidebarHelp";
@import "editorFonts";

.block-edit-mode-warning {
padding: $sp-2;
margin: 0;
}
4 changes: 4 additions & 0 deletions assets/src/variations/stretched-link/edit.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.is-style-stretched-link {
outline: 1px dashed grey;
outline-offset: 2px;
}
21 changes: 21 additions & 0 deletions assets/src/variations/stretched-link/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.is-style-stretched-link {
position: relative;
width: fit-content;
margin: auto;

// Ensure it's only applying to the first link.
a:first-of-type {
&:before {
content: "";
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}

&:after {
display: none;
}
}
}

0 comments on commit 3db0e20

Please sign in to comment.