Skip to content

Commit

Permalink
Adding in photo positioning.
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldhuereca committed Sep 24, 2024
1 parent 477daf6 commit 77960b2
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 28 deletions.
4 changes: 4 additions & 0 deletions build/blocks/photo-block/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@
"type": "string",
"default": "center"
},
"photoPosition": {
"type": "string",
"default": "center"
},
"imageSize": {
"type": "string",
"default": "large"
Expand Down
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-a11y', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-escape-html', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-plugins', 'wp-url'), 'version' => 'a80a1794c64297fec9e3');
<?php return array('dependencies' => array('react', 'wp-a11y', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-escape-html', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => 'db5e1769faa91c9fc22f');
12 changes: 12 additions & 0 deletions build/index.css

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

2 changes: 1 addition & 1 deletion build/index.css.map

Large diffs are not rendered by default.

202 changes: 187 additions & 15 deletions build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions includes/Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ function ( $v, $k ) {
$section_css_classes = array(
'dlx-photo-block__container',
'align' . esc_attr( $attributes['align'] ),
'dlx-photo-position-' . esc_attr( $attributes['photoPosition'] ),
);
if ( $has_global_style ) {
$section_css_classes[] = $global_style_css_class;
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/photo-block/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@
"type": "string",
"default": "center"
},
"photoPosition": {
"type": "string",
"default": "center"
},
"imageSize": {
"type": "string",
"default": "large"
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/photo-block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const PhotoBlock = ( props ) => {
align,
globalStyle,
photoDropShadow,
photoPosition,
} = props.attributes;

const { globalStyleCSSClassName } = useSelect( ( newSelect ) => {
Expand Down Expand Up @@ -184,6 +185,7 @@ const PhotoBlock = ( props ) => {
className: classnames(
`dlx-photo-block`,
`align${ align }`,
`dlx-photo-position-${ photoPosition }`,
`dlx-screen-${ currentScreen }`,
`dlx-caption-position-${ captionPosition }`,
globalStyleCSSClassName,
Expand Down
41 changes: 32 additions & 9 deletions src/screens/Edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ import {
Layers,
Undo2,
} from 'lucide-react';
import {
positionLeft,
positionRight,
positionCenter,
} from '@wordpress/icons';
import { applyFilters } from '@wordpress/hooks';
import classnames from 'classnames';
import { blockStore } from '../../store';
Expand Down Expand Up @@ -75,6 +80,7 @@ const EditScreen = forwardRef( ( props, ref ) => {
imageSize,
cssGramFilter,
globalStyle,
photoPosition,
} = attributes;

const { globalStyleCSSClassName } = useSelect( ( newSelect ) => {
Expand Down Expand Up @@ -399,6 +405,32 @@ const EditScreen = forwardRef( ( props, ref ) => {
<AlignmentToolbar { ...props } />
)
}
<ToolbarGroup>
<ToolbarButton
icon={ positionLeft }
label={ __( 'Positon Left', 'photo-block' ) }
onClick={ () => {
setAttributes( { photoPosition: 'left' } );
} }
isPressed={ 'left' === photoPosition }
/>
<ToolbarButton
icon={ positionCenter }
label={ __( 'Positon Center', 'photo-block' ) }
onClick={ () => {
setAttributes( { photoPosition: 'center' } );
} }
isPressed={ 'center' === photoPosition }
/>
<ToolbarButton
icon={ positionRight }
label={ __( 'Positon Right', 'photo-block' ) }
onClick={ () => {
setAttributes( { photoPosition: 'right' } );
} }
isPressed={ 'right' === photoPosition }
/>
</ToolbarGroup>
<ToolbarGroup>
{
isJustCropped && (
Expand Down Expand Up @@ -427,15 +459,6 @@ const EditScreen = forwardRef( ( props, ref ) => {
>
{ __( 'Crop', 'photo-block' ) }
</ToolbarButton>
{ /* <ToolbarButton
icon={ <Stars /> }
label={ __( 'Effects', 'photo-block' ) }
onClick={ () => {
setScreen( 'effects' );
} }
>
{ __( 'Effects', 'photo-block' ) }
</ToolbarButton> */ }
</ToolbarGroup>
<ToolbarGroup>
<ToolbarButton
Expand Down
33 changes: 32 additions & 1 deletion src/screens/FeaturedImageEdit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import {
import classnames from 'classnames';
import hexToRgba from 'hex-to-rgba';
import { useDispatch, useSelect } from '@wordpress/data';

import {
positionLeft,
positionRight,
positionCenter,
} from '@wordpress/icons';
import SendCommand from '../../utils/SendCommand';
import useDeviceType from '../../hooks/useDeviceType';
import PanelBodyControl from '../../components/PanelBody';
Expand Down Expand Up @@ -70,6 +74,7 @@ const FeaturedImageScreen = forwardRef( ( props, ref ) => {
photoOpacity,
photoBlur,
photoDropShadow,
photoPosition,
photoBackgroundColor,
cssGramFilter,
lightboxEnabled,
Expand Down Expand Up @@ -326,6 +331,32 @@ const FeaturedImageScreen = forwardRef( ( props, ref ) => {
<AlignmentToolbar { ...props } />
)
}
<ToolbarGroup>
<ToolbarButton
icon={ positionLeft }
label={ __( 'Positon Left', 'photo-block' ) }
onClick={ () => {
setAttributes( { photoPosition: 'left' } );
} }
isPressed={ 'left' === photoPosition }
/>
<ToolbarButton
icon={ positionCenter }
label={ __( 'Positon Center', 'photo-block' ) }
onClick={ () => {
setAttributes( { photoPosition: 'center' } );
} }
isPressed={ 'center' === photoPosition }
/>
<ToolbarButton
icon={ positionRight }
label={ __( 'Positon Right', 'photo-block' ) }
onClick={ () => {
setAttributes( { photoPosition: 'right' } );
} }
isPressed={ 'right' === photoPosition }
/>
</ToolbarGroup>
<ToolbarGroup>
<ToolbarButton
icon={ <Link /> }
Expand Down
9 changes: 9 additions & 0 deletions src/scss/block-backend-frontend.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
flex-direction: column;
align-items: center;
}
.dlx-photo-position-left .dlx-photo-block__figure {
align-items: flex-start
}
.dlx-photo-position-right .dlx-photo-block__figure {
align-items: flex-end;
}
.dlx-photo-position-center .dlx-photo-block__figure {
align-items: center;
}
.dlx-photo-block__image {
box-sizing: border-box;
}
Expand Down

0 comments on commit 77960b2

Please sign in to comment.