-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
index.js
42 lines (35 loc) · 972 Bytes
/
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
/**
* External dependencies
*/
import { useToolbarItem } from 'reakit/Toolbar';
/**
* WordPress dependencies
*/
import { forwardRef, useContext } from '@wordpress/element';
import warning from '@wordpress/warning';
/**
* Internal dependencies
*/
import ToolbarContext from '../toolbar-context';
function ToolbarItem( { children, ...props }, ref ) {
const accessibleToolbarState = useContext( ToolbarContext );
// https://reakit.io/docs/composition/#props-hooks
const itemProps = useToolbarItem( accessibleToolbarState, {
...props,
ref,
} );
if ( typeof children !== 'function' ) {
warning(
'`ToolbarItem` is a generic headless component that accepts only function children props'
);
return null;
}
if ( ! accessibleToolbarState ) {
warning(
'`ToolbarItem` should be rendered within `<Toolbar __experimentalAccessibilityLabel="label">`'
);
return null;
}
return children( itemProps );
}
export default forwardRef( ToolbarItem );