Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiled gallery: rounded corners #14704

Merged
merged 4 commits into from
Feb 17, 2020
Merged
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
1 change: 1 addition & 0 deletions extensions/blocks/tiled-gallery/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const ALLOWED_MEDIA_TYPES = [ 'image' ];
export const DEFAULT_GALLERY_WIDTH = 580;
export const GUTTER_WIDTH = 4;
export const MAX_COLUMNS = 20;
export const MAX_ROUNDED_CORNERS = 20;
export const PHOTON_MAX_RESIZE = 2000;

/**
Expand Down
21 changes: 20 additions & 1 deletion extensions/blocks/tiled-gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ import {
*/
import FilterToolbar from './filter-toolbar';
import Layout from './layout';
import { ALLOWED_MEDIA_TYPES, LAYOUT_STYLES, MAX_COLUMNS } from './constants';
import {
ALLOWED_MEDIA_TYPES,
LAYOUT_CIRCLE,
LAYOUT_STYLES,
MAX_COLUMNS,
MAX_ROUNDED_CORNERS,
} from './constants';
import { getActiveStyleName } from '../../shared/block-styles';
import { icon } from '.';
import EditButton from '../../shared/edit-button';
Expand Down Expand Up @@ -156,6 +162,8 @@ class TiledGalleryEdit extends Component {

setColumnsNumber = value => this.setAttributes( { columns: value } );

setRoundedCorners = value => this.setAttributes( { roundedCorners: value } );

setImageAttributes = index => attributes => {
const {
attributes: { images },
Expand Down Expand Up @@ -192,6 +200,7 @@ class TiledGalleryEdit extends Component {
imageFilter,
images,
linkTo,
roundedCorners,
} = attributes;

const dropZone = <DropZone onFilesDrop={ this.addFiles } />;
Expand Down Expand Up @@ -262,6 +271,15 @@ class TiledGalleryEdit extends Component {
max={ Math.min( MAX_COLUMNS, images.length ) }
/>
) }
{ layoutStyle !== LAYOUT_CIRCLE && (
<RangeControl
label={ __( 'Rounded corners', 'jetpack' ) }
value={ roundedCorners }
onChange={ this.setRoundedCorners }
min={ 0 }
max={ MAX_ROUNDED_CORNERS }
/>
) }
<SelectControl
label={ __( 'Link To', 'jetpack' ) }
value={ linkTo }
Expand All @@ -285,6 +303,7 @@ class TiledGalleryEdit extends Component {
onMoveForward={ this.onMoveForward }
onRemoveImage={ this.onRemoveImage }
onSelectImage={ this.onSelectImage }
roundedCorners={ roundedCorners }
selectedImage={ isSelected ? selectedImage : null }
setImageAttributes={ this.setImageAttributes }
>
Expand Down
4 changes: 4 additions & 0 deletions extensions/blocks/tiled-gallery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ const blockAttributes = {
default: 'none',
type: 'string',
},
roundedCorners: {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

borderRadius could be another name and match CSS rule, but figured this is more self-explanatory.

type: 'integer',
default: 0,
},
};

const exampleAttributes = {
Expand Down
14 changes: 10 additions & 4 deletions extensions/blocks/tiled-gallery/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { __, sprintf } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import classnames from 'classnames';
Copy link
Member Author

@simison simison Feb 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that this doesn't end up to built bundle meant for frontend _inc/blocks/tiled-gallery/view.js and make it needlessly bigger.


/**
* Internal dependencies
Expand All @@ -12,6 +13,7 @@ import GalleryImageSave from '../gallery-image/save';
import Mosaic from './mosaic';
import Square from './square';
import { isSquareishLayout, photonizedImgProps } from '../utils';
import { LAYOUT_CIRCLE, MAX_ROUNDED_CORNERS } from '../constants';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that this doesn't pull in wp.i18n dependency on frontend bundle.


export default class Layout extends Component {
// This is tricky:
Expand Down Expand Up @@ -73,14 +75,18 @@ export default class Layout extends Component {
}

render() {
const { align, children, className, columns, images, layoutStyle } = this.props;

const { align, children, className, columns, images, layoutStyle, roundedCorners } = this.props;
const LayoutRenderer = isSquareishLayout( layoutStyle ) ? Square : Mosaic;

const renderedImages = this.props.images.map( this.renderImage, this );
const roundedCornersValue =
layoutStyle !== LAYOUT_CIRCLE ? Math.min( roundedCorners, MAX_ROUNDED_CORNERS ) : 0;

return (
<div className={ className }>
<div
className={ classnames( className, {
[ `has-rounded-corners-${ roundedCornersValue }` ]: roundedCornersValue > 0,
} ) }
>
<LayoutRenderer
align={ align }
columns={ columns }
Expand Down
9 changes: 8 additions & 1 deletion extensions/blocks/tiled-gallery/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export default function TiledGallerySave( { attributes } ) {
return null;
}

const { align, className, columns = defaultColumnsNumber( attributes ), linkTo } = attributes;
const {
align,
className,
columns = defaultColumnsNumber( attributes ),
linkTo,
roundedCorners,
} = attributes;

return (
<Layout
Expand All @@ -25,6 +31,7 @@ export default function TiledGallerySave( { attributes } ) {
isSave
layoutStyle={ getActiveStyleName( LAYOUT_STYLES, className ) }
linkTo={ linkTo }
roundedCorners={ roundedCorners }
/>
);
}
7 changes: 7 additions & 0 deletions extensions/blocks/tiled-gallery/view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@import './css-gram.scss';

$tiled-gallery-max-column-count: 20;
$tiled-gallery-max-rounded-corners: 20; // See constants.js for JS counterpart

.wp-block-jetpack-tiled-gallery {
margin: 0 auto $jetpack-block-margin-bottom;
Expand Down Expand Up @@ -33,6 +34,12 @@ $tiled-gallery-max-column-count: 20;
display: flex;
}
}

@for $i from 1 through $tiled-gallery-max-rounded-corners {
Copy link
Member Author

@simison simison Feb 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will generate 20 lines of CSS like this. Figured it's lightweight enough addition when limited to 20 or so.

Alternatively (maybe in another PR) we can have this in a separate CSS file which we enqueue only when they have rounded corners

Another alternative is to generate this in PHP for the exact number as inline CSS, allowing the setting to become unlimited instead of capped to 20.

&.has-rounded-corners-#{$i} .tiled-gallery__item img {
border-radius: #{$i}px;
}
}
}

.tiled-gallery__gallery {
Expand Down