Skip to content

Commit d297511

Browse files
authored
feat: add both slick and swiper sliders (#47)
1 parent cc2adba commit d297511

File tree

12 files changed

+330
-71
lines changed

12 files changed

+330
-71
lines changed

src/blocks/block-slider/_slider-admin.scss renamed to src/blocks/block-slick/_slick-admin.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
.wp-block-client-slider {
1+
.wp-block-client-slick {
22
.block-editor-block-list__layout {
33
overflow: auto;
44
white-space: nowrap;
55
}
66

7-
[data-type='client/slider-item'] {
7+
[data-type='client/slick-item'] {
88
display: inline-block;
99
width: 95%;
1010
}

src/blocks/block-slick/_slick.scss

Whitespace-only changes.
Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ const {
1515
const {
1616
PanelBody,
1717
PanelRow,
18+
SelectControl,
1819
ToggleControl,
1920
} = wp.components;
2021

2122
/*
2223
* Register block
2324
*/
24-
registerBlockType( 'client/slider', {
25-
title: __( 'Slider', 'grayscale' ),
25+
registerBlockType( 'client/slick', {
26+
title: __( 'Slick Slider', 'grayscale' ),
2627
description: __(
27-
'Slideshow of items.',
28+
'Slideshow of items using Slick.',
2829
'grayscale'
2930
),
3031
category: 'widgets',
@@ -36,6 +37,10 @@ registerBlockType( 'client/slider', {
3637
type: 'boolean',
3738
default: false,
3839
},
40+
effect: {
41+
type: 'string',
42+
deafult: 'slide',
43+
},
3944
navigation: {
4045
type: 'boolean',
4146
default: true,
@@ -49,13 +54,17 @@ registerBlockType( 'client/slider', {
4954
supports: {
5055
anchor: true,
5156
align: [],
57+
dimensions: {
58+
minHeight: true,
59+
},
5260
multiple: true,
5361
},
5462
parent: null,
5563
edit: ( props ) => {
5664
const {
5765
attributes: {
5866
autoplay,
67+
effect,
5968
navigation,
6069
pagination,
6170
},
@@ -94,52 +103,53 @@ registerBlockType( 'client/slider', {
94103
} ) }
95104
/>
96105
</PanelRow>
106+
<PanelRow>
107+
<SelectControl
108+
label={ __( 'Effect', 'grayscale' ) }
109+
value={ effect }
110+
options={
111+
[
112+
{ label: __( 'Slide', 'grayscale' ), value: 'slide' },
113+
{ label: __( 'Fade', 'grayscale' ), value: 'fade' },
114+
]
115+
}
116+
onChange={ ( value ) => setAttributes( {
117+
effect: value,
118+
} ) }
119+
/>
120+
</PanelRow>
97121
</PanelBody>
98122
</InspectorControls>
99123
<div className={ classnames( className ) }>
100-
<InnerBlocks allowedBlocks={ [ 'client/slider-item' ] } />
124+
<InnerBlocks allowedBlocks={ [ 'client/slick-item' ] } />
101125
</div>
102126
</>
103127
);
104128
},
105129
save: ( props ) => {
106130
const {
107131
autoplay,
132+
effect,
108133
navigation,
109134
pagination,
110135
} = props.attributes;
111136
return (
112137
<div
113-
className={ classnames( 'swiper' ) }
114138
data-autoplay={ autoplay ? 'true' : 'false' }
139+
data-effect={ effect }
115140
data-navigation={ navigation ? 'true' : 'false' }
116141
data-pagination={ pagination ? 'true' : 'false' }
117142
>
118-
<div className="swiper-wrapper">
119-
<InnerBlocks.Content />
120-
</div>
121-
{
122-
pagination ? (
123-
<div className="swiper-pagination"></div>
124-
) : null
125-
}
126-
{
127-
navigation ? (
128-
<>
129-
<div className="swiper-button-prev"></div>
130-
<div className="swiper-button-next"></div>
131-
</>
132-
) : null
133-
}
143+
<InnerBlocks.Content />
134144
</div>
135145
);
136146
},
137147
} );
138148

139-
registerBlockType( 'client/slider-item', {
140-
title: __( 'Slider Item', 'grayscale' ),
149+
registerBlockType( 'client/slick-item', {
150+
title: __( 'Slick Slider Item', 'grayscale' ),
141151
description: __(
142-
'Slide within the Slider.',
152+
'Slide within the Slick Slider.',
143153
'grayscale'
144154
),
145155
category: 'widgets',
@@ -153,7 +163,7 @@ registerBlockType( 'client/slider-item', {
153163
align: [],
154164
multiple: true,
155165
},
156-
parent: [ 'client/slider' ],
166+
parent: [ 'client/slick' ],
157167
edit: ( props ) => {
158168
const {
159169
className,
@@ -167,7 +177,7 @@ registerBlockType( 'client/slider-item', {
167177
},
168178
save: () => {
169179
return (
170-
<div className={ classnames( 'swiper-slide' ) }>
180+
<div className={ classnames( 'slick-slide' ) }>
171181
<InnerBlocks.Content />
172182
</div>
173183
);

src/blocks/block-slick/slick.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
jQuery( function( $ ) {
2+
if ( $( '.wp-block-client-slick' ).length ) {
3+
$( '.wp-block-client-slick' ).each( ( i, el ) => {
4+
const $el = $( el );
5+
6+
// For a list of avaialble parameters,
7+
// check https://kenwheeler.github.io/slick/#settings
8+
$el.slick( {
9+
arrows: $el.data( 'navigation' ) ? true : false,
10+
autoplay: $el.data( 'autoplay' ) ? true : false,
11+
fade: $el.data( 'effect' ) === 'fade' ? true : false,
12+
dots: $el.data( 'pagination' ) ? true : false,
13+
} );
14+
} );
15+
}
16+
} );

src/blocks/block-slider/slider.js

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.wp-block-client-swiper {
2+
.block-editor-block-list__layout {
3+
overflow: auto;
4+
white-space: nowrap;
5+
}
6+
7+
[data-type='client/swiper-item'] {
8+
display: inline-block;
9+
width: 95%;
10+
}
11+
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
.wp-block-client-slider {
1+
.wp-block-client-swiper {
22
--swiper-theme-color: var(--wp--preset--color--major);
33
--swiper-navigation-size: 2rem;
44
--swiper-navigation-color: var(--swiper-theme-color);
55
--swiper-pagination-bullet-size: 1rem;
66

7-
:where(.swiper-slide) {
8-
background: var(--wp--preset--color--background);
9-
}
10-
117
.swiper-slide {
128
height: auto;
139

0 commit comments

Comments
 (0)