-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
106 lines (98 loc) · 2.59 KB
/
index.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
102
103
104
105
106
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { Button } from '@wordpress/components';
import { forwardRef, useRef } from '@wordpress/element';
import { _x, sprintf } from '@wordpress/i18n';
import { Icon, plus } from '@wordpress/icons';
import deprecated from '@wordpress/deprecated';
/**
* Internal dependencies
*/
import Inserter from '../inserter';
import { useMergeRefs } from '@wordpress/compose';
function ButtonBlockAppender(
{ rootClientId, className, onFocus, tabIndex, onSelect },
ref
) {
const inserterButtonRef = useRef();
const mergedInserterButtonRef = useMergeRefs( [ inserterButtonRef, ref ] );
return (
<Inserter
position="bottom center"
rootClientId={ rootClientId }
__experimentalIsQuick
onSelectOrClose={ ( ...args ) => {
if ( onSelect && typeof onSelect === 'function' ) {
onSelect( ...args );
}
inserterButtonRef.current?.focus();
} }
renderToggle={ ( {
onToggle,
disabled,
isOpen,
blockTitle,
hasSingleBlockType,
} ) => {
const isToggleButton = ! hasSingleBlockType;
const label = hasSingleBlockType
? sprintf(
// translators: %s: the name of the block when there is only one
_x(
'Add %s',
'directly add the only allowed block'
),
blockTitle
)
: _x(
'Add block',
'Generic label for block inserter button'
);
return (
<Button
__next40pxDefaultSize
ref={ mergedInserterButtonRef }
onFocus={ onFocus }
tabIndex={ tabIndex }
className={ clsx(
className,
'block-editor-button-block-appender'
) }
onClick={ onToggle }
aria-haspopup={ isToggleButton ? 'true' : undefined }
aria-expanded={ isToggleButton ? isOpen : undefined }
// Disable reason: There shouldn't be a case where this button is disabled but not visually hidden.
// eslint-disable-next-line no-restricted-syntax
disabled={ disabled }
label={ label }
showTooltip
>
<Icon icon={ plus } />
</Button>
);
} }
isAppender
/>
);
}
/**
* Use `ButtonBlockAppender` instead.
*
* @deprecated
*/
export const ButtonBlockerAppender = forwardRef( ( props, ref ) => {
deprecated( `wp.blockEditor.ButtonBlockerAppender`, {
alternative: 'wp.blockEditor.ButtonBlockAppender',
since: '5.9',
} );
return ButtonBlockAppender( props, ref );
} );
/**
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/button-block-appender/README.md
*/
export default forwardRef( ButtonBlockAppender );