Skip to content

Commit

Permalink
Add stretched link variations from plugin (#2270)
Browse files Browse the repository at this point in the history
* Add stretched link variations

- Include styles and JS code from plugin

---------

Co-authored-by: Dan Tovbein <dtovbein@gmail.com>
  • Loading branch information
GP-Dan-Tovbein and dantovbein committed Apr 25, 2024
1 parent e4d9709 commit 38cf0a1
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
22 changes: 22 additions & 0 deletions assets/src/block-variations/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const {registerBlockVariation} = wp.blocks;
const {__} = wp.i18n;

/*
This file will register general block variations. In case of register a very
specific block variation, such as PostsList or ActionsList ,you can create an isolated file.
*/

export const registerBlockVariations = () => {
// Group Stretched Link variation
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: 'group-stretched-link'},
scope: ['inserter', 'transform'],
isActive: blockAttributes => {
return blockAttributes.className === 'group-stretched-link';
},
icon: 'admin-links',
});
};
4 changes: 4 additions & 0 deletions assets/src/editorIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {registerMediaBlock} from './blocks/Media/MediaBlock';
import {registerBlockTemplates} from './block-templates/register';
import {registerTimelineBlock} from './blocks/Timeline/TimelineBlock';
import {registerColumnsBlock} from './blocks/Columns/ColumnsBlock';
import {registerBlockVariations} from './block-variations';

wp.domReady(() => {
// Make sure to unregister the posts-list native variation before registering planet4-blocks/posts-list
Expand All @@ -30,6 +31,9 @@ wp.domReady(() => {
// Beta blocks
registerActionsListBlock();
registerPostsListBlock();

// Block variations
registerBlockVariations();
});

setupCustomSidebar();
Expand Down
3 changes: 3 additions & 0 deletions assets/src/scss/editorStyle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@
@import "blocks/Submenu/SubmenuEditorStyle";
@import "blocks/TakeActionBoxout/TakeActionBoxoutEditorStyle";
@import "blocks/Timeline/TimelineEditorStyle";

// Variations
@import "variations/stretched-link/edit";
3 changes: 3 additions & 0 deletions assets/src/scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ Text Domain: planet4-master-theme

@import "layout/query-loop-overrides";

// Variations
@import "variations/stretched-link";

// Hide WPML footer language switcher.
.wpml-ls-statics-footer {
display: none;
Expand Down
4 changes: 4 additions & 0 deletions assets/src/scss/variations/stretched-link/edit.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.group-stretched-link {
outline: 1px dashed grey;
outline-offset: 2px;
}
35 changes: 35 additions & 0 deletions assets/src/scss/variations/stretched-link/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.group-stretched-link {
position: relative;

[class*="is-style-rounded-"].force-no-caption {
overflow: hidden;
border-radius: 50%;
transform: translateZ(0); // This is needed for Safari, otherwise the animation looks off.

img {
transition: transform .2s ease-in-out;
}
}

&:hover {
[class*="is-style-rounded-"] img {
transform: scale(1.3);
}
}

// 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 38cf0a1

Please sign in to comment.