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

Carousel Block #143

Merged
merged 23 commits into from
Oct 14, 2019
Merged

Carousel Block #143

merged 23 commits into from
Oct 14, 2019

Conversation

jeffersonrabb
Copy link
Contributor

@jeffersonrabb jeffersonrabb commented Oct 8, 2019

All Submissions:

Changes proposed in this Pull Request:

Adds a Carousel block that uses amp-carousel to display posts. amp-carousel cannot currently be used in the editor because it does not support DOM mutation after page load, which occurs whenever the array of posts to be displayed changes. Eventually Bento AMP will resolve this, but until this is available we will use the Swiper library to make the block functional in the editor. Currently, there is only a placeholder in the editor.

Screen Shot 2019-10-08 at 12 18 29 AM

Closes #48.

How to test the changes in this Pull Request:

  1. Check out the branch and execute npm run build:webpack
  2. Add Articles Carousel block to a post.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@thomasguillot
Copy link
Contributor

Any chance we can have some settings for the autoplay like for Jetpack Slideshow? (and maybe the effect).

https://cld.wthms.co/tjUxYc

@jeffersonrabb
Copy link
Contributor Author

Any chance we can have some settings for the autoplay like for Jetpack Slideshow? (and maybe the effect).

We can support the toggle and the interval, but AFAIK amp-carousel does not support alternative transitions. Docs are here. See anything I missed?

@thomasguillot
Copy link
Contributor

We can support the toggle and the interval, but AFAIK amp-carousel does not support alternative transitions. Docs are here. See anything I missed?

Ok, no problem for the transitions. The autoplay is much more needed 😊

@jeffersonrabb
Copy link
Contributor Author

The autoplay is much more needed

Added in 07a9db4

@thomasguillot
Copy link
Contributor

Added in 07a9db4

That was quick! 😊
Can we have a play/pause button when using the autoplay?

@thomasguillot
Copy link
Contributor

@jeffersonrabb I committed a bunch of fixes:

  • Update block icon
  • Resize avatar size on > tablet
  • Have links in white for better contrast against black
  • Make sure .entry-wrapper doesn't overflow
  • Add a cursor: pointer to the prev/next buttons

How about we add a new style? Something like this:

Screenshot 2019-10-09 at 14 46 46

Can we have 2 toggles (on by default) to:

  1. show/hide the bullets, and
  2. show/hide the arrows

@jeffersonrabb
Copy link
Contributor Author

jeffersonrabb commented Oct 9, 2019

Can we have a play/pause button when using the autoplay?

Added in 07a9db4

Correction: ce71688

@thomasguillot I left the play/pause button in the upper left corner, for you to position however you see fit.

@jeffersonrabb
Copy link
Contributor Author

show/hide the bullets, and show/hide the arrows

Wouldn't hiding these be compromising the block's usability and accessibility?

@jeffersonrabb
Copy link
Contributor Author

How about we add a new style?

I like the alternate style. Another possible style might be to use thumbnails instead of bullets?

@thomasguillot
Copy link
Contributor

Wouldn't hiding these be compromising the block's usability and accessibility?

Yes and no 😊

  • The arrows are technically not needed since you can navigate with the bullets.
  • If you hide the bullets, a visitor will have no idea how many slides there are or which one is on. Maybe we could have a counter if the bullets are hidden, like "2 / 5".
  • You can only hide both if you are on autoplay (otherwise how would a visitor see the rest of the carousel 😅). But yes, this option isn't great for usability and accessibility. Maybe we could display a warning message.

I think allowing these to be hidden offers a bit more flexibility to the block and front-end design.

@thomasguillot
Copy link
Contributor

Another possible style might be to use thumbnails instead of bullets?

Thumbnails would be great!

@thomasguillot
Copy link
Contributor

In b981df6 I added a few more changes:

I moved the play/pause button to the top right corner like for Jetpack Slideshow.
I increased the maximum delay time to 20 s because I felt that 5 s was not always enough time to process, the image, the title, the author and the date.
And I set the default time to 5 s rather than 3 s.

@thomasguillot
Copy link
Contributor

One thing I noticed is if you completely disable the AMP plugin, there's no fallback and you get all the posts, one after the other.

newspack test_(1440 x 1048)

Comment on lines 17 to 44
wp_enqueue_script(
'amp-carousel',
'https://cdn.ampproject.org/v0/amp-carousel-0.1.js',
null,
NEWSPACK_BLOCKS__VERSION,
true
);
wp_enqueue_script(
'amp-selector',
'https://cdn.ampproject.org/v0/amp-selector-0.1.js',
null,
NEWSPACK_BLOCKS__VERSION,
true
);

Choose a reason for hiding this comment

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

The AMP plugin is already registering this script in amp_register_default_scripts(): https://github.com/ampproject/amp-wp/blob/039554da947563bd7a3432aa724282b1c20a86b9/includes/amp-helper-functions.php#L435-L499

These scripts are registered even when the page is not AMP. They are registered always. It gets amp-runtime as a dependency.

So no script is registered here.

So all you need to do here is:

wp_enqueue_script( 'amp-carousel' );
wp_enqueue_script( 'amp-selector' );

In reality, you can even remove the Newspack_Blocks::is_amp() check because enqueueing those scripts will not hurt in AMP pages. The AMP plugin will ensure that those scripts are present if they weren't already enqueued when there is an amp-carousel or amp-selector in the page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The AMP plugin is already registering this script in amp_register_default_scripts():

What if the AMP plugin is not installed at all?

@jeffersonrabb
Copy link
Contributor Author

One thing I noticed is if you completely disable the AMP plugin, there's no fallback and you get all the posts, one after the other.

Should be resolved in b2c2a5b

@jeffersonrabb
Copy link
Contributor Author

Editor implementation using Swiper: 5dc0ddb

@thomasguillot
Copy link
Contributor

I added a few changes to the editor's stylesheet in 4f4523c

jeffersonrabb and others added 10 commits October 11, 2019 07:29
* Have links in white for better contrast against black
* Make sure `.entry-wrapper` doesn't overflow
* Add a `cursor: pointer` to the prev/next buttons
* Reposition the play/pause button to the top right corner
* Increase maximum delay time to 20 s
* Set default delay time to 5 s
@claudiulodro claudiulodro self-assigned this Oct 13, 2019
Copy link
Contributor

@claudiulodro claudiulodro left a comment

Choose a reason for hiding this comment

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

Looks good, just needs some minor tweaks. I'll make those updates on Monday and then this should be good to go.

src/blocks/carousel/edit.js Outdated Show resolved Hide resolved
src/blocks/carousel/edit.js Outdated Show resolved Hide resolved
src/blocks/carousel/edit.js Outdated Show resolved Hide resolved
src/blocks/carousel/view.php Show resolved Hide resolved
src/blocks/carousel/edit.js Show resolved Hide resolved
src/blocks/carousel/view.php Outdated Show resolved Hide resolved
Copy link
Contributor

@claudiulodro claudiulodro left a comment

Choose a reason for hiding this comment

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

This should be good to go. We can fine-tune the customization options in future PRs if needed.

@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Homepage Blocks: Carousel
5 participants