Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion src/blocks/carousel/slide/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
],
"description": "A single slide within the carousel.",
"textdomain": "carousel-kit",
"attributes": {},
"attributes": {
"verticalAlignment": {
"type": "string"
}
},
"usesContext": [
"carousel-kit/carousel/allowedSlideBlocks"
],
Expand Down
30 changes: 27 additions & 3 deletions src/blocks/carousel/slide/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
import {
useBlockProps,
useInnerBlocksProps,
BlockControls,
BlockVerticalAlignmentToolbar,
} from '@wordpress/block-editor';
import type { CarouselSlideAttributes } from '../types';

export default function Edit( {
attributes,
setAttributes,
context,
}: {
attributes: CarouselSlideAttributes;
setAttributes: ( attributes: Partial<CarouselSlideAttributes> ) => void;
context: { 'carousel-kit/carousel/allowedSlideBlocks'?: string[] };
} ) {
const allowedBlocks = context[ 'carousel-kit/carousel/allowedSlideBlocks' ];

const { verticalAlignment } = attributes;

const blockProps = useBlockProps( {
className: 'embla__slide',
className: `embla__slide${
verticalAlignment ? ` is-vertically-aligned-${ verticalAlignment }` : ''
}`,
} );

const innerBlocksProps = useInnerBlocksProps( blockProps, {
Expand All @@ -19,5 +31,17 @@ export default function Edit( {
templateLock: false,
} );

return <div { ...innerBlocksProps } />;
return (
<>
<BlockControls>
<BlockVerticalAlignmentToolbar
value={ verticalAlignment }
onChange={ ( value ) =>
setAttributes( { verticalAlignment: value } )
}
/>
</BlockControls>
<div { ...innerBlocksProps } />
</>
);
}
8 changes: 6 additions & 2 deletions src/blocks/carousel/slide/save.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
import type { CarouselSlideAttributes } from '../types';

export default function Save() {
export default function Save( { attributes }: { attributes: CarouselSlideAttributes } ) {
const { verticalAlignment } = attributes;
const blockProps = useBlockProps.save( {
className: 'embla__slide',
className: `embla__slide${
verticalAlignment ? ` is-vertically-aligned-${ verticalAlignment }` : ''
}`,
role: 'group',
'aria-roledescription': 'slide',
'data-wp-interactive': 'carousel-kit/carousel',
Expand Down
21 changes: 21 additions & 0 deletions src/blocks/carousel/styles/_core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@
margin-inline-end: 0;
margin-block-start: 0;
margin-block-end: 0;

/* Vertical alignment support */
display: flex;
flex-direction: column;

&.is-vertically-aligned-top {
justify-content: flex-start;
}

&.is-vertically-aligned-center,
&.is-vertically-aligned-middle {
justify-content: center;
}

&.is-vertically-aligned-bottom {
justify-content: flex-end;
}

&.is-vertically-aligned-space-between {
justify-content: space-between;
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/blocks/carousel/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { EmblaOptionsType } from 'embla-carousel';
import type { BlockVerticalAlignmentToolbar } from '@wordpress/block-editor';

export type CarouselAttributes = {
loop: boolean;
Expand All @@ -20,7 +21,9 @@ export type CarouselAttributes = {
};

export type CarouselViewportAttributes = Record<string, never>;
export type CarouselSlideAttributes = Record<string, never>;
export type CarouselSlideAttributes = {
verticalAlignment?: BlockVerticalAlignmentToolbar.Value;
};
export type CarouselControlsAttributes = Record<string, never>;
export type CarouselDotsAttributes = Record<string, never>;

Expand Down