-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
gallery.js
81 lines (76 loc) · 1.9 KB
/
gallery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import {
RichText,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
import { View } from '@wordpress/primitives';
import { forwardRef } from '@wordpress/element';
export const Gallery = ( props, captionRef ) => {
const {
attributes,
isSelected,
setAttributes,
mediaPlaceholder,
insertBlocksAfter,
blockProps,
__unstableLayoutClassNames: layoutClassNames,
showCaption,
} = props;
const { align, columns, caption, imageCrop } = attributes;
return (
<figure
{ ...blockProps }
className={ classnames(
blockProps.className,
layoutClassNames,
'blocks-gallery-grid',
{
[ `align${ align }` ]: align,
[ `columns-${ columns }` ]: columns !== undefined,
[ `columns-default` ]: columns === undefined,
'is-cropped': imageCrop,
}
) }
>
{ blockProps.children }
{ isSelected && ! blockProps.children && (
<View className="blocks-gallery-media-placeholder-wrapper">
{ mediaPlaceholder }
</View>
) }
{ showCaption &&
( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
identifier="caption"
aria-label={ __( 'Gallery caption text' ) }
placeholder={ __( 'Write gallery caption…' ) }
value={ caption }
className={ classnames(
'blocks-gallery-caption',
__experimentalGetElementClassName( 'caption' )
) }
ref={ captionRef }
tagName="figcaption"
onChange={ ( value ) =>
setAttributes( { caption: value } )
}
inlineToolbar
__unstableOnSplitAtEnd={ () =>
insertBlocksAfter(
createBlock( getDefaultBlockName() )
)
}
/>
) }
</figure>
);
};
export default forwardRef( Gallery );