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: Move localized style labels into settings #30752

Merged
merged 1 commit into from
Feb 13, 2019
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
30 changes: 14 additions & 16 deletions client/gutenberg/extensions/tiled-gallery/constants.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
/**
* Internal Dependencies
*/
import { _x } from 'gutenberg/extensions/presets/jetpack/utils/i18n';

export const ALLOWED_MEDIA_TYPES = [ 'image' ];
export const DEFAULT_GALLERY_WIDTH = 580;
export const DEFAULT_LAYOUT = 'rectangular';
export const GUTTER_WIDTH = 4;
export const MAX_COLUMNS = 20;
export const PHOTON_MAX_RESIZE = 2000;

/**
* Layouts
*/
export const LAYOUT_CIRCLE = 'circle';
export const LAYOUT_COLUMN = 'columns';
export const LAYOUT_DEFAULT = 'rectangular';
export const LAYOUT_SQUARE = 'square';
export const LAYOUT_STYLES = [
{
isDefault: true,
label: _x( 'Tiled mosaic', 'Tiled gallery layout' ),
name: DEFAULT_LAYOUT,
name: LAYOUT_DEFAULT,
},
{
label: _x( 'Circles', 'Tiled gallery layout' ),
name: 'circle',
name: LAYOUT_CIRCLE,
},
{
label: _x( 'Square tiles', 'Tiled gallery layout' ),
name: 'square',
name: LAYOUT_SQUARE,
},
{
label: _x( 'Tiled columns', 'Tiled gallery layout' ),
name: 'columns',
name: LAYOUT_COLUMN,
},
];
export const MAX_COLUMNS = 20;
export const PHOTON_MAX_RESIZE = 2000;
31 changes: 26 additions & 5 deletions client/gutenberg/extensions/tiled-gallery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,34 @@ import { Path, SVG } from '@wordpress/components';
import { __, _x } from 'gutenberg/extensions/presets/jetpack/utils/i18n';
import edit from './edit';
import save from './save';
import { DEFAULT_LAYOUT, LAYOUT_STYLES } from './constants';
import {
LAYOUT_CIRCLE,
LAYOUT_COLUMN,
LAYOUT_DEFAULT,
LAYOUT_SQUARE,
LAYOUT_STYLES,
} from './constants';

/**
* Style dependencies
*/
import './editor.scss';

// Style names are translated. Avoid introducing an i18n dependency elsewhere (view)
// by only including the labels here, the only place they're needed.
//
// Map style names to labels and merge them together.
const styleNames = {
[ LAYOUT_DEFAULT ]: _x( 'Tiled mosaic', 'Tiled gallery layout' ),
[ LAYOUT_CIRCLE ]: _x( 'Circles', 'Tiled gallery layout' ),
[ LAYOUT_COLUMN ]: _x( 'Tiled columns', 'Tiled gallery layout' ),
[ LAYOUT_SQUARE ]: _x( 'Square tiles', 'Tiled gallery layout' ),
};
const layoutStylesWithLabels = LAYOUT_STYLES.map( style => ( {
...style,
label: styleNames[ style.name ],
} ) );

const blockAttributes = {
// Set default align
align: {
Expand All @@ -26,7 +47,7 @@ const blockAttributes = {
},
// Set default className (used with block styles)
className: {
default: `is-style-${ DEFAULT_LAYOUT }`,
default: `is-style-${ LAYOUT_DEFAULT }`,
type: 'string',
},
columns: {
Expand Down Expand Up @@ -109,7 +130,7 @@ export const settings = {
_x( 'photos', 'block search term' ),
_x( 'masonry', 'block search term' ),
],
styles: LAYOUT_STYLES,
styles: layoutStylesWithLabels,
supports: {
align: [ 'center', 'wide', 'full' ],
customClassName: false,
Expand Down Expand Up @@ -174,11 +195,11 @@ export const settings = {
},
layout: {
type: 'string',
shortcode: ( { named: { type = DEFAULT_LAYOUT } } ) => {
shortcode: ( { named: { type = LAYOUT_DEFAULT } } ) => {
// @TODO: if `type=slideshow`, return a slideshow block
return LAYOUT_STYLES.map( style => style.name ).includes( type )
? type
: DEFAULT_LAYOUT;
: LAYOUT_DEFAULT;
},
},
},
Expand Down