Skip to content

Commit

Permalink
Merge pull request #143 from Automattic/add/carousel
Browse files Browse the repository at this point in the history
Carousel Block
  • Loading branch information
claudiulodro authored Oct 14, 2019
2 parents acd706c + 91ca6a8 commit f3a72e1
Show file tree
Hide file tree
Showing 12 changed files with 1,172 additions and 7 deletions.
5 changes: 4 additions & 1 deletion newspack-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static function dependencies_from_path( $path ) {
*
* @return string Class list separated by spaces.
*/
public static function block_classes( $type, $attributes = array() ) {
public static function block_classes( $type, $attributes = array(), $extra = array() ) {
$align = isset( $attributes['align'] ) ? $attributes['align'] : 'center';
$classes = array(
"wp-block-newspack-blocks-{$type}",
Expand All @@ -168,6 +168,9 @@ public static function block_classes( $type, $attributes = array() ) {
if ( isset( $attributes['className'] ) ) {
array_push( $classes, $attributes['className'] );
}
if ( is_array( $extra ) && ! empty( $extra ) ) {
$classes = array_merge( $classes, $extra );
}
return implode( $classes, ' ' );
}

Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"test": "tests"
},
"private": true,
"dependencies": {},
"dependencies": {
"swiper": "4.5.1"
},
"scripts": {
"build:webpack": "calypso-build --config='./webpack.config.js'",
"clean": "rm -rf dist/",
Expand Down
37 changes: 37 additions & 0 deletions src/blocks/carousel/create-swiper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* External dependencies
*/
import { mapValues, merge } from 'lodash';
import Swiper from 'Swiper';
import '../../../node_modules/swiper/dist/css/swiper.css';

export default function createSwiper(
container = '.swiper-container',
params = {},
callbacks = {}
) {
const defaultParams = {
effect: 'slide',
grabCursor: true,
init: true,
initialSlide: 0,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
pagination: {
bulletElement: 'button',
clickable: true,
el: '.swiper-pagination',
type: 'bullets',
},
preventClicksPropagation: false /* Necessary for normal block interactions */,
releaseFormElements: false,
setWrapperSize: true,
touchStartPreventDefault: false,
};
// const [ { default: Swiper } ] = await Promise.all( [
// import( /* webpackChunkName: "swiper" */ 'swiper' ),
// ] );
return new Swiper( container, merge( {}, defaultParams, params ) );
}
Loading

0 comments on commit f3a72e1

Please sign in to comment.