-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathedit.js
101 lines (95 loc) · 2.27 KB
/
edit.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
AlignmentControl,
BlockControls,
RichText,
useBlockProps,
} from '@wordpress/block-editor';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
import { Platform } from '@wordpress/element';
/**
* Internal dependencies
*/
import { Figure } from './figure';
import { BlockQuote } from './blockquote';
const isWebPlatform = Platform.OS === 'web';
function PullQuoteEdit( {
attributes,
setAttributes,
isSelected,
insertBlocksAfter,
} ) {
const { textAlign, citation, value } = attributes;
const blockProps = useBlockProps( {
className: classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ),
} );
const shouldShowCitation = ! RichText.isEmpty( citation ) || isSelected;
return (
<>
<BlockControls group="block">
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
<Figure { ...blockProps }>
<BlockQuote>
<RichText
identifier="value"
tagName="p"
value={ value }
onChange={ ( nextValue ) =>
setAttributes( {
value: nextValue,
} )
}
aria-label={ __( 'Pullquote text' ) }
placeholder={
// translators: placeholder text used for the quote
__( 'Add quote' )
}
textAlign="center"
/>
{ shouldShowCitation && (
<RichText
identifier="citation"
tagName={ isWebPlatform ? 'cite' : undefined }
style={ { display: 'block' } }
value={ citation }
aria-label={ __( 'Pullquote citation text' ) }
placeholder={
// translators: placeholder text used for the citation
__( 'Add citation' )
}
onChange={ ( nextCitation ) =>
setAttributes( {
citation: nextCitation,
} )
}
className="wp-block-pullquote__citation"
__unstableMobileNoFocusOnMount
textAlign="center"
__unstableOnSplitAtEnd={ () =>
insertBlocksAfter(
createBlock( getDefaultBlockName() )
)
}
/>
) }
</BlockQuote>
</Figure>
</>
);
}
export default PullQuoteEdit;