-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add a Marquee block #13
base: trunk
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look at the approach of using a Block Variation of the Group block to implement this.
Unfortunately, the Block Variations API seems insufficient to pull this off. We'd need a few things that it does not provide AFAIK:
- A way to customize the CSS used by the block (for the scrolling animation)
- A way to wrap the block with another HTML element that serves as a scroll container
I got a bit stuck on how to "clone" the inner blocks of the Marquee correctly. For a marquee animation to work, the inner contents of the Marquee block need to be duplicated so that the animation gives an illusion that the same element is scrolling infinitely. Here's an example from Nectar blocks: output_bac22c.mp4At the moment, multiple Inner blocks are not possible (WordPress/gutenberg#6808), so I think I'll have to resort to cloning the element on the front end. |
I could also duplicate the inner content using the HTML API. But this means converting the block to a dynamic one. It feels a bit like overkill but it's probably the right way to go. |
Oh, I think I don't actually need the HTML API, I can render the <?php
$inner_blocks = $block->inner_blocks;
$inner_blocks_html = '';
foreach ($inner_blocks as $inner_block) {
$inner_blocks_html .= $inner_block->render();
}
?>
<div <?php echo get_block_wrapper_attributes(); ?> >
<div className="wp-block-wpcomsp-marquee__inner"><?php echo $inner_blocks_html; ?></div>
<div className="wp-block-wpcomsp-marquee__inner"><?php echo $inner_blocks_html; ?></div>
</div> |
From experience creating marquees, I've always used js to measure the parent, then measure the content, then duplicate content as necessary to fill the parent. Is it possible to measure those widths without js after the CSS has been rendered? |
…rientatio attribute
0c66d31
to
0ad0dee
Compare
I was wrong here again - I would need to get the block props from the
It's not possible 🙂 I'm back to using JS on the frontend to clone the inner elements of the Marquee block: // view.js
store("wpcomsp/marquee", {
callbacks: {
init: () => {
const { ref } = getElement();
const clonedElement = ref.firstElementChild.cloneNode(true);
ref.appendChild(clonedElement);
},
},
});
Thanks for the tip! Is it necessary to measure the parent, though? I'm cloning the inner blocks once and animating the whole parent container. So, if you (for example) want more space between the items, you modify the parent's layout. It looks something like this: output_f1833f.mp4 |
I think you do, because you don't want all that white space, you want to hug the child items together. I think you can animate the parent container as long as it hugs the width of its child items; then you can easily duplicate the parent. Also keep in mind block spacing: you'll want to apply that setting evenly between all blocks. I added this in the Figma file if needed. :) |
Ah, yeah, that makes sense, thank you! 🙂 |
I made some more progress: output_8592d6_2.mp4I might have to add a placeholder because en empty Marquee (without any inner blocks) looks just like an empty space (see this comment). I'm considering whether the Marquee block should contain a single inner |
I have to wrap up for today, but here's the status update: I figured that I'll need the PS. @Nyiriland That's the exact same idea as what you've described. The The way I want to accomplish this is with a Block Variation, but I ran into 2 issues:
|
I may have ran into this issue also, it was related to WordPress/gutenberg#62202. I worked around it by pinning |
Not sure if that helps at this stage, but it'd be amazing to let users see the animation in the site editor without opening the preview in a new tab. What if we triggered the interaction when the block is not selected? Selecting it with make the content visible and editable; deselecting would trigger the preview mode again. |
This is what I also see that I will have to enable the experimental support for ES Modules for the view script to use Interactivity API with |
I agree a preview of the scrolling would definitely be ideal to show in the editor, but to comply with a11y best practices, the motion should be user-triggered. I think we could include a toggle in the toolbar and sidebar; some explorations below. @jarekmorawski please jump in if you know of design precedence for this kind of setting! |
That sounds great, I'll try to incorporate this today. I think that the Markdown block in P2 and the Custom HTML blocks both have a "preview" mode so we can use a similar UI (in the block's toolbar) |
The issue with |
I figured out the issue with the // This works
const innerBlocksProps = useInnerBlocksProps(blockProps, {
allowedBlocks: ["core/group"],
...
});
// This DOES NOT work
const innerBlocksProps = useInnerBlocksProps(blockProps, {
allowedBlocks: ["wpcomsp/marquee-content"],
...
}); The issue I’m running into now is twofold:
|
I could not find a better solution than just using
Another thing that I'm uncertain about is the re-registering the Core variations. At the moment, I just copy-pasted the definition from Gutenberg but that definition can change at any moment 🙂. |
I need to wrap up work on the block from my side. Unfortunately, I didn't get far enough to implement the preview. However, it shouldn't be difficult to extend the block from its current state. I'm happy that I could re-use the mechanics of the
|
Some other notes:
|
On the off chance that this even a little bit helpful, we implemented a marquee as a Group block style for a recent project. We didn't do anything for the editor view, but here's what we did for the front-end: add_filter( 'render_block_core/group', 'wpcomsp_marquee_group_block', 10, 2 );
/**
* Filter output for marquee style group blocks.
*
* @param string $block_content Block content.
* @param array $block The full block.
*
* @return string Modified block content.
*/
function wpcomsp_marquee_group_block( string $block_content, array $block ): string {
if ( 'is-style-marquee' === ( $block['attrs']['className'] ?? false ) ) {
$tag_name = $block['attrs']['tagName'] ?? 'div';
$classlist = '';
$styles = '';
$tags = new \WP_HTML_Tag_Processor( $block_content );
// Capture the class and style attribute values before removing them.
if ( $tags->next_tag( $tag_name ) ) {
$classlist = $tags->get_attribute( 'class' );
$styles = $tags->get_attribute( 'style' );
$tags->remove_attribute( 'class' );
$tags->remove_attribute( 'style' );
}
// Capture the original block without wrapper attributes to use as content.
$content = $tags->get_updated_html();
$block_content = sprintf(
'<%1$s class="%2$s" style="%3$s">%4$s%4$s</%1$s>',
$tag_name,
$classlist,
$styles,
$content
);
}
return $block_content;
} And the styles: /* --- Marquee style - Group block --- */
.is-style-marquee {
--marquee-gap: var(--wp--preset--spacing--13);
display: flex;
gap: var( --marquee-gap );
overflow: hidden;
position: relative;
user-select: none;
> * {
animation: marquee 35s linear infinite;
flex-shrink: 0;
display: flex;
gap: var(--marquee-gap);
justify-content: space-around;
margin: 0;
min-width: 100%;
}
&:hover {
> * {
animation-play-state: paused;
}
}
}
@media (prefers-reduced-motion: reduce) {
.is-style-marquee {
> * {
animation-play-state: paused !important;
}
}
}
@keyframes marquee {
from {
transform: translateX(0);
}
to {
transform: translateX(calc(-100% - var(--marquee-gap)));
}
} |
Hi @Nyiriland @michalczaplinski I require a marquee block on https://github.com/a8cteam51/blanes-museum project. I found out we already have a draft pull request for the block. Can anyone share the status of the block development? Let me know if you need help taking this block development further. |
Hey @sagarnasit! This work on this block was done as part of a 2-week sprint. I would love to move it forward but it's difficult to find resources, but we should get @stronenv's opinion on that. |
Hey @sagarnasit ! Thanks for flagging. If you need a marquee for the Blanes Museum feel free to extend on this block, that's great! cc: @nate-allen |
@Nyiriland @stronenv Is the current status of this block then that it's looking for a dev? |
@tommusrhodus I believe so, but let's tag in our project manager @dhanson-wp to confirm. |
@tommusrhodus that is correct. This block needs a dev. |
This adds a Marquee block that is capable of scrolling the contents that it contains. The block takes a Paragraph, Heading, Button, or Image block as children.
🚧 It's a WIP