Skip to content

Commit

Permalink
Eoxia#27[Blocks] add: Carousel block parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
eoxia-amandine committed Jan 8, 2025
1 parent 5614bbb commit 38e3f94
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 32 deletions.
8 changes: 8 additions & 0 deletions blocks/build/eo-carousel/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"speed": {
"type": "number",
"default": 300
},
"pagination": {
"type": "boolean",
"default": true
},
"navigation": {
"type": "boolean",
"default": true
}
},
"supports": {},
Expand Down
2 changes: 1 addition & 1 deletion blocks/build/eo-carousel/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '24d81fb11939d0081bb5');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '53218907a6063a7bb7b1');
25 changes: 24 additions & 1 deletion blocks/build/eo-carousel/index.js

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

2 changes: 1 addition & 1 deletion blocks/build/eo-carousel/index.js.map

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions blocks/build/eo-carousel/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,35 @@

$carousel_attr = array(
'slidesPerView' => esc_attr( $attributes['slidesPerView'] ),
'loop' => esc_attr( $attributes['loop'] )
'loop' => esc_attr( $attributes['loop'] ),
'speed' => esc_attr( $attributes['speed'] )
);

if ( $attributes['autoplay'] ) {
$carousel_attr['autoplay'] = array( 'delay' => $attributes['autoplayDelay'] * 10 );
} else {
$carousel_attr['autoplay'] = false;
}


if ( ! $attributes['pagination'] ) {
$carousel_attr['pagination'] = false;
}
if ( ! $attributes['navigation'] ) {
$carousel_attr['navigation'] = false;
}
?>

<div <?php echo wp_kses_data( get_block_wrapper_attributes( [ 'class' => 'swiper' ] ) ); ?> data-carousel=<?php echo wp_json_encode( $carousel_attr ); ?>>
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<?php echo wp_kses_post( $content ); ?>
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>

<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<?php if ( $attributes['pagination'] ) : ?>
<div class="swiper-pagination"></div>
<?php endif; ?>

<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
<?php if ( $attributes['navigation'] ) : ?>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<?php endif; ?>
</div>
2 changes: 1 addition & 1 deletion blocks/build/eo-carousel/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '2cbbc5284f283d2a2a6c');
<?php return array('dependencies' => array(), 'version' => '79aa1181d165cc92c347');
7 changes: 3 additions & 4 deletions blocks/build/eo-carousel/view.js

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

2 changes: 1 addition & 1 deletion blocks/build/eo-carousel/view.js.map

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

8 changes: 8 additions & 0 deletions blocks/src/eo-carousel/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
"speed": {
"type": "number",
"default": 300
},
"pagination": {
"type": "boolean",
"default": true
},
"navigation": {
"type": "boolean",
"default": true
}
},
"supports": {},
Expand Down
20 changes: 20 additions & 0 deletions blocks/src/eo-carousel/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ export default function Edit( { attributes, setAttributes, clientId } ) {
min={1}
max={6}
/>
<RangeControl
label={ __( 'Slide animation speed (MS)', 'eo-blocks' ) }
step={50}
value={attributes.speed}
onChange={(value) => setAttributes({speed: value})}
min={0}
max={2000}
/>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Prev/Next navigation', 'eo-blocks' ) }
checked={ attributes.navigation }
onChange={ ( value ) => setAttributes( { navigation: value } ) }
/>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Dots navigation', 'eo-blocks' ) }
checked={ attributes.pagination }
onChange={ ( value ) => setAttributes( { pagination: value } ) }
/>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Loop sliding', 'eo-blocks' ) }
Expand Down
25 changes: 15 additions & 10 deletions blocks/src/eo-carousel/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,35 @@

$carousel_attr = array(
'slidesPerView' => esc_attr( $attributes['slidesPerView'] ),
'loop' => esc_attr( $attributes['loop'] )
'loop' => esc_attr( $attributes['loop'] ),
'speed' => esc_attr( $attributes['speed'] )
);

if ( $attributes['autoplay'] ) {
$carousel_attr['autoplay'] = array( 'delay' => $attributes['autoplayDelay'] * 10 );
} else {
$carousel_attr['autoplay'] = false;
}


if ( ! $attributes['pagination'] ) {
$carousel_attr['pagination'] = false;
}
if ( ! $attributes['navigation'] ) {
$carousel_attr['navigation'] = false;
}
?>

<div <?php echo wp_kses_data( get_block_wrapper_attributes( [ 'class' => 'swiper' ] ) ); ?> data-carousel=<?php echo wp_json_encode( $carousel_attr ); ?>>
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<?php echo wp_kses_post( $content ); ?>
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>

<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<?php if ( $attributes['pagination'] ) : ?>
<div class="swiper-pagination"></div>
<?php endif; ?>

<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
<?php if ( $attributes['navigation'] ) : ?>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<?php endif; ?>
</div>
5 changes: 2 additions & 3 deletions blocks/src/eo-carousel/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ document.addEventListener('DOMContentLoaded', () => {
const swiperDefaultAttributes = {
slidesPerView: 1,
loop: true,
speed: 300,
autoplay: false,
pagination: {
el: '.swiper-pagination',
dynamicBullets: true,
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
scrollbar: {
el: '.swiper-scrollbar',
},
}

console.log(jQuery.extend( swiperDefaultAttributes, swiperCustomAttributes ));
Expand Down

0 comments on commit 38e3f94

Please sign in to comment.